]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c
ShellPkg : Check pointer before dereferencing
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel2CommandsLib / Cp.c
1 /** @file
2 Main file for cp shell level 2 function.
3
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
9
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.
12
13 **/
14
15 #include "UefiShellLevel2CommandsLib.h"
16
17 /**
18 Function to take a list of files to copy and a destination location and do
19 the verification and copying of those files to that location. This function
20 will report any errors to the user and halt.
21
22 @param[in] FileList A LIST_ENTRY* based list of files to move.
23 @param[in] DestDir The destination location.
24 @param[in] SilentMode TRUE to eliminate screen output.
25 @param[in] RecursiveMode TRUE to copy directories.
26 @param[in] Resp The response to the overwrite query (if always).
27
28 @retval SHELL_SUCCESS the files were all moved.
29 @retval SHELL_INVALID_PARAMETER a parameter was invalid
30 @retval SHELL_SECURITY_VIOLATION a security violation ocurred
31 @retval SHELL_WRITE_PROTECTED the destination was write protected
32 @retval SHELL_OUT_OF_RESOURCES a memory allocation failed
33 **/
34 SHELL_STATUS
35 EFIAPI
36 ValidateAndCopyFiles(
37 IN CONST EFI_SHELL_FILE_INFO *FileList,
38 IN CONST CHAR16 *DestDir,
39 IN BOOLEAN SilentMode,
40 IN BOOLEAN RecursiveMode,
41 IN VOID **Resp
42 );
43
44 /**
45 Function to Copy one file to another location
46
47 If the destination exists the user will be prompted and the result put into *resp
48
49 @param[in] Source pointer to source file name
50 @param[in] Dest pointer to destination file name
51 @param[out] Resp pointer to response from question. Pass back on looped calling
52 @param[in] SilentMode whether to run in quiet mode or not
53
54 @retval SHELL_SUCCESS The source file was copied to the destination
55 **/
56 SHELL_STATUS
57 EFIAPI
58 CopySingleFile(
59 IN CONST CHAR16 *Source,
60 IN CONST CHAR16 *Dest,
61 OUT VOID **Resp,
62 IN BOOLEAN SilentMode
63 )
64 {
65 VOID *Response;
66 UINTN ReadSize;
67 SHELL_FILE_HANDLE SourceHandle;
68 SHELL_FILE_HANDLE DestHandle;
69 EFI_STATUS Status;
70 VOID *Buffer;
71 CHAR16 *TempName;
72 UINTN Size;
73 EFI_SHELL_FILE_INFO *List;
74 SHELL_STATUS ShellStatus;
75
76
77 ASSERT(Resp != NULL);
78
79 SourceHandle = NULL;
80 DestHandle = NULL;
81 Response = *Resp;
82 List = NULL;
83
84 ReadSize = PcdGet16(PcdShellFileOperationSize);
85 // Why bother copying a file to itself
86 if (StrCmp(Source, Dest) == 0) {
87 return (SHELL_SUCCESS);
88 }
89
90 //
91 // Open destination file without create
92 //
93 Status = ShellOpenFileByName(Dest, &DestHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0);
94
95 //
96 // close file
97 //
98 if (DestHandle != NULL) {
99 ShellCloseFile(&DestHandle);
100 DestHandle = NULL;
101 }
102
103 //
104 // if the destination file existed check response and possibly prompt user
105 //
106 if (!EFI_ERROR(Status)) {
107 if (Response == NULL && !SilentMode) {
108 Status = ShellPromptForResponseHii(ShellPromptResponseTypeYesNoAllCancel, STRING_TOKEN (STR_GEN_DEST_EXIST_OVR), gShellLevel2HiiHandle, &Response);
109 }
110 //
111 // possibly return based on response
112 //
113 if (!SilentMode) {
114 switch (*(SHELL_PROMPT_RESPONSE*)Response) {
115 case ShellPromptResponseNo:
116 //
117 // return success here so we dont stop the process
118 //
119 return (SHELL_SUCCESS);
120 case ShellPromptResponseCancel:
121 *Resp = Response;
122 //
123 // indicate to stop everything
124 //
125 return (SHELL_ABORTED);
126 case ShellPromptResponseAll:
127 *Resp = Response;
128 case ShellPromptResponseYes:
129 break;
130 default:
131 return SHELL_ABORTED;
132 }
133 }
134 }
135
136 if (ShellIsDirectory(Source) == EFI_SUCCESS) {
137 Status = ShellCreateDirectory(Dest, &DestHandle);
138 if (EFI_ERROR(Status)) {
139 return (SHELL_ACCESS_DENIED);
140 }
141
142 //
143 // Now copy all the files under the directory...
144 //
145 TempName = NULL;
146 Size = 0;
147 StrnCatGrow(&TempName, &Size, Source, 0);
148 StrnCatGrow(&TempName, &Size, L"\\*", 0);
149 if (TempName != NULL) {
150 ShellOpenFileMetaArg((CHAR16*)TempName, EFI_FILE_MODE_READ, &List);
151 *TempName = CHAR_NULL;
152 StrnCatGrow(&TempName, &Size, Dest, 0);
153 StrnCatGrow(&TempName, &Size, L"\\", 0);
154 ShellStatus = ValidateAndCopyFiles(List, TempName, SilentMode, TRUE, Resp);
155 ShellCloseFileMetaArg(&List);
156 SHELL_FREE_NON_NULL(TempName);
157 Size = 0;
158 }
159 } else {
160 //
161 // open file with create enabled
162 //
163 Status = ShellOpenFileByName(Dest, &DestHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
164 if (EFI_ERROR(Status)) {
165 return (SHELL_ACCESS_DENIED);
166 }
167
168 //
169 // open source file
170 //
171 Status = ShellOpenFileByName(Source, &SourceHandle, EFI_FILE_MODE_READ, 0);
172 ASSERT_EFI_ERROR(Status);
173
174 //
175 // copy data between files
176 //
177 Buffer = AllocateZeroPool(ReadSize);
178 ASSERT(Buffer != NULL);
179 while (ReadSize == PcdGet16(PcdShellFileOperationSize) && !EFI_ERROR(Status)) {
180 Status = ShellReadFile(SourceHandle, &ReadSize, Buffer);
181 ASSERT_EFI_ERROR(Status);
182 Status = ShellWriteFile(DestHandle, &ReadSize, Buffer);
183 }
184 }
185
186 //
187 // close files
188 //
189 if (DestHandle != NULL) {
190 ShellCloseFile(&DestHandle);
191 DestHandle = NULL;
192 }
193 if (SourceHandle != NULL) {
194 ShellCloseFile(&SourceHandle);
195 SourceHandle = NULL;
196 }
197
198 //
199 // return
200 //
201 return (SHELL_SUCCESS);
202 }
203
204 /**
205 function to take a list of files to copy and a destination location and do
206 the verification and copying of those files to that location. This function
207 will report any errors to the user and halt.
208
209 The key is to have this function called ONLY once. this allows for the parameter
210 verification to happen correctly.
211
212 @param[in] FileList A LIST_ENTRY* based list of files to move.
213 @param[in] DestDir The destination location.
214 @param[in] SilentMode TRUE to eliminate screen output.
215 @param[in] RecursiveMode TRUE to copy directories.
216 @param[in] Resp The response to the overwrite query (if always).
217
218 @retval SHELL_SUCCESS the files were all moved.
219 @retval SHELL_INVALID_PARAMETER a parameter was invalid
220 @retval SHELL_SECURITY_VIOLATION a security violation ocurred
221 @retval SHELL_WRITE_PROTECTED the destination was write protected
222 @retval SHELL_OUT_OF_RESOURCES a memory allocation failed
223 **/
224 SHELL_STATUS
225 EFIAPI
226 ValidateAndCopyFiles(
227 IN CONST EFI_SHELL_FILE_INFO *FileList,
228 IN CONST CHAR16 *DestDir,
229 IN BOOLEAN SilentMode,
230 IN BOOLEAN RecursiveMode,
231 IN VOID **Resp
232 )
233 {
234 CHAR16 *HiiOutput;
235 CHAR16 *HiiResultOk;
236 CONST EFI_SHELL_FILE_INFO *Node;
237 SHELL_STATUS ShellStatus;
238 CHAR16 *DestPath;
239 VOID *Response;
240 UINTN PathLen;
241 CONST CHAR16 *Cwd;
242 CONST CHAR16 *TempLocation;
243 UINTN NewSize;
244
245 if (Resp == NULL) {
246 Response = NULL;
247 } else {
248 Response = *Resp;
249 }
250
251 DestPath = NULL;
252 ShellStatus = SHELL_SUCCESS;
253 PathLen = 0;
254 Cwd = ShellGetCurrentDir(NULL);
255
256 ASSERT(FileList != NULL);
257 ASSERT(DestDir != NULL);
258
259 //
260 // We already verified that this was present.
261 //
262 ASSERT(Cwd != NULL);
263
264 //
265 // If we are trying to copy multiple files... make sure we got a directory for the target...
266 //
267 if (EFI_ERROR(ShellIsDirectory(DestDir)) && FileList->Link.ForwardLink != FileList->Link.BackLink) {
268 //
269 // Error for destination not a directory
270 //
271 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, DestDir);
272 return (SHELL_INVALID_PARAMETER);
273 }
274 for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&FileList->Link)
275 ; !IsNull(&FileList->Link, &Node->Link)
276 ; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&FileList->Link, &Node->Link)
277 ){
278 //
279 // skip the directory traversing stuff...
280 //
281 if (StrCmp(Node->FileName, L".") == 0 || StrCmp(Node->FileName, L"..") == 0) {
282 continue;
283 }
284
285 NewSize = StrSize(DestDir);
286 NewSize += StrSize(Node->FullName);
287 NewSize += StrSize(Cwd);
288 if (NewSize > PathLen) {
289 PathLen = NewSize;
290 }
291
292 //
293 // Make sure got -r if required
294 //
295 if (!RecursiveMode && !EFI_ERROR(ShellIsDirectory(Node->FullName))) {
296 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DIR_REQ), gShellLevel2HiiHandle);
297 return (SHELL_INVALID_PARAMETER);
298 }
299
300 //
301 // make sure got dest as dir if needed
302 //
303 if (!EFI_ERROR(ShellIsDirectory(Node->FullName)) && EFI_ERROR(ShellIsDirectory(DestDir))) {
304 //
305 // Error for destination not a directory
306 //
307 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, DestDir);
308 return (SHELL_INVALID_PARAMETER);
309 }
310 }
311
312 HiiOutput = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_CP_OUTPUT), NULL);
313 HiiResultOk = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_GEN_RES_OK), NULL);
314 DestPath = AllocateZeroPool(PathLen);
315
316 if (DestPath == NULL || HiiOutput == NULL || HiiResultOk == NULL) {
317 SHELL_FREE_NON_NULL(DestPath);
318 SHELL_FREE_NON_NULL(HiiOutput);
319 SHELL_FREE_NON_NULL(HiiResultOk);
320 return (SHELL_OUT_OF_RESOURCES);
321 }
322
323 //
324 // Go through the list of files to copy...
325 //
326 for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&FileList->Link)
327 ; !IsNull(&FileList->Link, &Node->Link)
328 ; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&FileList->Link, &Node->Link)
329 ){
330 if (ShellGetExecutionBreakFlag()) {
331 break;
332 }
333 ASSERT(Node->FileName != NULL);
334 ASSERT(Node->FullName != NULL);
335
336 //
337 // skip the directory traversing stuff...
338 //
339 if (StrCmp(Node->FileName, L".") == 0 || StrCmp(Node->FileName, L"..") == 0) {
340 continue;
341 }
342
343 if (FileList->Link.ForwardLink == FileList->Link.BackLink // 1 item
344 && EFI_ERROR(ShellIsDirectory(DestDir)) // not an existing directory
345 ) {
346 if (StrStr(DestDir, L":") == NULL) {
347 //
348 // simple copy of a single file
349 //
350 StrCpy(DestPath, Cwd);
351 if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {
352 StrCat(DestPath, L"\\");
353 } else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {
354 ((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;
355 }
356 StrCat(DestPath, DestDir);
357 } else {
358 StrCpy(DestPath, DestDir);
359 }
360 } else {
361 //
362 // we have multiple files or a directory in the DestDir
363 //
364
365 //
366 // Check for leading slash
367 //
368 if (DestDir[0] == L'\\') {
369 //
370 // Copy to the root of CWD
371 //
372 StrCpy(DestPath, Cwd);
373 while (PathRemoveLastItem(DestPath));
374 StrCat(DestPath, DestDir+1);
375 StrCat(DestPath, Node->FileName);
376 } else if (StrStr(DestDir, L":") == NULL) {
377 StrCpy(DestPath, Cwd);
378 if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {
379 StrCat(DestPath, L"\\");
380 } else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {
381 ((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;
382 }
383 StrCat(DestPath, DestDir);
384 if (DestDir[StrLen(DestDir)-1] != L'\\' && Node->FileName[0] != L'\\') {
385 StrCat(DestPath, L"\\");
386 } else if (DestDir[StrLen(DestDir)-1] == L'\\' && Node->FileName[0] == L'\\') {
387 ((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;
388 }
389 StrCat(DestPath, Node->FileName);
390
391 } else {
392 StrCpy(DestPath, DestDir);
393 if (DestDir[StrLen(DestDir)-1] != L'\\' && Node->FileName[0] != L'\\') {
394 StrCat(DestPath, L"\\");
395 } else if (DestDir[StrLen(DestDir)-1] == L'\\' && Node->FileName[0] == L'\\') {
396 ((CHAR16*)DestDir)[StrLen(DestDir)-1] = CHAR_NULL;
397 }
398 StrCat(DestPath, Node->FileName);
399 }
400 }
401
402 //
403 // Make sure the path exists
404 //
405 if (EFI_ERROR(VerifyIntermediateDirectories(DestPath))) {
406 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DIR_WNF), gShellLevel2HiiHandle);
407 ShellStatus = SHELL_DEVICE_ERROR;
408 break;
409 }
410
411 if ( !EFI_ERROR(ShellIsDirectory(Node->FullName))
412 && !EFI_ERROR(ShellIsDirectory(DestPath))
413 && StrniCmp(Node->FullName, DestPath, StrLen(DestPath)) == NULL
414 ){
415 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_SD_PARENT), gShellLevel2HiiHandle);
416 ShellStatus = SHELL_INVALID_PARAMETER;
417 break;
418 }
419 if (StringNoCaseCompare(&Node->FullName, &DestPath) == 0) {
420 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_SD_SAME), gShellLevel2HiiHandle);
421 ShellStatus = SHELL_INVALID_PARAMETER;
422 break;
423 }
424
425 if ((TempLocation = StrniCmp(Node->FullName, DestPath, StrLen(Node->FullName))) == 0
426 && (DestPath[StrLen(Node->FullName)] == CHAR_NULL || DestPath[StrLen(Node->FullName)] == L'\\')
427 ) {
428 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_SD_SAME), gShellLevel2HiiHandle);
429 ShellStatus = SHELL_INVALID_PARAMETER;
430 break;
431 }
432
433 PathCleanUpDirectories(DestPath);
434
435 ShellPrintEx(-1, -1, HiiOutput, Node->FullName, DestPath);
436
437 //
438 // copy single file...
439 //
440 ShellStatus = CopySingleFile(Node->FullName, DestPath, &Response, SilentMode);
441 if (ShellStatus != SHELL_SUCCESS) {
442 break;
443 }
444 }
445 if (ShellStatus == SHELL_SUCCESS && Resp == NULL) {
446 ShellPrintEx(-1, -1, L"%s", HiiResultOk);
447 }
448
449 SHELL_FREE_NON_NULL(DestPath);
450 SHELL_FREE_NON_NULL(HiiOutput);
451 SHELL_FREE_NON_NULL(HiiResultOk);
452 if (Resp == NULL) {
453 SHELL_FREE_NON_NULL(Response);
454 }
455
456 return (ShellStatus);
457 }
458
459 /**
460 Validate and if successful copy all the files from the list into
461 destination directory.
462
463 @param[in] FileList The list of files to copy.
464 @param[in] DestDir The directory to copy files to.
465 @param[in] SilentMode TRUE to eliminate screen output.
466 @param[in] RecursiveMode TRUE to copy directories.
467
468 @retval SHELL_INVALID_PARAMETER A parameter was invalid.
469 @retval SHELL_SUCCESS The operation was successful.
470 **/
471 SHELL_STATUS
472 EFIAPI
473 ProcessValidateAndCopyFiles(
474 IN EFI_SHELL_FILE_INFO *FileList,
475 IN CONST CHAR16 *DestDir,
476 IN BOOLEAN SilentMode,
477 IN BOOLEAN RecursiveMode
478 )
479 {
480 SHELL_STATUS ShellStatus;
481 EFI_SHELL_FILE_INFO *List;
482 EFI_STATUS Status;
483 EFI_FILE_INFO *FileInfo;
484
485 List = NULL;
486
487 Status = ShellOpenFileMetaArg((CHAR16*)DestDir, EFI_FILE_MODE_READ, &List);
488 if (List != NULL && List->Link.ForwardLink != List->Link.BackLink) {
489 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_MARG_ERROR), gShellLevel2HiiHandle, DestDir);
490 ShellStatus = SHELL_INVALID_PARAMETER;
491 ShellCloseFileMetaArg(&List);
492 } else if (List != NULL) {
493 ASSERT(((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink) != NULL);
494 ASSERT(((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->FullName != NULL);
495 FileInfo = NULL;
496 FileInfo = gEfiShellProtocol->GetFileInfo(((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->Handle);
497 ASSERT(FileInfo != NULL);
498 if ((FileInfo->Attribute & EFI_FILE_READ_ONLY) == 0) {
499 ShellStatus = ValidateAndCopyFiles(FileList, ((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->FullName, SilentMode, RecursiveMode, NULL);
500 } else {
501 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_ERROR), gShellLevel2HiiHandle);
502 ShellStatus = SHELL_ACCESS_DENIED;
503 }
504 SHELL_FREE_NON_NULL(FileInfo);
505 ShellCloseFileMetaArg(&List);
506 } else {
507 ShellStatus = ValidateAndCopyFiles(FileList, DestDir, SilentMode, RecursiveMode, NULL);
508 }
509
510 return (ShellStatus);
511 }
512
513 STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
514 {L"-r", TypeFlag},
515 {L"-q", TypeFlag},
516 {NULL, TypeMax}
517 };
518
519 /**
520 Function for 'cp' command.
521
522 @param[in] ImageHandle Handle to the Image (NULL if Internal).
523 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
524 **/
525 SHELL_STATUS
526 EFIAPI
527 ShellCommandRunCp (
528 IN EFI_HANDLE ImageHandle,
529 IN EFI_SYSTEM_TABLE *SystemTable
530 )
531 {
532 EFI_STATUS Status;
533 LIST_ENTRY *Package;
534 CHAR16 *ProblemParam;
535 SHELL_STATUS ShellStatus;
536 UINTN ParamCount;
537 UINTN LoopCounter;
538 EFI_SHELL_FILE_INFO *FileList;
539 BOOLEAN SilentMode;
540 BOOLEAN RecursiveMode;
541 CONST CHAR16 *Cwd;
542
543 ProblemParam = NULL;
544 ShellStatus = SHELL_SUCCESS;
545 ParamCount = 0;
546 FileList = NULL;
547
548 //
549 // initialize the shell lib (we must be in non-auto-init...)
550 //
551 Status = ShellInitialize();
552 ASSERT_EFI_ERROR(Status);
553
554 Status = CommandInit();
555 ASSERT_EFI_ERROR(Status);
556
557 //
558 // parse the command line
559 //
560 Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
561 if (EFI_ERROR(Status)) {
562 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
563 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
564 FreePool(ProblemParam);
565 ShellStatus = SHELL_INVALID_PARAMETER;
566 } else {
567 ASSERT(FALSE);
568 }
569 } else {
570 //
571 // check for "-?"
572 //
573 if (ShellCommandLineGetFlag(Package, L"-?")) {
574 ASSERT(FALSE);
575 }
576
577 //
578 // Initialize SilentMode and RecursiveMode
579 //
580 if (gEfiShellProtocol->BatchIsActive()) {
581 SilentMode = TRUE;
582 } else {
583 SilentMode = ShellCommandLineGetFlag(Package, L"-q");
584 }
585 RecursiveMode = ShellCommandLineGetFlag(Package, L"-r");
586
587 switch (ParamCount = ShellCommandLineGetCount(Package)) {
588 case 0:
589 case 1:
590 //
591 // we have insufficient parameters
592 //
593 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle);
594 ShellStatus = SHELL_INVALID_PARAMETER;
595 break;
596 case 2:
597 //
598 // must have valid CWD for single parameter...
599 //
600 Cwd = ShellGetCurrentDir(NULL);
601 if (Cwd == NULL){
602 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);
603 ShellStatus = SHELL_INVALID_PARAMETER;
604 } else {
605 Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, 1), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
606 if (FileList == NULL || IsListEmpty(&FileList->Link) || EFI_ERROR(Status)) {
607 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1));
608 ShellStatus = SHELL_NOT_FOUND;
609 } else {
610 ShellStatus = ProcessValidateAndCopyFiles(FileList, Cwd, SilentMode, RecursiveMode);
611 }
612 }
613
614 break;
615 default:
616 //
617 // Make a big list of all the files...
618 //
619 for (ParamCount--, LoopCounter = 1 ; LoopCounter < ParamCount && ShellStatus == SHELL_SUCCESS ; LoopCounter++) {
620 if (ShellGetExecutionBreakFlag()) {
621 break;
622 }
623 Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, LoopCounter), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
624 if (EFI_ERROR(Status) || FileList == NULL || IsListEmpty(&FileList->Link)) {
625 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, LoopCounter));
626 ShellStatus = SHELL_NOT_FOUND;
627 }
628 }
629 if (ShellStatus != SHELL_SUCCESS) {
630 Status = ShellCloseFileMetaArg(&FileList);
631 } else {
632 //
633 // now copy them all...
634 //
635 if (FileList != NULL && !IsListEmpty(&FileList->Link)) {
636 ShellStatus = ProcessValidateAndCopyFiles(FileList, PathCleanUpDirectories((CHAR16*)ShellCommandLineGetRawValue(Package, ParamCount)), SilentMode, RecursiveMode);
637 Status = ShellCloseFileMetaArg(&FileList);
638 if (EFI_ERROR(Status) && ShellStatus == SHELL_SUCCESS) {
639 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_FILE), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, ParamCount), ShellStatus|MAX_BIT);
640 ShellStatus = SHELL_ACCESS_DENIED;
641 }
642 }
643 }
644 break;
645 } // switch on parameter count
646
647 if (FileList != NULL) {
648 ShellCloseFileMetaArg(&FileList);
649 }
650
651 //
652 // free the command line package
653 //
654 ShellCommandLineFreeVarList (Package);
655 }
656
657 if (ShellGetExecutionBreakFlag()) {
658 return (SHELL_ABORTED);
659 }
660
661 return (ShellStatus);
662 }
663