]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellCommandLib/ConsistMapping.c
ShellPkg: Refine the code to reduce time cost of 'map -r'
[mirror_edk2.git] / ShellPkg / Library / UefiShellCommandLib / ConsistMapping.c
index 48739e20fd3059ab9ade003cbf4acfbea1557edd..86e8dc59a8951bab39356886c7ec2428e32d6110 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for support of shell consist mapping.\r
 \r
-  Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2005 - 2015, 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
 #include <Library/SortLib.h>\r
 #include <Library/UefiLib.h>\r
 #include <Protocol/UsbIo.h>\r
+#include <Protocol/BlockIo.h>\r
+#include <Protocol/SimpleFileSystem.h>\r
+\r
+\r
 \r
 typedef enum {\r
   MTDTypeUnknown,\r
@@ -42,12 +46,26 @@ typedef struct {
   CHAR16    *Name;\r
 } MTD_NAME;\r
 \r
-typedef VOID (EFIAPI *SerialDecodeFucntion) (EFI_DEVICE_PATH_PROTOCOL *DevPath, DEVICE_CONSIST_MAPPING_INFO *MapInfo,EFI_DEVICE_PATH_PROTOCOL *);\r
+/**\r
+  Serial Decode function.\r
+\r
+  @param  DevPath          The Device path info.\r
+  @param  MapInfo          The map info.\r
+  @param  OrigDevPath      The original device path protocol.\r
+\r
+**/\r
+typedef \r
+VOID \r
+(EFIAPI *SERIAL_DECODE_FUNCTION) (\r
+  EFI_DEVICE_PATH_PROTOCOL    *DevPath, \r
+  DEVICE_CONSIST_MAPPING_INFO *MapInfo,\r
+  EFI_DEVICE_PATH_PROTOCOL    *OrigDevPath\r
+  );\r
 \r
 typedef struct {\r
   UINT8 Type;\r
   UINT8 SubType;\r
-  SerialDecodeFucntion SerialFun;\r
+  SERIAL_DECODE_FUNCTION SerialFun;\r
   INTN (EFIAPI *CompareFun) (EFI_DEVICE_PATH_PROTOCOL *DevPath, EFI_DEVICE_PATH_PROTOCOL *DevPath2);\r
 } DEV_PATH_CONSIST_MAPPING_TABLE;\r
 \r
@@ -102,7 +120,7 @@ CatPrint (
     ASSERT (Str->Str != NULL);\r
   }\r
 \r
-  StrnCat (Str->Str, AppendStr, StringSize/sizeof(CHAR16) - 1 - StrLen(Str->Str));\r
+  StrCatS (Str->Str, StringSize/sizeof(CHAR16), AppendStr);\r
   Str->Len = StringSize;\r
 \r
   FreePool (AppendStr);\r
@@ -426,6 +444,7 @@ DevPathCompareDefault (
 \r
   @param[in] DevicePathNode   The node to get info on.\r
   @param[in] MappingItem      The info item to populate.\r
+  @param[in] DevicePath       Ignored.\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -453,6 +472,7 @@ DevPathSerialHardDrive (
 \r
   @param[in] DevicePathNode   The node to get info on.\r
   @param[in] MappingItem      The info item to populate.\r
+  @param[in] DevicePath       Ignored.\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -476,6 +496,7 @@ DevPathSerialAtapi (
 \r
   @param[in] DevicePathNode   The node to get info on.\r
   @param[in] MappingItem      The info item to populate.\r
+  @param[in] DevicePath       Ignored.\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -500,6 +521,7 @@ DevPathSerialCdRom (
 \r
   @param[in] DevicePathNode   The node to get info on.\r
   @param[in] MappingItem      The info item to populate.\r
+  @param[in] DevicePath       Ignored.\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -524,6 +546,7 @@ DevPathSerialFibre (
 \r
   @param[in] DevicePathNode   The node to get info on.\r
   @param[in] MappingItem      The info item to populate.\r
+  @param[in] DevicePath       Ignored.\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -550,6 +573,7 @@ DevPathSerialUart (
 \r
   @param[in] DevicePathNode   The node to get info on.\r
   @param[in] MappingItem      The info item to populate.\r
+  @param[in] DevicePath       Ignored.\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -608,6 +632,7 @@ DevPathSerialUsb (
 \r
   @param[in] DevicePathNode   The node to get info on.\r
   @param[in] MappingItem      The info item to populate.\r
+  @param[in] DevicePath       Ignored.\r
 \r
 **/\r
 VOID\r
@@ -671,6 +696,7 @@ DevPathSerialVendor (
 \r
   @param[in] DevicePathNode   The node to get info on.\r
   @param[in] MappingItem      The info item to populate.\r
+  @param[in] DevicePath       Ignored.\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -694,6 +720,7 @@ DevPathSerialLun (
 \r
   @param[in] DevicePathNode   The node to get info on.\r
   @param[in] MappingItem      The info item to populate.\r
+  @param[in] DevicePath       Ignored.\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -719,6 +746,7 @@ DevPathSerialSata (
 \r
   @param[in] DevicePathNode   The node to get info on.\r
   @param[in] MappingItem      The info item to populate.\r
+  @param[in] DevicePath       Ignored.\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -763,6 +791,7 @@ DevPathSerialIScsi (
 \r
   @param[in] DevicePathNode   The node to get info on.\r
   @param[in] MappingItem      The info item to populate.\r
+  @param[in] DevicePath       Ignored.\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -786,6 +815,7 @@ DevPathSerialI2O (
 \r
   @param[in] DevicePathNode   The node to get info on.\r
   @param[in] MappingItem      The info item to populate.\r
+  @param[in] DevicePath       Ignored.\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -823,6 +853,7 @@ DevPathSerialMacAddr (
 \r
   @param[in] DevicePathNode   The node to get info on.\r
   @param[in] MappingItem      The info item to populate.\r
+  @param[in] DevicePath       Ignored.\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -856,6 +887,7 @@ DevPathSerialInfiniBand (
 \r
   @param[in] DevicePathNode   The node to get info on.\r
   @param[in] MappingItem      The info item to populate.\r
+  @param[in] DevicePath       Ignored.\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -901,6 +933,8 @@ DevPathSerialIPv4 (
 \r
   @param[in] DevicePathNode   The node to get info on.\r
   @param[in] MappingItem      The info item to populate.\r
+  @param[in] DevicePath       Ignored.\r
+\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -938,6 +972,8 @@ DevPathSerialIPv6 (
 \r
   @param[in] DevicePathNode   The node to get info on.\r
   @param[in] MappingItem      The info item to populate.\r
+  @param[in] DevicePath       Ignored.\r
+\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -962,6 +998,7 @@ DevPathSerialScsi (
 \r
   @param[in] DevicePathNode   The node to get info on.\r
   @param[in] MappingItem      The info item to populate.\r
+  @param[in] DevicePath       Ignored.\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -987,6 +1024,7 @@ DevPathSerial1394 (
 \r
   @param[in] DevicePathNode   The node to get info on.\r
   @param[in] MappingItem      The info item to populate.\r
+  @param[in] DevicePath       Ignored.\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -1015,6 +1053,7 @@ DevPathSerialAcpi (
 \r
   @param[in] DevicePathNode       Ignored.\r
   @param[in] MappingItem          Ignored.\r
+  @param[in] DevicePath           Ignored.\r
 \r
   Does nothing.\r
 **/\r
@@ -1265,7 +1304,7 @@ GetDeviceConsistMappingInfo (
   IN EFI_DEVICE_PATH_PROTOCOL       *DevicePath\r
   )\r
 {\r
-  SerialDecodeFucntion      SerialFun;\r
+  SERIAL_DECODE_FUNCTION    SerialFun;\r
   UINTN                     Index;\r
   EFI_DEVICE_PATH_PROTOCOL  *OriginalDevicePath;\r
 \r
@@ -1314,20 +1353,22 @@ ShellCommandConsistMappingInitialize (
   OUT EFI_DEVICE_PATH_PROTOCOL           ***Table\r
   )\r
 {\r
-  EFI_HANDLE                *HandleBuffer;\r
-  UINTN                     HandleNum;\r
-  UINTN                     HandleLoop;\r
-  EFI_DEVICE_PATH_PROTOCOL  **TempTable;\r
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
-  EFI_DEVICE_PATH_PROTOCOL  *HIDevicePath;\r
-  UINTN                     Index;\r
-  EFI_STATUS                Status;\r
+  EFI_HANDLE                      *HandleBuffer;\r
+  UINTN                           HandleNum;\r
+  UINTN                           HandleLoop;\r
+  EFI_DEVICE_PATH_PROTOCOL        **TempTable;\r
+  EFI_DEVICE_PATH_PROTOCOL        *DevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL        *HIDevicePath;\r
+  EFI_BLOCK_IO_PROTOCOL           *BlockIo;\r
+  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFileSystem;\r
+  UINTN                           Index;\r
+  EFI_STATUS                      Status;\r
 \r
   HandleBuffer              = NULL;\r
 \r
   Status = gBS->LocateHandleBuffer (\r
-              AllHandles,\r
-              NULL,\r
+              ByProtocol,\r
+              &gEfiDevicePathProtocolGuid,\r
               NULL,\r
               &HandleNum,\r
               &HandleBuffer\r
@@ -1350,6 +1391,20 @@ ShellCommandConsistMappingInitialize (
       continue;\r
     }\r
 \r
+    Status = gBS->HandleProtocol( HandleBuffer[HandleLoop], \r
+                                  &gEfiBlockIoProtocolGuid, \r
+                                  (VOID **)&BlockIo\r
+                                  );\r
+    if (EFI_ERROR(Status)) {\r
+      Status = gBS->HandleProtocol( HandleBuffer[HandleLoop], \r
+                                    &gEfiSimpleFileSystemProtocolGuid, \r
+                                    (VOID **)&SimpleFileSystem\r
+                                    );\r
+      if (EFI_ERROR(Status)) {\r
+        continue;\r
+      }\r
+    }\r
+\r
     for (Index = 0; TempTable[Index] != NULL; Index++) {\r
       if (DevicePathCompare (&TempTable[Index], &HIDevicePath) == 0) {\r
         FreePool (HIDevicePath);\r