This also renames them to stay consistent with our naming style.
* 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;
/* 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) {
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;
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;
}
* 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;
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);
}
}
if (new_node)
end = mempcpy(end, new_node, new_node->Length);
- SetDevicePathEndNode(end);
+ *end = DEVICE_PATH_END_NODE;
return ret;
}
/* 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) \
+ }
/* 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;
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;
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);
-}