boot: Use EFI_FILE* instead of EFI_FILE_HANDLE
authorJan Janssen <medhefgo@web.de>
Thu, 13 Jan 2022 11:34:35 +0000 (12:34 +0100)
committerJan Janssen <medhefgo@web.de>
Thu, 13 Jan 2022 13:26:43 +0000 (14:26 +0100)
They are both the same, but the former is shorter and also closer
to how file handles are represented in the UEFI spec.

src/boot/efi/boot.c
src/boot/efi/cpio.c
src/boot/efi/devicetree.c
src/boot/efi/devicetree.h
src/boot/efi/drivers.c
src/boot/efi/drivers.h
src/boot/efi/pe.c
src/boot/efi/random-seed.c
src/boot/efi/util.c
src/boot/efi/util.h

index 96a41bbb50621abe426dc99de86cd2e48c46f6df..ce901e7cb68b95dc9ab7b77b42e582c1ffc32e48 100644 (file)
@@ -1309,12 +1309,9 @@ good:
         entry->next_name = xpool_print(L"%s+%u-%u%s", prefix, next_left, next_done, suffix ?: L"");
 }
 
-static void config_entry_bump_counters(
-                ConfigEntry *entry,
-                EFI_FILE_HANDLE root_dir) {
-
+static void config_entry_bump_counters(ConfigEntry *entry, EFI_FILE *root_dir) {
         _cleanup_freepool_ CHAR16* old_path = NULL, *new_path = NULL;
-        _cleanup_(file_handle_closep) EFI_FILE_HANDLE handle = NULL;
+        _cleanup_(file_closep) EFI_FILE *handle = NULL;
         _cleanup_freepool_ EFI_FILE_INFO *file_info = NULL;
         UINTN file_info_size;
         EFI_STATUS err;
@@ -1375,7 +1372,6 @@ static void config_entry_add_from_file(
         UINTN pos = 0;
         CHAR8 *key, *value;
         EFI_STATUS err;
-        EFI_FILE_HANDLE handle;
         _cleanup_freepool_ CHAR16 *initrd = NULL;
 
         assert(config);
@@ -1483,10 +1479,10 @@ static void config_entry_add_from_file(
                 return;
 
         /* check existence */
+        _cleanup_(file_closep) EFI_FILE *handle = NULL;
         err = root_dir->Open(root_dir, &handle, entry->loader, EFI_FILE_MODE_READ, 0ULL);
         if (EFI_ERROR(err))
                 return;
-        handle->Close(handle);
 
         /* add initrd= to options */
         if (entry->type == LOADER_LINUX && initrd) {
@@ -1571,7 +1567,7 @@ static void config_load_entries(
                 EFI_FILE *root_dir,
                 const CHAR16 *loaded_image_path) {
 
-        _cleanup_(file_handle_closep) EFI_FILE_HANDLE entries_dir = NULL;
+        _cleanup_(file_closep) EFI_FILE *entries_dir = NULL;
         _cleanup_freepool_ EFI_FILE_INFO *f = NULL;
         UINTN f_size = 0;
         EFI_STATUS err;
@@ -1888,9 +1884,6 @@ static ConfigEntry *config_entry_add_loader_auto(
                 const CHAR16 *title,
                 const CHAR16 *loader) {
 
-        EFI_FILE_HANDLE handle;
-        EFI_STATUS err;
-
         assert(config);
         assert(device);
         assert(root_dir);
@@ -1916,10 +1909,10 @@ static ConfigEntry *config_entry_add_loader_auto(
         }
 
         /* check existence */
-        err = root_dir->Open(root_dir, &handle, (CHAR16*) loader, EFI_FILE_MODE_READ, 0ULL);
+        _cleanup_(file_closep) EFI_FILE *handle = NULL;
+        EFI_STATUS err = root_dir->Open(root_dir, &handle, (CHAR16*) loader, EFI_FILE_MODE_READ, 0ULL);
         if (EFI_ERROR(err))
                 return NULL;
-        handle->Close(handle);
 
         return config_entry_add_loader(config, device, LOADER_AUTO, id, key, title, loader, NULL);
 }
@@ -1939,7 +1932,7 @@ static void config_entry_add_osx(Config *config) {
                 return;
 
         for (UINTN i = 0; i < n_handles; i++) {
-                _cleanup_(file_handle_closep) EFI_FILE *root = LibOpenRoot(handles[i]);
+                _cleanup_(file_closep) EFI_FILE *root = LibOpenRoot(handles[i]);
                 if (!root)
                         continue;
 
@@ -2066,7 +2059,7 @@ static void config_entry_add_linux(
                 EFI_HANDLE *device,
                 EFI_FILE *root_dir) {
 
-        _cleanup_(file_handle_closep) EFI_FILE_HANDLE linux_dir = NULL;
+        _cleanup_(file_closep) EFI_FILE *linux_dir = NULL;
         _cleanup_freepool_ EFI_FILE_INFO *f = NULL;
         ConfigEntry *entry;
         UINTN f_size = 0;
@@ -2224,7 +2217,7 @@ static void config_load_xbootldr(
                 Config *config,
                 EFI_HANDLE *device) {
 
-        _cleanup_(file_handle_closep) EFI_FILE *root_dir = NULL;
+        _cleanup_(file_closep) EFI_FILE *root_dir = NULL;
         EFI_HANDLE new_device;
         EFI_STATUS err;
 
@@ -2240,7 +2233,7 @@ static void config_load_xbootldr(
 }
 
 static EFI_STATUS image_start(
-                EFI_FILE_HANDLE root_dir,
+                EFI_FILE *root_dir,
                 EFI_HANDLE parent_image,
                 const Config *config,
                 const ConfigEntry *entry) {
@@ -2456,7 +2449,7 @@ static void config_load_all_entries(
 
 EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
         _cleanup_freepool_ EFI_LOADED_IMAGE *loaded_image = NULL;
-        _cleanup_(file_handle_closep) EFI_FILE *root_dir = NULL;
+        _cleanup_(file_closep) EFI_FILE *root_dir = NULL;
         _cleanup_(config_free) Config config = {};
         CHAR16 *loaded_image_path;
         EFI_STATUS err;
index 924ac35939b5c62f5e61ca5d5e29243f52a5c934..258755366ed735c6c5365d1a5d430a58d7fb0982 100644 (file)
@@ -316,7 +316,7 @@ EFI_STATUS pack_cpio(
                 void **ret_buffer,
                 UINTN *ret_buffer_size) {
 
-        _cleanup_(file_handle_closep) EFI_FILE_HANDLE root = NULL, extra_dir = NULL;
+        _cleanup_(file_closep) EFI_FILE *root = NULL, *extra_dir = NULL;
         UINTN dirent_size = 0, buffer_size = 0, n_items = 0, n_allocated = 0;
         _cleanup_freepool_ CHAR16 *rel_dropin_dir = NULL;
         _cleanup_freepool_ EFI_FILE_INFO *dirent = NULL;
index 476843bbce646da096eb6eb15fe879e9a524ad70..b8ba52a52357a810ab013ada8bb0f0aaea697374 100644 (file)
@@ -64,9 +64,8 @@ static EFI_STATUS devicetree_fixup(struct devicetree_state *state, UINTN len) {
         return err;
 }
 
-EFI_STATUS devicetree_install(struct devicetree_state *state,
-                EFI_FILE_HANDLE root_dir, CHAR16 *name) {
-        _cleanup_(file_handle_closep) EFI_FILE_HANDLE handle = NULL;
+EFI_STATUS devicetree_install(struct devicetree_state *state, EFI_FILE *root_dir, CHAR16 *name) {
+        _cleanup_(file_closep) EFI_FILE *handle = NULL;
         _cleanup_freepool_ EFI_FILE_INFO *info = NULL;
         UINTN len;
         EFI_STATUS err;
index fa8a1be6eda3af23c145150a4e6863e41f707cc4..71ce1050284a9e4d8e58a12f01aa0fb2d22f825d 100644 (file)
@@ -7,7 +7,7 @@ struct devicetree_state {
         void *orig;
 };
 
-EFI_STATUS devicetree_install(struct devicetree_state *state, EFI_FILE_HANDLE root_dir, CHAR16 *name);
+EFI_STATUS devicetree_install(struct devicetree_state *state, EFI_FILE *root_dir, CHAR16 *name);
 EFI_STATUS devicetree_install_from_memory(
                 struct devicetree_state *state, const VOID *dtb_buffer, UINTN dtb_length);
 void devicetree_cleanup(struct devicetree_state *state);
index 851203e694d3342943270a72187cded96812e754..55dd0eb33e0d730d489295986ec8516fae51b6cf 100644 (file)
@@ -80,9 +80,9 @@ static EFI_STATUS reconnect(void) {
 EFI_STATUS load_drivers(
                 EFI_HANDLE parent_image,
                 EFI_LOADED_IMAGE *loaded_image,
-                EFI_FILE_HANDLE root_dir) {
+                EFI_FILE *root_dir) {
 
-        _cleanup_(file_handle_closep) EFI_FILE_HANDLE drivers_dir = NULL;
+        _cleanup_(file_closep) EFI_FILE *drivers_dir = NULL;
         _cleanup_freepool_ EFI_FILE_INFO *dirent = NULL;
         UINTN dirent_size = 0, n_succeeded = 0;
         EFI_STATUS err;
index c192c6d44c9ab5900c023fe0442efd66a22b16c1..242aedcdd7838217fdc569ebade67f50c6371c91 100644 (file)
@@ -6,4 +6,4 @@
 EFI_STATUS load_drivers(
                 EFI_HANDLE parent_image,
                 EFI_LOADED_IMAGE *loaded_image,
-                EFI_FILE_HANDLE root_dir);
+                EFI_FILE *root_dir);
index 2fc38f7b36626a66eb9d0f6e0d0ac7a6911e6db6..e16716498ff90490e42bb6d69bfd29f4ae862824 100644 (file)
@@ -224,7 +224,7 @@ EFI_STATUS pe_file_locate_sections(
                 UINTN *offsets,
                 UINTN *sizes) {
         _cleanup_freepool_ struct PeSectionHeader *section_table = NULL;
-        _cleanup_(file_handle_closep) EFI_FILE_HANDLE handle = NULL;
+        _cleanup_(file_closep) EFI_FILE *handle = NULL;
         struct DosFileHeader dos;
         struct PeFileHeader pe;
         UINTN len, section_table_len;
index 9d8e34d1ee68340351922f71b50a3e21a9e1adfd..b007f41f7e9feef42d0859c17ee9837646675085 100644 (file)
@@ -225,7 +225,7 @@ static void validate_sha256(void) {
 
 EFI_STATUS process_random_seed(EFI_FILE *root_dir, RandomSeedMode mode) {
         _cleanup_freepool_ void *seed = NULL, *new_seed = NULL, *rng = NULL, *for_kernel = NULL, *system_token = NULL;
-        _cleanup_(file_handle_closep) EFI_FILE_HANDLE handle = NULL;
+        _cleanup_(file_closep) EFI_FILE *handle = NULL;
         UINTN size, rsize, wsize, system_token_size = 0;
         _cleanup_freepool_ EFI_FILE_INFO *info = NULL;
         EFI_STATUS err;
index db998ca8da99c0907dc4bb17adeb1b16b077b9b8..4fac6d3eee8d1df25061dfba7d11b5a4a8964ddf 100644 (file)
@@ -435,8 +435,8 @@ CHAR8 *strchra(const CHAR8 *s, CHAR8 c) {
         return NULL;
 }
 
-EFI_STATUS file_read(EFI_FILE_HANDLE dir, const CHAR16 *name, UINTN off, UINTN size, CHAR8 **ret, UINTN *ret_size) {
-        _cleanup_(file_handle_closep) EFI_FILE_HANDLE handle = NULL;
+EFI_STATUS file_read(EFI_FILE *dir, const CHAR16 *name, UINTN off, UINTN size, CHAR8 **ret, UINTN *ret_size) {
+        _cleanup_(file_closep) EFI_FILE *handle = NULL;
         _cleanup_freepool_ CHAR8 *buf = NULL;
         EFI_STATUS err;
 
@@ -544,7 +544,7 @@ void sort_pointer_array(
 }
 
 EFI_STATUS get_file_info_harder(
-                EFI_FILE_HANDLE handle,
+                EFI_FILE *handle,
                 EFI_FILE_INFO **ret,
                 UINTN *ret_size) {
 
@@ -577,7 +577,7 @@ EFI_STATUS get_file_info_harder(
 }
 
 EFI_STATUS readdir_harder(
-                EFI_FILE_HANDLE handle,
+                EFI_FILE *handle,
                 EFI_FILE_INFO **buffer,
                 UINTN *buffer_size) {
 
@@ -700,11 +700,11 @@ CHAR16 **strv_free(CHAR16 **v) {
 }
 
 EFI_STATUS open_directory(
-                EFI_FILE_HANDLE root,
+                EFI_FILE *root,
                 const CHAR16 *path,
-                EFI_FILE_HANDLE *ret) {
+                EFI_FILE **ret) {
 
-        _cleanup_(file_handle_closep) EFI_FILE_HANDLE dir = NULL;
+        _cleanup_(file_closep) EFI_FILE *dir = NULL;
         _cleanup_freepool_ EFI_FILE_INFO *file_info = NULL;
         EFI_STATUS err;
 
index 58ca44443da656b0c0d049a96236e2b373af1615..0c477fccf13daaab8dd3c724fb1cd4da863fb7f6 100644 (file)
@@ -71,7 +71,7 @@ CHAR8 *strchra(const CHAR8 *s, CHAR8 c);
 CHAR16 *xstra_to_path(const CHAR8 *stra);
 CHAR16 *xstra_to_str(const CHAR8 *stra);
 
-EFI_STATUS file_read(EFI_FILE_HANDLE dir, const CHAR16 *name, UINTN off, UINTN size, CHAR8 **content, UINTN *content_size);
+EFI_STATUS file_read(EFI_FILE *dir, const CHAR16 *name, UINTN off, UINTN size, CHAR8 **content, UINTN *content_size);
 
 static inline void free_poolp(void *p) {
         void *q = *(void**) p;
@@ -84,7 +84,7 @@ static inline void free_poolp(void *p) {
 
 #define _cleanup_freepool_ _cleanup_(free_poolp)
 
-static inline void file_handle_closep(EFI_FILE_HANDLE *handle) {
+static inline void file_closep(EFI_FILE **handle) {
         if (!*handle)
                 return;
 
@@ -117,9 +117,9 @@ void clear_screen(UINTN attr);
 typedef INTN (*compare_pointer_func_t)(const void *a, const void *b);
 void sort_pointer_array(void **array, UINTN n_members, compare_pointer_func_t compare);
 
-EFI_STATUS get_file_info_harder(EFI_FILE_HANDLE handle, EFI_FILE_INFO **ret, UINTN *ret_size);
+EFI_STATUS get_file_info_harder(EFI_FILE *handle, EFI_FILE_INFO **ret, UINTN *ret_size);
 
-EFI_STATUS readdir_harder(EFI_FILE_HANDLE handle, EFI_FILE_INFO **buffer, UINTN *buffer_size);
+EFI_STATUS readdir_harder(EFI_FILE *handle, EFI_FILE_INFO **buffer, UINTN *buffer_size);
 
 UINTN strnlena(const CHAR8 *p, UINTN maxlen);
 CHAR8 *xstrndup8(const CHAR8 *p, UINTN sz);
@@ -136,7 +136,7 @@ static inline void strv_freep(CHAR16 ***p) {
         strv_free(*p);
 }
 
-EFI_STATUS open_directory(EFI_FILE_HANDLE root_dir, const CHAR16 *path, EFI_FILE_HANDLE *ret);
+EFI_STATUS open_directory(EFI_FILE *root_dir, const CHAR16 *path, EFI_FILE **ret);
 
 /* Conversion between EFI_PHYSICAL_ADDRESS and pointers is not obvious. The former is always 64bit, even on
  * 32bit archs. And gcc complains if we cast a pointer to an integer of a different size. Hence let's do the