From 5320ef6adfa7699a06b7c1e2836ae1509a3c669c Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Sun, 26 Nov 2017 16:12:10 +0000 Subject: [PATCH] Add efidp_format_device_path_node to format a single node in a device path, much like efidp_format_device_path will format the entire path. Sponsored by: Netflix --- lib/libefivar/efivar-dp-format.c | 26 ++++++++++++++++++++++---- lib/libefivar/efivar-dp.h | 2 ++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/libefivar/efivar-dp-format.c b/lib/libefivar/efivar-dp-format.c index ca122ef63c3..a04642fa6c8 100644 --- a/lib/libefivar/efivar-dp-format.c +++ b/lib/libefivar/efivar-dp-format.c @@ -2272,7 +2272,6 @@ static const DEVICE_PATH_TO_TEXT_TABLE mUefiDevicePathLibToTextTable[] = { {0, 0, NULL} }; -#ifndef __FreeBSD__ /** Converts a device node to its string representation. @@ -2288,7 +2287,7 @@ static const DEVICE_PATH_TO_TEXT_TABLE mUefiDevicePathLibToTextTable[] = { is NULL or there was insufficient memory. **/ -CHAR16 * +static char * EFIAPI UefiDevicePathLibConvertDeviceNodeToText ( IN CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode, @@ -2299,6 +2298,7 @@ UefiDevicePathLibConvertDeviceNodeToText ( POOL_PRINT Str; UINTN Index; DEVICE_PATH_TO_TEXT ToText; + EFI_DEVICE_PATH_PROTOCOL *Node; if (DeviceNode == NULL) { return NULL; @@ -2310,6 +2310,7 @@ UefiDevicePathLibConvertDeviceNodeToText ( // Process the device path node // If not found, use a generic function // + Node = __DECONST(EFI_DEVICE_PATH_PROTOCOL *, DeviceNode); ToText = DevPathToTextNodeGeneric; for (Index = 0; mUefiDevicePathLibToTextTable[Index].Function != NULL; Index++) { if (DevicePathType (DeviceNode) == mUefiDevicePathLibToTextTable[Index].Type && @@ -2323,12 +2324,11 @@ UefiDevicePathLibConvertDeviceNodeToText ( // // Print this node // - ToText (&Str, (VOID *) DeviceNode, DisplayOnly, AllowShortcuts); + ToText (&Str, (VOID *) Node, DisplayOnly, AllowShortcuts); ASSERT (Str.Str != NULL); return Str.Str; } -#endif /** Converts a device path to its text representation. @@ -2431,8 +2431,26 @@ efidp_format_device_path(char *buf, size_t len, const_efidp dp, ssize_t max) return retval; } +ssize_t +efidp_format_device_path_node(char *buf, size_t len, const_efidp dp, ssize_t max) +{ + char *str; + ssize_t retval; + + str = UefiDevicePathLibConvertDeviceNodeToText ( + __DECONST(EFI_DEVICE_PATH_PROTOCOL *, dp), FALSE, TRUE); + if (str == NULL) + return -1; + strlcpy(buf, str, len); + retval = strlen(str); + free(str); + + return retval; +} + size_t efidp_size(const_efidp dp) { + return GetDevicePathSize(__DECONST(EFI_DEVICE_PATH_PROTOCOL *, dp)); } diff --git a/lib/libefivar/efivar-dp.h b/lib/libefivar/efivar-dp.h index f620a67550a..46771850df2 100644 --- a/lib/libefivar/efivar-dp.h +++ b/lib/libefivar/efivar-dp.h @@ -60,6 +60,8 @@ typedef const efidp_data *const_efidp; */ ssize_t efidp_format_device_path(char *buf, size_t len, const_efidp dp, ssize_t max); +ssize_t efidp_format_device_path_node(char *buf, size_t len, const_efidp dp, + ssize_t max); ssize_t efidp_parse_device_path(char *path, efidp out, size_t max); size_t efidp_size(const_efidp);