iPXE
Functions
efi_file.h File Reference

EFI file protocols. More...

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
int efi_file_install (EFI_HANDLE handle)
 Install EFI simple file system protocol. More...
 
void efi_file_uninstall (EFI_HANDLE handle)
 Uninstall EFI simple file system protocol. More...
 

Detailed Description

EFI file protocols.

Definition in file efi_file.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ efi_file_install()

int efi_file_install ( EFI_HANDLE  handle)

Install EFI simple file system protocol.

Parameters
handleEFI handle
Return values
rcReturn status code

Definition at line 842 of file efi_file.c.

842  {
844  union {
845  EFI_DISK_IO_PROTOCOL *diskio;
846  void *interface;
847  } diskio;
848  EFI_STATUS efirc;
849  int rc;
850 
851  /* Reset root directory state */
852  efi_file_root.pos = 0;
853 
854  /* Install the simple file system protocol, block I/O
855  * protocol, and disk I/O protocol. We don't have a block
856  * device, but large parts of the EDK2 codebase make the
857  * assumption that file systems are normally attached to block
858  * devices, and so we create a dummy block device on the same
859  * handle just to keep things looking normal.
860  */
861  if ( ( efirc = bs->InstallMultipleProtocolInterfaces (
862  &handle,
869  rc = -EEFI ( efirc );
870  DBGC ( handle, "Could not install simple file system "
871  "protocols: %s\n", strerror ( rc ) );
872  goto err_install;
873  }
874 
875  /* The FAT filesystem driver has a bug: if a block device
876  * contains no FAT filesystem but does have an
877  * EFI_SIMPLE_FILE_SYSTEM_PROTOCOL instance, the FAT driver
878  * will assume that it must have previously installed the
879  * EFI_SIMPLE_FILE_SYSTEM_PROTOCOL. This causes the FAT
880  * driver to claim control of our device, and to refuse to
881  * stop driving it, which prevents us from later uninstalling
882  * correctly.
883  *
884  * Work around this bug by opening the disk I/O protocol
885  * ourselves, thereby preventing the FAT driver from opening
886  * it.
887  *
888  * Note that the alternative approach of opening the block I/O
889  * protocol (and thereby in theory preventing DiskIo from
890  * attaching to the block I/O protocol) causes an endless loop
891  * of calls to our DRIVER_STOP method when starting the EFI
892  * shell. I have no idea why this is.
893  */
894  if ( ( efirc = bs->OpenProtocol ( handle, &efi_disk_io_protocol_guid,
895  &diskio.interface, efi_image_handle,
896  handle,
897  EFI_OPEN_PROTOCOL_BY_DRIVER ) ) != 0){
898  rc = -EEFI ( efirc );
899  DBGC ( handle, "Could not open disk I/O protocol: %s\n",
900  strerror ( rc ) );
902  goto err_open;
903  }
904  assert ( diskio.diskio == &efi_disk_io_protocol );
905 
906  return 0;
907 
910  err_open:
912  handle,
919  err_install:
920  return rc;
921 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:162
static EFI_BLOCK_IO_PROTOCOL efi_block_io_protocol
Dummy EFI block I/O protocol.
Definition: efi_file.c:798
#define DBGC(...)
Definition: compiler.h:505
#define EFI_OPEN_PROTOCOL_BY_DRIVER
Definition: UefiSpec.h:1274
EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES InstallMultipleProtocolInterfaces
Definition: UefiSpec.h:1915
#define DBGC_EFI_OPENERS(...)
Definition: efi.h:286
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1906
static EFI_DISK_IO_PROTOCOL efi_disk_io_protocol
Dummy EFI disk I/O protocol.
Definition: efi_file.c:830
EFI_GUID efi_disk_io_protocol_guid
Disk I/O protocol GUID.
Definition: efi_guid.c:144
size_t pos
Current file position.
Definition: efi_file.c:77
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
An object interface.
Definition: interface.h:124
EFI_GUID efi_simple_file_system_protocol_guid
Simple file system protocol GUID.
Definition: efi_guid.c:232
static struct efi_file efi_file_root
Root directory.
Definition: efi_file.c:87
This protocol is used to abstract Block I/O interfaces.
Definition: DiskIo.h:106
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:33
EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES UninstallMultipleProtocolInterfaces
Definition: UefiSpec.h:1916
EFI_GUID efi_block_io_protocol_guid
Block I/O protocol GUID.
Definition: efi_guid.c:108
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1905
static EFI_SIMPLE_FILE_SYSTEM_PROTOCOL efi_simple_file_system_protocol
EFI simple file system protocol.
Definition: efi_file.c:744
uint16_t handle
Handle.
Definition: smbios.h:16
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References assert(), EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseProtocol, DBGC, DBGC_EFI_OPENERS, EEFI, efi_block_io_protocol, efi_block_io_protocol_guid, efi_disk_io_protocol, efi_disk_io_protocol_guid, efi_file_root, efi_image_handle, EFI_OPEN_PROTOCOL_BY_DRIVER, efi_simple_file_system_protocol, efi_simple_file_system_protocol_guid, efi_systab, handle, EFI_BOOT_SERVICES::InstallMultipleProtocolInterfaces, NULL, EFI_BOOT_SERVICES::OpenProtocol, efi_file::pos, rc, strerror(), and EFI_BOOT_SERVICES::UninstallMultipleProtocolInterfaces.

Referenced by efi_image_exec().

◆ efi_file_uninstall()

void efi_file_uninstall ( EFI_HANDLE  handle)

Uninstall EFI simple file system protocol.

Parameters
handleEFI handle

Definition at line 928 of file efi_file.c.

928  {
930  EFI_STATUS efirc;
931  int rc;
932 
933  /* Close our own disk I/O protocol */
936 
937  /* We must install the file system protocol first, since
938  * otherwise the EDK2 code will attempt to helpfully uninstall
939  * it when the block I/O protocol is uninstalled, leading to a
940  * system lock-up.
941  */
942  if ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
943  handle,
949  &efi_block_io_protocol, NULL ) ) != 0 ) {
950  rc = -EEFI ( efirc );
951  DBGC ( handle, "Could not uninstall simple file system "
952  "protocols: %s\n", strerror ( rc ) );
953  /* Oh dear */
954  }
955 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:162
static EFI_BLOCK_IO_PROTOCOL efi_block_io_protocol
Dummy EFI block I/O protocol.
Definition: efi_file.c:798
#define DBGC(...)
Definition: compiler.h:505
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1906
static EFI_DISK_IO_PROTOCOL efi_disk_io_protocol
Dummy EFI disk I/O protocol.
Definition: efi_file.c:830
EFI_GUID efi_disk_io_protocol_guid
Disk I/O protocol GUID.
Definition: efi_guid.c:144
EFI_GUID efi_simple_file_system_protocol_guid
Simple file system protocol GUID.
Definition: efi_guid.c:232
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:33
EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES UninstallMultipleProtocolInterfaces
Definition: UefiSpec.h:1916
EFI_GUID efi_block_io_protocol_guid
Block I/O protocol GUID.
Definition: efi_guid.c:108
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
EFI_SYSTEM_TABLE * efi_systab
static EFI_SIMPLE_FILE_SYSTEM_PROTOCOL efi_simple_file_system_protocol
EFI simple file system protocol.
Definition: efi_file.c:744
uint16_t handle
Handle.
Definition: smbios.h:16
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseProtocol, DBGC, EEFI, efi_block_io_protocol, efi_block_io_protocol_guid, efi_disk_io_protocol, efi_disk_io_protocol_guid, efi_image_handle, efi_simple_file_system_protocol, efi_simple_file_system_protocol_guid, efi_systab, handle, NULL, rc, strerror(), and EFI_BOOT_SERVICES::UninstallMultipleProtocolInterfaces.

Referenced by efi_image_exec().