boot: Move more device path helpers to device-path-util.c
This also renames them to stay consistent with our naming style.
This commit is contained in:
+2
-1
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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) \
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user