]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: Drop use of LibOpenRoot
authorJan Janssen <medhefgo@web.de>
Thu, 26 May 2022 08:46:58 +0000 (10:46 +0200)
committerJan Janssen <medhefgo@web.de>
Thu, 9 Jun 2022 10:50:13 +0000 (12:50 +0200)
src/boot/efi/boot.c
src/boot/efi/shim.c
src/boot/efi/util.c
src/boot/efi/util.h
src/boot/efi/xbootldr.c

index 60e8786e3eed90bd56cd5ca8ceabfe574a0ccd9a..dd5dad71f322cbd9fd936858c88cf8c28a3835ec 100644 (file)
@@ -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();
index fb4aecaee0217ada87254dc279fa4bf14770ca4b..663eafbae41839690482231cb6e952c2ea8d8ee7 100644 (file)
@@ -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)
index 06859d2f3a3a22f987071b7ee80f8eec46fa6f19..7d607e04c7d9ff8004ca4568d0700b909f4707b4 100644 (file)
@@ -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;
+}
index 06c298d776df354fa0af65c3da9b58bf92d579ea..75d3e51415ebb6ee559fbad3bf40077b0c4285b3 100644 (file)
@@ -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);
index bc82768715f6de4c1240546814aa2bd75c3b3ea5..583bc4216fd8b5c813b6df1f9991521018c7159a 100644 (file)
@@ -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;