From: Luca Boccassi Date: Thu, 11 May 2023 23:49:25 +0000 (+0100) Subject: efi: move get_dropin_dir to util.c X-Git-Tag: v254-rc1~382^2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3e8cb05e1263d684cdc315e32e933e5895bd6257;p=thirdparty%2Fsystemd.git efi: move get_dropin_dir to util.c Will be used elsewhere in a later commit. Rename to clarify that it provides .extra.d/ directories. --- diff --git a/src/boot/efi/cpio.c b/src/boot/efi/cpio.c index f82a31b4752..bb3754a3bc7 100644 --- a/src/boot/efi/cpio.c +++ b/src/boot/efi/cpio.c @@ -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) diff --git a/src/boot/efi/util.c b/src/boot/efi/util.c index c5f17424664..d5a23338fe5 100644 --- a/src/boot/efi/util.c +++ b/src/boot/efi/util.c @@ -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); +} diff --git a/src/boot/efi/util.h b/src/boot/efi/util.h index 929f3bca8c8..aadbbdad0d1 100644 --- a/src/boot/efi/util.h +++ b/src/boot/efi/util.h @@ -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);