]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c
ShellPkg: increase available size for PcdShellFileOperationSize
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel2CommandsLib / Cp.c
index 876cb9d3ef8c0cacd0e99c60e88356ed8103b5e4..05f3844966a68315dd8644289a1b21c8add865c6 100644 (file)
@@ -87,8 +87,9 @@ CopySingleFile(
   Response        = *Resp;\r
   List            = NULL;\r
   DestVolumeInfo  = NULL;\r
+  ShellStatus     = SHELL_SUCCESS;\r
 \r
-  ReadSize = PcdGet16(PcdShellFileOperationSize);\r
+  ReadSize = PcdGet32(PcdShellFileOperationSize);\r
   // Why bother copying a file to itself\r
   if (StrCmp(Source, Dest) == 0) {\r
     return (SHELL_SUCCESS);\r
@@ -232,7 +233,7 @@ CopySingleFile(
         //\r
         Buffer = AllocateZeroPool(ReadSize);\r
         ASSERT(Buffer != NULL);\r
-        while (ReadSize == PcdGet16(PcdShellFileOperationSize) && !EFI_ERROR(Status)) {\r
+        while (ReadSize == PcdGet32(PcdShellFileOperationSize) && !EFI_ERROR(Status)) {\r
           Status = ShellReadFile(SourceHandle, &ReadSize, Buffer);\r
           Status = ShellWriteFile(DestHandle, &ReadSize, Buffer);\r
         }\r
@@ -255,7 +256,7 @@ CopySingleFile(
   //\r
   // return\r
   //\r
-  return (SHELL_SUCCESS);\r
+  return ShellStatus;\r
 }\r
 \r
 /**\r
@@ -313,11 +314,6 @@ ValidateAndCopyFiles(
   ASSERT(FileList != NULL);\r
   ASSERT(DestDir  != NULL);\r
 \r
-  //\r
-  // We already verified that this was present.\r
-  //\r
-  ASSERT(Cwd      != NULL);\r
-\r
   //\r
   // If we are trying to copy multiple files... make sure we got a directory for the target...\r
   //\r
@@ -341,7 +337,7 @@ ValidateAndCopyFiles(
 \r
     NewSize =  StrSize(DestDir);\r
     NewSize += StrSize(Node->FullName);\r
-    NewSize += StrSize(Cwd);\r
+    NewSize += (Cwd == NULL)? 0 : StrSize(Cwd);\r
     if (NewSize > PathLen) {\r
       PathLen = NewSize;\r
     }\r
@@ -404,7 +400,12 @@ ValidateAndCopyFiles(
         //\r
         // simple copy of a single file\r
         //\r
-        StrCpy(DestPath, Cwd);\r
+        if (Cwd != NULL) {\r
+          StrCpy(DestPath, Cwd);\r
+        } else {\r
+          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, DestDir);\r
+          return (SHELL_INVALID_PARAMETER);\r
+        }\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
@@ -423,15 +424,25 @@ ValidateAndCopyFiles(
       // Check for leading slash\r
       //\r
       if (DestDir[0] == L'\\') {\r
-          //\r
-          // Copy to the root of CWD\r
-          //\r
-        StrCpy(DestPath, Cwd);\r
+         //\r
+         // Copy to the root of CWD\r
+         //\r
+        if (Cwd != NULL) {\r
+          StrCpy(DestPath, Cwd);\r
+        } else {\r
+          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, DestDir);\r
+          return (SHELL_INVALID_PARAMETER);\r
+        }\r
         while (PathRemoveLastItem(DestPath));\r
         StrCat(DestPath, DestDir+1);\r
         StrCat(DestPath, Node->FileName);\r
       } else if (StrStr(DestDir, L":") == NULL) {\r
-        StrCpy(DestPath, Cwd);\r
+        if (Cwd != NULL) {\r
+          StrCpy(DestPath, Cwd);\r
+        } else {\r
+          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, DestDir);\r
+          return (SHELL_INVALID_PARAMETER);\r
+        }\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
@@ -537,12 +548,11 @@ ProcessValidateAndCopyFiles(
 {\r
   SHELL_STATUS        ShellStatus;\r
   EFI_SHELL_FILE_INFO *List;\r
-  EFI_STATUS          Status;\r
   EFI_FILE_INFO       *FileInfo;\r
 \r
   List = NULL;\r
 \r
-  Status = ShellOpenFileMetaArg((CHAR16*)DestDir, EFI_FILE_MODE_READ, &List);\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
     ShellStatus = SHELL_INVALID_PARAMETER;\r
@@ -562,7 +572,7 @@ ProcessValidateAndCopyFiles(
     SHELL_FREE_NON_NULL(FileInfo);\r
     ShellCloseFileMetaArg(&List);\r
   } else {\r
-      ShellStatus = ValidateAndCopyFiles(FileList, DestDir, SilentMode, RecursiveMode, NULL);\r
+    ShellStatus = ValidateAndCopyFiles(FileList, DestDir, SilentMode, RecursiveMode, NULL);\r
   }\r
 \r
   return (ShellStatus);\r