]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.c
MdePkg UefiDevicePathLib: Validate before touch input buffer.
[mirror_edk2.git] / MdePkg / Library / UefiDevicePathLib / UefiDevicePathLib.c
index e05736bbb7bebff8afbf10321f609b3ebed7540a..baad7bc1f7f156ecee63b2befdd50166a2675895 100644 (file)
@@ -8,28 +8,31 @@
   environment varibles. Multi-instance device paths should never be placed\r
   on a Handle.\r
 \r
-  Copyright (c) 2006, Intel Corporation                                                         \r
-  All rights reserved. This program and the accompanying materials                          \r
+  Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
+  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
+  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
-\r
 **/\r
 \r
+\r
+#include "UefiDevicePathLib.h"\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 specified by\r
-  DevicePath including the end of device path node.  If DevicePath is NULL, then 0 is returned.\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
+  @param  DevicePath  A pointer to a device path data structure.\r
 \r
-  @return The size of a device path in bytes.\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
@@ -38,38 +41,24 @@ GetDevicePathSize (
   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
   )\r
 {\r
-  CONST EFI_DEVICE_PATH_PROTOCOL  *Start;\r
-\r
-  if (DevicePath == NULL) {\r
-    return 0;\r
-  }\r
-\r
-  //\r
-  // Search for the end of the device path structure\r
-  //\r
-  Start = DevicePath;\r
-  while (!EfiIsDevicePathEnd (DevicePath)) {\r
-    DevicePath = EfiNextDevicePathNode (DevicePath);\r
-  }\r
-\r
-  //\r
-  // Compute the size and add back in the size of the end device path structure\r
-  //\r
-  return ((UINTN) DevicePath - (UINTN) Start) + sizeof (EFI_DEVICE_PATH_PROTOCOL);\r
+  return UefiDevicePathLibGetDevicePathSize (DevicePath);\r
 }\r
 \r
 /**\r
-  Creates a new device path by appending a second device path to a first device path.\r
-\r
-  This function allocates space for a new copy of the device path specified by DevicePath.  If\r
-  DevicePath is NULL, then NULL is returned.  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
+  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 DevicePath.  \r
+  If DevicePath is NULL, then NULL is returned.  If the memory is successfully \r
+  allocated, then the contents of DevicePath are copied to the newly allocated \r
+  buffer, and a pointer to that buffer 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
-  @return A pointer to the duplicated device path.\r
+  @param  DevicePath    A pointer to a device path data structure.\r
 \r
+  @retval NULL          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
@@ -77,42 +66,31 @@ DuplicateDevicePath (
   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
   )\r
 {\r
-  EFI_DEVICE_PATH_PROTOCOL  *NewDevicePath;\r
-  UINTN                     Size;\r
-\r
-  //\r
-  // Compute the size\r
-  //\r
-  Size = GetDevicePathSize (DevicePath);\r
-  if (Size == 0) {\r
-    return NULL;\r
-  }\r
-\r
-  //\r
-  // Allocate space for duplicate device path\r
-  //\r
-  NewDevicePath = AllocateCopyPool (Size, DevicePath);\r
-\r
-  return NewDevicePath;\r
+  return UefiDevicePathLibDuplicateDevicePath (DevicePath);\r
 }\r
 \r
 /**\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 NULL is returned.  \r
+  This function creates a new device path by appending a copy of SecondDevicePath \r
+  to a copy of FirstDevicePath in a newly allocated buffer.  Only the end-of-device-path \r
+  device node from SecondDevicePath is retained. The newly created device path is \r
+  returned. If FirstDevicePath is NULL, then it is ignored, and a duplicate of \r
+  SecondDevicePath is returned.  If SecondDevicePath is NULL, then it is ignored, \r
+  and a duplicate of FirstDevicePath is returned. If both FirstDevicePath and \r
+  SecondDevicePath are NULL, then a copy of an end-of-device-path is returned.  \r
+  \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
+  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  FirstDevicePath            A pointer to a device path data structure.\r
   @param  SecondDevicePath           A pointer to a device path data structure.\r
-\r
-  @return A pointer to the new device path.\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 SecondDevicePath are NULL.\r
 \r
 **/\r
 EFI_DEVICE_PATH_PROTOCOL *\r
@@ -122,62 +100,35 @@ AppendDevicePath (
   IN CONST EFI_DEVICE_PATH_PROTOCOL  *SecondDevicePath  OPTIONAL\r
   )\r
 {\r
-  UINTN                     Size;\r
-  UINTN                     Size1;\r
-  UINTN                     Size2;\r
-  EFI_DEVICE_PATH_PROTOCOL  *NewDevicePath;\r
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePath2;\r
-\r
-  //\r
-  // If there's only 1 path, just duplicate it.\r
-  //\r
-  if (FirstDevicePath == NULL) {\r
-    return DuplicateDevicePath (SecondDevicePath);\r
-  }\r
-\r
-  if (SecondDevicePath == NULL) {\r
-    return DuplicateDevicePath (FirstDevicePath);\r
-  }\r
-\r
-  //\r
-  // Allocate space for the combined device path. It only has one end node of\r
-  // length EFI_DEVICE_PATH_PROTOCOL.\r
-  //\r
-  Size1         = GetDevicePathSize (FirstDevicePath);\r
-  Size2         = GetDevicePathSize (SecondDevicePath);\r
-  Size          = Size1 + Size2 - sizeof (EFI_DEVICE_PATH_PROTOCOL);\r
-\r
-  NewDevicePath = AllocatePool (Size);\r
-\r
-  if (NewDevicePath != NULL) {\r
-    NewDevicePath = CopyMem (NewDevicePath, FirstDevicePath, Size1);\r
-    //\r
-    // Over write FirstDevicePath EndNode and do the copy\r
-    //\r
-    DevicePath2 = (EFI_DEVICE_PATH_PROTOCOL *) ((CHAR8 *) NewDevicePath +\r
-                  (Size1 - sizeof (EFI_DEVICE_PATH_PROTOCOL)));\r
-    CopyMem (DevicePath2, SecondDevicePath, Size2);\r
-  }\r
-\r
-  return NewDevicePath;\r
+  return UefiDevicePathLibAppendDevicePath (FirstDevicePath, SecondDevicePath);\r
 }\r
 \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 specified by\r
-  DevicePathNode to a copy of the device path specified by DevicePath in an allocated buffer.\r
-  The end-of-device-path device node is moved after the end of the appended device node.\r
-  If DevicePath is NULL, then NULL is returned.\r
-  If DevicePathNode is NULL, then NULL is returned.\r
-  If there is not enough memory to allocate space for the new device path, then NULL is returned.  \r
-  The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r
-  free the memory allocated.\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. The end-of-device-path device node is moved after the \r
+  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
-  @return A pointer to the new device path.\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
@@ -187,52 +138,25 @@ AppendDevicePathNode (
   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePathNode  OPTIONAL\r
   )\r
 {\r
-  EFI_DEVICE_PATH_PROTOCOL  *TempDevicePath;\r
-  EFI_DEVICE_PATH_PROTOCOL  *NextNode;\r
-  EFI_DEVICE_PATH_PROTOCOL  *NewDevicePath;\r
-  UINTN                     NodeLength;\r
-\r
-  if (DevicePath == NULL || DevicePathNode == NULL) {\r
-    return NULL;\r
-  }\r
-  //\r
-  // Build a Node that has a terminator on it\r
-  //\r
-  NodeLength = DevicePathNodeLength (DevicePathNode);\r
-\r
-  TempDevicePath = AllocatePool (NodeLength + sizeof (EFI_DEVICE_PATH_PROTOCOL));\r
-  if (TempDevicePath == NULL) {\r
-    return NULL;\r
-  }\r
-  TempDevicePath = CopyMem (TempDevicePath, DevicePathNode, NodeLength);\r
-  //\r
-  // Add and end device path node to convert Node to device path\r
-  //\r
-  NextNode = NextDevicePathNode (TempDevicePath);\r
-  SetDevicePathEndNode (NextNode);\r
-  //\r
-  // Append device paths\r
-  //\r
-  NewDevicePath = AppendDevicePath (DevicePath, TempDevicePath);\r
-\r
-  FreePool (TempDevicePath);\r
-\r
-  return NewDevicePath;\r
+  return UefiDevicePathLibAppendDevicePathNode (DevicePath, DevicePathNode);\r
 }\r
 \r
 /**\r
   Creates a new device path by appending the specified device path instance to the specified device\r
   path.\r
  \r
-  This function creates a new device path by appending a copy of the device path instance specified\r
-  by DevicePathInstance to a copy of the device path secified by DevicePath in a allocated buffer.\r
-  The end-of-device-path device node is moved after the end of the appended device path instance\r
-  and a new end-of-device-path-instance node is inserted between. \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 there is not enough memory to allocate space for the new device path, then NULL is returned.  \r
-  The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r
-  free the memory allocated.\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
@@ -247,59 +171,33 @@ AppendDevicePathInstance (
   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePathInstance OPTIONAL\r
   )\r
 {\r
-  EFI_DEVICE_PATH_PROTOCOL  *NewDevicePath;\r
-  EFI_DEVICE_PATH_PROTOCOL  *TempDevicePath;\r
-  UINTN                     SrcSize;\r
-  UINTN                     InstanceSize;\r
-\r
-  if (DevicePath == NULL) {\r
-    return DuplicateDevicePath (DevicePathInstance);\r
-  }\r
-\r
-  if (DevicePathInstance == NULL) {\r
-    return NULL;\r
-  }\r
-\r
-  SrcSize       = GetDevicePathSize (DevicePath);\r
-  InstanceSize  = GetDevicePathSize (DevicePathInstance);\r
-\r
-  NewDevicePath = AllocatePool (SrcSize + InstanceSize);\r
-  if (NewDevicePath != NULL) {\r
-    \r
-    TempDevicePath = CopyMem (NewDevicePath, DevicePath, SrcSize);;\r
\r
-    while (!IsDevicePathEnd (TempDevicePath)) {\r
-      TempDevicePath = NextDevicePathNode (TempDevicePath);\r
-    }\r
-    \r
-    TempDevicePath->SubType  = END_INSTANCE_DEVICE_PATH_SUBTYPE;\r
-    TempDevicePath           = NextDevicePathNode (TempDevicePath);\r
-    CopyMem (TempDevicePath, DevicePathInstance, InstanceSize);\r
-  }\r
-\r
-  return NewDevicePath;\r
+  return UefiDevicePathLibAppendDevicePathInstance (DevicePath, DevicePathInstance);\r
 }\r
 \r
 /**\r
   Creates a copy of the current device path instance and returns a pointer to the next device path\r
   instance.\r
 \r
-  This function creates a copy of the current device path instance. It also updates DevicePath to\r
-  point to the next device path instance in the device path (or NULL if no more) and updates Size\r
-  to hold the size of the device path instance copy.\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 NULL is returned.  \r
-  The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r
-  free the memory allocated.\r
+  If DevicePath points to a invalid device path, 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 device path\r
-                                     instance. On output, this holds the pointer to the next device\r
-                                     path instance or NULL if there are no more device path\r
-                                     instances in the device path pointer to a device path data\r
-                                     structure.\r
-  @param  Size                       On output, this holds the size of the device path instance, in\r
-                                     bytes or zero, if DevicePath is NULL.\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
@@ -311,62 +209,20 @@ GetNextDevicePathInstance (
   OUT UINTN                          *Size\r
   )\r
 {\r
-  EFI_DEVICE_PATH_PROTOCOL  *DevPath;\r
-  EFI_DEVICE_PATH_PROTOCOL  *ReturnValue;\r
-  UINT8                     Temp;\r
-\r
-  ASSERT (Size != NULL);\r
-\r
-  if (DevicePath == NULL || *DevicePath == NULL) {\r
-    *Size = 0;\r
-    return NULL;\r
-  }\r
-\r
-  //\r
-  // Find the end of the device path instance\r
-  //\r
-  DevPath = *DevicePath;\r
-  while (!IsDevicePathEndType (DevPath)) {\r
-    DevPath = NextDevicePathNode (DevPath);\r
-  }\r
-\r
-  //\r
-  // Compute the size of the device path instance\r
-  //\r
-  *Size = ((UINTN) DevPath - (UINTN) (*DevicePath)) + sizeof (EFI_DEVICE_PATH_PROTOCOL);\r
\r
-  //\r
-  // Make a copy and return the device path instance\r
-  //\r
-  Temp              = DevPath->SubType;\r
-  DevPath->SubType  = END_ENTIRE_DEVICE_PATH_SUBTYPE;\r
-  ReturnValue       = DuplicateDevicePath (*DevicePath);\r
-  DevPath->SubType  = Temp;\r
-\r
-  //\r
-  // If DevPath is the end of an entire device path, then another instance\r
-  // does not follow, so *DevicePath is set to NULL.\r
-  //\r
-  if (DevicePathSubType (DevPath) == END_ENTIRE_DEVICE_PATH_SUBTYPE) {\r
-    *DevicePath = NULL;\r
-  } else {\r
-    *DevicePath = NextDevicePathNode (DevPath);\r
-  }\r
-\r
-  return ReturnValue;\r
+  return UefiDevicePathLibGetNextDevicePathInstance (DevicePath, Size);\r
 }\r
 \r
 /**\r
-  Creates a copy of the current device path instance and returns a pointer to the next device path\r
-  instance.\r
+  Creates a device node.\r
 \r
-  This function creates a new device node in a newly allocated buffer of size NodeLength and\r
-  initializes the device path node header with NodeType and NodeSubType.  The new device path node\r
-  is returned.\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 NULL is returned.  \r
-  The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r
-  free the memory allocated.\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
@@ -383,34 +239,22 @@ CreateDeviceNode (
   IN UINT16                          NodeLength\r
   )\r
 {\r
-  EFI_DEVICE_PATH_PROTOCOL      *DevicePath;\r
-\r
-  if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {\r
-    //\r
-    // NodeLength is less than the size of the header.\r
-    //\r
-    return NULL;\r
-  }\r
\r
-  DevicePath = AllocatePool (NodeLength);\r
-  if (DevicePath != NULL) {\r
-     DevicePath->Type    = NodeType;\r
-     DevicePath->SubType = NodeSubType;\r
-  }\r
-\r
-  return DevicePath;\r
+  return UefiDevicePathLibCreateDeviceNode (NodeType, NodeSubType, NodeLength);\r
 }\r
 \r
 /**\r
   Determines if a device path is single or multi-instance.\r
 \r
-  This function returns TRUE if the device path specified by DevicePath is multi-instance.\r
-  Otherwise, FALSE is returned.  If DevicePath is NULL, then FALSE is returned.\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
   @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 is NULL.\r
+  @retval  FALSE                     DevicePath is not multi-instance, or DevicePath \r
+                                     is NULL or invalid.\r
 \r
 **/\r
 BOOLEAN\r
@@ -419,105 +263,98 @@ IsDevicePathMultiInstance (
   IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
   )\r
 {\r
-  CONST EFI_DEVICE_PATH_PROTOCOL     *Node;\r
+  return UefiDevicePathLibIsDevicePathMultiInstance (DevicePath);\r
+}\r
 \r
-  if (DevicePath == NULL) {\r
-    return FALSE;\r
-  }\r
+/**\r
+  Converts a device node to its string representation.\r
 \r
-  Node = DevicePath;\r
-  while (!EfiIsDevicePathEnd (Node)) {\r
-    if (EfiIsDevicePathEndInstance (Node)) {\r
-      return TRUE;\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
-    Node = EfiNextDevicePathNode (Node);\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
-  return FALSE;\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
+  return UefiDevicePathLibConvertDeviceNodeToText (DeviceNode, DisplayOnly, AllowShortcuts);\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
+  return UefiDevicePathLibConvertDevicePathToText (DevicePath, DisplayOnly, AllowShortcuts);\r
+}\r
 \r
 /**\r
-  Retrieves the device path protocol from a handle.\r
+  Convert text to the binary representation of a device node.\r
 \r
-  This function returns the device path protocol from the handle specified by Handle.  If Handle is\r
-  NULL or Handle does not contain a device path protocol, then NULL is returned.\r
\r
-  @param  Handle                     The handle from which to retrieve the device path protocol.\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 The device path protocol from the handle specified by Handle.\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
-DevicePathFromHandle (\r
-  IN EFI_HANDLE                      Handle\r
+ConvertTextToDeviceNode (\r
+  IN CONST CHAR16 *TextDeviceNode\r
   )\r
 {\r
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
-  EFI_STATUS                Status;\r
-\r
-  Status = gBS->HandleProtocol (\r
-                  Handle,\r
-                  &gEfiDevicePathProtocolGuid,\r
-                  (VOID *) &DevicePath\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    DevicePath = NULL;\r
-  }\r
-  return DevicePath;\r
+  return UefiDevicePathLibConvertTextToDeviceNode (TextDeviceNode);\r
 }\r
 \r
 /**\r
-  Allocates a device path for a file and appends it to an existing device path.\r
+  Convert text to the binary representation of a device path.\r
 \r
-  If Device is a valid device handle that contains a device path protocol, then a device path for\r
-  the file specified by FileName  is allocated and appended to the device path associated with the\r
-  handle Device.  The allocated device path is returned.  If Device is NULL or Device is a handle\r
-  that does not support the device path protocol, then a device path containing a single device\r
-  path node for the file specified by FileName is allocated and returned.\r
-  If FileName is NULL, then ASSERT().\r
 \r
-  @param  Device                     A pointer to a device handle.  This parameter is optional and\r
-                                     may be NULL.\r
-  @param  FileName                   A pointer to a Null-terminated Unicode string.\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 The allocated device path.\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
-FileDevicePath (\r
-  IN EFI_HANDLE                      Device,     OPTIONAL\r
-  IN CONST CHAR16                    *FileName\r
+ConvertTextToDevicePath (\r
+  IN CONST CHAR16 *TextDevicePath\r
   )\r
 {\r
-  UINTN                     Size;\r
-  FILEPATH_DEVICE_PATH      *FilePath;\r
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
-  EFI_DEVICE_PATH_PROTOCOL  *FileDevicePath;\r
-\r
-  DevicePath = NULL;\r
-\r
-  Size = StrSize (FileName);\r
-  FileDevicePath = AllocatePool (Size + SIZE_OF_FILEPATH_DEVICE_PATH + EFI_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
-\r
-    DevicePath = AppendDevicePath (DevicePath, FileDevicePath);\r
-    FreePool (FileDevicePath);\r
-  }\r
-\r
-  return DevicePath;\r
+  return UefiDevicePathLibConvertTextToDevicePath (TextDevicePath);\r
 }\r
-\r