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 - 2016, 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
;
489 FullCwd
= AllocateZeroPool(StrSize(Cwd
) + sizeof(CHAR16
));
490 if (FullCwd
== NULL
) {
491 return SHELL_OUT_OF_RESOURCES
;
493 StrCpyS(FullCwd
, StrSize(Cwd
)/sizeof(CHAR16
)+1, Cwd
);
494 StrCatS(FullCwd
, StrSize(Cwd
)/sizeof(CHAR16
)+1, L
"\\");
498 Status
= ShellLevel2StripQuotes (DestParameter
, &CleanFilePathStr
);
499 if (EFI_ERROR (Status
)) {
500 SHELL_FREE_NON_NULL(FullCwd
);
501 if (Status
== EFI_OUT_OF_RESOURCES
) {
502 return SHELL_OUT_OF_RESOURCES
;
504 return SHELL_INVALID_PARAMETER
;
508 ASSERT (CleanFilePathStr
!= NULL
);
511 // Get and validate the destination location
513 ShellStatus
= GetDestinationLocation(CleanFilePathStr
, &DestPath
, FullCwd
, (BOOLEAN
)(FileList
->Link
.ForwardLink
== FileList
->Link
.BackLink
), &Attr
);
514 FreePool (CleanFilePathStr
);
516 if (ShellStatus
!= SHELL_SUCCESS
) {
517 SHELL_FREE_NON_NULL (FullCwd
);
518 return (ShellStatus
);
520 DestPath
= PathCleanUpDirectories(DestPath
);
521 if (DestPath
== NULL
) {
523 return (SHELL_OUT_OF_RESOURCES
);
526 HiiOutput
= HiiGetString (gShellLevel2HiiHandle
, STRING_TOKEN (STR_MV_OUTPUT
), NULL
);
527 HiiResultOk
= HiiGetString (gShellLevel2HiiHandle
, STRING_TOKEN (STR_GEN_RES_OK
), NULL
);
528 if (HiiOutput
== NULL
|| HiiResultOk
== NULL
) {
529 SHELL_FREE_NON_NULL(DestPath
);
530 SHELL_FREE_NON_NULL(HiiOutput
);
531 SHELL_FREE_NON_NULL(HiiResultOk
);
532 SHELL_FREE_NON_NULL(FullCwd
);
533 return (SHELL_OUT_OF_RESOURCES
);
537 // Go through the list of files and directories to move...
539 for (Node
= (EFI_SHELL_FILE_INFO
*)GetFirstNode(&FileList
->Link
)
540 ; !IsNull(&FileList
->Link
, &Node
->Link
)
541 ; Node
= (EFI_SHELL_FILE_INFO
*)GetNextNode(&FileList
->Link
, &Node
->Link
)
543 if (ShellGetExecutionBreakFlag()) {
548 // These should never be NULL
550 ASSERT(Node
->FileName
!= NULL
);
551 ASSERT(Node
->FullName
!= NULL
);
552 ASSERT(Node
->Info
!= NULL
);
555 // skip the directory traversing stuff...
557 if (StrCmp(Node
->FileName
, L
".") == 0 || StrCmp(Node
->FileName
, L
"..") == 0) {
561 SHELL_FREE_NON_NULL(FullDestPath
);
563 if (ShellIsDirectory(DestPath
)==EFI_SUCCESS
) {
564 CreateFullDestPath((CONST CHAR16
**)&DestPath
, &FullDestPath
, Node
->FileName
);
568 // Validate that the move is valid
570 if (!IsValidMove(Node
->FullName
, FullCwd
, FullDestPath
!=NULL
? FullDestPath
:DestPath
, Node
->Info
->Attribute
, Attr
, Node
->Status
)) {
571 ShellStatus
= SHELL_INVALID_PARAMETER
;
575 ShellPrintEx(-1, -1, HiiOutput
, Node
->FullName
, FullDestPath
!=NULL
? FullDestPath
:DestPath
);
578 // See if destination exists
580 if (!EFI_ERROR(ShellFileExists(FullDestPath
!=NULL
? FullDestPath
:DestPath
))) {
581 if (Response
== NULL
) {
582 ShellPromptForResponseHii(ShellPromptResponseTypeYesNoAllCancel
, STRING_TOKEN (STR_GEN_DEST_EXIST_OVR
), gShellLevel2HiiHandle
, &Response
);
584 switch (*(SHELL_PROMPT_RESPONSE
*)Response
) {
585 case ShellPromptResponseNo
:
589 case ShellPromptResponseCancel
:
592 // indicate to stop everything
594 SHELL_FREE_NON_NULL(FullCwd
);
595 return (SHELL_ABORTED
);
596 case ShellPromptResponseAll
:
599 case ShellPromptResponseYes
:
605 SHELL_FREE_NON_NULL(FullCwd
);
606 return SHELL_ABORTED
;
608 Status
= ShellDeleteFileByName(FullDestPath
!=NULL
? FullDestPath
:DestPath
);
611 if (IsBetweenFileSystem(Node
->FullName
, FullCwd
, DestPath
)) {
612 while (FullDestPath
== NULL
&& DestPath
!= NULL
&& DestPath
[0] != CHAR_NULL
&& DestPath
[StrLen(DestPath
) - 1] == L
'\\') {
613 DestPath
[StrLen(DestPath
) - 1] = CHAR_NULL
;
615 Status
= MoveBetweenFileSystems(Node
, FullDestPath
!=NULL
? FullDestPath
:DestPath
, &Response
);
617 Status
= MoveWithinFileSystems(Node
, DestPath
, &Response
);
619 // Display error status
621 if (EFI_ERROR(Status
)) {
622 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel2HiiHandle
, L
"mv", Status
);
629 if (EFI_ERROR(Status
)) {
630 ShellStatus
= SHELL_INVALID_PARAMETER
;
631 if (Status
== EFI_SECURITY_VIOLATION
) {
632 ShellStatus
= SHELL_SECURITY_VIOLATION
;
633 } else if (Status
== EFI_WRITE_PROTECTED
) {
634 ShellStatus
= SHELL_WRITE_PROTECTED
;
635 } else if (Status
== EFI_OUT_OF_RESOURCES
) {
636 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
637 } else if (Status
== EFI_DEVICE_ERROR
) {
638 ShellStatus
= SHELL_DEVICE_ERROR
;
639 } else if (Status
== EFI_ACCESS_DENIED
) {
640 ShellStatus
= SHELL_ACCESS_DENIED
;
643 ShellPrintEx(-1, -1, L
"%s", HiiResultOk
);
648 SHELL_FREE_NON_NULL(FullDestPath
);
649 SHELL_FREE_NON_NULL(DestPath
);
650 SHELL_FREE_NON_NULL(HiiOutput
);
651 SHELL_FREE_NON_NULL(HiiResultOk
);
652 SHELL_FREE_NON_NULL(FullCwd
);
653 return (ShellStatus
);
657 Function for 'mv' command.
659 @param[in] ImageHandle Handle to the Image (NULL if Internal).
660 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
665 IN EFI_HANDLE ImageHandle
,
666 IN EFI_SYSTEM_TABLE
*SystemTable
671 CHAR16
*ProblemParam
;
674 SHELL_STATUS ShellStatus
;
677 EFI_SHELL_FILE_INFO
*FileList
;
681 ShellStatus
= SHELL_SUCCESS
;
687 // initialize the shell lib (we must be in non-auto-init...)
689 Status
= ShellInitialize();
690 ASSERT_EFI_ERROR(Status
);
693 // parse the command line
695 Status
= ShellCommandLineParse (EmptyParamList
, &Package
, &ProblemParam
, TRUE
);
696 if (EFI_ERROR(Status
)) {
697 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
698 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, L
"mv", ProblemParam
);
699 FreePool(ProblemParam
);
700 ShellStatus
= SHELL_INVALID_PARAMETER
;
708 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
712 switch (ParamCount
= ShellCommandLineGetCount(Package
)) {
716 // we have insufficient parameters
718 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel2HiiHandle
, L
"mv");
719 ShellStatus
= SHELL_INVALID_PARAMETER
;
723 // must have valid CWD for single parameter...
725 if (ShellGetCurrentDir(NULL
) == NULL
){
726 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_CWD
), gShellLevel2HiiHandle
, L
"mv");
727 ShellStatus
= SHELL_INVALID_PARAMETER
;
729 Status
= ShellOpenFileMetaArg((CHAR16
*)ShellCommandLineGetRawValue(Package
, 1), EFI_FILE_MODE_WRITE
|EFI_FILE_MODE_READ
, &FileList
);
730 if (FileList
== NULL
|| IsListEmpty(&FileList
->Link
) || EFI_ERROR(Status
)) {
731 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_FILE_NF
), gShellLevel2HiiHandle
, L
"mv", ShellCommandLineGetRawValue(Package
, 1));
732 ShellStatus
= SHELL_NOT_FOUND
;
735 // ValidateAndMoveFiles will report errors to the screen itself
737 CwdSize
= StrSize(ShellGetCurrentDir(NULL
)) + sizeof(CHAR16
);
738 Cwd
= AllocateZeroPool(CwdSize
);
739 ASSERT (Cwd
!= NULL
);
740 StrCpyS(Cwd
, CwdSize
/sizeof(CHAR16
), ShellGetCurrentDir(NULL
));
741 StrCatS(Cwd
, CwdSize
/sizeof(CHAR16
), L
"\\");
742 ShellStatus
= ValidateAndMoveFiles(FileList
, &Response
, Cwd
);
749 ///@todo make sure this works with error half way through and continues...
750 for (ParamCount
--, LoopCounter
= 1 ; LoopCounter
< ParamCount
; LoopCounter
++) {
751 if (ShellGetExecutionBreakFlag()) {
754 Status
= ShellOpenFileMetaArg((CHAR16
*)ShellCommandLineGetRawValue(Package
, LoopCounter
), EFI_FILE_MODE_WRITE
|EFI_FILE_MODE_READ
, &FileList
);
755 if (FileList
== NULL
|| IsListEmpty(&FileList
->Link
) || EFI_ERROR(Status
)) {
756 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_FILE_NF
), gShellLevel2HiiHandle
, L
"mv", ShellCommandLineGetRawValue(Package
, LoopCounter
));
757 ShellStatus
= SHELL_NOT_FOUND
;
760 // ValidateAndMoveFiles will report errors to the screen itself
761 // Only change ShellStatus if it's sucessful
763 if (ShellStatus
== SHELL_SUCCESS
) {
764 ShellStatus
= ValidateAndMoveFiles(FileList
, &Response
, ShellCommandLineGetRawValue(Package
, ParamCount
));
766 ValidateAndMoveFiles(FileList
, &Response
, ShellCommandLineGetRawValue(Package
, ParamCount
));
769 if (FileList
!= NULL
&& !IsListEmpty(&FileList
->Link
)) {
770 Status
= ShellCloseFileMetaArg(&FileList
);
771 if (EFI_ERROR(Status
) && ShellStatus
== SHELL_SUCCESS
) {
772 ShellStatus
= SHELL_ACCESS_DENIED
;
773 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_FILE
), gShellLevel2HiiHandle
, L
"mv", ShellCommandLineGetRawValue(Package
, 1), ShellStatus
|MAX_BIT
);
778 } // switch on parameter count
780 if (FileList
!= NULL
) {
781 ShellCloseFileMetaArg(&FileList
);
785 // free the command line package
787 ShellCommandLineFreeVarList (Package
);
790 SHELL_FREE_NON_NULL(Response
);
792 if (ShellGetExecutionBreakFlag()) {
793 return (SHELL_ABORTED
);
796 return (ShellStatus
);