2 Member functions of EFI_SHELL_PROTOCOL and functions for creation,
3 manipulation, and initialization of EFI_SHELL_PROTOCOL.
5 (C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>
6 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
7 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
8 This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 #define INIT_NAME_BUFFER_SIZE 128
23 Close an open file handle.
25 This function closes a specified file handle. All "dirty" cached file data is
26 flushed to the device, and the file is closed. In all cases the handle is
29 @param[in] FileHandle The file handle to close.
31 @retval EFI_SUCCESS The file handle was closed successfully.
36 IN SHELL_FILE_HANDLE FileHandle
39 ShellFileHandleRemove(FileHandle
);
40 return (FileHandleClose(ConvertShellHandleToEfiFileProtocol(FileHandle
)));
44 Internal worker to determine whether there is a BlockIo somewhere
45 upon the device path specified.
47 @param[in] DevicePath The device path to test.
49 @retval TRUE gEfiBlockIoProtocolGuid was installed on a handle with this device path
50 @retval FALSE gEfiBlockIoProtocolGuid was not found.
53 InternalShellProtocolIsBlockIoPresent(
54 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
57 EFI_DEVICE_PATH_PROTOCOL
*DevicePathCopy
;
63 DevicePathCopy
= (EFI_DEVICE_PATH_PROTOCOL
*)DevicePath
;
64 Status
= gBS
->LocateDevicePath(&gEfiBlockIoProtocolGuid
, &DevicePathCopy
, &Handle
);
66 if ((Handle
!= NULL
) && (!EFI_ERROR(Status
))) {
73 Internal worker to determine whether there is a file system somewhere
74 upon the device path specified.
76 @param[in] DevicePath The device path to test.
78 @retval TRUE gEfiSimpleFileSystemProtocolGuid was installed on a handle with this device path
79 @retval FALSE gEfiSimpleFileSystemProtocolGuid was not found.
82 InternalShellProtocolIsSimpleFileSystemPresent(
83 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
86 EFI_DEVICE_PATH_PROTOCOL
*DevicePathCopy
;
92 DevicePathCopy
= (EFI_DEVICE_PATH_PROTOCOL
*)DevicePath
;
93 Status
= gBS
->LocateDevicePath(&gEfiSimpleFileSystemProtocolGuid
, &DevicePathCopy
, &Handle
);
95 if ((Handle
!= NULL
) && (!EFI_ERROR(Status
))) {
103 This function creates a mapping for a device path.
105 If both DeviecPath and Mapping are NULL, this will reset the mapping to default values.
107 @param DevicePath Points to the device path. If this is NULL and Mapping points to a valid mapping,
108 then the mapping will be deleted.
109 @param Mapping Points to the NULL-terminated mapping for the device path. Must end with a ':'
111 @retval EFI_SUCCESS Mapping created or deleted successfully.
112 @retval EFI_NO_MAPPING There is no handle that corresponds exactly to DevicePath. See the
113 boot service function LocateDevicePath().
114 @retval EFI_ACCESS_DENIED The mapping is a built-in alias.
115 @retval EFI_INVALID_PARAMETER Mapping was NULL
116 @retval EFI_INVALID_PARAMETER Mapping did not end with a ':'
117 @retval EFI_INVALID_PARAMETER DevicePath was not pointing at a device that had a SIMPLE_FILE_SYSTEM_PROTOCOL installed.
118 @retval EFI_NOT_FOUND There was no mapping found to delete
119 @retval EFI_OUT_OF_RESOURCES Memory allocation failed
124 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath OPTIONAL
,
125 IN CONST CHAR16
*Mapping
129 SHELL_MAP_LIST
*MapListNode
;
131 if (Mapping
== NULL
){
132 return (EFI_INVALID_PARAMETER
);
135 if (Mapping
[StrLen(Mapping
)-1] != ':') {
136 return (EFI_INVALID_PARAMETER
);
140 // Delete the mapping
142 if (DevicePath
== NULL
) {
143 if (IsListEmpty(&gShellMapList
.Link
)) {
144 return (EFI_NOT_FOUND
);
146 for ( MapListNode
= (SHELL_MAP_LIST
*)GetFirstNode(&gShellMapList
.Link
)
147 ; !IsNull(&gShellMapList
.Link
, &MapListNode
->Link
)
148 ; MapListNode
= (SHELL_MAP_LIST
*)GetNextNode(&gShellMapList
.Link
, &MapListNode
->Link
)
150 if (StringNoCaseCompare(&MapListNode
->MapName
, &Mapping
) == 0) {
151 RemoveEntryList(&MapListNode
->Link
);
152 SHELL_FREE_NON_NULL(MapListNode
->DevicePath
);
153 SHELL_FREE_NON_NULL(MapListNode
->MapName
);
154 SHELL_FREE_NON_NULL(MapListNode
->CurrentDirectoryPath
);
155 FreePool(MapListNode
);
156 return (EFI_SUCCESS
);
161 // We didnt find one to delete
163 return (EFI_NOT_FOUND
);
167 // make sure this is a valid to add device path
169 ///@todo add BlockIo to this test...
170 if (!InternalShellProtocolIsSimpleFileSystemPresent(DevicePath
)
171 && !InternalShellProtocolIsBlockIoPresent(DevicePath
)) {
172 return (EFI_INVALID_PARAMETER
);
176 // First make sure there is no old mapping
178 Status
= EfiShellSetMap(NULL
, Mapping
);
179 if ((Status
!= EFI_SUCCESS
) && (Status
!= EFI_NOT_FOUND
)) {
184 // now add the new one.
186 Status
= ShellCommandAddMapItemAndUpdatePath(Mapping
, DevicePath
, 0, FALSE
);
192 Gets the device path from the mapping.
194 This function gets the device path associated with a mapping.
196 @param Mapping A pointer to the mapping
198 @retval !=NULL Pointer to the device path that corresponds to the
199 device mapping. The returned pointer does not need
201 @retval NULL There is no device path associated with the
204 CONST EFI_DEVICE_PATH_PROTOCOL
*
206 EfiShellGetDevicePathFromMap(
207 IN CONST CHAR16
*Mapping
210 SHELL_MAP_LIST
*MapListItem
;
217 StrnCatGrow(&NewName
, &Size
, Mapping
, 0);
218 if (Mapping
[StrLen(Mapping
)-1] != L
':') {
219 StrnCatGrow(&NewName
, &Size
, L
":", 0);
222 MapListItem
= ShellCommandFindMapItem(NewName
);
226 if (MapListItem
!= NULL
) {
227 return (MapListItem
->DevicePath
);
233 Gets the mapping(s) that most closely matches the device path.
235 This function gets the mapping which corresponds to the device path *DevicePath. If
236 there is no exact match, then the mapping which most closely matches *DevicePath
237 is returned, and *DevicePath is updated to point to the remaining portion of the
238 device path. If there is an exact match, the mapping is returned and *DevicePath
239 points to the end-of-device-path node.
241 If there are multiple map names they will be semi-colon seperated in the
242 NULL-terminated string.
244 @param DevicePath On entry, points to a device path pointer. On
245 exit, updates the pointer to point to the
246 portion of the device path after the mapping.
248 @retval NULL No mapping was found.
249 @return !=NULL Pointer to NULL-terminated mapping. The buffer
250 is callee allocated and should be freed by the caller.
254 EfiShellGetMapFromDevicePath(
255 IN OUT EFI_DEVICE_PATH_PROTOCOL
**DevicePath
258 SHELL_MAP_LIST
*Node
;
259 CHAR16
*PathForReturn
;
261 // EFI_HANDLE PathHandle;
262 // EFI_HANDLE MapHandle;
263 // EFI_STATUS Status;
264 // EFI_DEVICE_PATH_PROTOCOL *DevicePathCopy;
265 // EFI_DEVICE_PATH_PROTOCOL *MapPathCopy;
267 if (DevicePath
== NULL
|| *DevicePath
== NULL
) {
271 PathForReturn
= NULL
;
274 for ( Node
= (SHELL_MAP_LIST
*)GetFirstNode(&gShellMapList
.Link
)
275 ; !IsNull(&gShellMapList
.Link
, &Node
->Link
)
276 ; Node
= (SHELL_MAP_LIST
*)GetNextNode(&gShellMapList
.Link
, &Node
->Link
)
279 // check for exact match
281 if (DevicePathCompare(DevicePath
, &Node
->DevicePath
) == 0) {
282 ASSERT((PathForReturn
== NULL
&& PathSize
== 0) || (PathForReturn
!= NULL
));
284 PathForReturn
= StrnCatGrow(&PathForReturn
, &PathSize
, L
";", 0);
286 PathForReturn
= StrnCatGrow(&PathForReturn
, &PathSize
, Node
->MapName
, 0);
289 if (PathForReturn
!= NULL
) {
290 while (!IsDevicePathEndType (*DevicePath
)) {
291 *DevicePath
= NextDevicePathNode (*DevicePath
);
293 SetDevicePathEndNode (*DevicePath
);
296 ///@todo finish code for inexact matches.
297 if (PathForReturn == NULL) {
300 DevicePathCopy = DuplicateDevicePath(*DevicePath);
301 ASSERT(DevicePathCopy != NULL);
302 Status = gBS->LocateDevicePath(&gEfiSimpleFileSystemProtocolGuid, &DevicePathCopy, &PathHandle);
303 ASSERT_EFI_ERROR(Status);
305 // check each of the device paths we have to get the root of the path for consist mappings
307 for ( Node = (SHELL_MAP_LIST *)GetFirstNode(&gShellMapList.Link)
308 ; !IsNull(&gShellMapList.Link, &Node->Link)
309 ; Node = (SHELL_MAP_LIST *)GetNextNode(&gShellMapList.Link, &Node->Link)
311 if ((Node->Flags & SHELL_MAP_FLAGS_CONSIST) == 0) {
314 MapPathCopy = DuplicateDevicePath(Node->DevicePath);
315 ASSERT(MapPathCopy != NULL);
316 Status = gBS->LocateDevicePath(&gEfiSimpleFileSystemProtocolGuid, &MapPathCopy, &MapHandle);
317 if (MapHandle == PathHandle) {
319 *DevicePath = DevicePathCopy;
322 DevicePathCopy = NULL;
323 PathForReturn = StrnCatGrow(&PathForReturn, &PathSize, Node->MapName, 0);
324 PathForReturn = StrnCatGrow(&PathForReturn, &PathSize, L";", 0);
329 // now add on the non-consistent mappings
331 for ( Node = (SHELL_MAP_LIST *)GetFirstNode(&gShellMapList.Link)
332 ; !IsNull(&gShellMapList.Link, &Node->Link)
333 ; Node = (SHELL_MAP_LIST *)GetNextNode(&gShellMapList.Link, &Node->Link)
335 if ((Node->Flags & SHELL_MAP_FLAGS_CONSIST) != 0) {
338 MapPathCopy = Node->DevicePath;
339 ASSERT(MapPathCopy != NULL);
340 Status = gBS->LocateDevicePath(&gEfiSimpleFileSystemProtocolGuid, &MapPathCopy, &MapHandle);
341 if (MapHandle == PathHandle) {
342 PathForReturn = StrnCatGrow(&PathForReturn, &PathSize, Node->MapName, 0);
343 PathForReturn = StrnCatGrow(&PathForReturn, &PathSize, L";", 0);
350 return (AddBufferToFreeList(PathForReturn
));
354 Converts a device path to a file system-style path.
356 This function converts a device path to a file system path by replacing part, or all, of
357 the device path with the file-system mapping. If there are more than one application
358 file system mappings, the one that most closely matches Path will be used.
360 @param Path The pointer to the device path
362 @retval NULL the device path could not be found.
363 @return all The pointer of the NULL-terminated file path. The path
364 is callee-allocated and should be freed by the caller.
368 EfiShellGetFilePathFromDevicePath(
369 IN CONST EFI_DEVICE_PATH_PROTOCOL
*Path
372 EFI_DEVICE_PATH_PROTOCOL
*DevicePathCopy
;
373 EFI_DEVICE_PATH_PROTOCOL
*MapPathCopy
;
374 SHELL_MAP_LIST
*MapListItem
;
375 CHAR16
*PathForReturn
;
377 EFI_HANDLE PathHandle
;
378 EFI_HANDLE MapHandle
;
380 FILEPATH_DEVICE_PATH
*FilePath
;
381 FILEPATH_DEVICE_PATH
*AlignedNode
;
383 PathForReturn
= NULL
;
386 DevicePathCopy
= (EFI_DEVICE_PATH_PROTOCOL
*)Path
;
387 ASSERT(DevicePathCopy
!= NULL
);
388 if (DevicePathCopy
== NULL
) {
392 Status
= gBS
->LocateDevicePath(&gEfiSimpleFileSystemProtocolGuid
, &DevicePathCopy
, &PathHandle
);
394 if (EFI_ERROR(Status
)) {
398 // check each of the device paths we have to get the root of the path
400 for ( MapListItem
= (SHELL_MAP_LIST
*)GetFirstNode(&gShellMapList
.Link
)
401 ; !IsNull(&gShellMapList
.Link
, &MapListItem
->Link
)
402 ; MapListItem
= (SHELL_MAP_LIST
*)GetNextNode(&gShellMapList
.Link
, &MapListItem
->Link
)
404 MapPathCopy
= (EFI_DEVICE_PATH_PROTOCOL
*)MapListItem
->DevicePath
;
405 ASSERT(MapPathCopy
!= NULL
);
407 Status
= gBS
->LocateDevicePath(&gEfiSimpleFileSystemProtocolGuid
, &MapPathCopy
, &MapHandle
);
408 if (MapHandle
== PathHandle
) {
409 ASSERT((PathForReturn
== NULL
&& PathSize
== 0) || (PathForReturn
!= NULL
));
410 PathForReturn
= StrnCatGrow(&PathForReturn
, &PathSize
, MapListItem
->MapName
, 0);
412 // go through all the remaining nodes in the device path
414 for ( FilePath
= (FILEPATH_DEVICE_PATH
*)DevicePathCopy
415 ; !IsDevicePathEnd (&FilePath
->Header
)
416 ; FilePath
= (FILEPATH_DEVICE_PATH
*)NextDevicePathNode (&FilePath
->Header
)
419 // If any node is not a file path node, then the conversion can not be completed
421 if ((DevicePathType(&FilePath
->Header
) != MEDIA_DEVICE_PATH
) ||
422 (DevicePathSubType(&FilePath
->Header
) != MEDIA_FILEPATH_DP
)) {
423 FreePool(PathForReturn
);
428 // append the path part onto the filepath.
430 ASSERT((PathForReturn
== NULL
&& PathSize
== 0) || (PathForReturn
!= NULL
));
432 AlignedNode
= AllocateCopyPool (DevicePathNodeLength(FilePath
), FilePath
);
433 if (AlignedNode
== NULL
) {
434 FreePool (PathForReturn
);
438 // File Path Device Path Nodes 'can optionally add a "\" separator to
439 // the beginning and/or the end of the Path Name string.'
440 // (UEFI Spec 2.4 section 9.3.6.4).
441 // If necessary, add a "\", but otherwise don't
442 // (This is specified in the above section, and also implied by the
443 // UEFI Shell spec section 3.7)
444 if ((PathSize
!= 0) &&
445 (PathForReturn
!= NULL
) &&
446 (PathForReturn
[PathSize
/ sizeof (CHAR16
) - 1] != L
'\\') &&
447 (AlignedNode
->PathName
[0] != L
'\\')) {
448 PathForReturn
= StrnCatGrow (&PathForReturn
, &PathSize
, L
"\\", 1);
451 PathForReturn
= StrnCatGrow(&PathForReturn
, &PathSize
, AlignedNode
->PathName
, 0);
452 FreePool(AlignedNode
);
453 } // for loop of remaining nodes
455 if (PathForReturn
!= NULL
) {
458 } // for loop of paths to check
459 return(PathForReturn
);
463 Converts a file system style name to a device path.
465 This function converts a file system style name to a device path, by replacing any
466 mapping references to the associated device path.
468 @param[in] Path The pointer to the path.
470 @return The pointer of the file path. The file path is callee
471 allocated and should be freed by the caller.
472 @retval NULL The path could not be found.
473 @retval NULL There was not enough available memory.
475 EFI_DEVICE_PATH_PROTOCOL
*
477 EfiShellGetDevicePathFromFilePath(
478 IN CONST CHAR16
*Path
485 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
486 EFI_DEVICE_PATH_PROTOCOL
*DevicePathCopy
;
487 EFI_DEVICE_PATH_PROTOCOL
*DevicePathCopyForFree
;
488 EFI_DEVICE_PATH_PROTOCOL
*DevicePathForReturn
;
499 if (StrStr(Path
, L
":") == NULL
) {
500 Cwd
= EfiShellGetCurDir(NULL
);
504 Size
= StrSize(Cwd
) + StrSize(Path
);
505 NewPath
= AllocateZeroPool(Size
);
506 if (NewPath
== NULL
) {
509 StrCpyS(NewPath
, Size
/sizeof(CHAR16
), Cwd
);
510 StrCatS(NewPath
, Size
/sizeof(CHAR16
), L
"\\");
511 if (*Path
== L
'\\') {
513 while (PathRemoveLastItem(NewPath
)) ;
515 StrCatS(NewPath
, Size
/sizeof(CHAR16
), Path
);
516 DevicePathForReturn
= EfiShellGetDevicePathFromFilePath(NewPath
);
518 return (DevicePathForReturn
);
523 // find the part before (but including) the : for the map name
525 ASSERT((MapName
== NULL
&& Size
== 0) || (MapName
!= NULL
));
526 MapName
= StrnCatGrow(&MapName
, &Size
, Path
, (StrStr(Path
, L
":")-Path
+1));
527 if (MapName
== NULL
|| MapName
[StrLen(MapName
)-1] != L
':') {
532 // look up the device path in the map
534 DevicePath
= EfiShellGetDevicePathFromMap(MapName
);
535 if (DevicePath
== NULL
) {
537 // Must have been a bad Mapname
543 // make a copy for LocateDevicePath to modify (also save a pointer to call FreePool with)
545 DevicePathCopyForFree
= DevicePathCopy
= DuplicateDevicePath(DevicePath
);
546 if (DevicePathCopy
== NULL
) {
555 Status
= gBS
->LocateDevicePath(&gEfiSimpleFileSystemProtocolGuid
, &DevicePathCopy
, &Handle
);
556 if (EFI_ERROR(Status
)) {
557 if (DevicePathCopyForFree
!= NULL
) {
558 FreePool(DevicePathCopyForFree
);
565 // build the full device path
567 if ((*(Path
+StrLen(MapName
)) != CHAR_NULL
) &&
568 (*(Path
+StrLen(MapName
)+1) == CHAR_NULL
)) {
569 DevicePathForReturn
= FileDevicePath(Handle
, L
"\\");
571 DevicePathForReturn
= FileDevicePath(Handle
, Path
+StrLen(MapName
));
575 if (DevicePathCopyForFree
!= NULL
) {
576 FreePool(DevicePathCopyForFree
);
579 return (DevicePathForReturn
);
583 Gets the name of the device specified by the device handle.
585 This function gets the user-readable name of the device specified by the device
586 handle. If no user-readable name could be generated, then *BestDeviceName will be
587 NULL and EFI_NOT_FOUND will be returned.
589 If EFI_DEVICE_NAME_USE_COMPONENT_NAME is set, then the function will return the
590 device's name using the EFI_COMPONENT_NAME2_PROTOCOL, if present on
593 If EFI_DEVICE_NAME_USE_DEVICE_PATH is set, then the function will return the
594 device's name using the EFI_DEVICE_PATH_PROTOCOL, if present on DeviceHandle.
595 If both EFI_DEVICE_NAME_USE_COMPONENT_NAME and
596 EFI_DEVICE_NAME_USE_DEVICE_PATH are set, then
597 EFI_DEVICE_NAME_USE_COMPONENT_NAME will have higher priority.
599 @param DeviceHandle The handle of the device.
600 @param Flags Determines the possible sources of component names.
602 EFI_DEVICE_NAME_USE_COMPONENT_NAME
603 EFI_DEVICE_NAME_USE_DEVICE_PATH
604 @param Language A pointer to the language specified for the device
605 name, in the same format as described in the UEFI
606 specification, Appendix M
607 @param BestDeviceName On return, points to the callee-allocated NULL-
608 terminated name of the device. If no device name
609 could be found, points to NULL. The name must be
610 freed by the caller...
612 @retval EFI_SUCCESS Get the name successfully.
613 @retval EFI_NOT_FOUND Fail to get the device name.
614 @retval EFI_INVALID_PARAMETER Flags did not have a valid bit set.
615 @retval EFI_INVALID_PARAMETER BestDeviceName was NULL
616 @retval EFI_INVALID_PARAMETER DeviceHandle was NULL
620 EfiShellGetDeviceName(
621 IN EFI_HANDLE DeviceHandle
,
622 IN EFI_SHELL_DEVICE_NAME_FLAGS Flags
,
624 OUT CHAR16
**BestDeviceName
628 EFI_COMPONENT_NAME2_PROTOCOL
*CompName2
;
629 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
630 EFI_HANDLE
*HandleList
;
633 CHAR16
*DeviceNameToReturn
;
635 UINTN ParentControllerCount
;
636 EFI_HANDLE
*ParentControllerBuffer
;
637 UINTN ParentDriverCount
;
638 EFI_HANDLE
*ParentDriverBuffer
;
640 if (BestDeviceName
== NULL
||
643 return (EFI_INVALID_PARAMETER
);
647 // make sure one of the 2 supported bits is on
649 if (((Flags
& EFI_DEVICE_NAME_USE_COMPONENT_NAME
) == 0) &&
650 ((Flags
& EFI_DEVICE_NAME_USE_DEVICE_PATH
) == 0)) {
651 return (EFI_INVALID_PARAMETER
);
654 DeviceNameToReturn
= NULL
;
655 *BestDeviceName
= NULL
;
660 if ((Flags
& EFI_DEVICE_NAME_USE_COMPONENT_NAME
) != 0) {
661 Status
= ParseHandleDatabaseByRelationship(
664 HR_DRIVER_BINDING_HANDLE
|HR_DEVICE_DRIVER
,
667 for (LoopVar
= 0; LoopVar
< HandleCount
; LoopVar
++){
669 // Go through those handles until we get one that passes for GetComponentName
671 Status
= gBS
->OpenProtocol(
673 &gEfiComponentName2ProtocolGuid
,
677 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
678 if (EFI_ERROR(Status
)) {
679 Status
= gBS
->OpenProtocol(
681 &gEfiComponentNameProtocolGuid
,
685 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
688 if (EFI_ERROR(Status
)) {
691 Lang
= GetBestLanguageForDriver(CompName2
->SupportedLanguages
, Language
, FALSE
);
692 Status
= CompName2
->GetControllerName(CompName2
, DeviceHandle
, NULL
, Lang
, &DeviceNameToReturn
);
695 if (!EFI_ERROR(Status
) && DeviceNameToReturn
!= NULL
) {
699 if (HandleList
!= NULL
) {
700 FreePool(HandleList
);
704 // Now check the parent controller using this as the child.
706 if (DeviceNameToReturn
== NULL
){
707 PARSE_HANDLE_DATABASE_PARENTS(DeviceHandle
, &ParentControllerCount
, &ParentControllerBuffer
);
708 for (LoopVar
= 0 ; LoopVar
< ParentControllerCount
; LoopVar
++) {
709 PARSE_HANDLE_DATABASE_UEFI_DRIVERS(ParentControllerBuffer
[LoopVar
], &ParentDriverCount
, &ParentDriverBuffer
);
710 for (HandleCount
= 0 ; HandleCount
< ParentDriverCount
; HandleCount
++) {
712 // try using that driver's component name with controller and our driver as the child.
714 Status
= gBS
->OpenProtocol(
715 ParentDriverBuffer
[HandleCount
],
716 &gEfiComponentName2ProtocolGuid
,
720 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
721 if (EFI_ERROR(Status
)) {
722 Status
= gBS
->OpenProtocol(
723 ParentDriverBuffer
[HandleCount
],
724 &gEfiComponentNameProtocolGuid
,
728 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
731 if (EFI_ERROR(Status
)) {
734 Lang
= GetBestLanguageForDriver(CompName2
->SupportedLanguages
, Language
, FALSE
);
735 Status
= CompName2
->GetControllerName(CompName2
, ParentControllerBuffer
[LoopVar
], DeviceHandle
, Lang
, &DeviceNameToReturn
);
738 if (!EFI_ERROR(Status
) && DeviceNameToReturn
!= NULL
) {
745 SHELL_FREE_NON_NULL(ParentDriverBuffer
);
746 if (!EFI_ERROR(Status
) && DeviceNameToReturn
!= NULL
) {
750 SHELL_FREE_NON_NULL(ParentControllerBuffer
);
753 // dont return on fail since we will try device path if that bit is on
755 if (DeviceNameToReturn
!= NULL
){
756 ASSERT(BestDeviceName
!= NULL
);
757 StrnCatGrow(BestDeviceName
, NULL
, DeviceNameToReturn
, 0);
758 return (EFI_SUCCESS
);
761 if ((Flags
& EFI_DEVICE_NAME_USE_DEVICE_PATH
) != 0) {
762 Status
= gBS
->OpenProtocol(
764 &gEfiDevicePathProtocolGuid
,
768 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
769 if (!EFI_ERROR(Status
)) {
771 // use device path to text on the device path
773 *BestDeviceName
= ConvertDevicePathToText(DevicePath
, TRUE
, TRUE
);
774 return (EFI_SUCCESS
);
778 // none of the selected bits worked.
780 return (EFI_NOT_FOUND
);
784 Opens the root directory of a device on a handle
786 This function opens the root directory of a device and returns a file handle to it.
788 @param DeviceHandle The handle of the device that contains the volume.
789 @param FileHandle On exit, points to the file handle corresponding to the root directory on the
792 @retval EFI_SUCCESS Root opened successfully.
793 @retval EFI_NOT_FOUND EFI_SIMPLE_FILE_SYSTEM could not be found or the root directory
795 @retval EFI_VOLUME_CORRUPTED The data structures in the volume were corrupted.
796 @retval EFI_DEVICE_ERROR The device had an error.
797 @retval Others Error status returned from EFI_SIMPLE_FILE_SYSTEM_PROTOCOL->OpenVolume().
801 EfiShellOpenRootByHandle(
802 IN EFI_HANDLE DeviceHandle
,
803 OUT SHELL_FILE_HANDLE
*FileHandle
807 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*SimpleFileSystem
;
808 EFI_FILE_PROTOCOL
*RealFileHandle
;
809 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
812 // get the simple file system interface
814 Status
= gBS
->OpenProtocol(DeviceHandle
,
815 &gEfiSimpleFileSystemProtocolGuid
,
816 (VOID
**)&SimpleFileSystem
,
819 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
820 if (EFI_ERROR(Status
)) {
821 return (EFI_NOT_FOUND
);
824 Status
= gBS
->OpenProtocol(DeviceHandle
,
825 &gEfiDevicePathProtocolGuid
,
829 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
830 if (EFI_ERROR(Status
)) {
831 return (EFI_NOT_FOUND
);
834 // Open the root volume now...
836 Status
= SimpleFileSystem
->OpenVolume(SimpleFileSystem
, &RealFileHandle
);
837 if (EFI_ERROR(Status
)) {
841 *FileHandle
= ConvertEfiFileProtocolToShellHandle(RealFileHandle
, EfiShellGetMapFromDevicePath(&DevPath
));
842 return (EFI_SUCCESS
);
846 Opens the root directory of a device.
848 This function opens the root directory of a device and returns a file handle to it.
850 @param DevicePath Points to the device path corresponding to the device where the
851 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL is installed.
852 @param FileHandle On exit, points to the file handle corresponding to the root directory on the
855 @retval EFI_SUCCESS Root opened successfully.
856 @retval EFI_NOT_FOUND EFI_SIMPLE_FILE_SYSTEM could not be found or the root directory
858 @retval EFI_VOLUME_CORRUPTED The data structures in the volume were corrupted.
859 @retval EFI_DEVICE_ERROR The device had an error
860 @retval EFI_INVALID_PARAMETER FileHandle is NULL.
865 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
866 OUT SHELL_FILE_HANDLE
*FileHandle
872 if (FileHandle
== NULL
) {
873 return (EFI_INVALID_PARAMETER
);
877 // find the handle of the device with that device handle and the file system
880 Status
= gBS
->LocateDevicePath(&gEfiSimpleFileSystemProtocolGuid
,
883 if (EFI_ERROR(Status
)) {
884 return (EFI_NOT_FOUND
);
887 return (EfiShellOpenRootByHandle(Handle
, FileHandle
));
891 Returns whether any script files are currently being processed.
893 @retval TRUE There is at least one script file active.
894 @retval FALSE No script files are active now.
899 EfiShellBatchIsActive (
903 if (ShellCommandGetCurrentScriptFile() == NULL
) {
910 Worker function to open a file based on a device path. this will open the root
911 of the volume and then traverse down to the file itself.
913 @param DevicePath Device Path of the file.
914 @param FileHandle Pointer to the file upon a successful return.
915 @param OpenMode mode to open file in.
916 @param Attributes the File Attributes to use when creating a new file.
918 @retval EFI_SUCCESS the file is open and FileHandle is valid
919 @retval EFI_UNSUPPORTED the device path cotained non-path elements
920 @retval other an error ocurred.
923 InternalOpenFileDevicePath(
924 IN OUT EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
925 OUT SHELL_FILE_HANDLE
*FileHandle
,
927 IN UINT64 Attributes OPTIONAL
931 FILEPATH_DEVICE_PATH
*FilePathNode
;
933 SHELL_FILE_HANDLE ShellHandle
;
934 EFI_FILE_PROTOCOL
*Handle1
;
935 EFI_FILE_PROTOCOL
*Handle2
;
936 FILEPATH_DEVICE_PATH
*AlignedNode
;
938 if (FileHandle
== NULL
) {
939 return (EFI_INVALID_PARAMETER
);
949 Status
= EfiShellOpenRoot(DevicePath
, &ShellHandle
);
951 if (!EFI_ERROR(Status
)) {
952 Handle1
= ConvertShellHandleToEfiFileProtocol(ShellHandle
);
953 if (Handle1
!= NULL
) {
955 // chop off the begining part before the file system part...
958 Status
= gBS
->LocateDevicePath(&gEfiSimpleFileSystemProtocolGuid
,
961 if (!EFI_ERROR(Status
)) {
963 // To access as a file system, the file path should only
964 // contain file path components. Follow the file path nodes
965 // and find the target file
967 for ( FilePathNode
= (FILEPATH_DEVICE_PATH
*)DevicePath
968 ; !IsDevicePathEnd (&FilePathNode
->Header
)
969 ; FilePathNode
= (FILEPATH_DEVICE_PATH
*) NextDevicePathNode (&FilePathNode
->Header
)
971 SHELL_FREE_NON_NULL(AlignedNode
);
972 AlignedNode
= AllocateCopyPool (DevicePathNodeLength(FilePathNode
), FilePathNode
);
974 // For file system access each node should be a file path component
976 if (DevicePathType (&FilePathNode
->Header
) != MEDIA_DEVICE_PATH
||
977 DevicePathSubType (&FilePathNode
->Header
) != MEDIA_FILEPATH_DP
979 Status
= EFI_UNSUPPORTED
;
984 // Open this file path node
990 // if this is the last node in the DevicePath always create (if that was requested).
992 if (IsDevicePathEnd ((NextDevicePathNode (&FilePathNode
->Header
)))) {
993 Status
= Handle2
->Open (
996 AlignedNode
->PathName
,
1003 // This is not the last node and we dont want to 'create' existing
1004 // directory entries...
1008 // open without letting it create
1009 // prevents error on existing files/directories
1011 Status
= Handle2
->Open (
1014 AlignedNode
->PathName
,
1015 OpenMode
&~EFI_FILE_MODE_CREATE
,
1019 // if above failed now open and create the 'item'
1020 // if OpenMode EFI_FILE_MODE_CREATE bit was on (but disabled above)
1022 if ((EFI_ERROR (Status
)) && ((OpenMode
& EFI_FILE_MODE_CREATE
) != 0)) {
1023 Status
= Handle2
->Open (
1026 AlignedNode
->PathName
,
1033 // Close the last node
1035 ShellInfoObject
.NewEfiShellProtocol
->CloseFile (Handle2
);
1038 // If there's been an error, stop
1040 if (EFI_ERROR (Status
)) {
1047 SHELL_FREE_NON_NULL(AlignedNode
);
1048 if (EFI_ERROR(Status
)) {
1049 if (Handle1
!= NULL
) {
1050 ShellInfoObject
.NewEfiShellProtocol
->CloseFile(Handle1
);
1053 *FileHandle
= ConvertEfiFileProtocolToShellHandle(Handle1
, ShellFileHandleGetPath(ShellHandle
));
1059 Creates a file or directory by name.
1061 This function creates an empty new file or directory with the specified attributes and
1062 returns the new file's handle. If the file already exists and is read-only, then
1063 EFI_INVALID_PARAMETER will be returned.
1065 If the file already existed, it is truncated and its attributes updated. If the file is
1066 created successfully, the FileHandle is the file's handle, else, the FileHandle is NULL.
1068 If the file name begins with >v, then the file handle which is returned refers to the
1069 shell environment variable with the specified name. If the shell environment variable
1070 already exists and is non-volatile then EFI_INVALID_PARAMETER is returned.
1072 @param FileName Pointer to NULL-terminated file path
1073 @param FileAttribs The new file's attrbiutes. the different attributes are
1074 described in EFI_FILE_PROTOCOL.Open().
1075 @param FileHandle On return, points to the created file handle or directory's handle
1077 @retval EFI_SUCCESS The file was opened. FileHandle points to the new file's handle.
1078 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
1079 @retval EFI_UNSUPPORTED could not open the file path
1080 @retval EFI_NOT_FOUND the specified file could not be found on the devide, or could not
1081 file the file system on the device.
1082 @retval EFI_NO_MEDIA the device has no medium.
1083 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no
1085 @retval EFI_DEVICE_ERROR The device reported an error or can't get the file path according
1087 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
1088 @retval EFI_WRITE_PROTECTED An attempt was made to create a file, or open a file for write
1089 when the media is write-protected.
1090 @retval EFI_ACCESS_DENIED The service denied access to the file.
1091 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the file.
1092 @retval EFI_VOLUME_FULL The volume is full.
1097 IN CONST CHAR16
*FileName
,
1098 IN UINT64 FileAttribs
,
1099 OUT SHELL_FILE_HANDLE
*FileHandle
1102 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1107 // Is this for an environment variable
1108 // do we start with >v
1110 if (StrStr(FileName
, L
">v") == FileName
) {
1111 Status
= IsVolatileEnv (FileName
+ 2, &Volatile
);
1112 if (EFI_ERROR (Status
)) {
1116 return (EFI_INVALID_PARAMETER
);
1118 *FileHandle
= CreateFileInterfaceEnv(FileName
+2);
1119 return (EFI_SUCCESS
);
1123 // We are opening a regular file.
1125 DevicePath
= EfiShellGetDevicePathFromFilePath(FileName
);
1126 if (DevicePath
== NULL
) {
1127 return (EFI_NOT_FOUND
);
1130 Status
= InternalOpenFileDevicePath(DevicePath
, FileHandle
, EFI_FILE_MODE_READ
|EFI_FILE_MODE_WRITE
|EFI_FILE_MODE_CREATE
, FileAttribs
);
1131 FreePool(DevicePath
);
1137 Register a GUID and a localized human readable name for it.
1139 If Guid is not assigned a name, then assign GuidName to Guid. This list of GUID
1140 names must be used whenever a shell command outputs GUID information.
1142 This function is only available when the major and minor versions in the
1143 EfiShellProtocol are greater than or equal to 2 and 1, respectively.
1145 @param[in] Guid A pointer to the GUID being registered.
1146 @param[in] GuidName A pointer to the localized name for the GUID being registered.
1148 @retval EFI_SUCCESS The operation was successful.
1149 @retval EFI_INVALID_PARAMETER Guid was NULL.
1150 @retval EFI_INVALID_PARAMETER GuidName was NULL.
1151 @retval EFI_ACCESS_DENIED Guid already is assigned a name.
1155 EfiShellRegisterGuidName(
1156 IN CONST EFI_GUID
*Guid
,
1157 IN CONST CHAR16
*GuidName
1160 return (AddNewGuidNameMapping(Guid
, GuidName
, NULL
));
1164 Opens a file or a directory by file name.
1166 This function opens the specified file in the specified OpenMode and returns a file
1168 If the file name begins with >v, then the file handle which is returned refers to the
1169 shell environment variable with the specified name. If the shell environment variable
1170 exists, is non-volatile and the OpenMode indicates EFI_FILE_MODE_WRITE, then
1171 EFI_INVALID_PARAMETER is returned.
1173 If the file name is >i, then the file handle which is returned refers to the standard
1174 input. If the OpenMode indicates EFI_FILE_MODE_WRITE, then EFI_INVALID_PARAMETER
1177 If the file name is >o, then the file handle which is returned refers to the standard
1178 output. If the OpenMode indicates EFI_FILE_MODE_READ, then EFI_INVALID_PARAMETER
1181 If the file name is >e, then the file handle which is returned refers to the standard
1182 error. If the OpenMode indicates EFI_FILE_MODE_READ, then EFI_INVALID_PARAMETER
1185 If the file name is NUL, then the file handle that is returned refers to the standard NUL
1186 file. If the OpenMode indicates EFI_FILE_MODE_READ, then EFI_INVALID_PARAMETER is
1189 If return EFI_SUCCESS, the FileHandle is the opened file's handle, else, the
1192 @param FileName Points to the NULL-terminated UCS-2 encoded file name.
1193 @param FileHandle On return, points to the file handle.
1194 @param OpenMode File open mode. Either EFI_FILE_MODE_READ or
1195 EFI_FILE_MODE_WRITE from section 12.4 of the UEFI
1197 @retval EFI_SUCCESS The file was opened. FileHandle has the opened file's handle.
1198 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value. FileHandle is NULL.
1199 @retval EFI_UNSUPPORTED Could not open the file path. FileHandle is NULL.
1200 @retval EFI_NOT_FOUND The specified file could not be found on the device or the file
1201 system could not be found on the device. FileHandle is NULL.
1202 @retval EFI_NO_MEDIA The device has no medium. FileHandle is NULL.
1203 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no
1204 longer supported. FileHandle is NULL.
1205 @retval EFI_DEVICE_ERROR The device reported an error or can't get the file path according
1206 the FileName. FileHandle is NULL.
1207 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. FileHandle is NULL.
1208 @retval EFI_WRITE_PROTECTED An attempt was made to create a file, or open a file for write
1209 when the media is write-protected. FileHandle is NULL.
1210 @retval EFI_ACCESS_DENIED The service denied access to the file. FileHandle is NULL.
1211 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the file. FileHandle
1213 @retval EFI_VOLUME_FULL The volume is full. FileHandle is NULL.
1217 EfiShellOpenFileByName(
1218 IN CONST CHAR16
*FileName
,
1219 OUT SHELL_FILE_HANDLE
*FileHandle
,
1223 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1230 // Is this for StdIn
1232 if (StrCmp(FileName
, L
">i") == 0) {
1234 // make sure not writing to StdIn
1236 if ((OpenMode
& EFI_FILE_MODE_WRITE
) != 0) {
1237 return (EFI_INVALID_PARAMETER
);
1239 *FileHandle
= ShellInfoObject
.NewShellParametersProtocol
->StdIn
;
1240 ASSERT(*FileHandle
!= NULL
);
1241 return (EFI_SUCCESS
);
1245 // Is this for StdOut
1247 if (StrCmp(FileName
, L
">o") == 0) {
1249 // make sure not writing to StdIn
1251 if ((OpenMode
& EFI_FILE_MODE_READ
) != 0) {
1252 return (EFI_INVALID_PARAMETER
);
1254 *FileHandle
= &FileInterfaceStdOut
;
1255 return (EFI_SUCCESS
);
1259 // Is this for NUL / NULL file
1261 if ((gUnicodeCollation
->StriColl (gUnicodeCollation
, (CHAR16
*)FileName
, L
"NUL") == 0) ||
1262 (gUnicodeCollation
->StriColl (gUnicodeCollation
, (CHAR16
*)FileName
, L
"NULL") == 0)) {
1263 *FileHandle
= &FileInterfaceNulFile
;
1264 return (EFI_SUCCESS
);
1268 // Is this for StdErr
1270 if (StrCmp(FileName
, L
">e") == 0) {
1272 // make sure not writing to StdIn
1274 if ((OpenMode
& EFI_FILE_MODE_READ
) != 0) {
1275 return (EFI_INVALID_PARAMETER
);
1277 *FileHandle
= &FileInterfaceStdErr
;
1278 return (EFI_SUCCESS
);
1282 // Is this for an environment variable
1283 // do we start with >v
1285 if (StrStr(FileName
, L
">v") == FileName
) {
1286 Status
= IsVolatileEnv (FileName
+ 2, &Volatile
);
1287 if (EFI_ERROR (Status
)) {
1291 ((OpenMode
& EFI_FILE_MODE_WRITE
) != 0)) {
1292 return (EFI_INVALID_PARAMETER
);
1294 *FileHandle
= CreateFileInterfaceEnv(FileName
+2);
1295 return (EFI_SUCCESS
);
1299 // We are opening a regular file.
1301 DevicePath
= EfiShellGetDevicePathFromFilePath(FileName
);
1303 if (DevicePath
== NULL
) {
1304 return (EFI_NOT_FOUND
);
1308 // Copy the device path, open the file, then free the memory
1310 Status
= InternalOpenFileDevicePath(DevicePath
, FileHandle
, OpenMode
, 0); // 0 = no specific file attributes
1311 FreePool(DevicePath
);
1317 Deletes the file specified by the file name.
1319 This function deletes a file.
1321 @param FileName Points to the NULL-terminated file name.
1323 @retval EFI_SUCCESS The file was closed and deleted, and the handle was closed.
1324 @retval EFI_WARN_DELETE_FAILURE The handle was closed but the file was not deleted.
1325 @sa EfiShellCreateFile
1329 EfiShellDeleteFileByName(
1330 IN CONST CHAR16
*FileName
1333 SHELL_FILE_HANDLE FileHandle
;
1339 // get a handle to the file
1341 Status
= EfiShellCreateFile(FileName
,
1344 if (EFI_ERROR(Status
)) {
1348 // now delete the file
1350 ShellFileHandleRemove(FileHandle
);
1351 return (ShellInfoObject
.NewEfiShellProtocol
->DeleteFile(FileHandle
));
1355 Disables the page break output mode.
1359 EfiShellDisablePageBreak (
1363 ShellInfoObject
.PageBreakEnabled
= FALSE
;
1367 Enables the page break output mode.
1371 EfiShellEnablePageBreak (
1375 ShellInfoObject
.PageBreakEnabled
= TRUE
;
1379 internal worker function to load and run an image via device path.
1381 @param ParentImageHandle A handle of the image that is executing the specified
1383 @param DevicePath device path of the file to execute
1384 @param CommandLine Points to the NULL-terminated UCS-2 encoded string
1385 containing the command line. If NULL then the command-
1387 @param Environment Points to a NULL-terminated array of environment
1388 variables with the format 'x=y', where x is the
1389 environment variable name and y is the value. If this
1390 is NULL, then the current shell environment is used.
1392 @param[out] StartImageStatus Returned status from gBS->StartImage.
1394 @retval EFI_SUCCESS The command executed successfully. The status code
1395 returned by the command is pointed to by StatusCode.
1396 @retval EFI_INVALID_PARAMETER The parameters are invalid.
1397 @retval EFI_OUT_OF_RESOURCES Out of resources.
1398 @retval EFI_UNSUPPORTED Nested shell invocations are not allowed.
1401 InternalShellExecuteDevicePath(
1402 IN CONST EFI_HANDLE
*ParentImageHandle
,
1403 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
1404 IN CONST CHAR16
*CommandLine OPTIONAL
,
1405 IN CONST CHAR16
**Environment OPTIONAL
,
1406 OUT EFI_STATUS
*StartImageStatus OPTIONAL
1410 EFI_STATUS StartStatus
;
1411 EFI_STATUS CleanupStatus
;
1412 EFI_HANDLE NewHandle
;
1413 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
1414 LIST_ENTRY OrigEnvs
;
1415 EFI_SHELL_PARAMETERS_PROTOCOL ShellParamsProtocol
;
1421 if (ParentImageHandle
== NULL
) {
1422 return (EFI_INVALID_PARAMETER
);
1425 InitializeListHead(&OrigEnvs
);
1426 ZeroMem(&ShellParamsProtocol
, sizeof(EFI_SHELL_PARAMETERS_PROTOCOL
));
1430 NewCmdLine
= AllocateCopyPool (StrSize (CommandLine
), CommandLine
);
1431 if (NewCmdLine
== NULL
) {
1432 return EFI_OUT_OF_RESOURCES
;
1435 for (Walker
= NewCmdLine
; Walker
!= NULL
&& *Walker
!= CHAR_NULL
; Walker
++) {
1436 if (*Walker
== L
'^' && *(Walker
+1) == L
'#') {
1437 CopyMem(Walker
, Walker
+1, StrSize(Walker
) - sizeof(Walker
[0]));
1442 // Load the image with:
1443 // FALSE - not from boot manager and NULL, 0 being not already in memory
1445 Status
= gBS
->LoadImage(
1448 (EFI_DEVICE_PATH_PROTOCOL
*)DevicePath
,
1453 if (EFI_ERROR(Status
)) {
1454 if (NewHandle
!= NULL
) {
1455 gBS
->UnloadImage(NewHandle
);
1457 FreePool (NewCmdLine
);
1460 Status
= gBS
->OpenProtocol(
1462 &gEfiLoadedImageProtocolGuid
,
1463 (VOID
**)&LoadedImage
,
1466 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
1468 if (!EFI_ERROR(Status
)) {
1470 // If the image is not an app abort it.
1472 if (LoadedImage
->ImageCodeType
!= EfiLoaderCode
){
1477 STRING_TOKEN (STR_SHELL_IMAGE_NOT_APP
),
1478 ShellInfoObject
.HiiHandle
1483 ASSERT(LoadedImage
->LoadOptionsSize
== 0);
1484 if (NewCmdLine
!= NULL
) {
1485 LoadedImage
->LoadOptionsSize
= (UINT32
)StrSize(NewCmdLine
);
1486 LoadedImage
->LoadOptions
= (VOID
*)NewCmdLine
;
1490 // Save our current environment settings for later restoration if necessary
1492 if (Environment
!= NULL
) {
1493 Status
= GetEnvironmentVariableList(&OrigEnvs
);
1494 if (!EFI_ERROR(Status
)) {
1495 Status
= SetEnvironmentVariables(Environment
);
1500 // Initialize and install a shell parameters protocol on the image.
1502 ShellParamsProtocol
.StdIn
= ShellInfoObject
.NewShellParametersProtocol
->StdIn
;
1503 ShellParamsProtocol
.StdOut
= ShellInfoObject
.NewShellParametersProtocol
->StdOut
;
1504 ShellParamsProtocol
.StdErr
= ShellInfoObject
.NewShellParametersProtocol
->StdErr
;
1505 Status
= UpdateArgcArgv(&ShellParamsProtocol
, NewCmdLine
, Efi_Application
, NULL
, NULL
);
1506 ASSERT_EFI_ERROR(Status
);
1508 // Replace Argv[0] with the full path of the binary we're executing:
1509 // If the command line was "foo", the binary might be called "foo.efi".
1510 // "The first entry in [Argv] is always the full file path of the
1511 // executable" - UEFI Shell Spec section 2.3
1513 ImagePath
= EfiShellGetFilePathFromDevicePath (DevicePath
);
1514 // The image we're executing isn't necessarily in a filesystem - it might
1515 // be memory mapped. In this case EfiShellGetFilePathFromDevicePath will
1516 // return NULL, and we'll leave Argv[0] as UpdateArgcArgv set it.
1517 if (ImagePath
!= NULL
) {
1518 if (ShellParamsProtocol
.Argv
== NULL
) {
1519 // Command line was empty or null.
1520 // (UpdateArgcArgv sets Argv to NULL when CommandLine is "" or NULL)
1521 ShellParamsProtocol
.Argv
= AllocatePool (sizeof (CHAR16
*));
1522 if (ShellParamsProtocol
.Argv
== NULL
) {
1523 Status
= EFI_OUT_OF_RESOURCES
;
1526 ShellParamsProtocol
.Argc
= 1;
1528 // Free the string UpdateArgcArgv put in Argv[0];
1529 FreePool (ShellParamsProtocol
.Argv
[0]);
1531 ShellParamsProtocol
.Argv
[0] = ImagePath
;
1534 Status
= gBS
->InstallProtocolInterface(&NewHandle
, &gEfiShellParametersProtocolGuid
, EFI_NATIVE_INTERFACE
, &ShellParamsProtocol
);
1535 ASSERT_EFI_ERROR(Status
);
1537 ///@todo initialize and install ShellInterface protocol on the new image for compatibility if - PcdGetBool(PcdShellSupportOldProtocols)
1540 // now start the image and if the caller wanted the return code pass it to them...
1542 if (!EFI_ERROR(Status
)) {
1543 StartStatus
= gBS
->StartImage(
1548 if (StartImageStatus
!= NULL
) {
1549 *StartImageStatus
= StartStatus
;
1552 CleanupStatus
= gBS
->UninstallProtocolInterface(
1554 &gEfiShellParametersProtocolGuid
,
1555 &ShellParamsProtocol
1557 ASSERT_EFI_ERROR(CleanupStatus
);
1563 // Unload image - We should only get here if we didn't call StartImage
1564 gBS
->UnloadImage (NewHandle
);
1567 // Free Argv (Allocated in UpdateArgcArgv)
1568 if (ShellParamsProtocol
.Argv
!= NULL
) {
1569 for (Index
= 0; Index
< ShellParamsProtocol
.Argc
; Index
++) {
1570 if (ShellParamsProtocol
.Argv
[Index
] != NULL
) {
1571 FreePool (ShellParamsProtocol
.Argv
[Index
]);
1574 FreePool (ShellParamsProtocol
.Argv
);
1578 // Restore environment variables
1579 if (!IsListEmpty(&OrigEnvs
)) {
1580 CleanupStatus
= SetEnvironmentVariableList(&OrigEnvs
);
1581 ASSERT_EFI_ERROR (CleanupStatus
);
1584 FreePool (NewCmdLine
);
1590 internal worker function to load and run an image in the current shell.
1592 @param CommandLine Points to the NULL-terminated UCS-2 encoded string
1593 containing the command line. If NULL then the command-
1595 @param Environment Points to a NULL-terminated array of environment
1596 variables with the format 'x=y', where x is the
1597 environment variable name and y is the value. If this
1598 is NULL, then the current shell environment is used.
1600 @param[out] StartImageStatus Returned status from the command line.
1602 @retval EFI_SUCCESS The command executed successfully. The status code
1603 returned by the command is pointed to by StatusCode.
1604 @retval EFI_INVALID_PARAMETER The parameters are invalid.
1605 @retval EFI_OUT_OF_RESOURCES Out of resources.
1606 @retval EFI_UNSUPPORTED Nested shell invocations are not allowed.
1609 InternalShellExecute(
1610 IN CONST CHAR16
*CommandLine OPTIONAL
,
1611 IN CONST CHAR16
**Environment OPTIONAL
,
1612 OUT EFI_STATUS
*StartImageStatus OPTIONAL
1616 EFI_STATUS CleanupStatus
;
1617 LIST_ENTRY OrigEnvs
;
1619 InitializeListHead(&OrigEnvs
);
1622 // Save our current environment settings for later restoration if necessary
1624 if (Environment
!= NULL
) {
1625 Status
= GetEnvironmentVariableList(&OrigEnvs
);
1626 if (!EFI_ERROR(Status
)) {
1627 Status
= SetEnvironmentVariables(Environment
);
1633 Status
= RunShellCommand(CommandLine
, StartImageStatus
);
1635 // Restore environment variables
1636 if (!IsListEmpty(&OrigEnvs
)) {
1637 CleanupStatus
= SetEnvironmentVariableList(&OrigEnvs
);
1638 ASSERT_EFI_ERROR (CleanupStatus
);
1645 Determine if the UEFI Shell is currently running with nesting enabled or disabled.
1647 @retval FALSE nesting is required
1648 @retval other nesting is enabled
1666 if (ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.NoNest
) {
1669 Status
= SHELL_GET_ENVIRONMENT_VARIABLE(mNoNestingEnvVarName
, &TempSize
, Temp
);
1670 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1671 Temp
= AllocateZeroPool(TempSize
+ sizeof(CHAR16
));
1673 Status
= SHELL_GET_ENVIRONMENT_VARIABLE(mNoNestingEnvVarName
, &TempSize
, Temp
);
1676 Temp2
= StrnCatGrow(&Temp2
, NULL
, mNoNestingTrue
, 0);
1677 if (Temp
!= NULL
&& Temp2
!= NULL
&& StringNoCaseCompare(&Temp
, &Temp2
) == 0) {
1679 // Use the no nesting method.
1685 SHELL_FREE_NON_NULL(Temp
);
1686 SHELL_FREE_NON_NULL(Temp2
);
1691 Execute the command line.
1693 This function creates a nested instance of the shell and executes the specified
1694 command (CommandLine) with the specified environment (Environment). Upon return,
1695 the status code returned by the specified command is placed in StatusCode.
1697 If Environment is NULL, then the current environment is used and all changes made
1698 by the commands executed will be reflected in the current environment. If the
1699 Environment is non-NULL, then the changes made will be discarded.
1701 The CommandLine is executed from the current working directory on the current
1704 @param ParentImageHandle A handle of the image that is executing the specified
1706 @param CommandLine Points to the NULL-terminated UCS-2 encoded string
1707 containing the command line. If NULL then the command-
1709 @param Environment Points to a NULL-terminated array of environment
1710 variables with the format 'x=y', where x is the
1711 environment variable name and y is the value. If this
1712 is NULL, then the current shell environment is used.
1713 @param StatusCode Points to the status code returned by the CommandLine.
1715 @retval EFI_SUCCESS The command executed successfully. The status code
1716 returned by the command is pointed to by StatusCode.
1717 @retval EFI_INVALID_PARAMETER The parameters are invalid.
1718 @retval EFI_OUT_OF_RESOURCES Out of resources.
1719 @retval EFI_UNSUPPORTED Nested shell invocations are not allowed.
1720 @retval EFI_UNSUPPORTED The support level required for this function is not present.
1722 @sa InternalShellExecuteDevicePath
1727 IN EFI_HANDLE
*ParentImageHandle
,
1728 IN CHAR16
*CommandLine OPTIONAL
,
1729 IN CHAR16
**Environment OPTIONAL
,
1730 OUT EFI_STATUS
*StatusCode OPTIONAL
1735 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
1738 if ((PcdGet8(PcdShellSupportLevel
) < 1)) {
1739 return (EFI_UNSUPPORTED
);
1742 if (NestingEnabled()) {
1743 DevPath
= AppendDevicePath (ShellInfoObject
.ImageDevPath
, ShellInfoObject
.FileDevPath
);
1746 Temp
= ConvertDevicePathToText(ShellInfoObject
.FileDevPath
, TRUE
, TRUE
);
1748 Temp
= ConvertDevicePathToText(ShellInfoObject
.ImageDevPath
, TRUE
, TRUE
);
1750 Temp
= ConvertDevicePathToText(DevPath
, TRUE
, TRUE
);
1756 ASSERT((Temp
== NULL
&& Size
== 0) || (Temp
!= NULL
));
1757 StrnCatGrow(&Temp
, &Size
, L
"Shell.efi -exit ", 0);
1758 StrnCatGrow(&Temp
, &Size
, CommandLine
, 0);
1760 Status
= InternalShellExecuteDevicePath(
1764 (CONST CHAR16
**)Environment
,
1768 // de-allocate and return
1773 Status
= InternalShellExecute(
1774 (CONST CHAR16
*)CommandLine
,
1775 (CONST CHAR16
**)Environment
,
1783 Utility cleanup function for EFI_SHELL_FILE_INFO objects.
1785 1) frees all pointers (non-NULL)
1786 2) Closes the SHELL_FILE_HANDLE
1788 @param FileListNode pointer to the list node to free
1791 InternalFreeShellFileInfoNode(
1792 IN EFI_SHELL_FILE_INFO
*FileListNode
1795 if (FileListNode
->Info
!= NULL
) {
1796 FreePool((VOID
*)FileListNode
->Info
);
1798 if (FileListNode
->FileName
!= NULL
) {
1799 FreePool((VOID
*)FileListNode
->FileName
);
1801 if (FileListNode
->FullName
!= NULL
) {
1802 FreePool((VOID
*)FileListNode
->FullName
);
1804 if (FileListNode
->Handle
!= NULL
) {
1805 ShellInfoObject
.NewEfiShellProtocol
->CloseFile(FileListNode
->Handle
);
1807 FreePool(FileListNode
);
1810 Frees the file list.
1812 This function cleans up the file list and any related data structures. It has no
1813 impact on the files themselves.
1815 @param FileList The file list to free. Type EFI_SHELL_FILE_INFO is
1816 defined in OpenFileList()
1818 @retval EFI_SUCCESS Free the file list successfully.
1819 @retval EFI_INVALID_PARAMETER FileList was NULL or *FileList was NULL;
1823 EfiShellFreeFileList(
1824 IN EFI_SHELL_FILE_INFO
**FileList
1827 EFI_SHELL_FILE_INFO
*ShellFileListItem
;
1829 if (FileList
== NULL
|| *FileList
== NULL
) {
1830 return (EFI_INVALID_PARAMETER
);
1833 for ( ShellFileListItem
= (EFI_SHELL_FILE_INFO
*)GetFirstNode(&(*FileList
)->Link
)
1834 ; !IsListEmpty(&(*FileList
)->Link
)
1835 ; ShellFileListItem
= (EFI_SHELL_FILE_INFO
*)GetFirstNode(&(*FileList
)->Link
)
1837 RemoveEntryList(&ShellFileListItem
->Link
);
1838 InternalFreeShellFileInfoNode(ShellFileListItem
);
1840 InternalFreeShellFileInfoNode(*FileList
);
1842 return(EFI_SUCCESS
);
1846 Deletes the duplicate file names files in the given file list.
1848 This function deletes the reduplicate files in the given file list.
1850 @param FileList A pointer to the first entry in the file list.
1852 @retval EFI_SUCCESS Always success.
1853 @retval EFI_INVALID_PARAMETER FileList was NULL or *FileList was NULL;
1857 EfiShellRemoveDupInFileList(
1858 IN EFI_SHELL_FILE_INFO
**FileList
1861 EFI_SHELL_FILE_INFO
*ShellFileListItem
;
1862 EFI_SHELL_FILE_INFO
*ShellFileListItem2
;
1863 EFI_SHELL_FILE_INFO
*TempNode
;
1865 if (FileList
== NULL
|| *FileList
== NULL
) {
1866 return (EFI_INVALID_PARAMETER
);
1868 for ( ShellFileListItem
= (EFI_SHELL_FILE_INFO
*)GetFirstNode(&(*FileList
)->Link
)
1869 ; !IsNull(&(*FileList
)->Link
, &ShellFileListItem
->Link
)
1870 ; ShellFileListItem
= (EFI_SHELL_FILE_INFO
*)GetNextNode(&(*FileList
)->Link
, &ShellFileListItem
->Link
)
1872 for ( ShellFileListItem2
= (EFI_SHELL_FILE_INFO
*)GetNextNode(&(*FileList
)->Link
, &ShellFileListItem
->Link
)
1873 ; !IsNull(&(*FileList
)->Link
, &ShellFileListItem2
->Link
)
1874 ; ShellFileListItem2
= (EFI_SHELL_FILE_INFO
*)GetNextNode(&(*FileList
)->Link
, &ShellFileListItem2
->Link
)
1876 if (gUnicodeCollation
->StriColl(
1878 (CHAR16
*)ShellFileListItem
->FullName
,
1879 (CHAR16
*)ShellFileListItem2
->FullName
) == 0
1881 TempNode
= (EFI_SHELL_FILE_INFO
*)GetPreviousNode(
1883 &ShellFileListItem2
->Link
1885 RemoveEntryList(&ShellFileListItem2
->Link
);
1886 InternalFreeShellFileInfoNode(ShellFileListItem2
);
1887 // Set ShellFileListItem2 to PreviousNode so we don't access Freed
1888 // memory in GetNextNode in the loop expression above.
1889 ShellFileListItem2
= TempNode
;
1893 return (EFI_SUCCESS
);
1897 // This is the same structure as the external version, but it has no CONST qualifiers.
1900 LIST_ENTRY Link
; ///< Linked list members.
1901 EFI_STATUS Status
; ///< Status of opening the file. Valid only if Handle != NULL.
1902 CHAR16
*FullName
; ///< Fully qualified filename.
1903 CHAR16
*FileName
; ///< name of this file.
1904 SHELL_FILE_HANDLE Handle
; ///< Handle for interacting with the opened file or NULL if closed.
1905 EFI_FILE_INFO
*Info
; ///< Pointer to the FileInfo struct for this file or NULL.
1906 } EFI_SHELL_FILE_INFO_NO_CONST
;
1909 Allocates and duplicates a EFI_SHELL_FILE_INFO node.
1911 @param[in] Node The node to copy from.
1912 @param[in] Save TRUE to set Node->Handle to NULL, FALSE otherwise.
1914 @retval NULL a memory allocation error ocurred
1915 @return != NULL a pointer to the new node
1917 EFI_SHELL_FILE_INFO
*
1918 InternalDuplicateShellFileInfo(
1919 IN EFI_SHELL_FILE_INFO
*Node
,
1923 EFI_SHELL_FILE_INFO_NO_CONST
*NewNode
;
1926 // try to confirm that the objects are in sync
1928 ASSERT(sizeof(EFI_SHELL_FILE_INFO_NO_CONST
) == sizeof(EFI_SHELL_FILE_INFO
));
1930 NewNode
= AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO
));
1931 if (NewNode
== NULL
) {
1934 NewNode
->FullName
= AllocateCopyPool(StrSize(Node
->FullName
), Node
->FullName
);
1935 NewNode
->FileName
= AllocateCopyPool(StrSize(Node
->FileName
), Node
->FileName
);
1936 NewNode
->Info
= AllocateCopyPool((UINTN
)Node
->Info
->Size
, Node
->Info
);
1937 if ( NewNode
->FullName
== NULL
1938 || NewNode
->FileName
== NULL
1939 || NewNode
->Info
== NULL
1941 SHELL_FREE_NON_NULL(NewNode
->FullName
);
1942 SHELL_FREE_NON_NULL(NewNode
->FileName
);
1943 SHELL_FREE_NON_NULL(NewNode
->Info
);
1944 SHELL_FREE_NON_NULL(NewNode
);
1947 NewNode
->Status
= Node
->Status
;
1948 NewNode
->Handle
= Node
->Handle
;
1950 Node
->Handle
= NULL
;
1953 return((EFI_SHELL_FILE_INFO
*)NewNode
);
1957 Allocates and populates a EFI_SHELL_FILE_INFO structure. if any memory operation
1958 failed it will return NULL.
1960 @param[in] BasePath the Path to prepend onto filename for FullPath
1961 @param[in] Status Status member initial value.
1962 @param[in] FileName FileName member initial value.
1963 @param[in] Handle Handle member initial value.
1964 @param[in] Info Info struct to copy.
1966 @retval NULL An error ocurred.
1967 @return a pointer to the newly allocated structure.
1969 EFI_SHELL_FILE_INFO
*
1970 CreateAndPopulateShellFileInfo(
1971 IN CONST CHAR16
*BasePath
,
1972 IN CONST EFI_STATUS Status
,
1973 IN CONST CHAR16
*FileName
,
1974 IN CONST SHELL_FILE_HANDLE Handle
,
1975 IN CONST EFI_FILE_INFO
*Info
1978 EFI_SHELL_FILE_INFO
*ShellFileListItem
;
1985 ShellFileListItem
= AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO
));
1986 if (ShellFileListItem
== NULL
) {
1989 if (Info
!= NULL
&& Info
->Size
!= 0) {
1990 ShellFileListItem
->Info
= AllocateZeroPool((UINTN
)Info
->Size
);
1991 if (ShellFileListItem
->Info
== NULL
) {
1992 FreePool(ShellFileListItem
);
1995 CopyMem(ShellFileListItem
->Info
, Info
, (UINTN
)Info
->Size
);
1997 ShellFileListItem
->Info
= NULL
;
1999 if (FileName
!= NULL
) {
2000 ASSERT(TempString
== NULL
);
2001 ShellFileListItem
->FileName
= StrnCatGrow(&TempString
, 0, FileName
, 0);
2002 if (ShellFileListItem
->FileName
== NULL
) {
2003 FreePool(ShellFileListItem
->Info
);
2004 FreePool(ShellFileListItem
);
2008 ShellFileListItem
->FileName
= NULL
;
2012 if (BasePath
!= NULL
) {
2013 ASSERT((TempString
== NULL
&& Size
== 0) || (TempString
!= NULL
));
2014 TempString
= StrnCatGrow(&TempString
, &Size
, BasePath
, 0);
2015 if (TempString
== NULL
) {
2016 FreePool((VOID
*)ShellFileListItem
->FileName
);
2017 SHELL_FREE_NON_NULL(ShellFileListItem
->Info
);
2018 FreePool(ShellFileListItem
);
2022 if (ShellFileListItem
->FileName
!= NULL
) {
2023 ASSERT((TempString
== NULL
&& Size
== 0) || (TempString
!= NULL
));
2024 TempString
= StrnCatGrow(&TempString
, &Size
, ShellFileListItem
->FileName
, 0);
2025 if (TempString
== NULL
) {
2026 FreePool((VOID
*)ShellFileListItem
->FileName
);
2027 FreePool(ShellFileListItem
->Info
);
2028 FreePool(ShellFileListItem
);
2033 TempString
= PathCleanUpDirectories(TempString
);
2035 ShellFileListItem
->FullName
= TempString
;
2036 ShellFileListItem
->Status
= Status
;
2037 ShellFileListItem
->Handle
= Handle
;
2039 return (ShellFileListItem
);
2043 Find all files in a specified directory.
2045 @param FileDirHandle Handle of the directory to search.
2046 @param FileList On return, points to the list of files in the directory
2047 or NULL if there are no files in the directory.
2049 @retval EFI_SUCCESS File information was returned successfully.
2050 @retval EFI_VOLUME_CORRUPTED The file system structures have been corrupted.
2051 @retval EFI_DEVICE_ERROR The device reported an error.
2052 @retval EFI_NO_MEDIA The device media is not present.
2053 @retval EFI_INVALID_PARAMETER The FileDirHandle was not a directory.
2054 @return An error from FileHandleGetFileName().
2058 EfiShellFindFilesInDir(
2059 IN SHELL_FILE_HANDLE FileDirHandle
,
2060 OUT EFI_SHELL_FILE_INFO
**FileList
2063 EFI_SHELL_FILE_INFO
*ShellFileList
;
2064 EFI_SHELL_FILE_INFO
*ShellFileListItem
;
2065 EFI_FILE_INFO
*FileInfo
;
2074 Status
= FileHandleGetFileName(FileDirHandle
, &BasePath
);
2075 if (EFI_ERROR(Status
)) {
2079 if (ShellFileHandleGetPath(FileDirHandle
) != NULL
) {
2082 TempString
= StrnCatGrow(&TempString
, &Size
, ShellFileHandleGetPath(FileDirHandle
), 0);
2083 if (TempString
== NULL
) {
2084 SHELL_FREE_NON_NULL(BasePath
);
2085 return (EFI_OUT_OF_RESOURCES
);
2087 TempSpot
= StrStr(TempString
, L
";");
2089 if (TempSpot
!= NULL
) {
2090 *TempSpot
= CHAR_NULL
;
2093 TempString
= StrnCatGrow(&TempString
, &Size
, BasePath
, 0);
2094 if (TempString
== NULL
) {
2095 SHELL_FREE_NON_NULL(BasePath
);
2096 return (EFI_OUT_OF_RESOURCES
);
2098 SHELL_FREE_NON_NULL(BasePath
);
2099 BasePath
= TempString
;
2103 ShellFileList
= NULL
;
2104 ShellFileListItem
= NULL
;
2106 Status
= EFI_SUCCESS
;
2109 for ( Status
= FileHandleFindFirstFile(FileDirHandle
, &FileInfo
)
2110 ; !EFI_ERROR(Status
) && !NoFile
2111 ; Status
= FileHandleFindNextFile(FileDirHandle
, FileInfo
, &NoFile
)
2113 if (ShellFileList
== NULL
) {
2114 ShellFileList
= (EFI_SHELL_FILE_INFO
*)AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO
));
2115 if (ShellFileList
== NULL
) {
2116 SHELL_FREE_NON_NULL (BasePath
);
2117 return EFI_OUT_OF_RESOURCES
;
2119 InitializeListHead(&ShellFileList
->Link
);
2122 // allocate a new EFI_SHELL_FILE_INFO and populate it...
2124 ShellFileListItem
= CreateAndPopulateShellFileInfo(
2126 EFI_SUCCESS
, // success since we didnt fail to open it...
2128 NULL
, // no handle since not open
2130 if (ShellFileListItem
== NULL
) {
2131 Status
= EFI_OUT_OF_RESOURCES
;
2133 // Free resources outside the loop.
2137 InsertTailList(&ShellFileList
->Link
, &ShellFileListItem
->Link
);
2139 if (EFI_ERROR(Status
)) {
2140 EfiShellFreeFileList(&ShellFileList
);
2143 *FileList
= ShellFileList
;
2145 SHELL_FREE_NON_NULL(BasePath
);
2150 Get the GUID value from a human readable name.
2152 If GuidName is a known GUID name, then update Guid to have the correct value for
2155 This function is only available when the major and minor versions in the
2156 EfiShellProtocol are greater than or equal to 2 and 1, respectively.
2158 @param[in] GuidName A pointer to the localized name for the GUID being queried.
2159 @param[out] Guid A pointer to the GUID structure to be filled in.
2161 @retval EFI_SUCCESS The operation was successful.
2162 @retval EFI_INVALID_PARAMETER Guid was NULL.
2163 @retval EFI_INVALID_PARAMETER GuidName was NULL.
2164 @retval EFI_NOT_FOUND GuidName is not a known GUID Name.
2168 EfiShellGetGuidFromName(
2169 IN CONST CHAR16
*GuidName
,
2176 if (Guid
== NULL
|| GuidName
== NULL
) {
2177 return (EFI_INVALID_PARAMETER
);
2180 Status
= GetGuidFromStringName(GuidName
, NULL
, &NewGuid
);
2182 if (!EFI_ERROR(Status
)) {
2183 CopyGuid(Guid
, NewGuid
);
2190 Get the human readable name for a GUID from the value.
2192 If Guid is assigned a name, then update *GuidName to point to the name. The callee
2193 should not modify the value.
2195 This function is only available when the major and minor versions in the
2196 EfiShellProtocol are greater than or equal to 2 and 1, respectively.
2198 @param[in] Guid A pointer to the GUID being queried.
2199 @param[out] GuidName A pointer to a pointer the localized to name for the GUID being requested
2201 @retval EFI_SUCCESS The operation was successful.
2202 @retval EFI_INVALID_PARAMETER Guid was NULL.
2203 @retval EFI_INVALID_PARAMETER GuidName was NULL.
2204 @retval EFI_NOT_FOUND Guid is not assigned a name.
2208 EfiShellGetGuidName(
2209 IN CONST EFI_GUID
*Guid
,
2210 OUT CONST CHAR16
**GuidName
2215 if (Guid
== NULL
|| GuidName
== NULL
) {
2216 return (EFI_INVALID_PARAMETER
);
2219 Name
= GetStringNameFromGuid(Guid
, NULL
);
2220 if (Name
== NULL
|| StrLen(Name
) == 0) {
2221 SHELL_FREE_NON_NULL(Name
);
2222 return (EFI_NOT_FOUND
);
2225 *GuidName
= AddBufferToFreeList(Name
);
2227 return (EFI_SUCCESS
);
2233 If FileHandle is a directory then the function reads from FileHandle and reads in
2234 each of the FileInfo structures. If one of them matches the Pattern's first
2235 "level" then it opens that handle and calls itself on that handle.
2237 If FileHandle is a file and matches all of the remaining Pattern (which would be
2238 on its last node), then add a EFI_SHELL_FILE_INFO object for this file to fileList.
2240 Upon a EFI_SUCCESS return fromt he function any the caller is responsible to call
2241 FreeFileList with FileList.
2243 @param[in] FilePattern The FilePattern to check against.
2244 @param[in] UnicodeCollation The pointer to EFI_UNICODE_COLLATION_PROTOCOL structure
2245 @param[in] FileHandle The FileHandle to start with
2246 @param[in, out] FileList pointer to pointer to list of found files.
2247 @param[in] ParentNode The node for the parent. Same file as identified by HANDLE.
2248 @param[in] MapName The file system name this file is on.
2250 @retval EFI_SUCCESS all files were found and the FileList contains a list.
2251 @retval EFI_NOT_FOUND no files were found
2252 @retval EFI_OUT_OF_RESOURCES a memory allocation failed
2256 IN CONST CHAR16
*FilePattern
,
2257 IN EFI_UNICODE_COLLATION_PROTOCOL
*UnicodeCollation
,
2258 IN SHELL_FILE_HANDLE FileHandle
,
2259 IN OUT EFI_SHELL_FILE_INFO
**FileList
,
2260 IN CONST EFI_SHELL_FILE_INFO
*ParentNode OPTIONAL
,
2261 IN CONST CHAR16
*MapName
2265 CONST CHAR16
*NextFilePatternStart
;
2266 CHAR16
*CurrentFilePattern
;
2267 EFI_SHELL_FILE_INFO
*ShellInfo
;
2268 EFI_SHELL_FILE_INFO
*ShellInfoNode
;
2269 EFI_SHELL_FILE_INFO
*NewShellNode
;
2270 EFI_FILE_INFO
*FileInfo
;
2272 CHAR16
*NewFullName
;
2275 if ( FilePattern
== NULL
2276 || UnicodeCollation
== NULL
2279 return (EFI_INVALID_PARAMETER
);
2282 CurrentFilePattern
= NULL
;
2284 if (*FilePattern
== L
'\\') {
2288 for( NextFilePatternStart
= FilePattern
2289 ; *NextFilePatternStart
!= CHAR_NULL
&& *NextFilePatternStart
!= L
'\\'
2290 ; NextFilePatternStart
++);
2292 CurrentFilePattern
= AllocateZeroPool((NextFilePatternStart
-FilePattern
+1)*sizeof(CHAR16
));
2293 if (CurrentFilePattern
== NULL
) {
2294 return EFI_OUT_OF_RESOURCES
;
2297 StrnCpyS(CurrentFilePattern
, NextFilePatternStart
-FilePattern
+1, FilePattern
, NextFilePatternStart
-FilePattern
);
2299 if (CurrentFilePattern
[0] == CHAR_NULL
2300 &&NextFilePatternStart
[0] == CHAR_NULL
2303 // we want the parent or root node (if no parent)
2305 if (ParentNode
== NULL
) {
2307 // We want the root node. create the node.
2309 FileInfo
= FileHandleGetInfo(FileHandle
);
2310 NewShellNode
= CreateAndPopulateShellFileInfo(
2317 SHELL_FREE_NON_NULL(FileInfo
);
2320 // Add the current parameter FileHandle to the list, then end...
2322 NewShellNode
= InternalDuplicateShellFileInfo((EFI_SHELL_FILE_INFO
*)ParentNode
, TRUE
);
2324 if (NewShellNode
== NULL
) {
2325 Status
= EFI_OUT_OF_RESOURCES
;
2327 NewShellNode
->Handle
= NULL
;
2328 if (*FileList
== NULL
) {
2329 *FileList
= AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO
));
2330 InitializeListHead(&((*FileList
)->Link
));
2334 // Add to the returning to use list
2336 InsertTailList(&(*FileList
)->Link
, &NewShellNode
->Link
);
2338 Status
= EFI_SUCCESS
;
2341 Status
= EfiShellFindFilesInDir(FileHandle
, &ShellInfo
);
2343 if (!EFI_ERROR(Status
)){
2344 if (StrStr(NextFilePatternStart
, L
"\\") != NULL
){
2349 for ( ShellInfoNode
= (EFI_SHELL_FILE_INFO
*)GetFirstNode(&ShellInfo
->Link
)
2350 ; !IsNull (&ShellInfo
->Link
, &ShellInfoNode
->Link
)
2351 ; ShellInfoNode
= (EFI_SHELL_FILE_INFO
*)GetNextNode(&ShellInfo
->Link
, &ShellInfoNode
->Link
)
2353 if (UnicodeCollation
->MetaiMatch(UnicodeCollation
, (CHAR16
*)ShellInfoNode
->FileName
, CurrentFilePattern
)){
2354 if (ShellInfoNode
->FullName
!= NULL
&& StrStr(ShellInfoNode
->FullName
, L
":") == NULL
) {
2355 Size
= StrSize (ShellInfoNode
->FullName
) + StrSize (MapName
);
2356 NewFullName
= AllocateZeroPool(Size
);
2357 if (NewFullName
== NULL
) {
2358 Status
= EFI_OUT_OF_RESOURCES
;
2360 StrCpyS(NewFullName
, Size
/ sizeof(CHAR16
), MapName
);
2361 StrCatS(NewFullName
, Size
/ sizeof(CHAR16
), ShellInfoNode
->FullName
);
2362 FreePool ((VOID
*) ShellInfoNode
->FullName
);
2363 ShellInfoNode
->FullName
= NewFullName
;
2366 if (Directory
&& !EFI_ERROR(Status
) && ShellInfoNode
->FullName
!= NULL
&& ShellInfoNode
->FileName
!= NULL
){
2368 // should be a directory
2372 // don't open the . and .. directories
2374 if ( (StrCmp(ShellInfoNode
->FileName
, L
".") != 0)
2375 && (StrCmp(ShellInfoNode
->FileName
, L
"..") != 0)
2380 if (EFI_ERROR(Status
)) {
2384 // Open the directory since we need that handle in the next recursion.
2386 ShellInfoNode
->Status
= EfiShellOpenFileByName (ShellInfoNode
->FullName
, &ShellInfoNode
->Handle
, EFI_FILE_MODE_READ
);
2389 // recurse with the next part of the pattern
2391 Status
= ShellSearchHandle(NextFilePatternStart
, UnicodeCollation
, ShellInfoNode
->Handle
, FileList
, ShellInfoNode
, MapName
);
2392 EfiShellClose(ShellInfoNode
->Handle
);
2393 ShellInfoNode
->Handle
= NULL
;
2395 } else if (!EFI_ERROR(Status
)) {
2401 // copy the information we need into a new Node
2403 NewShellNode
= InternalDuplicateShellFileInfo(ShellInfoNode
, FALSE
);
2404 if (NewShellNode
== NULL
) {
2405 Status
= EFI_OUT_OF_RESOURCES
;
2407 if (*FileList
== NULL
) {
2408 *FileList
= AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO
));
2409 InitializeListHead(&((*FileList
)->Link
));
2413 // Add to the returning to use list
2415 InsertTailList(&(*FileList
)->Link
, &NewShellNode
->Link
);
2418 if (EFI_ERROR(Status
)) {
2422 if (EFI_ERROR(Status
)) {
2423 EfiShellFreeFileList(&ShellInfo
);
2425 Status
= EfiShellFreeFileList(&ShellInfo
);
2430 if (*FileList
== NULL
|| (*FileList
!= NULL
&& IsListEmpty(&(*FileList
)->Link
))) {
2431 Status
= EFI_NOT_FOUND
;
2434 FreePool(CurrentFilePattern
);
2439 Find files that match a specified pattern.
2441 This function searches for all files and directories that match the specified
2442 FilePattern. The FilePattern can contain wild-card characters. The resulting file
2443 information is placed in the file list FileList.
2445 Wildcards are processed
2446 according to the rules specified in UEFI Shell 2.0 spec section 3.7.1.
2448 The files in the file list are not opened. The OpenMode field is set to 0 and the FileInfo
2449 field is set to NULL.
2451 if *FileList is not NULL then it must be a pre-existing and properly initialized list.
2453 @param FilePattern Points to a NULL-terminated shell file path, including wildcards.
2454 @param FileList On return, points to the start of a file list containing the names
2455 of all matching files or else points to NULL if no matching files
2456 were found. only on a EFI_SUCCESS return will; this be non-NULL.
2458 @retval EFI_SUCCESS Files found. FileList is a valid list.
2459 @retval EFI_NOT_FOUND No files found.
2460 @retval EFI_NO_MEDIA The device has no media
2461 @retval EFI_DEVICE_ERROR The device reported an error
2462 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted
2467 IN CONST CHAR16
*FilePattern
,
2468 OUT EFI_SHELL_FILE_INFO
**FileList
2472 CHAR16
*PatternCopy
;
2473 CHAR16
*PatternCurrentLocation
;
2474 EFI_DEVICE_PATH_PROTOCOL
*RootDevicePath
;
2475 SHELL_FILE_HANDLE RootFileHandle
;
2479 if ( FilePattern
== NULL
2481 || StrStr(FilePattern
, L
":") == NULL
2483 return (EFI_INVALID_PARAMETER
);
2485 Status
= EFI_SUCCESS
;
2486 RootDevicePath
= NULL
;
2487 RootFileHandle
= NULL
;
2489 PatternCopy
= AllocateCopyPool(StrSize(FilePattern
), FilePattern
);
2490 if (PatternCopy
== NULL
) {
2491 return (EFI_OUT_OF_RESOURCES
);
2494 PatternCopy
= PathCleanUpDirectories(PatternCopy
);
2496 Count
= StrStr(PatternCopy
, L
":") - PatternCopy
+ 1;
2497 ASSERT (Count
<= StrLen (PatternCopy
));
2499 ASSERT(MapName
== NULL
);
2500 MapName
= StrnCatGrow(&MapName
, NULL
, PatternCopy
, Count
);
2501 if (MapName
== NULL
) {
2502 Status
= EFI_OUT_OF_RESOURCES
;
2504 RootDevicePath
= EfiShellGetDevicePathFromFilePath(PatternCopy
);
2505 if (RootDevicePath
== NULL
) {
2506 Status
= EFI_INVALID_PARAMETER
;
2508 Status
= EfiShellOpenRoot(RootDevicePath
, &RootFileHandle
);
2509 if (!EFI_ERROR(Status
)) {
2510 for ( PatternCurrentLocation
= PatternCopy
2511 ; *PatternCurrentLocation
!= ':'
2512 ; PatternCurrentLocation
++);
2513 PatternCurrentLocation
++;
2514 Status
= ShellSearchHandle(PatternCurrentLocation
, gUnicodeCollation
, RootFileHandle
, FileList
, NULL
, MapName
);
2515 EfiShellClose(RootFileHandle
);
2517 FreePool(RootDevicePath
);
2521 SHELL_FREE_NON_NULL(PatternCopy
);
2522 SHELL_FREE_NON_NULL(MapName
);
2528 Opens the files that match the path specified.
2530 This function opens all of the files specified by Path. Wildcards are processed
2531 according to the rules specified in UEFI Shell 2.0 spec section 3.7.1. Each
2532 matching file has an EFI_SHELL_FILE_INFO structure created in a linked list.
2534 @param Path A pointer to the path string.
2535 @param OpenMode Specifies the mode used to open each file, EFI_FILE_MODE_READ or
2536 EFI_FILE_MODE_WRITE.
2537 @param FileList Points to the start of a list of files opened.
2539 @retval EFI_SUCCESS Create the file list successfully.
2540 @return Others Can't create the file list.
2544 EfiShellOpenFileList(
2547 IN OUT EFI_SHELL_FILE_INFO
**FileList
2551 EFI_SHELL_FILE_INFO
*ShellFileListItem
;
2554 CONST CHAR16
*CurDir
;
2557 PathCleanUpDirectories(Path
);
2562 if (FileList
== NULL
|| *FileList
== NULL
) {
2563 return (EFI_INVALID_PARAMETER
);
2566 if (*Path
== L
'.' && *(Path
+1) == L
'\\') {
2571 // convert a local path to an absolute path
2573 if (StrStr(Path
, L
":") == NULL
) {
2574 CurDir
= EfiShellGetCurDir(NULL
);
2575 ASSERT((Path2
== NULL
&& Path2Size
== 0) || (Path2
!= NULL
));
2576 StrnCatGrow(&Path2
, &Path2Size
, CurDir
, 0);
2577 StrnCatGrow(&Path2
, &Path2Size
, L
"\\", 0);
2578 if (*Path
== L
'\\') {
2580 while (PathRemoveLastItem(Path2
)) ;
2582 ASSERT((Path2
== NULL
&& Path2Size
== 0) || (Path2
!= NULL
));
2583 StrnCatGrow(&Path2
, &Path2Size
, Path
, 0);
2585 ASSERT(Path2
== NULL
);
2586 StrnCatGrow(&Path2
, NULL
, Path
, 0);
2589 PathCleanUpDirectories (Path2
);
2594 Status
= EfiShellFindFiles(Path2
, FileList
);
2598 if (EFI_ERROR(Status
)) {
2604 // We had no errors so open all the files (that are not already opened...)
2606 for ( ShellFileListItem
= (EFI_SHELL_FILE_INFO
*)GetFirstNode(&(*FileList
)->Link
)
2607 ; !IsNull(&(*FileList
)->Link
, &ShellFileListItem
->Link
)
2608 ; ShellFileListItem
= (EFI_SHELL_FILE_INFO
*)GetNextNode(&(*FileList
)->Link
, &ShellFileListItem
->Link
)
2610 if (ShellFileListItem
->Status
== 0 && ShellFileListItem
->Handle
== NULL
) {
2611 ShellFileListItem
->Status
= EfiShellOpenFileByName (ShellFileListItem
->FullName
, &ShellFileListItem
->Handle
, OpenMode
);
2617 return (EFI_NOT_FOUND
);
2619 return(EFI_SUCCESS
);
2623 Gets the environment variable and Attributes, or list of environment variables. Can be
2624 used instead of GetEnv().
2626 This function returns the current value of the specified environment variable and
2627 the Attributes. If no variable name was specified, then all of the known
2628 variables will be returned.
2630 @param[in] Name A pointer to the environment variable name. If Name is NULL,
2631 then the function will return all of the defined shell
2632 environment variables. In the case where multiple environment
2633 variables are being returned, each variable will be terminated
2634 by a NULL, and the list will be terminated by a double NULL.
2635 @param[out] Attributes If not NULL, a pointer to the returned attributes bitmask for
2636 the environment variable. In the case where Name is NULL, and
2637 multiple environment variables are being returned, Attributes
2640 @retval NULL The environment variable doesn't exist.
2641 @return A non-NULL value points to the variable's value. The returned
2642 pointer does not need to be freed by the caller.
2647 IN CONST CHAR16
*Name
,
2648 OUT UINT32
*Attributes OPTIONAL
2655 CHAR16
*CurrentWriteLocation
;
2663 // Build the semi-colon delimited list. (2 passes)
2665 for ( Node
= (ENV_VAR_LIST
*)GetFirstNode(&gShellEnvVarList
.Link
)
2666 ; !IsNull(&gShellEnvVarList
.Link
, &Node
->Link
)
2667 ; Node
= (ENV_VAR_LIST
*)GetNextNode(&gShellEnvVarList
.Link
, &Node
->Link
)
2669 ASSERT(Node
->Key
!= NULL
);
2670 Size
+= StrSize(Node
->Key
);
2673 Size
+= 2*sizeof(CHAR16
);
2675 Buffer
= AllocateZeroPool(Size
);
2676 if (Buffer
== NULL
) {
2679 CurrentWriteLocation
= (CHAR16
*)Buffer
;
2681 for ( Node
= (ENV_VAR_LIST
*)GetFirstNode(&gShellEnvVarList
.Link
)
2682 ; !IsNull(&gShellEnvVarList
.Link
, &Node
->Link
)
2683 ; Node
= (ENV_VAR_LIST
*)GetNextNode(&gShellEnvVarList
.Link
, &Node
->Link
)
2685 ASSERT(Node
->Key
!= NULL
);
2686 StrCpyS( CurrentWriteLocation
,
2687 (Size
)/sizeof(CHAR16
) - (CurrentWriteLocation
- ((CHAR16
*)Buffer
)),
2690 CurrentWriteLocation
+= StrLen(CurrentWriteLocation
) + 1;
2695 // We are doing a specific environment variable
2697 Status
= ShellFindEnvVarInList(Name
, (CHAR16
**)&Buffer
, &Size
, Attributes
);
2699 if (EFI_ERROR(Status
)){
2701 // get the size we need for this EnvVariable
2703 Status
= SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(Name
, Attributes
, &Size
, Buffer
);
2704 if (Status
== EFI_BUFFER_TOO_SMALL
) {
2706 // Allocate the space and recall the get function
2708 Buffer
= AllocateZeroPool(Size
);
2709 Status
= SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(Name
, Attributes
, &Size
, Buffer
);
2712 // we didnt get it (might not exist)
2713 // free the memory if we allocated any and return NULL
2715 if (EFI_ERROR(Status
)) {
2716 if (Buffer
!= NULL
) {
2722 // If we did not find the environment variable in the gShellEnvVarList
2723 // but get it from UEFI variable storage successfully then we need update
2724 // the gShellEnvVarList.
2726 ShellFreeEnvVarList ();
2727 Status
= ShellInitEnvVarList ();
2728 ASSERT (Status
== EFI_SUCCESS
);
2734 // return the buffer
2736 return (AddBufferToFreeList(Buffer
));
2740 Gets either a single or list of environment variables.
2742 If name is not NULL then this function returns the current value of the specified
2743 environment variable.
2745 If Name is NULL, then a list of all environment variable names is returned. Each is a
2746 NULL terminated string with a double NULL terminating the list.
2748 @param Name A pointer to the environment variable name. If
2749 Name is NULL, then the function will return all
2750 of the defined shell environment variables. In
2751 the case where multiple environment variables are
2752 being returned, each variable will be terminated by
2753 a NULL, and the list will be terminated by a double
2756 @retval !=NULL A pointer to the returned string.
2757 The returned pointer does not need to be freed by the caller.
2759 @retval NULL The environment variable doesn't exist or there are
2760 no environment variables.
2765 IN CONST CHAR16
*Name
2768 return (EfiShellGetEnvEx(Name
, NULL
));
2772 Internal variable setting function. Allows for setting of the read only variables.
2774 @param Name Points to the NULL-terminated environment variable name.
2775 @param Value Points to the NULL-terminated environment variable value. If the value is an
2776 empty string then the environment variable is deleted.
2777 @param Volatile Indicates whether the variable is non-volatile (FALSE) or volatile (TRUE).
2779 @retval EFI_SUCCESS The environment variable was successfully updated.
2782 InternalEfiShellSetEnv(
2783 IN CONST CHAR16
*Name
,
2784 IN CONST CHAR16
*Value
,
2790 if (Value
== NULL
|| StrLen(Value
) == 0) {
2791 Status
= SHELL_DELETE_ENVIRONMENT_VARIABLE(Name
);
2792 if (!EFI_ERROR(Status
)) {
2793 ShellRemvoeEnvVarFromList(Name
);
2796 SHELL_DELETE_ENVIRONMENT_VARIABLE(Name
);
2797 Status
= ShellAddEnvVarToList(
2798 Name
, Value
, StrSize(Value
),
2799 EFI_VARIABLE_BOOTSERVICE_ACCESS
| (Volatile
? 0 : EFI_VARIABLE_NON_VOLATILE
)
2801 if (!EFI_ERROR (Status
)) {
2803 ? SHELL_SET_ENVIRONMENT_VARIABLE_V (Name
, StrSize (Value
) - sizeof (CHAR16
), Value
)
2804 : SHELL_SET_ENVIRONMENT_VARIABLE_NV (Name
, StrSize (Value
) - sizeof (CHAR16
), Value
);
2805 if (EFI_ERROR (Status
)) {
2806 ShellRemvoeEnvVarFromList(Name
);
2814 Sets the environment variable.
2816 This function changes the current value of the specified environment variable. If the
2817 environment variable exists and the Value is an empty string, then the environment
2818 variable is deleted. If the environment variable exists and the Value is not an empty
2819 string, then the value of the environment variable is changed. If the environment
2820 variable does not exist and the Value is an empty string, there is no action. If the
2821 environment variable does not exist and the Value is a non-empty string, then the
2822 environment variable is created and assigned the specified value.
2824 For a description of volatile and non-volatile environment variables, see UEFI Shell
2825 2.0 specification section 3.6.1.
2827 @param Name Points to the NULL-terminated environment variable name.
2828 @param Value Points to the NULL-terminated environment variable value. If the value is an
2829 empty string then the environment variable is deleted.
2830 @param Volatile Indicates whether the variable is non-volatile (FALSE) or volatile (TRUE).
2832 @retval EFI_SUCCESS The environment variable was successfully updated.
2837 IN CONST CHAR16
*Name
,
2838 IN CONST CHAR16
*Value
,
2842 if (Name
== NULL
|| *Name
== CHAR_NULL
) {
2843 return (EFI_INVALID_PARAMETER
);
2846 // Make sure we dont 'set' a predefined read only variable
2848 if ((StrCmp (Name
, L
"cwd") == 0) ||
2849 (StrCmp (Name
, L
"lasterror") == 0) ||
2850 (StrCmp (Name
, L
"profiles") == 0) ||
2851 (StrCmp (Name
, L
"uefishellsupport") == 0) ||
2852 (StrCmp (Name
, L
"uefishellversion") == 0) ||
2853 (StrCmp (Name
, L
"uefiversion") == 0) ||
2854 (!ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.NoNest
&&
2855 StrCmp (Name
, mNoNestingEnvVarName
) == 0)
2857 return (EFI_INVALID_PARAMETER
);
2859 return (InternalEfiShellSetEnv(Name
, Value
, Volatile
));
2863 Returns the current directory on the specified device.
2865 If FileSystemMapping is NULL, it returns the current working directory. If the
2866 FileSystemMapping is not NULL, it returns the current directory associated with the
2867 FileSystemMapping. In both cases, the returned name includes the file system
2868 mapping (i.e. fs0:\current-dir).
2870 Note that the current directory string should exclude the tailing backslash character.
2872 @param FileSystemMapping A pointer to the file system mapping. If NULL,
2873 then the current working directory is returned.
2875 @retval !=NULL The current directory.
2876 @retval NULL Current directory does not exist.
2881 IN CONST CHAR16
*FileSystemMapping OPTIONAL
2884 CHAR16
*PathToReturn
;
2886 SHELL_MAP_LIST
*MapListItem
;
2887 if (!IsListEmpty(&gShellMapList
.Link
)) {
2889 // if parameter is NULL, use current
2891 if (FileSystemMapping
== NULL
) {
2892 return (EfiShellGetEnv(L
"cwd"));
2895 PathToReturn
= NULL
;
2896 MapListItem
= ShellCommandFindMapItem(FileSystemMapping
);
2897 if (MapListItem
!= NULL
) {
2898 ASSERT((PathToReturn
== NULL
&& Size
== 0) || (PathToReturn
!= NULL
));
2899 PathToReturn
= StrnCatGrow(&PathToReturn
, &Size
, MapListItem
->MapName
, 0);
2900 PathToReturn
= StrnCatGrow(&PathToReturn
, &Size
, MapListItem
->CurrentDirectoryPath
, 0);
2903 return (AddBufferToFreeList(PathToReturn
));
2910 Changes the current directory on the specified device.
2912 If the FileSystem is NULL, and the directory Dir does not contain a file system's
2913 mapped name, this function changes the current working directory.
2915 If the FileSystem is NULL and the directory Dir contains a mapped name, then the
2916 current file system and the current directory on that file system are changed.
2918 If FileSystem is NULL, and Dir is not NULL, then this changes the current working file
2921 If FileSystem is not NULL and Dir is not NULL, then this function changes the current
2922 directory on the specified file system.
2924 If the current working directory or the current working file system is changed then the
2925 %cwd% environment variable will be updated
2927 Note that the current directory string should exclude the tailing backslash character.
2929 @param FileSystem A pointer to the file system's mapped name. If NULL, then the current working
2930 directory is changed.
2931 @param Dir Points to the NULL-terminated directory on the device specified by FileSystem.
2933 @retval EFI_SUCCESS The operation was sucessful
2934 @retval EFI_NOT_FOUND The file system could not be found
2939 IN CONST CHAR16
*FileSystem OPTIONAL
,
2940 IN CONST CHAR16
*Dir
2944 SHELL_MAP_LIST
*MapListItem
;
2948 CHAR16
*DirectoryName
;
2955 DirectoryName
= NULL
;
2957 if ((FileSystem
== NULL
&& Dir
== NULL
) || Dir
== NULL
) {
2958 return (EFI_INVALID_PARAMETER
);
2961 if (IsListEmpty(&gShellMapList
.Link
)){
2962 return (EFI_NOT_FOUND
);
2965 DirectoryName
= StrnCatGrow(&DirectoryName
, NULL
, Dir
, 0);
2966 ASSERT(DirectoryName
!= NULL
);
2968 PathCleanUpDirectories(DirectoryName
);
2970 if (FileSystem
== NULL
) {
2972 // determine the file system mapping to use
2974 if (StrStr(DirectoryName
, L
":") != NULL
) {
2975 ASSERT(MapName
== NULL
);
2976 MapName
= StrnCatGrow(&MapName
, NULL
, DirectoryName
, (StrStr(DirectoryName
, L
":")-DirectoryName
+1));
2979 // find the file system mapping's entry in the list
2982 if (MapName
!= NULL
) {
2983 MapListItem
= ShellCommandFindMapItem(MapName
);
2986 // make that the current file system mapping
2988 if (MapListItem
!= NULL
) {
2989 gShellCurMapping
= MapListItem
;
2992 MapListItem
= gShellCurMapping
;
2995 if (MapListItem
== NULL
) {
2996 FreePool (DirectoryName
);
2997 SHELL_FREE_NON_NULL(MapName
);
2998 return (EFI_NOT_FOUND
);
3002 // now update the MapListItem's current directory
3004 if (MapListItem
->CurrentDirectoryPath
!= NULL
&& DirectoryName
[StrLen(DirectoryName
) - 1] != L
':') {
3005 FreePool(MapListItem
->CurrentDirectoryPath
);
3006 MapListItem
->CurrentDirectoryPath
= NULL
;
3008 if (MapName
!= NULL
) {
3009 TempLen
= StrLen(MapName
);
3010 if (TempLen
!= StrLen(DirectoryName
)) {
3011 ASSERT((MapListItem
->CurrentDirectoryPath
== NULL
&& Size
== 0) || (MapListItem
->CurrentDirectoryPath
!= NULL
));
3012 MapListItem
->CurrentDirectoryPath
= StrnCatGrow(&MapListItem
->CurrentDirectoryPath
, &Size
, DirectoryName
+StrLen(MapName
), 0);
3016 ASSERT((MapListItem
->CurrentDirectoryPath
== NULL
&& Size
== 0) || (MapListItem
->CurrentDirectoryPath
!= NULL
));
3017 MapListItem
->CurrentDirectoryPath
= StrnCatGrow(&MapListItem
->CurrentDirectoryPath
, &Size
, DirectoryName
, 0);
3019 if ((MapListItem
->CurrentDirectoryPath
!= NULL
&& MapListItem
->CurrentDirectoryPath
[StrLen(MapListItem
->CurrentDirectoryPath
)-1] == L
'\\') || (MapListItem
->CurrentDirectoryPath
== NULL
)) {
3020 ASSERT((MapListItem
->CurrentDirectoryPath
== NULL
&& Size
== 0) || (MapListItem
->CurrentDirectoryPath
!= NULL
));
3021 if (MapListItem
->CurrentDirectoryPath
!= NULL
) {
3022 MapListItem
->CurrentDirectoryPath
[StrLen(MapListItem
->CurrentDirectoryPath
)-1] = CHAR_NULL
;
3027 // cant have a mapping in the directory...
3029 if (StrStr(DirectoryName
, L
":") != NULL
) {
3030 FreePool (DirectoryName
);
3031 return (EFI_INVALID_PARAMETER
);
3034 // FileSystem != NULL
3036 MapListItem
= ShellCommandFindMapItem(FileSystem
);
3037 if (MapListItem
== NULL
) {
3038 FreePool (DirectoryName
);
3039 return (EFI_INVALID_PARAMETER
);
3041 // gShellCurMapping = MapListItem;
3042 if (DirectoryName
!= NULL
) {
3044 // change current dir on that file system
3047 if (MapListItem
->CurrentDirectoryPath
!= NULL
) {
3048 FreePool(MapListItem
->CurrentDirectoryPath
);
3049 DEBUG_CODE(MapListItem
->CurrentDirectoryPath
= NULL
;);
3051 // ASSERT((MapListItem->CurrentDirectoryPath == NULL && Size == 0) || (MapListItem->CurrentDirectoryPath != NULL));
3052 // MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, FileSystem, 0);
3053 ASSERT((MapListItem
->CurrentDirectoryPath
== NULL
&& Size
== 0) || (MapListItem
->CurrentDirectoryPath
!= NULL
));
3054 MapListItem
->CurrentDirectoryPath
= StrnCatGrow(&MapListItem
->CurrentDirectoryPath
, &Size
, L
"\\", 0);
3055 ASSERT((MapListItem
->CurrentDirectoryPath
== NULL
&& Size
== 0) || (MapListItem
->CurrentDirectoryPath
!= NULL
));
3056 MapListItem
->CurrentDirectoryPath
= StrnCatGrow(&MapListItem
->CurrentDirectoryPath
, &Size
, DirectoryName
, 0);
3057 if (MapListItem
->CurrentDirectoryPath
!= NULL
&& MapListItem
->CurrentDirectoryPath
[StrLen(MapListItem
->CurrentDirectoryPath
)-1] == L
'\\') {
3058 ASSERT((MapListItem
->CurrentDirectoryPath
== NULL
&& Size
== 0) || (MapListItem
->CurrentDirectoryPath
!= NULL
));
3059 MapListItem
->CurrentDirectoryPath
[StrLen(MapListItem
->CurrentDirectoryPath
)-1] = CHAR_NULL
;
3063 FreePool (DirectoryName
);
3065 // if updated the current directory then update the environment variable
3067 if (MapListItem
== gShellCurMapping
) {
3069 ASSERT((TempString
== NULL
&& Size
== 0) || (TempString
!= NULL
));
3070 StrnCatGrow(&TempString
, &Size
, MapListItem
->MapName
, 0);
3071 ASSERT((TempString
== NULL
&& Size
== 0) || (TempString
!= NULL
));
3072 StrnCatGrow(&TempString
, &Size
, MapListItem
->CurrentDirectoryPath
, 0);
3073 Status
= InternalEfiShellSetEnv(L
"cwd", TempString
, TRUE
);
3074 FreePool(TempString
);
3077 return(EFI_SUCCESS
);
3081 Return help information about a specific command.
3083 This function returns the help information for the specified command. The help text
3084 can be internal to the shell or can be from a UEFI Shell manual page.
3086 If Sections is specified, then each section name listed will be compared in a casesensitive
3087 manner, to the section names described in Appendix B. If the section exists,
3088 it will be appended to the returned help text. If the section does not exist, no
3089 information will be returned. If Sections is NULL, then all help text information
3090 available will be returned.
3092 @param Command Points to the NULL-terminated UEFI Shell command name.
3093 @param Sections Points to the NULL-terminated comma-delimited
3094 section names to return. If NULL, then all
3095 sections will be returned.
3096 @param HelpText On return, points to a callee-allocated buffer
3097 containing all specified help text.
3099 @retval EFI_SUCCESS The help text was returned.
3100 @retval EFI_OUT_OF_RESOURCES The necessary buffer could not be allocated to hold the
3102 @retval EFI_INVALID_PARAMETER HelpText is NULL
3103 @retval EFI_NOT_FOUND There is no help text available for Command.
3107 EfiShellGetHelpText(
3108 IN CONST CHAR16
*Command
,
3109 IN CONST CHAR16
*Sections OPTIONAL
,
3110 OUT CHAR16
**HelpText
3113 CONST CHAR16
*ManFileName
;
3117 ASSERT(HelpText
!= NULL
);
3120 ManFileName
= ShellCommandGetManFileNameHandler(Command
);
3122 if (ManFileName
!= NULL
) {
3123 return (ProcessManFile(ManFileName
, Command
, Sections
, NULL
, HelpText
));
3125 if ((StrLen(Command
)> 4)
3126 && (Command
[StrLen(Command
)-1] == L
'i' || Command
[StrLen(Command
)-1] == L
'I')
3127 && (Command
[StrLen(Command
)-2] == L
'f' || Command
[StrLen(Command
)-2] == L
'F')
3128 && (Command
[StrLen(Command
)-3] == L
'e' || Command
[StrLen(Command
)-3] == L
'E')
3129 && (Command
[StrLen(Command
)-4] == L
'.')
3131 FixCommand
= AllocateZeroPool(StrSize(Command
) - 4 * sizeof (CHAR16
));
3132 if (FixCommand
== NULL
) {
3133 return EFI_OUT_OF_RESOURCES
;
3136 StrnCpyS( FixCommand
,
3137 (StrSize(Command
) - 4 * sizeof (CHAR16
))/sizeof(CHAR16
),
3141 Status
= ProcessManFile(FixCommand
, FixCommand
, Sections
, NULL
, HelpText
);
3142 FreePool(FixCommand
);
3145 return (ProcessManFile(Command
, Command
, Sections
, NULL
, HelpText
));
3151 Gets the enable status of the page break output mode.
3153 User can use this function to determine current page break mode.
3155 @retval TRUE The page break output mode is enabled.
3156 @retval FALSE The page break output mode is disabled.
3160 EfiShellGetPageBreak(
3164 return(ShellInfoObject
.PageBreakEnabled
);
3168 Judges whether the active shell is the root shell.
3170 This function makes the user to know that whether the active Shell is the root shell.
3172 @retval TRUE The active Shell is the root Shell.
3173 @retval FALSE The active Shell is NOT the root Shell.
3177 EfiShellIsRootShell(
3181 return(ShellInfoObject
.RootShellInstance
);
3185 function to return a semi-colon delimeted list of all alias' in the current shell
3187 up to caller to free the memory.
3189 @retval NULL No alias' were found
3190 @retval NULL An error ocurred getting alias'
3191 @return !NULL a list of all alias'
3194 InternalEfiShellGetListAlias(
3201 CHAR16
*VariableName
;
3203 UINTN NameBufferSize
;
3207 NameBufferSize
= INIT_NAME_BUFFER_SIZE
;
3208 VariableName
= AllocateZeroPool(NameBufferSize
);
3212 if (VariableName
== NULL
) {
3216 VariableName
[0] = CHAR_NULL
;
3219 NameSize
= NameBufferSize
;
3220 Status
= gRT
->GetNextVariableName(&NameSize
, VariableName
, &Guid
);
3221 if (Status
== EFI_NOT_FOUND
){
3223 } else if (Status
== EFI_BUFFER_TOO_SMALL
) {
3224 NameBufferSize
= NameSize
> NameBufferSize
* 2 ? NameSize
: NameBufferSize
* 2;
3225 SHELL_FREE_NON_NULL(VariableName
);
3226 VariableName
= AllocateZeroPool(NameBufferSize
);
3227 if (VariableName
== NULL
) {
3228 Status
= EFI_OUT_OF_RESOURCES
;
3229 SHELL_FREE_NON_NULL(RetVal
);
3234 NameSize
= NameBufferSize
;
3235 Status
= gRT
->GetNextVariableName(&NameSize
, VariableName
, &Guid
);
3238 if (EFI_ERROR (Status
)) {
3239 SHELL_FREE_NON_NULL(RetVal
);
3244 if (CompareGuid(&Guid
, &gShellAliasGuid
)){
3245 ASSERT((RetVal
== NULL
&& RetSize
== 0) || (RetVal
!= NULL
));
3246 RetVal
= StrnCatGrow(&RetVal
, &RetSize
, VariableName
, 0);
3247 RetVal
= StrnCatGrow(&RetVal
, &RetSize
, L
";", 0);
3250 SHELL_FREE_NON_NULL(VariableName
);
3256 Convert a null-terminated unicode string, in-place, to all lowercase.
3259 @param Str The null-terminated string to be converted to all lowercase.
3261 @return The null-terminated string converted into all lowercase.
3270 for (Index
= 0; Str
[Index
] != L
'\0'; Index
++) {
3271 if (Str
[Index
] >= L
'A' && Str
[Index
] <= L
'Z') {
3272 Str
[Index
] -= (CHAR16
)(L
'A' - L
'a');
3279 This function returns the command associated with a alias or a list of all
3282 @param[in] Alias Points to the NULL-terminated shell alias.
3283 If this parameter is NULL, then all
3284 aliases will be returned in ReturnedData.
3285 @param[out] Volatile upon return of a single command if TRUE indicates
3286 this is stored in a volatile fashion. FALSE otherwise.
3288 @return If Alias is not NULL, it will return a pointer to
3289 the NULL-terminated command for that alias.
3290 If Alias is NULL, ReturnedData points to a ';'
3291 delimited list of alias (e.g.
3292 ReturnedData = "dir;del;copy;mfp") that is NULL-terminated.
3293 @retval NULL an error ocurred
3294 @retval NULL Alias was not a valid Alias
3299 IN CONST CHAR16
*Alias
,
3300 OUT BOOLEAN
*Volatile OPTIONAL
3310 // Convert to lowercase to make aliases case-insensitive
3311 if (Alias
!= NULL
) {
3312 AliasLower
= AllocateCopyPool (StrSize (Alias
), Alias
);
3313 if (AliasLower
== NULL
) {
3316 ToLower (AliasLower
);
3318 if (Volatile
== NULL
) {
3319 GetVariable2 (AliasLower
, &gShellAliasGuid
, (VOID
**)&AliasVal
, NULL
);
3320 FreePool(AliasLower
);
3321 return (AddBufferToFreeList(AliasVal
));
3325 Status
= gRT
->GetVariable(AliasLower
, &gShellAliasGuid
, &Attribs
, &RetSize
, RetVal
);
3326 if (Status
== EFI_BUFFER_TOO_SMALL
) {
3327 RetVal
= AllocateZeroPool(RetSize
);
3328 Status
= gRT
->GetVariable(AliasLower
, &gShellAliasGuid
, &Attribs
, &RetSize
, RetVal
);
3330 if (EFI_ERROR(Status
)) {
3331 if (RetVal
!= NULL
) {
3334 FreePool(AliasLower
);
3337 if ((EFI_VARIABLE_NON_VOLATILE
& Attribs
) == EFI_VARIABLE_NON_VOLATILE
) {
3343 FreePool (AliasLower
);
3344 return (AddBufferToFreeList(RetVal
));
3346 return (AddBufferToFreeList(InternalEfiShellGetListAlias()));
3350 Changes a shell command alias.
3352 This function creates an alias for a shell command or if Alias is NULL it will delete an existing alias.
3354 this function does not check for built in alias'.
3356 @param[in] Command Points to the NULL-terminated shell command or existing alias.
3357 @param[in] Alias Points to the NULL-terminated alias for the shell command. If this is NULL, and
3358 Command refers to an alias, that alias will be deleted.
3359 @param[in] Volatile if TRUE the Alias being set will be stored in a volatile fashion. if FALSE the
3360 Alias being set will be stored in a non-volatile fashion.
3362 @retval EFI_SUCCESS Alias created or deleted successfully.
3363 @retval EFI_NOT_FOUND the Alias intended to be deleted was not found
3367 IN CONST CHAR16
*Command
,
3368 IN CONST CHAR16
*Alias
,
3374 BOOLEAN DeleteAlias
;
3376 DeleteAlias
= FALSE
;
3377 if (Alias
== NULL
) {
3379 // We must be trying to remove one if Alias is NULL
3380 // remove an alias (but passed in COMMAND parameter)
3385 ASSERT (Alias
!= NULL
);
3388 // Convert to lowercase to make aliases case-insensitive
3390 AliasLower
= AllocateCopyPool (StrSize (Alias
), Alias
);
3391 if (AliasLower
== NULL
) {
3392 return EFI_OUT_OF_RESOURCES
;
3394 ToLower (AliasLower
);
3397 Status
= gRT
->SetVariable (AliasLower
, &gShellAliasGuid
, 0, 0, NULL
);
3399 Status
= gRT
->SetVariable (
3400 AliasLower
, &gShellAliasGuid
,
3401 EFI_VARIABLE_BOOTSERVICE_ACCESS
| (Volatile
? 0 : EFI_VARIABLE_NON_VOLATILE
),
3402 StrSize (Command
), (VOID
*) Command
3406 FreePool (AliasLower
);
3412 Changes a shell command alias.
3414 This function creates an alias for a shell command or if Alias is NULL it will delete an existing alias.
3417 @param[in] Command Points to the NULL-terminated shell command or existing alias.
3418 @param[in] Alias Points to the NULL-terminated alias for the shell command. If this is NULL, and
3419 Command refers to an alias, that alias will be deleted.
3420 @param[in] Replace If TRUE and the alias already exists, then the existing alias will be replaced. If
3421 FALSE and the alias already exists, then the existing alias is unchanged and
3422 EFI_ACCESS_DENIED is returned.
3423 @param[in] Volatile if TRUE the Alias being set will be stored in a volatile fashion. if FALSE the
3424 Alias being set will be stored in a non-volatile fashion.
3426 @retval EFI_SUCCESS Alias created or deleted successfully.
3427 @retval EFI_NOT_FOUND the Alias intended to be deleted was not found
3428 @retval EFI_ACCESS_DENIED The alias is a built-in alias or already existed and Replace was set to
3430 @retval EFI_INVALID_PARAMETER Command is null or the empty string.
3435 IN CONST CHAR16
*Command
,
3436 IN CONST CHAR16
*Alias
,
3441 if (ShellCommandIsOnAliasList(Alias
==NULL
?Command
:Alias
)) {
3443 // cant set over a built in alias
3445 return (EFI_ACCESS_DENIED
);
3446 } else if (Command
== NULL
|| *Command
== CHAR_NULL
|| StrLen(Command
) == 0) {
3448 // Command is null or empty
3450 return (EFI_INVALID_PARAMETER
);
3451 } else if (EfiShellGetAlias(Command
, NULL
) != NULL
&& !Replace
) {
3453 // Alias already exists, Replace not set
3455 return (EFI_ACCESS_DENIED
);
3457 return (InternalSetAlias(Command
, Alias
, Volatile
));
3461 // Pure FILE_HANDLE operations are passed to FileHandleLib
3462 // these functions are indicated by the *
3463 EFI_SHELL_PROTOCOL mShellProtocol
= {
3469 EfiShellGetHelpText
,
3470 EfiShellGetDevicePathFromMap
,
3471 EfiShellGetMapFromDevicePath
,
3472 EfiShellGetDevicePathFromFilePath
,
3473 EfiShellGetFilePathFromDevicePath
,
3477 EfiShellOpenFileList
,
3478 EfiShellFreeFileList
,
3479 EfiShellRemoveDupInFileList
,
3480 EfiShellBatchIsActive
,
3481 EfiShellIsRootShell
,
3482 EfiShellEnablePageBreak
,
3483 EfiShellDisablePageBreak
,
3484 EfiShellGetPageBreak
,
3485 EfiShellGetDeviceName
,
3486 (EFI_SHELL_GET_FILE_INFO
)FileHandleGetInfo
, //*
3487 (EFI_SHELL_SET_FILE_INFO
)FileHandleSetInfo
, //*
3488 EfiShellOpenFileByName
,
3491 (EFI_SHELL_READ_FILE
)FileHandleRead
, //*
3492 (EFI_SHELL_WRITE_FILE
)FileHandleWrite
, //*
3493 (EFI_SHELL_DELETE_FILE
)FileHandleDelete
, //*
3494 EfiShellDeleteFileByName
,
3495 (EFI_SHELL_GET_FILE_POSITION
)FileHandleGetPosition
, //*
3496 (EFI_SHELL_SET_FILE_POSITION
)FileHandleSetPosition
, //*
3497 (EFI_SHELL_FLUSH_FILE
)FileHandleFlush
, //*
3499 EfiShellFindFilesInDir
,
3500 (EFI_SHELL_GET_FILE_SIZE
)FileHandleGetSize
, //*
3502 EfiShellOpenRootByHandle
,
3504 SHELL_MAJOR_VERSION
,
3505 SHELL_MINOR_VERSION
,
3507 // New for UEFI Shell 2.1
3508 EfiShellRegisterGuidName
,
3509 EfiShellGetGuidName
,
3510 EfiShellGetGuidFromName
,
3515 Function to create and install on the current handle.
3517 Will overwrite any existing ShellProtocols in the system to be sure that
3518 the current shell is in control.
3520 This must be removed via calling CleanUpShellProtocol().
3522 @param[in, out] NewShell The pointer to the pointer to the structure
3525 @retval EFI_SUCCESS The operation was successful.
3526 @return An error from LocateHandle, CreateEvent, or other core function.
3529 CreatePopulateInstallShellProtocol (
3530 IN OUT EFI_SHELL_PROTOCOL
**NewShell
3536 UINTN HandleCounter
;
3537 SHELL_PROTOCOL_HANDLE_LIST
*OldProtocolNode
;
3538 EFI_SHELL_PROTOCOL
*OldShell
;
3540 if (NewShell
== NULL
) {
3541 return (EFI_INVALID_PARAMETER
);
3546 OldProtocolNode
= NULL
;
3547 InitializeListHead(&ShellInfoObject
.OldShellList
.Link
);
3550 // Initialize EfiShellProtocol object...
3552 Status
= gBS
->CreateEvent(0,
3556 &mShellProtocol
.ExecutionBreak
);
3557 if (EFI_ERROR(Status
)) {
3562 // Get the size of the buffer we need.
3564 Status
= gBS
->LocateHandle(ByProtocol
,
3565 &gEfiShellProtocolGuid
,
3569 if (Status
== EFI_BUFFER_TOO_SMALL
) {
3571 // Allocate and recall with buffer of correct size
3573 Buffer
= AllocateZeroPool(BufferSize
);
3574 if (Buffer
== NULL
) {
3575 return (EFI_OUT_OF_RESOURCES
);
3577 Status
= gBS
->LocateHandle(ByProtocol
,
3578 &gEfiShellProtocolGuid
,
3582 if (EFI_ERROR(Status
)) {
3587 // now overwrite each of them, but save the info to restore when we end.
3589 for (HandleCounter
= 0 ; HandleCounter
< (BufferSize
/sizeof(EFI_HANDLE
)) ; HandleCounter
++) {
3590 Status
= gBS
->OpenProtocol(Buffer
[HandleCounter
],
3591 &gEfiShellProtocolGuid
,
3592 (VOID
**) &OldShell
,
3595 EFI_OPEN_PROTOCOL_GET_PROTOCOL
3597 if (!EFI_ERROR(Status
)) {
3598 OldProtocolNode
= AllocateZeroPool(sizeof(SHELL_PROTOCOL_HANDLE_LIST
));
3599 if (OldProtocolNode
== NULL
) {
3600 if (!IsListEmpty (&ShellInfoObject
.OldShellList
.Link
)) {
3601 CleanUpShellProtocol (&mShellProtocol
);
3603 Status
= EFI_OUT_OF_RESOURCES
;
3607 // reinstall over the old one...
3609 OldProtocolNode
->Handle
= Buffer
[HandleCounter
];
3610 OldProtocolNode
->Interface
= OldShell
;
3611 Status
= gBS
->ReinstallProtocolInterface(
3612 OldProtocolNode
->Handle
,
3613 &gEfiShellProtocolGuid
,
3614 OldProtocolNode
->Interface
,
3615 (VOID
*)(&mShellProtocol
));
3616 if (!EFI_ERROR(Status
)) {
3618 // we reinstalled sucessfully. log this so we can reverse it later.
3622 // add to the list for subsequent...
3624 InsertTailList(&ShellInfoObject
.OldShellList
.Link
, &OldProtocolNode
->Link
);
3629 } else if (Status
== EFI_NOT_FOUND
) {
3630 ASSERT(IsListEmpty(&ShellInfoObject
.OldShellList
.Link
));
3632 // no one else published yet. just publish it ourselves.
3634 Status
= gBS
->InstallProtocolInterface (
3636 &gEfiShellProtocolGuid
,
3637 EFI_NATIVE_INTERFACE
,
3638 (VOID
*)(&mShellProtocol
));
3641 if (PcdGetBool(PcdShellSupportOldProtocols
)){
3642 ///@todo support ShellEnvironment2
3643 ///@todo do we need to support ShellEnvironment (not ShellEnvironment2) also?
3646 if (!EFI_ERROR(Status
)) {
3647 *NewShell
= &mShellProtocol
;
3653 Opposite of CreatePopulateInstallShellProtocol.
3655 Free all memory and restore the system to the state it was in before calling
3656 CreatePopulateInstallShellProtocol.
3658 @param[in, out] NewShell The pointer to the new shell protocol structure.
3660 @retval EFI_SUCCESS The operation was successful.
3663 CleanUpShellProtocol (
3664 IN OUT EFI_SHELL_PROTOCOL
*NewShell
3667 SHELL_PROTOCOL_HANDLE_LIST
*Node2
;
3670 // if we need to restore old protocols...
3672 if (!IsListEmpty(&ShellInfoObject
.OldShellList
.Link
)) {
3673 for (Node2
= (SHELL_PROTOCOL_HANDLE_LIST
*) GetFirstNode (&ShellInfoObject
.OldShellList
.Link
)
3674 ; !IsListEmpty (&ShellInfoObject
.OldShellList
.Link
)
3675 ; Node2
= (SHELL_PROTOCOL_HANDLE_LIST
*) GetFirstNode (&ShellInfoObject
.OldShellList
.Link
)
3677 RemoveEntryList (&Node2
->Link
);
3678 gBS
->ReinstallProtocolInterface (Node2
->Handle
, &gEfiShellProtocolGuid
, NewShell
, Node2
->Interface
);
3683 // no need to restore
3685 gBS
->UninstallProtocolInterface (gImageHandle
, &gEfiShellProtocolGuid
, NewShell
);
3691 Cleanup the shell environment.
3693 @param[in, out] NewShell The pointer to the new shell protocol structure.
3695 @retval EFI_SUCCESS The operation was successful.
3698 CleanUpShellEnvironment (
3699 IN OUT EFI_SHELL_PROTOCOL
*NewShell
3703 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*SimpleEx
;
3705 CleanUpShellProtocol (NewShell
);
3707 Status
= gBS
->CloseEvent(NewShell
->ExecutionBreak
);
3708 NewShell
->ExecutionBreak
= NULL
;
3710 Status
= gBS
->OpenProtocol(
3711 gST
->ConsoleInHandle
,
3712 &gEfiSimpleTextInputExProtocolGuid
,
3716 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
3718 if (!EFI_ERROR (Status
)) {
3719 Status
= SimpleEx
->UnregisterKeyNotify(SimpleEx
, ShellInfoObject
.CtrlCNotifyHandle1
);
3720 Status
= SimpleEx
->UnregisterKeyNotify(SimpleEx
, ShellInfoObject
.CtrlCNotifyHandle2
);
3721 Status
= SimpleEx
->UnregisterKeyNotify(SimpleEx
, ShellInfoObject
.CtrlCNotifyHandle3
);
3722 Status
= SimpleEx
->UnregisterKeyNotify(SimpleEx
, ShellInfoObject
.CtrlCNotifyHandle4
);
3723 Status
= SimpleEx
->UnregisterKeyNotify(SimpleEx
, ShellInfoObject
.CtrlSNotifyHandle1
);
3724 Status
= SimpleEx
->UnregisterKeyNotify(SimpleEx
, ShellInfoObject
.CtrlSNotifyHandle2
);
3725 Status
= SimpleEx
->UnregisterKeyNotify(SimpleEx
, ShellInfoObject
.CtrlSNotifyHandle3
);
3726 Status
= SimpleEx
->UnregisterKeyNotify(SimpleEx
, ShellInfoObject
.CtrlSNotifyHandle4
);
3732 Notification function for keystrokes.
3734 @param[in] KeyData The key that was pressed.
3736 @retval EFI_SUCCESS The operation was successful.
3740 NotificationFunction(
3741 IN EFI_KEY_DATA
*KeyData
3744 if ( ((KeyData
->Key
.UnicodeChar
== L
'c') &&
3745 (KeyData
->KeyState
.KeyShiftState
== (EFI_SHIFT_STATE_VALID
|EFI_LEFT_CONTROL_PRESSED
) || KeyData
->KeyState
.KeyShiftState
== (EFI_SHIFT_STATE_VALID
|EFI_RIGHT_CONTROL_PRESSED
))) ||
3746 (KeyData
->Key
.UnicodeChar
== 3)
3748 if (ShellInfoObject
.NewEfiShellProtocol
->ExecutionBreak
== NULL
) {
3749 return (EFI_UNSUPPORTED
);
3751 return (gBS
->SignalEvent(ShellInfoObject
.NewEfiShellProtocol
->ExecutionBreak
));
3752 } else if ((KeyData
->Key
.UnicodeChar
== L
's') &&
3753 (KeyData
->KeyState
.KeyShiftState
== (EFI_SHIFT_STATE_VALID
|EFI_LEFT_CONTROL_PRESSED
) || KeyData
->KeyState
.KeyShiftState
== (EFI_SHIFT_STATE_VALID
|EFI_RIGHT_CONTROL_PRESSED
))
3755 ShellInfoObject
.HaltOutput
= TRUE
;
3757 return (EFI_SUCCESS
);
3761 Function to start monitoring for CTRL-C using SimpleTextInputEx. This
3762 feature's enabled state was not known when the shell initially launched.
3764 @retval EFI_SUCCESS The feature is enabled.
3765 @retval EFI_OUT_OF_RESOURCES There is not enough mnemory available.
3768 InernalEfiShellStartMonitor(
3772 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*SimpleEx
;
3773 EFI_KEY_DATA KeyData
;
3776 Status
= gBS
->OpenProtocol(
3777 gST
->ConsoleInHandle
,
3778 &gEfiSimpleTextInputExProtocolGuid
,
3782 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
3783 if (EFI_ERROR(Status
)) {
3788 STRING_TOKEN (STR_SHELL_NO_IN_EX
),
3789 ShellInfoObject
.HiiHandle
);
3790 return (EFI_SUCCESS
);
3793 if (ShellInfoObject
.NewEfiShellProtocol
->ExecutionBreak
== NULL
) {
3794 return (EFI_UNSUPPORTED
);
3797 KeyData
.KeyState
.KeyToggleState
= 0;
3798 KeyData
.Key
.ScanCode
= 0;
3799 KeyData
.KeyState
.KeyShiftState
= EFI_SHIFT_STATE_VALID
|EFI_LEFT_CONTROL_PRESSED
;
3800 KeyData
.Key
.UnicodeChar
= L
'c';
3802 Status
= SimpleEx
->RegisterKeyNotify(
3805 NotificationFunction
,
3806 &ShellInfoObject
.CtrlCNotifyHandle1
);
3808 KeyData
.KeyState
.KeyShiftState
= EFI_SHIFT_STATE_VALID
|EFI_RIGHT_CONTROL_PRESSED
;
3809 if (!EFI_ERROR(Status
)) {
3810 Status
= SimpleEx
->RegisterKeyNotify(
3813 NotificationFunction
,
3814 &ShellInfoObject
.CtrlCNotifyHandle2
);
3816 KeyData
.KeyState
.KeyShiftState
= EFI_SHIFT_STATE_VALID
|EFI_LEFT_CONTROL_PRESSED
;
3817 KeyData
.Key
.UnicodeChar
= 3;
3818 if (!EFI_ERROR(Status
)) {
3819 Status
= SimpleEx
->RegisterKeyNotify(
3822 NotificationFunction
,
3823 &ShellInfoObject
.CtrlCNotifyHandle3
);
3825 KeyData
.KeyState
.KeyShiftState
= EFI_SHIFT_STATE_VALID
|EFI_RIGHT_CONTROL_PRESSED
;
3826 if (!EFI_ERROR(Status
)) {
3827 Status
= SimpleEx
->RegisterKeyNotify(
3830 NotificationFunction
,
3831 &ShellInfoObject
.CtrlCNotifyHandle4
);