]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: Move more device path helpers to device-path-util.c
authorJan Janssen <medhefgo@web.de>
Sat, 7 Jan 2023 10:58:14 +0000 (11:58 +0100)
committerJan Janssen <medhefgo@web.de>
Wed, 22 Feb 2023 20:54:11 +0000 (21:54 +0100)
This also renames them to stay consistent with our naming style.

src/boot/efi/cpio.c
src/boot/efi/device-path-util.c
src/boot/efi/device-path-util.h
src/boot/efi/part-discovery.c
src/boot/efi/proto/device-path.h

index c53f19b25c32b7de502ff53e1e31c681bfa714a4..f82a31b47520455efb689c80f7f946c3bdf12bc0 100644 (file)
@@ -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;
 
index a693c3f2962fe47f04edb54be915eb10a31c2148..c376d7a845d5289d9944d7b4539d1582434c6042 100644 (file)
@@ -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;
 }
index acc6ed0b74c5fcb77e9aa1e0f9c85467fb9c938e..08f1a9c216754056fecedb0f1c2f334f05d46b43 100644 (file)
@@ -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)          \
+        }
index 2524eb6fd0e49790205a149e72d6038f3cc2dbe2..68dcf888720ffe947731c01e7c13b6447c896239 100644 (file)
@@ -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;
 
index f6583b3697d0d9bb1d03c2cc9e5fd0b3730879a8..df7a6a08f9ca37d00355501e55848224bac1bd21 100644 (file)
@@ -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);
-}