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 602 of file efi_file.c.

602  {
604  union {
605  EFI_DISK_IO_PROTOCOL *diskio;
606  void *interface;
607  } diskio;
608  EFI_STATUS efirc;
609  int rc;
610 
611  /* Reset root directory state */
612  efi_file_root.pos = 0;
613 
614  /* Install the simple file system protocol, block I/O
615  * protocol, and disk I/O protocol. We don't have a block
616  * device, but large parts of the EDK2 codebase make the
617  * assumption that file systems are normally attached to block
618  * devices, and so we create a dummy block device on the same
619  * handle just to keep things looking normal.
620  */
621  if ( ( efirc = bs->InstallMultipleProtocolInterfaces (
622  &handle,
629  rc = -EEFI ( efirc );
630  DBGC ( handle, "Could not install simple file system "
631  "protocols: %s\n", strerror ( rc ) );
632  goto err_install;
633  }
634 
635  /* The FAT filesystem driver has a bug: if a block device
636  * contains no FAT filesystem but does have an
637  * EFI_SIMPLE_FILE_SYSTEM_PROTOCOL instance, the FAT driver
638  * will assume that it must have previously installed the
639  * EFI_SIMPLE_FILE_SYSTEM_PROTOCOL. This causes the FAT
640  * driver to claim control of our device, and to refuse to
641  * stop driving it, which prevents us from later uninstalling
642  * correctly.
643  *
644  * Work around this bug by opening the disk I/O protocol
645  * ourselves, thereby preventing the FAT driver from opening
646  * it.
647  *
648  * Note that the alternative approach of opening the block I/O
649  * protocol (and thereby in theory preventing DiskIo from
650  * attaching to the block I/O protocol) causes an endless loop
651  * of calls to our DRIVER_STOP method when starting the EFI
652  * shell. I have no idea why this is.
653  */
654  if ( ( efirc = bs->OpenProtocol ( handle, &efi_disk_io_protocol_guid,
655  &diskio.interface, efi_image_handle,
656  handle,
657  EFI_OPEN_PROTOCOL_BY_DRIVER ) ) != 0){
658  rc = -EEFI ( efirc );
659  DBGC ( handle, "Could not open disk I/O protocol: %s\n",
660  strerror ( rc ) );
662  goto err_open;
663  }
664  assert ( diskio.diskio == &efi_disk_io_protocol );
665 
666  return 0;
667 
670  err_open:
672  handle,
679  err_install:
680  return rc;
681 }
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:157
static EFI_BLOCK_IO_PROTOCOL efi_block_io_protocol
Dummy EFI block I/O protocol.
Definition: efi_file.c:558
#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:260
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:590
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:60
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
An object interface.
Definition: interface.h:109
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:63
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:30
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:504
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 688 of file efi_file.c.

688  {
690  EFI_STATUS efirc;
691  int rc;
692 
693  /* Close our own disk I/O protocol */
696 
697  /* We must install the file system protocol first, since
698  * otherwise the EDK2 code will attempt to helpfully uninstall
699  * it when the block I/O protocol is uninstalled, leading to a
700  * system lock-up.
701  */
702  if ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
703  handle,
709  &efi_block_io_protocol, NULL ) ) != 0 ) {
710  rc = -EEFI ( efirc );
711  DBGC ( handle, "Could not uninstall simple file system "
712  "protocols: %s\n", strerror ( rc ) );
713  /* Oh dear */
714  }
715 }
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:157
static EFI_BLOCK_IO_PROTOCOL efi_block_io_protocol
Dummy EFI block I/O protocol.
Definition: efi_file.c:558
#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:590
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:30
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:504
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().