TianoCore EDK2 master
Loading...
Searching...
No Matches
Mv.c
Go to the documentation of this file.
1
11
22BOOLEAN
24 IN CONST CHAR16 *FullName,
25 IN CONST CHAR16 *Cwd,
26 IN CONST CHAR16 *DestPath
27 )
28{
29 CHAR16 *Test;
30 CHAR16 *Test1;
31 UINTN Result;
32
33 Test = StrStr (FullName, L":");
34 if ((Test == NULL) && (Cwd != NULL)) {
35 Test = StrStr (Cwd, L":");
36 }
37
38 Test1 = StrStr (DestPath, L":");
39 if ((Test1 == NULL) && (Cwd != NULL)) {
40 Test1 = StrStr (Cwd, L":");
41 }
42
43 if ((Test1 != NULL) && (Test != NULL)) {
44 *Test = CHAR_NULL;
45 *Test1 = CHAR_NULL;
46 Result = StringNoCaseCompare (&FullName, &DestPath);
47 *Test = L':';
48 *Test1 = L':';
49 if (Result != 0) {
50 return (TRUE);
51 }
52 }
53
54 return (FALSE);
55}
56
72BOOLEAN
74 IN CONST CHAR16 *SrcPath,
75 IN CONST CHAR16 *CwdPath
76 )
77{
78 CHAR16 *SrcPathBuffer;
79 CHAR16 *CwdPathBuffer;
80 BOOLEAN Ret;
81
82 ASSERT (CwdPath != NULL);
83 if (SrcPath == NULL) {
84 return FALSE;
85 }
86
87 Ret = TRUE;
88
89 SrcPathBuffer = AllocateCopyPool (StrSize (SrcPath), SrcPath);
90 if (SrcPathBuffer == NULL) {
91 return FALSE;
92 }
93
94 CwdPathBuffer = AllocateCopyPool (StrSize (CwdPath), CwdPath);
95 if (CwdPathBuffer == NULL) {
96 FreePool (SrcPathBuffer);
97 return FALSE;
98 }
99
100 gUnicodeCollation->StrUpr (gUnicodeCollation, SrcPathBuffer);
101 gUnicodeCollation->StrUpr (gUnicodeCollation, CwdPathBuffer);
102
103 if (SrcPathBuffer[StrLen (SrcPathBuffer) -1] == L'\\') {
104 SrcPathBuffer[StrLen (SrcPathBuffer) - 1] = CHAR_NULL;
105 }
106
107 if (CwdPathBuffer[StrLen (CwdPathBuffer) - 1] == L'\\') {
108 CwdPathBuffer[StrLen (CwdPathBuffer) - 1] = CHAR_NULL;
109 }
110
111 if ((StrCmp (CwdPathBuffer, SrcPathBuffer) == 0) ||
112 ((StrStr (CwdPathBuffer, SrcPathBuffer) == CwdPathBuffer) &&
113 (CwdPathBuffer[StrLen (SrcPathBuffer)] == L'\\'))
114 )
115 {
116 Ret = FALSE;
117 }
118
119 FreePool (SrcPathBuffer);
120 FreePool (CwdPathBuffer);
121
122 return Ret;
123}
124
145BOOLEAN
147 IN CONST CHAR16 *SourcePath,
148 IN CONST CHAR16 *Cwd,
149 IN CONST CHAR16 *DestPath,
150 IN CONST UINT64 Attribute,
151 IN CONST UINT64 DestAttr,
152 IN CONST EFI_STATUS FileStatus
153 )
154{
155 CHAR16 *DestPathCopy;
156 CHAR16 *DestPathWalker;
157
158 if ((Cwd != NULL) && ((Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY)) {
159 if (!IsSoucePathValid (SourcePath, Cwd)) {
160 //
161 // Invalid move
162 //
163 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MV_INV_CWD), gShellLevel2HiiHandle);
164 return FALSE;
165 }
166 }
167
168 //
169 // invalid to move read only or move to a read only destination
170 //
171 if ( ((Attribute & EFI_FILE_READ_ONLY) != 0)
172 || (FileStatus == EFI_WRITE_PROTECTED)
173 || ((DestAttr & EFI_FILE_READ_ONLY) != 0)
174 )
175 {
176 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MV_INV_RO), gShellLevel2HiiHandle, SourcePath);
177 return (FALSE);
178 }
179
180 DestPathCopy = AllocateCopyPool (StrSize (DestPath), DestPath);
181 if (DestPathCopy == NULL) {
182 return (FALSE);
183 }
184
185 for (DestPathWalker = DestPathCopy; *DestPathWalker == L'\\'; DestPathWalker++) {
186 }
187
188 while (DestPathWalker != NULL && DestPathWalker[StrLen (DestPathWalker)-1] == L'\\') {
189 DestPathWalker[StrLen (DestPathWalker)-1] = CHAR_NULL;
190 }
191
192 ASSERT (DestPathWalker != NULL);
193 ASSERT (SourcePath != NULL);
194
195 //
196 // If they're the same, or if source is "above" dest on file path tree
197 //
198 if ((StringNoCaseCompare (&DestPathWalker, &SourcePath) == 0) ||
199 ((StrStr (DestPathWalker, SourcePath) == DestPathWalker) &&
200 (DestPathWalker[StrLen (SourcePath)] == '\\')
201 )
202 )
203 {
204 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MV_INV_SUB), gShellLevel2HiiHandle);
205 FreePool (DestPathCopy);
206 return (FALSE);
207 }
208
209 FreePool (DestPathCopy);
210
211 return (TRUE);
212}
213
234 IN CONST CHAR16 *DestParameter,
235 IN OUT CHAR16 **DestPathPointer,
236 IN CONST CHAR16 *Cwd,
237 IN CONST BOOLEAN SingleSource,
238 IN OUT UINT64 *DestAttr
239 )
240{
241 EFI_SHELL_FILE_INFO *DestList;
243 CHAR16 *DestPath;
244 UINTN NewSize;
245 UINTN CurrentSize;
246
247 DestList = NULL;
248 DestPath = NULL;
249
250 ASSERT (DestAttr != NULL);
251
252 if (StrStr (DestParameter, L"\\") == DestParameter) {
253 if (Cwd == NULL) {
255 }
256
257 DestPath = AllocateZeroPool (StrSize (Cwd));
258 if (DestPath == NULL) {
259 return (SHELL_OUT_OF_RESOURCES);
260 }
261
262 StrCpyS (DestPath, StrSize (Cwd) / sizeof (CHAR16), Cwd);
263 while (PathRemoveLastItem (DestPath)) {
264 }
265
266 //
267 // Append DestParameter beyond '\' which may be present
268 //
269 CurrentSize = StrSize (DestPath);
270 StrnCatGrow (&DestPath, &CurrentSize, &DestParameter[1], 0);
271
272 *DestPathPointer = DestPath;
273 return (SHELL_SUCCESS);
274 }
275
276 //
277 // get the destination path
278 //
279 ShellOpenFileMetaArg ((CHAR16 *)DestParameter, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ|EFI_FILE_MODE_CREATE, &DestList);
280 if ((DestList == NULL) || IsListEmpty (&DestList->Link)) {
281 //
282 // Not existing... must be renaming
283 //
284 if (StrStr (DestParameter, L":") == NULL) {
285 if (Cwd == NULL) {
286 ShellCloseFileMetaArg (&DestList);
287 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);
289 }
290
291 NewSize = StrSize (Cwd);
292 NewSize += StrSize (DestParameter);
293 DestPath = AllocateZeroPool (NewSize);
294 if (DestPath == NULL) {
295 ShellCloseFileMetaArg (&DestList);
296 return (SHELL_OUT_OF_RESOURCES);
297 }
298
299 StrCpyS (DestPath, NewSize / sizeof (CHAR16), Cwd);
300 if ((DestPath[StrLen (DestPath)-1] != L'\\') && (DestParameter[0] != L'\\')) {
301 StrCatS (DestPath, NewSize / sizeof (CHAR16), L"\\");
302 } else if ((DestPath[StrLen (DestPath)-1] == L'\\') && (DestParameter[0] == L'\\')) {
303 ((CHAR16 *)DestPath)[StrLen (DestPath)-1] = CHAR_NULL;
304 }
305
306 StrCatS (DestPath, NewSize / sizeof (CHAR16), DestParameter);
307 } else {
308 ASSERT (DestPath == NULL);
309 DestPath = StrnCatGrow (&DestPath, NULL, DestParameter, 0);
310 if (DestPath == NULL) {
311 ShellCloseFileMetaArg (&DestList);
312 return (SHELL_OUT_OF_RESOURCES);
313 }
314 }
315 } else {
316 Node = (EFI_SHELL_FILE_INFO *)GetFirstNode (&DestList->Link);
317 *DestAttr = Node->Info->Attribute;
318 //
319 // Make sure there is only 1 node in the list.
320 //
321 if (!IsNodeAtEnd (&DestList->Link, &Node->Link)) {
322 ShellCloseFileMetaArg (&DestList);
323 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_MARG_ERROR), gShellLevel2HiiHandle, L"mv", DestParameter);
325 }
326
327 //
328 // If we are a directory or a single file, then one node is fine.
329 //
330 if ((ShellIsDirectory (Node->FullName) == EFI_SUCCESS) || SingleSource) {
331 DestPath = AllocateZeroPool (StrSize (Node->FullName)+sizeof (CHAR16));
332 if (DestPath == NULL) {
333 ShellCloseFileMetaArg (&DestList);
334 return (SHELL_OUT_OF_RESOURCES);
335 }
336
337 StrCpyS (DestPath, (StrSize (Node->FullName)+sizeof (CHAR16)) / sizeof (CHAR16), Node->FullName);
338 StrCatS (DestPath, (StrSize (Node->FullName)+sizeof (CHAR16)) / sizeof (CHAR16), L"\\");
339 } else {
340 //
341 // cant move multiple files onto a single file.
342 //
343 ShellCloseFileMetaArg (&DestList);
344 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_ERROR), gShellLevel2HiiHandle, L"mv", DestParameter);
346 }
347 }
348
349 *DestPathPointer = DestPath;
350 ShellCloseFileMetaArg (&DestList);
351
352 return (SHELL_SUCCESS);
353}
354
367 IN CONST CHAR16 *DestPath,
368 OUT VOID **Resp
369 )
370{
371 SHELL_STATUS ShellStatus;
372
373 //
374 // First we copy the file
375 //
376 ShellStatus = CopySingleFile (Node->FullName, DestPath, Resp, TRUE, L"mv");
377
378 //
379 // Check our result
380 //
381 if (ShellStatus == SHELL_SUCCESS) {
382 //
383 // The copy was successful. delete the source file.
384 //
385 CascadeDelete (Node, TRUE);
386 Node->Handle = NULL;
387 } else if (ShellStatus == SHELL_ABORTED) {
388 return EFI_ABORTED;
389 } else if (ShellStatus == SHELL_ACCESS_DENIED) {
390 return EFI_ACCESS_DENIED;
391 } else if (ShellStatus == SHELL_VOLUME_FULL) {
392 return EFI_VOLUME_FULL;
393 } else {
394 return EFI_UNSUPPORTED;
395 }
396
397 return (EFI_SUCCESS);
398}
399
413 IN CONST CHAR16 **DestPath,
414 OUT CHAR16 **FullDestPath,
415 IN CONST CHAR16 *FileName
416 )
417{
418 UINTN Size;
419
420 if ((FullDestPath == NULL) || (FileName == NULL) || (DestPath == NULL) || (*DestPath == NULL)) {
421 return (EFI_INVALID_PARAMETER);
422 }
423
424 Size = StrSize (*DestPath) + StrSize (FileName);
425
426 *FullDestPath = AllocateZeroPool (Size);
427 if (*FullDestPath == NULL) {
428 return (EFI_OUT_OF_RESOURCES);
429 }
430
431 StrCpyS (*FullDestPath, Size / sizeof (CHAR16), *DestPath);
432 if (((*FullDestPath)[StrLen (*FullDestPath)-1] != L'\\') && (FileName[0] != L'\\')) {
433 StrCatS (*FullDestPath, Size / sizeof (CHAR16), L"\\");
434 }
435
436 StrCatS (*FullDestPath, Size / sizeof (CHAR16), FileName);
437
438 return (EFI_SUCCESS);
439}
440
454 IN CHAR16 *DestPath,
455 OUT VOID **Resp
456 )
457{
458 EFI_FILE_INFO *NewFileInfo;
459 CHAR16 *TempLocation;
460 UINTN NewSize;
461 UINTN Length;
462 EFI_STATUS Status;
463
464 //
465 // Chop off map info from DestPath
466 //
467 if ((TempLocation = StrStr (DestPath, L":")) != NULL) {
468 CopyMem (DestPath, TempLocation+1, StrSize (TempLocation+1));
469 }
470
471 //
472 // construct the new file info block
473 //
474 NewSize = StrSize (DestPath);
475 NewSize += StrSize (Node->FileName) + SIZE_OF_EFI_FILE_INFO + sizeof (CHAR16);
476 NewFileInfo = AllocateZeroPool (NewSize);
477 if (NewFileInfo == NULL) {
478 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellLevel2HiiHandle);
479 Status = EFI_OUT_OF_RESOURCES;
480 } else {
481 CopyMem (NewFileInfo, Node->Info, SIZE_OF_EFI_FILE_INFO);
482 if (DestPath[0] != L'\\') {
483 StrCpyS (NewFileInfo->FileName, (NewSize - SIZE_OF_EFI_FILE_INFO) / sizeof (CHAR16), L"\\");
484 StrCatS (NewFileInfo->FileName, (NewSize - SIZE_OF_EFI_FILE_INFO) / sizeof (CHAR16), DestPath);
485 } else {
486 StrCpyS (NewFileInfo->FileName, (NewSize - SIZE_OF_EFI_FILE_INFO) / sizeof (CHAR16), DestPath);
487 }
488
489 Length = StrLen (NewFileInfo->FileName);
490 if (Length > 0) {
491 Length--;
492 }
493
494 if (NewFileInfo->FileName[Length] == L'\\') {
495 if (Node->FileName[0] == L'\\') {
496 //
497 // Don't allow for double slashes. Eliminate one of them.
498 //
499 NewFileInfo->FileName[Length] = CHAR_NULL;
500 }
501
502 StrCatS (NewFileInfo->FileName, (NewSize - SIZE_OF_EFI_FILE_INFO) / sizeof (CHAR16), Node->FileName);
503 }
504
505 NewFileInfo->Size = SIZE_OF_EFI_FILE_INFO + StrSize (NewFileInfo->FileName);
506
507 //
508 // Perform the move operation
509 //
510 Status = ShellSetFileInfo (Node->Handle, NewFileInfo);
511
512 //
513 // Free the info object we used...
514 //
515 FreePool (NewFileInfo);
516 }
517
518 return (Status);
519}
520
538 IN EFI_SHELL_FILE_INFO *FileList,
539 OUT VOID **Resp,
540 IN CONST CHAR16 *DestParameter
541 )
542{
543 EFI_STATUS Status;
544 CHAR16 *HiiOutput;
545 CHAR16 *HiiResultOk;
546 CHAR16 *DestPath;
547 CHAR16 *FullDestPath;
548 CONST CHAR16 *Cwd;
549 CHAR16 *FullCwd;
550 SHELL_STATUS ShellStatus;
552 VOID *Response;
553 UINT64 Attr;
554 CHAR16 *CleanFilePathStr;
555
556 ASSERT (FileList != NULL);
557 ASSERT (DestParameter != NULL);
558
559 DestPath = NULL;
560 FullDestPath = NULL;
561 Cwd = ShellGetCurrentDir (NULL);
562 Response = *Resp;
563 Attr = 0;
564 CleanFilePathStr = NULL;
565 FullCwd = NULL;
566
567 if (Cwd != NULL) {
568 FullCwd = AllocateZeroPool (StrSize (Cwd) + sizeof (CHAR16));
569 if (FullCwd == NULL) {
571 } else {
572 StrCpyS (FullCwd, StrSize (Cwd)/sizeof (CHAR16)+1, Cwd);
573 StrCatS (FullCwd, StrSize (Cwd)/sizeof (CHAR16)+1, L"\\");
574 }
575 }
576
577 Status = ShellLevel2StripQuotes (DestParameter, &CleanFilePathStr);
578 if (EFI_ERROR (Status)) {
579 SHELL_FREE_NON_NULL (FullCwd);
580 if (Status == EFI_OUT_OF_RESOURCES) {
582 } else {
584 }
585 }
586
587 ASSERT (CleanFilePathStr != NULL);
588
589 //
590 // Get and validate the destination location
591 //
592 ShellStatus = GetDestinationLocation (CleanFilePathStr, &DestPath, FullCwd, (BOOLEAN)(FileList->Link.ForwardLink == FileList->Link.BackLink), &Attr);
593 FreePool (CleanFilePathStr);
594
595 if (ShellStatus != SHELL_SUCCESS) {
596 SHELL_FREE_NON_NULL (FullCwd);
597 return (ShellStatus);
598 }
599
600 DestPath = PathCleanUpDirectories (DestPath);
601 if (DestPath == NULL) {
602 FreePool (FullCwd);
603 return (SHELL_OUT_OF_RESOURCES);
604 }
605
606 HiiOutput = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_MV_OUTPUT), NULL);
607 HiiResultOk = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_GEN_RES_OK), NULL);
608 if ((HiiOutput == NULL) || (HiiResultOk == NULL)) {
609 SHELL_FREE_NON_NULL (DestPath);
610 SHELL_FREE_NON_NULL (HiiOutput);
611 SHELL_FREE_NON_NULL (HiiResultOk);
612 SHELL_FREE_NON_NULL (FullCwd);
613 return (SHELL_OUT_OF_RESOURCES);
614 }
615
616 //
617 // Go through the list of files and directories to move...
618 //
619 for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode (&FileList->Link)
620 ; !IsNull (&FileList->Link, &Node->Link)
621 ; Node = (EFI_SHELL_FILE_INFO *)GetNextNode (&FileList->Link, &Node->Link)
622 )
623 {
625 break;
626 }
627
628 //
629 // These should never be NULL
630 //
631 ASSERT (Node->FileName != NULL);
632 ASSERT (Node->FullName != NULL);
633 ASSERT (Node->Info != NULL);
634
635 //
636 // skip the directory traversing stuff...
637 //
638 if ((StrCmp (Node->FileName, L".") == 0) || (StrCmp (Node->FileName, L"..") == 0)) {
639 continue;
640 }
641
642 SHELL_FREE_NON_NULL (FullDestPath);
643 FullDestPath = NULL;
644 if (ShellIsDirectory (DestPath) == EFI_SUCCESS) {
645 CreateFullDestPath ((CONST CHAR16 **)&DestPath, &FullDestPath, Node->FileName);
646 }
647
648 //
649 // Validate that the move is valid
650 //
651 if (!IsValidMove (Node->FullName, FullCwd, (FullDestPath != NULL) ? FullDestPath : DestPath, Node->Info->Attribute, Attr, Node->Status)) {
652 ShellStatus = SHELL_INVALID_PARAMETER;
653 continue;
654 }
655
656 ShellPrintEx (-1, -1, HiiOutput, Node->FullName, FullDestPath != NULL ? FullDestPath : DestPath);
657
658 //
659 // See if destination exists
660 //
661 if (!EFI_ERROR (ShellFileExists ((FullDestPath != NULL) ? FullDestPath : DestPath))) {
662 if (Response == NULL) {
663 ShellPromptForResponseHii (ShellPromptResponseTypeYesNoAllCancel, STRING_TOKEN (STR_GEN_DEST_EXIST_OVR), gShellLevel2HiiHandle, &Response);
664 }
665
666 if (Response == NULL) {
667 return SHELL_ABORTED;
668 }
669
670 switch (*(SHELL_PROMPT_RESPONSE *)Response) {
671 case ShellPromptResponseNo:
672 FreePool (Response);
673 Response = NULL;
674 continue;
675 case ShellPromptResponseCancel:
676 *Resp = Response;
677 //
678 // indicate to stop everything
679 //
680 SHELL_FREE_NON_NULL (FullCwd);
681 return (SHELL_ABORTED);
682 case ShellPromptResponseAll:
683 *Resp = Response;
684 break;
685 case ShellPromptResponseYes:
686 FreePool (Response);
687 Response = NULL;
688 break;
689 default:
690 FreePool (Response);
691 SHELL_FREE_NON_NULL (FullCwd);
692 return SHELL_ABORTED;
693 }
694
695 Status = ShellDeleteFileByName (FullDestPath != NULL ? FullDestPath : DestPath);
696 }
697
698 if (IsBetweenFileSystem (Node->FullName, FullCwd, DestPath)) {
699 while (FullDestPath == NULL && DestPath != NULL && DestPath[0] != CHAR_NULL && DestPath[StrLen (DestPath) - 1] == L'\\') {
700 DestPath[StrLen (DestPath) - 1] = CHAR_NULL;
701 }
702
703 Status = MoveBetweenFileSystems (Node, FullDestPath != NULL ? FullDestPath : DestPath, &Response);
704 } else {
705 Status = MoveWithinFileSystems (Node, DestPath, &Response);
706 //
707 // Display error status
708 //
709 if (EFI_ERROR (Status)) {
710 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, L"mv", Status);
711 }
712 }
713
714 //
715 // Check our result
716 //
717 if (EFI_ERROR (Status)) {
718 ShellStatus = SHELL_INVALID_PARAMETER;
719 if (Status == EFI_SECURITY_VIOLATION) {
720 ShellStatus = SHELL_SECURITY_VIOLATION;
721 } else if (Status == EFI_WRITE_PROTECTED) {
722 ShellStatus = SHELL_WRITE_PROTECTED;
723 } else if (Status == EFI_OUT_OF_RESOURCES) {
724 ShellStatus = SHELL_OUT_OF_RESOURCES;
725 } else if (Status == EFI_DEVICE_ERROR) {
726 ShellStatus = SHELL_DEVICE_ERROR;
727 } else if (Status == EFI_ACCESS_DENIED) {
728 ShellStatus = SHELL_ACCESS_DENIED;
729 }
730 } else {
731 ShellPrintEx (-1, -1, L"%s", HiiResultOk);
732 }
733 } // main for loop
734
735 SHELL_FREE_NON_NULL (FullDestPath);
736 SHELL_FREE_NON_NULL (DestPath);
737 SHELL_FREE_NON_NULL (HiiOutput);
738 SHELL_FREE_NON_NULL (HiiResultOk);
739 SHELL_FREE_NON_NULL (FullCwd);
740 return (ShellStatus);
741}
742
750EFIAPI
752 IN EFI_HANDLE ImageHandle,
753 IN EFI_SYSTEM_TABLE *SystemTable
754 )
755{
756 EFI_STATUS Status;
757 LIST_ENTRY *Package;
758 CHAR16 *ProblemParam;
759 CHAR16 *Cwd;
760 UINTN CwdSize;
761 SHELL_STATUS ShellStatus;
762 UINTN ParamCount;
763 UINTN LoopCounter;
764 EFI_SHELL_FILE_INFO *FileList;
765 VOID *Response;
766
767 ProblemParam = NULL;
768 ShellStatus = SHELL_SUCCESS;
769 ParamCount = 0;
770 FileList = NULL;
771 Response = NULL;
772
773 //
774 // initialize the shell lib (we must be in non-auto-init...)
775 //
776 Status = ShellInitialize ();
777 ASSERT_EFI_ERROR (Status);
778
779 //
780 // parse the command line
781 //
782 Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
783 if (EFI_ERROR (Status)) {
784 if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
785 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"mv", ProblemParam);
786 FreePool (ProblemParam);
787 ShellStatus = SHELL_INVALID_PARAMETER;
788 } else {
789 ASSERT (FALSE);
790 }
791 } else {
792 //
793 // check for "-?"
794 //
795 if (ShellCommandLineGetFlag (Package, L"-?")) {
796 ASSERT (FALSE);
797 }
798
799 switch (ParamCount = ShellCommandLineGetCount (Package)) {
800 case 0:
801 case 1:
802 //
803 // we have insufficient parameters
804 //
805 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle, L"mv");
806 ShellStatus = SHELL_INVALID_PARAMETER;
807 break;
808 case 2:
809 //
810 // must have valid CWD for single parameter...
811 //
812 if (ShellGetCurrentDir (NULL) == NULL) {
813 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle, L"mv");
814 ShellStatus = SHELL_INVALID_PARAMETER;
815 } else {
816 Status = ShellOpenFileMetaArg ((CHAR16 *)ShellCommandLineGetRawValue (Package, 1), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
817 if ((FileList == NULL) || IsListEmpty (&FileList->Link) || EFI_ERROR (Status)) {
818 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, L"mv", ShellCommandLineGetRawValue (Package, 1));
819 ShellStatus = SHELL_NOT_FOUND;
820 } else {
821 //
822 // ValidateAndMoveFiles will report errors to the screen itself
823 //
824 CwdSize = StrSize (ShellGetCurrentDir (NULL)) + sizeof (CHAR16);
825 Cwd = AllocateZeroPool (CwdSize);
826 if (Cwd == NULL) {
827 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellLevel2HiiHandle, L"mv");
828 ShellStatus = SHELL_OUT_OF_RESOURCES;
829 } else {
830 StrCpyS (Cwd, CwdSize / sizeof (CHAR16), ShellGetCurrentDir (NULL));
831 StrCatS (Cwd, CwdSize / sizeof (CHAR16), L"\\");
832 ShellStatus = ValidateAndMoveFiles (FileList, &Response, Cwd);
833 FreePool (Cwd);
834 }
835 }
836 }
837
838 break;
839 default:
841 for (ParamCount--, LoopCounter = 1; LoopCounter < ParamCount; LoopCounter++) {
843 break;
844 }
845
846 Status = ShellOpenFileMetaArg ((CHAR16 *)ShellCommandLineGetRawValue (Package, LoopCounter), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
847 if ((FileList == NULL) || IsListEmpty (&FileList->Link) || EFI_ERROR (Status)) {
848 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, L"mv", ShellCommandLineGetRawValue (Package, LoopCounter));
849 ShellStatus = SHELL_NOT_FOUND;
850 } else {
851 //
852 // ValidateAndMoveFiles will report errors to the screen itself
853 // Only change ShellStatus if it's successful
854 //
855 if (ShellStatus == SHELL_SUCCESS) {
856 ShellStatus = ValidateAndMoveFiles (FileList, &Response, ShellCommandLineGetRawValue (Package, ParamCount));
857 } else {
858 ValidateAndMoveFiles (FileList, &Response, ShellCommandLineGetRawValue (Package, ParamCount));
859 }
860 }
861
862 if ((FileList != NULL) && !IsListEmpty (&FileList->Link)) {
863 Status = ShellCloseFileMetaArg (&FileList);
864 if (EFI_ERROR (Status) && (ShellStatus == SHELL_SUCCESS)) {
865 ShellStatus = SHELL_ACCESS_DENIED;
866 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_FILE), gShellLevel2HiiHandle, L"mv", ShellCommandLineGetRawValue (Package, 1), ShellStatus|MAX_BIT);
867 }
868 }
869 }
870
871 break;
872 } // switch on parameter count
873
874 if (FileList != NULL) {
875 ShellCloseFileMetaArg (&FileList);
876 }
877
878 //
879 // free the command line package
880 //
882 }
883
884 SHELL_FREE_NON_NULL (Response);
885
887 return (SHELL_ABORTED);
888 }
889
890 return (ShellStatus);
891}
#define MAX_BIT
UINT64 UINTN
BOOLEAN EFIAPI IsNull(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
Definition: LinkedList.c:443
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
Definition: String.c:72
BOOLEAN EFIAPI IsListEmpty(IN CONST LIST_ENTRY *ListHead)
Definition: LinkedList.c:403
RETURN_STATUS EFIAPI StrCpyS(OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source)
Definition: SafeString.c:226
LIST_ENTRY *EFIAPI GetNextNode(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
Definition: LinkedList.c:333
INTN EFIAPI StrCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
Definition: String.c:109
BOOLEAN EFIAPI IsNodeAtEnd(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
Definition: LinkedList.c:481
LIST_ENTRY *EFIAPI GetFirstNode(IN CONST LIST_ENTRY *List)
Definition: LinkedList.c:298
RETURN_STATUS EFIAPI StrCatS(IN OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source)
Definition: SafeString.c:405
CHAR16 *EFIAPI PathCleanUpDirectories(IN CHAR16 *Path)
Definition: FilePaths.c:68
BOOLEAN EFIAPI PathRemoveLastItem(IN OUT CHAR16 *Path)
Definition: FilePaths.c:22
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
Definition: String.c:30
CHAR16 *EFIAPI StrStr(IN CONST CHAR16 *String, IN CONST CHAR16 *SearchString)
Definition: String.c:224
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
SHELL_STATUS CopySingleFile(IN CONST CHAR16 *Source, IN CONST CHAR16 *Dest, OUT VOID **Resp, IN BOOLEAN SilentMode, IN CONST CHAR16 *CmdName)
Definition: Cp.c:54
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
#define SIZE_OF_EFI_FILE_INFO
Definition: FileInfo.h:62
EFI_STRING EFIAPI HiiGetString(IN EFI_HII_HANDLE HiiHandle, IN EFI_STRING_ID StringId, IN CONST CHAR8 *Language OPTIONAL)
Definition: HiiString.c:211
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
SHELL_STATUS
Definition: Shell.h:21
@ SHELL_OUT_OF_RESOURCES
Definition: Shell.h:73
@ SHELL_ACCESS_DENIED
Definition: Shell.h:106
@ SHELL_ABORTED
Definition: Shell.h:128
@ SHELL_SUCCESS
Definition: Shell.h:25
@ SHELL_NOT_FOUND
Definition: Shell.h:101
@ SHELL_VOLUME_FULL
Definition: Shell.h:84
@ SHELL_DEVICE_ERROR
Definition: Shell.h:63
@ SHELL_SECURITY_VIOLATION
Definition: Shell.h:141
@ SHELL_WRITE_PROTECTED
Definition: Shell.h:68
@ SHELL_INVALID_PARAMETER
Definition: Shell.h:35
SHELL_STATUS GetDestinationLocation(IN CONST CHAR16 *DestParameter, IN OUT CHAR16 **DestPathPointer, IN CONST CHAR16 *Cwd, IN CONST BOOLEAN SingleSource, IN OUT UINT64 *DestAttr)
Definition: Mv.c:233
EFI_STATUS MoveWithinFileSystems(IN EFI_SHELL_FILE_INFO *Node, IN CHAR16 *DestPath, OUT VOID **Resp)
Definition: Mv.c:452
SHELL_STATUS ValidateAndMoveFiles(IN EFI_SHELL_FILE_INFO *FileList, OUT VOID **Resp, IN CONST CHAR16 *DestParameter)
Definition: Mv.c:537
BOOLEAN IsBetweenFileSystem(IN CONST CHAR16 *FullName, IN CONST CHAR16 *Cwd, IN CONST CHAR16 *DestPath)
Definition: Mv.c:23
BOOLEAN IsValidMove(IN CONST CHAR16 *SourcePath, IN CONST CHAR16 *Cwd, IN CONST CHAR16 *DestPath, IN CONST UINT64 Attribute, IN CONST UINT64 DestAttr, IN CONST EFI_STATUS FileStatus)
Definition: Mv.c:146
SHELL_STATUS EFIAPI ShellCommandRunMv(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Mv.c:751
EFI_STATUS CreateFullDestPath(IN CONST CHAR16 **DestPath, OUT CHAR16 **FullDestPath, IN CONST CHAR16 *FileName)
Definition: Mv.c:412
EFI_STATUS MoveBetweenFileSystems(IN EFI_SHELL_FILE_INFO *Node, IN CONST CHAR16 *DestPath, OUT VOID **Resp)
Definition: Mv.c:365
BOOLEAN IsSoucePathValid(IN CONST CHAR16 *SrcPath, IN CONST CHAR16 *CwdPath)
Definition: Mv.c:73
SHELL_STATUS CascadeDelete(IN EFI_SHELL_FILE_INFO *Node, IN CONST BOOLEAN Quiet)
Definition: Rm.c:66
CONST CHAR16 *EFIAPI ShellGetCurrentDir(IN CHAR16 *CONST DeviceName OPTIONAL)
EFI_STATUS EFIAPI ShellSetFileInfo(IN SHELL_FILE_HANDLE FileHandle, IN EFI_FILE_INFO *FileInfo)
Definition: UefiShellLib.c:601
BOOLEAN EFIAPI ShellGetExecutionBreakFlag(VOID)
EFI_STATUS EFIAPI ShellDeleteFileByName(IN CONST CHAR16 *FileName)
EFI_STATUS EFIAPI ShellPromptForResponseHii(IN SHELL_PROMPT_REQUEST_TYPE Type, IN CONST EFI_STRING_ID HiiFormatStringId, IN CONST EFI_HII_HANDLE HiiFormatHandle, IN OUT VOID **Response)
EFI_STATUS EFIAPI ShellCloseFileMetaArg(IN OUT EFI_SHELL_FILE_INFO **ListHead)
#define ShellCommandLineParse(CheckList, CheckPackage, ProblemParam, AutoPageBreak)
Make it easy to upgrade from older versions of the shell library.
Definition: ShellLib.h:755
EFI_STATUS EFIAPI ShellPrintHiiEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR8 *Language OPTIONAL, IN CONST EFI_STRING_ID HiiFormatStringId, IN CONST EFI_HII_HANDLE HiiFormatHandle,...)
BOOLEAN EFIAPI ShellCommandLineGetFlag(IN CONST LIST_ENTRY *CONST CheckPackage, IN CONST CHAR16 *CONST KeyString)
CHAR16 *EFIAPI StrnCatGrow(IN OUT CHAR16 **Destination, IN OUT UINTN *CurrentSize, IN CONST CHAR16 *Source, IN UINTN Count)
SHELL_PROMPT_RESPONSE
Definition: ShellLib.h:1198
EFI_STATUS EFIAPI ShellFileExists(IN CONST CHAR16 *Name)
EFI_STATUS EFIAPI ShellOpenFileMetaArg(IN CHAR16 *Arg, IN UINT64 OpenMode, IN OUT EFI_SHELL_FILE_INFO **ListHead)
VOID EFIAPI ShellCommandLineFreeVarList(IN LIST_ENTRY *CheckPackage)
EFI_STATUS EFIAPI ShellInitialize(VOID)
Definition: UefiShellLib.c:532
EFI_STATUS EFIAPI ShellIsDirectory(IN CONST CHAR16 *DirName)
EFI_STATUS EFIAPI ShellPrintEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR16 *Format,...)
CONST CHAR16 *EFIAPI ShellCommandLineGetRawValue(IN CONST LIST_ENTRY *CONST CheckPackage, IN UINTN Position)
UINTN EFIAPI ShellCommandLineGetCount(IN CONST LIST_ENTRY *CheckPackage)
SHELL_PARAM_ITEM EmptyParamList[]
Helper structure for no parameters (besides -? and -b)
Definition: UefiShellLib.c:19
INTN EFIAPI Test(CONST VOID *b1, CONST VOID *b2)
INTN EFIAPI StringNoCaseCompare(IN CONST VOID *Buffer1, IN CONST VOID *Buffer2)
Definition: BaseSortLib.c:92
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
#define STRING_TOKEN(t)
EFI_STATUS ShellLevel2StripQuotes(IN CONST CHAR16 *OriginalString, OUT CHAR16 **CleanString)
UINT64 Size
Definition: FileInfo.h:23
UINT64 Attribute
Definition: FileInfo.h:47
CHAR16 FileName[1]
Definition: FileInfo.h:52
LIST_ENTRY Link
Linked list members.
Definition: Shell.h:153
EFI_FILE_INFO * Info
Pointer to the FileInfo struct for this file or NULL.
Definition: Shell.h:158
EFI_STATUS Status
Status of opening the file. Valid only if Handle != NULL.
Definition: Shell.h:154
CONST CHAR16 * FullName
Fully qualified filename.
Definition: Shell.h:155
CONST CHAR16 * FileName
name of this file.
Definition: Shell.h:156