boot: Use EFI_FILE* instead of EFI_FILE_HANDLE

They are both the same, but the former is shorter and also closer
to how file handles are represented in the UEFI spec.
This commit is contained in:
Jan Janssen
2022-01-13 14:26:43 +01:00
parent 41b74a18b2
commit 85eb489e23
10 changed files with 32 additions and 40 deletions
+11 -18
View 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;
+1 -1
View 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;
+2 -3
View 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;
+1 -1
View 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);
+2 -2
View 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;
+1 -1
View 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);
+1 -1
View 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;
+1 -1
View 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;
+7 -7
View 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;
+5 -5
View 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