]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellLevel3CommandsLib/Touch.c
QuarkSocPkg: Add new package for Quark SoC X1000
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel3CommandsLib / Touch.c
index 0252f7748de588be1fdbc8f827b9c3b303ba65ba..88c5d750e0ccd223996e79dfde18e8689f1ac946 100644 (file)
@@ -1,7 +1,8 @@
 /** @file\r
   Main file for Touch shell level 3 function.\r
 \r
-  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>\r
+  (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<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 <Library/ShellLib.h>\r
 \r
+/**\r
+  Do the touch operation on a single handle.\r
+\r
+  @param[in] Handle   The handle to update the date/time on.\r
+\r
+  @retval EFI_ACCESS_DENIED The file referenced by Handle is read only.\r
+  @retval EFI_SUCCESS       The operation was successful.\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 TouchFileByHandle (\r
@@ -30,7 +39,11 @@ TouchFileByHandle (
     return (EFI_ACCESS_DENIED);\r
   }\r
   Status = gRT->GetTime(&FileInfo->ModificationTime, NULL);\r
-  ASSERT_EFI_ERROR(Status);\r
+  if (EFI_ERROR(Status)) {\r
+    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, L"gRT->GetTime", Status);\r
+    return (SHELL_DEVICE_ERROR);\r
+  }\r
+\r
   CopyMem(&FileInfo->LastAccessTime, &FileInfo->ModificationTime, sizeof(EFI_TIME));\r
 \r
   Status = gEfiShellProtocol->SetFileInfo(Handle, FileInfo);\r
@@ -40,6 +53,17 @@ TouchFileByHandle (
   return (Status);\r
 }\r
 \r
+/**\r
+  Touch a given file and potantially recurse down if it was a directory.\r
+\r
+  @param[in] Name   The name of this file.\r
+  @param[in] FS     The name of the file system this file is on.\r
+  @param[in] Handle The handle of this file already opened.\r
+  @param[in] Rec    TRUE to recurse if possible.\r
+\r
+  @retval EFI_INVALID_PARAMETER A parameter was invalid.\r
+  @retval EFI_SUCCESS           The operation was successful.\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 DoTouchByHandle (\r
@@ -60,18 +84,23 @@ DoTouchByHandle (
 \r
   if (FS == NULL) {\r
     FS = StrnCatGrow(&FS, NULL, Name, 0);\r
-    TempSpot = StrStr(FS, L"\\");\r
-    if (TempSpot != NULL) {\r
-      *TempSpot = CHAR_NULL;\r
+    if (FS != NULL) {\r
+      TempSpot = StrStr(FS, L"\\");\r
+      if (TempSpot != NULL) {\r
+        *TempSpot = CHAR_NULL;\r
+      }\r
     }\r
   }\r
+  if (FS == NULL) {\r
+    return (EFI_INVALID_PARAMETER);\r
+  }\r
 \r
   //\r
   // do it\r
   //\r
   Status = TouchFileByHandle(Handle);\r
   if (EFI_ERROR(Status)) {\r
-    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NO_OPEN), gShellLevel3HiiHandle, Name, Status);\r
+    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel3HiiHandle, L"touch", Name);  \r
     return (Status);\r
   }\r
 \r
@@ -101,7 +130,7 @@ DoTouchByHandle (
         //\r
         Status = gEfiShellProtocol->OpenFileByName (Walker->FullName, &Walker->Handle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE);\r
         if (EFI_ERROR(Status)) {\r
-          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NO_OPEN), gShellLevel3HiiHandle, Walker->FullName, Status);\r
+          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel3HiiHandle, L"touch", Walker->FullName);  \r
           Status = EFI_ACCESS_DENIED;\r
         } else {\r
           Status = DoTouchByHandle(Walker->FullName, FS, Walker->Handle, TRUE);\r
@@ -169,7 +198,7 @@ ShellCommandRunTouch (
   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), gShellLevel3HiiHandle, ProblemParam);\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, L"touch", ProblemParam);  \r
       FreePool(ProblemParam);\r
       ShellStatus = SHELL_INVALID_PARAMETER;\r
     } else {\r
@@ -186,7 +215,7 @@ ShellCommandRunTouch (
       //\r
       // we insufficient parameters\r
       //\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel3HiiHandle);\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel3HiiHandle, L"touch");  \r
       ShellStatus = SHELL_INVALID_PARAMETER;\r
     } else {\r
       //\r
@@ -199,7 +228,7 @@ ShellCommandRunTouch (
          ){\r
         Status = ShellOpenFileMetaArg((CHAR16*)Param, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, &FileList);\r
         if (EFI_ERROR(Status)) {\r
-          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, (CHAR16*)Param);\r
+          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel3HiiHandle, L"touch", (CHAR16*)Param);  \r
           ShellStatus = SHELL_NOT_FOUND;\r
           break;\r
         }\r
@@ -212,7 +241,7 @@ ShellCommandRunTouch (
           // check that we have at least 1 file\r
           //\r
           if (FileList == NULL || IsListEmpty(&FileList->Link)) {\r
-            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel3HiiHandle, Param);\r
+            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel3HiiHandle, L"touch", Param);  \r
             continue;\r
           } else {\r
             //\r
@@ -226,14 +255,14 @@ ShellCommandRunTouch (
               // make sure the file opened ok\r
               //\r
               if (EFI_ERROR(Node->Status)){\r
-                ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NO_OPEN), gShellLevel3HiiHandle, Node->FileName, Node->Status);\r
+                ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel3HiiHandle, L"touch", Node->FileName);  \r
                 ShellStatus = SHELL_NOT_FOUND;\r
                 continue;\r
               }\r
 \r
               Status = DoTouchByHandle(Node->FullName, NULL, Node->Handle, ShellCommandLineGetFlag(Package, L"-r"));\r
               if (EFI_ERROR(Status) && Status != EFI_ACCESS_DENIED) {\r
-                ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NO_OPEN), gShellLevel3HiiHandle, Node->FileName, Status);\r
+                ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel3HiiHandle, L"touch", Node->FileName);  \r
                 ShellStatus = SHELL_NOT_FOUND;\r
               }\r
             }\r