iPXE
|
EFI file protocols. More...
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <errno.h>
#include <wchar.h>
#include <ipxe/image.h>
#include <ipxe/cpio.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/Protocol/SimpleFileSystem.h>
#include <ipxe/efi/Protocol/BlockIo.h>
#include <ipxe/efi/Protocol/DiskIo.h>
#include <ipxe/efi/Protocol/LoadFile2.h>
#include <ipxe/efi/Guid/FileInfo.h>
#include <ipxe/efi/Guid/FileSystemInfo.h>
#include <ipxe/efi/efi_strings.h>
#include <ipxe/efi/efi_path.h>
#include <ipxe/efi/efi_file.h>
Go to the source code of this file.
Data Structures | |
struct | efi_file_reader |
An EFI virtual file reader. More... | |
struct | efi_file |
An EFI file. More... | |
struct | efi_file_path |
An EFI fixed device path file. More... | |
Macros | |
#define | EFI_MEDIA_ID_MAGIC 0x69505845 |
EFI media ID. More... | |
#define | LINUX_INITRD_VENDOR_GUID |
Linux initrd fixed device path vendor GUID. More... | |
Variables | |
static struct efi_file | efi_file_root |
Root directory. More... | |
static struct efi_file_path | efi_file_initrd |
Magic initrd file. More... | |
struct { | |
VENDOR_DEVICE_PATH vendor | |
EFI_DEVICE_PATH_PROTOCOL end | |
} | efi_file_initrd_path |
Linux initrd fixed device path. More... | |
static EFI_SIMPLE_FILE_SYSTEM_PROTOCOL | efi_simple_file_system_protocol |
EFI simple file system protocol. More... | |
static EFI_BLOCK_IO_MEDIA | efi_block_io_media |
Dummy block I/O media. More... | |
static EFI_BLOCK_IO_PROTOCOL | efi_block_io_protocol |
Dummy EFI block I/O protocol. More... | |
static EFI_DISK_IO_PROTOCOL | efi_disk_io_protocol |
Dummy EFI disk I/O protocol. More... | |
EFI file protocols.
Definition in file efi_file.c.
#define EFI_MEDIA_ID_MAGIC 0x69505845 |
EFI media ID.
Definition at line 54 of file efi_file.c.
#define LINUX_INITRD_VENDOR_GUID |
Linux initrd fixed device path vendor GUID.
Definition at line 57 of file efi_file.c.
FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
|
static |
Free EFI file.
refcnt | Reference count |
Definition at line 114 of file efi_file.c.
References container_of, efi_file::file, free, and image_put().
Referenced by efi_file_open_image().
|
static |
Get EFI file name (for debugging)
file | EFI file |
name | Name |
Definition at line 128 of file efi_file.c.
References efi_file_root, and efi_file::file.
Referenced by efi_file_close(), efi_file_delete(), efi_file_flush(), efi_file_get_info(), efi_file_load(), efi_file_open(), efi_file_open_fixed(), efi_file_open_image(), efi_file_path_claim(), efi_file_path_install(), efi_file_path_uninstall(), efi_file_read(), efi_file_read_initrd(), efi_file_set_info(), efi_file_set_position(), and efi_file_write().
|
static |
Find EFI file image.
name | Filename |
image | Image, or NULL |
Definition at line 139 of file efi_file.c.
References for_each_image, image::name, name, NULL, and strcasecmp().
Referenced by efi_file_open().
Get length of EFI file.
file | EFI file |
len | Length of file |
Definition at line 157 of file efi_file.c.
References efi_file_reader::data, efi_file_reader::file, efi_file_reader::len, NULL, efi_file_reader::pos, and efi_file::read.
Referenced by efi_file_info(), efi_file_load(), and efi_file_set_position().
|
static |
Read chunk of EFI file.
reader | EFI file reader |
data | Input data, or UNULL to zero-fill |
len | Length of input data |
len | Length of output data |
Definition at line 184 of file efi_file.c.
References copy_from_user(), data, efi_file_reader::data, efi_file_reader::file, efi_file::file, len, efi_file_reader::len, memset(), offset, and efi_file_reader::pos.
Referenced by efi_file_read_image(), and efi_file_read_initrd().
|
static |
Read from image-backed file.
reader | EFI file reader |
len | Length read |
Definition at line 225 of file efi_file.c.
References image::data, efi_file_read_chunk(), efi_file_reader::file, efi_file::file, efi_file::image, and image::len.
Referenced by efi_file_image().
|
static |
Read from magic initrd file.
reader | EFI file reader |
len | Length read |
Definition at line 239 of file efi_file.c.
References cpio_header(), cpio_name(), cpio_pad_len(), image::data, DBGC, efi_file_name(), efi_file_read_chunk(), efi_file_reader::file, efi_file::file, image::flags, for_each_image, IMAGE_HIDDEN, INITRD_ALIGN, len, image::len, image::name, name, pad_len, efi_file_reader::pos, UNULL, and virt_to_user().
|
static |
Open fixed file.
file | EFI file |
wname | Filename |
new | New EFI file |
efirc | EFI status code |
Definition at line 304 of file efi_file.c.
References DBGC, efi_file_name(), efi_file::file, ref_get, and efi_file::refcnt.
Referenced by efi_file_open(), and efi_file_open_volume().
Associate file with image.
file | EFI file |
image | Image |
Definition at line 325 of file efi_file.c.
References efi_file_read_image(), efi_file::image, image::name, efi_file::name, and efi_file::read.
Referenced by efi_file_open_image(), and efi_file_read_dir().
|
static |
Open image-backed file.
image | Image |
wname | Filename |
new | New EFI file |
efirc | EFI status code |
Definition at line 340 of file efi_file.c.
References DBGC, efi_file_free(), efi_file_image(), efi_file_name(), efi_file_root, EFI_OUT_OF_RESOURCES, efi_file::file, image_get(), efi_file::load, memcpy(), ref_init, and zalloc().
Referenced by efi_file_open().
|
static |
Open file.
this | EFI file |
new | New EFI file |
wname | Filename |
mode | File mode |
attributes | File attributes (for newly-created files) |
efirc | EFI status code |
Definition at line 373 of file efi_file.c.
References container_of, DBGC, efi_file_find(), efi_file_initrd, EFI_FILE_MODE_READ, efi_file_name(), efi_file_open_fixed(), efi_file_open_image(), efi_file_root, EFI_NOT_FOUND, EFI_WRITE_PROTECTED, efi_file::file, efi_file_path::file, find_image_tag(), efi_file::name, name, NULL, selected_image, snprintf(), strcasecmp(), strncasecmp(), strrchr(), and wcslen().
|
static |
Close file.
this | EFI file |
efirc | EFI status code |
Definition at line 439 of file efi_file.c.
References container_of, DBGC, efi_file_name(), efi_file::file, and ref_put.
Referenced by efi_file_delete().
|
static |
Close and delete file.
this | EFI file |
efirc | EFI status code |
Definition at line 455 of file efi_file.c.
References container_of, DBGC, efi_file_close(), efi_file_name(), EFI_WARN_DELETE_FAILURE, and efi_file::file.
|
static |
Return variable-length data structure.
base | Base data structure (starting with UINT64) |
base_len | Length of base data structure |
name | Name to append to base data structure |
len | Length of data buffer |
data | Data buffer |
efirc | EFI status code |
Definition at line 477 of file efi_file.c.
References base, data, EFI_BUFFER_TOO_SMALL, efi_snprintf(), len, memcpy(), name, and strlen().
Referenced by efi_file_get_info(), and efi_file_info().
|
static |
Return file information structure.
file | EFI file |
len | Length of data buffer |
data | Data buffer |
efirc | EFI status code |
Definition at line 506 of file efi_file.c.
References data, EFI_FILE_DIRECTORY, efi_file_len(), EFI_FILE_READ_ONLY, efi_file_root, efi_file_varlen(), efi_file::file, info, len, memset(), and SIZE_OF_EFI_FILE_INFO.
Referenced by efi_file_get_info(), and efi_file_read_dir().
|
static |
Read directory entry.
file | EFI file |
len | Length to read |
data | Data buffer |
efirc | EFI status code |
Definition at line 534 of file efi_file.c.
References data, efi_file_image(), efi_file_info(), image::flags, for_each_image, IMAGE_HIDDEN, index, len, and efi_file::pos.
Referenced by efi_file_read().
|
static |
Read from file.
this | EFI file |
len | Length to read |
data | Data buffer |
efirc | EFI status code |
Definition at line 574 of file efi_file.c.
References assert(), container_of, data, efi_file_reader::data, DBGC, efi_file_name(), efi_file_read_dir(), efi_file_reader::file, efi_file::file, len, efi_file_reader::len, efi_file_reader::pos, efi_file::pos, and efi_file::read.
Referenced by efi_file_load().
|
static |
Write to file.
this | EFI file |
len | Length to write |
data | Data buffer |
efirc | EFI status code |
Definition at line 607 of file efi_file.c.
References container_of, DBGC, efi_file_name(), EFI_WRITE_PROTECTED, efi_file::file, and len.
|
static |
Set file position.
this | EFI file |
position | New file position |
efirc | EFI status code |
Definition at line 624 of file efi_file.c.
References container_of, DBGC, efi_file_len(), efi_file_name(), EFI_UNSUPPORTED, efi_file::file, and len.
|
static |
Get file position.
this | EFI file |
position | New file position |
efirc | EFI status code |
Definition at line 660 of file efi_file.c.
References container_of, and efi_file::file.
|
static |
Get file information.
this | EFI file |
type | Type of information |
len | Buffer size |
data | Buffer |
efirc | EFI status code |
Definition at line 677 of file efi_file.c.
References container_of, data, DBGC, efi_file_info(), efi_file_info_id, efi_file_name(), efi_file_system_info_id, efi_file_varlen(), efi_guid_ntoa(), EFI_UNSUPPORTED, efi_file::file, for_each_image, len, image::len, memcmp(), memset(), EFI_FILE_SYSTEM_INFO::ReadOnly, EFI_FILE_SYSTEM_INFO::Size, SIZE_OF_EFI_FILE_SYSTEM_INFO, type, and EFI_FILE_SYSTEM_INFO::VolumeSize.
|
static |
Set file information.
this | EFI file |
type | Type of information |
len | Buffer size |
data | Buffer |
efirc | EFI status code |
Definition at line 723 of file efi_file.c.
References container_of, DBGC, efi_file_name(), efi_guid_ntoa(), EFI_WRITE_PROTECTED, efi_file::file, and type.
|
static |
Flush file modified data.
this | EFI file |
type | Type of information |
len | Buffer size |
data | Buffer |
efirc | EFI status code |
Definition at line 741 of file efi_file.c.
References container_of, DBGC, efi_file_name(), and efi_file::file.
|
static |
Load file.
this | EFI file loader |
path | File path |
boot | Boot policy |
len | Buffer size |
data | Buffer, or NULL |
efirc | EFI status code |
Definition at line 759 of file efi_file.c.
References container_of, data, DBGC, EFI_BUFFER_TOO_SMALL, efi_file_len(), efi_file_name(), efi_file_read(), efi_file::file, len, and efi_file::load.
|
static |
Open root directory.
filesystem | EFI simple file system |
file | EFI file handle |
efirc | EFI status code |
Definition at line 864 of file efi_file.c.
References DBGC, efi_file_open_fixed(), efi_file_root, and efi_file_path::file.
|
static |
Dummy block I/O reset.
Definition at line 879 of file efi_file.c.
References DBGC, and efi_file_root.
|
static |
Dummy block I/O read.
Definition at line 888 of file efi_file.c.
References data, DBGC, efi_file_root, EFI_NO_MEDIA, lba, and len.
|
static |
Dummy block I/O write.
Definition at line 899 of file efi_file.c.
References data, DBGC, efi_file_root, EFI_NO_MEDIA, lba, and len.
|
static |
Dummy block I/O flush.
Definition at line 911 of file efi_file.c.
References DBGC, and efi_file_root.
|
static |
Dummy disk I/O read.
Definition at line 937 of file efi_file.c.
References data, DBGC, efi_file_root, EFI_NO_MEDIA, len, and offset.
|
static |
Dummy disk I/O write.
Definition at line 948 of file efi_file.c.
References data, DBGC, efi_file_root, EFI_NO_MEDIA, len, and offset.
|
static |
Claim use of fixed device path.
file | Fixed device path file |
rc | Return status code |
The design choice in Linux of using a single fixed device path is unfortunately messy to support, since device paths must be unique within a system. When multiple bootloaders are used (e.g. GRUB loading iPXE loading Linux) then only one bootloader can ever install the device path onto a handle. Bootloaders must therefore be prepared to locate an existing handle and uninstall its device path protocol instance before installing a new handle with the required device path.
Definition at line 979 of file efi_file.c.
References assert(), EFI_SYSTEM_TABLE::BootServices, DBGC, EEFI, efi_device_path_protocol_guid, efi_devpath_text(), efi_file_name(), efi_handle_name(), efi_systab, end, END_DEVICE_PATH_TYPE, efi_file::file, efi_file_path::file, handle, EFI_BOOT_SERVICES::HandleProtocol, EFI_BOOT_SERVICES::LocateDevicePath, NULL, old, rc, strerror(), EFI_DEVICE_PATH_PROTOCOL::Type, EFI_BOOT_SERVICES::UninstallMultipleProtocolInterfaces, and VOID.
Referenced by efi_file_install().
|
static |
Install fixed device path file.
file | Fixed device path file |
rc | Return status code |
Linux 5.7 added the ability to autodetect an initrd by searching for a handle via a fixed vendor-specific "Linux initrd device path" and then locating and using the EFI_LOAD_FILE2_PROTOCOL instance on that handle.
Definition at line 1038 of file efi_file.c.
References assert(), EFI_SYSTEM_TABLE::BootServices, DBGC, EEFI, efi_device_path_protocol_guid, efi_devpath_text(), efi_file_name(), efi_load_file2_protocol_guid, efi_systab, efi_file::file, efi_file_path::file, EFI_BOOT_SERVICES::InstallMultipleProtocolInterfaces, NULL, rc, and strerror().
Referenced by efi_file_install().
|
static |
Uninstall fixed device path file.
file | Fixed device path file |
rc | Return status code |
Definition at line 1070 of file efi_file.c.
References EFI_SYSTEM_TABLE::BootServices, DBGC, EEFI, efi_device_path_protocol_guid, efi_devpath_text(), efi_file_name(), efi_guid_ntoa(), efi_load_file2_protocol_guid, efi_systab, efi_file::file, efi_file_path::file, NULL, rc, strerror(), and EFI_BOOT_SERVICES::UninstallMultipleProtocolInterfaces.
Referenced by efi_file_install(), and efi_file_uninstall().
int efi_file_install | ( | EFI_HANDLE | handle | ) |
Install EFI simple file system protocol.
handle | EFI handle |
rc | Return status code |
Definition at line 1115 of file efi_file.c.
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_initrd, efi_file_path_claim(), efi_file_path_install(), efi_file_path_uninstall(), efi_file_root, efi_image_handle, EFI_OPEN_PROTOCOL_BY_DRIVER, efi_simple_file_system_protocol, efi_simple_file_system_protocol_guid, efi_systab, image::flags, for_each_image, handle, IMAGE_HIDDEN, EFI_BOOT_SERVICES::InstallMultipleProtocolInterfaces, NULL, EFI_BOOT_SERVICES::OpenProtocol, efi_file::pos, rc, strerror(), and EFI_BOOT_SERVICES::UninstallMultipleProtocolInterfaces.
Referenced by efi_image_exec().
void efi_file_uninstall | ( | EFI_HANDLE | handle | ) |
Uninstall EFI simple file system protocol.
handle | EFI handle |
Definition at line 1218 of file efi_file.c.
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_file_initrd, efi_file_path_uninstall(), 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().
|
static |
Root directory.
Definition at line 106 of file efi_file.c.
Referenced by efi_block_io_flush_blocks(), efi_block_io_read_blocks(), efi_block_io_reset(), efi_block_io_write_blocks(), efi_disk_io_read_disk(), efi_disk_io_write_disk(), efi_file_info(), efi_file_install(), efi_file_name(), efi_file_open(), efi_file_open_image(), and efi_file_open_volume().
|
static |
Magic initrd file.
Definition at line 107 of file efi_file.c.
Referenced by efi_file_install(), efi_file_open(), and efi_file_uninstall().
VENDOR_DEVICE_PATH vendor |
Definition at line 811 of file efi_file.c.
Definition at line 812 of file efi_file.c.
Referenced by efi_file_path_claim().
struct { ... } efi_file_initrd_path |
Linux initrd fixed device path.
|
static |
EFI simple file system protocol.
Definition at line 872 of file efi_file.c.
Referenced by efi_file_install(), and efi_file_uninstall().
|
static |
Dummy block I/O media.
Definition at line 918 of file efi_file.c.
|
static |
Dummy EFI block I/O protocol.
Definition at line 926 of file efi_file.c.
Referenced by efi_file_install(), and efi_file_uninstall().
|
static |
Dummy EFI disk I/O protocol.
Definition at line 958 of file efi_file.c.
Referenced by efi_file_install(), and efi_file_uninstall().