diff options
author | Jan Janssen <medhefgo@web.de> | 2023-01-07 11:58:14 +0100 |
---|---|---|
committer | Jan Janssen <medhefgo@web.de> | 2023-02-22 21:54:11 +0100 |
commit | 0b9266282176a969a2e8178570b7876751aa65b9 (patch) | |
tree | 54c5181b0bea3618b4438fe5832dea2c8ffbbe4f /src/boot | |
parent | d755ac62149110ee716f6a9f5da3161144c293af (diff) | |
download | systemd-0b9266282176a969a2e8178570b7876751aa65b9.tar.gz |
boot: Move more device path helpers to device-path-util.c
This also renames them to stay consistent with our naming style.
Diffstat (limited to 'src/boot')
-rw-r--r-- | src/boot/efi/cpio.c | 3 | ||||
-rw-r--r-- | src/boot/efi/device-path-util.c | 23 | ||||
-rw-r--r-- | src/boot/efi/device-path-util.h | 19 | ||||
-rw-r--r-- | src/boot/efi/part-discovery.c | 5 | ||||
-rw-r--r-- | src/boot/efi/proto/device-path.h | 17 |
5 files changed, 34 insertions, 33 deletions
diff --git a/src/boot/efi/cpio.c b/src/boot/efi/cpio.c index c53f19b25c..f82a31b475 100644 --- a/src/boot/efi/cpio.c +++ b/src/boot/efi/cpio.c @@ -311,7 +311,8 @@ static char16_t *get_dropin_dir(const EFI_DEVICE_PATH *file_path) { * 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; !IsDevicePathEnd(node); node = NextDevicePathNode(node)) + 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; diff --git a/src/boot/efi/device-path-util.c b/src/boot/efi/device-path-util.c index a693c3f296..c376d7a845 100644 --- a/src/boot/efi/device-path-util.c +++ b/src/boot/efi/device-path-util.c @@ -1,7 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include "device-path-util.h" -#include "proto/device-path.h" #include "util.h" EFI_STATUS make_file_device_path(EFI_HANDLE device, const char16_t *file, EFI_DEVICE_PATH **ret_dp) { @@ -16,8 +15,8 @@ EFI_STATUS make_file_device_path(EFI_HANDLE device, const char16_t *file, EFI_DE return err; EFI_DEVICE_PATH *end_node = dp; - while (!IsDevicePathEnd(end_node)) - end_node = NextDevicePathNode(end_node); + while (!device_path_is_end(end_node)) + end_node = device_path_next_node(end_node); size_t file_size = strsize16(file); size_t dp_size = (uint8_t *) end_node - (uint8_t *) dp; @@ -33,8 +32,8 @@ EFI_STATUS make_file_device_path(EFI_HANDLE device, const char16_t *file, EFI_DE dp->Length = sizeof(FILEPATH_DEVICE_PATH) + file_size; memcpy((uint8_t *) dp + sizeof(FILEPATH_DEVICE_PATH), file, file_size); - dp = NextDevicePathNode(dp); - SetDevicePathEndNode(dp); + dp = device_path_next_node(dp); + *dp = DEVICE_PATH_END_NODE; return EFI_SUCCESS; } @@ -52,8 +51,8 @@ EFI_STATUS device_path_to_str(const EFI_DEVICE_PATH *dp, char16_t **ret) { * to convert it ourselves if we are given filepath-only device path. */ size_t size = 0; - for (const EFI_DEVICE_PATH *node = dp; !IsDevicePathEnd(node); - node = NextDevicePathNode(node)) { + for (const EFI_DEVICE_PATH *node = dp; !device_path_is_end(node); + node = device_path_next_node(node)) { if (node->Type != MEDIA_DEVICE_PATH || node->SubType != MEDIA_FILEPATH_DP) return err; @@ -94,16 +93,16 @@ bool device_path_startswith(const EFI_DEVICE_PATH *dp, const EFI_DEVICE_PATH *st if (!dp) return false; for (;;) { - if (IsDevicePathEnd(start)) + if (device_path_is_end(start)) return true; - if (IsDevicePathEnd(dp)) + if (device_path_is_end(dp)) return false; if (start->Length != dp->Length) return false; if (memcmp(dp, start, start->Length) != 0) return false; - start = NextDevicePathNode(start); - dp = NextDevicePathNode(dp); + start = device_path_next_node(start); + dp = device_path_next_node(dp); } } @@ -123,6 +122,6 @@ EFI_DEVICE_PATH *device_path_replace_node( if (new_node) end = mempcpy(end, new_node, new_node->Length); - SetDevicePathEndNode(end); + *end = DEVICE_PATH_END_NODE; return ret; } diff --git a/src/boot/efi/device-path-util.h b/src/boot/efi/device-path-util.h index acc6ed0b74..08f1a9c216 100644 --- a/src/boot/efi/device-path-util.h +++ b/src/boot/efi/device-path-util.h @@ -1,10 +1,27 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "efi.h" +#include "proto/device-path.h" EFI_STATUS make_file_device_path(EFI_HANDLE device, const char16_t *file, EFI_DEVICE_PATH **ret_dp); EFI_STATUS device_path_to_str(const EFI_DEVICE_PATH *dp, char16_t **ret); bool device_path_startswith(const EFI_DEVICE_PATH *dp, const EFI_DEVICE_PATH *start); EFI_DEVICE_PATH *device_path_replace_node( const EFI_DEVICE_PATH *path, const EFI_DEVICE_PATH *node, const EFI_DEVICE_PATH *new_node); + +static inline EFI_DEVICE_PATH *device_path_next_node(const EFI_DEVICE_PATH *dp) { + assert(dp); + return (EFI_DEVICE_PATH *) ((uint8_t *) dp + dp->Length); +} + +static inline bool device_path_is_end(const EFI_DEVICE_PATH *dp) { + assert(dp); + return dp->Type == END_DEVICE_PATH_TYPE && dp->SubType == END_ENTIRE_DEVICE_PATH_SUBTYPE; +} + +#define DEVICE_PATH_END_NODE \ + (EFI_DEVICE_PATH) { \ + .Type = END_DEVICE_PATH_TYPE, \ + .SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE, \ + .Length = sizeof(EFI_DEVICE_PATH) \ + } diff --git a/src/boot/efi/part-discovery.c b/src/boot/efi/part-discovery.c index 2524eb6fd0..68dcf88872 100644 --- a/src/boot/efi/part-discovery.c +++ b/src/boot/efi/part-discovery.c @@ -165,7 +165,8 @@ static EFI_STATUS find_device(const EFI_GUID *type, EFI_HANDLE *device, EFI_DEVI /* Find the (last) partition node itself. */ EFI_DEVICE_PATH *part_node = NULL; - for (EFI_DEVICE_PATH *node = partition_path; !IsDevicePathEnd(node); node = NextDevicePathNode(node)) { + for (EFI_DEVICE_PATH *node = partition_path; !device_path_is_end(node); + node = device_path_next_node(node)) { if (node->Type != MEDIA_DEVICE_PATH || node->SubType != MEDIA_HARDDRIVE_DP) continue; @@ -282,7 +283,7 @@ char16_t *disk_get_part_uuid(EFI_HANDLE *handle) { if (err != EFI_SUCCESS) return NULL; - for (; !IsDevicePathEnd(dp); dp = NextDevicePathNode(dp)) { + for (; !device_path_is_end(dp); dp = device_path_next_node(dp)) { if (dp->Type != MEDIA_DEVICE_PATH || dp->SubType != MEDIA_HARDDRIVE_DP) continue; diff --git a/src/boot/efi/proto/device-path.h b/src/boot/efi/proto/device-path.h index f6583b3697..df7a6a08f9 100644 --- a/src/boot/efi/proto/device-path.h +++ b/src/boot/efi/proto/device-path.h @@ -81,20 +81,3 @@ typedef struct { EFI_DEVICE_PATH* (EFIAPI *ConvertTextToDevicPath)( const char16_t *ConvertTextToDevicPath); } EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL; - -static inline EFI_DEVICE_PATH *NextDevicePathNode(const EFI_DEVICE_PATH *dp) { - assert(dp); - return (EFI_DEVICE_PATH *) ((uint8_t *) dp + dp->Length); -} - -static inline bool IsDevicePathEnd(const EFI_DEVICE_PATH *dp) { - assert(dp); - return dp->Type == END_DEVICE_PATH_TYPE && dp->SubType == END_ENTIRE_DEVICE_PATH_SUBTYPE; -} - -static inline void SetDevicePathEndNode(EFI_DEVICE_PATH *dp) { - assert(dp); - dp->Type = END_DEVICE_PATH_TYPE; - dp->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE; - dp->Length = sizeof(EFI_DEVICE_PATH); -} |