2 Main file for mv shell level 2 function.
4 (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2009 - 2015, 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 ( StringNoCaseCompare (&DestPathWalker
, &SourcePath
) == 0 ||
132 ((StrStr(DestPathWalker
, SourcePath
) == DestPathWalker
) &&
133 (DestPathWalker
[StrLen(SourcePath
)] == '\\')
136 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MV_INV_SUB
), gShellLevel2HiiHandle
);
137 FreePool(DestPathCopy
);
140 FreePool(DestPathCopy
);
146 Function to take a destination path that might contain wildcards and verify
147 that there is only a single possible target (IE we cant have wildcards that
148 have 2 possible destination).
150 if the result is sucessful the caller must free *DestPathPointer.
152 @param[in] DestParameter The original path to the destination.
153 @param[in, out] DestPathPointer A pointer to the callee allocated final path.
154 @param[in] Cwd A pointer to the current working directory.
155 @param[in] SingleSource TRUE to have only one source file.
156 @param[in, out] DestAttr A pointer to the destination information attribute.
158 @retval SHELL_INVALID_PARAMETER The DestParameter could not be resolved to a location.
159 @retval SHELL_INVALID_PARAMETER The DestParameter could be resolved to more than 1 location.
160 @retval SHELL_INVALID_PARAMETER Cwd is required and is NULL.
161 @retval SHELL_SUCCESS The operation was sucessful.
165 GetDestinationLocation(
166 IN CONST CHAR16
*DestParameter
,
167 IN OUT CHAR16
**DestPathPointer
,
168 IN CONST CHAR16
*Cwd
,
169 IN CONST BOOLEAN SingleSource
,
170 IN OUT UINT64
*DestAttr
173 EFI_SHELL_FILE_INFO
*DestList
;
174 EFI_SHELL_FILE_INFO
*Node
;
182 ASSERT(DestAttr
!= NULL
);
184 if (StrStr(DestParameter
, L
"\\") == DestParameter
) {
186 return SHELL_INVALID_PARAMETER
;
188 DestPath
= AllocateZeroPool(StrSize(Cwd
));
189 if (DestPath
== NULL
) {
190 return (SHELL_OUT_OF_RESOURCES
);
192 StrCpyS(DestPath
, StrSize(Cwd
) / sizeof(CHAR16
), Cwd
);
193 while (PathRemoveLastItem(DestPath
)) ;
196 // Append DestParameter beyond '\' which may be present
198 CurrentSize
= StrSize(DestPath
);
199 StrnCatGrow(&DestPath
, &CurrentSize
, &DestParameter
[1], 0);
201 *DestPathPointer
= DestPath
;
202 return (SHELL_SUCCESS
);
205 // get the destination path
207 ShellOpenFileMetaArg((CHAR16
*)DestParameter
, EFI_FILE_MODE_WRITE
|EFI_FILE_MODE_READ
|EFI_FILE_MODE_CREATE
, &DestList
);
208 if (DestList
== NULL
|| IsListEmpty(&DestList
->Link
)) {
210 // Not existing... must be renaming
212 if (StrStr(DestParameter
, L
":") == NULL
) {
214 ShellCloseFileMetaArg(&DestList
);
215 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_CWD
), gShellLevel2HiiHandle
);
216 return (SHELL_INVALID_PARAMETER
);
218 NewSize
= StrSize(Cwd
);
219 NewSize
+= StrSize(DestParameter
);
220 DestPath
= AllocateZeroPool(NewSize
);
221 if (DestPath
== NULL
) {
222 ShellCloseFileMetaArg(&DestList
);
223 return (SHELL_OUT_OF_RESOURCES
);
225 StrCpyS(DestPath
, NewSize
/ sizeof(CHAR16
), Cwd
);
226 if (DestPath
[StrLen(DestPath
)-1] != L
'\\' && DestParameter
[0] != L
'\\') {
227 StrCatS(DestPath
, NewSize
/ sizeof(CHAR16
), L
"\\");
228 } else if (DestPath
[StrLen(DestPath
)-1] == L
'\\' && DestParameter
[0] == L
'\\') {
229 ((CHAR16
*)DestPath
)[StrLen(DestPath
)-1] = CHAR_NULL
;
231 StrCatS(DestPath
, NewSize
/ sizeof(CHAR16
), DestParameter
);
233 ASSERT(DestPath
== NULL
);
234 DestPath
= StrnCatGrow(&DestPath
, NULL
, DestParameter
, 0);
235 if (DestPath
== NULL
) {
236 ShellCloseFileMetaArg(&DestList
);
237 return (SHELL_OUT_OF_RESOURCES
);
241 Node
= (EFI_SHELL_FILE_INFO
*)GetFirstNode(&DestList
->Link
);
242 *DestAttr
= Node
->Info
->Attribute
;
244 // Make sure there is only 1 node in the list.
246 if (!IsNodeAtEnd(&DestList
->Link
, &Node
->Link
)) {
247 ShellCloseFileMetaArg(&DestList
);
248 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_MARG_ERROR
), gShellLevel2HiiHandle
, L
"mv", DestParameter
);
249 return (SHELL_INVALID_PARAMETER
);
253 // If we are a directory or a single file, then one node is fine.
255 if (ShellIsDirectory(Node
->FullName
)==EFI_SUCCESS
|| SingleSource
) {
256 DestPath
= AllocateZeroPool(StrSize(Node
->FullName
)+sizeof(CHAR16
));
257 if (DestPath
== NULL
) {
258 ShellCloseFileMetaArg(&DestList
);
259 return (SHELL_OUT_OF_RESOURCES
);
261 StrCpyS(DestPath
, (StrSize(Node
->FullName
)+sizeof(CHAR16
)) / sizeof(CHAR16
), Node
->FullName
);
262 StrCatS(DestPath
, (StrSize(Node
->FullName
)+sizeof(CHAR16
)) / sizeof(CHAR16
), L
"\\");
265 // cant move multiple files onto a single file.
267 ShellCloseFileMetaArg(&DestList
);
268 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_FILE_ERROR
), gShellLevel2HiiHandle
, L
"mv", DestParameter
);
269 return (SHELL_INVALID_PARAMETER
);
273 *DestPathPointer
= DestPath
;
274 ShellCloseFileMetaArg(&DestList
);
276 return (SHELL_SUCCESS
);
280 Function to do a move across file systems.
282 @param[in] Node A pointer to the file to be removed.
283 @param[in] DestPath A pointer to the destination file path.
284 @param[out] Resp A pointer to response from question. Pass back on looped calling
286 @retval SHELL_SUCCESS The source file was moved to the destination.
290 MoveBetweenFileSystems(
291 IN EFI_SHELL_FILE_INFO
*Node
,
292 IN CONST CHAR16
*DestPath
,
296 SHELL_STATUS ShellStatus
;
299 // First we copy the file
301 ShellStatus
= CopySingleFile (Node
->FullName
, DestPath
, Resp
, TRUE
, L
"mv");
306 if (ShellStatus
== SHELL_SUCCESS
) {
308 // The copy was successful. delete the source file.
310 CascadeDelete(Node
, TRUE
);
312 } else if (ShellStatus
== SHELL_ABORTED
) {
314 } else if (ShellStatus
== SHELL_ACCESS_DENIED
) {
315 return EFI_ACCESS_DENIED
;
316 } else if (ShellStatus
== SHELL_VOLUME_FULL
) {
317 return EFI_VOLUME_FULL
;
319 return EFI_UNSUPPORTED
;
322 return (EFI_SUCCESS
);
326 Function to take the destination path and target file name to generate the full destination path.
328 @param[in] DestPath A pointer to the destination file path string.
329 @param[out] FullDestPath A pointer to the full destination path string.
330 @param[in] FileName Name string of the targe file.
332 @retval SHELL_SUCCESS the files were all moved.
333 @retval SHELL_INVALID_PARAMETER a parameter was invalid
334 @retval SHELL_OUT_OF_RESOURCES a memory allocation failed
339 IN CONST CHAR16
**DestPath
,
340 OUT CHAR16
**FullDestPath
,
341 IN CONST CHAR16
*FileName
345 if (FullDestPath
== NULL
|| FileName
== NULL
|| DestPath
== NULL
|| *DestPath
== NULL
){
346 return (EFI_INVALID_PARAMETER
);
349 Size
= StrSize(*DestPath
) + StrSize(FileName
);
351 *FullDestPath
= AllocateZeroPool(Size
);
352 if (*FullDestPath
== NULL
){
353 return (EFI_OUT_OF_RESOURCES
);
356 StrCpyS(*FullDestPath
, Size
/ sizeof(CHAR16
), *DestPath
);
357 if ((*FullDestPath
)[StrLen(*FullDestPath
)-1] != L
'\\' && FileName
[0] != L
'\\') {
358 StrCatS(*FullDestPath
, Size
/ sizeof(CHAR16
), L
"\\");
360 StrCatS(*FullDestPath
, Size
/ sizeof(CHAR16
), FileName
);
362 return (EFI_SUCCESS
);
366 Function to do a move within a file system.
368 @param[in] Node A pointer to the file to be removed.
369 @param[in] DestPath A pointer to the destination file path.
370 @param[out] Resp A pointer to response from question. Pass back on looped calling.
372 @retval SHELL_SUCCESS The source file was moved to the destination.
373 @retval SHELL_OUT_OF_RESOURCES A memory allocation failed.
377 MoveWithinFileSystems(
378 IN EFI_SHELL_FILE_INFO
*Node
,
383 EFI_FILE_INFO
*NewFileInfo
;
384 CHAR16
*TempLocation
;
390 // Chop off map info from DestPath
392 if ((TempLocation
= StrStr(DestPath
, L
":")) != NULL
) {
393 CopyMem(DestPath
, TempLocation
+1, StrSize(TempLocation
+1));
397 // construct the new file info block
399 NewSize
= StrSize(DestPath
);
400 NewSize
+= StrSize(Node
->FileName
) + SIZE_OF_EFI_FILE_INFO
+ sizeof(CHAR16
);
401 NewFileInfo
= AllocateZeroPool(NewSize
);
402 if (NewFileInfo
== NULL
) {
403 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_MEM
), gShellLevel2HiiHandle
);
404 Status
= EFI_OUT_OF_RESOURCES
;
406 CopyMem(NewFileInfo
, Node
->Info
, SIZE_OF_EFI_FILE_INFO
);
407 if (DestPath
[0] != L
'\\') {
408 StrCpyS(NewFileInfo
->FileName
, (NewSize
- SIZE_OF_EFI_FILE_INFO
) / sizeof(CHAR16
), L
"\\");
409 StrCatS(NewFileInfo
->FileName
, (NewSize
- SIZE_OF_EFI_FILE_INFO
) / sizeof(CHAR16
), DestPath
);
411 StrCpyS(NewFileInfo
->FileName
, (NewSize
- SIZE_OF_EFI_FILE_INFO
) / sizeof(CHAR16
), DestPath
);
413 Length
= StrLen(NewFileInfo
->FileName
);
417 if (NewFileInfo
->FileName
[Length
] == L
'\\') {
418 if (Node
->FileName
[0] == L
'\\') {
420 // Don't allow for double slashes. Eliminate one of them.
422 NewFileInfo
->FileName
[Length
] = CHAR_NULL
;
424 StrCatS(NewFileInfo
->FileName
, (NewSize
- SIZE_OF_EFI_FILE_INFO
) / sizeof(CHAR16
), Node
->FileName
);
426 NewFileInfo
->Size
= SIZE_OF_EFI_FILE_INFO
+ StrSize(NewFileInfo
->FileName
);
429 // Perform the move operation
431 Status
= ShellSetFileInfo(Node
->Handle
, NewFileInfo
);
434 // Free the info object we used...
436 FreePool(NewFileInfo
);
442 function to take a list of files to move and a destination location and do
443 the verification and moving of those files to that location. This function
444 will report any errors to the user and continue to move the rest of the files.
446 @param[in] FileList A LIST_ENTRY* based list of files to move
447 @param[out] Resp pointer to response from question. Pass back on looped calling
448 @param[in] DestParameter the originally specified destination location
450 @retval SHELL_SUCCESS the files were all moved.
451 @retval SHELL_INVALID_PARAMETER a parameter was invalid
452 @retval SHELL_SECURITY_VIOLATION a security violation ocurred
453 @retval SHELL_WRITE_PROTECTED the destination was write protected
454 @retval SHELL_OUT_OF_RESOURCES a memory allocation failed
458 ValidateAndMoveFiles(
459 IN EFI_SHELL_FILE_INFO
*FileList
,
461 IN CONST CHAR16
*DestParameter
468 CHAR16
*FullDestPath
;
471 SHELL_STATUS ShellStatus
;
472 EFI_SHELL_FILE_INFO
*Node
;
475 CHAR16
*CleanFilePathStr
;
477 ASSERT(FileList
!= NULL
);
478 ASSERT(DestParameter
!= NULL
);
482 Cwd
= ShellGetCurrentDir(NULL
);
485 CleanFilePathStr
= NULL
;
487 FullCwd
= AllocateZeroPool(StrSize(Cwd
) + sizeof(CHAR16
));
488 if (FullCwd
== NULL
) {
489 return SHELL_OUT_OF_RESOURCES
;
491 StrCpyS(FullCwd
, StrSize(Cwd
)/sizeof(CHAR16
)+1, Cwd
);
492 StrCatS(FullCwd
, StrSize(Cwd
)/sizeof(CHAR16
)+1, L
"\\");
495 Status
= ShellLevel2StripQuotes (DestParameter
, &CleanFilePathStr
);
496 if (EFI_ERROR (Status
)) {
498 if (Status
== EFI_OUT_OF_RESOURCES
) {
499 return SHELL_OUT_OF_RESOURCES
;
501 return SHELL_INVALID_PARAMETER
;
505 ASSERT (CleanFilePathStr
!= NULL
);
508 // Get and validate the destination location
510 ShellStatus
= GetDestinationLocation(CleanFilePathStr
, &DestPath
, FullCwd
, (BOOLEAN
)(FileList
->Link
.ForwardLink
== FileList
->Link
.BackLink
), &Attr
);
511 FreePool (CleanFilePathStr
);
513 if (ShellStatus
!= SHELL_SUCCESS
) {
515 return (ShellStatus
);
517 DestPath
= PathCleanUpDirectories(DestPath
);
518 if (DestPath
== NULL
) {
520 return (SHELL_OUT_OF_RESOURCES
);
523 HiiOutput
= HiiGetString (gShellLevel2HiiHandle
, STRING_TOKEN (STR_MV_OUTPUT
), NULL
);
524 HiiResultOk
= HiiGetString (gShellLevel2HiiHandle
, STRING_TOKEN (STR_GEN_RES_OK
), NULL
);
525 if (HiiOutput
== NULL
|| HiiResultOk
== NULL
) {
526 SHELL_FREE_NON_NULL(DestPath
);
527 SHELL_FREE_NON_NULL(HiiOutput
);
528 SHELL_FREE_NON_NULL(HiiResultOk
);
530 return (SHELL_OUT_OF_RESOURCES
);
534 // Go through the list of files and directories to move...
536 for (Node
= (EFI_SHELL_FILE_INFO
*)GetFirstNode(&FileList
->Link
)
537 ; !IsNull(&FileList
->Link
, &Node
->Link
)
538 ; Node
= (EFI_SHELL_FILE_INFO
*)GetNextNode(&FileList
->Link
, &Node
->Link
)
540 if (ShellGetExecutionBreakFlag()) {
545 // These should never be NULL
547 ASSERT(Node
->FileName
!= NULL
);
548 ASSERT(Node
->FullName
!= NULL
);
549 ASSERT(Node
->Info
!= NULL
);
552 // skip the directory traversing stuff...
554 if (StrCmp(Node
->FileName
, L
".") == 0 || StrCmp(Node
->FileName
, L
"..") == 0) {
558 SHELL_FREE_NON_NULL(FullDestPath
);
560 if (ShellIsDirectory(DestPath
)==EFI_SUCCESS
) {
561 CreateFullDestPath((CONST CHAR16
**)&DestPath
, &FullDestPath
, Node
->FileName
);
565 // Validate that the move is valid
567 if (!IsValidMove(Node
->FullName
, FullCwd
, FullDestPath
!=NULL
? FullDestPath
:DestPath
, Node
->Info
->Attribute
, Attr
, Node
->Status
)) {
568 ShellStatus
= SHELL_INVALID_PARAMETER
;
572 ShellPrintEx(-1, -1, HiiOutput
, Node
->FullName
, FullDestPath
!=NULL
? FullDestPath
:DestPath
);
575 // See if destination exists
577 if (!EFI_ERROR(ShellFileExists(FullDestPath
!=NULL
? FullDestPath
:DestPath
))) {
578 if (Response
== NULL
) {
579 ShellPromptForResponseHii(ShellPromptResponseTypeYesNoAllCancel
, STRING_TOKEN (STR_GEN_DEST_EXIST_OVR
), gShellLevel2HiiHandle
, &Response
);
581 switch (*(SHELL_PROMPT_RESPONSE
*)Response
) {
582 case ShellPromptResponseNo
:
586 case ShellPromptResponseCancel
:
589 // indicate to stop everything
592 return (SHELL_ABORTED
);
593 case ShellPromptResponseAll
:
596 case ShellPromptResponseYes
:
603 return SHELL_ABORTED
;
605 Status
= ShellDeleteFileByName(FullDestPath
!=NULL
? FullDestPath
:DestPath
);
608 if (IsBetweenFileSystem(Node
->FullName
, FullCwd
, DestPath
)) {
609 while (FullDestPath
== NULL
&& DestPath
!= NULL
&& DestPath
[0] != CHAR_NULL
&& DestPath
[StrLen(DestPath
) - 1] == L
'\\') {
610 DestPath
[StrLen(DestPath
) - 1] = CHAR_NULL
;
612 Status
= MoveBetweenFileSystems(Node
, FullDestPath
!=NULL
? FullDestPath
:DestPath
, &Response
);
614 Status
= MoveWithinFileSystems(Node
, DestPath
, &Response
);
616 // Display error status
618 if (EFI_ERROR(Status
)) {
619 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, L
"mv", Status
);
626 if (EFI_ERROR(Status
)) {
627 ShellStatus
= SHELL_INVALID_PARAMETER
;
628 if (Status
== EFI_SECURITY_VIOLATION
) {
629 ShellStatus
= SHELL_SECURITY_VIOLATION
;
630 } else if (Status
== EFI_WRITE_PROTECTED
) {
631 ShellStatus
= SHELL_WRITE_PROTECTED
;
632 } else if (Status
== EFI_OUT_OF_RESOURCES
) {
633 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
634 } else if (Status
== EFI_DEVICE_ERROR
) {
635 ShellStatus
= SHELL_DEVICE_ERROR
;
636 } else if (Status
== EFI_ACCESS_DENIED
) {
637 ShellStatus
= SHELL_ACCESS_DENIED
;
640 ShellPrintEx(-1, -1, L
"%s", HiiResultOk
);
645 SHELL_FREE_NON_NULL(FullDestPath
);
646 SHELL_FREE_NON_NULL(DestPath
);
647 SHELL_FREE_NON_NULL(HiiOutput
);
648 SHELL_FREE_NON_NULL(HiiResultOk
);
650 return (ShellStatus
);
654 Function for 'mv' command.
656 @param[in] ImageHandle Handle to the Image (NULL if Internal).
657 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
662 IN EFI_HANDLE ImageHandle
,
663 IN EFI_SYSTEM_TABLE
*SystemTable
668 CHAR16
*ProblemParam
;
671 SHELL_STATUS ShellStatus
;
674 EFI_SHELL_FILE_INFO
*FileList
;
678 ShellStatus
= SHELL_SUCCESS
;
684 // initialize the shell lib (we must be in non-auto-init...)
686 Status
= ShellInitialize();
687 ASSERT_EFI_ERROR(Status
);
690 // parse the command line
692 Status
= ShellCommandLineParse (EmptyParamList
, &Package
, &ProblemParam
, TRUE
);
693 if (EFI_ERROR(Status
)) {
694 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
695 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, L
"mv", ProblemParam
);
696 FreePool(ProblemParam
);
697 ShellStatus
= SHELL_INVALID_PARAMETER
;
705 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
709 switch (ParamCount
= ShellCommandLineGetCount(Package
)) {
713 // we have insufficient parameters
715 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel2HiiHandle
, L
"mv");
716 ShellStatus
= SHELL_INVALID_PARAMETER
;
720 // must have valid CWD for single parameter...
722 if (ShellGetCurrentDir(NULL
) == NULL
){
723 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_CWD
), gShellLevel2HiiHandle
, L
"mv");
724 ShellStatus
= SHELL_INVALID_PARAMETER
;
726 Status
= ShellOpenFileMetaArg((CHAR16
*)ShellCommandLineGetRawValue(Package
, 1), EFI_FILE_MODE_WRITE
|EFI_FILE_MODE_READ
, &FileList
);
727 if (FileList
== NULL
|| IsListEmpty(&FileList
->Link
) || EFI_ERROR(Status
)) {
728 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_FILE_NF
), gShellLevel2HiiHandle
, L
"mv", ShellCommandLineGetRawValue(Package
, 1));
729 ShellStatus
= SHELL_NOT_FOUND
;
732 // ValidateAndMoveFiles will report errors to the screen itself
734 CwdSize
= StrSize(ShellGetCurrentDir(NULL
)) + 1;
735 Cwd
= AllocateZeroPool(CwdSize
);
736 ASSERT (Cwd
!= NULL
);
737 StrCpyS(Cwd
, CwdSize
/sizeof(CHAR16
), ShellGetCurrentDir(NULL
));
738 StrCatS(Cwd
, CwdSize
/sizeof(CHAR16
), L
"\\");
739 ShellStatus
= ValidateAndMoveFiles(FileList
, &Response
, Cwd
);
746 ///@todo make sure this works with error half way through and continues...
747 for (ParamCount
--, LoopCounter
= 1 ; LoopCounter
< ParamCount
; LoopCounter
++) {
748 if (ShellGetExecutionBreakFlag()) {
751 Status
= ShellOpenFileMetaArg((CHAR16
*)ShellCommandLineGetRawValue(Package
, LoopCounter
), EFI_FILE_MODE_WRITE
|EFI_FILE_MODE_READ
, &FileList
);
752 if (FileList
== NULL
|| IsListEmpty(&FileList
->Link
) || EFI_ERROR(Status
)) {
753 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_FILE_NF
), gShellLevel2HiiHandle
, L
"mv", ShellCommandLineGetRawValue(Package
, LoopCounter
));
754 ShellStatus
= SHELL_NOT_FOUND
;
757 // ValidateAndMoveFiles will report errors to the screen itself
758 // Only change ShellStatus if it's sucessful
760 if (ShellStatus
== SHELL_SUCCESS
) {
761 ShellStatus
= ValidateAndMoveFiles(FileList
, &Response
, ShellCommandLineGetRawValue(Package
, ParamCount
));
763 ValidateAndMoveFiles(FileList
, &Response
, ShellCommandLineGetRawValue(Package
, ParamCount
));
766 if (FileList
!= NULL
&& !IsListEmpty(&FileList
->Link
)) {
767 Status
= ShellCloseFileMetaArg(&FileList
);
768 if (EFI_ERROR(Status
) && ShellStatus
== SHELL_SUCCESS
) {
769 ShellStatus
= SHELL_ACCESS_DENIED
;
770 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_FILE
), gShellLevel2HiiHandle
, L
"mv", ShellCommandLineGetRawValue(Package
, 1), ShellStatus
|MAX_BIT
);
775 } // switch on parameter count
777 if (FileList
!= NULL
) {
778 ShellCloseFileMetaArg(&FileList
);
782 // free the command line package
784 ShellCommandLineFreeVarList (Package
);
787 SHELL_FREE_NON_NULL(Response
);
789 if (ShellGetExecutionBreakFlag()) {
790 return (SHELL_ABORTED
);
793 return (ShellStatus
);