efi: move get_dropin_dir to util.c
authorLuca Boccassi <bluca@debian.org>
Thu, 11 May 2023 23:49:25 +0000 (00:49 +0100)
committerLuca Boccassi <bluca@debian.org>
Tue, 23 May 2023 22:22:51 +0000 (23:22 +0100)
Will be used elsewhere in a later commit. Rename to clarify that it
provides .extra.d/ directories.

src/boot/efi/cpio.c
src/boot/efi/util.c
src/boot/efi/util.h

index f82a31b47520455efb689c80f7f946c3bdf12bc0..bb3754a3bc7d9ab32256a84aee0e152a67e69696 100644 (file)
@@ -301,29 +301,6 @@ static EFI_STATUS pack_cpio_trailer(
         return EFI_SUCCESS;
 }
 
-static char16_t *get_dropin_dir(const EFI_DEVICE_PATH *file_path) {
-        if (!file_path)
-                return NULL;
-
-        /* A device path is allowed to have more than one file path node. If that is the case they are
-         * supposed to be concatenated. Unfortunately, the device path to text protocol simply converts the
-         * nodes individually and then combines those with the usual '/' for device path nodes. But this does
-         * not create a legal EFI file path that the file protocol can use. */
-
-        /* Make sure we really only got file paths. */
-        for (const EFI_DEVICE_PATH *node = file_path; !device_path_is_end(node);
-             node = device_path_next_node(node))
-                if (node->Type != MEDIA_DEVICE_PATH || node->SubType != MEDIA_FILEPATH_DP)
-                        return NULL;
-
-        _cleanup_free_ char16_t *file_path_str = NULL;
-        if (device_path_to_str(file_path, &file_path_str) != EFI_SUCCESS)
-                return NULL;
-
-        convert_efi_path(file_path_str);
-        return xasprintf("%ls.extra.d", file_path_str);
-}
-
 EFI_STATUS pack_cpio(
                 EFI_LOADED_IMAGE_PROTOCOL *loaded_image,
                 const char16_t *dropin_dir,
@@ -363,7 +340,7 @@ EFI_STATUS pack_cpio(
                 return log_error_status(err, "Unable to open root directory: %m");
 
         if (!dropin_dir)
-                dropin_dir = rel_dropin_dir = get_dropin_dir(loaded_image->FilePath);
+                dropin_dir = rel_dropin_dir = get_extra_dir(loaded_image->FilePath);
 
         err = open_directory(root, dropin_dir, &extra_dir);
         if (err == EFI_NOT_FOUND)
index c5f17424664adb67b1111e54f955026b81c75c94..d5a23338fe56f13e66551abd9baaf3a18dede079 100644 (file)
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+#include "device-path-util.h"
 #include "proto/device-path.h"
 #include "proto/simple-text-io.h"
 #include "ticks.h"
@@ -665,3 +666,26 @@ void *find_configuration_table(const EFI_GUID *guid) {
 
         return NULL;
 }
+
+char16_t *get_extra_dir(const EFI_DEVICE_PATH *file_path) {
+        if (!file_path)
+                return NULL;
+
+        /* A device path is allowed to have more than one file path node. If that is the case they are
+         * supposed to be concatenated. Unfortunately, the device path to text protocol simply converts the
+         * nodes individually and then combines those with the usual '/' for device path nodes. But this does
+         * not create a legal EFI file path that the file protocol can use. */
+
+        /* Make sure we really only got file paths. */
+        for (const EFI_DEVICE_PATH *node = file_path; !device_path_is_end(node);
+             node = device_path_next_node(node))
+                if (node->Type != MEDIA_DEVICE_PATH || node->SubType != MEDIA_FILEPATH_DP)
+                        return NULL;
+
+        _cleanup_free_ char16_t *file_path_str = NULL;
+        if (device_path_to_str(file_path, &file_path_str) != EFI_SUCCESS)
+                return NULL;
+
+        convert_efi_path(file_path_str);
+        return xasprintf("%ls.extra.d", file_path_str);
+}
index 929f3bca8c839677c83c6ed5e089b7b9d6b7b1d9..aadbbdad0d15d5de2555942fb040625dccbd996c 100644 (file)
@@ -212,3 +212,5 @@ static inline bool efi_guid_equal(const EFI_GUID *a, const EFI_GUID *b) {
 }
 
 void *find_configuration_table(const EFI_GUID *guid);
+
+char16_t *get_extra_dir(const EFI_DEVICE_PATH *file_path);