mirror of
https://github.com/ipxe/ipxe
synced 2026-01-02 01:42:37 +03:00
[efi] Perform meaningful error code conversions
Exploit the redefinition of iPXE error codes to include a "platform error code" to allow for meaningful conversion of EFI_STATUS values to iPXE errors and vice versa. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -20,6 +20,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <ipxe/open.h>
|
||||
#include <ipxe/process.h>
|
||||
#include <ipxe/iobuf.h>
|
||||
@@ -59,7 +60,7 @@ struct efi_download_file {
|
||||
*/
|
||||
static void efi_download_close ( struct efi_download_file *file, int rc ) {
|
||||
|
||||
file->finish_callback ( file->context, RC_TO_EFIRC ( rc ) );
|
||||
file->finish_callback ( file->context, EFIRC ( rc ) );
|
||||
|
||||
intf_shutdown ( &file->xfer, rc );
|
||||
}
|
||||
@@ -77,6 +78,7 @@ static int efi_download_deliver_iob ( struct efi_download_file *file,
|
||||
struct xfer_metadata *meta ) {
|
||||
EFI_STATUS efirc;
|
||||
size_t len = iob_len ( iobuf );
|
||||
int rc;
|
||||
|
||||
/* Calculate new buffer position */
|
||||
if ( meta->flags & XFER_FL_ABS_OFFSET )
|
||||
@@ -84,14 +86,21 @@ static int efi_download_deliver_iob ( struct efi_download_file *file,
|
||||
file->pos += meta->offset;
|
||||
|
||||
/* Call out to the data handler */
|
||||
efirc = file->data_callback ( file->context, iobuf->data,
|
||||
len, file->pos );
|
||||
if ( ( efirc = file->data_callback ( file->context, iobuf->data,
|
||||
len, file->pos ) ) != 0 ) {
|
||||
rc = -EEFI ( efirc );
|
||||
goto err_callback;
|
||||
}
|
||||
|
||||
/* Update current buffer position */
|
||||
file->pos += len;
|
||||
|
||||
/* Success */
|
||||
rc = 0;
|
||||
|
||||
err_callback:
|
||||
free_iob ( iobuf );
|
||||
return EFIRC_TO_RC ( efirc );
|
||||
return rc;
|
||||
}
|
||||
|
||||
/** Data transfer interface operations */
|
||||
@@ -135,7 +144,7 @@ efi_download_start ( IPXE_DOWNLOAD_PROTOCOL *This __unused,
|
||||
rc = xfer_open ( &file->xfer, LOCATION_URI_STRING, Url );
|
||||
if ( rc ) {
|
||||
free ( file );
|
||||
return RC_TO_EFIRC ( rc );
|
||||
return EFIRC ( rc );
|
||||
}
|
||||
|
||||
file->pos = 0;
|
||||
@@ -162,7 +171,7 @@ efi_download_abort ( IPXE_DOWNLOAD_PROTOCOL *This __unused,
|
||||
EFI_STATUS Status ) {
|
||||
struct efi_download_file *file = File;
|
||||
|
||||
efi_download_close ( file, EFIRC_TO_RC ( Status ) );
|
||||
efi_download_close ( file, -EEFI ( Status ) );
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -195,6 +204,7 @@ static IPXE_DOWNLOAD_PROTOCOL ipxe_download_protocol_interface = {
|
||||
int efi_download_install ( EFI_HANDLE *handle ) {
|
||||
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
|
||||
EFI_STATUS efirc;
|
||||
int rc;
|
||||
|
||||
efirc = bs->InstallMultipleProtocolInterfaces (
|
||||
handle,
|
||||
@@ -202,9 +212,10 @@ int efi_download_install ( EFI_HANDLE *handle ) {
|
||||
&ipxe_download_protocol_interface,
|
||||
NULL );
|
||||
if ( efirc ) {
|
||||
rc = -EEFI ( efirc );
|
||||
DBG ( "Could not install download protocol: %s\n",
|
||||
efi_strerror ( efirc ) );
|
||||
return EFIRC_TO_RC ( efirc );
|
||||
strerror ( rc ) );
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user