]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Application/Shell/ShellProtocol.c
ShellPkg: Fix several GCC compiler warnings
[mirror_edk2.git] / ShellPkg / Application / Shell / ShellProtocol.c
1 /** @file
2 Member functions of EFI_SHELL_PROTOCOL and functions for creation,
3 manipulation, and initialization of EFI_SHELL_PROTOCOL.
4
5 Copyright (c) 2009 - 2010, 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
10
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.
13
14 **/
15
16 #include "Shell.h"
17 #include <Library/FileHandleLib.h>
18
19 /**
20 Close an open file handle.
21
22 This function closes a specified file handle. All "dirty" cached file data is
23 flushed to the device, and the file is closed. In all cases the handle is
24 closed.
25
26 @param[in] FileHandle The file handle to close.
27
28 @retval EFI_SUCCESS The file handle was closed successfully.
29 **/
30 EFI_STATUS
31 EFIAPI
32 EfiShellClose (
33 IN SHELL_FILE_HANDLE FileHandle
34 )
35 {
36 ShellFileHandleRemove(FileHandle);
37 return (FileHandleClose(FileHandle));
38 }
39
40 /**
41 Internal worker to determine whether there is a file system somewhere
42 upon the device path specified.
43
44 @param[in] DevicePath The device path to test.
45
46 @retval TRUE gEfiSimpleFileSystemProtocolGuid was installed on a handle with this device path
47 @retval FALSE gEfiSimpleFileSystemProtocolGuid was not found.
48 **/
49 BOOLEAN
50 EFIAPI
51 InternalShellProtocolIsSimpleFileSystemPresent(
52 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
53 )
54 {
55 EFI_DEVICE_PATH_PROTOCOL *DevicePathCopy;
56 EFI_STATUS Status;
57 EFI_HANDLE Handle;
58
59 Handle = NULL;
60
61 DevicePathCopy = (EFI_DEVICE_PATH_PROTOCOL*)DevicePath;
62 Status = gBS->LocateDevicePath(&gEfiSimpleFileSystemProtocolGuid, &DevicePathCopy, &Handle);
63
64 if ((Handle != NULL) && (!EFI_ERROR(Status))) {
65 return (TRUE);
66 }
67 return (FALSE);
68 }
69
70 /**
71 Internal worker debug helper function to print out maps as they are added.
72
73 @param[in] Mapping string mapping that has been added
74 @param[in] DevicePath pointer to device path that has been mapped.
75
76 @retval EFI_SUCCESS the operation was successful.
77 @return other an error ocurred
78
79 @sa LocateHandle
80 @sa OpenProtocol
81 **/
82 EFI_STATUS
83 EFIAPI
84 InternalShellProtocolDebugPrintMessage (
85 IN CONST CHAR16 *Mapping,
86 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
87 )
88 {
89 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *DevicePathToText;
90 EFI_STATUS Status;
91 CHAR16 *Temp;
92
93 Status = EFI_SUCCESS;
94 DEBUG_CODE_BEGIN();
95 DevicePathToText = NULL;
96
97 Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid,
98 NULL,
99 (VOID**)&DevicePathToText);
100 if (Mapping != NULL) {
101 DEBUG((EFI_D_INFO, "Added new map item:\"%S\"\r\n", Mapping));
102 }
103 if (!EFI_ERROR(Status)) {
104 if (DevicePath != NULL) {
105 Temp = DevicePathToText->ConvertDevicePathToText(DevicePath, TRUE, TRUE);
106 DEBUG((EFI_D_INFO, "DevicePath: %S\r\n", Temp));
107 FreePool(Temp);
108 }
109 }
110 DEBUG_CODE_END();
111 return (Status);
112 }
113
114 /**
115 This function creates a mapping for a device path.
116
117 If both DeviecPath and Mapping are NULL, this will reset the mapping to default values.
118
119 @param DevicePath Points to the device path. If this is NULL and Mapping points to a valid mapping,
120 then the mapping will be deleted.
121 @param Mapping Points to the NULL-terminated mapping for the device path. Must end with a ':'
122
123 @retval EFI_SUCCESS Mapping created or deleted successfully.
124 @retval EFI_NO_MAPPING There is no handle that corresponds exactly to DevicePath. See the
125 boot service function LocateDevicePath().
126 @retval EFI_ACCESS_DENIED The mapping is a built-in alias.
127 @retval EFI_INVALID_PARAMETER Mapping was NULL
128 @retval EFI_INVALID_PARAMETER Mapping did not end with a ':'
129 @retval EFI_INVALID_PARAMETER DevicePath was not pointing at a device that had a SIMPLE_FILE_SYSTEM_PROTOCOL installed.
130 @retval EFI_NOT_FOUND There was no mapping found to delete
131 @retval EFI_OUT_OF_RESOURCES Memory allocation failed
132 **/
133 EFI_STATUS
134 EFIAPI
135 EfiShellSetMap(
136 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL,
137 IN CONST CHAR16 *Mapping
138 )
139 {
140 EFI_STATUS Status;
141 SHELL_MAP_LIST *MapListNode;
142
143 if (Mapping == NULL){
144 return (EFI_INVALID_PARAMETER);
145 }
146
147 if (Mapping[StrLen(Mapping)-1] != ':') {
148 return (EFI_INVALID_PARAMETER);
149 }
150
151 //
152 // Delete the mapping
153 //
154 if (DevicePath == NULL) {
155 if (IsListEmpty(&gShellMapList.Link)) {
156 return (EFI_NOT_FOUND);
157 }
158 for ( MapListNode = (SHELL_MAP_LIST *)GetFirstNode(&gShellMapList.Link)
159 ; !IsNull(&gShellMapList.Link, &MapListNode->Link)
160 ; MapListNode = (SHELL_MAP_LIST *)GetNextNode(&gShellMapList.Link, &MapListNode->Link)
161 ){
162 if (StringNoCaseCompare(&MapListNode->MapName, &Mapping) == 0) {
163 RemoveEntryList(&MapListNode->Link);
164 FreePool(MapListNode);
165 return (EFI_SUCCESS);
166 }
167 } // for loop
168
169 //
170 // We didnt find one to delete
171 //
172 return (EFI_NOT_FOUND);
173 }
174
175 //
176 // make sure this is a valid to add device path
177 //
178 ///@todo add BlockIo to this test...
179 if (!InternalShellProtocolIsSimpleFileSystemPresent(DevicePath)) {
180 return (EFI_INVALID_PARAMETER);
181 }
182
183 //
184 // First make sure there is no old mapping
185 //
186 Status = EfiShellSetMap(NULL, Mapping);
187 if ((Status != EFI_SUCCESS) && (Status != EFI_NOT_FOUND)) {
188 return (Status);
189 }
190
191 //
192 // now add the new one.
193 //
194 Status = ShellCommandAddMapItemAndUpdatePath(Mapping, DevicePath, 0, FALSE);
195
196 return(Status);
197 }
198
199 /**
200 Gets the device path from the mapping.
201
202 This function gets the device path associated with a mapping.
203
204 @param Mapping A pointer to the mapping
205
206 @retval !=NULL Pointer to the device path that corresponds to the
207 device mapping. The returned pointer does not need
208 to be freed.
209 @retval NULL There is no device path associated with the
210 specified mapping.
211 **/
212 CONST EFI_DEVICE_PATH_PROTOCOL *
213 EFIAPI
214 EfiShellGetDevicePathFromMap(
215 IN CONST CHAR16 *Mapping
216 )
217 {
218 SHELL_MAP_LIST *MapListItem;
219 CHAR16 *NewName;
220 UINTN Size;
221
222 NewName = NULL;
223 Size = 0;
224
225 StrnCatGrow(&NewName, &Size, Mapping, 0);
226 if (Mapping[StrLen(Mapping)-1] != L':') {
227 StrnCatGrow(&NewName, &Size, L":", 0);
228 }
229
230 MapListItem = ShellCommandFindMapItem(NewName);
231
232 FreePool(NewName);
233
234 if (MapListItem != NULL) {
235 return (MapListItem->DevicePath);
236 }
237 return(NULL);
238 }
239
240 /**
241 Gets the mapping(s) that most closely matches the device path.
242
243 This function gets the mapping which corresponds to the device path *DevicePath. If
244 there is no exact match, then the mapping which most closely matches *DevicePath
245 is returned, and *DevicePath is updated to point to the remaining portion of the
246 device path. If there is an exact match, the mapping is returned and *DevicePath
247 points to the end-of-device-path node.
248
249 If there are multiple map names they will be semi-colon seperated in the
250 NULL-terminated string.
251
252 @param DevicePath On entry, points to a device path pointer. On
253 exit, updates the pointer to point to the
254 portion of the device path after the mapping.
255
256 @retval NULL No mapping was found.
257 @return !=NULL Pointer to NULL-terminated mapping. The buffer
258 is callee allocated and should be freed by the caller.
259 **/
260 CONST CHAR16 *
261 EFIAPI
262 EfiShellGetMapFromDevicePath(
263 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
264 )
265 {
266 SHELL_MAP_LIST *Node;
267 CHAR16 *PathForReturn;
268 UINTN PathSize;
269 // EFI_HANDLE PathHandle;
270 // EFI_HANDLE MapHandle;
271 // EFI_STATUS Status;
272 // EFI_DEVICE_PATH_PROTOCOL *DevicePathCopy;
273 // EFI_DEVICE_PATH_PROTOCOL *MapPathCopy;
274
275 if (DevicePath == NULL || *DevicePath == NULL) {
276 return (NULL);
277 }
278
279 PathForReturn = NULL;
280 PathSize = 0;
281
282 for ( Node = (SHELL_MAP_LIST *)GetFirstNode(&gShellMapList.Link)
283 ; !IsNull(&gShellMapList.Link, &Node->Link)
284 ; Node = (SHELL_MAP_LIST *)GetNextNode(&gShellMapList.Link, &Node->Link)
285 ){
286 //
287 // check for exact match
288 //
289 if (DevicePathCompare(DevicePath, &Node->DevicePath) == 0) {
290 ASSERT((PathForReturn == NULL && PathSize == 0) || (PathForReturn != NULL));
291 if (PathSize != 0) {
292 PathForReturn = StrnCatGrow(&PathForReturn, &PathSize, L";", 0);
293 }
294 PathForReturn = StrnCatGrow(&PathForReturn, &PathSize, Node->MapName, 0);
295 }
296 }
297 if (PathForReturn != NULL) {
298 while (!IsDevicePathEndType (*DevicePath)) {
299 *DevicePath = NextDevicePathNode (*DevicePath);
300 }
301 SetDevicePathEndNode (*DevicePath);
302 }
303 /*
304 ///@todo finish code for inexact matches.
305 if (PathForReturn == NULL) {
306 PathSize = 0;
307
308 DevicePathCopy = DuplicateDevicePath(*DevicePath);
309 ASSERT(DevicePathCopy != NULL);
310 Status = gBS->LocateDevicePath(&gEfiSimpleFileSystemProtocolGuid, &DevicePathCopy, &PathHandle);
311 ASSERT_EFI_ERROR(Status);
312 //
313 // check each of the device paths we have to get the root of the path for consist mappings
314 //
315 for ( Node = (SHELL_MAP_LIST *)GetFirstNode(&gShellMapList.Link)
316 ; !IsNull(&gShellMapList.Link, &Node->Link)
317 ; Node = (SHELL_MAP_LIST *)GetNextNode(&gShellMapList.Link, &Node->Link)
318 ){
319 if ((Node->Flags & SHELL_MAP_FLAGS_CONSIST) == 0) {
320 continue;
321 }
322 MapPathCopy = DuplicateDevicePath(Node->DevicePath);
323 ASSERT(MapPathCopy != NULL);
324 Status = gBS->LocateDevicePath(&gEfiSimpleFileSystemProtocolGuid, &MapPathCopy, &MapHandle);
325 if (MapHandle == PathHandle) {
326
327 *DevicePath = DevicePathCopy;
328
329 MapPathCopy = NULL;
330 DevicePathCopy = NULL;
331 PathForReturn = StrnCatGrow(&PathForReturn, &PathSize, Node->MapName, 0);
332 PathForReturn = StrnCatGrow(&PathForReturn, &PathSize, L";", 0);
333 break;
334 }
335 }
336 //
337 // now add on the non-consistent mappings
338 //
339 for ( Node = (SHELL_MAP_LIST *)GetFirstNode(&gShellMapList.Link)
340 ; !IsNull(&gShellMapList.Link, &Node->Link)
341 ; Node = (SHELL_MAP_LIST *)GetNextNode(&gShellMapList.Link, &Node->Link)
342 ){
343 if ((Node->Flags & SHELL_MAP_FLAGS_CONSIST) != 0) {
344 continue;
345 }
346 MapPathCopy = Node->DevicePath;
347 ASSERT(MapPathCopy != NULL);
348 Status = gBS->LocateDevicePath(&gEfiSimpleFileSystemProtocolGuid, &MapPathCopy, &MapHandle);
349 if (MapHandle == PathHandle) {
350 PathForReturn = StrnCatGrow(&PathForReturn, &PathSize, Node->MapName, 0);
351 PathForReturn = StrnCatGrow(&PathForReturn, &PathSize, L";", 0);
352 break;
353 }
354 }
355 }
356 */
357
358 return (AddBufferToFreeList(PathForReturn));
359 }
360
361 /**
362 Converts a device path to a file system-style path.
363
364 This function converts a device path to a file system path by replacing part, or all, of
365 the device path with the file-system mapping. If there are more than one application
366 file system mappings, the one that most closely matches Path will be used.
367
368 @param Path The pointer to the device path
369
370 @retval NULL the device path could not be found.
371 @return all The pointer of the NULL-terminated file path. The path
372 is callee-allocated and should be freed by the caller.
373 **/
374 CHAR16 *
375 EFIAPI
376 EfiShellGetFilePathFromDevicePath(
377 IN CONST EFI_DEVICE_PATH_PROTOCOL *Path
378 )
379 {
380 EFI_DEVICE_PATH_PROTOCOL *DevicePathCopy;
381 EFI_DEVICE_PATH_PROTOCOL *MapPathCopy;
382 SHELL_MAP_LIST *MapListItem;
383 CHAR16 *PathForReturn;
384 UINTN PathSize;
385 EFI_HANDLE PathHandle;
386 EFI_HANDLE MapHandle;
387 EFI_STATUS Status;
388 FILEPATH_DEVICE_PATH *FilePath;
389
390 PathForReturn = NULL;
391 PathSize = 0;
392
393 DevicePathCopy = (EFI_DEVICE_PATH_PROTOCOL*)Path;
394 ASSERT(DevicePathCopy != NULL);
395 if (DevicePathCopy == NULL) {
396 return (NULL);
397 }
398 ///@todo BlockIo?
399 Status = gBS->LocateDevicePath(&gEfiSimpleFileSystemProtocolGuid, &DevicePathCopy, &PathHandle);
400
401 if (EFI_ERROR(Status)) {
402 return (NULL);
403 }
404 //
405 // check each of the device paths we have to get the root of the path
406 //
407 for ( MapListItem = (SHELL_MAP_LIST *)GetFirstNode(&gShellMapList.Link)
408 ; !IsNull(&gShellMapList.Link, &MapListItem->Link)
409 ; MapListItem = (SHELL_MAP_LIST *)GetNextNode(&gShellMapList.Link, &MapListItem->Link)
410 ){
411 MapPathCopy = (EFI_DEVICE_PATH_PROTOCOL*)MapListItem->DevicePath;
412 ASSERT(MapPathCopy != NULL);
413 ///@todo BlockIo?
414 Status = gBS->LocateDevicePath(&gEfiSimpleFileSystemProtocolGuid, &MapPathCopy, &MapHandle);
415 if (MapHandle == PathHandle) {
416 ASSERT((PathForReturn == NULL && PathSize == 0) || (PathForReturn != NULL));
417 PathForReturn = StrnCatGrow(&PathForReturn, &PathSize, MapListItem->MapName, 0);
418 //
419 // go through all the remaining nodes in the device path
420 //
421 for ( FilePath = (FILEPATH_DEVICE_PATH*)DevicePathCopy
422 ; !IsDevicePathEnd (&FilePath->Header)
423 ; FilePath = (FILEPATH_DEVICE_PATH*)NextDevicePathNode (&FilePath->Header)
424 ){
425 //
426 // all the rest should be file path nodes
427 //
428 if ((DevicePathType(&FilePath->Header) != MEDIA_DEVICE_PATH) ||
429 (DevicePathSubType(&FilePath->Header) != MEDIA_FILEPATH_DP)) {
430 FreePool(PathForReturn);
431 PathForReturn = NULL;
432 ASSERT(FALSE);
433 } else {
434 //
435 // append the path part onto the filepath.
436 //
437 ASSERT((PathForReturn == NULL && PathSize == 0) || (PathForReturn != NULL));
438 PathForReturn = StrnCatGrow(&PathForReturn, &PathSize, L"\\", 1);
439 PathForReturn = StrnCatGrow(&PathForReturn, &PathSize, FilePath->PathName, 0);
440 }
441 } // for loop of remaining nodes
442 }
443 if (PathForReturn != NULL) {
444 break;
445 }
446 } // for loop of paths to check
447 return(PathForReturn);
448 }
449
450 /**
451 Converts a file system style name to a device path.
452
453 This function converts a file system style name to a device path, by replacing any
454 mapping references to the associated device path.
455
456 @param Path the pointer to the path
457
458 @return all The pointer of the file path. The file path is callee
459 allocated and should be freed by the caller.
460 **/
461 EFI_DEVICE_PATH_PROTOCOL *
462 EFIAPI
463 EfiShellGetDevicePathFromFilePath(
464 IN CONST CHAR16 *Path
465 )
466 {
467 CHAR16 *MapName;
468 CHAR16 *NewPath;
469 CONST CHAR16 *Cwd;
470 UINTN Size;
471 CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath;
472 EFI_DEVICE_PATH_PROTOCOL *DevicePathCopy;
473 EFI_DEVICE_PATH_PROTOCOL *DevicePathCopyForFree;
474 EFI_DEVICE_PATH_PROTOCOL *DevicePathForReturn;
475 EFI_HANDLE Handle;
476 EFI_STATUS Status;
477
478 MapName = NULL;
479 ASSERT(Path != NULL);
480
481 if (StrStr(Path, L":") == NULL) {
482 Cwd = EfiShellGetCurDir(NULL);
483 if (Cwd == NULL) {
484 return (NULL);
485 }
486 Size = StrSize(Cwd);
487 Size += StrSize(Path);
488 NewPath = AllocateZeroPool(Size);
489 ASSERT(NewPath != NULL);
490 StrCpy(NewPath, Cwd);
491 if ((NewPath[0] == (CHAR16)L'\\') &&
492 (NewPath[StrLen(NewPath)-1] == (CHAR16)L'\\')
493 ) {
494 ((CHAR16*)NewPath)[StrLen(NewPath)-1] = CHAR_NULL;
495 }
496 StrCat(NewPath, Path);
497 DevicePathForReturn = EfiShellGetDevicePathFromFilePath(NewPath);
498 FreePool(NewPath);
499 return (DevicePathForReturn);
500 }
501
502 Size = 0;
503 //
504 // find the part before (but including) the : for the map name
505 //
506 ASSERT((MapName == NULL && Size == 0) || (MapName != NULL));
507 MapName = StrnCatGrow(&MapName, &Size, Path, (StrStr(Path, L":")-Path+1));
508 if (MapName[StrLen(MapName)-1] != L':') {
509 ASSERT(FALSE);
510 return (NULL);
511 }
512
513 //
514 // look up the device path in the map
515 //
516 DevicePath = EfiShellGetDevicePathFromMap(MapName);
517 if (DevicePath == NULL) {
518 //
519 // Must have been a bad Mapname
520 //
521 return (NULL);
522 }
523
524 //
525 // make a copy for LocateDevicePath to modify (also save a pointer to call FreePool with)
526 //
527 DevicePathCopyForFree = DevicePathCopy = DuplicateDevicePath(DevicePath);
528 if (DevicePathCopy == NULL) {
529 ASSERT(FALSE);
530 FreePool(MapName);
531 return (NULL);
532 }
533
534 //
535 // get the handle
536 //
537 ///@todo BlockIo?
538 Status = gBS->LocateDevicePath(&gEfiSimpleFileSystemProtocolGuid, &DevicePathCopy, &Handle);
539 if (EFI_ERROR(Status)) {
540 if (DevicePathCopyForFree != NULL) {
541 FreePool(DevicePathCopyForFree);
542 }
543 FreePool(MapName);
544 return (NULL);
545 }
546
547 //
548 // build the full device path
549 //
550 DevicePathForReturn = FileDevicePath(Handle, Path+StrLen(MapName)+1);
551
552 FreePool(MapName);
553 if (DevicePathCopyForFree != NULL) {
554 FreePool(DevicePathCopyForFree);
555 }
556
557 return (DevicePathForReturn);
558 }
559
560 /**
561 Gets the name of the device specified by the device handle.
562
563 This function gets the user-readable name of the device specified by the device
564 handle. If no user-readable name could be generated, then *BestDeviceName will be
565 NULL and EFI_NOT_FOUND will be returned.
566
567 If EFI_DEVICE_NAME_USE_COMPONENT_NAME is set, then the function will return the
568 device's name using the EFI_COMPONENT_NAME2_PROTOCOL, if present on
569 DeviceHandle.
570
571 If EFI_DEVICE_NAME_USE_DEVICE_PATH is set, then the function will return the
572 device's name using the EFI_DEVICE_PATH_PROTOCOL, if present on DeviceHandle.
573 If both EFI_DEVICE_NAME_USE_COMPONENT_NAME and
574 EFI_DEVICE_NAME_USE_DEVICE_PATH are set, then
575 EFI_DEVICE_NAME_USE_COMPONENT_NAME will have higher priority.
576
577 @param DeviceHandle The handle of the device.
578 @param Flags Determines the possible sources of component names.
579 Valid bits are:
580 EFI_DEVICE_NAME_USE_COMPONENT_NAME
581 EFI_DEVICE_NAME_USE_DEVICE_PATH
582 @param Language A pointer to the language specified for the device
583 name, in the same format as described in the UEFI
584 specification, Appendix M
585 @param BestDeviceName On return, points to the callee-allocated NULL-
586 terminated name of the device. If no device name
587 could be found, points to NULL. The name must be
588 freed by the caller...
589
590 @retval EFI_SUCCESS Get the name successfully.
591 @retval EFI_NOT_FOUND Fail to get the device name.
592 @retval EFI_INVALID_PARAMETER Flags did not have a valid bit set.
593 @retval EFI_INVALID_PARAMETER BestDeviceName was NULL
594 @retval EFI_INVALID_PARAMETER DeviceHandle was NULL
595 **/
596 EFI_STATUS
597 EFIAPI
598 EfiShellGetDeviceName(
599 IN EFI_HANDLE DeviceHandle,
600 IN EFI_SHELL_DEVICE_NAME_FLAGS Flags,
601 IN CHAR8 *Language,
602 OUT CHAR16 **BestDeviceName
603 )
604 {
605 EFI_STATUS Status;
606 EFI_COMPONENT_NAME2_PROTOCOL *CompName2;
607 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *DevicePathToText;
608 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
609 EFI_HANDLE *HandleList;
610 UINTN HandleCount;
611 UINTN LoopVar;
612 CHAR16 *DeviceNameToReturn;
613 CHAR8 *Lang;
614 CHAR8 *TempChar;
615
616 if (BestDeviceName == NULL ||
617 DeviceHandle == NULL
618 ){
619 return (EFI_INVALID_PARAMETER);
620 }
621
622 //
623 // make sure one of the 2 supported bits is on
624 //
625 if (((Flags & EFI_DEVICE_NAME_USE_COMPONENT_NAME) == 0) &&
626 ((Flags & EFI_DEVICE_NAME_USE_DEVICE_PATH) == 0)) {
627 return (EFI_INVALID_PARAMETER);
628 }
629
630 DeviceNameToReturn = NULL;
631 *BestDeviceName = NULL;
632 HandleList = NULL;
633 HandleCount = 0;
634 Lang = NULL;
635
636 if ((Flags & EFI_DEVICE_NAME_USE_COMPONENT_NAME) != 0) {
637 Status = ParseHandleDatabaseByRelationship(
638 NULL,
639 DeviceHandle,
640 HR_DRIVER_BINDING_HANDLE|HR_DEVICE_DRIVER,
641 &HandleCount,
642 &HandleList);
643 for (LoopVar = 0; LoopVar < HandleCount ; LoopVar++){
644 //
645 // Go through those handles until we get one that passes for GetComponentName
646 //
647 Status = gBS->OpenProtocol(
648 HandleList[LoopVar],
649 &gEfiComponentName2ProtocolGuid,
650 (VOID**)&CompName2,
651 gImageHandle,
652 NULL,
653 EFI_OPEN_PROTOCOL_GET_PROTOCOL);
654 if (EFI_ERROR(Status)) {
655 Status = gBS->OpenProtocol(
656 HandleList[LoopVar],
657 &gEfiComponentNameProtocolGuid,
658 (VOID**)&CompName2,
659 gImageHandle,
660 NULL,
661 EFI_OPEN_PROTOCOL_GET_PROTOCOL);
662 }
663
664 if (EFI_ERROR(Status)) {
665 continue;
666 }
667 if (Language == NULL) {
668 Lang = AllocatePool(AsciiStrSize(CompName2->SupportedLanguages));
669 AsciiStrCpy(Lang, CompName2->SupportedLanguages);
670 TempChar = AsciiStrStr(Lang, ";");
671 if (TempChar != NULL){
672 *TempChar = CHAR_NULL;
673 }
674 } else {
675 Lang = AllocatePool(AsciiStrSize(Language));
676 AsciiStrCpy(Lang, Language);
677 }
678 Status = CompName2->GetControllerName(CompName2, DeviceHandle, NULL, Lang, &DeviceNameToReturn);
679 FreePool(Lang);
680 Lang = NULL;
681 if (!EFI_ERROR(Status) && DeviceNameToReturn != NULL) {
682 break;
683 }
684 }
685 if (HandleList != NULL) {
686 FreePool(HandleList);
687 }
688 if (DeviceNameToReturn != NULL){
689 ASSERT(BestDeviceName == NULL);
690 StrnCatGrow(BestDeviceName, NULL, DeviceNameToReturn, 0);
691 return (EFI_SUCCESS);
692 }
693 //
694 // dont return on fail since we will try device path if that bit is on
695 //
696 }
697 if ((Flags & EFI_DEVICE_NAME_USE_DEVICE_PATH) != 0) {
698 Status = gBS->LocateProtocol(
699 &gEfiDevicePathToTextProtocolGuid,
700 NULL,
701 (VOID**)&DevicePathToText);
702 //
703 // we now have the device path to text protocol
704 //
705 if (!EFI_ERROR(Status)) {
706 Status = gBS->OpenProtocol(
707 DeviceHandle,
708 &gEfiDevicePathProtocolGuid,
709 (VOID**)&DevicePath,
710 gImageHandle,
711 NULL,
712 EFI_OPEN_PROTOCOL_GET_PROTOCOL);
713 if (!EFI_ERROR(Status)) {
714 //
715 // use device path to text on the device path
716 //
717 *BestDeviceName = DevicePathToText->ConvertDevicePathToText(DevicePath, TRUE, TRUE);
718 return (EFI_SUCCESS);
719 }
720 }
721 }
722 //
723 // none of the selected bits worked.
724 //
725 return (EFI_NOT_FOUND);
726 }
727
728 /**
729 Opens the root directory of a device on a handle
730
731 This function opens the root directory of a device and returns a file handle to it.
732
733 @param DeviceHandle The handle of the device that contains the volume.
734 @param FileHandle On exit, points to the file handle corresponding to the root directory on the
735 device.
736
737 @retval EFI_SUCCESS Root opened successfully.
738 @retval EFI_NOT_FOUND EFI_SIMPLE_FILE_SYSTEM could not be found or the root directory
739 could not be opened.
740 @retval EFI_VOLUME_CORRUPTED The data structures in the volume were corrupted.
741 @retval EFI_DEVICE_ERROR The device had an error
742 **/
743 EFI_STATUS
744 EFIAPI
745 EfiShellOpenRootByHandle(
746 IN EFI_HANDLE DeviceHandle,
747 OUT SHELL_FILE_HANDLE *FileHandle
748 )
749 {
750 EFI_STATUS Status;
751 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFileSystem;
752 EFI_FILE_PROTOCOL *RealFileHandle;
753 EFI_DEVICE_PATH_PROTOCOL *DevPath;
754
755 //
756 // get the simple file system interface
757 //
758 Status = gBS->OpenProtocol(DeviceHandle,
759 &gEfiSimpleFileSystemProtocolGuid,
760 (VOID**)&SimpleFileSystem,
761 gImageHandle,
762 NULL,
763 EFI_OPEN_PROTOCOL_GET_PROTOCOL);
764 if (EFI_ERROR(Status)) {
765 return (EFI_NOT_FOUND);
766 }
767
768 Status = gBS->OpenProtocol(DeviceHandle,
769 &gEfiDevicePathProtocolGuid,
770 (VOID**)&DevPath,
771 gImageHandle,
772 NULL,
773 EFI_OPEN_PROTOCOL_GET_PROTOCOL);
774 if (EFI_ERROR(Status)) {
775 return (EFI_NOT_FOUND);
776 }
777 //
778 // Open the root volume now...
779 //
780 Status = SimpleFileSystem->OpenVolume(SimpleFileSystem, &RealFileHandle);
781 *FileHandle = ConvertEfiFileProtocolToShellHandle(RealFileHandle, EfiShellGetMapFromDevicePath(&DevPath));
782 return (Status);
783 }
784
785 /**
786 Opens the root directory of a device.
787
788 This function opens the root directory of a device and returns a file handle to it.
789
790 @param DevicePath Points to the device path corresponding to the device where the
791 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL is installed.
792 @param FileHandle On exit, points to the file handle corresponding to the root directory on the
793 device.
794
795 @retval EFI_SUCCESS Root opened successfully.
796 @retval EFI_NOT_FOUND EFI_SIMPLE_FILE_SYSTEM could not be found or the root directory
797 could not be opened.
798 @retval EFI_VOLUME_CORRUPTED The data structures in the volume were corrupted.
799 @retval EFI_DEVICE_ERROR The device had an error
800 **/
801 EFI_STATUS
802 EFIAPI
803 EfiShellOpenRoot(
804 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
805 OUT SHELL_FILE_HANDLE *FileHandle
806 )
807 {
808 EFI_STATUS Status;
809 EFI_HANDLE Handle;
810
811 //
812 // find the handle of the device with that device handle and the file system
813 //
814 ///@todo BlockIo?
815 Status = gBS->LocateDevicePath(&gEfiSimpleFileSystemProtocolGuid,
816 &DevicePath,
817 &Handle);
818 if (EFI_ERROR(Status)) {
819 return (EFI_NOT_FOUND);
820 }
821
822 return (EfiShellOpenRootByHandle(Handle, FileHandle));
823 }
824
825 /**
826 Returns whether any script files are currently being processed.
827
828 @retval TRUE There is at least one script file active.
829 @retval FALSE No script files are active now.
830
831 **/
832 BOOLEAN
833 EFIAPI
834 EfiShellBatchIsActive (
835 VOID
836 )
837 {
838 if (ShellCommandGetCurrentScriptFile() == NULL) {
839 return (FALSE);
840 }
841 return (TRUE);
842 }
843
844 /**
845 Worker function to open a file based on a device path. this will open the root
846 of the volume and then traverse down to the file itself.
847
848 @param DevicePath Device Path of the file.
849 @param FileHandle Pointer to the file upon a successful return.
850 @param OpenMode mode to open file in.
851 @param Attributes the File Attributes to use when creating a new file.
852
853 @retval EFI_SUCCESS the file is open and FileHandle is valid
854 @retval EFI_UNSUPPORTED the device path cotained non-path elements
855 @retval other an error ocurred.
856 **/
857 EFI_STATUS
858 EFIAPI
859 InternalOpenFileDevicePath(
860 IN OUT EFI_DEVICE_PATH_PROTOCOL *DevicePath,
861 OUT SHELL_FILE_HANDLE *FileHandle,
862 IN UINT64 OpenMode,
863 IN UINT64 Attributes OPTIONAL
864 )
865 {
866 EFI_STATUS Status;
867 FILEPATH_DEVICE_PATH *FilePathNode;
868 EFI_HANDLE Handle;
869 SHELL_FILE_HANDLE ShellHandle;
870 EFI_FILE_PROTOCOL *Handle1;
871 EFI_FILE_PROTOCOL *Handle2;
872 EFI_DEVICE_PATH_PROTOCOL *DpCopy;
873
874 ASSERT(FileHandle != NULL);
875 *FileHandle = NULL;
876 Handle1 = NULL;
877 DpCopy = DevicePath;
878
879 Status = EfiShellOpenRoot(DevicePath, &ShellHandle);
880
881 if (!EFI_ERROR(Status)) {
882 Handle1 = ConvertShellHandleToEfiFileProtocol(ShellHandle);
883 //
884 // chop off the begining part before the file system part...
885 //
886 ///@todo BlockIo?
887 Status = gBS->LocateDevicePath(&gEfiSimpleFileSystemProtocolGuid,
888 &DevicePath,
889 &Handle);
890 if (!EFI_ERROR(Status)) {
891 //
892 // To access as a file system, the file path should only
893 // contain file path components. Follow the file path nodes
894 // and find the target file
895 //
896 for ( FilePathNode = (FILEPATH_DEVICE_PATH *)DevicePath
897 ; !IsDevicePathEnd (&FilePathNode->Header)
898 ; FilePathNode = (FILEPATH_DEVICE_PATH *) NextDevicePathNode (&FilePathNode->Header)
899 ){
900 //
901 // For file system access each node should be a file path component
902 //
903 if (DevicePathType (&FilePathNode->Header) != MEDIA_DEVICE_PATH ||
904 DevicePathSubType (&FilePathNode->Header) != MEDIA_FILEPATH_DP
905 ) {
906 Status = EFI_UNSUPPORTED;
907 break;
908 }
909
910 //
911 // Open this file path node
912 //
913 Handle2 = Handle1;
914 Handle1 = NULL;
915
916 //
917 // if this is the last node in the DevicePath always create (if that was requested).
918 //
919 if (IsDevicePathEnd ((NextDevicePathNode (&FilePathNode->Header)))) {
920 Status = Handle2->Open (
921 Handle2,
922 &Handle1,
923 FilePathNode->PathName,
924 OpenMode,
925 Attributes
926 );
927 } else {
928
929 //
930 // This is not the last node and we dont want to 'create' existing
931 // directory entries...
932 //
933
934 //
935 // open without letting it create
936 // prevents error on existing files/directories
937 //
938 Status = Handle2->Open (
939 Handle2,
940 &Handle1,
941 FilePathNode->PathName,
942 OpenMode &~EFI_FILE_MODE_CREATE,
943 Attributes
944 );
945 //
946 // if above failed now open and create the 'item'
947 // if OpenMode EFI_FILE_MODE_CREATE bit was on (but disabled above)
948 //
949 if ((EFI_ERROR (Status)) && ((OpenMode & EFI_FILE_MODE_CREATE) != 0)) {
950 Status = Handle2->Open (
951 Handle2,
952 &Handle1,
953 FilePathNode->PathName,
954 OpenMode,
955 Attributes
956 );
957 }
958 }
959 //
960 // Close the last node
961 //
962 Handle2->Close (Handle2);
963
964 //
965 // If there's been an error, stop
966 //
967 if (EFI_ERROR (Status)) {
968 break;
969 }
970 } // for loop
971 }
972 }
973 if (EFI_ERROR(Status)) {
974 if (Handle1 != NULL) {
975 Handle1->Close(Handle1);
976 }
977 } else {
978 *FileHandle = ConvertEfiFileProtocolToShellHandle(Handle1, ShellFileHandleGetPath(ShellHandle));
979 }
980 return (Status);
981 }
982
983 /**
984 Creates a file or directory by name.
985
986 This function creates an empty new file or directory with the specified attributes and
987 returns the new file's handle. If the file already exists and is read-only, then
988 EFI_INVALID_PARAMETER will be returned.
989
990 If the file already existed, it is truncated and its attributes updated. If the file is
991 created successfully, the FileHandle is the file's handle, else, the FileHandle is NULL.
992
993 If the file name begins with >v, then the file handle which is returned refers to the
994 shell environment variable with the specified name. If the shell environment variable
995 already exists and is non-volatile then EFI_INVALID_PARAMETER is returned.
996
997 @param FileName Pointer to NULL-terminated file path
998 @param FileAttribs The new file's attrbiutes. the different attributes are
999 described in EFI_FILE_PROTOCOL.Open().
1000 @param FileHandle On return, points to the created file handle or directory's handle
1001
1002 @retval EFI_SUCCESS The file was opened. FileHandle points to the new file's handle.
1003 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
1004 @retval EFI_UNSUPPORTED could not open the file path
1005 @retval EFI_NOT_FOUND the specified file could not be found on the devide, or could not
1006 file the file system on the device.
1007 @retval EFI_NO_MEDIA the device has no medium.
1008 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no
1009 longer supported.
1010 @retval EFI_DEVICE_ERROR The device reported an error or can't get the file path according
1011 the DirName.
1012 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
1013 @retval EFI_WRITE_PROTECTED An attempt was made to create a file, or open a file for write
1014 when the media is write-protected.
1015 @retval EFI_ACCESS_DENIED The service denied access to the file.
1016 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the file.
1017 @retval EFI_VOLUME_FULL The volume is full.
1018 **/
1019 EFI_STATUS
1020 EFIAPI
1021 EfiShellCreateFile(
1022 IN CONST CHAR16 *FileName,
1023 IN UINT64 FileAttribs,
1024 OUT SHELL_FILE_HANDLE *FileHandle
1025 )
1026 {
1027 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
1028 EFI_STATUS Status;
1029
1030 //
1031 // Is this for an environment variable
1032 // do we start with >v
1033 //
1034 if (StrStr(FileName, L">v") == FileName) {
1035 if (!IsVolatileEnv(FileName+2)) {
1036 return (EFI_INVALID_PARAMETER);
1037 }
1038 *FileHandle = CreateFileInterfaceEnv(FileName+2);
1039 return (EFI_SUCCESS);
1040 }
1041
1042 //
1043 // We are opening a regular file.
1044 //
1045 DevicePath = EfiShellGetDevicePathFromFilePath(FileName);
1046 if (DevicePath == NULL) {
1047 return (EFI_NOT_FOUND);
1048 }
1049
1050 Status = InternalOpenFileDevicePath(DevicePath, FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, FileAttribs); // 0 = no specific file attributes
1051 FreePool(DevicePath);
1052
1053 return(Status);
1054 }
1055
1056 /**
1057 Opens a file or a directory by file name.
1058
1059 This function opens the specified file in the specified OpenMode and returns a file
1060 handle.
1061 If the file name begins with >v, then the file handle which is returned refers to the
1062 shell environment variable with the specified name. If the shell environment variable
1063 exists, is non-volatile and the OpenMode indicates EFI_FILE_MODE_WRITE, then
1064 EFI_INVALID_PARAMETER is returned.
1065
1066 If the file name is >i, then the file handle which is returned refers to the standard
1067 input. If the OpenMode indicates EFI_FILE_MODE_WRITE, then EFI_INVALID_PARAMETER
1068 is returned.
1069
1070 If the file name is >o, then the file handle which is returned refers to the standard
1071 output. If the OpenMode indicates EFI_FILE_MODE_READ, then EFI_INVALID_PARAMETER
1072 is returned.
1073
1074 If the file name is >e, then the file handle which is returned refers to the standard
1075 error. If the OpenMode indicates EFI_FILE_MODE_READ, then EFI_INVALID_PARAMETER
1076 is returned.
1077
1078 If the file name is NUL, then the file handle that is returned refers to the standard NUL
1079 file. If the OpenMode indicates EFI_FILE_MODE_READ, then EFI_INVALID_PARAMETER is
1080 returned.
1081
1082 If return EFI_SUCCESS, the FileHandle is the opened file's handle, else, the
1083 FileHandle is NULL.
1084
1085 @param FileName Points to the NULL-terminated UCS-2 encoded file name.
1086 @param FileHandle On return, points to the file handle.
1087 @param OpenMode File open mode. Either EFI_FILE_MODE_READ or
1088 EFI_FILE_MODE_WRITE from section 12.4 of the UEFI
1089 Specification.
1090 @retval EFI_SUCCESS The file was opened. FileHandle has the opened file's handle.
1091 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value. FileHandle is NULL.
1092 @retval EFI_UNSUPPORTED Could not open the file path. FileHandle is NULL.
1093 @retval EFI_NOT_FOUND The specified file could not be found on the device or the file
1094 system could not be found on the device. FileHandle is NULL.
1095 @retval EFI_NO_MEDIA The device has no medium. FileHandle is NULL.
1096 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no
1097 longer supported. FileHandle is NULL.
1098 @retval EFI_DEVICE_ERROR The device reported an error or can't get the file path according
1099 the FileName. FileHandle is NULL.
1100 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. FileHandle is NULL.
1101 @retval EFI_WRITE_PROTECTED An attempt was made to create a file, or open a file for write
1102 when the media is write-protected. FileHandle is NULL.
1103 @retval EFI_ACCESS_DENIED The service denied access to the file. FileHandle is NULL.
1104 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the file. FileHandle
1105 is NULL.
1106 @retval EFI_VOLUME_FULL The volume is full. FileHandle is NULL.
1107 **/
1108 EFI_STATUS
1109 EFIAPI
1110 EfiShellOpenFileByName(
1111 IN CONST CHAR16 *FileName,
1112 OUT SHELL_FILE_HANDLE *FileHandle,
1113 IN UINT64 OpenMode
1114 )
1115 {
1116 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
1117 EFI_STATUS Status;
1118
1119 *FileHandle = NULL;
1120
1121 //
1122 // Is this for StdIn
1123 //
1124 if (StrCmp(FileName, L">i") == 0) {
1125 //
1126 // make sure not writing to StdIn
1127 //
1128 if ((OpenMode & EFI_FILE_MODE_WRITE) != 0) {
1129 return (EFI_INVALID_PARAMETER);
1130 }
1131 *FileHandle = ShellInfoObject.NewShellParametersProtocol->StdIn;
1132 ASSERT(*FileHandle != NULL);
1133 return (EFI_SUCCESS);
1134 }
1135
1136 //
1137 // Is this for StdOut
1138 //
1139 if (StrCmp(FileName, L">o") == 0) {
1140 //
1141 // make sure not writing to StdIn
1142 //
1143 if ((OpenMode & EFI_FILE_MODE_READ) != 0) {
1144 return (EFI_INVALID_PARAMETER);
1145 }
1146 *FileHandle = &FileInterfaceStdOut;
1147 return (EFI_SUCCESS);
1148 }
1149
1150 //
1151 // Is this for NUL file
1152 //
1153 if (StrCmp(FileName, L"NUL") == 0) {
1154 *FileHandle = &FileInterfaceNulFile;
1155 return (EFI_SUCCESS);
1156 }
1157
1158 //
1159 // Is this for StdErr
1160 //
1161 if (StrCmp(FileName, L">e") == 0) {
1162 //
1163 // make sure not writing to StdIn
1164 //
1165 if ((OpenMode & EFI_FILE_MODE_READ) != 0) {
1166 return (EFI_INVALID_PARAMETER);
1167 }
1168 *FileHandle = &FileInterfaceStdErr;
1169 return (EFI_SUCCESS);
1170 }
1171
1172 //
1173 // Is this for an environment variable
1174 // do we start with >v
1175 //
1176 if (StrStr(FileName, L">v") == FileName) {
1177 if (!IsVolatileEnv(FileName+2) &&
1178 ((OpenMode & EFI_FILE_MODE_WRITE) != 0)) {
1179 return (EFI_INVALID_PARAMETER);
1180 }
1181 *FileHandle = CreateFileInterfaceEnv(FileName+2);
1182 return (EFI_SUCCESS);
1183 }
1184
1185 //
1186 // We are opening a regular file.
1187 //
1188 DevicePath = EfiShellGetDevicePathFromFilePath(FileName);
1189 // DEBUG_CODE(InternalShellProtocolDebugPrintMessage (NULL, DevicePath););
1190 if (DevicePath == NULL) {
1191 return (EFI_NOT_FOUND);
1192 }
1193
1194 //
1195 // Copy the device path, open the file, then free the memory
1196 //
1197 Status = InternalOpenFileDevicePath(DevicePath, FileHandle, OpenMode, 0); // 0 = no specific file attributes
1198 FreePool(DevicePath);
1199
1200 return(Status);
1201 }
1202
1203 /**
1204 Deletes the file specified by the file name.
1205
1206 This function deletes a file.
1207
1208 @param FileName Points to the NULL-terminated file name.
1209
1210 @retval EFI_SUCCESS The file was closed and deleted, and the handle was closed.
1211 @retval EFI_WARN_DELETE_FAILURE The handle was closed but the file was not deleted.
1212 @sa EfiShellCreateFile
1213 **/
1214 EFI_STATUS
1215 EFIAPI
1216 EfiShellDeleteFileByName(
1217 IN CONST CHAR16 *FileName
1218 )
1219 {
1220 SHELL_FILE_HANDLE FileHandle;
1221 EFI_STATUS Status;
1222
1223 //
1224 // get a handle to the file
1225 //
1226 Status = EfiShellCreateFile(FileName,
1227 0,
1228 &FileHandle);
1229 if (EFI_ERROR(Status)) {
1230 return (Status);
1231 }
1232 //
1233 // now delete the file
1234 //
1235 return (ShellInfoObject.NewEfiShellProtocol->DeleteFile(FileHandle));
1236 }
1237
1238 /**
1239 Disables the page break output mode.
1240 **/
1241 VOID
1242 EFIAPI
1243 EfiShellDisablePageBreak (
1244 VOID
1245 )
1246 {
1247 ShellInfoObject.PageBreakEnabled = FALSE;
1248 }
1249
1250 /**
1251 Enables the page break output mode.
1252 **/
1253 VOID
1254 EFIAPI
1255 EfiShellEnablePageBreak (
1256 VOID
1257 )
1258 {
1259 ShellInfoObject.PageBreakEnabled = TRUE;
1260 }
1261
1262 /**
1263 internal worker function to load and run an image via device path.
1264
1265 @param ParentImageHandle A handle of the image that is executing the specified
1266 command line.
1267 @param DevicePath device path of the file to execute
1268 @param CommandLine Points to the NULL-terminated UCS-2 encoded string
1269 containing the command line. If NULL then the command-
1270 line will be empty.
1271 @param Environment Points to a NULL-terminated array of environment
1272 variables with the format 'x=y', where x is the
1273 environment variable name and y is the value. If this
1274 is NULL, then the current shell environment is used.
1275 @param StatusCode Points to the status code returned by the command.
1276
1277 @retval EFI_SUCCESS The command executed successfully. The status code
1278 returned by the command is pointed to by StatusCode.
1279 @retval EFI_INVALID_PARAMETER The parameters are invalid.
1280 @retval EFI_OUT_OF_RESOURCES Out of resources.
1281 @retval EFI_UNSUPPORTED Nested shell invocations are not allowed.
1282 **/
1283 EFI_STATUS
1284 EFIAPI
1285 InternalShellExecuteDevicePath(
1286 IN CONST EFI_HANDLE *ParentImageHandle,
1287 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
1288 IN CONST CHAR16 *CommandLine OPTIONAL,
1289 IN CONST CHAR16 **Environment OPTIONAL,
1290 OUT EFI_STATUS *StatusCode OPTIONAL
1291 )
1292 {
1293 EFI_STATUS Status;
1294 EFI_HANDLE NewHandle;
1295 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
1296 LIST_ENTRY OrigEnvs;
1297 EFI_SHELL_PARAMETERS_PROTOCOL ShellParamsProtocol;
1298
1299 if (ParentImageHandle == NULL) {
1300 return (EFI_INVALID_PARAMETER);
1301 }
1302
1303 InitializeListHead(&OrigEnvs);
1304
1305 NewHandle = NULL;
1306
1307 //
1308 // Load the image with:
1309 // FALSE - not from boot manager and NULL, 0 being not already in memory
1310 //
1311 Status = gBS->LoadImage(
1312 FALSE,
1313 *ParentImageHandle,
1314 (EFI_DEVICE_PATH_PROTOCOL*)DevicePath,
1315 NULL,
1316 0,
1317 &NewHandle);
1318
1319 if (EFI_ERROR(Status)) {
1320 if (NewHandle != NULL) {
1321 gBS->UnloadImage(NewHandle);
1322 }
1323 return (Status);
1324 }
1325 Status = gBS->OpenProtocol(
1326 NewHandle,
1327 &gEfiLoadedImageProtocolGuid,
1328 (VOID**)&LoadedImage,
1329 gImageHandle,
1330 NULL,
1331 EFI_OPEN_PROTOCOL_GET_PROTOCOL);
1332
1333 if (!EFI_ERROR(Status)) {
1334 ASSERT(LoadedImage->LoadOptionsSize == 0);
1335 if (CommandLine != NULL) {
1336 LoadedImage->LoadOptionsSize = (UINT32)StrSize(CommandLine);
1337 LoadedImage->LoadOptions = (VOID*)CommandLine;
1338 }
1339
1340 //
1341 // Save our current environment settings for later restoration if necessary
1342 //
1343 if (Environment != NULL) {
1344 Status = GetEnvironmentVariableList(&OrigEnvs);
1345 if (!EFI_ERROR(Status)) {
1346 Status = SetEnvironmentVariables(Environment);
1347 }
1348 }
1349
1350 //
1351 // Initialize and install a shell parameters protocol on the image.
1352 //
1353 ShellParamsProtocol.StdIn = ShellInfoObject.NewShellParametersProtocol->StdIn;
1354 ShellParamsProtocol.StdOut = ShellInfoObject.NewShellParametersProtocol->StdOut;
1355 ShellParamsProtocol.StdErr = ShellInfoObject.NewShellParametersProtocol->StdErr;
1356 Status = UpdateArgcArgv(&ShellParamsProtocol, CommandLine, NULL, NULL);
1357 ASSERT_EFI_ERROR(Status);
1358 Status = gBS->InstallProtocolInterface(&NewHandle, &gEfiShellParametersProtocolGuid, EFI_NATIVE_INTERFACE, &ShellParamsProtocol);
1359 ASSERT_EFI_ERROR(Status);
1360
1361 ///@todo initialize and install ShellInterface protocol on the new image for compatibility if - PcdGetBool(PcdShellSupportOldProtocols)
1362
1363 //
1364 // now start the image and if the caller wanted the return code pass it to them...
1365 //
1366 if (!EFI_ERROR(Status)) {
1367 if (StatusCode != NULL) {
1368 *StatusCode = gBS->StartImage(NewHandle, NULL, NULL);
1369 } else {
1370 Status = gBS->StartImage(NewHandle, NULL, NULL);
1371 }
1372 }
1373
1374 //
1375 // Cleanup (and dont overwrite errors)
1376 //
1377 if (EFI_ERROR(Status)) {
1378 gBS->UninstallProtocolInterface(NewHandle, &gEfiShellParametersProtocolGuid, &ShellParamsProtocol);
1379 } else {
1380 Status = gBS->UninstallProtocolInterface(NewHandle, &gEfiShellParametersProtocolGuid, &ShellParamsProtocol);
1381 ASSERT_EFI_ERROR(Status);
1382 }
1383 }
1384
1385 if (!IsListEmpty(&OrigEnvs)) {
1386 if (EFI_ERROR(Status)) {
1387 SetEnvironmentVariableList(&OrigEnvs);
1388 } else {
1389 Status = SetEnvironmentVariableList(&OrigEnvs);
1390 }
1391 }
1392
1393 return(Status);
1394 }
1395 /**
1396 Execute the command line.
1397
1398 This function creates a nested instance of the shell and executes the specified
1399 command (CommandLine) with the specified environment (Environment). Upon return,
1400 the status code returned by the specified command is placed in StatusCode.
1401
1402 If Environment is NULL, then the current environment is used and all changes made
1403 by the commands executed will be reflected in the current environment. If the
1404 Environment is non-NULL, then the changes made will be discarded.
1405
1406 The CommandLine is executed from the current working directory on the current
1407 device.
1408
1409 @param ParentImageHandle A handle of the image that is executing the specified
1410 command line.
1411 @param CommandLine Points to the NULL-terminated UCS-2 encoded string
1412 containing the command line. If NULL then the command-
1413 line will be empty.
1414 @param Environment Points to a NULL-terminated array of environment
1415 variables with the format 'x=y', where x is the
1416 environment variable name and y is the value. If this
1417 is NULL, then the current shell environment is used.
1418 @param StatusCode Points to the status code returned by the command.
1419
1420 @retval EFI_SUCCESS The command executed successfully. The status code
1421 returned by the command is pointed to by StatusCode.
1422 @retval EFI_INVALID_PARAMETER The parameters are invalid.
1423 @retval EFI_OUT_OF_RESOURCES Out of resources.
1424 @retval EFI_UNSUPPORTED Nested shell invocations are not allowed.
1425 @retval EFI_UNSUPPORTED The support level required for this function is not present.
1426
1427 @sa InternalShellExecuteDevicePath
1428 **/
1429 EFI_STATUS
1430 EFIAPI
1431 EfiShellExecute(
1432 IN EFI_HANDLE *ParentImageHandle,
1433 IN CHAR16 *CommandLine OPTIONAL,
1434 IN CHAR16 **Environment OPTIONAL,
1435 OUT EFI_STATUS *StatusCode OPTIONAL
1436 )
1437 {
1438 EFI_STATUS Status;
1439 CHAR16 *Temp;
1440 EFI_DEVICE_PATH_PROTOCOL *DevPath;
1441 UINTN Size;
1442
1443 if ((PcdGet8(PcdShellSupportLevel) < 1)) {
1444 return (EFI_UNSUPPORTED);
1445 }
1446
1447 DevPath = AppendDevicePath (ShellInfoObject.ImageDevPath, ShellInfoObject.FileDevPath);
1448
1449 DEBUG_CODE_BEGIN();
1450 Temp = gDevPathToText->ConvertDevicePathToText(ShellInfoObject.FileDevPath, TRUE, TRUE);
1451 FreePool(Temp);
1452 Temp = gDevPathToText->ConvertDevicePathToText(ShellInfoObject.ImageDevPath, TRUE, TRUE);
1453 FreePool(Temp);
1454 Temp = gDevPathToText->ConvertDevicePathToText(DevPath, TRUE, TRUE);
1455 FreePool(Temp);
1456 DEBUG_CODE_END();
1457
1458 Temp = NULL;
1459 Size = 0;
1460 ASSERT((Temp == NULL && Size == 0) || (Temp != NULL));
1461 StrnCatGrow(&Temp, &Size, L"Shell.efi ", 0);
1462 StrnCatGrow(&Temp, &Size, CommandLine, 0);
1463
1464 Status = InternalShellExecuteDevicePath(
1465 ParentImageHandle,
1466 DevPath,
1467 Temp,
1468 (CONST CHAR16**)Environment,
1469 StatusCode);
1470
1471 //
1472 // de-allocate and return
1473 //
1474 FreePool(DevPath);
1475 FreePool(Temp);
1476 return(Status);
1477 }
1478
1479 /**
1480 Utility cleanup function for EFI_SHELL_FILE_INFO objects.
1481
1482 1) frees all pointers (non-NULL)
1483 2) Closes the SHELL_FILE_HANDLE
1484
1485 @param FileListNode pointer to the list node to free
1486 **/
1487 VOID
1488 EFIAPI
1489 InternalFreeShellFileInfoNode(
1490 IN EFI_SHELL_FILE_INFO *FileListNode
1491 )
1492 {
1493 if (FileListNode->Info != NULL) {
1494 FreePool((VOID*)FileListNode->Info);
1495 }
1496 if (FileListNode->FileName != NULL) {
1497 FreePool((VOID*)FileListNode->FileName);
1498 }
1499 if (FileListNode->FullName != NULL) {
1500 FreePool((VOID*)FileListNode->FullName);
1501 }
1502 if (FileListNode->Handle != NULL) {
1503 ShellInfoObject.NewEfiShellProtocol->CloseFile(FileListNode->Handle);
1504 }
1505 FreePool(FileListNode);
1506 }
1507 /**
1508 Frees the file list.
1509
1510 This function cleans up the file list and any related data structures. It has no
1511 impact on the files themselves.
1512
1513 @param FileList The file list to free. Type EFI_SHELL_FILE_INFO is
1514 defined in OpenFileList()
1515
1516 @retval EFI_SUCCESS Free the file list successfully.
1517 @retval EFI_INVALID_PARAMETER FileList was NULL or *FileList was NULL;
1518 **/
1519 EFI_STATUS
1520 EFIAPI
1521 EfiShellFreeFileList(
1522 IN EFI_SHELL_FILE_INFO **FileList
1523 )
1524 {
1525 EFI_SHELL_FILE_INFO *ShellFileListItem;
1526
1527 if (FileList == NULL || *FileList == NULL) {
1528 return (EFI_INVALID_PARAMETER);
1529 }
1530
1531 for ( ShellFileListItem = (EFI_SHELL_FILE_INFO*)GetFirstNode(&(*FileList)->Link)
1532 ; !IsListEmpty(&(*FileList)->Link)
1533 ; ShellFileListItem = (EFI_SHELL_FILE_INFO*)GetFirstNode(&(*FileList)->Link)
1534 ){
1535 RemoveEntryList(&ShellFileListItem->Link);
1536 InternalFreeShellFileInfoNode(ShellFileListItem);
1537 }
1538 return(EFI_SUCCESS);
1539 }
1540
1541 /**
1542 Deletes the duplicate file names files in the given file list.
1543
1544 This function deletes the reduplicate files in the given file list.
1545
1546 @param FileList A pointer to the first entry in the file list.
1547
1548 @retval EFI_SUCCESS Always success.
1549 @retval EFI_INVALID_PARAMETER FileList was NULL or *FileList was NULL;
1550 **/
1551 EFI_STATUS
1552 EFIAPI
1553 EfiShellRemoveDupInFileList(
1554 IN EFI_SHELL_FILE_INFO **FileList
1555 )
1556 {
1557 EFI_SHELL_FILE_INFO *ShellFileListItem;
1558 EFI_SHELL_FILE_INFO *ShellFileListItem2;
1559
1560 if (FileList == NULL || *FileList == NULL) {
1561 return (EFI_INVALID_PARAMETER);
1562 }
1563 for ( ShellFileListItem = (EFI_SHELL_FILE_INFO*)GetFirstNode(&(*FileList)->Link)
1564 ; !IsNull(&(*FileList)->Link, &ShellFileListItem->Link)
1565 ; ShellFileListItem = (EFI_SHELL_FILE_INFO*)GetNextNode(&(*FileList)->Link, &ShellFileListItem->Link)
1566 ){
1567 for ( ShellFileListItem2 = (EFI_SHELL_FILE_INFO*)GetNextNode(&(*FileList)->Link, &ShellFileListItem->Link)
1568 ; !IsNull(&(*FileList)->Link, &ShellFileListItem2->Link)
1569 ; ShellFileListItem2 = (EFI_SHELL_FILE_INFO*)GetNextNode(&(*FileList)->Link, &ShellFileListItem2->Link)
1570 ){
1571 if (gUnicodeCollation->StriColl(
1572 gUnicodeCollation,
1573 (CHAR16*)ShellFileListItem->FullName,
1574 (CHAR16*)ShellFileListItem2->FullName) == 0
1575 ){
1576 RemoveEntryList(&ShellFileListItem2->Link);
1577 InternalFreeShellFileInfoNode(ShellFileListItem2);
1578 }
1579 }
1580 }
1581 return (EFI_SUCCESS);
1582 }
1583 /**
1584 Allocates and duplicates a EFI_SHELL_FILE_INFO node.
1585
1586 @param[in] Node The node to copy from.
1587 @param[in] Save TRUE to set Node->Handle to NULL, FALSE otherwise.
1588
1589 @retval NULL a memory allocation error ocurred
1590 @return != NULL a pointer to the new node
1591 **/
1592 EFI_SHELL_FILE_INFO*
1593 EFIAPI
1594 InternalDuplicateShellFileInfo(
1595 IN EFI_SHELL_FILE_INFO *Node,
1596 IN BOOLEAN Save
1597 )
1598 {
1599 EFI_SHELL_FILE_INFO *NewNode;
1600
1601 NewNode = AllocatePool(sizeof(EFI_SHELL_FILE_INFO));
1602 if (NewNode == NULL) {
1603 return (NULL);
1604 }
1605 NewNode->FullName = AllocateZeroPool(StrSize(Node->FullName));
1606
1607 NewNode->FileName = AllocateZeroPool(StrSize(Node->FileName));
1608 NewNode->Info = AllocatePool((UINTN)Node->Info->Size);
1609 if ( NewNode->FullName == NULL
1610 || NewNode->FileName == NULL
1611 || NewNode->Info == NULL
1612 ){
1613 return(NULL);
1614 }
1615 NewNode->Status = Node->Status;
1616 NewNode->Handle = Node->Handle;
1617 if (!Save) {
1618 Node->Handle = NULL;
1619 }
1620 StrCpy((CHAR16*)NewNode->FullName, Node->FullName);
1621 StrCpy((CHAR16*)NewNode->FileName, Node->FileName);
1622 CopyMem(NewNode->Info, Node->Info, (UINTN)Node->Info->Size);
1623
1624 return(NewNode);
1625 }
1626
1627 /**
1628 Allocates and populates a EFI_SHELL_FILE_INFO structure. if any memory operation
1629 failed it will return NULL.
1630
1631 @param[in] BasePath the Path to prepend onto filename for FullPath
1632 @param[in] Status Status member initial value.
1633 @param[in] FullName FullName member initial value.
1634 @param[in] FileName FileName member initial value.
1635 @param[in] Handle Handle member initial value.
1636 @param[in] Info Info struct to copy.
1637
1638 @retval NULL An error ocurred.
1639 @return a pointer to the newly allocated structure.
1640 **/
1641 EFI_SHELL_FILE_INFO *
1642 EFIAPI
1643 CreateAndPopulateShellFileInfo(
1644 IN CONST CHAR16 *BasePath,
1645 IN CONST EFI_STATUS Status,
1646 IN CONST CHAR16 *FullName,
1647 IN CONST CHAR16 *FileName,
1648 IN CONST SHELL_FILE_HANDLE Handle,
1649 IN CONST EFI_FILE_INFO *Info
1650 )
1651 {
1652 EFI_SHELL_FILE_INFO *ShellFileListItem;
1653 CHAR16 *TempString;
1654 UINTN Size;
1655
1656 TempString = NULL;
1657 Size = 0;
1658
1659 ShellFileListItem = AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));
1660 if (ShellFileListItem == NULL) {
1661 return (NULL);
1662 }
1663 if (Info != NULL) {
1664 ShellFileListItem->Info = AllocateZeroPool((UINTN)Info->Size);
1665 if (ShellFileListItem->Info == NULL) {
1666 FreePool(ShellFileListItem);
1667 return (NULL);
1668 }
1669 CopyMem(ShellFileListItem->Info, Info, (UINTN)Info->Size);
1670 } else {
1671 ShellFileListItem->Info = NULL;
1672 }
1673 if (FileName != NULL) {
1674 ASSERT(TempString == NULL);
1675 ShellFileListItem->FileName = StrnCatGrow(&TempString, 0, FileName, 0);
1676 if (ShellFileListItem->FileName == NULL) {
1677 FreePool(ShellFileListItem->Info);
1678 FreePool(ShellFileListItem);
1679 return (NULL);
1680 }
1681 } else {
1682 ShellFileListItem->FileName = NULL;
1683 }
1684 Size = 0;
1685 TempString = NULL;
1686 if (BasePath != NULL) {
1687 ASSERT((TempString == NULL && Size == 0) || (TempString != NULL));
1688 TempString = StrnCatGrow(&TempString, &Size, BasePath, 0);
1689 if (TempString == NULL) {
1690 FreePool((VOID*)ShellFileListItem->FileName);
1691 FreePool(ShellFileListItem->Info);
1692 FreePool(ShellFileListItem);
1693 return (NULL);
1694 }
1695 }
1696 if (ShellFileListItem->FileName != NULL) {
1697 ASSERT((TempString == NULL && Size == 0) || (TempString != NULL));
1698 TempString = StrnCatGrow(&TempString, &Size, ShellFileListItem->FileName, 0);
1699 if (TempString == NULL) {
1700 FreePool((VOID*)ShellFileListItem->FileName);
1701 FreePool(ShellFileListItem->Info);
1702 FreePool(ShellFileListItem);
1703 return (NULL);
1704 }
1705 }
1706
1707 ShellFileListItem->FullName = TempString;
1708 ShellFileListItem->Status = Status;
1709 ShellFileListItem->Handle = Handle;
1710
1711 return (ShellFileListItem);
1712 }
1713
1714 /**
1715 Find all files in a specified directory.
1716
1717 @param FileDirHandle Handle of the directory to search.
1718 @param FileList On return, points to the list of files in the directory
1719 or NULL if there are no files in the directory.
1720
1721 @retval EFI_SUCCESS File information was returned successfully.
1722 @retval EFI_VOLUME_CORRUPTED The file system structures have been corrupted.
1723 @retval EFI_DEVICE_ERROR The device reported an error.
1724 @retval EFI_NO_MEDIA The device media is not present.
1725 @retval EFI_INVALID_PARAMETER The FileDirHandle was not a directory.
1726 @return An error from FileHandleGetFileName().
1727 **/
1728 EFI_STATUS
1729 EFIAPI
1730 EfiShellFindFilesInDir(
1731 IN SHELL_FILE_HANDLE FileDirHandle,
1732 OUT EFI_SHELL_FILE_INFO **FileList
1733 )
1734 {
1735 EFI_SHELL_FILE_INFO *ShellFileList;
1736 EFI_SHELL_FILE_INFO *ShellFileListItem;
1737 EFI_FILE_INFO *FileInfo;
1738 EFI_STATUS Status;
1739 BOOLEAN NoFile;
1740 CHAR16 *TempString;
1741 CHAR16 *BasePath;
1742 UINTN Size;
1743 CHAR16 *TempSpot;
1744
1745 Status = FileHandleGetFileName(FileDirHandle, &BasePath);
1746 if (EFI_ERROR(Status)) {
1747 return (Status);
1748 }
1749
1750 if (ShellFileHandleGetPath(FileDirHandle) != NULL) {
1751 TempString = NULL;
1752 Size = 0;
1753 TempString = StrnCatGrow(&TempString, &Size, ShellFileHandleGetPath(FileDirHandle), 0);
1754 TempSpot = StrStr(TempString, L";");
1755
1756 if (TempSpot != NULL) {
1757 *TempSpot = CHAR_NULL;
1758 }
1759
1760 TempString = StrnCatGrow(&TempString, &Size, BasePath, 0);
1761 BasePath = TempString;
1762 }
1763
1764 NoFile = FALSE;
1765 ShellFileList = NULL;
1766 ShellFileListItem = NULL;
1767 FileInfo = NULL;
1768 Status = EFI_SUCCESS;
1769
1770
1771 for ( Status = FileHandleFindFirstFile(FileDirHandle, &FileInfo)
1772 ; !EFI_ERROR(Status) && !NoFile
1773 ; Status = FileHandleFindNextFile(FileDirHandle, FileInfo, &NoFile)
1774 ){
1775 TempString = NULL;
1776 Size = 0;
1777 //
1778 // allocate a new EFI_SHELL_FILE_INFO and populate it...
1779 //
1780 ASSERT((TempString == NULL && Size == 0) || (TempString != NULL));
1781 TempString = StrnCatGrow(&TempString, &Size, BasePath, 0);
1782 TempString = StrnCatGrow(&TempString, &Size, FileInfo->FileName, 0);
1783 ShellFileListItem = CreateAndPopulateShellFileInfo(
1784 BasePath,
1785 EFI_SUCCESS, // success since we didnt fail to open it...
1786 TempString,
1787 FileInfo->FileName,
1788 NULL, // no handle since not open
1789 FileInfo);
1790
1791 if (ShellFileList == NULL) {
1792 ShellFileList = (EFI_SHELL_FILE_INFO*)AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));
1793 ASSERT(ShellFileList != NULL);
1794 InitializeListHead(&ShellFileList->Link);
1795 }
1796 InsertTailList(&ShellFileList->Link, &ShellFileListItem->Link);
1797 }
1798 if (EFI_ERROR(Status)) {
1799 EfiShellFreeFileList(&ShellFileList);
1800 *FileList = NULL;
1801 } else {
1802 *FileList = ShellFileList;
1803 }
1804 SHELL_FREE_NON_NULL(BasePath);
1805 return(Status);
1806 }
1807
1808 /**
1809 Updates a file name to be preceeded by the mapped drive name
1810
1811 @param[in] BasePath the Mapped drive name to prepend
1812 @param[in,out] Path pointer to pointer to the file name to update.
1813
1814 @retval EFI_SUCCESS
1815 @retval EFI_OUT_OF_RESOURCES
1816 **/
1817 EFI_STATUS
1818 EFIAPI
1819 UpdateFileName(
1820 IN CONST CHAR16 *BasePath,
1821 IN OUT CHAR16 **Path
1822 )
1823 {
1824 CHAR16 *Path2;
1825 UINTN Path2Size;
1826
1827 Path2Size = 0;
1828 Path2 = NULL;
1829
1830 ASSERT(Path != NULL);
1831 ASSERT(*Path != NULL);
1832 ASSERT(BasePath != NULL);
1833
1834 //
1835 // convert a local path to an absolute path
1836 //
1837 if (StrStr(*Path, L":") == NULL) {
1838 ASSERT((Path2 == NULL && Path2Size == 0) || (Path2 != NULL));
1839 StrnCatGrow(&Path2, &Path2Size, BasePath, 0);
1840 if (Path2 == NULL) {
1841 return (EFI_OUT_OF_RESOURCES);
1842 }
1843 ASSERT((Path2 == NULL && Path2Size == 0) || (Path2 != NULL));
1844 StrnCatGrow(&Path2, &Path2Size, (*Path)[0] == L'\\'?(*Path) + 1 :*Path, 0);
1845 if (Path2 == NULL) {
1846 return (EFI_OUT_OF_RESOURCES);
1847 }
1848 }
1849
1850 FreePool(*Path);
1851 (*Path) = Path2;
1852
1853 return (EFI_SUCCESS);
1854 }
1855
1856 /**
1857 If FileHandle is a directory then the function reads from FileHandle and reads in
1858 each of the FileInfo structures. If one of them matches the Pattern's first
1859 "level" then it opens that handle and calls itself on that handle.
1860
1861 If FileHandle is a file and matches all of the remaining Pattern (which would be
1862 on its last node), then add a EFI_SHELL_FILE_INFO object for this file to fileList.
1863
1864 if FileList is NULL, then ASSERT
1865 if FilePattern is NULL, then ASSERT
1866 if UnicodeCollation is NULL, then ASSERT
1867 if FileHandle is NULL, then ASSERT
1868
1869 Upon a EFI_SUCCESS return fromt he function any the caller is responsible to call
1870 FreeFileList with FileList.
1871
1872 @param[in] FilePattern The FilePattern to check against.
1873 @param[in] UnicodeCollation The pointer to EFI_UNICODE_COLLATION_PROTOCOL structure
1874 @param[in] FileHandle The FileHandle to start with
1875 @param[in,out] FileList pointer to pointer to list of found files.
1876 @param[in] ParentNode The node for the parent. Same file as identified by HANDLE.
1877
1878 @retval EFI_SUCCESS all files were found and the FileList contains a list.
1879 @retval EFI_NOT_FOUND no files were found
1880 @retval EFI_OUT_OF_RESOURCES a memory allocation failed
1881 **/
1882 EFI_STATUS
1883 EFIAPI
1884 ShellSearchHandle(
1885 IN CONST CHAR16 *FilePattern,
1886 IN EFI_UNICODE_COLLATION_PROTOCOL *UnicodeCollation,
1887 IN SHELL_FILE_HANDLE FileHandle,
1888 IN OUT EFI_SHELL_FILE_INFO **FileList,
1889 IN CONST EFI_SHELL_FILE_INFO *ParentNode OPTIONAL
1890 )
1891 {
1892 EFI_STATUS Status;
1893 CONST CHAR16 *NextFilePatternStart;
1894 CHAR16 *CurrentFilePattern;
1895 EFI_SHELL_FILE_INFO *ShellInfo;
1896 EFI_SHELL_FILE_INFO *ShellInfoNode;
1897 EFI_SHELL_FILE_INFO *NewShellNode;
1898 BOOLEAN Directory;
1899
1900 if ( FilePattern == NULL
1901 || UnicodeCollation == NULL
1902 || FileList == NULL
1903 ){
1904 return (EFI_INVALID_PARAMETER);
1905 }
1906 ShellInfo = NULL;
1907 CurrentFilePattern = NULL;
1908
1909 if (*FilePattern == L'\\') {
1910 FilePattern++;
1911 }
1912
1913 for( NextFilePatternStart = FilePattern
1914 ; *NextFilePatternStart != CHAR_NULL && *NextFilePatternStart != L'\\'
1915 ; NextFilePatternStart++);
1916
1917 CurrentFilePattern = AllocateZeroPool((NextFilePatternStart-FilePattern+1)*sizeof(CHAR16));
1918 ASSERT(CurrentFilePattern != NULL);
1919 StrnCpy(CurrentFilePattern, FilePattern, NextFilePatternStart-FilePattern);
1920
1921 if (CurrentFilePattern[0] == CHAR_NULL
1922 &&NextFilePatternStart[0] == CHAR_NULL
1923 ){
1924 //
1925 // Add the current parameter FileHandle to the list, then end...
1926 //
1927 if (ParentNode == NULL) {
1928 Status = EFI_INVALID_PARAMETER;
1929 } else {
1930 NewShellNode = InternalDuplicateShellFileInfo((EFI_SHELL_FILE_INFO*)ParentNode, TRUE);
1931 if (NewShellNode == NULL) {
1932 Status = EFI_OUT_OF_RESOURCES;
1933 } else {
1934 NewShellNode->Handle = NULL;
1935 if (*FileList == NULL) {
1936 *FileList = AllocatePool(sizeof(EFI_SHELL_FILE_INFO));
1937 InitializeListHead(&((*FileList)->Link));
1938 }
1939
1940 //
1941 // Add to the returning to use list
1942 //
1943 InsertTailList(&(*FileList)->Link, &NewShellNode->Link);
1944
1945 Status = EFI_SUCCESS;
1946 }
1947 }
1948 } else {
1949 Status = EfiShellFindFilesInDir(FileHandle, &ShellInfo);
1950
1951 if (!EFI_ERROR(Status)){
1952 if (StrStr(NextFilePatternStart, L"\\") != NULL){
1953 Directory = TRUE;
1954 } else {
1955 Directory = FALSE;
1956 }
1957 for ( ShellInfoNode = (EFI_SHELL_FILE_INFO*)GetFirstNode(&ShellInfo->Link)
1958 ; !IsNull (&ShellInfo->Link, &ShellInfoNode->Link)
1959 ; ShellInfoNode = (EFI_SHELL_FILE_INFO*)GetNextNode(&ShellInfo->Link, &ShellInfoNode->Link)
1960 ){
1961 if (UnicodeCollation->MetaiMatch(UnicodeCollation, (CHAR16*)ShellInfoNode->FileName, CurrentFilePattern)){
1962 if (Directory){
1963 //
1964 // should be a directory
1965 //
1966
1967 //
1968 // don't open the . and .. directories
1969 //
1970 if ( (StrCmp(ShellInfoNode->FileName, L".") != 0)
1971 && (StrCmp(ShellInfoNode->FileName, L"..") != 0)
1972 ){
1973 //
1974 //
1975 //
1976 ASSERT_EFI_ERROR(Status);
1977 if (EFI_ERROR(Status)) {
1978 break;
1979 }
1980 //
1981 // Open the directory since we need that handle in the next recursion.
1982 //
1983 ShellInfoNode->Status = EfiShellOpenFileByName (ShellInfoNode->FullName, &ShellInfoNode->Handle, EFI_FILE_MODE_READ);
1984
1985 //
1986 // recurse with the next part of the pattern
1987 //
1988 Status = ShellSearchHandle(NextFilePatternStart, UnicodeCollation, ShellInfoNode->Handle, FileList, ShellInfoNode);
1989 }
1990 } else {
1991 //
1992 // should be a file
1993 //
1994
1995 //
1996 // copy the information we need into a new Node
1997 //
1998 NewShellNode = InternalDuplicateShellFileInfo(ShellInfoNode, FALSE);
1999 ASSERT(NewShellNode != NULL);
2000 if (NewShellNode == NULL) {
2001 Status = EFI_OUT_OF_RESOURCES;
2002 }
2003 if (*FileList == NULL) {
2004 *FileList = AllocatePool(sizeof(EFI_SHELL_FILE_INFO));
2005 InitializeListHead(&((*FileList)->Link));
2006 }
2007
2008 //
2009 // Add to the returning to use list
2010 //
2011 InsertTailList(&(*FileList)->Link, &NewShellNode->Link);
2012 }
2013 }
2014 if (EFI_ERROR(Status)) {
2015 break;
2016 }
2017 }
2018 if (EFI_ERROR(Status)) {
2019 EfiShellFreeFileList(&ShellInfo);
2020 } else {
2021 Status = EfiShellFreeFileList(&ShellInfo);
2022 }
2023 }
2024 }
2025
2026 FreePool(CurrentFilePattern);
2027 return (Status);
2028 }
2029
2030 /**
2031 Find files that match a specified pattern.
2032
2033 This function searches for all files and directories that match the specified
2034 FilePattern. The FilePattern can contain wild-card characters. The resulting file
2035 information is placed in the file list FileList.
2036
2037 Wildcards are processed
2038 according to the rules specified in UEFI Shell 2.0 spec section 3.7.1.
2039
2040 The files in the file list are not opened. The OpenMode field is set to 0 and the FileInfo
2041 field is set to NULL.
2042
2043 if *FileList is not NULL then it must be a pre-existing and properly initialized list.
2044
2045 @param FilePattern Points to a NULL-terminated shell file path, including wildcards.
2046 @param FileList On return, points to the start of a file list containing the names
2047 of all matching files or else points to NULL if no matching files
2048 were found. only on a EFI_SUCCESS return will; this be non-NULL.
2049
2050 @retval EFI_SUCCESS Files found. FileList is a valid list.
2051 @retval EFI_NOT_FOUND No files found.
2052 @retval EFI_NO_MEDIA The device has no media
2053 @retval EFI_DEVICE_ERROR The device reported an error
2054 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted
2055 **/
2056 EFI_STATUS
2057 EFIAPI
2058 EfiShellFindFiles(
2059 IN CONST CHAR16 *FilePattern,
2060 OUT EFI_SHELL_FILE_INFO **FileList
2061 )
2062 {
2063 EFI_STATUS Status;
2064 CHAR16 *PatternCopy;
2065 CHAR16 *PatternCurrentLocation;
2066 EFI_DEVICE_PATH_PROTOCOL *RootDevicePath;
2067 SHELL_FILE_HANDLE RootFileHandle;
2068 CHAR16 *MapName;
2069 UINTN Count;
2070
2071 if ( FilePattern == NULL
2072 || FileList == NULL
2073 || StrStr(FilePattern, L":") == NULL
2074 ){
2075 return (EFI_INVALID_PARAMETER);
2076 }
2077 Status = EFI_SUCCESS;
2078 RootDevicePath = NULL;
2079 RootFileHandle = NULL;
2080 MapName = NULL;
2081 PatternCopy = AllocatePool(StrSize(FilePattern));
2082 if (PatternCopy == NULL) {
2083 return (EFI_OUT_OF_RESOURCES);
2084 }
2085 StrCpy(PatternCopy, FilePattern);
2086
2087 PatternCopy = CleanPath(PatternCopy);
2088
2089 Count = StrStr(PatternCopy, L":") - PatternCopy;
2090 Count += 2;
2091
2092 ASSERT(MapName == NULL);
2093 MapName = StrnCatGrow(&MapName, NULL, PatternCopy, Count);
2094
2095 if (!EFI_ERROR(Status)) {
2096 RootDevicePath = EfiShellGetDevicePathFromFilePath(PatternCopy);
2097 if (RootDevicePath == NULL) {
2098 Status = EFI_INVALID_PARAMETER;
2099 } else {
2100 Status = EfiShellOpenRoot(RootDevicePath, &RootFileHandle);
2101 if (!EFI_ERROR(Status)) {
2102 for ( PatternCurrentLocation = PatternCopy
2103 ; *PatternCurrentLocation != ':'
2104 ; PatternCurrentLocation++);
2105 PatternCurrentLocation++;
2106 Status = ShellSearchHandle(PatternCurrentLocation, gUnicodeCollation, RootFileHandle, FileList, NULL);
2107 }
2108 FreePool(RootDevicePath);
2109 }
2110 }
2111
2112 if (PatternCopy != NULL) {
2113 FreePool(PatternCopy);
2114 }
2115 if (MapName != NULL) {
2116 FreePool(MapName);
2117 }
2118
2119 return(Status);
2120 }
2121
2122 /**
2123 Opens the files that match the path specified.
2124
2125 This function opens all of the files specified by Path. Wildcards are processed
2126 according to the rules specified in UEFI Shell 2.0 spec section 3.7.1. Each
2127 matching file has an EFI_SHELL_FILE_INFO structure created in a linked list.
2128
2129 @param Path A pointer to the path string.
2130 @param OpenMode Specifies the mode used to open each file, EFI_FILE_MODE_READ or
2131 EFI_FILE_MODE_WRITE.
2132 @param FileList Points to the start of a list of files opened.
2133
2134 @retval EFI_SUCCESS Create the file list successfully.
2135 @return Others Can't create the file list.
2136 **/
2137 EFI_STATUS
2138 EFIAPI
2139 EfiShellOpenFileList(
2140 IN CHAR16 *Path,
2141 IN UINT64 OpenMode,
2142 IN OUT EFI_SHELL_FILE_INFO **FileList
2143 )
2144 {
2145 EFI_STATUS Status;
2146 EFI_SHELL_FILE_INFO *ShellFileListItem;
2147 CHAR16 *Path2;
2148 UINTN Path2Size;
2149 CONST CHAR16 *CurDir;
2150
2151 ShellCommandCleanPath(Path);
2152
2153 Path2Size = 0;
2154 Path2 = NULL;
2155
2156 ASSERT(FileList != NULL);
2157 ASSERT(*FileList != NULL);
2158
2159 if (*Path == L'.' && *(Path+1) == L'\\') {
2160 Path++;
2161 }
2162
2163 //
2164 // convert a local path to an absolute path
2165 //
2166 if (StrStr(Path, L":") == NULL) {
2167 CurDir = EfiShellGetCurDir(NULL);
2168 ASSERT((Path2 == NULL && Path2Size == 0) || (Path2 != NULL));
2169 StrnCatGrow(&Path2, &Path2Size, CurDir, 0);
2170 if (*Path == L'\\') {
2171 Path++;
2172 }
2173 ASSERT((Path2 == NULL && Path2Size == 0) || (Path2 != NULL));
2174 StrnCatGrow(&Path2, &Path2Size, Path, 0);
2175 } else {
2176 ASSERT(Path2 == NULL);
2177 StrnCatGrow(&Path2, NULL, Path, 0);
2178 }
2179
2180 CleanPath (Path2);
2181
2182 //
2183 // do the search
2184 //
2185 Status = EfiShellFindFiles(Path2, FileList);
2186
2187 FreePool(Path2);
2188
2189 if (EFI_ERROR(Status)) {
2190 return (Status);
2191 }
2192
2193 //
2194 // We had no errors so open all the files (that are not already opened...)
2195 //
2196 for ( ShellFileListItem = (EFI_SHELL_FILE_INFO*)GetFirstNode(&(*FileList)->Link)
2197 ; !IsNull(&(*FileList)->Link, &ShellFileListItem->Link)
2198 ; ShellFileListItem = (EFI_SHELL_FILE_INFO*)GetNextNode(&(*FileList)->Link, &ShellFileListItem->Link)
2199 ){
2200 if (ShellFileListItem->Status == 0 && ShellFileListItem->Handle == NULL) {
2201 ShellFileListItem->Status = EfiShellOpenFileByName (ShellFileListItem->FullName, &ShellFileListItem->Handle, OpenMode);
2202 }
2203 }
2204
2205 return(EFI_SUCCESS);
2206 }
2207
2208 /**
2209 This function updated with errata.
2210
2211 Gets either a single or list of environment variables.
2212
2213 If name is not NULL then this function returns the current value of the specified
2214 environment variable.
2215
2216 If Name is NULL, then a list of all environment variable names is returned. Each is a
2217 NULL terminated string with a double NULL terminating the list.
2218
2219 @param Name A pointer to the environment variable name. If
2220 Name is NULL, then the function will return all
2221 of the defined shell environment variables. In
2222 the case where multiple environment variables are
2223 being returned, each variable will be terminated by
2224 a NULL, and the list will be terminated by a double
2225 NULL.
2226
2227 @return !=NULL A pointer to the returned string.
2228 The returned pointer does not need to be freed by the caller.
2229
2230 @retval NULL The environment variable doesn't exist or there are
2231 no environment variables.
2232 **/
2233 CONST CHAR16 *
2234 EFIAPI
2235 EfiShellGetEnv(
2236 IN CONST CHAR16 *Name
2237 )
2238 {
2239 EFI_STATUS Status;
2240 VOID *Buffer;
2241 UINTN Size;
2242 LIST_ENTRY List;
2243 ENV_VAR_LIST *Node;
2244 CHAR16 *CurrentWriteLocation;
2245
2246 Size = 0;
2247 Buffer = NULL;
2248
2249 if (Name == NULL) {
2250 //
2251 // Get all our environment variables
2252 //
2253 InitializeListHead(&List);
2254 Status = GetEnvironmentVariableList(&List);
2255 if (EFI_ERROR(Status)){
2256 return (NULL);
2257 }
2258
2259 //
2260 // Build the semi-colon delimited list. (2 passes)
2261 //
2262 for ( Node = (ENV_VAR_LIST*)GetFirstNode(&List)
2263 ; !IsNull(&List, &Node->Link)
2264 ; Node = (ENV_VAR_LIST*)GetNextNode(&List, &Node->Link)
2265 ){
2266 ASSERT(Node->Key != NULL);
2267 Size += StrSize(Node->Key);
2268 }
2269
2270 Size += 2*sizeof(CHAR16);
2271
2272 Buffer = AllocateZeroPool(Size);
2273 CurrentWriteLocation = (CHAR16*)Buffer;
2274
2275 for ( Node = (ENV_VAR_LIST*)GetFirstNode(&List)
2276 ; !IsNull(&List, &Node->Link)
2277 ; Node = (ENV_VAR_LIST*)GetNextNode(&List, &Node->Link)
2278 ){
2279 ASSERT(Node->Key != NULL);
2280 StrCpy(CurrentWriteLocation, Node->Key);
2281 CurrentWriteLocation += StrLen(CurrentWriteLocation) + 1;
2282 }
2283
2284 //
2285 // Free the list...
2286 //
2287 FreeEnvironmentVariableList(&List);
2288 } else {
2289 //
2290 // We are doing a specific environment variable
2291 //
2292
2293 //
2294 // get the size we need for this EnvVariable
2295 //
2296 Status = SHELL_GET_ENVIRONMENT_VARIABLE(Name, &Size, Buffer);
2297 if (Status == EFI_BUFFER_TOO_SMALL) {
2298 //
2299 // Allocate the space and recall the get function
2300 //
2301 Buffer = AllocateZeroPool(Size);
2302 ASSERT(Buffer != NULL);
2303 Status = SHELL_GET_ENVIRONMENT_VARIABLE(Name, &Size, Buffer);
2304 }
2305 //
2306 // we didnt get it (might not exist)
2307 // free the memory if we allocated any and return NULL
2308 //
2309 if (EFI_ERROR(Status)) {
2310 if (Buffer != NULL) {
2311 FreePool(Buffer);
2312 }
2313 return (NULL);
2314 }
2315 }
2316
2317 //
2318 // return the buffer
2319 //
2320 return (AddBufferToFreeList(Buffer));
2321 }
2322
2323 /**
2324 Internal variable setting function. Allows for setting of the read only variables.
2325
2326 @param Name Points to the NULL-terminated environment variable name.
2327 @param Value Points to the NULL-terminated environment variable value. If the value is an
2328 empty string then the environment variable is deleted.
2329 @param Volatile Indicates whether the variable is non-volatile (FALSE) or volatile (TRUE).
2330
2331 @retval EFI_SUCCESS The environment variable was successfully updated.
2332 **/
2333 EFI_STATUS
2334 EFIAPI
2335 InternalEfiShellSetEnv(
2336 IN CONST CHAR16 *Name,
2337 IN CONST CHAR16 *Value,
2338 IN BOOLEAN Volatile
2339 )
2340 {
2341 if (Value == NULL || StrLen(Value) == 0) {
2342 return (SHELL_DELETE_ENVIRONMENT_VARIABLE(Name));
2343 } else {
2344 SHELL_DELETE_ENVIRONMENT_VARIABLE(Name);
2345 if (Volatile) {
2346 return (SHELL_SET_ENVIRONMENT_VARIABLE_V(Name, StrSize(Value), Value));
2347 } else {
2348 return (SHELL_SET_ENVIRONMENT_VARIABLE_NV(Name, StrSize(Value), Value));
2349 }
2350 }
2351 }
2352
2353 /**
2354 Sets the environment variable.
2355
2356 This function changes the current value of the specified environment variable. If the
2357 environment variable exists and the Value is an empty string, then the environment
2358 variable is deleted. If the environment variable exists and the Value is not an empty
2359 string, then the value of the environment variable is changed. If the environment
2360 variable does not exist and the Value is an empty string, there is no action. If the
2361 environment variable does not exist and the Value is a non-empty string, then the
2362 environment variable is created and assigned the specified value.
2363
2364 For a description of volatile and non-volatile environment variables, see UEFI Shell
2365 2.0 specification section 3.6.1.
2366
2367 @param Name Points to the NULL-terminated environment variable name.
2368 @param Value Points to the NULL-terminated environment variable value. If the value is an
2369 empty string then the environment variable is deleted.
2370 @param Volatile Indicates whether the variable is non-volatile (FALSE) or volatile (TRUE).
2371
2372 @retval EFI_SUCCESS The environment variable was successfully updated.
2373 **/
2374 EFI_STATUS
2375 EFIAPI
2376 EfiShellSetEnv(
2377 IN CONST CHAR16 *Name,
2378 IN CONST CHAR16 *Value,
2379 IN BOOLEAN Volatile
2380 )
2381 {
2382 if (Name == NULL || *Name == CHAR_NULL) {
2383 return (EFI_INVALID_PARAMETER);
2384 }
2385 //
2386 // Make sure we dont 'set' a predefined read only variable
2387 //
2388 if (gUnicodeCollation->StriColl(
2389 gUnicodeCollation,
2390 (CHAR16*)Name,
2391 L"cwd") == 0
2392 ||gUnicodeCollation->StriColl(
2393 gUnicodeCollation,
2394 (CHAR16*)Name,
2395 L"Lasterror") == 0
2396 ||gUnicodeCollation->StriColl(
2397 gUnicodeCollation,
2398 (CHAR16*)Name,
2399 L"profiles") == 0
2400 ||gUnicodeCollation->StriColl(
2401 gUnicodeCollation,
2402 (CHAR16*)Name,
2403 L"uefishellsupport") == 0
2404 ||gUnicodeCollation->StriColl(
2405 gUnicodeCollation,
2406 (CHAR16*)Name,
2407 L"uefishellversion") == 0
2408 ||gUnicodeCollation->StriColl(
2409 gUnicodeCollation,
2410 (CHAR16*)Name,
2411 L"uefiversion") == 0
2412 ){
2413 return (EFI_INVALID_PARAMETER);
2414 }
2415 return (InternalEfiShellSetEnv(Name, Value, Volatile));
2416 }
2417
2418 /**
2419 Returns the current directory on the specified device.
2420
2421 If FileSystemMapping is NULL, it returns the current working directory. If the
2422 FileSystemMapping is not NULL, it returns the current directory associated with the
2423 FileSystemMapping. In both cases, the returned name includes the file system
2424 mapping (i.e. fs0:\current-dir).
2425
2426 @param FileSystemMapping A pointer to the file system mapping. If NULL,
2427 then the current working directory is returned.
2428
2429 @retval !=NULL The current directory.
2430 @retval NULL Current directory does not exist.
2431 **/
2432 CONST CHAR16 *
2433 EFIAPI
2434 EfiShellGetCurDir(
2435 IN CONST CHAR16 *FileSystemMapping OPTIONAL
2436 )
2437 {
2438 CHAR16 *PathToReturn;
2439 UINTN Size;
2440 SHELL_MAP_LIST *MapListItem;
2441 if (!IsListEmpty(&gShellMapList.Link)) {
2442 //
2443 // if parameter is NULL, use current
2444 //
2445 if (FileSystemMapping == NULL) {
2446 return (EfiShellGetEnv(L"cwd"));
2447 } else {
2448 Size = 0;
2449 PathToReturn = NULL;
2450 MapListItem = ShellCommandFindMapItem(FileSystemMapping);
2451 if (MapListItem != NULL) {
2452 ASSERT((PathToReturn == NULL && Size == 0) || (PathToReturn != NULL));
2453 PathToReturn = StrnCatGrow(&PathToReturn, &Size, MapListItem->MapName, 0);
2454 PathToReturn = StrnCatGrow(&PathToReturn, &Size, MapListItem->CurrentDirectoryPath, 0);
2455 }
2456 }
2457 return (AddBufferToFreeList(PathToReturn));
2458 } else {
2459 return (NULL);
2460 }
2461 }
2462
2463 /**
2464 Changes the current directory on the specified device.
2465
2466 If the FileSystem is NULL, and the directory Dir does not contain a file system's
2467 mapped name, this function changes the current working directory.
2468
2469 If the FileSystem is NULL and the directory Dir contains a mapped name, then the
2470 current file system and the current directory on that file system are changed.
2471
2472 If FileSystem is NULL, and Dir is not NULL, then this changes the current working file
2473 system.
2474
2475 If FileSystem is not NULL and Dir is not NULL, then this function changes the current
2476 directory on the specified file system.
2477
2478 If the current working directory or the current working file system is changed then the
2479 %cwd% environment variable will be updated
2480
2481 @param FileSystem A pointer to the file system's mapped name. If NULL, then the current working
2482 directory is changed.
2483 @param Dir Points to the NULL-terminated directory on the device specified by FileSystem.
2484
2485 @retval EFI_SUCCESS The operation was sucessful
2486 @retval EFI_NOT_FOUND The file system could not be found
2487 **/
2488 EFI_STATUS
2489 EFIAPI
2490 EfiShellSetCurDir(
2491 IN CONST CHAR16 *FileSystem OPTIONAL,
2492 IN CONST CHAR16 *Dir
2493 )
2494 {
2495 CHAR16 *MapName;
2496 SHELL_MAP_LIST *MapListItem;
2497 UINTN Size;
2498 EFI_STATUS Status;
2499 CHAR16 *TempString;
2500 CHAR16 *DirectoryName;
2501 UINTN TempLen;
2502
2503 Size = 0;
2504 MapName = NULL;
2505 MapListItem = NULL;
2506 TempString = NULL;
2507 DirectoryName = NULL;
2508
2509 if (FileSystem == NULL && Dir == NULL) {
2510 return (EFI_INVALID_PARAMETER);
2511 }
2512
2513 if (IsListEmpty(&gShellMapList.Link)){
2514 return (EFI_NOT_FOUND);
2515 }
2516
2517 DirectoryName = StrnCatGrow(&DirectoryName, NULL, Dir, 0);
2518 ASSERT(DirectoryName != NULL);
2519
2520 CleanPath(DirectoryName);
2521
2522 if (FileSystem == NULL) {
2523 //
2524 // determine the file system mapping to use
2525 //
2526 if (StrStr(DirectoryName, L":") != NULL) {
2527 ASSERT(MapName == NULL);
2528 MapName = StrnCatGrow(&MapName, NULL, DirectoryName, (StrStr(DirectoryName, L":")-DirectoryName+1));
2529 }
2530 //
2531 // find the file system mapping's entry in the list
2532 // or use current
2533 //
2534 if (MapName != NULL) {
2535 MapListItem = ShellCommandFindMapItem(MapName);
2536
2537 //
2538 // make that the current file system mapping
2539 //
2540 if (MapListItem != NULL) {
2541 gShellCurDir = MapListItem;
2542 }
2543 } else {
2544 MapListItem = gShellCurDir;
2545 }
2546
2547 if (MapListItem == NULL) {
2548 return (EFI_NOT_FOUND);
2549 }
2550
2551 //
2552 // now update the MapListItem's current directory
2553 //
2554 if (MapListItem->CurrentDirectoryPath != NULL && DirectoryName[StrLen(DirectoryName) - 1] != L':') {
2555 FreePool(MapListItem->CurrentDirectoryPath);
2556 MapListItem->CurrentDirectoryPath = NULL;
2557 }
2558 if (MapName != NULL) {
2559 TempLen = StrLen(MapName);
2560 if (TempLen != StrLen(DirectoryName)) {
2561 ASSERT((MapListItem->CurrentDirectoryPath == NULL && Size == 0) || (MapListItem->CurrentDirectoryPath != NULL));
2562 MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, DirectoryName+StrLen(MapName), 0);
2563 }
2564 } else {
2565 ASSERT((MapListItem->CurrentDirectoryPath == NULL && Size == 0) || (MapListItem->CurrentDirectoryPath != NULL));
2566 MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, DirectoryName, 0);
2567 }
2568 if ((MapListItem->CurrentDirectoryPath != NULL && MapListItem->CurrentDirectoryPath[StrLen(MapListItem->CurrentDirectoryPath)-1] != L'\\') || (MapListItem->CurrentDirectoryPath == NULL)) {
2569 ASSERT((MapListItem->CurrentDirectoryPath == NULL && Size == 0) || (MapListItem->CurrentDirectoryPath != NULL));
2570 MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, L"\\", 0);
2571 }
2572 } else {
2573 //
2574 // cant have a mapping in the directory...
2575 //
2576 if (StrStr(DirectoryName, L":") != NULL) {
2577 return (EFI_INVALID_PARAMETER);
2578 }
2579 //
2580 // FileSystem != NULL
2581 //
2582 MapListItem = ShellCommandFindMapItem(FileSystem);
2583 if (MapListItem == NULL) {
2584 return (EFI_INVALID_PARAMETER);
2585 }
2586 // gShellCurDir = MapListItem;
2587 if (DirectoryName != NULL) {
2588 //
2589 // change current dir on that file system
2590 //
2591
2592 if (MapListItem->CurrentDirectoryPath != NULL) {
2593 FreePool(MapListItem->CurrentDirectoryPath);
2594 DEBUG_CODE(MapListItem->CurrentDirectoryPath = NULL;);
2595 }
2596 // ASSERT((MapListItem->CurrentDirectoryPath == NULL && Size == 0) || (MapListItem->CurrentDirectoryPath != NULL));
2597 // MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, FileSystem, 0);
2598 ASSERT((MapListItem->CurrentDirectoryPath == NULL && Size == 0) || (MapListItem->CurrentDirectoryPath != NULL));
2599 MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, L"\\", 0);
2600 ASSERT((MapListItem->CurrentDirectoryPath == NULL && Size == 0) || (MapListItem->CurrentDirectoryPath != NULL));
2601 MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, DirectoryName, 0);
2602 if (MapListItem->CurrentDirectoryPath[StrLen(MapListItem->CurrentDirectoryPath)-1] != L'\\') {
2603 ASSERT((MapListItem->CurrentDirectoryPath == NULL && Size == 0) || (MapListItem->CurrentDirectoryPath != NULL));
2604 MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, L"\\", 0);
2605 }
2606 }
2607 }
2608 //
2609 // if updated the current directory then update the environment variable
2610 //
2611 if (MapListItem == gShellCurDir) {
2612 Size = 0;
2613 ASSERT((TempString == NULL && Size == 0) || (TempString != NULL));
2614 StrnCatGrow(&TempString, &Size, MapListItem->MapName, 0);
2615 ASSERT((TempString == NULL && Size == 0) || (TempString != NULL));
2616 StrnCatGrow(&TempString, &Size, MapListItem->CurrentDirectoryPath, 0);
2617 Status = InternalEfiShellSetEnv(L"cwd", TempString, TRUE);
2618 FreePool(TempString);
2619 return (Status);
2620 }
2621 return(EFI_SUCCESS);
2622 }
2623
2624 /**
2625 Return help information about a specific command.
2626
2627 This function returns the help information for the specified command. The help text
2628 can be internal to the shell or can be from a UEFI Shell manual page.
2629
2630 If Sections is specified, then each section name listed will be compared in a casesensitive
2631 manner, to the section names described in Appendix B. If the section exists,
2632 it will be appended to the returned help text. If the section does not exist, no
2633 information will be returned. If Sections is NULL, then all help text information
2634 available will be returned.
2635
2636 @param Command Points to the NULL-terminated UEFI Shell command name.
2637 @param Sections Points to the NULL-terminated comma-delimited
2638 section names to return. If NULL, then all
2639 sections will be returned.
2640 @param HelpText On return, points to a callee-allocated buffer
2641 containing all specified help text.
2642
2643 @retval EFI_SUCCESS The help text was returned.
2644 @retval EFI_OUT_OF_RESOURCES The necessary buffer could not be allocated to hold the
2645 returned help text.
2646 @retval EFI_INVALID_PARAMETER HelpText is NULL
2647 @retval EFI_NOT_FOUND There is no help text available for Command.
2648 **/
2649 EFI_STATUS
2650 EFIAPI
2651 EfiShellGetHelpText(
2652 IN CONST CHAR16 *Command,
2653 IN CONST CHAR16 *Sections OPTIONAL,
2654 OUT CHAR16 **HelpText
2655 )
2656 {
2657 CONST CHAR16 *ManFileName;
2658
2659 ASSERT(HelpText != NULL);
2660
2661 ManFileName = ShellCommandGetManFileNameHandler(Command);
2662
2663 if (ManFileName != NULL) {
2664 return (ProcessManFile(ManFileName, Command, Sections, NULL, HelpText));
2665 } else {
2666 return (ProcessManFile(Command, Command, Sections, NULL, HelpText));
2667 }
2668 }
2669
2670 /**
2671 Gets the enable status of the page break output mode.
2672
2673 User can use this function to determine current page break mode.
2674
2675 @retval TRUE The page break output mode is enabled.
2676 @retval FALSE The page break output mode is disabled.
2677 **/
2678 BOOLEAN
2679 EFIAPI
2680 EfiShellGetPageBreak(
2681 VOID
2682 )
2683 {
2684 return(ShellInfoObject.PageBreakEnabled);
2685 }
2686
2687 /**
2688 Judges whether the active shell is the root shell.
2689
2690 This function makes the user to know that whether the active Shell is the root shell.
2691
2692 @retval TRUE The active Shell is the root Shell.
2693 @retval FALSE The active Shell is NOT the root Shell.
2694 **/
2695 BOOLEAN
2696 EFIAPI
2697 EfiShellIsRootShell(
2698 VOID
2699 )
2700 {
2701 return(ShellInfoObject.RootShellInstance);
2702 }
2703
2704 /**
2705 function to return a semi-colon delimeted list of all alias' in the current shell
2706
2707 up to caller to free the memory.
2708
2709 @retval NULL No alias' were found
2710 @retval NULL An error ocurred getting alias'
2711 @return !NULL a list of all alias'
2712 **/
2713 CHAR16 *
2714 EFIAPI
2715 InternalEfiShellGetListAlias(
2716 )
2717 {
2718 UINT64 MaxStorSize;
2719 UINT64 RemStorSize;
2720 UINT64 MaxVarSize;
2721 EFI_STATUS Status;
2722 EFI_GUID Guid;
2723 CHAR16 *VariableName;
2724 UINTN NameSize;
2725 CHAR16 *RetVal;
2726 UINTN RetSize;
2727 CHAR16 *Alias;
2728
2729 Status = gRT->QueryVariableInfo(EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS, &MaxStorSize, &RemStorSize, &MaxVarSize);
2730 ASSERT_EFI_ERROR(Status);
2731
2732 VariableName = AllocateZeroPool((UINTN)MaxVarSize);
2733 RetSize = 0;
2734 RetVal = NULL;
2735
2736 VariableName[0] = CHAR_NULL;
2737
2738 while (TRUE) {
2739 NameSize = (UINTN)MaxVarSize;
2740 Status = gRT->GetNextVariableName(&NameSize, VariableName, &Guid);
2741 if (Status == EFI_NOT_FOUND){
2742 break;
2743 }
2744 ASSERT_EFI_ERROR(Status);
2745 if (EFI_ERROR(Status)) {
2746 break;
2747 }
2748 if (CompareGuid(&Guid, &gShellAliasGuid)){
2749 Alias = GetVariable(VariableName, &gShellAliasGuid);
2750 ASSERT((RetVal == NULL && RetSize == 0) || (RetVal != NULL));
2751 RetVal = StrnCatGrow(&RetVal, &RetSize, VariableName, 0);
2752 RetVal = StrnCatGrow(&RetVal, &RetSize, L";", 0);
2753 } // compare guid
2754 } // while
2755 FreePool(VariableName);
2756
2757 return (RetVal);
2758 }
2759
2760 /**
2761 This function returns the command associated with a alias or a list of all
2762 alias'.
2763
2764 @param[in] Alias Points to the NULL-terminated shell alias.
2765 If this parameter is NULL, then all
2766 aliases will be returned in ReturnedData.
2767 @param[out] Volatile upon return of a single command if TRUE indicates
2768 this is stored in a volatile fashion. FALSE otherwise.
2769
2770 @return If Alias is not NULL, it will return a pointer to
2771 the NULL-terminated command for that alias.
2772 If Alias is NULL, ReturnedData points to a ';'
2773 delimited list of alias (e.g.
2774 ReturnedData = "dir;del;copy;mfp") that is NULL-terminated.
2775 @retval NULL an error ocurred
2776 @retval NULL Alias was not a valid Alias
2777 **/
2778 CONST CHAR16 *
2779 EFIAPI
2780 EfiShellGetAlias(
2781 IN CONST CHAR16 *Alias,
2782 OUT BOOLEAN *Volatile OPTIONAL
2783 )
2784 {
2785 CHAR16 *RetVal;
2786 UINTN RetSize;
2787 UINT32 Attribs;
2788 EFI_STATUS Status;
2789
2790 if (Alias != NULL) {
2791 if (Volatile == NULL) {
2792 return (AddBufferToFreeList(GetVariable((CHAR16*)Alias, &gShellAliasGuid)));
2793 }
2794 RetSize = 0;
2795 RetVal = NULL;
2796 Status = gRT->GetVariable((CHAR16*)Alias, &gShellAliasGuid, &Attribs, &RetSize, RetVal);
2797 if (Status == EFI_BUFFER_TOO_SMALL) {
2798 RetVal = AllocateZeroPool(RetSize);
2799 Status = gRT->GetVariable((CHAR16*)Alias, &gShellAliasGuid, &Attribs, &RetSize, RetVal);
2800 }
2801 if (EFI_ERROR(Status)) {
2802 if (RetVal != NULL) {
2803 FreePool(RetVal);
2804 }
2805 return (NULL);
2806 }
2807 if ((EFI_VARIABLE_NON_VOLATILE & Attribs) == EFI_VARIABLE_NON_VOLATILE) {
2808 *Volatile = FALSE;
2809 } else {
2810 *Volatile = TRUE;
2811 }
2812
2813 return (AddBufferToFreeList(RetVal));
2814 }
2815 return (AddBufferToFreeList(InternalEfiShellGetListAlias()));
2816 }
2817
2818 /**
2819 Changes a shell command alias.
2820
2821 This function creates an alias for a shell command or if Alias is NULL it will delete an existing alias.
2822
2823 this function does not check for built in alias'.
2824
2825 @param[in] Command Points to the NULL-terminated shell command or existing alias.
2826 @param[in] Alias Points to the NULL-terminated alias for the shell command. If this is NULL, and
2827 Command refers to an alias, that alias will be deleted.
2828 @param[in] Volatile if TRUE the Alias being set will be stored in a volatile fashion. if FALSE the
2829 Alias being set will be stored in a non-volatile fashion.
2830
2831 @retval EFI_SUCCESS Alias created or deleted successfully.
2832 @retval EFI_NOT_FOUND the Alias intended to be deleted was not found
2833 **/
2834 EFI_STATUS
2835 EFIAPI
2836 InternalSetAlias(
2837 IN CONST CHAR16 *Command,
2838 IN CONST CHAR16 *Alias,
2839 IN BOOLEAN Volatile
2840 )
2841 {
2842 //
2843 // We must be trying to remove one if Alias is NULL
2844 //
2845 if (Alias == NULL) {
2846 //
2847 // remove an alias (but passed in COMMAND parameter)
2848 //
2849 return (gRT->SetVariable((CHAR16*)Command, &gShellAliasGuid, 0, 0, NULL));
2850 } else {
2851 //
2852 // Add and replace are the same
2853 //
2854
2855 // We dont check the error return on purpose since the variable may not exist.
2856 gRT->SetVariable((CHAR16*)Command, &gShellAliasGuid, 0, 0, NULL);
2857
2858 return (gRT->SetVariable((CHAR16*)Alias, &gShellAliasGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS|(Volatile?0:EFI_VARIABLE_NON_VOLATILE), StrSize(Command), (VOID*)Command));
2859 }
2860 }
2861
2862 /**
2863 Changes a shell command alias.
2864
2865 This function creates an alias for a shell command or if Alias is NULL it will delete an existing alias.
2866
2867
2868 @param[in] Command Points to the NULL-terminated shell command or existing alias.
2869 @param[in] Alias Points to the NULL-terminated alias for the shell command. If this is NULL, and
2870 Command refers to an alias, that alias will be deleted.
2871 @param[in] Replace If TRUE and the alias already exists, then the existing alias will be replaced. If
2872 FALSE and the alias already exists, then the existing alias is unchanged and
2873 EFI_ACCESS_DENIED is returned.
2874 @param[in] Volatile if TRUE the Alias being set will be stored in a volatile fashion. if FALSE the
2875 Alias being set will be stored in a non-volatile fashion.
2876
2877 @retval EFI_SUCCESS Alias created or deleted successfully.
2878 @retval EFI_NOT_FOUND the Alias intended to be deleted was not found
2879 @retval EFI_ACCESS_DENIED The alias is a built-in alias or already existed and Replace was set to
2880 FALSE.
2881 **/
2882 EFI_STATUS
2883 EFIAPI
2884 EfiShellSetAlias(
2885 IN CONST CHAR16 *Command,
2886 IN CONST CHAR16 *Alias,
2887 IN BOOLEAN Replace,
2888 IN BOOLEAN Volatile
2889 )
2890 {
2891 //
2892 // cant set over a built in alias
2893 //
2894 if (ShellCommandIsOnAliasList(Alias==NULL?Command:Alias)) {
2895 return (EFI_ACCESS_DENIED);
2896 }
2897 if (Command == NULL || *Command == CHAR_NULL || StrLen(Command) == 0) {
2898 return (EFI_INVALID_PARAMETER);
2899 }
2900
2901 if (EfiShellGetAlias(Command, NULL) != NULL && !Replace) {
2902 return (EFI_ACCESS_DENIED);
2903 }
2904
2905 return (InternalSetAlias(Command, Alias, Volatile));
2906 }
2907
2908 // Pure FILE_HANDLE operations are passed to FileHandleLib
2909 // these functions are indicated by the *
2910 EFI_SHELL_PROTOCOL mShellProtocol = {
2911 EfiShellExecute,
2912 EfiShellGetEnv,
2913 EfiShellSetEnv,
2914 EfiShellGetAlias,
2915 EfiShellSetAlias,
2916 EfiShellGetHelpText,
2917 EfiShellGetDevicePathFromMap,
2918 EfiShellGetMapFromDevicePath,
2919 EfiShellGetDevicePathFromFilePath,
2920 EfiShellGetFilePathFromDevicePath,
2921 EfiShellSetMap,
2922 EfiShellGetCurDir,
2923 EfiShellSetCurDir,
2924 EfiShellOpenFileList,
2925 EfiShellFreeFileList,
2926 EfiShellRemoveDupInFileList,
2927 EfiShellBatchIsActive,
2928 EfiShellIsRootShell,
2929 EfiShellEnablePageBreak,
2930 EfiShellDisablePageBreak,
2931 EfiShellGetPageBreak,
2932 EfiShellGetDeviceName,
2933 (EFI_SHELL_GET_FILE_INFO)FileHandleGetInfo, //*
2934 (EFI_SHELL_SET_FILE_INFO)FileHandleSetInfo, //*
2935 EfiShellOpenFileByName,
2936 EfiShellClose,
2937 EfiShellCreateFile,
2938 (EFI_SHELL_READ_FILE)FileHandleRead, //*
2939 (EFI_SHELL_WRITE_FILE)FileHandleWrite, //*
2940 (EFI_SHELL_DELETE_FILE)FileHandleDelete, //*
2941 EfiShellDeleteFileByName,
2942 (EFI_SHELL_GET_FILE_POSITION)FileHandleGetPosition, //*
2943 (EFI_SHELL_SET_FILE_POSITION)FileHandleSetPosition, //*
2944 (EFI_SHELL_FLUSH_FILE)FileHandleFlush, //*
2945 EfiShellFindFiles,
2946 EfiShellFindFilesInDir,
2947 (EFI_SHELL_GET_FILE_SIZE)FileHandleGetSize, //*
2948 EfiShellOpenRoot,
2949 EfiShellOpenRootByHandle,
2950 NULL,
2951 SHELL_MAJOR_VERSION,
2952 SHELL_MINOR_VERSION
2953 };
2954
2955 /**
2956 Function to create and install on the current handle.
2957
2958 Will overwrite any existing ShellProtocols in the system to be sure that
2959 the current shell is in control.
2960
2961 This must be removed via calling CleanUpShellProtocol().
2962
2963 @param[in,out] NewShell The pointer to the pointer to the structure
2964 to install.
2965
2966 @retval EFI_SUCCESS The operation was successful.
2967 @return An error from LocateHandle, CreateEvent, or other core function.
2968 **/
2969 EFI_STATUS
2970 EFIAPI
2971 CreatePopulateInstallShellProtocol (
2972 IN OUT EFI_SHELL_PROTOCOL **NewShell
2973 )
2974 {
2975 EFI_STATUS Status;
2976 UINTN BufferSize;
2977 EFI_HANDLE *Buffer;
2978 UINTN HandleCounter;
2979 SHELL_PROTOCOL_HANDLE_LIST *OldProtocolNode;
2980
2981 BufferSize = 0;
2982 Buffer = NULL;
2983 OldProtocolNode = NULL;
2984 InitializeListHead(&ShellInfoObject.OldShellList.Link);
2985
2986 ASSERT(NewShell != NULL);
2987
2988 //
2989 // Initialize EfiShellProtocol object...
2990 //
2991 *NewShell = &mShellProtocol;
2992 Status = gBS->CreateEvent(0,
2993 0,
2994 NULL,
2995 NULL,
2996 &mShellProtocol.ExecutionBreak);
2997 ASSERT_EFI_ERROR(Status);
2998
2999 //
3000 // Get the size of the buffer we need.
3001 //
3002 Status = gBS->LocateHandle(ByProtocol,
3003 &gEfiShellProtocolGuid,
3004 NULL,
3005 &BufferSize,
3006 Buffer);
3007 if (Status == EFI_BUFFER_TOO_SMALL) {
3008 //
3009 // Allocate and recall with buffer of correct size
3010 //
3011 Buffer = AllocateZeroPool(BufferSize);
3012 ASSERT(Buffer != NULL);
3013 Status = gBS->LocateHandle(ByProtocol,
3014 &gEfiShellProtocolGuid,
3015 NULL,
3016 &BufferSize,
3017 Buffer);
3018 ASSERT_EFI_ERROR(Status);
3019 //
3020 // now overwrite each of them, but save the info to restore when we end.
3021 //
3022 for (HandleCounter = 0 ; HandleCounter < (BufferSize/sizeof(EFI_HANDLE)) ; HandleCounter++) {
3023 OldProtocolNode = AllocateZeroPool(sizeof(SHELL_PROTOCOL_HANDLE_LIST));
3024 ASSERT(OldProtocolNode != NULL);
3025 Status = gBS->OpenProtocol(Buffer[HandleCounter],
3026 &gEfiShellProtocolGuid,
3027 (VOID **) &(OldProtocolNode->Interface),
3028 gImageHandle,
3029 NULL,
3030 EFI_OPEN_PROTOCOL_GET_PROTOCOL
3031 );
3032 if (!EFI_ERROR(Status)) {
3033 //
3034 // reinstall over the old one...
3035 //
3036 OldProtocolNode->Handle = Buffer[HandleCounter];
3037 Status = gBS->ReinstallProtocolInterface(
3038 OldProtocolNode->Handle,
3039 &gEfiShellProtocolGuid,
3040 OldProtocolNode->Interface,
3041 (VOID*)(*NewShell));
3042 if (!EFI_ERROR(Status)) {
3043 //
3044 // we reinstalled sucessfully. log this so we can reverse it later.
3045 //
3046
3047 //
3048 // add to the list for subsequent...
3049 //
3050 InsertTailList(&ShellInfoObject.OldShellList.Link, &OldProtocolNode->Link);
3051 }
3052 }
3053 }
3054 FreePool(Buffer);
3055 } else if (Status == EFI_NOT_FOUND) {
3056 ASSERT(IsListEmpty(&ShellInfoObject.OldShellList.Link));
3057 //
3058 // no one else published yet. just publish it ourselves.
3059 //
3060 Status = gBS->InstallProtocolInterface (
3061 &gImageHandle,
3062 &gEfiShellProtocolGuid,
3063 EFI_NATIVE_INTERFACE,
3064 (VOID*)(*NewShell));
3065 }
3066
3067 if (PcdGetBool(PcdShellSupportOldProtocols)){
3068 ///@todo support ShellEnvironment2
3069 ///@todo do we need to support ShellEnvironment (not ShellEnvironment2) also?
3070 }
3071
3072 return (Status);
3073 }
3074
3075 /**
3076 Opposite of CreatePopulateInstallShellProtocol.
3077
3078 Free all memory and restore the system to the state it was in before calling
3079 CreatePopulateInstallShellProtocol.
3080
3081 @param[in,out] NewShell The pointer to the new shell protocol structure.
3082
3083 @retval EFI_SUCCESS The operation was successful.
3084 **/
3085 EFI_STATUS
3086 EFIAPI
3087 CleanUpShellProtocol (
3088 IN OUT EFI_SHELL_PROTOCOL *NewShell
3089 )
3090 {
3091 EFI_STATUS Status;
3092 SHELL_PROTOCOL_HANDLE_LIST *Node2;
3093
3094 //
3095 // if we need to restore old protocols...
3096 //
3097 if (!IsListEmpty(&ShellInfoObject.OldShellList.Link)) {
3098 for (Node2 = (SHELL_PROTOCOL_HANDLE_LIST *)GetFirstNode(&ShellInfoObject.OldShellList.Link)
3099 ; !IsListEmpty (&ShellInfoObject.OldShellList.Link)
3100 ; Node2 = (SHELL_PROTOCOL_HANDLE_LIST *)GetFirstNode(&ShellInfoObject.OldShellList.Link)
3101 ){
3102 RemoveEntryList(&Node2->Link);
3103 Status = gBS->ReinstallProtocolInterface(Node2->Handle,
3104 &gEfiShellProtocolGuid,
3105 NewShell,
3106 Node2->Interface);
3107 ASSERT_EFI_ERROR(Status);
3108 FreePool(Node2);
3109 }
3110 } else {
3111 //
3112 // no need to restore
3113 //
3114 Status = gBS->UninstallProtocolInterface(gImageHandle,
3115 &gEfiShellProtocolGuid,
3116 NewShell);
3117 ASSERT_EFI_ERROR(Status);
3118 }
3119 Status = gBS->CloseEvent(NewShell->ExecutionBreak);
3120
3121 return (Status);
3122 }
3123
3124