2 Main file for cp shell level 2 function.
4 Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "UefiShellLevel2CommandsLib.h"
16 #include <Guid/FileSystemInfo.h>
17 #include <Guid/FileSystemVolumeLabelInfo.h>
20 Function to take a list of files to copy and a destination location and do
21 the verification and copying of those files to that location. This function
22 will report any errors to the user and halt.
24 @param[in] FileList A LIST_ENTRY* based list of files to move.
25 @param[in] DestDir The destination location.
26 @param[in] SilentMode TRUE to eliminate screen output.
27 @param[in] RecursiveMode TRUE to copy directories.
28 @param[in] Resp The response to the overwrite query (if always).
30 @retval SHELL_SUCCESS the files were all moved.
31 @retval SHELL_INVALID_PARAMETER a parameter was invalid
32 @retval SHELL_SECURITY_VIOLATION a security violation ocurred
33 @retval SHELL_WRITE_PROTECTED the destination was write protected
34 @retval SHELL_OUT_OF_RESOURCES a memory allocation failed
39 IN CONST EFI_SHELL_FILE_INFO
*FileList
,
40 IN CONST CHAR16
*DestDir
,
41 IN BOOLEAN SilentMode
,
42 IN BOOLEAN RecursiveMode
,
47 Function to Copy one file to another location
49 If the destination exists the user will be prompted and the result put into *resp
51 @param[in] Source pointer to source file name
52 @param[in] Dest pointer to destination file name
53 @param[out] Resp pointer to response from question. Pass back on looped calling
54 @param[in] SilentMode whether to run in quiet mode or not
56 @retval SHELL_SUCCESS The source file was copied to the destination
61 IN CONST CHAR16
*Source
,
62 IN CONST CHAR16
*Dest
,
69 SHELL_FILE_HANDLE SourceHandle
;
70 SHELL_FILE_HANDLE DestHandle
;
75 EFI_SHELL_FILE_INFO
*List
;
76 SHELL_STATUS ShellStatus
;
77 UINT64 SourceFileSize
;
79 EFI_FILE_PROTOCOL
*DestVolumeFP
;
80 EFI_FILE_SYSTEM_INFO
*DestVolumeInfo
;
81 UINTN DestVolumeInfoSize
;
89 DestVolumeInfo
= NULL
;
90 ShellStatus
= SHELL_SUCCESS
;
92 ReadSize
= PcdGet32(PcdShellFileOperationSize
);
93 // Why bother copying a file to itself
94 if (StrCmp(Source
, Dest
) == 0) {
95 return (SHELL_SUCCESS
);
99 // if the destination file existed check response and possibly prompt user
101 if (ShellFileExists(Dest
) == EFI_SUCCESS
) {
102 if (Response
== NULL
&& !SilentMode
) {
103 Status
= ShellPromptForResponseHii(ShellPromptResponseTypeYesNoAllCancel
, STRING_TOKEN (STR_GEN_DEST_EXIST_OVR
), gShellLevel2HiiHandle
, &Response
);
106 // possibly return based on response
109 switch (*(SHELL_PROMPT_RESPONSE
*)Response
) {
110 case ShellPromptResponseNo
:
112 // return success here so we dont stop the process
114 return (SHELL_SUCCESS
);
115 case ShellPromptResponseCancel
:
118 // indicate to stop everything
120 return (SHELL_ABORTED
);
121 case ShellPromptResponseAll
:
123 case ShellPromptResponseYes
:
126 return SHELL_ABORTED
;
131 if (ShellIsDirectory(Source
) == EFI_SUCCESS
) {
132 Status
= ShellCreateDirectory(Dest
, &DestHandle
);
133 if (EFI_ERROR(Status
)) {
134 return (SHELL_ACCESS_DENIED
);
138 // Now copy all the files under the directory...
142 StrnCatGrow(&TempName
, &Size
, Source
, 0);
143 StrnCatGrow(&TempName
, &Size
, L
"\\*", 0);
144 if (TempName
!= NULL
) {
145 ShellOpenFileMetaArg((CHAR16
*)TempName
, EFI_FILE_MODE_READ
, &List
);
146 *TempName
= CHAR_NULL
;
147 StrnCatGrow(&TempName
, &Size
, Dest
, 0);
148 StrnCatGrow(&TempName
, &Size
, L
"\\", 0);
149 ShellStatus
= ValidateAndCopyFiles(List
, TempName
, SilentMode
, TRUE
, Resp
);
150 ShellCloseFileMetaArg(&List
);
151 SHELL_FREE_NON_NULL(TempName
);
155 Status
= ShellDeleteFileByName(Dest
);
158 // open file with create enabled
160 Status
= ShellOpenFileByName(Dest
, &DestHandle
, EFI_FILE_MODE_READ
|EFI_FILE_MODE_WRITE
|EFI_FILE_MODE_CREATE
, 0);
161 if (EFI_ERROR(Status
)) {
162 return (SHELL_ACCESS_DENIED
);
168 Status
= ShellOpenFileByName(Source
, &SourceHandle
, EFI_FILE_MODE_READ
, 0);
169 ASSERT_EFI_ERROR(Status
);
172 //get file size of source file and freespace available on destination volume
174 ShellGetFileSize(SourceHandle
, &SourceFileSize
);
175 ShellGetFileSize(DestHandle
, &DestFileSize
);
178 //if the destination file already exists then it will be replaced, meaning the sourcefile effectively needs less storage space
180 if(DestFileSize
< SourceFileSize
){
181 SourceFileSize
-= DestFileSize
;
187 //get the system volume info to check the free space
189 DestVolumeFP
= ConvertShellHandleToEfiFileProtocol(DestHandle
);
190 DestVolumeInfo
= NULL
;
191 DestVolumeInfoSize
= 0;
192 Status
= DestVolumeFP
->GetInfo(
194 &gEfiFileSystemInfoGuid
,
199 if (Status
== EFI_BUFFER_TOO_SMALL
) {
200 DestVolumeInfo
= AllocateZeroPool(DestVolumeInfoSize
);
201 Status
= DestVolumeFP
->GetInfo(
203 &gEfiFileSystemInfoGuid
,
210 //check if enough space available on destination drive to complete copy
212 if (DestVolumeInfo
!= NULL
&& (DestVolumeInfo
->FreeSpace
< SourceFileSize
)) {
214 //not enough space on destination directory to copy file
216 SHELL_FREE_NON_NULL(DestVolumeInfo
);
217 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_CPY_FAIL
), gShellLevel2HiiHandle
);
218 return(SHELL_VOLUME_FULL
);
221 // copy data between files
223 Buffer
= AllocateZeroPool(ReadSize
);
224 ASSERT(Buffer
!= NULL
);
225 while (ReadSize
== PcdGet32(PcdShellFileOperationSize
) && !EFI_ERROR(Status
)) {
226 Status
= ShellReadFile(SourceHandle
, &ReadSize
, Buffer
);
227 Status
= ShellWriteFile(DestHandle
, &ReadSize
, Buffer
);
230 SHELL_FREE_NON_NULL(DestVolumeInfo
);
236 if (DestHandle
!= NULL
) {
237 ShellCloseFile(&DestHandle
);
240 if (SourceHandle
!= NULL
) {
241 ShellCloseFile(&SourceHandle
);
252 function to take a list of files to copy and a destination location and do
253 the verification and copying of those files to that location. This function
254 will report any errors to the user and halt.
256 The key is to have this function called ONLY once. this allows for the parameter
257 verification to happen correctly.
259 @param[in] FileList A LIST_ENTRY* based list of files to move.
260 @param[in] DestDir The destination location.
261 @param[in] SilentMode TRUE to eliminate screen output.
262 @param[in] RecursiveMode TRUE to copy directories.
263 @param[in] Resp The response to the overwrite query (if always).
265 @retval SHELL_SUCCESS the files were all moved.
266 @retval SHELL_INVALID_PARAMETER a parameter was invalid
267 @retval SHELL_SECURITY_VIOLATION a security violation ocurred
268 @retval SHELL_WRITE_PROTECTED the destination was write protected
269 @retval SHELL_OUT_OF_RESOURCES a memory allocation failed
273 ValidateAndCopyFiles(
274 IN CONST EFI_SHELL_FILE_INFO
*FileList
,
275 IN CONST CHAR16
*DestDir
,
276 IN BOOLEAN SilentMode
,
277 IN BOOLEAN RecursiveMode
,
283 CONST EFI_SHELL_FILE_INFO
*Node
;
284 SHELL_STATUS ShellStatus
;
298 ShellStatus
= SHELL_SUCCESS
;
300 Cwd
= ShellGetCurrentDir(NULL
);
302 ASSERT(FileList
!= NULL
);
303 ASSERT(DestDir
!= NULL
);
306 // If we are trying to copy multiple files... make sure we got a directory for the target...
308 if (EFI_ERROR(ShellIsDirectory(DestDir
)) && FileList
->Link
.ForwardLink
!= FileList
->Link
.BackLink
) {
310 // Error for destination not a directory
312 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NOT_DIR
), gShellLevel2HiiHandle
, DestDir
);
313 return (SHELL_INVALID_PARAMETER
);
315 for (Node
= (EFI_SHELL_FILE_INFO
*)GetFirstNode(&FileList
->Link
)
316 ; !IsNull(&FileList
->Link
, &Node
->Link
)
317 ; Node
= (EFI_SHELL_FILE_INFO
*)GetNextNode(&FileList
->Link
, &Node
->Link
)
320 // skip the directory traversing stuff...
322 if (StrCmp(Node
->FileName
, L
".") == 0 || StrCmp(Node
->FileName
, L
"..") == 0) {
326 NewSize
= StrSize(DestDir
);
327 NewSize
+= StrSize(Node
->FullName
);
328 NewSize
+= (Cwd
== NULL
)? 0 : StrSize(Cwd
);
329 if (NewSize
> PathLen
) {
334 // Make sure got -r if required
336 if (!RecursiveMode
&& !EFI_ERROR(ShellIsDirectory(Node
->FullName
))) {
337 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_CP_DIR_REQ
), gShellLevel2HiiHandle
);
338 return (SHELL_INVALID_PARAMETER
);
342 // make sure got dest as dir if needed
344 if (!EFI_ERROR(ShellIsDirectory(Node
->FullName
)) && EFI_ERROR(ShellIsDirectory(DestDir
))) {
346 // Error for destination not a directory
348 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NOT_DIR
), gShellLevel2HiiHandle
, DestDir
);
349 return (SHELL_INVALID_PARAMETER
);
353 HiiOutput
= HiiGetString (gShellLevel2HiiHandle
, STRING_TOKEN (STR_CP_OUTPUT
), NULL
);
354 HiiResultOk
= HiiGetString (gShellLevel2HiiHandle
, STRING_TOKEN (STR_GEN_RES_OK
), NULL
);
355 DestPath
= AllocateZeroPool(PathLen
);
357 if (DestPath
== NULL
|| HiiOutput
== NULL
|| HiiResultOk
== NULL
) {
358 SHELL_FREE_NON_NULL(DestPath
);
359 SHELL_FREE_NON_NULL(HiiOutput
);
360 SHELL_FREE_NON_NULL(HiiResultOk
);
361 return (SHELL_OUT_OF_RESOURCES
);
365 // Go through the list of files to copy...
367 for (Node
= (EFI_SHELL_FILE_INFO
*)GetFirstNode(&FileList
->Link
)
368 ; !IsNull(&FileList
->Link
, &Node
->Link
)
369 ; Node
= (EFI_SHELL_FILE_INFO
*)GetNextNode(&FileList
->Link
, &Node
->Link
)
371 if (ShellGetExecutionBreakFlag()) {
374 ASSERT(Node
->FileName
!= NULL
);
375 ASSERT(Node
->FullName
!= NULL
);
378 // skip the directory traversing stuff...
380 if (StrCmp(Node
->FileName
, L
".") == 0 || StrCmp(Node
->FileName
, L
"..") == 0) {
384 if (FileList
->Link
.ForwardLink
== FileList
->Link
.BackLink
// 1 item
385 && EFI_ERROR(ShellIsDirectory(DestDir
)) // not an existing directory
387 if (StrStr(DestDir
, L
":") == NULL
) {
389 // simple copy of a single file
392 StrCpy(DestPath
, Cwd
);
394 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_DIR_NF
), gShellLevel2HiiHandle
, DestDir
);
395 return (SHELL_INVALID_PARAMETER
);
397 if (DestPath
[StrLen(DestPath
)-1] != L
'\\' && DestDir
[0] != L
'\\') {
398 StrCat(DestPath
, L
"\\");
399 } else if (DestPath
[StrLen(DestPath
)-1] == L
'\\' && DestDir
[0] == L
'\\') {
400 ((CHAR16
*)DestPath
)[StrLen(DestPath
)-1] = CHAR_NULL
;
402 StrCat(DestPath
, DestDir
);
404 StrCpy(DestPath
, DestDir
);
408 // we have multiple files or a directory in the DestDir
412 // Check for leading slash
414 if (DestDir
[0] == L
'\\') {
416 // Copy to the root of CWD
419 StrCpy(DestPath
, Cwd
);
421 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_DIR_NF
), gShellLevel2HiiHandle
, DestDir
);
422 return (SHELL_INVALID_PARAMETER
);
424 while (PathRemoveLastItem(DestPath
));
425 StrCat(DestPath
, DestDir
+1);
426 StrCat(DestPath
, Node
->FileName
);
427 } else if (StrStr(DestDir
, L
":") == NULL
) {
429 StrCpy(DestPath
, Cwd
);
431 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_DIR_NF
), gShellLevel2HiiHandle
, DestDir
);
432 return (SHELL_INVALID_PARAMETER
);
434 if (DestPath
[StrLen(DestPath
)-1] != L
'\\' && DestDir
[0] != L
'\\') {
435 StrCat(DestPath
, L
"\\");
436 } else if (DestPath
[StrLen(DestPath
)-1] == L
'\\' && DestDir
[0] == L
'\\') {
437 ((CHAR16
*)DestPath
)[StrLen(DestPath
)-1] = CHAR_NULL
;
439 StrCat(DestPath
, DestDir
);
440 if (DestDir
[StrLen(DestDir
)-1] != L
'\\' && Node
->FileName
[0] != L
'\\') {
441 StrCat(DestPath
, L
"\\");
442 } else if (DestDir
[StrLen(DestDir
)-1] == L
'\\' && Node
->FileName
[0] == L
'\\') {
443 ((CHAR16
*)DestPath
)[StrLen(DestPath
)-1] = CHAR_NULL
;
445 StrCat(DestPath
, Node
->FileName
);
448 StrCpy(DestPath
, DestDir
);
449 if (DestDir
[StrLen(DestDir
)-1] != L
'\\' && Node
->FileName
[0] != L
'\\') {
450 StrCat(DestPath
, L
"\\");
451 } else if (DestDir
[StrLen(DestDir
)-1] == L
'\\' && Node
->FileName
[0] == L
'\\') {
452 ((CHAR16
*)DestDir
)[StrLen(DestDir
)-1] = CHAR_NULL
;
454 StrCat(DestPath
, Node
->FileName
);
459 // Make sure the path exists
461 if (EFI_ERROR(VerifyIntermediateDirectories(DestPath
))) {
462 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_CP_DIR_WNF
), gShellLevel2HiiHandle
);
463 ShellStatus
= SHELL_DEVICE_ERROR
;
467 if ( !EFI_ERROR(ShellIsDirectory(Node
->FullName
))
468 && !EFI_ERROR(ShellIsDirectory(DestPath
))
469 && StrniCmp(Node
->FullName
, DestPath
, StrLen(DestPath
)) == NULL
471 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_CP_SD_PARENT
), gShellLevel2HiiHandle
);
472 ShellStatus
= SHELL_INVALID_PARAMETER
;
475 if (StringNoCaseCompare(&Node
->FullName
, &DestPath
) == 0) {
476 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_CP_SD_SAME
), gShellLevel2HiiHandle
);
477 ShellStatus
= SHELL_INVALID_PARAMETER
;
481 if ((StrniCmp(Node
->FullName
, DestPath
, StrLen(Node
->FullName
)) == 0)
482 && (DestPath
[StrLen(Node
->FullName
)] == CHAR_NULL
|| DestPath
[StrLen(Node
->FullName
)] == L
'\\')
484 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_CP_SD_SAME
), gShellLevel2HiiHandle
);
485 ShellStatus
= SHELL_INVALID_PARAMETER
;
489 PathCleanUpDirectories(DestPath
);
491 ShellPrintEx(-1, -1, HiiOutput
, Node
->FullName
, DestPath
);
494 // copy single file...
496 ShellStatus
= CopySingleFile(Node
->FullName
, DestPath
, &Response
, SilentMode
);
497 if (ShellStatus
!= SHELL_SUCCESS
) {
501 if (ShellStatus
== SHELL_SUCCESS
&& Resp
== NULL
) {
502 ShellPrintEx(-1, -1, L
"%s", HiiResultOk
);
505 SHELL_FREE_NON_NULL(DestPath
);
506 SHELL_FREE_NON_NULL(HiiOutput
);
507 SHELL_FREE_NON_NULL(HiiResultOk
);
509 SHELL_FREE_NON_NULL(Response
);
512 return (ShellStatus
);
517 Validate and if successful copy all the files from the list into
518 destination directory.
520 @param[in] FileList The list of files to copy.
521 @param[in] DestDir The directory to copy files to.
522 @param[in] SilentMode TRUE to eliminate screen output.
523 @param[in] RecursiveMode TRUE to copy directories.
525 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
526 @retval SHELL_SUCCESS The operation was successful.
530 ProcessValidateAndCopyFiles(
531 IN EFI_SHELL_FILE_INFO
*FileList
,
532 IN CONST CHAR16
*DestDir
,
533 IN BOOLEAN SilentMode
,
534 IN BOOLEAN RecursiveMode
537 SHELL_STATUS ShellStatus
;
538 EFI_SHELL_FILE_INFO
*List
;
539 EFI_FILE_INFO
*FileInfo
;
546 ShellOpenFileMetaArg((CHAR16
*)DestDir
, EFI_FILE_MODE_READ
, &List
);
547 if (List
!= NULL
&& List
->Link
.ForwardLink
!= List
->Link
.BackLink
) {
548 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_MARG_ERROR
), gShellLevel2HiiHandle
, DestDir
);
549 ShellStatus
= SHELL_INVALID_PARAMETER
;
550 ShellCloseFileMetaArg(&List
);
551 } else if (List
!= NULL
) {
552 ASSERT(((EFI_SHELL_FILE_INFO
*)List
->Link
.ForwardLink
) != NULL
);
553 ASSERT(((EFI_SHELL_FILE_INFO
*)List
->Link
.ForwardLink
)->FullName
!= NULL
);
554 FileInfo
= gEfiShellProtocol
->GetFileInfo(((EFI_SHELL_FILE_INFO
*)List
->Link
.ForwardLink
)->Handle
);
555 ASSERT(FileInfo
!= NULL
);
556 StrnCatGrow(&FullName
, NULL
, ((EFI_SHELL_FILE_INFO
*)List
->Link
.ForwardLink
)->FullName
, 0);
557 ShellCloseFileMetaArg(&List
);
558 if ((FileInfo
->Attribute
& EFI_FILE_READ_ONLY
) == 0) {
559 ShellStatus
= ValidateAndCopyFiles(FileList
, FullName
, SilentMode
, RecursiveMode
, NULL
);
561 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_CP_DEST_ERROR
), gShellLevel2HiiHandle
);
562 ShellStatus
= SHELL_ACCESS_DENIED
;
565 ShellCloseFileMetaArg(&List
);
566 ShellStatus
= ValidateAndCopyFiles(FileList
, DestDir
, SilentMode
, RecursiveMode
, NULL
);
569 SHELL_FREE_NON_NULL(FileInfo
);
570 SHELL_FREE_NON_NULL(FullName
);
571 return (ShellStatus
);
574 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
581 Function for 'cp' command.
583 @param[in] ImageHandle Handle to the Image (NULL if Internal).
584 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
589 IN EFI_HANDLE ImageHandle
,
590 IN EFI_SYSTEM_TABLE
*SystemTable
595 CHAR16
*ProblemParam
;
596 SHELL_STATUS ShellStatus
;
599 EFI_SHELL_FILE_INFO
*FileList
;
601 BOOLEAN RecursiveMode
;
605 ShellStatus
= SHELL_SUCCESS
;
610 // initialize the shell lib (we must be in non-auto-init...)
612 Status
= ShellInitialize();
613 ASSERT_EFI_ERROR(Status
);
615 Status
= CommandInit();
616 ASSERT_EFI_ERROR(Status
);
619 // parse the command line
621 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
622 if (EFI_ERROR(Status
)) {
623 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
624 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ProblemParam
);
625 FreePool(ProblemParam
);
626 ShellStatus
= SHELL_INVALID_PARAMETER
;
634 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
639 // Initialize SilentMode and RecursiveMode
641 if (gEfiShellProtocol
->BatchIsActive()) {
644 SilentMode
= ShellCommandLineGetFlag(Package
, L
"-q");
646 RecursiveMode
= ShellCommandLineGetFlag(Package
, L
"-r");
648 switch (ParamCount
= ShellCommandLineGetCount(Package
)) {
652 // we have insufficient parameters
654 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel2HiiHandle
);
655 ShellStatus
= SHELL_INVALID_PARAMETER
;
659 // must have valid CWD for single parameter...
661 Cwd
= ShellGetCurrentDir(NULL
);
663 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_CWD
), gShellLevel2HiiHandle
);
664 ShellStatus
= SHELL_INVALID_PARAMETER
;
666 Status
= ShellOpenFileMetaArg((CHAR16
*)ShellCommandLineGetRawValue(Package
, 1), EFI_FILE_MODE_WRITE
|EFI_FILE_MODE_READ
, &FileList
);
667 if (FileList
== NULL
|| IsListEmpty(&FileList
->Link
) || EFI_ERROR(Status
)) {
668 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_FILE_NF
), gShellLevel2HiiHandle
, ShellCommandLineGetRawValue(Package
, 1));
669 ShellStatus
= SHELL_NOT_FOUND
;
671 ShellStatus
= ProcessValidateAndCopyFiles(FileList
, Cwd
, SilentMode
, RecursiveMode
);
678 // Make a big list of all the files...
680 for (ParamCount
--, LoopCounter
= 1 ; LoopCounter
< ParamCount
&& ShellStatus
== SHELL_SUCCESS
; LoopCounter
++) {
681 if (ShellGetExecutionBreakFlag()) {
684 Status
= ShellOpenFileMetaArg((CHAR16
*)ShellCommandLineGetRawValue(Package
, LoopCounter
), EFI_FILE_MODE_WRITE
|EFI_FILE_MODE_READ
, &FileList
);
685 if (EFI_ERROR(Status
) || FileList
== NULL
|| IsListEmpty(&FileList
->Link
)) {
686 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_FILE_NF
), gShellLevel2HiiHandle
, ShellCommandLineGetRawValue(Package
, LoopCounter
));
687 ShellStatus
= SHELL_NOT_FOUND
;
690 if (ShellStatus
!= SHELL_SUCCESS
) {
691 Status
= ShellCloseFileMetaArg(&FileList
);
694 // now copy them all...
696 if (FileList
!= NULL
&& !IsListEmpty(&FileList
->Link
)) {
697 ShellStatus
= ProcessValidateAndCopyFiles(FileList
, PathCleanUpDirectories((CHAR16
*)ShellCommandLineGetRawValue(Package
, ParamCount
)), SilentMode
, RecursiveMode
);
698 Status
= ShellCloseFileMetaArg(&FileList
);
699 if (EFI_ERROR(Status
) && ShellStatus
== SHELL_SUCCESS
) {
700 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_FILE
), gShellLevel2HiiHandle
, ShellCommandLineGetRawValue(Package
, ParamCount
), ShellStatus
|MAX_BIT
);
701 ShellStatus
= SHELL_ACCESS_DENIED
;
706 } // switch on parameter count
708 if (FileList
!= NULL
) {
709 ShellCloseFileMetaArg(&FileList
);
713 // free the command line package
715 ShellCommandLineFreeVarList (Package
);
718 if (ShellGetExecutionBreakFlag()) {
719 return (SHELL_ABORTED
);
722 return (ShellStatus
);