2 Main file for mv shell level 2 function.
4 (C) Copyright 2013-2014, Hewlett-Packard Development Company, L.P.
5 Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "UefiShellLevel2CommandsLib.h"
19 function to determine if a move is between file systems.
21 @param FullName [in] The name of the file to move.
22 @param Cwd [in] The current working directory
23 @param DestPath [in] The target location to move to
25 @retval TRUE The move is across file system.
26 @retval FALSE The move is within a file system.
31 IN CONST CHAR16
*FullName
,
33 IN CONST CHAR16
*DestPath
40 Test
= StrStr(FullName
, L
":");
41 if (Test
== NULL
&& Cwd
!= NULL
) {
42 Test
= StrStr(Cwd
, L
":");
44 Test1
= StrStr(DestPath
, L
":");
45 if (Test1
== NULL
&& Cwd
!= NULL
) {
46 Test1
= StrStr(Cwd
, L
":");
48 if (Test1
!= NULL
&& Test
!= NULL
) {
51 Result
= StringNoCaseCompare(&FullName
, &DestPath
);
62 Function to validate that moving a specific file (FileName) to a specific
63 location (DestPath) is valid.
65 This function will verify that the destination is not a subdirectory of
66 FullName, that the Current working Directory is not being moved, and that
67 the directory is not read only.
69 if the move is invalid this function will report the error to StdOut.
71 @param SourcePath [in] The name of the file to move.
72 @param Cwd [in] The current working directory
73 @param DestPath [in] The target location to move to
74 @param Attribute [in] The Attribute of the file
75 @param DestAttr [in] The Attribute of the destination
76 @param FileStatus [in] The Status of the file when opened
78 @retval TRUE The move is valid
79 @retval FALSE The move is not
84 IN CONST CHAR16
*SourcePath
,
86 IN CONST CHAR16
*DestPath
,
87 IN CONST UINT64 Attribute
,
88 IN CONST UINT64 DestAttr
,
89 IN CONST EFI_STATUS FileStatus
93 CHAR16
*DestPathWalker
;
95 if (Cwd
!= NULL
&& StrCmp(SourcePath
, Cwd
) == 0) {
99 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MV_INV_CWD
), gShellLevel2HiiHandle
);
104 // invalid to move read only or move to a read only destination
106 if (((Attribute
& EFI_FILE_READ_ONLY
) != 0)
107 || (FileStatus
== EFI_WRITE_PROTECTED
)
108 || ((DestAttr
& EFI_FILE_READ_ONLY
) != 0)
110 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MV_INV_RO
), gShellLevel2HiiHandle
, SourcePath
);
114 DestPathCopy
= AllocateCopyPool(StrSize(DestPath
), DestPath
);
115 if (DestPathCopy
== NULL
) {
119 for (DestPathWalker
= DestPathCopy
; *DestPathWalker
== L
'\\'; DestPathWalker
++) ;
121 while(DestPathWalker
!= NULL
&& DestPathWalker
[StrLen(DestPathWalker
)-1] == L
'\\') {
122 DestPathWalker
[StrLen(DestPathWalker
)-1] = CHAR_NULL
;
125 ASSERT(DestPathWalker
!= NULL
);
126 ASSERT(SourcePath
!= NULL
);
129 // If they're the same, or if source is "above" dest on file path tree
131 if ( StrCmp(DestPathWalker
, SourcePath
) == 0
132 || StrStr(DestPathWalker
, SourcePath
) == DestPathWalker
134 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MV_INV_SUB
), gShellLevel2HiiHandle
);
135 FreePool(DestPathCopy
);
138 FreePool(DestPathCopy
);
144 Function to take a destination path that might contain wildcards and verify
145 that there is only a single possible target (IE we cant have wildcards that
146 have 2 possible destination).
148 if the result is sucessful the caller must free *DestPathPointer.
150 @param[in] DestParameter The original path to the destination.
151 @param[in, out] DestPathPointer A pointer to the callee allocated final path.
152 @param[in] Cwd A pointer to the current working directory.
153 @param[in] SingleSource TRUE to have only one source file.
154 @param[in, out] DestAttr A pointer to the destination information attribute.
156 @retval SHELL_INVALID_PARAMETER The DestParameter could not be resolved to a location.
157 @retval SHELL_INVALID_PARAMETER The DestParameter could be resolved to more than 1 location.
158 @retval SHELL_INVALID_PARAMETER Cwd is required and is NULL.
159 @retval SHELL_SUCCESS The operation was sucessful.
163 GetDestinationLocation(
164 IN CONST CHAR16
*DestParameter
,
165 IN OUT CHAR16
**DestPathPointer
,
166 IN CONST CHAR16
*Cwd
,
167 IN CONST BOOLEAN SingleSource
,
168 IN OUT UINT64
*DestAttr
171 EFI_SHELL_FILE_INFO
*DestList
;
172 EFI_SHELL_FILE_INFO
*Node
;
180 ASSERT(DestAttr
!= NULL
);
182 if (StrStr(DestParameter
, L
"\\") == DestParameter
) {
184 return SHELL_INVALID_PARAMETER
;
186 DestPath
= AllocateZeroPool(StrSize(Cwd
));
187 if (DestPath
== NULL
) {
188 return (SHELL_OUT_OF_RESOURCES
);
190 StrCpy(DestPath
, Cwd
);
191 while (PathRemoveLastItem(DestPath
)) ;
194 // Append DestParameter beyond '\' which may be present
196 CurrentSize
= StrSize(DestPath
);
197 StrnCatGrow(&DestPath
, &CurrentSize
, &DestParameter
[1], 0);
199 *DestPathPointer
= DestPath
;
200 return (SHELL_SUCCESS
);
203 // get the destination path
205 ShellOpenFileMetaArg((CHAR16
*)DestParameter
, EFI_FILE_MODE_WRITE
|EFI_FILE_MODE_READ
|EFI_FILE_MODE_CREATE
, &DestList
);
206 if (DestList
== NULL
|| IsListEmpty(&DestList
->Link
)) {
208 // Not existing... must be renaming
210 if (StrStr(DestParameter
, L
":") == NULL
) {
212 ShellCloseFileMetaArg(&DestList
);
213 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_CWD
), gShellLevel2HiiHandle
);
214 return (SHELL_INVALID_PARAMETER
);
216 NewSize
= StrSize(Cwd
);
217 NewSize
+= StrSize(DestParameter
);
218 DestPath
= AllocateZeroPool(NewSize
);
219 if (DestPath
== NULL
) {
220 ShellCloseFileMetaArg(&DestList
);
221 return (SHELL_OUT_OF_RESOURCES
);
223 StrCpy(DestPath
, Cwd
);
224 if (DestPath
[StrLen(DestPath
)-1] != L
'\\' && DestParameter
[0] != L
'\\') {
225 StrCat(DestPath
, L
"\\");
226 } else if (DestPath
[StrLen(DestPath
)-1] == L
'\\' && DestParameter
[0] == L
'\\') {
227 ((CHAR16
*)DestPath
)[StrLen(DestPath
)-1] = CHAR_NULL
;
229 StrCat(DestPath
, DestParameter
);
231 ASSERT(DestPath
== NULL
);
232 DestPath
= StrnCatGrow(&DestPath
, NULL
, DestParameter
, 0);
233 if (DestPath
== NULL
) {
234 ShellCloseFileMetaArg(&DestList
);
235 return (SHELL_OUT_OF_RESOURCES
);
239 Node
= (EFI_SHELL_FILE_INFO
*)GetFirstNode(&DestList
->Link
);
240 *DestAttr
= Node
->Info
->Attribute
;
242 // Make sure there is only 1 node in the list.
244 if (!IsNodeAtEnd(&DestList
->Link
, &Node
->Link
)) {
245 ShellCloseFileMetaArg(&DestList
);
246 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_MARG_ERROR
), gShellLevel2HiiHandle
, DestParameter
);
247 return (SHELL_INVALID_PARAMETER
);
251 // If we are a directory or a single file, then one node is fine.
253 if (ShellIsDirectory(Node
->FullName
)==EFI_SUCCESS
|| SingleSource
) {
254 DestPath
= AllocateZeroPool(StrSize(Node
->FullName
)+sizeof(CHAR16
));
255 if (DestPath
== NULL
) {
256 ShellCloseFileMetaArg(&DestList
);
257 return (SHELL_OUT_OF_RESOURCES
);
259 StrCpy(DestPath
, Node
->FullName
);
260 StrCat(DestPath
, L
"\\");
263 // cant move multiple files onto a single file.
265 ShellCloseFileMetaArg(&DestList
);
266 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_FILE_ERROR
), gShellLevel2HiiHandle
, DestParameter
);
267 return (SHELL_INVALID_PARAMETER
);
271 *DestPathPointer
= DestPath
;
272 ShellCloseFileMetaArg(&DestList
);
274 return (SHELL_SUCCESS
);
278 Function to do a move across file systems.
280 @param[in] Node A pointer to the file to be removed.
281 @param[in] DestPath A pointer to the destination file path.
282 @param[out] Resp A pointer to response from question. Pass back on looped calling
284 @retval SHELL_SUCCESS The source file was moved to the destination.
288 MoveBetweenFileSystems(
289 IN EFI_SHELL_FILE_INFO
*Node
,
290 IN CONST CHAR16
*DestPath
,
297 // First we copy the file
299 Status
= CopySingleFile(Node
->FullName
, DestPath
, Resp
, TRUE
);
304 if (!EFI_ERROR(Status
)) {
306 // The copy was successful. delete the source file.
308 CascadeDelete(Node
, TRUE
);
316 Function to take the destination path and target file name to generate the full destination path.
318 @param[in] DestPath A pointer to the destination file path string.
319 @param[out] FullDestPath A pointer to the full destination path string.
320 @param[in] FileName Name string of the targe file.
322 @retval SHELL_SUCCESS the files were all moved.
323 @retval SHELL_INVALID_PARAMETER a parameter was invalid
324 @retval SHELL_OUT_OF_RESOURCES a memory allocation failed
329 IN CONST CHAR16
**DestPath
,
330 OUT CHAR16
**FullDestPath
,
331 IN CONST CHAR16
*FileName
335 if (FullDestPath
== NULL
|| FileName
== NULL
|| DestPath
== NULL
|| *DestPath
== NULL
){
336 return (EFI_INVALID_PARAMETER
);
339 Size
= StrSize(*DestPath
) + StrSize(FileName
);
341 *FullDestPath
= AllocateZeroPool(Size
);
342 if (*FullDestPath
== NULL
){
343 return (EFI_OUT_OF_RESOURCES
);
346 StrnCpy(*FullDestPath
, *DestPath
, Size
/ sizeof(CHAR16
) - 1);
347 if ((*FullDestPath
)[StrLen(*FullDestPath
)-1] != L
'\\' && FileName
[0] != L
'\\') {
348 StrnCat(*FullDestPath
, L
"\\",Size
/ sizeof(CHAR16
) - 1 - StrLen(*FullDestPath
));
350 StrnCat(*FullDestPath
, FileName
, Size
/ sizeof(CHAR16
) - 1 - StrLen(*FullDestPath
));
352 return (EFI_SUCCESS
);
356 Function to do a move within a file system.
358 @param[in] Node A pointer to the file to be removed.
359 @param[in] DestPath A pointer to the destination file path.
360 @param[out] Resp A pointer to response from question. Pass back on looped calling.
362 @retval SHELL_SUCCESS The source file was moved to the destination.
363 @retval SHELL_OUT_OF_RESOURCES A memory allocation failed.
367 MoveWithinFileSystems(
368 IN EFI_SHELL_FILE_INFO
*Node
,
373 EFI_FILE_INFO
*NewFileInfo
;
374 CHAR16
*TempLocation
;
380 // Chop off map info from DestPath
382 if ((TempLocation
= StrStr(DestPath
, L
":")) != NULL
) {
383 CopyMem(DestPath
, TempLocation
+1, StrSize(TempLocation
+1));
387 // construct the new file info block
389 NewSize
= StrSize(DestPath
);
390 NewSize
+= StrSize(Node
->FileName
) + SIZE_OF_EFI_FILE_INFO
+ sizeof(CHAR16
);
391 NewFileInfo
= AllocateZeroPool(NewSize
);
392 if (NewFileInfo
== NULL
) {
393 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_MEM
), gShellLevel2HiiHandle
);
394 Status
= EFI_OUT_OF_RESOURCES
;
396 CopyMem(NewFileInfo
, Node
->Info
, SIZE_OF_EFI_FILE_INFO
);
397 if (DestPath
[0] != L
'\\') {
398 StrCpy(NewFileInfo
->FileName
, L
"\\");
399 StrCat(NewFileInfo
->FileName
, DestPath
);
401 StrCpy(NewFileInfo
->FileName
, DestPath
);
403 Length
= StrLen(NewFileInfo
->FileName
);
407 if (NewFileInfo
->FileName
[Length
] == L
'\\') {
408 if (Node
->FileName
[0] == L
'\\') {
410 // Don't allow for double slashes. Eliminate one of them.
412 NewFileInfo
->FileName
[Length
] = CHAR_NULL
;
414 StrCat(NewFileInfo
->FileName
, Node
->FileName
);
416 NewFileInfo
->Size
= SIZE_OF_EFI_FILE_INFO
+ StrSize(NewFileInfo
->FileName
);
419 // Perform the move operation
421 Status
= ShellSetFileInfo(Node
->Handle
, NewFileInfo
);
424 // Free the info object we used...
426 FreePool(NewFileInfo
);
432 function to take a list of files to move and a destination location and do
433 the verification and moving of those files to that location. This function
434 will report any errors to the user and continue to move the rest of the files.
436 @param[in] FileList A LIST_ENTRY* based list of files to move
437 @param[out] Resp pointer to response from question. Pass back on looped calling
438 @param[in] DestParameter the originally specified destination location
440 @retval SHELL_SUCCESS the files were all moved.
441 @retval SHELL_INVALID_PARAMETER a parameter was invalid
442 @retval SHELL_SECURITY_VIOLATION a security violation ocurred
443 @retval SHELL_WRITE_PROTECTED the destination was write protected
444 @retval SHELL_OUT_OF_RESOURCES a memory allocation failed
448 ValidateAndMoveFiles(
449 IN EFI_SHELL_FILE_INFO
*FileList
,
451 IN CONST CHAR16
*DestParameter
458 CHAR16
*FullDestPath
;
460 SHELL_STATUS ShellStatus
;
461 EFI_SHELL_FILE_INFO
*Node
;
464 CHAR16
*CleanFilePathStr
;
466 ASSERT(FileList
!= NULL
);
467 ASSERT(DestParameter
!= NULL
);
471 Cwd
= ShellGetCurrentDir(NULL
);
474 CleanFilePathStr
= NULL
;
476 Status
= ShellLevel2StripQuotes (DestParameter
, &CleanFilePathStr
);
477 if (EFI_ERROR (Status
)) {
478 if (Status
== EFI_OUT_OF_RESOURCES
) {
479 return SHELL_OUT_OF_RESOURCES
;
481 return SHELL_INVALID_PARAMETER
;
485 ASSERT (CleanFilePathStr
!= NULL
);
488 // Get and validate the destination location
490 ShellStatus
= GetDestinationLocation(CleanFilePathStr
, &DestPath
, Cwd
, (BOOLEAN
)(FileList
->Link
.ForwardLink
== FileList
->Link
.BackLink
), &Attr
);
491 FreePool (CleanFilePathStr
);
493 if (ShellStatus
!= SHELL_SUCCESS
) {
494 return (ShellStatus
);
496 DestPath
= PathCleanUpDirectories(DestPath
);
497 if (DestPath
== NULL
) {
498 return (SHELL_OUT_OF_RESOURCES
);
501 HiiOutput
= HiiGetString (gShellLevel2HiiHandle
, STRING_TOKEN (STR_MV_OUTPUT
), NULL
);
502 HiiResultOk
= HiiGetString (gShellLevel2HiiHandle
, STRING_TOKEN (STR_GEN_RES_OK
), NULL
);
503 if (HiiOutput
== NULL
|| HiiResultOk
== NULL
) {
504 SHELL_FREE_NON_NULL(DestPath
);
505 SHELL_FREE_NON_NULL(HiiOutput
);
506 SHELL_FREE_NON_NULL(HiiResultOk
);
507 return (SHELL_OUT_OF_RESOURCES
);
511 // Go through the list of files and directories to move...
513 for (Node
= (EFI_SHELL_FILE_INFO
*)GetFirstNode(&FileList
->Link
)
514 ; !IsNull(&FileList
->Link
, &Node
->Link
)
515 ; Node
= (EFI_SHELL_FILE_INFO
*)GetNextNode(&FileList
->Link
, &Node
->Link
)
517 if (ShellGetExecutionBreakFlag()) {
522 // These should never be NULL
524 ASSERT(Node
->FileName
!= NULL
);
525 ASSERT(Node
->FullName
!= NULL
);
526 ASSERT(Node
->Info
!= NULL
);
529 // skip the directory traversing stuff...
531 if (StrCmp(Node
->FileName
, L
".") == 0 || StrCmp(Node
->FileName
, L
"..") == 0) {
535 SHELL_FREE_NON_NULL(FullDestPath
);
537 if (ShellIsDirectory(DestPath
)==EFI_SUCCESS
) {
538 CreateFullDestPath((CONST CHAR16
**)&DestPath
, &FullDestPath
, Node
->FileName
);
542 // Validate that the move is valid
544 if (!IsValidMove(Node
->FullName
, Cwd
, FullDestPath
!=NULL
? FullDestPath
:DestPath
, Node
->Info
->Attribute
, Attr
, Node
->Status
)) {
545 ShellStatus
= SHELL_INVALID_PARAMETER
;
549 ShellPrintEx(-1, -1, HiiOutput
, Node
->FullName
, FullDestPath
!=NULL
? FullDestPath
:DestPath
);
552 // See if destination exists
554 if (!EFI_ERROR(ShellFileExists(FullDestPath
!=NULL
? FullDestPath
:DestPath
))) {
555 if (Response
== NULL
) {
556 ShellPromptForResponseHii(ShellPromptResponseTypeYesNoAllCancel
, STRING_TOKEN (STR_GEN_DEST_EXIST_OVR
), gShellLevel2HiiHandle
, &Response
);
558 switch (*(SHELL_PROMPT_RESPONSE
*)Response
) {
559 case ShellPromptResponseNo
:
563 case ShellPromptResponseCancel
:
566 // indicate to stop everything
568 return (SHELL_ABORTED
);
569 case ShellPromptResponseAll
:
572 case ShellPromptResponseYes
:
578 return SHELL_ABORTED
;
580 Status
= ShellDeleteFileByName(FullDestPath
!=NULL
? FullDestPath
:DestPath
);
583 if (IsBetweenFileSystem(Node
->FullName
, Cwd
, DestPath
)) {
584 while (FullDestPath
== NULL
&& DestPath
!= NULL
&& DestPath
[0] != CHAR_NULL
&& DestPath
[StrLen(DestPath
) - 1] == L
'\\') {
585 DestPath
[StrLen(DestPath
) - 1] = CHAR_NULL
;
587 Status
= MoveBetweenFileSystems(Node
, FullDestPath
!=NULL
? FullDestPath
:DestPath
, &Response
);
589 Status
= MoveWithinFileSystems(Node
, DestPath
, &Response
);
595 if (EFI_ERROR(Status
)) {
596 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, Status
);
597 ShellStatus
= SHELL_INVALID_PARAMETER
;
598 if (Status
== EFI_SECURITY_VIOLATION
) {
599 ShellStatus
= SHELL_SECURITY_VIOLATION
;
600 } else if (Status
== EFI_WRITE_PROTECTED
) {
601 ShellStatus
= SHELL_WRITE_PROTECTED
;
602 } else if (Status
== EFI_OUT_OF_RESOURCES
) {
603 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
604 } else if (Status
== EFI_DEVICE_ERROR
) {
605 ShellStatus
= SHELL_DEVICE_ERROR
;
606 } else if (Status
== EFI_ACCESS_DENIED
) {
607 ShellStatus
= SHELL_ACCESS_DENIED
;
610 ShellPrintEx(-1, -1, L
"%s", HiiResultOk
);
615 SHELL_FREE_NON_NULL(FullDestPath
);
616 SHELL_FREE_NON_NULL(DestPath
);
617 SHELL_FREE_NON_NULL(HiiOutput
);
618 SHELL_FREE_NON_NULL(HiiResultOk
);
619 return (ShellStatus
);
623 Function for 'mv' command.
625 @param[in] ImageHandle Handle to the Image (NULL if Internal).
626 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
631 IN EFI_HANDLE ImageHandle
,
632 IN EFI_SYSTEM_TABLE
*SystemTable
637 CHAR16
*ProblemParam
;
638 SHELL_STATUS ShellStatus
;
641 EFI_SHELL_FILE_INFO
*FileList
;
645 ShellStatus
= SHELL_SUCCESS
;
651 // initialize the shell lib (we must be in non-auto-init...)
653 Status
= ShellInitialize();
654 ASSERT_EFI_ERROR(Status
);
657 // parse the command line
659 Status
= ShellCommandLineParse (EmptyParamList
, &Package
, &ProblemParam
, TRUE
);
660 if (EFI_ERROR(Status
)) {
661 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
662 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ProblemParam
);
663 FreePool(ProblemParam
);
664 ShellStatus
= SHELL_INVALID_PARAMETER
;
672 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
676 switch (ParamCount
= ShellCommandLineGetCount(Package
)) {
680 // we have insufficient parameters
682 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel2HiiHandle
);
683 ShellStatus
= SHELL_INVALID_PARAMETER
;
687 // must have valid CWD for single parameter...
689 if (ShellGetCurrentDir(NULL
) == NULL
){
690 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_CWD
), gShellLevel2HiiHandle
);
691 ShellStatus
= SHELL_INVALID_PARAMETER
;
693 Status
= ShellOpenFileMetaArg((CHAR16
*)ShellCommandLineGetRawValue(Package
, 1), EFI_FILE_MODE_WRITE
|EFI_FILE_MODE_READ
, &FileList
);
694 if (FileList
== NULL
|| IsListEmpty(&FileList
->Link
) || EFI_ERROR(Status
)) {
695 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_FILE_NF
), gShellLevel2HiiHandle
, ShellCommandLineGetRawValue(Package
, 1));
696 ShellStatus
= SHELL_NOT_FOUND
;
699 // ValidateAndMoveFiles will report errors to the screen itself
701 ShellStatus
= ValidateAndMoveFiles(FileList
, &Response
, ShellGetCurrentDir(NULL
));
707 ///@todo make sure this works with error half way through and continues...
708 for (ParamCount
--, LoopCounter
= 1 ; LoopCounter
< ParamCount
; LoopCounter
++) {
709 if (ShellGetExecutionBreakFlag()) {
712 Status
= ShellOpenFileMetaArg((CHAR16
*)ShellCommandLineGetRawValue(Package
, LoopCounter
), EFI_FILE_MODE_WRITE
|EFI_FILE_MODE_READ
, &FileList
);
713 if (FileList
== NULL
|| IsListEmpty(&FileList
->Link
) || EFI_ERROR(Status
)) {
714 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_FILE_NF
), gShellLevel2HiiHandle
, ShellCommandLineGetRawValue(Package
, LoopCounter
));
715 ShellStatus
= SHELL_NOT_FOUND
;
718 // ValidateAndMoveFiles will report errors to the screen itself
719 // Only change ShellStatus if it's sucessful
721 if (ShellStatus
== SHELL_SUCCESS
) {
722 ShellStatus
= ValidateAndMoveFiles(FileList
, &Response
, ShellCommandLineGetRawValue(Package
, ParamCount
));
724 ValidateAndMoveFiles(FileList
, &Response
, ShellCommandLineGetRawValue(Package
, ParamCount
));
727 if (FileList
!= NULL
&& !IsListEmpty(&FileList
->Link
)) {
728 Status
= ShellCloseFileMetaArg(&FileList
);
729 if (EFI_ERROR(Status
) && ShellStatus
== SHELL_SUCCESS
) {
730 ShellStatus
= SHELL_ACCESS_DENIED
;
731 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_FILE
), gShellLevel2HiiHandle
, ShellCommandLineGetRawValue(Package
, 1), ShellStatus
|MAX_BIT
);
736 } // switch on parameter count
738 if (FileList
!= NULL
) {
739 ShellCloseFileMetaArg(&FileList
);
743 // free the command line package
745 ShellCommandLineFreeVarList (Package
);
748 SHELL_FREE_NON_NULL(Response
);
750 if (ShellGetExecutionBreakFlag()) {
751 return (SHELL_ABORTED
);
754 return (ShellStatus
);