]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c
ShellPkg/dh: Modify the dump of "ImageDevicePath" and "DevicePath"
[mirror_edk2.git] / ShellPkg / Library / UefiHandleParsingLib / UefiHandleParsingLib.c
index d3ee068ebaf62711ad22455c7b3fb4b4ac001d6f..1f2ca92bddbe6bd6420c9af1df80208d77343e2a 100644 (file)
@@ -847,6 +847,50 @@ ConvertDevicePathToShortText(
   return (Temp);\r
 }\r
 \r
+/**\r
+  Function to dump protocol information.\r
+\r
+  This will allocate the return buffer from boot services pool.\r
+\r
+  @param[in] TheHandle      The handle that has the protocol installed.\r
+  @param[in] Verbose        TRUE for additional information, FALSE otherwise.\r
+  @param[in] Protocol       The protocol is needed to dump.\r
+\r
+  @retval A pointer to a string containing the information.\r
+**/\r
+STATIC CHAR16*\r
+EFIAPI\r
+DevicePathProtocolDumpInformationEx (\r
+  IN CONST EFI_HANDLE   TheHandle,\r
+  IN CONST BOOLEAN      Verbose,\r
+  IN       EFI_GUID     *Protocol\r
+)\r
+{\r
+  EFI_DEVICE_PATH_PROTOCOL          *DevPath;\r
+  CHAR16                            *DevPathStr;\r
+  CHAR16                            *DevPathStrTemp;\r
+  UINTN                             Size;\r
+  EFI_STATUS                        Status;\r
+  DevPathStr     = NULL;\r
+  DevPathStrTemp = NULL;\r
+  Status = gBS->OpenProtocol(TheHandle, Protocol, (VOID**)&DevPath, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r
+  if (!EFI_ERROR(Status)) {\r
+    DevPathStr = ConvertDevicePathToShortText (DevPath, Verbose, 30);\r
+    if (Verbose) {\r
+      Size = StrSize(DevPathStr) + sizeof(CHAR16) * 2;\r
+      DevPathStrTemp = AllocateZeroPool (Size);\r
+      if (DevPathStrTemp != NULL) {\r
+        StrnCatS (DevPathStrTemp, Size/sizeof(CHAR16), L"  ", 2);\r
+        StrnCatS (DevPathStrTemp, Size/sizeof(CHAR16), DevPathStr, StrLen (DevPathStr));\r
+      }\r
+      FreePool (DevPathStr);\r
+      DevPathStr = DevPathStrTemp;\r
+    }\r
+    gBS->CloseProtocol(TheHandle, Protocol, gImageHandle, NULL);\r
+  }\r
+  return DevPathStr;\r
+}\r
+\r
 /**\r
   Function to dump information about DevicePath protocol.\r
 \r
@@ -864,17 +908,7 @@ DevicePathProtocolDumpInformation(
   IN CONST BOOLEAN    Verbose\r
   )\r
 {\r
-  EFI_DEVICE_PATH_PROTOCOL          *DevPath;\r
-  CHAR16                            *Temp;\r
-  EFI_STATUS                        Status;\r
-  Temp = NULL;\r
-\r
-  Status = gBS->OpenProtocol(TheHandle, &gEfiDevicePathProtocolGuid, (VOID**)&DevPath, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r
-  if (!EFI_ERROR(Status)) {\r
-    Temp = ConvertDevicePathToShortText (DevPath, Verbose, 30);\r
-    gBS->CloseProtocol(TheHandle, &gEfiDevicePathProtocolGuid, gImageHandle, NULL);\r
-  }\r
-  return (Temp);\r
+  return DevicePathProtocolDumpInformationEx (TheHandle, Verbose, &gEfiDevicePathProtocolGuid);\r
 }\r
 \r
 /**\r
@@ -894,17 +928,7 @@ LoadedImageDevicePathProtocolDumpInformation(
   IN CONST BOOLEAN    Verbose\r
   )\r
 {\r
-  EFI_DEVICE_PATH_PROTOCOL          *DevPath;\r
-  CHAR16                            *Temp;\r
-  EFI_STATUS                        Status;\r
-  Temp = NULL;\r
-\r
-  Status = gBS->OpenProtocol(TheHandle, &gEfiLoadedImageDevicePathProtocolGuid, (VOID**)&DevPath, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r
-  if (!EFI_ERROR(Status)) {\r
-    Temp = ConvertDevicePathToShortText (DevPath, Verbose, 30);\r
-    gBS->CloseProtocol(TheHandle, &gEfiDevicePathProtocolGuid, gImageHandle, NULL);\r
-  }\r
-  return (Temp);\r
+  return DevicePathProtocolDumpInformationEx (TheHandle, Verbose, &gEfiLoadedImageDevicePathProtocolGuid);\r
 }\r
 \r
 /**\r