From: Jan Janssen Date: Thu, 26 May 2022 08:46:58 +0000 (+0200) Subject: boot: Drop use of LibOpenRoot X-Git-Tag: v252-rc1~835^2~9 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f747ca3ec3bdbdc55aecb5803dbd9f65bc0cd169;p=thirdparty%2Fsystemd.git boot: Drop use of LibOpenRoot --- diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c index 60e8786e3ee..dd5dad71f32 100644 --- a/src/boot/efi/boot.c +++ b/src/boot/efi/boot.c @@ -1947,8 +1947,9 @@ static void config_entry_add_osx(Config *config) { return; for (UINTN i = 0; i < n_handles; i++) { - _cleanup_(file_closep) EFI_FILE *root = LibOpenRoot(handles[i]); - if (!root) + _cleanup_(file_closep) EFI_FILE *root = NULL; + + if (open_volume(handles[i], &root) != EFI_SUCCESS) continue; if (config_entry_add_loader_auto( @@ -2249,7 +2250,7 @@ static void config_load_xbootldr( assert(device); err = xbootldr_open(device, &new_device, &root_dir); - if (EFI_ERROR(err)) + if (err != EFI_SUCCESS) return; config_entry_add_unified(config, new_device, root_dir); @@ -2344,9 +2345,10 @@ static EFI_STATUS image_start( if (entry->call) (void) entry->call(); - _cleanup_(file_closep) EFI_FILE *image_root = LibOpenRoot(entry->device); - if (!image_root) - return log_error_status_stall(EFI_DEVICE_ERROR, L"Error opening root path."); + _cleanup_(file_closep) EFI_FILE *image_root = NULL; + err = open_volume(entry->device, &image_root); + if (err != EFI_SUCCESS) + return log_error_status_stall(err, L"Error opening root path: %r", err); path = FileDevicePath(entry->device, entry->loader); if (!path) @@ -2602,9 +2604,9 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) { export_variables(loaded_image, loaded_image_path, init_usec); - root_dir = LibOpenRoot(loaded_image->DeviceHandle); - if (!root_dir) - return log_error_status_stall(EFI_LOAD_ERROR, L"Unable to open root directory.", EFI_LOAD_ERROR); + err = open_volume(loaded_image->DeviceHandle, &root_dir); + if (err != EFI_SUCCESS) + return log_error_status_stall(err, L"Unable to open root directory: %r", err); if (secure_boot_enabled() && shim_loaded()) { err = security_policy_install(); diff --git a/src/boot/efi/shim.c b/src/boot/efi/shim.c index fb4aecaee02..663eafbae41 100644 --- a/src/boot/efi/shim.c +++ b/src/boot/efi/shim.c @@ -122,9 +122,10 @@ static EFIAPI EFI_STATUS security_policy_authentication (const EFI_SECURITY_PROT if (EFI_ERROR(status)) return status; - _cleanup_(file_closep) EFI_FILE *root = LibOpenRoot(h); - if (!root) - return EFI_NOT_FOUND; + _cleanup_(file_closep) EFI_FILE *root = NULL; + status = open_volume(h, &root); + if (status != EFI_SUCCESS) + return status; dev_path_str = DevicePathToStr(dp); if (!dev_path_str) diff --git a/src/boot/efi/util.c b/src/boot/efi/util.c index 06859d2f3a3..7d607e04c7d 100644 --- a/src/boot/efi/util.c +++ b/src/boot/efi/util.c @@ -682,3 +682,22 @@ void beep(UINTN beep_count) { } } #endif + +EFI_STATUS open_volume(EFI_HANDLE device, EFI_FILE **ret_file) { + EFI_STATUS err; + EFI_FILE *file; + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *volume; + + assert(ret_file); + + err = BS->HandleProtocol(device, &FileSystemProtocol, (void **) &volume); + if (err != EFI_SUCCESS) + return err; + + err = volume->OpenVolume(volume, &file); + if (err != EFI_SUCCESS) + return err; + + *ret_file = file; + return EFI_SUCCESS; +} diff --git a/src/boot/efi/util.h b/src/boot/efi/util.h index 06c298d776d..75d3e51415e 100644 --- a/src/boot/efi/util.h +++ b/src/boot/efi/util.h @@ -165,3 +165,5 @@ void beep(UINTN beep_count); #else static inline void beep(UINTN beep_count) {} #endif + +EFI_STATUS open_volume(EFI_HANDLE device, EFI_FILE **ret_file); diff --git a/src/boot/efi/xbootldr.c b/src/boot/efi/xbootldr.c index bc82768715f..583bc4216fd 100644 --- a/src/boot/efi/xbootldr.c +++ b/src/boot/efi/xbootldr.c @@ -247,17 +247,17 @@ EFI_STATUS xbootldr_open(EFI_HANDLE *device, EFI_HANDLE *ret_device, EFI_FILE ** assert(ret_root_dir); err = find_device(device, &partition_path); - if (EFI_ERROR(err)) + if (err != EFI_SUCCESS) return err; EFI_DEVICE_PATH *dp = partition_path; err = BS->LocateDevicePath(&BlockIoProtocol, &dp, &new_device); - if (EFI_ERROR(err)) + if (err != EFI_SUCCESS) return err; - root_dir = LibOpenRoot(new_device); - if (!root_dir) - return EFI_NOT_FOUND; + err = open_volume(new_device, &root_dir); + if (err != EFI_SUCCESS) + return err; *ret_device = new_device; *ret_root_dir = root_dir;