aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2023-05-04 15:29:23 +0100
committerMichael Brown <mcb30@ipxe.org>2023-05-05 13:05:28 +0100
commit22cc65535a331f05863f3c4b48910b0d50ff5dd7 (patch)
tree1d846165fa8259e9e934ce9c2c8533333ce33306
parentbd13697446e758d5fed6afcba8f3e9883b2e2de7 (diff)
downloadipxe-22cc65535a331f05863f3c4b48910b0d50ff5dd7.zip
ipxe-22cc65535a331f05863f3c4b48910b0d50ff5dd7.tar.gz
ipxe-22cc65535a331f05863f3c4b48910b0d50ff5dd7.tar.bz2
[efi] Allow downloaded images to take precedence over constructed files
Try searching for a matching registered image before checking for fixed filenames (such as "initrd.magic" for the dynamically generated magic initrd file). This minimises surprise by ensuring that an explicitly downloaded image will always be used verbatim. Signed-off-by: Michael Brown <mcb30@ipxe.org>
-rw-r--r--src/interface/efi/efi_file.c55
1 files changed, 33 insertions, 22 deletions
diff --git a/src/interface/efi/efi_file.c b/src/interface/efi/efi_file.c
index b232591..2ac6e2b 100644
--- a/src/interface/efi/efi_file.c
+++ b/src/interface/efi/efi_file.c
@@ -321,6 +321,33 @@ static void efi_file_image ( struct efi_file *file, struct image *image ) {
}
/**
+ * Open image-backed file
+ *
+ * @v image Image
+ * @v new New EFI file
+ * @ret efirc EFI status code
+ */
+static EFI_STATUS efi_file_open_image ( struct image *image,
+ EFI_FILE_PROTOCOL **new ) {
+ struct efi_file *file;
+
+ /* Allocate and initialise file */
+ file = zalloc ( sizeof ( *file ) );
+ if ( ! file )
+ return EFI_OUT_OF_RESOURCES;
+ ref_init ( &file->refcnt, efi_file_free );
+ memcpy ( &file->file, &efi_file_root.file, sizeof ( file->file ) );
+ memcpy ( &file->load, &efi_file_root.load, sizeof ( file->load ) );
+ efi_file_image ( file, image_get ( image ) );
+
+ /* Return opened file */
+ *new = &file->file;
+
+ DBGC ( file, "EFIFILE %s opened\n", efi_file_name ( file ) );
+ return 0;
+}
+
+/**
* Open file
*
* @v this EFI file
@@ -335,7 +362,6 @@ efi_file_open ( EFI_FILE_PROTOCOL *this, EFI_FILE_PROTOCOL **new,
CHAR16 *wname, UINT64 mode, UINT64 attributes __unused ) {
struct efi_file *file = container_of ( this, struct efi_file, file );
char buf[ wcslen ( wname ) + 1 /* NUL */ ];
- struct efi_file *new_file;
struct image *image;
char *name;
@@ -367,31 +393,16 @@ efi_file_open ( EFI_FILE_PROTOCOL *this, EFI_FILE_PROTOCOL **new,
return EFI_WRITE_PROTECTED;
}
+ /* Allow registered images to be opened */
+ if ( ( image = efi_file_find ( name ) ) != NULL )
+ return efi_file_open_image ( image, new );
+
/* Allow magic initrd to be opened */
if ( strcasecmp ( name, efi_file_initrd.file.name ) == 0 )
return efi_file_open_fixed ( &efi_file_initrd.file, new );
- /* Identify image */
- image = efi_file_find ( name );
- if ( ! image ) {
- DBGC ( file, "EFIFILE %s does not exist\n", name );
- return EFI_NOT_FOUND;
- }
-
- /* Allocate and initialise file */
- new_file = zalloc ( sizeof ( *new_file ) );
- if ( ! new_file )
- return EFI_OUT_OF_RESOURCES;
- ref_init ( &file->refcnt, efi_file_free );
- memcpy ( &new_file->file, &efi_file_root.file,
- sizeof ( new_file->file ) );
- memcpy ( &new_file->load, &efi_file_root.load,
- sizeof ( new_file->load ) );
- efi_file_image ( new_file, image_get ( image ) );
- *new = &new_file->file;
- DBGC ( new_file, "EFIFILE %s opened\n", efi_file_name ( new_file ) );
-
- return 0;
+ DBGC ( file, "EFIFILE %s does not exist\n", name );
+ return EFI_NOT_FOUND;
}
/**