]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c
comp - add comments and add input verification
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / DmpStore.c
index 0a586591beeb2a2a53a5f8d1bb7aa27ba584b00e..60ced4ee7311771901ed2fcefe891b3a8ff754e7 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for DmpStore shell Debug1 function.\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
@@ -25,6 +25,19 @@ STATIC CHAR16   *AttrType[] = {
   L"NV+RT+BS",  // 111\r
 };\r
 \r
+/**\r
+  Function to display or delete variables.\r
+\r
+  @param[in] VariableName   The variable name of the EFI variable (or NULL).\r
+  @param[in] Guid           The GUID of the variable set (or NULL).\r
+  @param[in] Delete         TRUE to delete, FALSE otherwise.\r
+\r
+  @retval SHELL_SUCCESS           The operation was successful.\r
+  @retval SHELL_OUT_OF_RESOURCES  A memorty allocation failed.\r
+  @retval SHELL_ABORTED           The abort message was received.\r
+  @retval SHELL_DEVICE_ERROR      UEFI Variable Services returned an error.\r
+  @retval SHELL_NOT_FOUND         the Name/Guid pair could not be found.\r
+**/\r
 SHELL_STATUS\r
 EFIAPI\r
 ProcessVariables (\r
@@ -44,21 +57,26 @@ ProcessVariables (
   UINTN                     DataSize;\r
   UINT32                    Atts;\r
   SHELL_STATUS              ShellStatus;\r
+  BOOLEAN                   Found;\r
+\r
+  Status = gRT->QueryVariableInfo(EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS|EFI_VARIABLE_NON_VOLATILE, &MaxStorSize, &RemStorSize, &MaxVarSize);\r
+  if (EFI_ERROR(Status)) {\r
+    return (SHELL_DEVICE_ERROR);\r
+  }\r
 \r
+  Found         = FALSE;\r
   ShellStatus   = SHELL_SUCCESS;\r
   Size          = PcdGet16(PcdShellFileOperationSize);\r
-  FoundVarName  = AllocatePool(Size);\r
+  FoundVarName  = AllocateZeroPool(Size);\r
 \r
   if (FoundVarName == NULL) {\r
     return (SHELL_OUT_OF_RESOURCES);\r
   }\r
   FoundVarName[0] = CHAR_NULL;\r
 \r
-  Status = gRT->QueryVariableInfo(EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS|EFI_VARIABLE_NON_VOLATILE, &MaxStorSize, &RemStorSize, &MaxVarSize);\r
-  ASSERT_EFI_ERROR(Status);\r
 \r
   DataSize = (UINTN)MaxVarSize;\r
-  DataBuffer = AllocatePool(DataSize);\r
+  DataBuffer = AllocateZeroPool(DataSize);\r
   if (DataBuffer == NULL) {\r
     FreePool(FoundVarName);\r
     return (SHELL_OUT_OF_RESOURCES);\r
@@ -98,6 +116,7 @@ ProcessVariables (
     //\r
     // do the print or delete\r
     //\r
+    Found = TRUE;\r
     if (!Delete) {\r
       ShellPrintHiiEx(\r
         -1,\r
@@ -135,8 +154,19 @@ ProcessVariables (
   if (DataBuffer != NULL) {\r
     FreePool(DataBuffer);\r
   }\r
-\r
-  return (SHELL_UNSUPPORTED);\r
+  if (!Found) {\r
+    if (VariableName != NULL && Guid == NULL) {\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_N), gShellDebug1HiiHandle, VariableName);\r
+    } else if (VariableName != NULL && Guid != NULL) {\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_GN), gShellDebug1HiiHandle, Guid, VariableName);\r
+    } else if (VariableName == NULL && Guid == NULL) {\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND), gShellDebug1HiiHandle);\r
+    } else if (VariableName == NULL && Guid != NULL) {\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_G), gShellDebug1HiiHandle, Guid);\r
+    } \r
+    return (SHELL_NOT_FOUND);\r
+  }\r
+  return (SHELL_SUCCESS);\r
 }\r
 \r
 STATIC CONST SHELL_PARAM_ITEM ParamList[] = {\r
@@ -148,6 +178,12 @@ STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
   {NULL, TypeMax}\r
   };\r
 \r
+/**\r
+  Function for 'dmpstore' command.\r
+\r
+  @param[in] ImageHandle  Handle to the Image (NULL if Internal).\r
+  @param[in] SystemTable  Pointer to the System Table (NULL if Internal).\r
+**/\r
 SHELL_STATUS\r
 EFIAPI\r
 ShellCommandRunDmpStore (\r
@@ -177,10 +213,7 @@ ShellCommandRunDmpStore (
       ASSERT(FALSE);\r
     }\r
   } else {\r
-    if (ShellCommandLineGetCount(Package) < 1) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);\r
-      ShellStatus = SHELL_INVALID_PARAMETER;\r
-    } else if (ShellCommandLineGetCount(Package) > 2) {\r
+    if (ShellCommandLineGetCount(Package) > 2) {\r
       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);\r
       ShellStatus = SHELL_INVALID_PARAMETER;\r
     } else if (ShellCommandLineGetFlag(Package, L"-all") && ShellCommandLineGetFlag(Package, L"-guid")) {\r
@@ -195,14 +228,14 @@ ShellCommandRunDmpStore (
         if (Temp != NULL) {\r
           Status = ConvertStringToGuid(Temp, &GuidData);\r
           if (EFI_ERROR(Status)) {\r
-            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"-guid");\r
+            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp);\r
             ShellStatus = SHELL_INVALID_PARAMETER;\r
           }\r
           Guid = &GuidData;\r
         } else  {\r
           Guid = &gEfiGlobalVariableGuid;\r
         }\r
-        VariableName = ShellCommandLineGetRawValue(Package, 2);\r
+        VariableName = ShellCommandLineGetRawValue(Package, 1);\r
       } else {\r
         VariableName  = NULL;\r
         Guid          = NULL;\r
@@ -210,9 +243,8 @@ ShellCommandRunDmpStore (
       if (ShellStatus == SHELL_SUCCESS) {\r
         if (ShellCommandLineGetFlag(Package, L"-s") || ShellCommandLineGetFlag(Package, L"-l")) {\r
           ///@todo fix this after Jordan makes lib...\r
-          ShellPrintEx(-1, -1, L"Not implemeneted yet (ASSERT follows).\r\n");\r
-          ShellStatus = SHELL_INVALID_PARAMETER;\r
-          ASSERT(FALSE);\r
+          ShellPrintEx(-1, -1, L"Not implemeneted yet.\r\n");\r
+          ShellStatus = SHELL_UNSUPPORTED;\r
         } else {\r
           ShellStatus = ProcessVariables (VariableName, Guid, ShellCommandLineGetFlag(Package, L"-d"));\r
         }\r