]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Cd - add more input verification.
authorjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 25 Mar 2011 20:58:08 +0000 (20:58 +0000)
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 25 Mar 2011 20:58:08 +0000 (20:58 +0000)
Cp - support "\" as root of drive indicator.
Load - invert "-nc" to not connect.
Ls - ignore archive file attribute.
Map - add more input verification.  fix add by handle.
Mv - support overwrite question. support "\" as root of drive indicator.
Parse - add comments.
Rm - add comments.
TimeDate - add more input verification. add comments.
Vol - add new command.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11426 6f19259b-4bc3-4df7-8a09-765794883524

14 files changed:
ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c
ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c
ShellPkg/Library/UefiShellLevel2CommandsLib/Load.c
ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c
ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c
ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c
ShellPkg/Library/UefiShellLevel2CommandsLib/Parse.c
ShellPkg/Library/UefiShellLevel2CommandsLib/Rm.c
ShellPkg/Library/UefiShellLevel2CommandsLib/TimeDate.c
ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c
ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.h
ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.inf
ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.uni
ShellPkg/Library/UefiShellLevel2CommandsLib/Vol.c [new file with mode: 0644]

index 99680b49d9abf8f318e3e168f9e7161407ebd61a..bee4b0ae43989d8486fa5b3e8acced18b6a9034f 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for attrib shell level 2 function.\r
 \r
-  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 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
@@ -192,14 +192,20 @@ ShellCommandRunCd (
         } else {\r
           Drive = StrCpy(Drive, Param1);\r
           Path = StrStr(Drive, L":");\r
-          *(++Path) = CHAR_NULL;\r
-          if (Path == Drive + StrLen(Drive)) {\r
+          ASSERT(Path != NULL);\r
+          if (*(Path+1) == CHAR_NULL) {\r
             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r
             ShellStatus = SHELL_NOT_FOUND;\r
           } else {\r
-            Status = gEfiShellProtocol->SetCurDir(Drive, ++Path);\r
+            *(Path+1) = CHAR_NULL;\r
+            if (Path == Drive + StrLen(Drive)) {\r
+              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r
+              ShellStatus = SHELL_NOT_FOUND;\r
+            } else {\r
+              Status = gEfiShellProtocol->SetCurDir(Drive, Path+2);\r
+              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_PRINT), gShellLevel2HiiHandle, ShellGetCurrentDir(Drive));\r
+            }\r
           }\r
-\r
           if (Status == EFI_NOT_FOUND) {\r
             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r
             Status = SHELL_NOT_FOUND;\r
index f15ff3030a65a362d970e8306f746add3e3a9fae..8c0bbce9aa021e2d15bc4636d17e9a23e2ffdcee 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for cp shell level 2 function.\r
 \r
-  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 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
 \r
 #include "UefiShellLevel2CommandsLib.h"\r
 \r
-// this is later in the file.\r
+/**\r
+  Function to take a list of files to copy and a destination location and do\r
+  the verification and copying of those files to that location.  This function\r
+  will report any errors to the user and halt.\r
+\r
+  @param[in] FileList           A LIST_ENTRY* based list of files to move.\r
+  @param[in] DestDir            The destination location.\r
+  @param[in] SilentMode         TRUE to eliminate screen output.\r
+  @param[in] RecursiveMode      TRUE to copy directories.\r
+  @param[in] Resp               The response to the overwrite query (if always).\r
+\r
+  @retval SHELL_SUCCESS             the files were all moved.\r
+  @retval SHELL_INVALID_PARAMETER   a parameter was invalid\r
+  @retval SHELL_SECURITY_VIOLATION  a security violation ocurred\r
+  @retval SHELL_WRITE_PROTECTED     the destination was write protected\r
+  @retval SHELL_OUT_OF_RESOURCES    a memory allocation failed\r
+**/\r
 SHELL_STATUS\r
 EFIAPI\r
 ValidateAndCopyFiles(\r
@@ -89,7 +105,7 @@ CopySingleFile(
   //\r
   if (!EFI_ERROR(Status)) {\r
     if (Response == NULL && !SilentMode) {\r
-      Status = ShellPromptForResponseHii(ShellPromptResponseTypeYesNoAllCancel, STRING_TOKEN (STR_CP_PROMPT), gShellLevel2HiiHandle, &Response);\r
+      Status = ShellPromptForResponseHii(ShellPromptResponseTypeYesNoAllCancel, STRING_TOKEN (STR_GEN_DEST_EXIST_OVR), gShellLevel2HiiHandle, &Response);\r
     }\r
     //\r
     // possibly return based on response\r
@@ -191,8 +207,11 @@ CopySingleFile(
   The key is to have this function called ONLY once.  this allows for the parameter\r
   verification to happen correctly.\r
 \r
-  @param[in] FileList           A LIST_ENTRY* based list of files to move\r
-  @param[in] DestDir            the destination location\r
+  @param[in] FileList           A LIST_ENTRY* based list of files to move.\r
+  @param[in] DestDir            The destination location.\r
+  @param[in] SilentMode         TRUE to eliminate screen output.\r
+  @param[in] RecursiveMode      TRUE to copy directories.\r
+  @param[in] Resp               The response to the overwrite query (if always).\r
 \r
   @retval SHELL_SUCCESS             the files were all moved.\r
   @retval SHELL_INVALID_PARAMETER   a parameter was invalid\r
@@ -257,7 +276,7 @@ ValidateAndCopyFiles(
     }\r
 \r
     NewSize =  StrSize(DestDir);\r
-    NewSize += StrSize(Node->FileName);\r
+    NewSize += StrSize(Node->FullName);\r
     NewSize += StrSize(Cwd);\r
     if (NewSize > PathLen) {\r
       PathLen = NewSize;\r
@@ -285,7 +304,7 @@ ValidateAndCopyFiles(
 \r
   HiiOutput   = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_CP_OUTPUT), NULL);\r
   HiiResultOk = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_GEN_RES_OK), NULL);\r
-  DestPath    = AllocatePool(PathLen);\r
+  DestPath    = AllocateZeroPool(PathLen);\r
 \r
   if (DestPath == NULL || HiiOutput == NULL || HiiResultOk == NULL) {\r
     SHELL_FREE_NON_NULL(DestPath);\r
@@ -317,17 +336,20 @@ ValidateAndCopyFiles(
     if (FileList->Link.ForwardLink == FileList->Link.BackLink // 1 item\r
       && EFI_ERROR(ShellIsDirectory(DestDir))                 // not an existing directory\r
      ) {\r
-      ASSERT(StrStr(DestDir, L":") == NULL);\r
-      //\r
-      // simple copy of a single file\r
-      //\r
-      StrCpy(DestPath, Cwd);\r
-      if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {\r
-        StrCat(DestPath, L"\\");\r
-      } else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {\r
-        ((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;\r
+      if (StrStr(DestDir, L":") == NULL) {\r
+        //\r
+        // simple copy of a single file\r
+        //\r
+        StrCpy(DestPath, Cwd);\r
+        if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {\r
+          StrCat(DestPath, L"\\");\r
+        } else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {\r
+          ((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;\r
+        }\r
+        StrCat(DestPath, DestDir);\r
+      } else {\r
+        StrCpy(DestPath, DestDir);\r
       }\r
-      StrCat(DestPath, DestDir);\r
     } else {\r
       //\r
       // we have multiple files or a directory in the DestDir\r
@@ -415,6 +437,18 @@ ValidateAndCopyFiles(
   return (ShellStatus);\r
 }\r
 \r
+/**\r
+  Validate and if successful copy all the files from the list into \r
+  destination directory.\r
+\r
+  @param[in] FileList       The list of files to copy.\r
+  @param[in] DestDir        The directory to copy files to.\r
+  @param[in] SilentMode     TRUE to eliminate screen output.\r
+  @param[in] RecursiveMode  TRUE to copy directories.\r
+\r
+  @retval SHELL_INVALID_PARAMETER   A parameter was invalid.\r
+  @retval SHELL_SUCCESS             The operation was successful.\r
+**/\r
 SHELL_STATUS\r
 EFIAPI\r
 ProcessValidateAndCopyFiles(\r
@@ -437,7 +471,6 @@ ProcessValidateAndCopyFiles(
     ShellStatus = SHELL_INVALID_PARAMETER;\r
     ShellCloseFileMetaArg(&List);\r
   } else if (List != NULL) {\r
-    ASSERT(List != NULL);\r
     ASSERT(((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink) != NULL);\r
     ASSERT(((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->FullName != NULL);\r
     FileInfo    = NULL;\r
index 1e29ad62e1bb3a09a475e22001893a43414cf521..5edb9d77355067bfdb1095a3a58fb88d6210fe99 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for attrib shell level 2 function.\r
 \r
-  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 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
@@ -248,9 +248,9 @@ ShellCommandRunLoad (
             // once we have an error preserve that value, but finish the loop.\r
             //\r
             if (EFI_ERROR(Status)) {\r
-              LoadDriver(Node->FullName, ShellCommandLineGetFlag(Package, L"-nc"));\r
+              LoadDriver(Node->FullName, (BOOLEAN)(ShellCommandLineGetFlag(Package, L"-nc")==FALSE));\r
             } else {\r
-              Status = LoadDriver(Node->FullName, ShellCommandLineGetFlag(Package, L"-nc"));\r
+              Status = LoadDriver(Node->FullName, (BOOLEAN)(ShellCommandLineGetFlag(Package, L"-nc")==FALSE));\r
             }\r
           } // for loop for multi-open\r
           if (EFI_ERROR(Status)) {\r
index 440d2450f5c068ef537564493fb66ab93f8841fe..73765113f47444fbf4950d4a86ac299c2a63a468 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for ls shell level 2 function.\r
 \r
-  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 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
@@ -234,7 +234,7 @@ PrintLsOutput(
         //\r
         // exact match on all bits\r
         //\r
-        if ( Node->Info->Attribute != Attribs) {\r
+        if ( (Node->Info->Attribute|EFI_FILE_ARCHIVE) != (Attribs|EFI_FILE_ARCHIVE)) {\r
           continue;\r
         }\r
       }\r
@@ -348,7 +348,7 @@ PrintLsOutput(
   }\r
 \r
   if (Rec){\r
-    DirectoryName = AllocatePool(LongestPath + 2*sizeof(CHAR16));\r
+    DirectoryName = AllocateZeroPool(LongestPath + 2*sizeof(CHAR16));\r
     if (DirectoryName == NULL) {\r
       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellLevel2HiiHandle);\r
       ShellStatus = SHELL_OUT_OF_RESOURCES;\r
@@ -417,7 +417,7 @@ ShellCommandRunLs (
   UINTN         Count;\r
   CHAR16        *FullPath;\r
   UINTN         Size;\r
-  EFI_TIME      theTime;\r
+  EFI_TIME      TheTime;\r
   BOOLEAN       SfoMode;\r
 \r
   Size                = 0;\r
@@ -532,7 +532,7 @@ ShellCommandRunLs (
           ASSERT(FullPath == NULL);\r
           StrnCatGrow(&FullPath, NULL, L"*", 0);\r
         }\r
-        Status = gRT->GetTime(&theTime, NULL);\r
+        Status = gRT->GetTime(&TheTime, NULL);\r
         ASSERT_EFI_ERROR(Status);\r
         SfoMode = ShellCommandLineGetFlag(Package, L"-sfo");\r
         if (ShellStatus == SHELL_SUCCESS) {\r
@@ -543,7 +543,7 @@ ShellCommandRunLs (
             FullPath,\r
             TRUE,\r
             Count,\r
-            (INT16)(theTime.TimeZone==2047?0:theTime.TimeZone)\r
+            (INT16)(TheTime.TimeZone==2047?0:TheTime.TimeZone)\r
            );\r
           if (ShellStatus == SHELL_NOT_FOUND) {\r
             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_FILES), gShellLevel2HiiHandle);\r
index d74a47ba52585f2a95355fbb58f34bf22af0e4c4..2b608a02cf620d97a02f72d998456087aae6fd47 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for map shell level 2 command.\r
 \r
-  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 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
 #include <Library/HandleParsingLib.h>\r
 #include <Library/SortLib.h>\r
 \r
+/**\r
+  Determine if a string has only numbers and letters.\r
+\r
+  This is useful for such things as Map names which can only be letters and numbers.\r
+\r
+  @param[in] String       pointer to the string to analyze,\r
+  @param[in] Len          Number of characters to analyze.\r
+\r
+  @retval TRUE            String has only numbers and letters\r
+  @retval FALSE           String has at least one other character.\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+IsNumberLetterOnly(\r
+  IN CONST CHAR16 *String,\r
+  IN CONST UINTN  Len\r
+  )\r
+{\r
+  UINTN Count;\r
+  for (Count = 0 ; Count < Len && String != NULL && *String != CHAR_NULL ; String++,Count++) {\r
+    if (! ((*String >= L'a' && *String <= L'z') ||\r
+           (*String >= L'A' && *String <= L'Z') ||\r
+           (*String >= L'0' && *String <= L'9'))\r
+        ){\r
+      return (FALSE);\r
+    }\r
+  }\r
+  return (TRUE);\r
+}\r
+\r
+/**\r
+  Do a search in the Target delimited list.\r
+\r
+  @param[in] List         The list to seatch in.\r
+  @param[in] MetaTarget   The item to search for. MetaMatching supported.\r
+  @param[out] FullName    Optional pointer to an allocated buffer containing \r
+                          the match.\r
+  @param[in] Meta         TRUE to use MetaMatching.\r
+  @param[in] SkipTrailingNumbers  TRUE to allow for numbers after the MetaTarget.\r
+  @param[in] Target       The single character that delimits list \r
+                          items (";" normally). \r
+**/\r
 BOOLEAN\r
 EFIAPI\r
 SearchList(\r
@@ -75,6 +117,11 @@ SearchList(
   return (FALSE);\r
 }\r
 \r
+/**\r
+  Add mappings for any devices without one.  Do not change any existing maps.\r
+\r
+  @retval EFI_SUCCESS   The operation was successful.\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 UpdateMapping (\r
@@ -109,7 +156,7 @@ UpdateMapping (
     //\r
     // Get all Device Paths\r
     //\r
-    DevicePathList = AllocatePool(sizeof(EFI_DEVICE_PATH_PROTOCOL*) * Count);\r
+    DevicePathList = AllocateZeroPool(sizeof(EFI_DEVICE_PATH_PROTOCOL*) * Count);\r
     ASSERT(DevicePathList != NULL);\r
 \r
     for (Count = 0 ; HandleList[Count] != NULL ; Count++) {\r
@@ -172,6 +219,18 @@ UpdateMapping (
   return (Status);\r
 }\r
 \r
+/**\r
+  Determine what type of device is represented and return it's string.  The \r
+  string is in allocated memory and must be callee freed.  The HII is is listed below.\r
+  The actual string cannot be determined.\r
+\r
+  @param[in] DevicePath     The device to analyze.\r
+\r
+  @retval STR_MAP_MEDIA_UNKNOWN   The media type is unknown.\r
+  @retval STR_MAP_MEDIA_HARDDISK  The media is a hard drive.\r
+  @retval STR_MAP_MEDIA_CDROM     The media is a CD ROM.\r
+  @retval STR_MAP_MEDIA_FLOPPY    The media is a floppy drive.\r
+**/\r
 CHAR16*\r
 EFIAPI\r
 GetDeviceMediaType (\r
@@ -265,18 +324,27 @@ MappingListHasType(
   IN CONST BOOLEAN    Consist\r
   )\r
 {\r
+  CHAR16 *NewSpecific;\r
   //\r
   // specific has priority\r
   //\r
-  if ( Specific != NULL\r
-    && SearchList(MapList, Specific, NULL, TRUE, FALSE, L";")) {\r
-    return (TRUE);\r
-  }\r
+  if (Specific != NULL) {\r
+    NewSpecific = AllocateZeroPool(StrSize(Specific) + sizeof(CHAR16));\r
+    StrCpy(NewSpecific, Specific);\r
+    if (NewSpecific[StrLen(NewSpecific)-1] != L':') {\r
+      StrCat(NewSpecific, L":");\r
+    }\r
 \r
+    if (SearchList(MapList, NewSpecific, NULL, TRUE, FALSE, L";")) {\r
+      FreePool(NewSpecific);\r
+      return (TRUE);\r
+    }\r
+    FreePool(NewSpecific);\r
+  }\r
   if (  Consist\r
     && (SearchList(MapList, L"HD*",  NULL, TRUE, TRUE, L";")\r
       ||SearchList(MapList, L"CD*",  NULL, TRUE, TRUE, L";")\r
-      ||SearchList(MapList, L"F*",   NULL, TRUE, TRUE, L";")\r
+      ||SearchList(MapList, L"AnyF*",   NULL, TRUE, TRUE, L";")\r
       ||SearchList(MapList, L"FP*",  NULL, TRUE, TRUE, L";"))){\r
     return (TRUE);\r
   }\r
@@ -294,7 +362,20 @@ MappingListHasType(
 }\r
 \r
 \r
-VOID\r
+/**\r
+  Display a single map line for device Handle if conditions are met.\r
+\r
+  @param[in] Verbose                TRUE to display (extra) verbose information.\r
+  @param[in] Consist                TRUE to display consistent mappings.\r
+  @param[in] Normal                 TRUE to display normal (not consist) mappings.\r
+  @param[in] TypeString             pointer to string of filter types.\r
+  @param[in] SFO                    TRUE to display output in Standard Output Format.\r
+  @param[in] Specific               pointer to string for specific map to display.\r
+  @param[in] Handle                 The handle to display from.\r
+\r
+  @retval EFI_SUCCESS               The mapping was displayed.\r
+**/\r
+EFI_STATUS\r
 EFIAPI\r
 PerformSingleMappingDisplay(\r
   IN CONST BOOLEAN    Verbose,\r
@@ -321,11 +402,11 @@ PerformSingleMappingDisplay(
   DevPathCopy = DevPath;\r
   MapList = gEfiShellProtocol->GetMapFromDevicePath(&DevPathCopy);\r
   if (MapList == NULL) {\r
-    return;\r
+    return EFI_NOT_FOUND;\r
   }\r
 \r
   if (!MappingListHasType(MapList, Specific, TypeString, Normal, Consist)){\r
-    return;\r
+    return EFI_NOT_FOUND;\r
   }\r
 \r
   CurrentName = NULL;\r
@@ -384,9 +465,18 @@ PerformSingleMappingDisplay(
   }\r
   FreePool(DevPathString);\r
   FreePool(CurrentName);\r
-  return;\r
+  return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Delete Specific from the list of maps for device Handle.\r
+\r
+  @param[in] Specific   The name to delete.\r
+  @param[in] Handle     The device to look on.\r
+\r
+  @retval EFI_SUCCESS     The delete was successful.\r
+  @retval EFI_NOT_FOUND   Name was not a map on Handle.\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 PerformSingleMappingDelete(\r
@@ -416,6 +506,10 @@ PerformSingleMappingDelete(
   return (gEfiShellProtocol->SetMap(NULL, CurrentName));\r
 }\r
 \r
+CONST CHAR16 Cd[] = L"cd*";\r
+CONST CHAR16 Hd[] = L"hd*";\r
+CONST CHAR16 Fp[] = L"fp*";\r
+CONST CHAR16 AnyF[] = L"F*";\r
 /**\r
   Function to display mapping information to the user.\r
 \r
@@ -433,10 +527,6 @@ PerformSingleMappingDelete(
   @retval SHELL_INVALID_PARAMETER     one of Consist or Normal must be TRUE if no Specific\r
 \r
 **/\r
-CONST CHAR16 Cd[] = L"cd*";\r
-CONST CHAR16 Hd[] = L"hd*";\r
-CONST CHAR16 Fp[] = L"fp*";\r
-CONST CHAR16 F[] = L"F*";\r
 SHELL_STATUS\r
 EFIAPI\r
 PerformMappingDisplay(\r
@@ -454,6 +544,7 @@ PerformMappingDisplay(
   UINTN                     BufferSize;\r
   UINTN                     LoopVar;\r
   CHAR16                    *Test;\r
+  BOOLEAN                   Found;\r
 \r
   if (!Consist && !Normal && Specific == NULL && TypeString == NULL) {\r
     ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle);\r
@@ -471,7 +562,7 @@ PerformMappingDisplay(
           return (SHELL_INVALID_PARAMETER);\r
         }\r
       } else if (Test == NULL) {\r
-        Test = (CHAR16*)F;\r
+        Test = (CHAR16*)AnyF;\r
       }\r
     }\r
   } else {\r
@@ -497,33 +588,31 @@ PerformMappingDisplay(
   //\r
   Status = gBS->LocateHandle(\r
     ByProtocol,\r
-    &gEfiDevicePathProtocolGuid,\r
+    &gEfiSimpleFileSystemProtocolGuid,\r
     NULL,\r
     &BufferSize,\r
     HandleBuffer);\r
   if (Status == EFI_BUFFER_TOO_SMALL) {\r
-    HandleBuffer = AllocatePool(BufferSize);\r
+    HandleBuffer = AllocateZeroPool(BufferSize);\r
     if (HandleBuffer == NULL) {\r
       return (SHELL_OUT_OF_RESOURCES);\r
     }\r
     Status = gBS->LocateHandle(\r
       ByProtocol,\r
-      &gEfiDevicePathProtocolGuid,\r
+      &gEfiSimpleFileSystemProtocolGuid,\r
       NULL,\r
       &BufferSize,\r
       HandleBuffer);\r
   }\r
-  ASSERT_EFI_ERROR(Status);\r
-  ASSERT(HandleBuffer != NULL);\r
 \r
   //\r
   // Get the map name(s) for each one.\r
   //\r
-  for ( LoopVar = 0\r
+  for ( LoopVar = 0, Found = FALSE\r
       ; LoopVar < (BufferSize / sizeof(EFI_HANDLE))\r
       ; LoopVar ++\r
      ){\r
-    PerformSingleMappingDisplay(\r
+    Status = PerformSingleMappingDisplay(\r
       Verbose,\r
       Consist,\r
       Normal,\r
@@ -531,6 +620,9 @@ PerformMappingDisplay(
       SFO,\r
       Specific,\r
       HandleBuffer[LoopVar]);\r
+    if (!EFI_ERROR(Status)) {\r
+      Found = TRUE;\r
+    }\r
   }\r
 \r
   //\r
@@ -544,7 +636,7 @@ PerformMappingDisplay(
     HandleBuffer);\r
   if (Status == EFI_BUFFER_TOO_SMALL) {\r
     FreePool(HandleBuffer);\r
-    HandleBuffer = AllocatePool(BufferSize);\r
+    HandleBuffer = AllocateZeroPool(BufferSize);\r
     if (HandleBuffer == NULL) {\r
       return (SHELL_OUT_OF_RESOURCES);\r
     }\r
@@ -568,14 +660,14 @@ PerformMappingDisplay(
       //\r
       if (gBS->OpenProtocol(\r
         HandleBuffer[LoopVar],\r
-        &gEfiDevicePathProtocolGuid,\r
+        &gEfiSimpleFileSystemProtocolGuid,\r
         NULL,\r
         gImageHandle,\r
         NULL,\r
         EFI_OPEN_PROTOCOL_TEST_PROTOCOL) == EFI_SUCCESS) {\r
           continue;\r
       }\r
-      PerformSingleMappingDisplay(\r
+      Status = PerformSingleMappingDisplay(\r
         Verbose,\r
         Consist,\r
         Normal,\r
@@ -583,12 +675,32 @@ PerformMappingDisplay(
         SFO,\r
         Specific,\r
         HandleBuffer[LoopVar]);\r
+      if (!EFI_ERROR(Status)) {\r
+        Found = TRUE;\r
+      }\r
     }\r
     FreePool(HandleBuffer);\r
   }\r
+  if (!Found) {\r
+    ShellPrintHiiEx(gST->ConOut->Mode->CursorColumn, gST->ConOut->Mode->CursorRow-1, NULL, STRING_TOKEN (STR_MAP_NF), gShellLevel2HiiHandle, Specific);\r
+  }\r
   return (SHELL_SUCCESS);\r
 }\r
 \r
+/**\r
+  Perform a mapping display and parse for multiple types in the TypeString.\r
+\r
+  @param[in] Verbose      TRUE to use verbose output.\r
+  @param[in] Consist      TRUE to display consistent names.\r
+  @param[in] Normal       TRUE to display normal names.\r
+  @param[in] TypeString   An optional comma-delimited list of types.\r
+  @param[in] SFO          TRUE to display in SFO format.  See Spec.\r
+  @param[in] Specific     An optional specific map name to display alone.\r
+\r
+  @retval SHELL_INVALID_PARAMETER   A parameter was invalid.\r
+  @retval SHELL_SUCCESS             The display was successful.\r
+  @sa PerformMappingDisplay\r
+**/\r
 SHELL_STATUS\r
 EFIAPI\r
 PerformMappingDisplay2(\r
@@ -633,6 +745,15 @@ PerformMappingDisplay2(
   return (ShellStatus);\r
 }\r
 \r
+/**\r
+  Delete a specific map.\r
+\r
+  @param[in] Specific  The pointer to the name of the map to delete.\r
+\r
+  @retval EFI_INVALID_PARAMETER     Specific was NULL.\r
+  @retval EFI_SUCCESS               The operation was successful.\r
+  @retval EFI_NOT_FOUND             Specific could not be found.\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 PerformMappingDelete(\r
@@ -663,7 +784,7 @@ PerformMappingDelete(
     &BufferSize,\r
     HandleBuffer);\r
   if (Status == EFI_BUFFER_TOO_SMALL) {\r
-    HandleBuffer = AllocatePool(BufferSize);\r
+    HandleBuffer = AllocateZeroPool(BufferSize);\r
     if (HandleBuffer == NULL) {\r
       return (EFI_OUT_OF_RESOURCES);\r
     }\r
@@ -703,7 +824,7 @@ PerformMappingDelete(
     HandleBuffer);\r
   if (Status == EFI_BUFFER_TOO_SMALL) {\r
     FreePool(HandleBuffer);\r
-    HandleBuffer = AllocatePool(BufferSize);\r
+    HandleBuffer = AllocateZeroPool(BufferSize);\r
     if (HandleBuffer == NULL) {\r
       return (EFI_OUT_OF_RESOURCES);\r
     }\r
@@ -773,54 +894,33 @@ AddMappingFromMapping(
 {\r
   CONST EFI_DEVICE_PATH_PROTOCOL  *DevPath;\r
   EFI_STATUS                      Status;\r
+  CHAR16                          *NewSName;\r
+  \r
+  NewSName = AllocateZeroPool(StrSize(SName) + sizeof(CHAR16));\r
+  StrCpy(NewSName, SName);\r
+  if (NewSName[StrLen(NewSName)-1] != L':') {\r
+    StrCat(NewSName, L":");\r
+  }\r
 \r
-  if (StrStr(SName, L"*") != NULL\r
-    ||StrStr(SName, L"?") != NULL\r
-    ||StrStr(SName, L"[") != NULL\r
-    ||StrStr(SName, L"]") != NULL) {\r
+  if (!IsNumberLetterOnly(NewSName, StrLen(NewSName)-1)) {\r
+    FreePool(NewSName);\r
     return (SHELL_INVALID_PARAMETER);\r
   }\r
 \r
   DevPath = gEfiShellProtocol->GetDevicePathFromMap(Map);\r
   if (DevPath == NULL) {\r
+    FreePool(NewSName);\r
     return (SHELL_INVALID_PARAMETER);\r
   }\r
 \r
-  Status = gEfiShellProtocol->SetMap(DevPath, SName);\r
+  Status = gEfiShellProtocol->SetMap(DevPath, NewSName);\r
+  FreePool(NewSName);\r
   if (EFI_ERROR(Status)) {\r
     return (SHELL_DEVICE_ERROR);\r
   }\r
   return (SHELL_SUCCESS);\r
 }\r
 \r
-/**\r
-  function to determine if a string has only numbers and letters\r
-\r
-  This is useful for such things as Map names which can only be letters and numbers\r
-\r
-  @param[in] String       pointer to the string to analyze\r
-\r
-  @retval TRUE            String has only numbers and letters\r
-  @retval FALSE           String has at least one other character.\r
-**/\r
-BOOLEAN\r
-EFIAPI\r
-IsNumberLetterOnly(\r
-  IN CONST CHAR16 *String\r
-  )\r
-{\r
-  while(String != NULL && *String != CHAR_NULL) {\r
-    if (! ((*String >= L'a' && *String <= L'z') ||\r
-           (*String >= L'A' && *String <= L'Z') ||\r
-           (*String >= L'0' && *String <= L'9'))\r
-        ){\r
-      return (FALSE);\r
-    }\r
-    String++;\r
-  }\r
-  return (TRUE);\r
-}\r
-\r
 /**\r
   function to add a mapping from an EFI_HANDLE.\r
 \r
@@ -844,8 +944,16 @@ AddMappingFromHandle(
 {\r
   EFI_DEVICE_PATH_PROTOCOL  *DevPath;\r
   EFI_STATUS                Status;\r
+  CHAR16                    *NewSName;\r
+  \r
+  NewSName = AllocateZeroPool(StrSize(SName) + sizeof(CHAR16));\r
+  StrCpy(NewSName, SName);\r
+  if (NewSName[StrLen(NewSName)-1] != L':') {\r
+    StrCat(NewSName, L":");\r
+  }\r
 \r
-  if (!IsNumberLetterOnly(SName)) {\r
+  if (!IsNumberLetterOnly(NewSName, StrLen(NewSName)-1)) {\r
+    FreePool(NewSName);\r
     return (SHELL_INVALID_PARAMETER);\r
   }\r
 \r
@@ -858,9 +966,11 @@ AddMappingFromHandle(
     EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
    );\r
   if (EFI_ERROR(Status)) {\r
+    FreePool(NewSName);\r
     return (SHELL_DEVICE_ERROR);\r
   }\r
-  Status = gEfiShellProtocol->SetMap(DevPath, SName);\r
+  Status = gEfiShellProtocol->SetMap(DevPath, NewSName);\r
+  FreePool(NewSName);\r
   if (EFI_ERROR(Status)) {\r
     return (SHELL_DEVICE_ERROR);\r
   }\r
@@ -897,7 +1007,7 @@ ShellCommandRunMap (
   CHAR16        *ProblemParam;\r
   CONST CHAR16  *SName;\r
   CONST CHAR16  *Mapping;\r
-  EFI_HANDLE    MappingAsHandle;\r
+  EFI_HANDLE    MapAsHandle;\r
   CONST EFI_DEVICE_PATH_PROTOCOL *DevPath;\r
   SHELL_STATUS  ShellStatus;\r
   BOOLEAN       SfoMode;\r
@@ -905,13 +1015,14 @@ ShellCommandRunMap (
   BOOLEAN       NormlMode;\r
   CONST CHAR16  *Param1;\r
   CONST CHAR16  *TypeString;\r
+  UINTN         TempStringLength;\r
 \r
   ProblemParam  = NULL;\r
   Mapping       = NULL;\r
   SName         = NULL;\r
   DevPath       = NULL;\r
   ShellStatus   = SHELL_SUCCESS;\r
-  MappingAsHandle = NULL;\r
+  MapAsHandle = NULL;\r
 \r
   //\r
   // initialize the shell lib (we must be in non-auto-init...)\r
@@ -1082,18 +1193,30 @@ ShellCommandRunMap (
            );\r
         } else {\r
           if (ShellIsHexOrDecimalNumber(Mapping, TRUE, FALSE)) {\r
-            MappingAsHandle = ConvertHandleIndexToHandle(StrHexToUintn(Mapping));\r
+            MapAsHandle = ConvertHandleIndexToHandle(ShellStrToUintn(Mapping));\r
           } else {\r
-            MappingAsHandle = NULL;\r
+            MapAsHandle = NULL;\r
           }\r
-          if (MappingAsHandle == NULL && Mapping[StrLen(Mapping)-1] != L':') {\r
+          if (MapAsHandle == NULL && Mapping[StrLen(Mapping)-1] != L':') {\r
             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, Mapping);\r
             ShellStatus = SHELL_INVALID_PARAMETER;\r
           } else {\r
-            if (MappingAsHandle != NULL) {\r
-              ShellStatus = AddMappingFromHandle(MappingAsHandle, SName);\r
+            if (MapAsHandle != NULL) {\r
+              TempStringLength = StrLen(SName);\r
+              if (!IsNumberLetterOnly(SName, TempStringLength-(SName[TempStringLength-1]==L':'?1:0))) {\r
+                ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, SName);\r
+                ShellStatus = SHELL_INVALID_PARAMETER;\r
+              } else {\r
+                ShellStatus = AddMappingFromHandle(MapAsHandle, SName);\r
+              }\r
             } else {\r
-              ShellStatus = AddMappingFromMapping(Mapping, SName);\r
+              TempStringLength = StrLen(SName);\r
+              if (!IsNumberLetterOnly(SName, TempStringLength-(SName[TempStringLength-1]==L':'?1:0))) {\r
+                ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, SName);\r
+                ShellStatus = SHELL_INVALID_PARAMETER;\r
+              } else {\r
+                ShellStatus = AddMappingFromMapping(Mapping, SName);\r
+              }\r
             }\r
             if (ShellStatus != SHELL_SUCCESS) {\r
               switch (ShellStatus) {\r
@@ -1103,6 +1226,9 @@ ShellCommandRunMap (
                 case SHELL_INVALID_PARAMETER:\r
                   ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle);\r
                   break;\r
+                case SHELL_DEVICE_ERROR:\r
+                  ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MAP_NOF), gShellLevel2HiiHandle, Mapping);\r
+                  break;\r
                 default:\r
                   ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, ShellStatus|MAX_BIT);\r
               }\r
index 7530289a52f56d8e00ff316261693d9ba7e7adca..dc9ef64d7f317c14fa77ff5b167411d6bebee051 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for mv shell level 2 function.\r
 \r
-  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 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
@@ -116,12 +116,13 @@ IsValidMove(
 \r
   if the result is sucessful the caller must free *DestPathPointer.\r
 \r
-  @param[in] DestDir              The original path to the destination\r
-  @param[in,out] DestPathPointer  a pointer to the callee allocated final path.\r
+  @param[in] DestDir              The original path to the destination.\r
+  @param[in,out] DestPathPointer  A pointer to the callee allocated final path.\r
+  @param[in] Cwd                  A pointer to the current working directory.\r
 \r
-  @retval EFI_INVALID_PARAMETR  the DestDir could not be resolved to a location\r
-  @retval EFI_INVALID_PARAMETR  the DestDir could be resolved to more than 1 location\r
-  @retval EFI_SUCCESS           the operation was sucessful\r
+  @retval EFI_INVALID_PARAMETR  The DestDir could not be resolved to a location.\r
+  @retval EFI_INVALID_PARAMETR  The DestDir could be resolved to more than 1 location.\r
+  @retval EFI_SUCCESS           The operation was sucessful.\r
 **/\r
 SHELL_STATUS\r
 EFIAPI\r
@@ -140,6 +141,17 @@ GetDestinationLocation(
 \r
   DestList = NULL;\r
   DestPath = NULL;\r
+\r
+  if (StrStr(DestDir, L"\\") == DestDir) {\r
+    DestPath = AllocateZeroPool(StrSize(Cwd));\r
+    if (DestPath == NULL) {\r
+      return (SHELL_OUT_OF_RESOURCES);\r
+    }\r
+    StrCpy(DestPath, Cwd);\r
+    while (ChopLastSlash(DestPath)) ;\r
+    *DestPathPointer =  DestPath;\r
+    return (SHELL_SUCCESS);\r
+  }\r
   //\r
   // get the destination path\r
   //\r
@@ -211,6 +223,7 @@ GetDestinationLocation(
   will report any errors to the user and continue to move the rest of the files.\r
 \r
   @param[in] FileList           A LIST_ENTRY* based list of files to move\r
+  @param[out] Resp              pointer to response from question.  Pass back on looped calling\r
   @param[in] DestDir            the destination location\r
 \r
   @retval SHELL_SUCCESS             the files were all moved.\r
@@ -223,6 +236,7 @@ SHELL_STATUS
 EFIAPI\r
 ValidateAndMoveFiles(\r
   IN CONST EFI_SHELL_FILE_INFO  *FileList,\r
+  OUT VOID                      **Resp,\r
   IN CONST CHAR16               *DestDir\r
   )\r
 {\r
@@ -237,12 +251,15 @@ ValidateAndMoveFiles(
   CHAR16                    *TempLocation;\r
   UINTN                     NewSize;\r
   UINTN                     Length;\r
+  VOID                      *Response;\r
+  SHELL_FILE_HANDLE         DestHandle;\r
 \r
   ASSERT(FileList != NULL);\r
   ASSERT(DestDir  != NULL);\r
 \r
   DestPath = NULL;\r
   Cwd      = ShellGetCurrentDir(NULL);\r
+  Response = *Resp;\r
 \r
   //\r
   // Get and validate the destination location\r
@@ -251,6 +268,7 @@ ValidateAndMoveFiles(
   if (ShellStatus != SHELL_SUCCESS) {\r
     return (ShellStatus);\r
   }\r
+  DestPath = CleanPath(DestPath);\r
 \r
   HiiOutput   = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_MV_OUTPUT), NULL);\r
   HiiResultOk = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_GEN_RES_OK), NULL);\r
@@ -325,9 +343,45 @@ ValidateAndMoveFiles(
         StrCat(NewFileInfo->FileName, Node->FileName);\r
       }\r
       NewFileInfo->Size = sizeof(EFI_FILE_INFO) + StrSize(NewFileInfo->FileName);\r
-\r
       ShellPrintEx(-1, -1, HiiOutput, Node->FullName, NewFileInfo->FileName);\r
 \r
+      if (!EFI_ERROR(ShellFileExists(NewFileInfo->FileName))) {\r
+        if (Response == NULL) {\r
+          ShellPromptForResponseHii(ShellPromptResponseTypeYesNoAllCancel, STRING_TOKEN (STR_GEN_DEST_EXIST_OVR), gShellLevel2HiiHandle, &Response);\r
+        }\r
+        switch (*(SHELL_PROMPT_RESPONSE*)Response) {\r
+          case ShellPromptResponseNo:\r
+            FreePool(NewFileInfo);\r
+            continue;\r
+          case ShellPromptResponseCancel:\r
+            *Resp = Response;\r
+            //\r
+            // indicate to stop everything\r
+            //\r
+            FreePool(NewFileInfo);\r
+            FreePool(DestPath);\r
+            FreePool(HiiOutput);\r
+            FreePool(HiiResultOk);\r
+            return (SHELL_ABORTED);\r
+          case ShellPromptResponseAll:\r
+            *Resp = Response;\r
+            break;\r
+          case ShellPromptResponseYes:\r
+            FreePool(Response);\r
+            break;\r
+          default:\r
+            FreePool(Response);\r
+            FreePool(NewFileInfo);\r
+            FreePool(DestPath);\r
+            FreePool(HiiOutput);\r
+            FreePool(HiiResultOk);\r
+            return SHELL_ABORTED;\r
+        }\r
+        Status = ShellOpenFileByName(NewFileInfo->FileName, &DestHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0);\r
+        ShellDeleteFile(&DestHandle);\r
+      }\r
+\r
+\r
       //\r
       // Perform the move operation\r
       //\r
@@ -336,7 +390,6 @@ ValidateAndMoveFiles(
       //\r
       // Free the info object we used...\r
       //\r
-      ASSERT  (NewFileInfo != NULL);\r
       FreePool(NewFileInfo);\r
 \r
       //\r
@@ -373,6 +426,12 @@ ValidateAndMoveFiles(
   return (ShellStatus);\r
 }\r
 \r
+/**\r
+  Function for 'mv' 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
 ShellCommandRunMv (\r
@@ -387,11 +446,13 @@ ShellCommandRunMv (
   UINTN               ParamCount;\r
   UINTN               LoopCounter;\r
   EFI_SHELL_FILE_INFO *FileList;\r
+  VOID                *Response;\r
 \r
   ProblemParam        = NULL;\r
   ShellStatus         = SHELL_SUCCESS;\r
   ParamCount          = 0;\r
   FileList            = NULL;\r
+  Response            = NULL;\r
 \r
   //\r
   // initialize the shell lib (we must be in non-auto-init...)\r
@@ -444,20 +505,20 @@ ShellCommandRunMv (
             //\r
             // ValidateAndMoveFiles will report errors to the screen itself\r
             //\r
-            ShellStatus = ValidateAndMoveFiles(FileList, ShellGetCurrentDir(NULL));\r
+            ShellStatus = ValidateAndMoveFiles(FileList, &Response, ShellGetCurrentDir(NULL));\r
           }\r
         }\r
 \r
         break;\r
       default:\r
         ///@todo make sure this works with error half way through and continues...\r
-        for (ParamCount--, LoopCounter = 1 ; LoopCounter < ParamCount && ShellStatus == SHELL_SUCCESS ; LoopCounter++) {\r
+        for (ParamCount--, LoopCounter = 1 ; LoopCounter < ParamCount ; LoopCounter++) {\r
           if (ShellGetExecutionBreakFlag()) {\r
             break;\r
           }\r
           Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, LoopCounter), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);\r
           if (FileList == NULL || IsListEmpty(&FileList->Link) || EFI_ERROR(Status)) {\r
-            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1));\r
+            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, LoopCounter));\r
             ShellStatus = SHELL_NOT_FOUND;\r
           } else  {\r
             //\r
@@ -465,9 +526,9 @@ ShellCommandRunMv (
             // Only change ShellStatus if it's sucessful\r
             //\r
             if (ShellStatus == SHELL_SUCCESS) {\r
-              ShellStatus = ValidateAndMoveFiles(FileList, ShellCommandLineGetRawValue(Package, ParamCount));\r
+              ShellStatus = ValidateAndMoveFiles(FileList, &Response, ShellCommandLineGetRawValue(Package, ParamCount));\r
             } else {\r
-              ValidateAndMoveFiles(FileList, ShellCommandLineGetRawValue(Package, ParamCount));\r
+              ValidateAndMoveFiles(FileList, &Response, ShellCommandLineGetRawValue(Package, ParamCount));\r
             }\r
           }\r
           if (FileList != NULL && !IsListEmpty(&FileList->Link)) {\r
@@ -491,6 +552,8 @@ ShellCommandRunMv (
     ShellCommandLineFreeVarList (Package);\r
   }\r
 \r
+  SHELL_FREE_NON_NULL(Response);\r
+\r
   if (ShellGetExecutionBreakFlag()) {\r
     return (SHELL_ABORTED);\r
   }\r
index 927c8d972993dbd373d51baa468a769fa3aad0b8..1cdc9e32e302dc6e467bdebfdd61da8cbe9455e2 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for Parse shell level 2 function.\r
 \r
-  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 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
 \r
 #include "UefiShellLevel2CommandsLib.h"\r
 \r
+/**\r
+  Do the actual parsing of the file.  the file should be SFO output from a \r
+  shell command or a similar format.\r
+\r
+  @param[in] FileName               The filename to open.\r
+  @param[in] TableName              The name of the table to find.\r
+  @param[in] ColumnIndex            The column number to get.\r
+  @param[in] TableNameInstance      Which instance of the table to get (row).\r
+  @param[in] ShellCommandInstance   Which instance of the command to get.\r
+\r
+  @retval SHELL_NOT_FOUND     The requested instance was not found.\r
+  @retval SHELL_SUCCESS       The operation was successful.\r
+**/\r
 SHELL_STATUS\r
 EFIAPI\r
 PerformParsing(\r
index bde710faf044f9be2a4b1df3728f71c2c581e24c..ea3792a3be1fb8a33b44c623643e507f244ee974 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for attrib shell level 2 function.\r
 \r
-  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 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
@@ -19,6 +19,14 @@ STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
   {NULL, TypeMax}\r
   };\r
 \r
+/**\r
+  Determine if a directory has no files in it.\r
+\r
+  @param[in] FileHandle   The EFI_HANDLE to the directory.\r
+  \r
+  @retval TRUE  The directory has no files (or directories).\r
+  @retval FALSE The directory has at least 1 file or directory in it.\r
+**/\r
 BOOLEAN\r
 EFIAPI\r
 IsDirectoryEmpty (\r
@@ -45,6 +53,17 @@ IsDirectoryEmpty (
   return (RetVal);\r
 }\r
 \r
+/**\r
+  Delete a node and all nodes under it (including sub directories).\r
+\r
+  @param[in] Node   The node to start deleting with.\r
+  @param[in] Quiet  TRUE to print no messages.\r
+\r
+  @retval SHELL_SUCCESS       The operation was successful.\r
+  @retval SHELL_ACCESS_DENIED A file was read only.\r
+  @retval SHELL_ABORTED       The abort message was received.\r
+  @retval SHELL_DEVICE_ERROR  A device error occured reading this Node.\r
+**/\r
 SHELL_STATUS\r
 EFIAPI\r
 CascadeDelete(\r
@@ -126,7 +145,7 @@ CascadeDelete(
   }\r
 \r
   //\r
-  // We cant allow for the warning here!\r
+  // We cant allow for the warning here! (Dont use EFI_ERROR Macro).\r
   //\r
   if (Status != EFI_SUCCESS){\r
     ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE_ERR), gShellLevel2HiiHandle, Status);\r
@@ -137,6 +156,13 @@ CascadeDelete(
   }\r
 }\r
 \r
+/**\r
+  Determins if a Node is a valid delete target.  Will prevent deleting the root directory.\r
+\r
+  @param[in] List       RESERVED.  Not used.\r
+  @param[in] Node       The node to analyze.\r
+  @param[in] Package    RESERVED.  Not used.\r
+**/\r
 BOOLEAN\r
 EFIAPI\r
 IsValidDeleteTarget(\r
index c8de9cf066e4d1e59197892312136b43aec39282..510aa60b2a85bccf4dd391fbe6ea676efbb0428f 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for time, timezone, and date shell level 2 and shell level 3 functions.\r
 \r
-  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 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
 \r
 #include "UefiShellLevel2CommandsLib.h"\r
 \r
-INT16\r
-EFIAPI\r
-AbsVal(\r
-  INT16 v\r
-  )\r
-{\r
-  if (v>0) {\r
-    return (v);\r
-  }\r
-  return ((INT16)(-v));\r
-}\r
+/**\r
+  Determine if String is a valid representation for a time or date.\r
+\r
+  @param[in] String     The pointer to the string to test.\r
+  @param[in] Char       The delimeter character.\r
+  @param[in] Min        The minimum value allowed.\r
+  @param[in] Max        The maximum value allowed.\r
+  @param[in] MinusOk    Whether negative numbers are permitted.\r
 \r
+  @retval TRUE    String is a valid representation.\r
+  @retval FALSE   String is invalid.\r
+**/\r
 BOOLEAN\r
 EFIAPI\r
 InternalIsTimeLikeString (\r
@@ -75,6 +75,16 @@ InternalIsTimeLikeString (
   return (TRUE);\r
 }\r
 \r
+/**\r
+  Verify that the DateString is valid and if so set that as the current \r
+  date.\r
+\r
+  @param[in] DateString     The pointer to a string representation of the date.\r
+\r
+  @retval SHELL_INVALID_PARAMETER   DateString was NULL.\r
+  @retval SHELL_INVALID_PARAMETER   DateString was mis-formatted.\r
+  @retval SHELL_SUCCESS             The operation was successful.\r
+**/\r
 SHELL_STATUS\r
 EFIAPI\r
 CheckAndSetDate (\r
@@ -83,7 +93,9 @@ CheckAndSetDate (
 {\r
   EFI_TIME      TheTime;\r
   EFI_STATUS    Status;\r
-  CONST CHAR16  *Walker;\r
+  CHAR16        *DateStringCopy;\r
+  CHAR16        *Walker;\r
+  CHAR16        *Walker1;\r
 \r
   if (!InternalIsTimeLikeString(DateString, L'/', 2, 2, FALSE)) {\r
     return (SHELL_INVALID_PARAMETER);\r
@@ -92,25 +104,41 @@ CheckAndSetDate (
   Status = gRT->GetTime(&TheTime, NULL);\r
   ASSERT_EFI_ERROR(Status);\r
 \r
-  Walker = DateString;\r
+  DateStringCopy = NULL;\r
+  DateStringCopy = StrnCatGrow(&DateStringCopy, NULL, DateString, 0);\r
+  if (DateStringCopy == NULL) {\r
+    return (SHELL_OUT_OF_RESOURCES);\r
+  }\r
+  Walker = DateStringCopy;\r
 \r
   TheTime.Month = 0xFF;\r
   TheTime.Day   = 0xFF;\r
   TheTime.Year  = 0xFFFF;\r
 \r
-  TheTime.Month = (UINT8)StrDecimalToUintn (Walker);\r
-  Walker = StrStr(Walker, L"/");\r
-  if (Walker != NULL && *Walker == L'/') {\r
-    Walker = Walker + 1;\r
+  Walker1 = StrStr(Walker, L"/");\r
+  if (Walker1 != NULL && *Walker1 == L'/') {\r
+    *Walker1 = CHAR_NULL;\r
+  }\r
+\r
+  TheTime.Month = (UINT8)ShellStrToUintn (Walker);\r
+  if (Walker1 != NULL) {\r
+    Walker = Walker1 + 1;\r
+  }\r
+  Walker1 = StrStr(Walker, L"/");\r
+  if (Walker1 != NULL && *Walker1 == L'/') {\r
+    *Walker1 = CHAR_NULL;\r
   }\r
   if (Walker != NULL && Walker[0] != CHAR_NULL) {\r
-    TheTime.Day = (UINT8)StrDecimalToUintn (Walker);\r
-    Walker = StrStr(Walker, L"/");\r
-    if (Walker != NULL && *Walker == L'/') {\r
-      Walker = Walker + 1;\r
+    TheTime.Day = (UINT8)ShellStrToUintn (Walker);\r
+    if (Walker1 != NULL) {\r
+      Walker = Walker1 + 1;\r
+    }\r
+    Walker1 = StrStr(Walker, L"/");\r
+    if (Walker1 != NULL && *Walker1 == L'/') {\r
+      *Walker1 = CHAR_NULL;\r
     }\r
     if (Walker != NULL && Walker[0] != CHAR_NULL) {\r
-      TheTime.Year = (UINT16)StrDecimalToUintn (Walker);\r
+      TheTime.Year = (UINT16)ShellStrToUintn (Walker);\r
     }\r
   }\r
 \r
@@ -241,6 +269,18 @@ STATIC CONST SHELL_PARAM_ITEM TimeParamList3[] = {
   {NULL, TypeMax}\r
   };\r
 \r
+/**\r
+  Verify that the TimeString is valid and if so set that as the current \r
+  time.\r
+\r
+  @param[in] TimeString     The pointer to a string representation of the time.\r
+  @param[in] Tz             The value to set for TimeZone.\r
+  @param[in] Daylight       The value to set for Daylight.\r
+\r
+  @retval SHELL_INVALID_PARAMETER   TimeString was NULL.\r
+  @retval SHELL_INVALID_PARAMETER   TimeString was mis-formatted.\r
+  @retval SHELL_SUCCESS             The operation was successful.\r
+**/\r
 SHELL_STATUS\r
 EFIAPI\r
 CheckAndSetTime (\r
@@ -251,7 +291,9 @@ CheckAndSetTime (
 {\r
   EFI_TIME      TheTime;\r
   EFI_STATUS    Status;\r
-  CONST CHAR16  *Walker;\r
+  CHAR16        *TimeStringCopy;\r
+  CHAR16        *Walker1;\r
+  CHAR16        *Walker2;\r
 \r
   if (TimeString != NULL && !InternalIsTimeLikeString(TimeString, L':', 1, 2, FALSE)) {\r
     return (SHELL_INVALID_PARAMETER);\r
@@ -259,30 +301,40 @@ CheckAndSetTime (
 \r
   Status = gRT->GetTime(&TheTime, NULL);\r
   ASSERT_EFI_ERROR(Status);\r
+  TimeStringCopy = NULL;\r
+  TimeStringCopy = StrnCatGrow(&TimeStringCopy, NULL, TimeString, 0);\r
 \r
   if (TimeString != NULL) {\r
-    Walker          = TimeString;\r
+    Walker1          = TimeStringCopy;\r
     TheTime.Hour    = 0xFF;\r
     TheTime.Minute  = 0xFF;\r
 \r
-    TheTime.Hour    = (UINT8)StrDecimalToUintn (Walker);\r
-    Walker          = StrStr(Walker, L":");\r
-    if (Walker != NULL && *Walker == L':') {\r
-      Walker = Walker + 1;\r
+    Walker2          = StrStr(Walker1, L":");\r
+    if (Walker2 != NULL && *Walker2 == L':') {\r
+      *Walker2 = CHAR_NULL;\r
     }\r
-    if (Walker != NULL && Walker[0] != CHAR_NULL) {\r
-      TheTime.Minute = (UINT8)StrDecimalToUintn (Walker);\r
-      Walker = StrStr(Walker, L":");\r
-      if (Walker != NULL && *Walker == L':') {\r
-        Walker = Walker + 1;\r
+    TheTime.Hour    = (UINT8)ShellStrToUintn (Walker1);\r
+    if (Walker2 != NULL) {\r
+      Walker1 = Walker2 + 1;\r
+    }\r
+    Walker2          = StrStr(Walker1, L":");\r
+    if (Walker2 != NULL && *Walker2 == L':') {\r
+      *Walker2 = CHAR_NULL;\r
+    }\r
+    if (Walker1 != NULL && Walker1[0] != CHAR_NULL) {\r
+      TheTime.Minute = (UINT8)ShellStrToUintn (Walker1);\r
+      if (Walker2 != NULL) {\r
+        Walker1 = Walker2 + 1;\r
       }\r
-      if (Walker != NULL && Walker[0] != CHAR_NULL) {\r
-        TheTime.Second = (UINT8)StrDecimalToUintn (Walker);\r
+      if (Walker1 != NULL && Walker1[0] != CHAR_NULL) {\r
+        TheTime.Second = (UINT8)ShellStrToUintn (Walker1);\r
       }\r
     }\r
   }\r
 \r
-  if ((Tz >= -1440 && Tz <= 1440)||(Tz == 2047)) {\r
+  FreePool(TimeStringCopy);\r
+\r
+  if ((Tz >= -1440 && Tz <= 1440)||(Tz == 0x7FF)) {\r
     TheTime.TimeZone = Tz;\r
   }\r
   if (Daylight <= 3 && Daylight != 2) {\r
@@ -376,7 +428,7 @@ ShellCommandRunTime (
         if (TheTime.TimeZone == 2047) {\r
           TzMinutes = 0;\r
         } else {\r
-          TzMinutes = AbsVal(TheTime.TimeZone) % 60;\r
+          TzMinutes = (ABS(TheTime.TimeZone)) % 60;\r
         }\r
 \r
         ShellPrintHiiEx (\r
@@ -389,7 +441,7 @@ ShellCommandRunTime (
           TheTime.Minute,\r
           TheTime.Second,\r
           TheTime.TimeZone==2047?L" ":(TheTime.TimeZone > 0?L"-":L"+"),\r
-          TheTime.TimeZone==2047?0:AbsVal(TheTime.TimeZone) / 60,\r
+          TheTime.TimeZone==2047?0:(ABS(TheTime.TimeZone)) / 60,\r
           TzMinutes\r
          );\r
          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CRLF), gShellLevel2HiiHandle);\r
@@ -397,7 +449,7 @@ ShellCommandRunTime (
         if (TheTime.TimeZone == 2047) {\r
           TzMinutes = 0;\r
         } else {\r
-          TzMinutes = AbsVal(TheTime.TimeZone) % 60;\r
+          TzMinutes = (ABS(TheTime.TimeZone)) % 60;\r
         }\r
 \r
         ShellPrintHiiEx (\r
@@ -410,18 +462,18 @@ ShellCommandRunTime (
           TheTime.Minute,\r
           TheTime.Second,\r
           TheTime.TimeZone==2047?L" ":(TheTime.TimeZone > 0?L"-":L"+"),\r
-          TheTime.TimeZone==2047?0:AbsVal(TheTime.TimeZone) / 60,\r
+          TheTime.TimeZone==2047?0:(ABS(TheTime.TimeZone)) / 60,\r
           TzMinutes\r
          );\r
           switch (TheTime.Daylight) {\r
-            case 0:\r
-              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DSTNA), gShellLevel2HiiHandle);\r
-              break;\r
             case EFI_TIME_ADJUST_DAYLIGHT:\r
-              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DSTST), gShellLevel2HiiHandle);\r
+              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DST1), gShellLevel2HiiHandle);\r
               break;\r
             case EFI_TIME_IN_DAYLIGHT:\r
-              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DSTDT), gShellLevel2HiiHandle);\r
+              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DST2), gShellLevel2HiiHandle);\r
+              break;\r
+            case EFI_TIME_IN_DAYLIGHT|EFI_TIME_ADJUST_DAYLIGHT:\r
+              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DST3), gShellLevel2HiiHandle);\r
               break;\r
             default:\r
               ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_ERROR), gShellLevel2HiiHandle, L"gRT->GetTime", L"TheTime.Daylight", TheTime.Daylight);\r
@@ -436,9 +488,9 @@ ShellCommandRunTime (
           //\r
           if ((TempLocation = ShellCommandLineGetValue(Package, L"-tz")) != NULL) {\r
             if (TempLocation[0] == L'-') {\r
-              Tz = (INT16)(0 - StrDecimalToUintn(++TempLocation));\r
+              Tz = (INT16)(0 - ShellStrToUintn(++TempLocation));\r
             } else {\r
-              Tz = (INT16)StrDecimalToUintn(TempLocation);\r
+              Tz = (INT16)ShellStrToUintn(TempLocation);\r
             }\r
             if (!(Tz >= -1440 && Tz <= 1440) && Tz != 2047) {\r
               ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"-d");\r
@@ -452,7 +504,7 @@ ShellCommandRunTime (
           }\r
           TempLocation = ShellCommandLineGetValue(Package, L"-d");\r
           if (TempLocation != NULL) {\r
-            Daylight = (UINT8)StrDecimalToUintn(TempLocation);\r
+            Daylight = (UINT8)ShellStrToUintn(TempLocation);\r
             if (Daylight != 0 && Daylight != 1 && Daylight != 3) {\r
               ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"-d");\r
               ShellStatus = SHELL_INVALID_PARAMETER;\r
@@ -539,8 +591,18 @@ STATIC CONST SHELL_PARAM_ITEM TimeZoneParamList3[] = {
     {-720 , STRING_TOKEN (STR_TIMEZONE_P12)},\r
     {-780 , STRING_TOKEN (STR_TIMEZONE_P13)},\r
     {-840 , STRING_TOKEN (STR_TIMEZONE_P14)}\r
-  };\r
+};\r
+\r
+/**\r
+  Verify that the TimeZoneString is valid and if so set that as the current \r
+  timezone.\r
 \r
+  @param[in] TimeZoneString     The pointer to a string representation of the timezone.\r
+\r
+  @retval SHELL_INVALID_PARAMETER   TimeZoneString was NULL.\r
+  @retval SHELL_INVALID_PARAMETER   TimeZoneString was mis-formatted.\r
+  @retval SHELL_SUCCESS             The operation was successful.\r
+**/\r
 SHELL_STATUS\r
 EFIAPI\r
 CheckAndSetTimeZone (\r
@@ -549,7 +611,9 @@ CheckAndSetTimeZone (
 {\r
   EFI_TIME      TheTime;\r
   EFI_STATUS    Status;\r
-  CONST CHAR16  *Walker;\r
+  CHAR16        *TimeZoneCopy;\r
+  CHAR16        *Walker;\r
+  CHAR16        *Walker2;\r
   UINTN         LoopVar;\r
 \r
   if (TimeZoneString == NULL) {\r
@@ -563,21 +627,26 @@ CheckAndSetTimeZone (
   Status = gRT->GetTime(&TheTime, NULL);\r
   ASSERT_EFI_ERROR(Status);\r
 \r
-  Walker = TimeZoneString;\r
+  TimeZoneCopy = NULL;\r
+  TimeZoneCopy = StrnCatGrow(&TimeZoneCopy, NULL, TimeZoneString, 0);\r
+  Walker = TimeZoneCopy;\r
+  Walker2 = StrStr(Walker, L":");\r
+  if (Walker2 != NULL && *Walker2 == L':') {\r
+    *Walker2 = CHAR_NULL;\r
+  }\r
   if (*Walker == L'-') {\r
-    TheTime.TimeZone = (INT16)((StrDecimalToUintn (++Walker)) * 60);\r
+    TheTime.TimeZone = (INT16)((ShellStrToUintn (++Walker)) * 60);\r
   } else {\r
-    TheTime.TimeZone = (INT16)((StrDecimalToUintn (Walker)) * -60);\r
+    TheTime.TimeZone = (INT16)((ShellStrToUintn (Walker)) * -60);\r
   }\r
-  Walker = StrStr(Walker, L":");\r
-  if (Walker != NULL && *Walker == L':') {\r
-    Walker = Walker + 1;\r
+  if (Walker2 != NULL) {\r
+    Walker = Walker2 + 1;\r
   }\r
   if (Walker != NULL && Walker[0] != CHAR_NULL) {\r
     if (TheTime.TimeZone < 0) {\r
-      TheTime.TimeZone = (INT16)(TheTime.TimeZone - (UINT8)StrDecimalToUintn (Walker));\r
+      TheTime.TimeZone = (INT16)(TheTime.TimeZone - (UINT8)ShellStrToUintn (Walker));\r
     } else {\r
-      TheTime.TimeZone = (INT16)(TheTime.TimeZone + (UINT8)StrDecimalToUintn (Walker));\r
+      TheTime.TimeZone = (INT16)(TheTime.TimeZone + (UINT8)ShellStrToUintn (Walker));\r
     }\r
   }\r
 \r
@@ -593,6 +662,8 @@ CheckAndSetTimeZone (
     }\r
   }\r
 \r
+  FreePool(TimeZoneCopy);\r
+\r
   if (!EFI_ERROR(Status)){\r
     return (SHELL_SUCCESS);\r
   }\r
@@ -716,7 +787,7 @@ ShellCommandRunTimeZone (
               if (TheTime.TimeZone == 2047) {\r
                 TzMinutes = 0;\r
               } else {\r
-                TzMinutes = AbsVal(TheTime.TimeZone) % 60;\r
+                TzMinutes = (ABS(TheTime.TimeZone)) % 60;\r
               }\r
 \r
               ShellPrintHiiEx (\r
@@ -726,7 +797,7 @@ ShellCommandRunTimeZone (
                 STRING_TOKEN(STR_TIMEZONE_SIMPLE),\r
                 gShellLevel2HiiHandle,\r
                 TheTime.TimeZone==2047?0:(TheTime.TimeZone > 0?L"-":L"+"),\r
-                TheTime.TimeZone==2047?0:AbsVal(TheTime.TimeZone) / 60,\r
+                TheTime.TimeZone==2047?0:(ABS(TheTime.TimeZone)) / 60,\r
                 TzMinutes);\r
             }\r
             Found = TRUE;\r
@@ -740,7 +811,7 @@ ShellCommandRunTimeZone (
           if (TheTime.TimeZone == 2047) {\r
             TzMinutes = 0;\r
           } else {\r
-            TzMinutes = AbsVal(TheTime.TimeZone) % 60;\r
+            TzMinutes = (ABS(TheTime.TimeZone)) % 60;\r
           }\r
           ShellPrintHiiEx (\r
             -1,\r
@@ -749,7 +820,7 @@ ShellCommandRunTimeZone (
             STRING_TOKEN(STR_TIMEZONE_SIMPLE),\r
             gShellLevel2HiiHandle,\r
             TheTime.TimeZone==2047?0:(TheTime.TimeZone > 0?L"-":L"+"),\r
-            TheTime.TimeZone==2047?0:AbsVal(TheTime.TimeZone) / 60,\r
+            TheTime.TimeZone==2047?0:(ABS(TheTime.TimeZone)) / 60,\r
             TzMinutes);\r
           if (ShellCommandLineGetFlag(Package, L"-f")) {\r
             ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN(STR_TIMEZONE_NI), gShellLevel2HiiHandle);\r
index 7fe5a1102cab3fd3099d7226d847ca32709b264c..11a15b5045903aaeaec013ee30968ebd4c560528 100644 (file)
   rm,\r
   reset,\r
   set,\r
-  timezone*\r
+  timezone*,\r
+  vol\r
 \r
   * functions are non-interactive only\r
 \r
 \r
-  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 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
@@ -40,6 +41,11 @@ CONST EFI_GUID gShellLevel2HiiGuid = \
     0xf95a7ccc, 0x4c55, 0x4426, { 0xa7, 0xb4, 0xdc, 0x89, 0x61, 0x95, 0xb, 0xae } \\r
   };\r
 \r
+/**\r
+  Get the filename to get help text from if not using HII.\r
+\r
+  @retval The filename.\r
+**/\r
 CONST CHAR16*\r
 EFIAPI\r
 ShellCommandGetManFileNameLevel2 (\r
@@ -94,6 +100,7 @@ ShellLevel2CommandsLibConstructor (
   ShellCommandRegisterCommandName(L"set",      ShellCommandRunSet     , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_SET)    );\r
   ShellCommandRegisterCommandName(L"ls",       ShellCommandRunLs      , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_LS)     );\r
   ShellCommandRegisterCommandName(L"rm",       ShellCommandRunRm      , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_RM)     );\r
+  ShellCommandRegisterCommandName(L"vol",      ShellCommandRunVol     , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_VOL)    );\r
 \r
   //\r
   // support for permenant (built in) aliases\r
@@ -295,13 +302,29 @@ VerifyIntermediateDirectories (
   return (Status);\r
 }\r
 \r
-// be lazy and borrow from baselib.\r
+/**\r
+  Be lazy and borrow from baselib.\r
+\r
+  @param[in] Char   The character to convert to upper case.\r
+\r
+  @return Char as an upper case character.\r
+**/\r
 CHAR16\r
 EFIAPI\r
 InternalCharToUpper (\r
   IN CONST CHAR16                    Char\r
   );\r
 \r
+/**\r
+  String comparison without regard to case for a limited number of characters.\r
+\r
+  @param[in] Source   The first item to compare.\r
+  @param[in] Target   The second item to compare.\r
+  @param[in] Count    How many characters to compare.\r
+\r
+  @retval NULL Source and Target are identical strings without regard to case.\r
+  @return The location in Source where there is a difference.\r
+**/\r
 CONST CHAR16*\r
 EFIAPI\r
 StrniCmp(\r
index c04acccf058a22e66eb02b47220a8f845194b6f8..cf862fef43c3c580d9144a2139eb57551279fc5c 100644 (file)
@@ -9,7 +9,7 @@
   * functions are non-interactive only\r
 \r
 \r
-  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 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
@@ -20,6 +20,9 @@
 \r
 **/\r
 \r
+#if !defined (_UEFI_SHELL_LEVEL2_COMMANDS_LIB_H_)\r
+#define _UEFI_SHELL_LEVEL2_COMMANDS_LIB_H_\r
+\r
 #include <Uefi.h>\r
 #include <ShellBase.h>\r
 \r
@@ -295,3 +298,19 @@ StrniCmp(
   IN CONST CHAR16 *Target,\r
   IN CONST UINTN  Count\r
   );\r
+\r
+/**\r
+  Function for 'Vol' 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
+ShellCommandRunVol (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  );\r
+\r
+#endif\r
+\r
index cf15753497cd68500adf3b1b23d509bb4a73cb89..8b618b1f5fdc0185010d6ba34c4d9414dbf5ac49 100644 (file)
@@ -1,7 +1,7 @@
 ##  @file\r
 # Provides shell level 2 functions\r
 #\r
-# Copyright (c) 2009, Intel Corporation. All rights reserved. <BR>\r
+# Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved. <BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -44,6 +44,7 @@
   Rm.c\r
   Mv.c\r
   Attrib.c\r
+  Vol.c\r
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r
index 726e7bdb41f6933b6c24748f2d839cf8b7b68801..7a1e8f5b836ea99c124443f96f28e8f336c914dd 100644 (file)
Binary files a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.uni and b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.uni differ
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Vol.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Vol.c
new file mode 100644 (file)
index 0000000..3688a50
--- /dev/null
@@ -0,0 +1,256 @@
+/** @file\r
+  Main file for vol shell level 2 function.\r
+\r
+  Copyright (c) 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
+  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
+**/\r
+\r
+#include "UefiShellLevel2CommandsLib.h"\r
+#include <Guid/FileSystemInfo.h>\r
+#include <Guid/FileSystemVolumeLabelInfo.h>\r
+\r
+/**\r
+  Print the info or change the volume info.\r
+\r
+  @param[in] Path           String with starting path.\r
+  @param[in] Delete         TRUE to delete the volume label. FALSE otherwise.\r
+  @param[in] Name           New name to set to the volume label.\r
+\r
+  @retval SHELL_SUCCESS     The operation was sucessful.\r
+**/\r
+SHELL_STATUS\r
+EFIAPI\r
+HandleVol(\r
+  IN CONST CHAR16  *Path,\r
+  IN CONST BOOLEAN Delete,\r
+  IN CONST CHAR16  *Name\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  SHELL_STATUS          ShellStatus;\r
+  EFI_FILE_SYSTEM_INFO  *SysInfo;\r
+  UINTN                 SysInfoSize;\r
+  SHELL_FILE_HANDLE     ShellFileHandle;\r
+  EFI_FILE_PROTOCOL     *EfiFpHandle;\r
+  UINTN                 Size1;\r
+  UINTN                 Size2;\r
+\r
+  ShellStatus   = SHELL_SUCCESS;\r
+\r
+  Status = gEfiShellProtocol->OpenFileByName(\r
+    Path,\r
+    &ShellFileHandle,\r
+    Name != NULL?EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE:EFI_FILE_MODE_READ);\r
+\r
+  if (EFI_ERROR(Status) || ShellFileHandle == NULL) {\r
+    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel2HiiHandle, Path);\r
+    ShellStatus = SHELL_ACCESS_DENIED;\r
+    return (ShellStatus);\r
+  }\r
+\r
+  //\r
+  // Get the Volume Info from ShellFileHandle\r
+  //\r
+  SysInfo     = NULL;\r
+  SysInfoSize = 0;\r
+  EfiFpHandle = ConvertShellHandleToEfiFileProtocol(ShellFileHandle);\r
+  Status = EfiFpHandle->GetInfo(\r
+    EfiFpHandle,\r
+    &gEfiFileSystemInfoGuid,\r
+    &SysInfoSize,\r
+    SysInfo);\r
+\r
+  if (Status == EFI_BUFFER_TOO_SMALL) {\r
+    SysInfo = AllocateZeroPool(SysInfoSize);\r
+    Status = EfiFpHandle->GetInfo(\r
+      EfiFpHandle,\r
+      &gEfiFileSystemInfoGuid,\r
+      &SysInfoSize,\r
+      SysInfo);\r
+  }\r
+\r
+  if (Delete) {\r
+    StrCpy ((CHAR16 *) SysInfo->VolumeLabel, L"");\r
+    SysInfo->Size = SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize(SysInfo->VolumeLabel);\r
+    Status = EfiFpHandle->SetInfo(\r
+      EfiFpHandle,\r
+      &gEfiFileSystemInfoGuid,\r
+      (UINTN)SysInfo->Size,\r
+      SysInfo);\r
+  } else if (Name != NULL) {\r
+    Size1 = StrSize(Name);\r
+    Size2 = StrSize(SysInfo->VolumeLabel);\r
+    if (Size1 > Size2) {\r
+      SysInfo = ReallocatePool((UINTN)SysInfo->Size, (UINTN)SysInfo->Size + Size1 - Size2, SysInfo);\r
+    }\r
+    StrCpy ((CHAR16 *) SysInfo->VolumeLabel, Name);\r
+    SysInfo->Size = SIZE_OF_EFI_FILE_SYSTEM_INFO + Size1;\r
+    Status = EfiFpHandle->SetInfo(\r
+      EfiFpHandle,\r
+      &gEfiFileSystemInfoGuid,\r
+      (UINTN)SysInfo->Size,\r
+      SysInfo);\r
+  }  \r
+\r
+  FreePool(SysInfo);\r
+\r
+  if (Delete || Name != NULL) {\r
+    if (EFI_ERROR(Status)) {\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_AD), gShellLevel2HiiHandle, Path);\r
+      ShellStatus = SHELL_ACCESS_DENIED;\r
+    }\r
+  }\r
+\r
+  SysInfo = AllocateZeroPool(SysInfoSize);\r
+  Status = EfiFpHandle->GetInfo(\r
+    EfiFpHandle,\r
+    &gEfiFileSystemInfoGuid,\r
+    &SysInfoSize,\r
+    SysInfo);\r
+\r
+  gEfiShellProtocol->CloseFile(ShellFileHandle);\r
+\r
+  //\r
+  // print VolumeInfo table\r
+  //\r
+  ShellPrintHiiEx (\r
+    0,\r
+    gST->ConOut->Mode->CursorRow,\r
+    NULL,\r
+    STRING_TOKEN (STR_VOL_VOLINFO),\r
+    gShellLevel2HiiHandle,\r
+    SysInfo->VolumeLabel,\r
+    SysInfo->ReadOnly?L"r":L"rw",\r
+    SysInfo->VolumeSize,\r
+    SysInfo->FreeSpace,\r
+    SysInfo->BlockSize\r
+   );\r
+  SHELL_FREE_NON_NULL(SysInfo);\r
+\r
+  return (ShellStatus);\r
+}\r
+\r
+STATIC CONST SHELL_PARAM_ITEM ParamList[] = {\r
+  {L"-d", TypeFlag},\r
+  {L"-n", TypeValue},\r
+  {NULL, TypeMax}\r
+  };\r
+\r
+/**\r
+  Function for 'Vol' 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
+ShellCommandRunVol (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+  LIST_ENTRY    *Package;\r
+  CHAR16        *ProblemParam;\r
+  SHELL_STATUS  ShellStatus;\r
+  CONST CHAR16  *PathName;\r
+  CONST CHAR16  *CurDir;\r
+  BOOLEAN       DeleteMode;\r
+  CHAR16        *FullPath;\r
+  UINTN         Length;\r
+\r
+  Length              = 0;\r
+  ProblemParam        = NULL;\r
+  ShellStatus         = SHELL_SUCCESS;\r
+  PathName            = NULL;\r
+  CurDir              = NULL;\r
+  FullPath            = NULL;\r
+\r
+  //\r
+  // initialize the shell lib (we must be in non-auto-init...)\r
+  //\r
+  Status = ShellInitialize();\r
+  ASSERT_EFI_ERROR(Status);\r
+\r
+  //\r
+  // Fix local copies of the protocol pointers\r
+  //\r
+  Status = CommandInit();\r
+  ASSERT_EFI_ERROR(Status);\r
+\r
+  //\r
+  // parse the command line\r
+  //\r
+  Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);\r
+  if (EFI_ERROR(Status)) {\r
+    if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);\r
+      FreePool(ProblemParam);\r
+      ShellStatus = SHELL_INVALID_PARAMETER;\r
+    } else {\r
+      ASSERT(FALSE);\r
+    }\r
+  } else {\r
+    //\r
+    // check for "-?"\r
+    //\r
+    if (ShellCommandLineGetFlag(Package, L"-?")) {\r
+      ASSERT(FALSE);\r
+    }\r
+\r
+    if (ShellCommandLineGetCount(Package) > 2) {\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);\r
+      ShellStatus = SHELL_INVALID_PARAMETER;\r
+    } else {\r
+      PathName = ShellCommandLineGetRawValue(Package, 1);\r
+      if (PathName == NULL) {\r
+        CurDir = gEfiShellProtocol->GetCurDir(NULL);\r
+        if (CurDir == NULL) {\r
+          ShellStatus = SHELL_NOT_FOUND;\r
+          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);\r
+        } else {\r
+          PathName = CurDir;\r
+        }\r
+      }\r
+      if (PathName != NULL) {\r
+        StrnCatGrow(&FullPath, &Length, PathName, StrStr(PathName, L"\\")==NULL?0:StrStr(PathName, L"\\")-PathName+1);\r
+        if (StrStr(FullPath, L":\\") == NULL) {\r
+          StrnCatGrow(&FullPath, &Length, L":\\", 0);\r
+        }\r
+        DeleteMode = ShellCommandLineGetFlag(Package, L"-d");\r
+        if (DeleteMode && ShellCommandLineGetFlag(Package, L"-n")) {\r
+          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CON), gShellLevel2HiiHandle);\r
+          ShellStatus = SHELL_INVALID_PARAMETER;\r
+        } else if (ShellCommandLineGetFlag(Package, L"-n") && ShellCommandLineGetValue(Package, L"-n") == NULL) {\r
+          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellLevel2HiiHandle, L"-n");\r
+          ShellStatus = SHELL_INVALID_PARAMETER;\r
+        } else if (ShellCommandLineGetValue(Package, L"-n") != NULL && StrLen(ShellCommandLineGetValue(Package, L"-n")) > 11) {\r
+          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellLevel2HiiHandle, L"-n");\r
+          ShellStatus = SHELL_INVALID_PARAMETER;\r
+        } else if (ShellStatus == SHELL_SUCCESS) {\r
+          ShellStatus = HandleVol(\r
+            FullPath,\r
+            DeleteMode,\r
+            ShellCommandLineGetValue(Package, L"-n")\r
+           );\r
+        }\r
+      }\r
+    }\r
+  }\r
+\r
+  SHELL_FREE_NON_NULL(FullPath);\r
+\r
+  //\r
+  // free the command line package\r
+  //\r
+  ShellCommandLineFreeVarList (Package);\r
+\r
+  return (ShellStatus);\r
+}\r