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