]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c
ShellPkg/UefiShellLevel2CommandsLib: Remove unnecessary EFIAPI
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel2CommandsLib / Cp.c
index 3a0068393929e2d48ab1e6b0aad85b6dd3d666b0..b8f6d310f66b9a417590f6a05990ca75ff2fc7a2 100644 (file)
@@ -1,7 +1,8 @@
 /** @file\r
   Main file for cp shell level 2 function.\r
 \r
-  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
+  Copyright (c) 2009 - 2016, 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
@@ -34,7 +35,6 @@
   @retval SHELL_OUT_OF_RESOURCES    a memory allocation failed\r
 **/\r
 SHELL_STATUS\r
-EFIAPI\r
 ValidateAndCopyFiles(\r
   IN CONST EFI_SHELL_FILE_INFO  *FileList,\r
   IN CONST CHAR16               *DestDir,\r
@@ -52,16 +52,17 @@ ValidateAndCopyFiles(
   @param[in] Dest       pointer to destination file name\r
   @param[out] Resp      pointer to response from question.  Pass back on looped calling\r
   @param[in] SilentMode whether to run in quiet mode or not\r
+  @param[in] CmdName    Source command name requesting single file copy\r
 \r
   @retval SHELL_SUCCESS   The source file was copied to the destination\r
 **/\r
 SHELL_STATUS\r
-EFIAPI\r
 CopySingleFile(\r
   IN CONST CHAR16 *Source,\r
   IN CONST CHAR16 *Dest,\r
   OUT VOID        **Resp,\r
-  IN BOOLEAN      SilentMode\r
+  IN BOOLEAN      SilentMode,\r
+  IN CONST CHAR16 *CmdName\r
   )\r
 {\r
   VOID                  *Response;\r
@@ -131,7 +132,7 @@ CopySingleFile(
   if (ShellIsDirectory(Source) == EFI_SUCCESS) {\r
     Status = ShellCreateDirectory(Dest, &DestHandle);\r
     if (EFI_ERROR(Status)) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_DIR_FAIL), gShellLevel2HiiHandle, Dest);\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_DIR_FAIL), gShellLevel2HiiHandle, CmdName, Dest);  \r
       return (SHELL_ACCESS_DENIED);\r
     }\r
 \r
@@ -160,15 +161,18 @@ CopySingleFile(
     //\r
     Status = ShellOpenFileByName(Dest, &DestHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);\r
     if (EFI_ERROR(Status)) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_OPEN_FAIL), gShellLevel2HiiHandle, Dest);\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_OPEN_FAIL), gShellLevel2HiiHandle, CmdName, Dest);  \r
       return (SHELL_ACCESS_DENIED);\r
     }\r
 \r
     //\r
     // open source file\r
     //\r
-    Status = ShellOpenFileByName(Source, &SourceHandle, EFI_FILE_MODE_READ, 0);\r
-    ASSERT_EFI_ERROR(Status);\r
+    Status = ShellOpenFileByName (Source, &SourceHandle, EFI_FILE_MODE_READ, 0);\r
+    if (EFI_ERROR (Status)) {\r
+      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_CP_SRC_OPEN_FAIL), gShellLevel2HiiHandle, CmdName, Source);\r
+      return (SHELL_ACCESS_DENIED);\r
+    }\r
 \r
     //\r
     //get file size of source file and freespace available on destination volume\r
@@ -216,26 +220,29 @@ CopySingleFile(
       //not enough space on destination directory to copy file\r
       //\r
       SHELL_FREE_NON_NULL(DestVolumeInfo);\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_FAIL), gShellLevel2HiiHandle);\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_FAIL), gShellLevel2HiiHandle, CmdName);  \r
       return(SHELL_VOLUME_FULL);\r
     } else {\r
       //\r
       // copy data between files\r
       //\r
       Buffer = AllocateZeroPool(ReadSize);\r
-      ASSERT(Buffer != NULL);\r
+      if (Buffer == NULL) {\r
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellLevel2HiiHandle, CmdName);\r
+        return SHELL_OUT_OF_RESOURCES;\r
+      }\r
       while (ReadSize == PcdGet32(PcdShellFileOperationSize) && !EFI_ERROR(Status)) {\r
         Status = ShellReadFile(SourceHandle, &ReadSize, Buffer);\r
         if (!EFI_ERROR(Status)) {\r
           Status = ShellWriteFile(DestHandle, &ReadSize, Buffer);\r
           if (EFI_ERROR(Status)) {\r
             ShellStatus = (SHELL_STATUS) (Status & (~MAX_BIT));\r
-            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_WRITE_ERROR), gShellLevel2HiiHandle, Dest);\r
+            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_WRITE_ERROR), gShellLevel2HiiHandle, CmdName, Dest);   \r
             break;\r
           }\r
         } else {\r
           ShellStatus = (SHELL_STATUS) (Status & (~MAX_BIT));\r
-          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_READ_ERROR), gShellLevel2HiiHandle, Source);\r
+          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_READ_ERROR), gShellLevel2HiiHandle, CmdName, Source);  \r
           break;\r
         }\r
       }\r
@@ -282,7 +289,6 @@ CopySingleFile(
   @retval SHELL_OUT_OF_RESOURCES    a memory allocation failed\r
 **/\r
 SHELL_STATUS\r
-EFIAPI\r
 ValidateAndCopyFiles(\r
   IN CONST EFI_SHELL_FILE_INFO  *FileList,\r
   IN CONST CHAR16               *DestDir,\r
@@ -295,11 +301,13 @@ ValidateAndCopyFiles(
   CHAR16                    *HiiResultOk;\r
   CONST EFI_SHELL_FILE_INFO *Node;\r
   SHELL_STATUS              ShellStatus;\r
+  EFI_STATUS                Status;\r
   CHAR16                    *DestPath;\r
   VOID                      *Response;\r
   UINTN                     PathSize;\r
   CONST CHAR16              *Cwd;\r
   UINTN                     NewSize;\r
+  CHAR16                    *CleanFilePathStr;\r
 \r
   if (Resp == NULL) {\r
     Response = NULL;\r
@@ -307,22 +315,36 @@ ValidateAndCopyFiles(
     Response = *Resp;\r
   }\r
 \r
-  DestPath    = NULL;\r
-  ShellStatus = SHELL_SUCCESS;\r
-  PathSize    = 0;\r
-  Cwd         = ShellGetCurrentDir(NULL);\r
+  DestPath         = NULL;\r
+  ShellStatus      = SHELL_SUCCESS;\r
+  PathSize         = 0;\r
+  Cwd              = ShellGetCurrentDir(NULL);\r
+  CleanFilePathStr = NULL;\r
 \r
   ASSERT(FileList != NULL);\r
   ASSERT(DestDir  != NULL);\r
 \r
+  \r
+  Status = ShellLevel2StripQuotes (DestDir, &CleanFilePathStr);\r
+  if (EFI_ERROR (Status)) {\r
+    if (Status == EFI_OUT_OF_RESOURCES) {\r
+      return SHELL_OUT_OF_RESOURCES;\r
+    } else {\r
+      return SHELL_INVALID_PARAMETER;\r
+    }\r
+  }\r
+  \r
+  ASSERT (CleanFilePathStr != NULL);\r
+\r
   //\r
   // If we are trying to copy multiple files... make sure we got a directory for the target...\r
   //\r
-  if (EFI_ERROR(ShellIsDirectory(DestDir)) && FileList->Link.ForwardLink != FileList->Link.BackLink) {\r
+  if (EFI_ERROR(ShellIsDirectory(CleanFilePathStr)) && FileList->Link.ForwardLink != FileList->Link.BackLink) {\r
     //\r
     // Error for destination not a directory\r
     //\r
-    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, DestDir);\r
+    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, L"cp", CleanFilePathStr); \r
+    FreePool (CleanFilePathStr);\r
     return (SHELL_INVALID_PARAMETER);\r
   }\r
   for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&FileList->Link)\r
@@ -336,9 +358,9 @@ ValidateAndCopyFiles(
       continue;\r
     }\r
 \r
-    NewSize =  StrSize(DestDir);\r
+    NewSize =  StrSize(CleanFilePathStr);\r
     NewSize += StrSize(Node->FullName);\r
-    NewSize += (Cwd == NULL)? 0 : StrSize(Cwd);\r
+    NewSize += (Cwd == NULL)? 0 : (StrSize(Cwd) + sizeof(CHAR16));\r
     if (NewSize > PathSize) {\r
       PathSize = NewSize;\r
     }\r
@@ -347,18 +369,20 @@ ValidateAndCopyFiles(
     // Make sure got -r if required\r
     //\r
     if (!RecursiveMode && !EFI_ERROR(ShellIsDirectory(Node->FullName))) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DIR_REQ), gShellLevel2HiiHandle);\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DIR_REQ), gShellLevel2HiiHandle, L"cp");  \r
+      FreePool (CleanFilePathStr);\r
       return (SHELL_INVALID_PARAMETER);\r
     }\r
 \r
     //\r
     // make sure got dest as dir if needed\r
     //\r
-    if (!EFI_ERROR(ShellIsDirectory(Node->FullName)) && EFI_ERROR(ShellIsDirectory(DestDir))) {\r
+    if (!EFI_ERROR(ShellIsDirectory(Node->FullName)) && EFI_ERROR(ShellIsDirectory(CleanFilePathStr))) {\r
       //\r
       // Error for destination not a directory\r
       //\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, DestDir);\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, L"cp", CleanFilePathStr);  \r
+      FreePool (CleanFilePathStr);\r
       return (SHELL_INVALID_PARAMETER);\r
     }\r
   }\r
@@ -371,6 +395,7 @@ ValidateAndCopyFiles(
     SHELL_FREE_NON_NULL(DestPath);\r
     SHELL_FREE_NON_NULL(HiiOutput);\r
     SHELL_FREE_NON_NULL(HiiResultOk);\r
+    FreePool (CleanFilePathStr);\r
     return (SHELL_OUT_OF_RESOURCES);\r
   }\r
 \r
@@ -395,26 +420,28 @@ ValidateAndCopyFiles(
     }\r
 \r
     if (FileList->Link.ForwardLink == FileList->Link.BackLink // 1 item\r
-      && EFI_ERROR(ShellIsDirectory(DestDir))                 // not an existing directory\r
+      && EFI_ERROR(ShellIsDirectory(CleanFilePathStr))                 // not an existing directory\r
       ) {\r
-      if (StrStr(DestDir, L":") == NULL) {\r
+      if (StrStr(CleanFilePathStr, L":") == NULL) {\r
         //\r
         // simple copy of a single file\r
         //\r
         if (Cwd != NULL) {\r
-          StrnCpy(DestPath, Cwd, PathSize/sizeof(CHAR16)-1);\r
+          StrCpyS(DestPath, PathSize / sizeof(CHAR16), Cwd);\r
+          StrCatS(DestPath, PathSize / sizeof(CHAR16), L"\\");\r
         } else {\r
-          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, DestDir);\r
+          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, L"cp", CleanFilePathStr);  \r
+          FreePool (CleanFilePathStr);\r
           return (SHELL_INVALID_PARAMETER);\r
         }\r
-        if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {\r
-          StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
-        } else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {\r
+        if (DestPath[StrLen(DestPath)-1] != L'\\' && CleanFilePathStr[0] != L'\\') {\r
+          StrCatS(DestPath, PathSize / sizeof(CHAR16), L"\\");\r
+        } else if (DestPath[StrLen(DestPath)-1] == L'\\' && CleanFilePathStr[0] == L'\\') {\r
           ((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;\r
         }\r
-        StrnCat(DestPath, DestDir, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
+        StrCatS(DestPath, PathSize/sizeof(CHAR16), CleanFilePathStr);\r
       } else {\r
-        StrnCpy(DestPath, DestDir, PathSize/sizeof(CHAR16) -1);\r
+        StrCpyS(DestPath, PathSize/sizeof(CHAR16), CleanFilePathStr);\r
       }\r
     } else {\r
       //\r
@@ -424,55 +451,59 @@ ValidateAndCopyFiles(
       //\r
       // Check for leading slash\r
       //\r
-      if (DestDir[0] == L'\\') {\r
+      if (CleanFilePathStr[0] == L'\\') {\r
          //\r
          // Copy to the root of CWD\r
          //\r
         if (Cwd != NULL) {\r
-          StrnCpy(DestPath, Cwd, PathSize/sizeof(CHAR16) -1);\r
+          StrCpyS(DestPath, PathSize/sizeof(CHAR16), Cwd);\r
+          StrCatS(DestPath, PathSize/sizeof(CHAR16), L"\\");\r
         } else {\r
-          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, DestDir);\r
+          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, L"cp",  CleanFilePathStr); \r
+          FreePool(CleanFilePathStr);\r
           return (SHELL_INVALID_PARAMETER);\r
         }\r
         while (PathRemoveLastItem(DestPath));\r
-        StrnCat(DestPath, DestDir+1, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
-        StrnCat(DestPath, Node->FileName, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
-      } else if (StrStr(DestDir, L":") == NULL) {\r
+        StrCatS(DestPath, PathSize/sizeof(CHAR16), CleanFilePathStr+1);\r
+        StrCatS(DestPath, PathSize/sizeof(CHAR16), Node->FileName);\r
+      } else if (StrStr(CleanFilePathStr, L":") == NULL) {\r
         if (Cwd != NULL) {\r
-          StrnCpy(DestPath, Cwd, PathSize/sizeof(CHAR16) -1);\r
+          StrCpyS(DestPath, PathSize/sizeof(CHAR16), Cwd);\r
+          StrCatS(DestPath, PathSize/sizeof(CHAR16), L"\\");\r
         } else {\r
-          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, DestDir);\r
+          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, L"cp", CleanFilePathStr);  \r
+          FreePool(CleanFilePathStr);\r
           return (SHELL_INVALID_PARAMETER);\r
         }\r
-        if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {\r
-          StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
-        } else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {\r
+        if (DestPath[StrLen(DestPath)-1] != L'\\' && CleanFilePathStr[0] != L'\\') {\r
+          StrCatS(DestPath, PathSize/sizeof(CHAR16), L"\\");\r
+        } else if (DestPath[StrLen(DestPath)-1] == L'\\' && CleanFilePathStr[0] == L'\\') {\r
           ((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;\r
         }\r
-        StrnCat(DestPath, DestDir, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
-        if (DestDir[StrLen(DestDir)-1] != L'\\' && Node->FileName[0] != L'\\') {\r
-          StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
-        } else if (DestDir[StrLen(DestDir)-1] == L'\\' && Node->FileName[0] == L'\\') {\r
+        StrCatS(DestPath, PathSize/sizeof(CHAR16), CleanFilePathStr);\r
+        if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] != L'\\' && Node->FileName[0] != L'\\') {\r
+          StrCatS(DestPath, PathSize/sizeof(CHAR16), L"\\");\r
+        } else if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] == L'\\' && Node->FileName[0] == L'\\') {\r
           ((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;\r
         }\r
-        StrnCat(DestPath, Node->FileName, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
+        StrCatS(DestPath, PathSize/sizeof(CHAR16), Node->FileName);\r
 \r
       } else {\r
-        StrnCpy(DestPath, DestDir, PathSize/sizeof(CHAR16) -1);\r
-        if (DestDir[StrLen(DestDir)-1] != L'\\' && Node->FileName[0] != L'\\') {\r
-          StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
-        } else if (DestDir[StrLen(DestDir)-1] == L'\\' && Node->FileName[0] == L'\\') {\r
-          ((CHAR16*)DestDir)[StrLen(DestDir)-1] = CHAR_NULL;\r
+        StrCpyS(DestPath, PathSize/sizeof(CHAR16), CleanFilePathStr);\r
+        if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] != L'\\' && Node->FileName[0] != L'\\') {\r
+          StrCatS(DestPath, PathSize/sizeof(CHAR16), L"\\");\r
+        } else if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] == L'\\' && Node->FileName[0] == L'\\') {\r
+          ((CHAR16*)CleanFilePathStr)[StrLen(CleanFilePathStr)-1] = CHAR_NULL;\r
         }\r
-        StrnCat(DestPath, Node->FileName, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
+        StrCatS(DestPath, PathSize/sizeof(CHAR16), Node->FileName);\r
       }\r
     }\r
-\r
+    \r
     //\r
     // Make sure the path exists\r
     //\r
     if (EFI_ERROR(VerifyIntermediateDirectories(DestPath))) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DIR_WNF), gShellLevel2HiiHandle);\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DIR_WNF), gShellLevel2HiiHandle, L"cp", DestPath);  \r
       ShellStatus = SHELL_DEVICE_ERROR;\r
       break;\r
     }\r
@@ -481,12 +512,12 @@ ValidateAndCopyFiles(
       && !EFI_ERROR(ShellIsDirectory(DestPath))\r
       && StrniCmp(Node->FullName, DestPath, StrLen(DestPath)) == NULL\r
       ){\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_SD_PARENT), gShellLevel2HiiHandle);\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_SD_PARENT), gShellLevel2HiiHandle, L"cp");  \r
       ShellStatus = SHELL_INVALID_PARAMETER;\r
       break;\r
     }\r
     if (StringNoCaseCompare(&Node->FullName, &DestPath) == 0) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_SD_SAME), gShellLevel2HiiHandle);\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_SD_SAME), gShellLevel2HiiHandle, L"cp");  \r
       ShellStatus = SHELL_INVALID_PARAMETER;\r
       break;\r
     }\r
@@ -494,7 +525,7 @@ ValidateAndCopyFiles(
     if ((StrniCmp(Node->FullName, DestPath, StrLen(Node->FullName)) == 0)\r
       && (DestPath[StrLen(Node->FullName)] == CHAR_NULL || DestPath[StrLen(Node->FullName)] == L'\\')\r
       ) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_SD_SAME), gShellLevel2HiiHandle);\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_SD_SAME), gShellLevel2HiiHandle, L"cp");  \r
       ShellStatus = SHELL_INVALID_PARAMETER;\r
       break;\r
     }\r
@@ -508,7 +539,7 @@ ValidateAndCopyFiles(
     //\r
     // copy single file...\r
     //\r
-    ShellStatus = CopySingleFile(Node->FullName, DestPath, &Response, SilentMode);\r
+    ShellStatus = CopySingleFile(Node->FullName, DestPath, &Response, SilentMode, L"cp");\r
     if (ShellStatus != SHELL_SUCCESS) {\r
       break;\r
     }\r
@@ -520,6 +551,7 @@ ValidateAndCopyFiles(
   SHELL_FREE_NON_NULL(DestPath);\r
   SHELL_FREE_NON_NULL(HiiOutput);\r
   SHELL_FREE_NON_NULL(HiiResultOk);\r
+  SHELL_FREE_NON_NULL(CleanFilePathStr);\r
   if (Resp == NULL) {\r
     SHELL_FREE_NON_NULL(Response);\r
   }\r
@@ -541,7 +573,6 @@ ValidateAndCopyFiles(
   @retval SHELL_SUCCESS             The operation was successful.\r
 **/\r
 SHELL_STATUS\r
-EFIAPI\r
 ProcessValidateAndCopyFiles(\r
   IN       EFI_SHELL_FILE_INFO  *FileList,\r
   IN CONST CHAR16               *DestDir,\r
@@ -560,7 +591,7 @@ ProcessValidateAndCopyFiles(
 \r
   ShellOpenFileMetaArg((CHAR16*)DestDir, EFI_FILE_MODE_READ, &List);\r
   if (List != NULL && List->Link.ForwardLink != List->Link.BackLink) {\r
-    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_MARG_ERROR), gShellLevel2HiiHandle, DestDir);\r
+    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_MARG_ERROR), gShellLevel2HiiHandle, L"cp", DestDir);  \r
     ShellStatus = SHELL_INVALID_PARAMETER;\r
     ShellCloseFileMetaArg(&List);\r
   } else if (List != NULL) {\r
@@ -573,7 +604,7 @@ ProcessValidateAndCopyFiles(
     if ((FileInfo->Attribute & EFI_FILE_READ_ONLY) == 0) {\r
       ShellStatus = ValidateAndCopyFiles(FileList, FullName, SilentMode, RecursiveMode, NULL);\r
     } else {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_ERROR), gShellLevel2HiiHandle);\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_ERROR), gShellLevel2HiiHandle, L"cp");  \r
       ShellStatus = SHELL_ACCESS_DENIED;\r
     }\r
   } else {\r
@@ -615,6 +646,7 @@ ShellCommandRunCp (
   BOOLEAN             SilentMode;\r
   BOOLEAN             RecursiveMode;\r
   CONST CHAR16        *Cwd;\r
+  CHAR16              *FullCwd;\r
 \r
   ProblemParam        = NULL;\r
   ShellStatus         = SHELL_SUCCESS;\r
@@ -636,7 +668,7 @@ ShellCommandRunCp (
   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
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"cp", ProblemParam);  \r
       FreePool(ProblemParam);\r
       ShellStatus = SHELL_INVALID_PARAMETER;\r
     } else {\r
@@ -666,7 +698,7 @@ ShellCommandRunCp (
         //\r
         // we have insufficient parameters\r
         //\r
-        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle);\r
+        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle, L"cp");  \r
         ShellStatus = SHELL_INVALID_PARAMETER;\r
         break;\r
       case 2:\r
@@ -675,15 +707,23 @@ ShellCommandRunCp (
         //\r
         Cwd = ShellGetCurrentDir(NULL);\r
         if (Cwd == NULL){\r
-          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);\r
+          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle, L"cp");  \r
           ShellStatus = SHELL_INVALID_PARAMETER;\r
         } else {\r
           Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, 1), 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, L"cp", ShellCommandLineGetRawValue(Package, 1));  \r
             ShellStatus = SHELL_NOT_FOUND;\r
           } else  {\r
-            ShellStatus = ProcessValidateAndCopyFiles(FileList, Cwd, SilentMode, RecursiveMode);\r
+            FullCwd = AllocateZeroPool(StrSize(Cwd) + sizeof(CHAR16));\r
+            if (FullCwd == NULL) {\r
+              ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellLevel2HiiHandle, L"cp");\r
+              ShellStatus = SHELL_OUT_OF_RESOURCES;\r
+            } else {\r
+              StrCpyS (FullCwd, StrSize (Cwd) / sizeof (CHAR16) + 1, Cwd);\r
+              ShellStatus = ProcessValidateAndCopyFiles (FileList, FullCwd, SilentMode, RecursiveMode);\r
+              FreePool (FullCwd);\r
+            }\r
           }\r
         }\r
 \r
@@ -698,7 +738,7 @@ ShellCommandRunCp (
           }\r
           Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, LoopCounter), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);\r
           if (EFI_ERROR(Status) || FileList == NULL || IsListEmpty(&FileList->Link)) {\r
-            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, LoopCounter));\r
+            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, L"cp", ShellCommandLineGetRawValue(Package, LoopCounter));  \r
             ShellStatus = SHELL_NOT_FOUND;\r
           }\r
         }\r
@@ -712,7 +752,7 @@ ShellCommandRunCp (
             ShellStatus = ProcessValidateAndCopyFiles(FileList, PathCleanUpDirectories((CHAR16*)ShellCommandLineGetRawValue(Package, ParamCount)), SilentMode, RecursiveMode);\r
             Status = ShellCloseFileMetaArg(&FileList);\r
             if (EFI_ERROR(Status) && ShellStatus == SHELL_SUCCESS) {\r
-              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_FILE), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, ParamCount), ShellStatus|MAX_BIT);\r
+              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_FILE), gShellLevel2HiiHandle, L"cp", ShellCommandLineGetRawValue(Package, ParamCount), ShellStatus|MAX_BIT);  \r
               ShellStatus = SHELL_ACCESS_DENIED;\r
             }\r
           }\r