/** @file\r
- UEFI Device Path Library.\r
+ Library instance that implement UEFI Device Path Library class based on protocol\r
+ gEfiDevicePathUtilitiesProtocolGuid.\r
\r
- Copyright (c) 2006, Intel Corporation<BR>\r
- All rights reserved. This program and the accompanying materials\r
- are licensed and made available under the terms and conditions of the BSD License\r
- which accompanies this distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php\r
-\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
- Module Name: UefiDevicePathLib.c\r
+ Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
-STATIC EFI_DEVICE_PATH_UTILITIES_PROTOCOL *mDevicePathUtilities = NULL;\r
+#include <Uefi.h>\r
+\r
+#include <Protocol/DevicePathUtilities.h>\r
+#include <Protocol/DevicePathToText.h>\r
+#include <Protocol/DevicePathFromText.h>\r
+\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/PcdLib.h>\r
+\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_UTILITIES_PROTOCOL *mDevicePathLibDevicePathUtilities = NULL;\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *mDevicePathLibDevicePathToText = NULL;\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL *mDevicePathLibDevicePathFromText = NULL;\r
+\r
+//\r
+// Template for an end-of-device path node.\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_DEVICE_PATH_PROTOCOL mUefiDevicePathLibEndDevicePath = {\r
+ END_DEVICE_PATH_TYPE,\r
+ END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
+ {\r
+ END_DEVICE_PATH_LENGTH,\r
+ 0\r
+ }\r
+};\r
\r
/**\r
The constructor function caches the pointer to DevicePathUtilites protocol.\r
- \r
+\r
The constructor function locates DevicePathUtilities protocol from protocol database.\r
- It will ASSERT() if that operation fails and it will always return EFI_SUCCESS. \r
+ It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.\r
\r
@param ImageHandle The firmware allocated handle for the EFI image.\r
@param SystemTable A pointer to the EFI System Table.\r
- \r
+\r
@retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
\r
**/\r
EFI_STATUS\r
EFIAPI\r
DevicePathLibConstructor (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
)\r
{\r
- EFI_STATUS Status;\r
+ EFI_STATUS Status;\r
\r
Status = gBS->LocateProtocol (\r
&gEfiDevicePathUtilitiesProtocolGuid,\r
NULL,\r
- (VOID**) &mDevicePathUtilities\r
+ (VOID **)&mDevicePathLibDevicePathUtilities\r
);\r
ASSERT_EFI_ERROR (Status);\r
- ASSERT (mDevicePathUtilities != NULL);\r
-\r
+ ASSERT (mDevicePathLibDevicePathUtilities != NULL);\r
return Status;\r
}\r
\r
/**\r
- This function returns the size, in bytes, \r
- of the device path data structure specified by DevicePath.\r
- If DevicePath is NULL, then 0 is returned.\r
+ Determine whether a given device path is valid.\r
+ If DevicePath is NULL, then ASSERT().\r
+\r
+ @param DevicePath A pointer to a device path data structure.\r
+ @param MaxSize The maximum size of the device path data structure.\r
+\r
+ @retval TRUE DevicePath is valid.\r
+ @retval FALSE The length of any node node in the DevicePath is less\r
+ than sizeof (EFI_DEVICE_PATH_PROTOCOL).\r
+ @retval FALSE If MaxSize is not zero, the size of the DevicePath\r
+ exceeds MaxSize.\r
+ @retval FALSE If PcdMaximumDevicePathNodeCount is not zero, the node\r
+ count of the DevicePath exceeds PcdMaximumDevicePathNodeCount.\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+IsDevicePathValid (\r
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
+ IN UINTN MaxSize\r
+ )\r
+{\r
+ UINTN Count;\r
+ UINTN Size;\r
+ UINTN NodeLength;\r
+\r
+ ASSERT (DevicePath != NULL);\r
+\r
+ if (MaxSize == 0) {\r
+ MaxSize = MAX_UINTN;\r
+ }\r
+\r
+ //\r
+ // Validate the input size big enough to touch the first node.\r
+ //\r
+ if (MaxSize < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {\r
+ return FALSE;\r
+ }\r
+\r
+ for (Count = 0, Size = 0; !IsDevicePathEnd (DevicePath); DevicePath = NextDevicePathNode (DevicePath)) {\r
+ NodeLength = DevicePathNodeLength (DevicePath);\r
+ if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {\r
+ return FALSE;\r
+ }\r
+\r
+ if (NodeLength > MAX_UINTN - Size) {\r
+ return FALSE;\r
+ }\r
+\r
+ Size += NodeLength;\r
+\r
+ //\r
+ // Validate next node before touch it.\r
+ //\r
+ if (Size > MaxSize - END_DEVICE_PATH_LENGTH ) {\r
+ return FALSE;\r
+ }\r
+\r
+ if (PcdGet32 (PcdMaximumDevicePathNodeCount) > 0) {\r
+ Count++;\r
+ if (Count >= PcdGet32 (PcdMaximumDevicePathNodeCount)) {\r
+ return FALSE;\r
+ }\r
+ }\r
+\r
+ //\r
+ // FilePath must be a NULL-terminated string.\r
+ //\r
+ if ((DevicePathType (DevicePath) == MEDIA_DEVICE_PATH) &&\r
+ (DevicePathSubType (DevicePath) == MEDIA_FILEPATH_DP) &&\r
+ (*(CHAR16 *)((UINT8 *)DevicePath + NodeLength - 2) != 0))\r
+ {\r
+ return FALSE;\r
+ }\r
+ }\r
+\r
+ //\r
+ // Only return TRUE when the End Device Path node is valid.\r
+ //\r
+ return (BOOLEAN)(DevicePathNodeLength (DevicePath) == END_DEVICE_PATH_LENGTH);\r
+}\r
+\r
+/**\r
+ Returns the Type field of a device path node.\r
+\r
+ Returns the Type field of the device path node specified by Node.\r
+\r
+ If Node is NULL, then ASSERT().\r
+\r
+ @param Node A pointer to a device path node data structure.\r
+\r
+ @return The Type field of the device path node specified by Node.\r
+\r
+**/\r
+UINT8\r
+EFIAPI\r
+DevicePathType (\r
+ IN CONST VOID *Node\r
+ )\r
+{\r
+ ASSERT (Node != NULL);\r
+ return ((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Type;\r
+}\r
+\r
+/**\r
+ Returns the SubType field of a device path node.\r
+\r
+ Returns the SubType field of the device path node specified by Node.\r
+\r
+ If Node is NULL, then ASSERT().\r
\r
- @param DevicePath A pointer to a device path data structure.\r
+ @param Node A pointer to a device path node data structure.\r
\r
- @return The size of a device path in bytes.\r
+ @return The SubType field of the device path node specified by Node.\r
+\r
+**/\r
+UINT8\r
+EFIAPI\r
+DevicePathSubType (\r
+ IN CONST VOID *Node\r
+ )\r
+{\r
+ ASSERT (Node != NULL);\r
+ return ((EFI_DEVICE_PATH_PROTOCOL *)(Node))->SubType;\r
+}\r
+\r
+/**\r
+ Returns the 16-bit Length field of a device path node.\r
+\r
+ Returns the 16-bit Length field of the device path node specified by Node.\r
+ Node is not required to be aligned on a 16-bit boundary, so it is recommended\r
+ that a function such as ReadUnaligned16() be used to extract the contents of\r
+ the Length field.\r
+\r
+ If Node is NULL, then ASSERT().\r
+\r
+ @param Node A pointer to a device path node data structure.\r
+\r
+ @return The 16-bit Length field of the device path node specified by Node.\r
\r
**/\r
UINTN\r
EFIAPI\r
-GetDevicePathSize (\r
- IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
+DevicePathNodeLength (\r
+ IN CONST VOID *Node\r
)\r
{\r
- return mDevicePathUtilities->GetDevicePathSize (DevicePath);\r
+ ASSERT (Node != NULL);\r
+ return ReadUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0]);\r
}\r
\r
/**\r
- This function allocates space for a new copy of the device path\r
- specified by DevicePath.\r
+ Returns a pointer to the next node in a device path.\r
+\r
+ Returns a pointer to the device path node that follows the device path node\r
+ specified by Node.\r
\r
- @param DevicePath A pointer to a device path data structure.\r
+ If Node is NULL, then ASSERT().\r
\r
- @return The duplicated device path.\r
+ @param Node A pointer to a device path node data structure.\r
+\r
+ @return a pointer to the device path node that follows the device path node\r
+ specified by Node.\r
\r
**/\r
EFI_DEVICE_PATH_PROTOCOL *\r
EFIAPI\r
-DuplicateDevicePath (\r
- IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
+NextDevicePathNode (\r
+ IN CONST VOID *Node\r
)\r
{\r
- return mDevicePathUtilities->DuplicateDevicePath (DevicePath);\r
+ ASSERT (Node != NULL);\r
+ return (EFI_DEVICE_PATH_PROTOCOL *)((UINT8 *)(Node) + DevicePathNodeLength (Node));\r
}\r
\r
/**\r
- This function appends the device path SecondDevicePath\r
- to every device path instance in FirstDevicePath. \r
+ Determines if a device path node is an end node of a device path.\r
+ This includes nodes that are the end of a device path instance and nodes that\r
+ are the end of an entire device path.\r
+\r
+ Determines if the device path node specified by Node is an end node of a device path.\r
+ This includes nodes that are the end of a device path instance and nodes that are the\r
+ end of an entire device path. If Node represents an end node of a device path,\r
+ then TRUE is returned. Otherwise, FALSE is returned.\r
+\r
+ If Node is NULL, then ASSERT().\r
\r
- @param FirstDevicePath A pointer to a device path data structure.\r
- \r
- @param SecondDevicePath A pointer to a device path data structure.\r
+ @param Node A pointer to a device path node data structure.\r
\r
- @return A pointer to the new device path is returned.\r
- NULL is returned if space for the new device path could not be allocated from pool.\r
- It is up to the caller to free the memory used by FirstDevicePath and SecondDevicePath\r
- if they are no longer needed.\r
+ @retval TRUE The device path node specified by Node is an end node of a device path.\r
+ @retval FALSE The device path node specified by Node is not an end node of\r
+ a device path.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+IsDevicePathEndType (\r
+ IN CONST VOID *Node\r
+ )\r
+{\r
+ ASSERT (Node != NULL);\r
+ return (BOOLEAN)(DevicePathType (Node) == END_DEVICE_PATH_TYPE);\r
+}\r
+\r
+/**\r
+ Determines if a device path node is an end node of an entire device path.\r
+\r
+ Determines if a device path node specified by Node is an end node of an entire\r
+ device path.\r
+ If Node represents the end of an entire device path, then TRUE is returned.\r
+ Otherwise, FALSE is returned.\r
+\r
+ If Node is NULL, then ASSERT().\r
+\r
+ @param Node A pointer to a device path node data structure.\r
+\r
+ @retval TRUE The device path node specified by Node is the end of an entire device path.\r
+ @retval FALSE The device path node specified by Node is not the end of an entire device path.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+IsDevicePathEnd (\r
+ IN CONST VOID *Node\r
+ )\r
+{\r
+ ASSERT (Node != NULL);\r
+ return (BOOLEAN)(IsDevicePathEndType (Node) && DevicePathSubType (Node) == END_ENTIRE_DEVICE_PATH_SUBTYPE);\r
+}\r
+\r
+/**\r
+ Determines if a device path node is an end node of a device path instance.\r
+\r
+ Determines if a device path node specified by Node is an end node of a device\r
+ path instance.\r
+ If Node represents the end of a device path instance, then TRUE is returned.\r
+ Otherwise, FALSE is returned.\r
+\r
+ If Node is NULL, then ASSERT().\r
+\r
+ @param Node A pointer to a device path node data structure.\r
+\r
+ @retval TRUE The device path node specified by Node is the end of a device\r
+ path instance.\r
+ @retval FALSE The device path node specified by Node is not the end of a\r
+ device path instance.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+IsDevicePathEndInstance (\r
+ IN CONST VOID *Node\r
+ )\r
+{\r
+ ASSERT (Node != NULL);\r
+ return (BOOLEAN)(IsDevicePathEndType (Node) && DevicePathSubType (Node) == END_INSTANCE_DEVICE_PATH_SUBTYPE);\r
+}\r
+\r
+/**\r
+ Sets the length, in bytes, of a device path node.\r
+\r
+ Sets the length of the device path node specified by Node to the value specified\r
+ by NodeLength. NodeLength is returned. Node is not required to be aligned on\r
+ a 16-bit boundary, so it is recommended that a function such as WriteUnaligned16()\r
+ be used to set the contents of the Length field.\r
+\r
+ If Node is NULL, then ASSERT().\r
+ If NodeLength >= SIZE_64KB, then ASSERT().\r
+ If NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL), then ASSERT().\r
+\r
+ @param Node A pointer to a device path node data structure.\r
+ @param Length The length, in bytes, of the device path node.\r
+\r
+ @return Length\r
+\r
+**/\r
+UINT16\r
+EFIAPI\r
+SetDevicePathNodeLength (\r
+ IN OUT VOID *Node,\r
+ IN UINTN Length\r
+ )\r
+{\r
+ ASSERT (Node != NULL);\r
+ ASSERT ((Length >= sizeof (EFI_DEVICE_PATH_PROTOCOL)) && (Length < SIZE_64KB));\r
+ return WriteUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0], (UINT16)(Length));\r
+}\r
+\r
+/**\r
+ Fills in all the fields of a device path node that is the end of an entire device path.\r
+\r
+ Fills in all the fields of a device path node specified by Node so Node represents\r
+ the end of an entire device path. The Type field of Node is set to\r
+ END_DEVICE_PATH_TYPE, the SubType field of Node is set to\r
+ END_ENTIRE_DEVICE_PATH_SUBTYPE, and the Length field of Node is set to\r
+ END_DEVICE_PATH_LENGTH. Node is not required to be aligned on a 16-bit boundary,\r
+ so it is recommended that a function such as WriteUnaligned16() be used to set\r
+ the contents of the Length field.\r
+\r
+ If Node is NULL, then ASSERT().\r
+\r
+ @param Node A pointer to a device path node data structure.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+SetDevicePathEndNode (\r
+ OUT VOID *Node\r
+ )\r
+{\r
+ ASSERT (Node != NULL);\r
+ CopyMem (Node, &mUefiDevicePathLibEndDevicePath, sizeof (mUefiDevicePathLibEndDevicePath));\r
+}\r
+\r
+/**\r
+ Returns the size of a device path in bytes.\r
+\r
+ This function returns the size, in bytes, of the device path data structure\r
+ specified by DevicePath including the end of device path node.\r
+ If DevicePath is NULL or invalid, then 0 is returned.\r
+\r
+ @param DevicePath A pointer to a device path data structure.\r
+\r
+ @retval 0 If DevicePath is NULL or invalid.\r
+ @retval Others The size of a device path in bytes.\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+GetDevicePathSize (\r
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
+ )\r
+{\r
+ return mDevicePathLibDevicePathUtilities->GetDevicePathSize (DevicePath);\r
+}\r
+\r
+/**\r
+ Creates a new copy of an existing device path.\r
+\r
+ This function allocates space for a new copy of the device path specified by\r
+ DevicePath. If DevicePath is NULL, then NULL is returned.\r
+ If the memory is successfully allocated, then the\r
+ contents of DevicePath are copied to the newly allocated buffer, and a pointer to that buffer\r
+ is returned. Otherwise, NULL is returned.\r
+ The memory for the new device path is allocated from EFI boot services memory.\r
+ It is the responsibility of the caller to free the memory allocated.\r
+\r
+ @param DevicePath A pointer to a device path data structure.\r
+\r
+ @retval NULL If DevicePath is NULL or invalid.\r
+ @retval Others A pointer to the duplicated device path.\r
\r
**/\r
EFI_DEVICE_PATH_PROTOCOL *\r
EFIAPI\r
-AppendDevicePath (\r
- IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath,\r
- IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath\r
+DuplicateDevicePath (\r
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
)\r
{\r
- return mDevicePathUtilities->AppendDevicePath (FirstDevicePath, SecondDevicePath);\r
+ return mDevicePathLibDevicePathUtilities->DuplicateDevicePath (DevicePath);\r
}\r
\r
/**\r
- This function appends the device path node SecondDevicePath\r
- to every device path instance in FirstDevicePath.\r
+ Creates a new device path by appending a second device path to a first device path.\r
+\r
+ This function creates a new device path by appending a copy of SecondDevicePath to a copy of\r
+ FirstDevicePath in a newly allocated buffer. Only the end-of-device-path device node from\r
+ SecondDevicePath is retained. The newly created device path is returned.\r
+ If FirstDevicePath is NULL, then it is ignored, and a duplicate of SecondDevicePath is returned.\r
+ If SecondDevicePath is NULL, then it is ignored, and a duplicate of FirstDevicePath is returned.\r
+ If both FirstDevicePath and SecondDevicePath are NULL, then a copy of an end-of-device-path is\r
+ returned.\r
+ If there is not enough memory for the newly allocated buffer, then NULL is returned.\r
+ The memory for the new device path is allocated from EFI boot services memory. It is the\r
+ responsibility of the caller to free the memory allocated.\r
+\r
+ @param FirstDevicePath A pointer to a device path data structure.\r
+ @param SecondDevicePath A pointer to a device path data structure.\r
+\r
+ @retval NULL If there is not enough memory for the newly allocated buffer.\r
+ @retval NULL If FirstDevicePath or SecondDevicePath is invalid.\r
+ @retval Others A pointer to the new device path if success.\r
+ Or a copy an end-of-device-path if both FirstDevicePath and\r
+ SecondDevicePath are NULL.\r
\r
- @param FirstDevicePath A pointer to a device path data structure.\r
- \r
- @param SecondDevicePath A pointer to a single device path node.\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+EFIAPI\r
+AppendDevicePath (\r
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath OPTIONAL,\r
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL\r
+ )\r
+{\r
+ return mDevicePathLibDevicePathUtilities->AppendDevicePath (FirstDevicePath, SecondDevicePath);\r
+}\r
\r
- @return A pointer to the new device path.\r
- If there is not enough temporary pool memory available to complete this function,\r
- then NULL is returned.\r
+/**\r
+ Creates a new path by appending the device node to the device path.\r
+\r
+ This function creates a new device path by appending a copy of the device node\r
+ specified by DevicePathNode to a copy of the device path specified by DevicePath\r
+ in an allocated buffer.\r
+ The end-of-device-path device node is moved after the end of the appended device node.\r
+ If DevicePathNode is NULL then a copy of DevicePath is returned.\r
+ If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device\r
+ path device node is returned.\r
+ If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path\r
+ device node is returned.\r
+ If there is not enough memory to allocate space for the new device path, then\r
+ NULL is returned.\r
+ The memory is allocated from EFI boot services memory. It is the responsibility\r
+ of the caller to free the memory allocated.\r
+\r
+ @param DevicePath A pointer to a device path data structure.\r
+ @param DevicePathNode A pointer to a single device path node.\r
+\r
+ @retval NULL If there is not enough memory for the new device path.\r
+ @retval Others A pointer to the new device path if success.\r
+ A copy of DevicePathNode followed by an end-of-device-path node\r
+ if both FirstDevicePath and SecondDevicePath are NULL.\r
+ A copy of an end-of-device-path node if both FirstDevicePath\r
+ and SecondDevicePath are NULL.\r
\r
**/\r
EFI_DEVICE_PATH_PROTOCOL *\r
EFIAPI\r
AppendDevicePathNode (\r
- IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath,\r
- IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath\r
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL,\r
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL\r
)\r
{\r
- return mDevicePathUtilities->AppendDeviceNode (FirstDevicePath, SecondDevicePath);\r
+ return mDevicePathLibDevicePathUtilities->AppendDeviceNode (DevicePath, DevicePathNode);\r
}\r
\r
/**\r
- This function appends the device path instance Instance to the device path Source.\r
- If Source is NULL, then a new device path with one instance is created. \r
-\r
- @param Source A pointer to a device path data structure.\r
- @param Instance A pointer to a device path instance.\r
+ Creates a new device path by appending the specified device path instance to\r
+ the specified device path.\r
+\r
+ This function creates a new device path by appending a copy of the device path\r
+ instance specified by DevicePathInstance to a copy of the device path specified\r
+ by DevicePath in a allocated buffer.\r
+ The end-of-device-path device node is moved after the end of the appended device\r
+ path instance and a new end-of-device-path-instance node is inserted between.\r
+ If DevicePath is NULL, then a copy if DevicePathInstance is returned.\r
+ If DevicePathInstance is NULL, then NULL is returned.\r
+ If DevicePath or DevicePathInstance is invalid, then NULL is returned.\r
+ If there is not enough memory to allocate space for the new device path, then\r
+ NULL is returned.\r
+ The memory is allocated from EFI boot services memory. It is the responsibility\r
+ of the caller to free the memory allocated.\r
+\r
+ @param DevicePath A pointer to a device path data structure.\r
+ @param DevicePathInstance A pointer to a device path instance.\r
\r
@return A pointer to the new device path.\r
- If there is not enough temporary pool memory available to complete this function,\r
- then NULL is returned.\r
\r
**/\r
EFI_DEVICE_PATH_PROTOCOL *\r
EFIAPI\r
AppendDevicePathInstance (\r
- IN CONST EFI_DEVICE_PATH_PROTOCOL *Source,\r
- IN CONST EFI_DEVICE_PATH_PROTOCOL *Instance\r
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL,\r
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL\r
)\r
{\r
- return mDevicePathUtilities->AppendDevicePathInstance (Source, Instance);\r
+ return mDevicePathLibDevicePathUtilities->AppendDevicePathInstance (DevicePath, DevicePathInstance);\r
}\r
\r
/**\r
- Function retrieves the next device path instance from a device path data structure.\r
-\r
- @param DevicePath A pointer to a device path data structure.\r
- \r
- @param Size A pointer to the size of a device path instance in bytes.\r
-\r
- @return This function returns a pointer to the current device path instance.\r
- In addition, it returns the size in bytes of the current device path instance in Size,\r
- and a pointer to the next device path instance in DevicePath.\r
- If there are no more device path instances in DevicePath, then DevicePath will be set to NULL.\r
+ Creates a copy of the current device path instance and returns a pointer to the\r
+ next device path instance.\r
+\r
+ This function creates a copy of the current device path instance. It also updates\r
+ DevicePath to point to the next device path instance in the device path (or NULL\r
+ if no more) and updates Size to hold the size of the device path instance copy.\r
+ If DevicePath is NULL, then NULL is returned.\r
+ If there is not enough memory to allocate space for the new device path, then\r
+ NULL is returned.\r
+ The memory is allocated from EFI boot services memory. It is the responsibility\r
+ of the caller to free the memory allocated.\r
+ If Size is NULL, then ASSERT().\r
+\r
+ @param DevicePath On input, this holds the pointer to the current\r
+ device path instance. On output, this holds\r
+ the pointer to the next device path instance\r
+ or NULL if there are no more device path\r
+ instances in the device path pointer to a\r
+ device path data structure.\r
+ @param Size On output, this holds the size of the device\r
+ path instance, in bytes or zero, if DevicePath\r
+ is NULL.\r
+\r
+ @return A pointer to the current device path instance.\r
\r
**/\r
EFI_DEVICE_PATH_PROTOCOL *\r
EFIAPI\r
GetNextDevicePathInstance (\r
IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,\r
- OUT UINTN *Size\r
+ OUT UINTN *Size\r
)\r
{\r
- ASSERT (DevicePath != NULL);\r
ASSERT (Size != NULL);\r
- return mDevicePathUtilities->GetNextDevicePathInstance (DevicePath, Size);\r
+ return mDevicePathLibDevicePathUtilities->GetNextDevicePathInstance (DevicePath, Size);\r
+}\r
+\r
+/**\r
+ Creates a device node.\r
+\r
+ This function creates a new device node in a newly allocated buffer of size\r
+ NodeLength and initializes the device path node header with NodeType and NodeSubType.\r
+ The new device path node is returned.\r
+ If NodeLength is smaller than a device path header, then NULL is returned.\r
+ If there is not enough memory to allocate space for the new device path, then\r
+ NULL is returned.\r
+ The memory is allocated from EFI boot services memory. It is the responsibility\r
+ of the caller to free the memory allocated.\r
+\r
+ @param NodeType The device node type for the new device node.\r
+ @param NodeSubType The device node sub-type for the new device node.\r
+ @param NodeLength The length of the new device node.\r
+\r
+ @return The new device path.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+EFIAPI\r
+CreateDeviceNode (\r
+ IN UINT8 NodeType,\r
+ IN UINT8 NodeSubType,\r
+ IN UINT16 NodeLength\r
+ )\r
+{\r
+ return mDevicePathLibDevicePathUtilities->CreateDeviceNode (NodeType, NodeSubType, NodeLength);\r
}\r
\r
/**\r
- Return TRUE is this is a multi instance device path.\r
+ Determines if a device path is single or multi-instance.\r
\r
- @param DevicePath A pointer to a device path data structure.\r
+ This function returns TRUE if the device path specified by DevicePath is\r
+ multi-instance.\r
+ Otherwise, FALSE is returned.\r
+ If DevicePath is NULL or invalid, then FALSE is returned.\r
\r
- @retval TRUE If DevicePath is multi-instance.\r
- @retval FALSE If DevicePath is not multi-instance or DevicePath is NULL.\r
+ @param DevicePath A pointer to a device path data structure.\r
+\r
+ @retval TRUE DevicePath is multi-instance.\r
+ @retval FALSE DevicePath is not multi-instance, or DevicePath\r
+ is NULL or invalid.\r
\r
**/\r
BOOLEAN\r
IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
)\r
{\r
- return mDevicePathUtilities->IsDevicePathMultiInstance (DevicePath);\r
+ return mDevicePathLibDevicePathUtilities->IsDevicePathMultiInstance (DevicePath);\r
}\r
\r
/**\r
- This function retrieves the device path protocol from a handle.\r
+ Retrieves the device path protocol from a handle.\r
+\r
+ This function returns the device path protocol from the handle specified by Handle.\r
+ If Handle is NULL or Handle does not contain a device path protocol, then NULL\r
+ is returned.\r
\r
- @param Handle The handle from which to retrieve the device path protocol.\r
+ @param Handle The handle from which to retrieve the device\r
+ path protocol.\r
\r
- @return This function returns the device path protocol from the handle specified by Handle.\r
- If Handle is NULL or Handle does not contain a device path protocol, then NULL is returned.\r
+ @return The device path protocol from the handle specified by Handle.\r
\r
**/\r
EFI_DEVICE_PATH_PROTOCOL *\r
Status = gBS->HandleProtocol (\r
Handle,\r
&gEfiDevicePathProtocolGuid,\r
- (VOID *) &DevicePath\r
+ (VOID *)&DevicePath\r
);\r
if (EFI_ERROR (Status)) {\r
DevicePath = NULL;\r
}\r
+\r
return DevicePath;\r
}\r
\r
/**\r
- This function allocates a device path for a file and appends it to an existing device path.\r
+ Allocates a device path for a file and appends it to an existing device path.\r
+\r
+ If Device is a valid device handle that contains a device path protocol, then\r
+ a device path for the file specified by FileName is allocated and appended to\r
+ the device path associated with the handle Device. The allocated device path\r
+ is returned. If Device is NULL or Device is a handle that does not support the\r
+ device path protocol, then a device path containing a single device path node\r
+ for the file specified by FileName is allocated and returned.\r
+ The memory for the new device path is allocated from EFI boot services memory.\r
+ It is the responsibility of the caller to free the memory allocated.\r
\r
- @param Device A pointer to a device handle. This parameter is optional and may be NULL.\r
- @param FileName A pointer to a Null-terminated Unicode string.\r
+ If FileName is NULL, then ASSERT().\r
+ If FileName is not aligned on a 16-bit boundary, then ASSERT().\r
\r
- @return If Device is a valid device handle that contains a device path protocol,\r
- then a device path for the file specified by FileName is allocated\r
- and appended to the device path associated with the handle Device. The allocated device path is returned.\r
- If Device is NULL or Device is a handle that does not support the device path protocol,\r
- then a device path containing a single device path node for the file specified by FileName\r
- is allocated and returned.\r
+ @param Device A pointer to a device handle. This parameter\r
+ is optional and may be NULL.\r
+ @param FileName A pointer to a Null-terminated Unicode string.\r
+\r
+ @return The allocated device path.\r
\r
**/\r
EFI_DEVICE_PATH_PROTOCOL *\r
EFIAPI\r
FileDevicePath (\r
- IN EFI_HANDLE Device, OPTIONAL\r
+ IN EFI_HANDLE Device OPTIONAL,\r
IN CONST CHAR16 *FileName\r
)\r
{\r
UINTN Size;\r
FILEPATH_DEVICE_PATH *FilePath;\r
EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
- EFI_DEVICE_PATH_PROTOCOL *FileDevicePathNode;\r
+ EFI_DEVICE_PATH_PROTOCOL *FileDevicePath;\r
\r
DevicePath = NULL;\r
\r
- Size = StrSize (FileName);\r
- FileDevicePathNode = mDevicePathUtilities->CreateDeviceNode (\r
- MEDIA_DEVICE_PATH,\r
- MEDIA_FILEPATH_DP,\r
- (UINT16) (Size + SIZE_OF_FILEPATH_DEVICE_PATH)\r
- );\r
- if (FileDevicePathNode != NULL) {\r
- FilePath = (FILEPATH_DEVICE_PATH *) FileDevicePathNode;\r
+ Size = StrSize (FileName);\r
+ FileDevicePath = AllocatePool (Size + SIZE_OF_FILEPATH_DEVICE_PATH + END_DEVICE_PATH_LENGTH);\r
+ if (FileDevicePath != NULL) {\r
+ FilePath = (FILEPATH_DEVICE_PATH *)FileDevicePath;\r
+ FilePath->Header.Type = MEDIA_DEVICE_PATH;\r
+ FilePath->Header.SubType = MEDIA_FILEPATH_DP;\r
CopyMem (&FilePath->PathName, FileName, Size);\r
+ SetDevicePathNodeLength (&FilePath->Header, Size + SIZE_OF_FILEPATH_DEVICE_PATH);\r
+ SetDevicePathEndNode (NextDevicePathNode (&FilePath->Header));\r
+\r
if (Device != NULL) {\r
DevicePath = DevicePathFromHandle (Device);\r
}\r
- DevicePath = AppendDevicePathNode (DevicePath, FileDevicePathNode);\r
- FreePool (FileDevicePathNode);\r
+\r
+ DevicePath = AppendDevicePath (DevicePath, FileDevicePath);\r
+ FreePool (FileDevicePath);\r
}\r
+\r
return DevicePath;\r
}\r
\r
+/**\r
+ Locate and return the protocol instance identified by the ProtocolGuid.\r
+\r
+ @param ProtocolGuid The GUID of the protocol.\r
+\r
+ @return A pointer to the protocol instance or NULL when absent.\r
+**/\r
+VOID *\r
+UefiDevicePathLibLocateProtocol (\r
+ EFI_GUID *ProtocolGuid\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ VOID *Protocol;\r
+\r
+ Status = gBS->LocateProtocol (\r
+ ProtocolGuid,\r
+ NULL,\r
+ (VOID **)&Protocol\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ return NULL;\r
+ } else {\r
+ return Protocol;\r
+ }\r
+}\r
+\r
+/**\r
+ Converts a device node to its string representation.\r
+\r
+ @param DeviceNode A Pointer to the device node to be converted.\r
+ @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation\r
+ of the display node is used, where applicable. If DisplayOnly\r
+ is FALSE, then the longer text representation of the display node\r
+ is used.\r
+ @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text\r
+ representation for a device node can be used, where applicable.\r
+\r
+ @return A pointer to the allocated text representation of the device node or NULL if DeviceNode\r
+ is NULL or there was insufficient memory.\r
+\r
+**/\r
+CHAR16 *\r
+EFIAPI\r
+ConvertDeviceNodeToText (\r
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode,\r
+ IN BOOLEAN DisplayOnly,\r
+ IN BOOLEAN AllowShortcuts\r
+ )\r
+{\r
+ if (mDevicePathLibDevicePathToText == NULL) {\r
+ mDevicePathLibDevicePathToText = UefiDevicePathLibLocateProtocol (&gEfiDevicePathToTextProtocolGuid);\r
+ }\r
+\r
+ if (mDevicePathLibDevicePathToText != NULL) {\r
+ return mDevicePathLibDevicePathToText->ConvertDeviceNodeToText (DeviceNode, DisplayOnly, AllowShortcuts);\r
+ } else {\r
+ return NULL;\r
+ }\r
+}\r
+\r
+/**\r
+ Converts a device path to its text representation.\r
+\r
+ @param DevicePath A Pointer to the device to be converted.\r
+ @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation\r
+ of the display node is used, where applicable. If DisplayOnly\r
+ is FALSE, then the longer text representation of the display node\r
+ is used.\r
+ @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text\r
+ representation for a device node can be used, where applicable.\r
+\r
+ @return A pointer to the allocated text representation of the device path or\r
+ NULL if DeviceNode is NULL or there was insufficient memory.\r
+\r
+**/\r
+CHAR16 *\r
+EFIAPI\r
+ConvertDevicePathToText (\r
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
+ IN BOOLEAN DisplayOnly,\r
+ IN BOOLEAN AllowShortcuts\r
+ )\r
+{\r
+ if (mDevicePathLibDevicePathToText == NULL) {\r
+ mDevicePathLibDevicePathToText = UefiDevicePathLibLocateProtocol (&gEfiDevicePathToTextProtocolGuid);\r
+ }\r
+\r
+ if (mDevicePathLibDevicePathToText != NULL) {\r
+ return mDevicePathLibDevicePathToText->ConvertDevicePathToText (DevicePath, DisplayOnly, AllowShortcuts);\r
+ } else {\r
+ return NULL;\r
+ }\r
+}\r
+\r
+/**\r
+ Convert text to the binary representation of a device node.\r
+\r
+ @param TextDeviceNode TextDeviceNode points to the text representation of a device\r
+ node. Conversion starts with the first character and continues\r
+ until the first non-device node character.\r
+\r
+ @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was\r
+ insufficient memory or text unsupported.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+EFIAPI\r
+ConvertTextToDeviceNode (\r
+ IN CONST CHAR16 *TextDeviceNode\r
+ )\r
+{\r
+ if (mDevicePathLibDevicePathFromText == NULL) {\r
+ mDevicePathLibDevicePathFromText = UefiDevicePathLibLocateProtocol (&gEfiDevicePathFromTextProtocolGuid);\r
+ }\r
+\r
+ if (mDevicePathLibDevicePathFromText != NULL) {\r
+ return mDevicePathLibDevicePathFromText->ConvertTextToDeviceNode (TextDeviceNode);\r
+ } else {\r
+ return NULL;\r
+ }\r
+}\r
+\r
+/**\r
+ Convert text to the binary representation of a device path.\r
+\r
+\r
+ @param TextDevicePath TextDevicePath points to the text representation of a device\r
+ path. Conversion starts with the first character and continues\r
+ until the first non-device node character.\r
+\r
+ @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or\r
+ there was insufficient memory.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+EFIAPI\r
+ConvertTextToDevicePath (\r
+ IN CONST CHAR16 *TextDevicePath\r
+ )\r
+{\r
+ if (mDevicePathLibDevicePathFromText == NULL) {\r
+ mDevicePathLibDevicePathFromText = UefiDevicePathLibLocateProtocol (&gEfiDevicePathFromTextProtocolGuid);\r
+ }\r
+\r
+ if (mDevicePathLibDevicePathFromText != NULL) {\r
+ return mDevicePathLibDevicePathFromText->ConvertTextToDevicePath (TextDevicePath);\r
+ } else {\r
+ return NULL;\r
+ }\r
+}\r