]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellCommandLib/ConsistMapping.c
Comment's added and fixed.
[mirror_edk2.git] / ShellPkg / Library / UefiShellCommandLib / ConsistMapping.c
index 3425e9e912beb65d4a171251d9f9086eb0f18cb3..fc9b906ffdd53d9e1c5d1bb7e3a3a5a50f416d49 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for support of shell consist mapping.\r
 \r
-  Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2005 - 2011, 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
@@ -29,9 +29,9 @@ typedef struct {
 } POOL_PRINT;\r
 \r
 typedef struct {\r
-  UINTN       HI;\r
-  MTD_TYPE    MTD;\r
-  POOL_PRINT  CSD;\r
+  UINTN       Hi;\r
+  MTD_TYPE    Mtd;\r
+  POOL_PRINT  Csd;\r
   BOOLEAN     Digital;\r
 } DEVICE_CONSIST_MAPPING_INFO;\r
 \r
@@ -43,8 +43,8 @@ typedef struct {
 typedef struct {\r
   UINT8 Type;\r
   UINT8 SubType;\r
-  VOID (*SerialFun) (EFI_DEVICE_PATH_PROTOCOL *, DEVICE_CONSIST_MAPPING_INFO *);\r
-  INTN (*CompareFun) (EFI_DEVICE_PATH_PROTOCOL *, EFI_DEVICE_PATH_PROTOCOL *);\r
+  VOID (EFIAPI *SerialFun) (EFI_DEVICE_PATH_PROTOCOL *DevPath, DEVICE_CONSIST_MAPPING_INFO *MapInfo);\r
+  INTN (EFIAPI *CompareFun) (EFI_DEVICE_PATH_PROTOCOL *DevPath, EFI_DEVICE_PATH_PROTOCOL *DevPath2);\r
 } DEV_PATH_CONSIST_MAPPING_TABLE;\r
 \r
 \r
@@ -128,7 +128,17 @@ MTD_NAME  mMTDName[] = {
   }\r
 };\r
 \r
-VOID\r
+/**\r
+  Function to append a 64 bit number / 25 onto the string.\r
+\r
+  @param[in,out] Str          The string so append onto.\r
+  @param[in]     Num          The number to divide and append.\r
+\r
+  @retval EFI_INVALID_PARAMETER   A parameter was NULL.\r
+  @retval EFI_SUCCESS             The appending was successful.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
 AppendCSDNum2 (\r
   IN OUT POOL_PRINT       *Str,\r
   IN UINT64               Num\r
@@ -137,7 +147,9 @@ AppendCSDNum2 (
   UINT64  Result;\r
   UINT32   Rem;\r
 \r
-  ASSERT(Str != NULL);\r
+  if (Str == NULL) {\r
+    return (EFI_INVALID_PARAMETER);\r
+  }\r
 \r
   Result = DivU64x32Remainder (Num, 25, &Rem);\r
   if (Result > 0) {\r
@@ -145,35 +157,61 @@ AppendCSDNum2 (
   }\r
 \r
   CatPrint (Str, L"%c", Rem + 'a');\r
+  return (EFI_SUCCESS);\r
 }\r
 \r
-VOID\r
+/**\r
+  Function to append a 64 bit number onto the mapping info.\r
+\r
+  @param[in,out] MappingItem  The mapping info object to append onto.\r
+  @param[in]     Num          The info to append.\r
+\r
+  @retval EFI_INVALID_PARAMETER   A parameter was NULL.\r
+  @retval EFI_SUCCESS             The appending was successful.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
 AppendCSDNum (\r
-  DEVICE_CONSIST_MAPPING_INFO            *MappingItem,\r
-  UINT64                                 Num\r
+  IN OUT DEVICE_CONSIST_MAPPING_INFO            *MappingItem,\r
+  IN     UINT64                                 Num\r
   )\r
 {\r
-  ASSERT(MappingItem != NULL);\r
+  if (MappingItem == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
 \r
   if (MappingItem->Digital) {\r
-    CatPrint (&MappingItem->CSD, L"%ld", Num);\r
+    CatPrint (&MappingItem->Csd, L"%ld", Num);\r
   } else {\r
-    AppendCSDNum2 (&MappingItem->CSD, Num);\r
+    AppendCSDNum2 (&MappingItem->Csd, Num);\r
   }\r
 \r
   MappingItem->Digital = (BOOLEAN)!(MappingItem->Digital);\r
+\r
+  return (EFI_SUCCESS);\r
 }\r
 \r
-VOID\r
+/**\r
+  Function to append string into the mapping info.\r
+\r
+  @param[in,out] MappingItem  The mapping info object to append onto.\r
+  @param[in]     Str          The info to append.\r
+\r
+  @retval EFI_INVALID_PARAMETER   A parameter was NULL.\r
+  @retval EFI_SUCCESS             The appending was successful.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
 AppendCSDStr (\r
-  DEVICE_CONSIST_MAPPING_INFO            *MappingItem,\r
-  CHAR16                                 *Str\r
+  IN OUT DEVICE_CONSIST_MAPPING_INFO            *MappingItem,\r
+  IN     CHAR16                                 *Str\r
   )\r
 {\r
   CHAR16  *Index;\r
 \r
-  ASSERT(Str != NULL);\r
-  ASSERT(MappingItem != NULL);\r
+  if (Str == NULL || MappingItem == NULL) {\r
+    return (EFI_INVALID_PARAMETER);\r
+  }\r
 \r
   if (MappingItem->Digital) {\r
     //\r
@@ -192,11 +230,11 @@ AppendCSDStr (
       case '7':\r
       case '8':\r
       case '9':\r
-        CatPrint (&MappingItem->CSD, L"%c", *Index);\r
+        CatPrint (&MappingItem->Csd, L"%c", *Index);\r
         break;\r
 \r
       case '1':\r
-        CatPrint (&MappingItem->CSD, L"16");\r
+        CatPrint (&MappingItem->Csd, L"16");\r
         break;\r
 \r
       case 'a':\r
@@ -205,7 +243,7 @@ AppendCSDStr (
       case 'd':\r
       case 'e':\r
       case 'f':\r
-        CatPrint (&MappingItem->CSD, L"1%c", *Index - 'a' + '0');\r
+        CatPrint (&MappingItem->Csd, L"1%c", *Index - 'a' + '0');\r
         break;\r
 \r
       case 'A':\r
@@ -214,7 +252,7 @@ AppendCSDStr (
       case 'D':\r
       case 'E':\r
       case 'F':\r
-        CatPrint (&MappingItem->CSD, L"1%c", *Index - 'A' + '0');\r
+        CatPrint (&MappingItem->Csd, L"1%c", *Index - 'A' + '0');\r
         break;\r
       }\r
     }\r
@@ -226,27 +264,41 @@ AppendCSDStr (
       //  a  b  c  d  e  f  g  h  i  j  k  l  m  n  o  p\r
       //\r
       if (*Index >= '0' && *Index <= '9') {\r
-        CatPrint (&MappingItem->CSD, L"%c", *Index - '0' + 'a');\r
+        CatPrint (&MappingItem->Csd, L"%c", *Index - '0' + 'a');\r
       } else if (*Index >= 'a' && *Index <= 'f') {\r
-        CatPrint (&MappingItem->CSD, L"%c", *Index - 'a' + 'k');\r
+        CatPrint (&MappingItem->Csd, L"%c", *Index - 'a' + 'k');\r
       } else if (*Index >= 'A' && *Index <= 'F') {\r
-        CatPrint (&MappingItem->CSD, L"%c", *Index - 'A' + 'k');\r
+        CatPrint (&MappingItem->Csd, L"%c", *Index - 'A' + 'k');\r
       }\r
     }\r
   }\r
 \r
   MappingItem->Digital = (BOOLEAN)!(MappingItem->Digital);\r
+\r
+  return (EFI_SUCCESS);\r
 }\r
 \r
-VOID\r
+/**\r
+  Function to append a Guid to the mapping item.\r
+\r
+  @param[in,out] MappingItem  The item to append onto.\r
+  @param[in]     Guid         The guid to append.\r
+\r
+  @retval EFI_SUCCESS           The appending operation was successful.\r
+  @retval EFI_INVALID_PARAMETER A parameter was NULL.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
 AppendCSDGuid (\r
   DEVICE_CONSIST_MAPPING_INFO            *MappingItem,\r
   EFI_GUID                               *Guid\r
   )\r
 {\r
   CHAR16  Buffer[64];\r
-  ASSERT(Guid != NULL);\r
-  ASSERT(MappingItem != NULL);\r
+\r
+  if (Guid == NULL || MappingItem == NULL) {\r
+    return (EFI_INVALID_PARAMETER);\r
+  }\r
 \r
   UnicodeSPrint (\r
     Buffer,\r
@@ -254,12 +306,24 @@ AppendCSDGuid (
     L"%g",\r
     Guid\r
    );\r
-//  StrLwr (Buffer);\r
+\r
   AppendCSDStr (MappingItem, Buffer);\r
+\r
+  return (EFI_SUCCESS);\r
 }\r
 \r
+/**\r
+  Function to compare 2 APCI device paths.\r
+\r
+  @param[in] DevicePath1        The first device path to compare.\r
+  @param[in] DevicePath2        The second device path to compare.\r
+\r
+  @retval 0 The device paths represent the same device.\r
+  @return   Non zero if the devices are different, zero otherwise.\r
+**/\r
 INTN\r
-_DevPathCompareAcpi (\r
+EFIAPI\r
+DevPathCompareAcpi (\r
   IN EFI_DEVICE_PATH_PROTOCOL       *DevicePath1,\r
   IN EFI_DEVICE_PATH_PROTOCOL       *DevicePath2\r
   )\r
@@ -267,8 +331,9 @@ _DevPathCompareAcpi (
   ACPI_HID_DEVICE_PATH  *Acpi1;\r
   ACPI_HID_DEVICE_PATH  *Acpi2;\r
 \r
-  ASSERT(DevicePath1 != NULL);\r
-  ASSERT(DevicePath2 != NULL);\r
+  if (DevicePath1 == NULL || DevicePath2 == NULL) {\r
+    return (-2);\r
+  }\r
 \r
   Acpi1 = (ACPI_HID_DEVICE_PATH *) DevicePath1;\r
   Acpi2 = (ACPI_HID_DEVICE_PATH *) DevicePath2;\r
@@ -283,8 +348,18 @@ _DevPathCompareAcpi (
   return -1;\r
 }\r
 \r
+/**\r
+  Function to compare 2 PCI device paths.\r
+\r
+  @param[in] DevicePath1        The first device path to compare.\r
+  @param[in] DevicePath2        The second device path to compare.\r
+\r
+  @retval 0 The device paths represent the same device.\r
+  @return   Non zero if the devices are different, zero otherwise.\r
+**/\r
 INTN\r
-_DevPathComparePci (\r
+EFIAPI\r
+DevPathComparePci (\r
   IN EFI_DEVICE_PATH_PROTOCOL       *DevicePath1,\r
   IN EFI_DEVICE_PATH_PROTOCOL       *DevicePath2\r
   )\r
@@ -361,8 +436,8 @@ DevPathSerialHardDrive (
   ASSERT(MappingItem != NULL);\r
 \r
   Hd = (HARDDRIVE_DEVICE_PATH *) DevicePathNode;\r
-  if (MappingItem->MTD == MTDTypeUnknown) {\r
-    MappingItem->MTD = MTDTypeHardDisk;\r
+  if (MappingItem->Mtd == MTDTypeUnknown) {\r
+    MappingItem->Mtd = MTDTypeHardDisk;\r
   }\r
 \r
   AppendCSDNum (MappingItem, Hd->PartitionNumber);\r
@@ -409,7 +484,7 @@ DevPathSerialCdRom (
   ASSERT(MappingItem != NULL);\r
 \r
   Cd                = (CDROM_DEVICE_PATH *) DevicePathNode;\r
-  MappingItem->MTD  = MTDTypeCDRom;\r
+  MappingItem->Mtd  = MTDTypeCDRom;\r
   AppendCSDNum (MappingItem, Cd->BootEntry);\r
 }\r
 \r
@@ -489,6 +564,7 @@ DevPathSerialUsb (
 \r
   @param[in] DevicePathNode   The node to get info on.\r
   @param[in] MappingItem      The info item to populate.\r
+\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -499,15 +575,15 @@ DevPathSerialVendor (
 {\r
   VENDOR_DEVICE_PATH  *Vendor;\r
   SAS_DEVICE_PATH     *Sas;\r
-  EFI_GUID            SasVendorGuid = DEVICE_PATH_MESSAGING_SAS;\r
 \r
-  ASSERT(DevicePathNode != NULL);\r
-  ASSERT(MappingItem != NULL);\r
+  if (DevicePathNode == NULL || MappingItem == NULL) {\r
+    return;\r
+  }\r
 \r
   Vendor = (VENDOR_DEVICE_PATH *) DevicePathNode;\r
   AppendCSDGuid (MappingItem, &Vendor->Guid);\r
 \r
-  if (CompareGuid (&SasVendorGuid, &Vendor->Guid) == 0) {\r
+  if (CompareGuid (&gEfiSasDevicePathGuid, &Vendor->Guid)) {\r
     Sas = (SAS_DEVICE_PATH *) Vendor;\r
     AppendCSDNum (MappingItem, Sas->SasAddress);\r
     AppendCSDNum (MappingItem, Sas->Lun);\r
@@ -577,7 +653,7 @@ DevPathSerialIScsi (
 {\r
 ///@todo make this a PCD\r
 //\r
-// As CSD of ISCSI node is quite long, we comment\r
+// As Csd of ISCSI node is quite long, we comment\r
 // the code below to keep the consistent mapping\r
 // short. Uncomment if you really need it.\r
 //\r
@@ -624,13 +700,13 @@ DevPathSerialI2O (
   IN DEVICE_CONSIST_MAPPING_INFO  *MappingItem\r
   )\r
 {\r
-  I2O_DEVICE_PATH *I2O;\r
+  I2O_DEVICE_PATH *DevicePath_I20;\r
 \r
   ASSERT(DevicePathNode != NULL);\r
   ASSERT(MappingItem != NULL);\r
 \r
-  I2O = (I2O_DEVICE_PATH *) DevicePathNode;\r
-  AppendCSDNum (MappingItem, I2O->Tid);\r
+  DevicePath_I20 = (I2O_DEVICE_PATH *) DevicePathNode;\r
+  AppendCSDNum (MappingItem, DevicePath_I20->Tid);\r
 }\r
 \r
 /**\r
@@ -817,14 +893,14 @@ DevPathSerial1394 (
   IN DEVICE_CONSIST_MAPPING_INFO  *MappingItem\r
   )\r
 {\r
-  F1394_DEVICE_PATH *F1394;\r
+  F1394_DEVICE_PATH *DevicePath_F1394;\r
   CHAR16            Buffer[20];\r
 \r
   ASSERT(DevicePathNode != NULL);\r
   ASSERT(MappingItem != NULL);\r
 \r
-  F1394 = (F1394_DEVICE_PATH *) DevicePathNode;\r
-  UnicodeSPrint (Buffer, 0, L"%lx", F1394->Guid);\r
+  DevicePath_F1394 = (F1394_DEVICE_PATH *) DevicePathNode;\r
+  UnicodeSPrint (Buffer, 0, L"%lx", DevicePath_F1394->Guid);\r
   AppendCSDStr (MappingItem, Buffer);\r
 }\r
 \r
@@ -849,7 +925,7 @@ DevPathSerialAcpi (
   Acpi = (ACPI_HID_DEVICE_PATH *) DevicePathNode;\r
   if ((Acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {\r
     if (EISA_ID_TO_NUM (Acpi->HID) == 0x0604) {\r
-      MappingItem->MTD = MTDTypeFloppy;\r
+      MappingItem->Mtd = MTDTypeFloppy;\r
       AppendCSDNum (MappingItem, Acpi->UID);\r
     }\r
   }\r
@@ -858,6 +934,9 @@ DevPathSerialAcpi (
 /**\r
   Empty function used for unknown devices.\r
 \r
+  @param[in] DevicePathNode       Ignored.\r
+  @param[in] MappingItem          Ignored.\r
+\r
   Does nothing.\r
 **/\r
 VOID\r
@@ -867,17 +946,18 @@ DevPathSerialDefault (
   IN DEVICE_CONSIST_MAPPING_INFO  *MappingItem\r
   )\r
 {\r
+  return;\r
 }\r
 \r
 DEV_PATH_CONSIST_MAPPING_TABLE  DevPathConsistMappingTable[] = {\r
   HARDWARE_DEVICE_PATH,\r
   HW_PCI_DP,\r
   DevPathSerialDefault,\r
-  _DevPathComparePci,\r
+  DevPathComparePci,\r
   ACPI_DEVICE_PATH,\r
   ACPI_DP,\r
   DevPathSerialAcpi,\r
-  _DevPathCompareAcpi,\r
+  DevPathCompareAcpi,\r
   MESSAGING_DEVICE_PATH,\r
   MSG_ATAPI_DP,\r
   DevPathSerialAtapi,\r
@@ -961,8 +1041,8 @@ DEV_PATH_CONSIST_MAPPING_TABLE  DevPathConsistMappingTable[] = {
 \r
   @param[in] DevicePathNode   The node to check.\r
 \r
-  @retval TRUE    The node is HI.\r
-  @retval FALSE   The node is not HI.\r
+  @retval TRUE    The node is Hi.\r
+  @retval FALSE   The node is not Hi.\r
 **/\r
 BOOLEAN\r
 EFIAPI\r
@@ -995,11 +1075,11 @@ IsHIDevicePathNode (
 }\r
 \r
 /**\r
-  Function to convert a standard device path structure into a HI version.\r
+  Function to convert a standard device path structure into a Hi version.\r
 \r
   @param[in] DevicePath   The device path to convert.\r
 \r
-  @return   the device path portion that is HI.\r
+  @return   the device path portion that is Hi.\r
 **/\r
 EFI_DEVICE_PATH_PROTOCOL *\r
 EFIAPI\r
@@ -1017,7 +1097,7 @@ GetHIDevicePath (
 \r
   NonHIDevicePathNodeCount  = 0;\r
 \r
-  HIDevicePath              = AllocatePool (sizeof (EFI_DEVICE_PATH_PROTOCOL));\r
+  HIDevicePath              = AllocateZeroPool (sizeof (EFI_DEVICE_PATH_PROTOCOL));\r
   SetDevicePathEndNode (HIDevicePath);\r
 \r
   Node.DevPath.Type       = END_DEVICE_PATH_TYPE;\r
@@ -1063,14 +1143,14 @@ GetDeviceConsistMappingInfo (
   IN EFI_DEVICE_PATH_PROTOCOL       *DevicePath\r
   )\r
 {\r
-  VOID (*SerialFun) (EFI_DEVICE_PATH_PROTOCOL *, DEVICE_CONSIST_MAPPING_INFO *);\r
+  VOID (EFIAPI *SerialFun) (EFI_DEVICE_PATH_PROTOCOL *, DEVICE_CONSIST_MAPPING_INFO *);\r
 \r
   UINTN Index;\r
 \r
   ASSERT(DevicePath != NULL);\r
   ASSERT(MappingItem != NULL);\r
 \r
-  SetMem (&MappingItem->CSD, sizeof (POOL_PRINT), 0);\r
+  SetMem (&MappingItem->Csd, sizeof (POOL_PRINT), 0);\r
 \r
   while (!IsDevicePathEnd (DevicePath)) {\r
     //\r
@@ -1204,13 +1284,13 @@ ShellCommandConsistMappingUnInitialize (
 }\r
 \r
 /**\r
-  Create a consistent mapped name for the device specified by DevicePath \r
+  Create a consistent mapped name for the device specified by DevicePath\r
   based on the Table.\r
 \r
-  This must be called after ShellCommandConsistMappingInitialize() and \r
+  This must be called after ShellCommandConsistMappingInitialize() and\r
   before ShellCommandConsistMappingUnInitialize() is called.\r
 \r
-  @param[in] DeviecPath   The pointer to the dev path for the device.\r
+  @param[in] DevicePath   The pointer to the dev path for the device.\r
   @param[in] Table        The Table of mapping information.\r
 \r
   @retval NULL            A consistent mapped name could not be created.\r
@@ -1219,8 +1299,8 @@ ShellCommandConsistMappingUnInitialize (
 CHAR16 *\r
 EFIAPI\r
 ShellCommandConsistMappingGenMappingName (\r
-  EFI_DEVICE_PATH_PROTOCOL    *DevicePath,\r
-  EFI_DEVICE_PATH_PROTOCOL    **Table\r
+  IN EFI_DEVICE_PATH_PROTOCOL    *DevicePath,\r
+  IN EFI_DEVICE_PATH_PROTOCOL    **Table\r
   )\r
 {\r
   POOL_PRINT                  Str;\r
@@ -1248,15 +1328,15 @@ ShellCommandConsistMappingGenMappingName (
     return NULL;\r
   }\r
 \r
-  MappingInfo.HI      = Index;\r
-  MappingInfo.MTD     = MTDTypeUnknown;\r
+  MappingInfo.Hi      = Index;\r
+  MappingInfo.Mtd     = MTDTypeUnknown;\r
   MappingInfo.Digital = FALSE;\r
 \r
   GetDeviceConsistMappingInfo (&MappingInfo, DevicePath);\r
 \r
   SetMem (&Str, sizeof (Str), 0);\r
   for (Index = 0; mMTDName[Index].MTDType != MTDTypeEnd; Index++) {\r
-    if (MappingInfo.MTD == mMTDName[Index].MTDType) {\r
+    if (MappingInfo.Mtd == mMTDName[Index].MTDType) {\r
       break;\r
     }\r
   }\r
@@ -1265,10 +1345,10 @@ ShellCommandConsistMappingGenMappingName (
     CatPrint (&Str, L"%s", mMTDName[Index].Name);\r
   }\r
 \r
-  CatPrint (&Str, L"%d", (UINTN) MappingInfo.HI);\r
-  if (MappingInfo.CSD.Str != NULL) {\r
-    CatPrint (&Str, L"%s", MappingInfo.CSD.Str);\r
-    FreePool (MappingInfo.CSD.Str);\r
+  CatPrint (&Str, L"%d", (UINTN) MappingInfo.Hi);\r
+  if (MappingInfo.Csd.Str != NULL) {\r
+    CatPrint (&Str, L"%s", MappingInfo.Csd.Str);\r
+    FreePool (MappingInfo.Csd.Str);\r
   }\r
 \r
   if (Str.Str != NULL) {\r
@@ -1277,6 +1357,9 @@ ShellCommandConsistMappingGenMappingName (
 \r
   NewSize           = (Str.Len + 1) * sizeof (CHAR16);\r
   Str.Str           = ReallocatePool (Str.Len, NewSize, Str.Str);\r
+  if (Str.Str == NULL) {\r
+    return (NULL);\r
+  }\r
   Str.Str[Str.Len]  = CHAR_NULL;\r
   return Str.Str;\r
 }\r