2 Provides interface to shell internal functions for shell commands.
4 (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "UefiShellCommandLib.h"
18 // STATIC local variables
19 STATIC SHELL_COMMAND_INTERNAL_LIST_ENTRY mCommandList
;
20 STATIC SCRIPT_FILE_LIST mScriptList
;
21 STATIC ALIAS_LIST mAliasList
;
22 STATIC BOOLEAN mEchoState
;
23 STATIC BOOLEAN mExitRequested
;
24 STATIC UINT64 mExitCode
;
25 STATIC BOOLEAN mExitScript
;
26 STATIC CHAR16
*mProfileList
;
27 STATIC UINTN mProfileListSize
;
28 STATIC UINTN mFsMaxCount
= 0;
29 STATIC UINTN mBlkMaxCount
= 0;
30 STATIC BUFFER_LIST mFileHandleList
;
32 STATIC CONST CHAR8 Hex
[] = {
51 // global variables required by library class.
52 EFI_UNICODE_COLLATION_PROTOCOL
*gUnicodeCollation
= NULL
;
53 SHELL_MAP_LIST gShellMapList
;
54 SHELL_MAP_LIST
*gShellCurDir
= NULL
;
56 CONST CHAR16
* SupportLevel
[] = {
64 Function to make sure that the global protocol pointers are valid.
65 must be called after constructor before accessing the pointers.
74 if (gUnicodeCollation
== NULL
) {
75 Status
= gBS
->LocateProtocol(&gEfiUnicodeCollation2ProtocolGuid
, NULL
, (VOID
**)&gUnicodeCollation
);
76 if (EFI_ERROR(Status
)) {
77 return (EFI_DEVICE_ERROR
);
84 Constructor for the Shell Command library.
86 Initialize the library and determine if the underlying is a UEFI Shell 2.0 or an EFI shell.
88 @param ImageHandle the image handle of the process
89 @param SystemTable the EFI System Table pointer
91 @retval EFI_SUCCESS the initialization was complete sucessfully
95 ShellCommandLibConstructor (
96 IN EFI_HANDLE ImageHandle
,
97 IN EFI_SYSTEM_TABLE
*SystemTable
101 InitializeListHead(&gShellMapList
.Link
);
102 InitializeListHead(&mCommandList
.Link
);
103 InitializeListHead(&mAliasList
.Link
);
104 InitializeListHead(&mScriptList
.Link
);
105 InitializeListHead(&mFileHandleList
.Link
);
108 mExitRequested
= FALSE
;
110 mProfileListSize
= 0;
113 if (gUnicodeCollation
== NULL
) {
114 Status
= gBS
->LocateProtocol(&gEfiUnicodeCollation2ProtocolGuid
, NULL
, (VOID
**)&gUnicodeCollation
);
115 if (EFI_ERROR(Status
)) {
116 return (EFI_DEVICE_ERROR
);
120 return (RETURN_SUCCESS
);
124 Frees list of file handles.
126 @param[in] List The list to free.
134 BUFFER_LIST
*BufferListEntry
;
140 // enumerate through the buffer list and free all memory
142 for ( BufferListEntry
= ( BUFFER_LIST
*)GetFirstNode(&List
->Link
)
143 ; !IsListEmpty (&List
->Link
)
144 ; BufferListEntry
= (BUFFER_LIST
*)GetFirstNode(&List
->Link
)
146 RemoveEntryList(&BufferListEntry
->Link
);
147 ASSERT(BufferListEntry
->Buffer
!= NULL
);
148 SHELL_FREE_NON_NULL(((SHELL_COMMAND_FILE_HANDLE
*)(BufferListEntry
->Buffer
))->Path
);
149 SHELL_FREE_NON_NULL(BufferListEntry
->Buffer
);
150 SHELL_FREE_NON_NULL(BufferListEntry
);
155 Destructor for the library. free any resources.
157 @param ImageHandle the image handle of the process
158 @param SystemTable the EFI System Table pointer
160 @retval RETURN_SUCCESS this function always returns success
164 ShellCommandLibDestructor (
165 IN EFI_HANDLE ImageHandle
,
166 IN EFI_SYSTEM_TABLE
*SystemTable
169 SHELL_COMMAND_INTERNAL_LIST_ENTRY
*Node
;
171 SCRIPT_FILE_LIST
*Node3
;
172 SHELL_MAP_LIST
*MapNode
;
174 // enumerate throught the list and free all the memory
176 while (!IsListEmpty (&mCommandList
.Link
)) {
177 Node
= (SHELL_COMMAND_INTERNAL_LIST_ENTRY
*)GetFirstNode(&mCommandList
.Link
);
178 RemoveEntryList(&Node
->Link
);
179 SHELL_FREE_NON_NULL(Node
->CommandString
);
181 DEBUG_CODE(Node
= NULL
;);
185 // enumerate through the alias list and free all memory
187 while (!IsListEmpty (&mAliasList
.Link
)) {
188 Node2
= (ALIAS_LIST
*)GetFirstNode(&mAliasList
.Link
);
189 RemoveEntryList(&Node2
->Link
);
190 SHELL_FREE_NON_NULL(Node2
->CommandString
);
191 SHELL_FREE_NON_NULL(Node2
->Alias
);
192 SHELL_FREE_NON_NULL(Node2
);
193 DEBUG_CODE(Node2
= NULL
;);
197 // enumerate throught the list and free all the memory
199 while (!IsListEmpty (&mScriptList
.Link
)) {
200 Node3
= (SCRIPT_FILE_LIST
*)GetFirstNode(&mScriptList
.Link
);
201 RemoveEntryList(&Node3
->Link
);
202 DeleteScriptFileStruct(Node3
->Data
);
207 // enumerate throught the mappings list and free all the memory
209 if (!IsListEmpty(&gShellMapList
.Link
)) {
210 for (MapNode
= (SHELL_MAP_LIST
*)GetFirstNode(&gShellMapList
.Link
)
211 ; !IsListEmpty (&gShellMapList
.Link
)
212 ; MapNode
= (SHELL_MAP_LIST
*)GetFirstNode(&gShellMapList
.Link
)
214 ASSERT(MapNode
!= NULL
);
215 RemoveEntryList(&MapNode
->Link
);
216 SHELL_FREE_NON_NULL(MapNode
->DevicePath
);
217 SHELL_FREE_NON_NULL(MapNode
->MapName
);
218 SHELL_FREE_NON_NULL(MapNode
->CurrentDirectoryPath
);
222 if (!IsListEmpty(&mFileHandleList
.Link
)){
223 FreeFileHandleList(&mFileHandleList
);
226 if (mProfileList
!= NULL
) {
227 FreePool(mProfileList
);
230 gUnicodeCollation
= NULL
;
233 return (RETURN_SUCCESS
);
237 Find a dynamic command protocol instance given a command name string.
239 @param CommandString the command name string
241 @return instance the command protocol instance, if dynamic command instance found
242 @retval NULL no dynamic command protocol instance found for name
244 CONST EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL
*
246 ShellCommandFindDynamicCommand (
247 IN CONST CHAR16
*CommandString
251 EFI_HANDLE
*CommandHandleList
;
252 EFI_HANDLE
*NextCommand
;
253 EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL
*DynamicCommand
;
255 CommandHandleList
= GetHandleListByProtocol(&gEfiShellDynamicCommandProtocolGuid
);
256 if (CommandHandleList
== NULL
) {
258 // not found or out of resources
263 for (NextCommand
= CommandHandleList
; *NextCommand
!= NULL
; NextCommand
++) {
264 Status
= gBS
->HandleProtocol(
266 &gEfiShellDynamicCommandProtocolGuid
,
267 (VOID
**)&DynamicCommand
270 if (EFI_ERROR(Status
)) {
274 if (gUnicodeCollation
->StriColl(
276 (CHAR16
*)CommandString
,
277 (CHAR16
*)DynamicCommand
->CommandName
) == 0
279 FreePool(CommandHandleList
);
280 return (DynamicCommand
);
284 FreePool(CommandHandleList
);
289 Checks if a command exists as a dynamic command protocol instance
291 @param[in] CommandString The command string to check for on the list.
295 ShellCommandDynamicCommandExists (
296 IN CONST CHAR16
*CommandString
299 return (BOOLEAN
) ((ShellCommandFindDynamicCommand(CommandString
) != NULL
));
303 Checks if a command is already on the internal command list.
305 @param[in] CommandString The command string to check for on the list.
309 ShellCommandIsCommandOnInternalList(
310 IN CONST CHAR16
*CommandString
313 SHELL_COMMAND_INTERNAL_LIST_ENTRY
*Node
;
316 // assert for NULL parameter
318 ASSERT(CommandString
!= NULL
);
321 // check for the command
323 for ( Node
= (SHELL_COMMAND_INTERNAL_LIST_ENTRY
*)GetFirstNode(&mCommandList
.Link
)
324 ; !IsNull(&mCommandList
.Link
, &Node
->Link
)
325 ; Node
= (SHELL_COMMAND_INTERNAL_LIST_ENTRY
*)GetNextNode(&mCommandList
.Link
, &Node
->Link
)
327 ASSERT(Node
->CommandString
!= NULL
);
328 if (gUnicodeCollation
->StriColl(
330 (CHAR16
*)CommandString
,
331 Node
->CommandString
) == 0
340 Checks if a command exists, either internally or through the dynamic command protocol.
342 @param[in] CommandString The command string to check for on the list.
346 ShellCommandIsCommandOnList(
347 IN CONST CHAR16
*CommandString
350 if (ShellCommandIsCommandOnInternalList(CommandString
)) {
354 return ShellCommandDynamicCommandExists(CommandString
);
358 Get the help text for a dynamic command.
360 @param[in] CommandString The command name.
362 @retval NULL No help text was found.
363 @return String of help text. Caller required to free.
367 ShellCommandGetDynamicCommandHelp(
368 IN CONST CHAR16
*CommandString
371 EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL
*DynamicCommand
;
373 DynamicCommand
= (EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL
*)ShellCommandFindDynamicCommand(CommandString
);
374 if (DynamicCommand
== NULL
) {
379 // TODO: how to get proper language?
381 return DynamicCommand
->GetHelp(DynamicCommand
, "en");
385 Get the help text for an internal command.
387 @param[in] CommandString The command name.
389 @retval NULL No help text was found.
390 @return String of help text. Caller reuiqred to free.
394 ShellCommandGetInternalCommandHelp(
395 IN CONST CHAR16
*CommandString
398 SHELL_COMMAND_INTERNAL_LIST_ENTRY
*Node
;
401 // assert for NULL parameter
403 ASSERT(CommandString
!= NULL
);
406 // check for the command
408 for ( Node
= (SHELL_COMMAND_INTERNAL_LIST_ENTRY
*)GetFirstNode(&mCommandList
.Link
)
409 ; !IsNull(&mCommandList
.Link
, &Node
->Link
)
410 ; Node
= (SHELL_COMMAND_INTERNAL_LIST_ENTRY
*)GetNextNode(&mCommandList
.Link
, &Node
->Link
)
412 ASSERT(Node
->CommandString
!= NULL
);
413 if (gUnicodeCollation
->StriColl(
415 (CHAR16
*)CommandString
,
416 Node
->CommandString
) == 0
418 return (HiiGetString(Node
->HiiHandle
, Node
->ManFormatHelp
, NULL
));
425 Get the help text for a command.
427 @param[in] CommandString The command name.
429 @retval NULL No help text was found.
430 @return String of help text.Caller reuiqred to free.
434 ShellCommandGetCommandHelp (
435 IN CONST CHAR16
*CommandString
439 HelpStr
= ShellCommandGetInternalCommandHelp(CommandString
);
441 if (HelpStr
== NULL
) {
442 HelpStr
= ShellCommandGetDynamicCommandHelp(CommandString
);
450 Registers handlers of type SHELL_RUN_COMMAND and
451 SHELL_GET_MAN_FILENAME for each shell command.
453 If the ShellSupportLevel is greater than the value of the
454 PcdShellSupportLevel then return RETURN_UNSUPPORTED.
456 Registers the handlers specified by GetHelpInfoHandler and CommandHandler
457 with the command specified by CommandString. If the command named by
458 CommandString has already been registered, then return
459 RETURN_ALREADY_STARTED.
461 If there are not enough resources available to register the handlers then
462 RETURN_OUT_OF_RESOURCES is returned.
464 If CommandString is NULL, then ASSERT().
465 If GetHelpInfoHandler is NULL, then ASSERT().
466 If CommandHandler is NULL, then ASSERT().
467 If ProfileName is NULL, then ASSERT().
469 @param[in] CommandString Pointer to the command name. This is the
470 name to look for on the command line in
472 @param[in] CommandHandler Pointer to a function that runs the
474 @param[in] GetManFileName Pointer to a function that provides man
476 @param[in] ShellMinSupportLevel minimum Shell Support Level which has this
478 @param[in] ProfileName profile name to require for support of this
480 @param[in] CanAffectLE indicates whether this command's return value
481 can change the LASTERROR environment variable.
482 @param[in] HiiHandle Handle of this command's HII entry.
483 @param[in] ManFormatHelp HII locator for the help text.
485 @retval RETURN_SUCCESS The handlers were registered.
486 @retval RETURN_OUT_OF_RESOURCES There are not enough resources available to
487 register the shell command.
488 @retval RETURN_UNSUPPORTED the ShellMinSupportLevel was higher than the
489 currently allowed support level.
490 @retval RETURN_ALREADY_STARTED The CommandString represents a command that
491 is already registered. Only 1 handler set for
492 a given command is allowed.
493 @sa SHELL_GET_MAN_FILENAME
494 @sa SHELL_RUN_COMMAND
498 ShellCommandRegisterCommandName (
499 IN CONST CHAR16
*CommandString
,
500 IN SHELL_RUN_COMMAND CommandHandler
,
501 IN SHELL_GET_MAN_FILENAME GetManFileName
,
502 IN UINT32 ShellMinSupportLevel
,
503 IN CONST CHAR16
*ProfileName
,
504 IN CONST BOOLEAN CanAffectLE
,
505 IN CONST EFI_HANDLE HiiHandle
,
506 IN CONST EFI_STRING_ID ManFormatHelp
509 SHELL_COMMAND_INTERNAL_LIST_ENTRY
*Node
;
510 SHELL_COMMAND_INTERNAL_LIST_ENTRY
*Command
;
511 SHELL_COMMAND_INTERNAL_LIST_ENTRY
*PrevCommand
;
512 INTN LexicalMatchValue
;
515 // Initialize local variables.
519 LexicalMatchValue
= 0;
522 // ASSERTs for NULL parameters
524 ASSERT(CommandString
!= NULL
);
525 ASSERT(GetManFileName
!= NULL
);
526 ASSERT(CommandHandler
!= NULL
);
527 ASSERT(ProfileName
!= NULL
);
530 // check for shell support level
532 if (PcdGet8(PcdShellSupportLevel
) < ShellMinSupportLevel
) {
533 return (RETURN_UNSUPPORTED
);
537 // check for already on the list
539 if (ShellCommandIsCommandOnList(CommandString
)) {
540 return (RETURN_ALREADY_STARTED
);
544 // allocate memory for new struct
546 Node
= AllocateZeroPool(sizeof(SHELL_COMMAND_INTERNAL_LIST_ENTRY
));
547 ASSERT(Node
!= NULL
);
548 Node
->CommandString
= AllocateCopyPool(StrSize(CommandString
), CommandString
);
549 ASSERT(Node
->CommandString
!= NULL
);
551 Node
->GetManFileName
= GetManFileName
;
552 Node
->CommandHandler
= CommandHandler
;
553 Node
->LastError
= CanAffectLE
;
554 Node
->HiiHandle
= HiiHandle
;
555 Node
->ManFormatHelp
= ManFormatHelp
;
557 if ( StrLen(ProfileName
)>0
558 && ((mProfileList
!= NULL
559 && StrStr(mProfileList
, ProfileName
) == NULL
) || mProfileList
== NULL
)
561 ASSERT((mProfileList
== NULL
&& mProfileListSize
== 0) || (mProfileList
!= NULL
));
562 if (mProfileList
== NULL
) {
564 // If this is the first make a leading ';'
566 StrnCatGrow(&mProfileList
, &mProfileListSize
, L
";", 0);
568 StrnCatGrow(&mProfileList
, &mProfileListSize
, ProfileName
, 0);
569 StrnCatGrow(&mProfileList
, &mProfileListSize
, L
";", 0);
573 // Insert a new entry on top of the list
575 InsertHeadList (&mCommandList
.Link
, &Node
->Link
);
578 // Move a new registered command to its sorted ordered location in the list
580 for (Command
= (SHELL_COMMAND_INTERNAL_LIST_ENTRY
*)GetFirstNode (&mCommandList
.Link
),
581 PrevCommand
= (SHELL_COMMAND_INTERNAL_LIST_ENTRY
*)GetFirstNode (&mCommandList
.Link
)
582 ; !IsNull (&mCommandList
.Link
, &Command
->Link
)
583 ; Command
= (SHELL_COMMAND_INTERNAL_LIST_ENTRY
*)GetNextNode (&mCommandList
.Link
, &Command
->Link
)) {
586 // Get Lexical Comparison Value between PrevCommand and Command list entry
588 LexicalMatchValue
= gUnicodeCollation
->StriColl (
590 PrevCommand
->CommandString
,
591 Command
->CommandString
595 // Swap PrevCommand and Command list entry if PrevCommand list entry
596 // is alphabetically greater than Command list entry
598 if (LexicalMatchValue
> 0){
599 Command
= (SHELL_COMMAND_INTERNAL_LIST_ENTRY
*) SwapListEntries (&PrevCommand
->Link
, &Command
->Link
);
600 } else if (LexicalMatchValue
< 0) {
602 // PrevCommand entry is lexically lower than Command entry
608 return (RETURN_SUCCESS
);
612 Function to get the current Profile string.
614 @retval NULL There are no installed profiles.
615 @return A semi-colon delimited list of profiles.
619 ShellCommandGetProfileList (
623 return (mProfileList
);
627 Checks if a command string has been registered for CommandString and if so it runs
628 the previously registered handler for that command with the command line.
630 If CommandString is NULL, then ASSERT().
632 If Sections is specified, then each section name listed will be compared in a casesensitive
633 manner, to the section names described in Appendix B UEFI Shell 2.0 spec. If the section exists,
634 it will be appended to the returned help text. If the section does not exist, no
635 information will be returned. If Sections is NULL, then all help text information
636 available will be returned.
638 @param[in] CommandString Pointer to the command name. This is the name
639 found on the command line in the shell.
640 @param[in, out] RetVal Pointer to the return vaule from the command handler.
642 @param[in, out] CanAffectLE indicates whether this command's return value
643 needs to be placed into LASTERROR environment variable.
645 @retval RETURN_SUCCESS The handler was run.
646 @retval RETURN_NOT_FOUND The CommandString did not match a registered
648 @sa SHELL_RUN_COMMAND
652 ShellCommandRunCommandHandler (
653 IN CONST CHAR16
*CommandString
,
654 IN OUT SHELL_STATUS
*RetVal
,
655 IN OUT BOOLEAN
*CanAffectLE OPTIONAL
658 SHELL_COMMAND_INTERNAL_LIST_ENTRY
*Node
;
659 EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL
*DynamicCommand
;
662 // assert for NULL parameters
664 ASSERT(CommandString
!= NULL
);
667 // check for the command
669 for ( Node
= (SHELL_COMMAND_INTERNAL_LIST_ENTRY
*)GetFirstNode(&mCommandList
.Link
)
670 ; !IsNull(&mCommandList
.Link
, &Node
->Link
)
671 ; Node
= (SHELL_COMMAND_INTERNAL_LIST_ENTRY
*)GetNextNode(&mCommandList
.Link
, &Node
->Link
)
673 ASSERT(Node
->CommandString
!= NULL
);
674 if (gUnicodeCollation
->StriColl(
676 (CHAR16
*)CommandString
,
677 Node
->CommandString
) == 0
679 if (CanAffectLE
!= NULL
) {
680 *CanAffectLE
= Node
->LastError
;
682 if (RetVal
!= NULL
) {
683 *RetVal
= Node
->CommandHandler(NULL
, gST
);
685 Node
->CommandHandler(NULL
, gST
);
687 return (RETURN_SUCCESS
);
692 // An internal command was not found, try to find a dynamic command
694 DynamicCommand
= (EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL
*)ShellCommandFindDynamicCommand(CommandString
);
695 if (DynamicCommand
!= NULL
) {
696 if (RetVal
!= NULL
) {
697 *RetVal
= DynamicCommand
->Handler(DynamicCommand
, gST
, gEfiShellParametersProtocol
, gEfiShellProtocol
);
699 DynamicCommand
->Handler(DynamicCommand
, gST
, gEfiShellParametersProtocol
, gEfiShellProtocol
);
701 return (RETURN_SUCCESS
);
704 return (RETURN_NOT_FOUND
);
708 Checks if a command string has been registered for CommandString and if so it
709 returns the MAN filename specified for that command.
711 If CommandString is NULL, then ASSERT().
713 @param[in] CommandString Pointer to the command name. This is the name
714 found on the command line in the shell.\
716 @retval NULL the commandString was not a registered command.
717 @return other the name of the MAN file.
718 @sa SHELL_GET_MAN_FILENAME
722 ShellCommandGetManFileNameHandler (
723 IN CONST CHAR16
*CommandString
726 SHELL_COMMAND_INTERNAL_LIST_ENTRY
*Node
;
729 // assert for NULL parameters
731 ASSERT(CommandString
!= NULL
);
734 // check for the command
736 for ( Node
= (SHELL_COMMAND_INTERNAL_LIST_ENTRY
*)GetFirstNode(&mCommandList
.Link
)
737 ; !IsNull(&mCommandList
.Link
, &Node
->Link
)
738 ; Node
= (SHELL_COMMAND_INTERNAL_LIST_ENTRY
*)GetNextNode(&mCommandList
.Link
, &Node
->Link
)
740 ASSERT(Node
->CommandString
!= NULL
);
741 if (gUnicodeCollation
->StriColl(
743 (CHAR16
*)CommandString
,
744 Node
->CommandString
) == 0
746 return (Node
->GetManFileName());
753 Get the list of all available shell internal commands. This is a linked list
754 (via LIST_ENTRY structure). enumerate through it using the BaseLib linked
755 list functions. do not modify the values.
757 @param[in] Sort TRUE to alphabetically sort the values first. FALSE otherwise.
759 @return a Linked list of all available shell commands.
763 ShellCommandGetCommandList (
764 IN CONST BOOLEAN Sort
768 // return ((COMMAND_LIST*)(&mCommandList));
770 return ((COMMAND_LIST
*)(&mCommandList
));
774 Registers aliases to be set as part of the initialization of the shell application.
776 If Command is NULL, then ASSERT().
777 If Alias is NULL, then ASSERT().
779 @param[in] Command Pointer to the Command
780 @param[in] Alias Pointer to Alias
782 @retval RETURN_SUCCESS The handlers were registered.
783 @retval RETURN_OUT_OF_RESOURCES There are not enough resources available to
784 register the shell command.
788 ShellCommandRegisterAlias (
789 IN CONST CHAR16
*Command
,
790 IN CONST CHAR16
*Alias
794 ALIAS_LIST
*CommandAlias
;
795 ALIAS_LIST
*PrevCommandAlias
;
796 INTN LexicalMatchValue
;
801 ASSERT(Command
!= NULL
);
802 ASSERT(Alias
!= NULL
);
805 // allocate memory for new struct
807 Node
= AllocateZeroPool(sizeof(ALIAS_LIST
));
808 ASSERT(Node
!= NULL
);
809 Node
->CommandString
= AllocateCopyPool(StrSize(Command
), Command
);
810 Node
->Alias
= AllocateCopyPool(StrSize(Alias
), Alias
);
811 ASSERT(Node
->CommandString
!= NULL
);
812 ASSERT(Node
->Alias
!= NULL
);
814 InsertHeadList (&mAliasList
.Link
, &Node
->Link
);
817 // Move a new pre-defined registered alias to its sorted ordered location in the list
819 for ( CommandAlias
= (ALIAS_LIST
*)GetFirstNode (&mAliasList
.Link
),
820 PrevCommandAlias
= (ALIAS_LIST
*)GetFirstNode (&mAliasList
.Link
)
821 ; !IsNull (&mAliasList
.Link
, &CommandAlias
->Link
)
822 ; CommandAlias
= (ALIAS_LIST
*) GetNextNode (&mAliasList
.Link
, &CommandAlias
->Link
) ) {
824 // Get Lexical comparison value between PrevCommandAlias and CommandAlias List Entry
826 LexicalMatchValue
= gUnicodeCollation
->StriColl (
828 PrevCommandAlias
->Alias
,
833 // Swap PrevCommandAlias and CommandAlias list entry if PrevCommandAlias list entry
834 // is alphabetically greater than CommandAlias list entry
836 if (LexicalMatchValue
> 0) {
837 CommandAlias
= (ALIAS_LIST
*) SwapListEntries (&PrevCommandAlias
->Link
, &CommandAlias
->Link
);
838 } else if (LexicalMatchValue
< 0) {
840 // PrevCommandAlias entry is lexically lower than CommandAlias entry
846 return (RETURN_SUCCESS
);
850 Get the list of all shell alias commands. This is a linked list
851 (via LIST_ENTRY structure). enumerate through it using the BaseLib linked
852 list functions. do not modify the values.
854 @return a Linked list of all requested shell alias'.
858 ShellCommandGetInitAliasList (
862 return (&mAliasList
);
866 Determine if a given alias is on the list of built in alias'.
868 @param[in] Alias The alias to test for
870 @retval TRUE The alias is a built in alias
871 @retval FALSE The alias is not a built in alias
875 ShellCommandIsOnAliasList(
876 IN CONST CHAR16
*Alias
882 // assert for NULL parameter
884 ASSERT(Alias
!= NULL
);
887 // check for the Alias
889 for ( Node
= (ALIAS_LIST
*)GetFirstNode(&mAliasList
.Link
)
890 ; !IsNull(&mAliasList
.Link
, &Node
->Link
)
891 ; Node
= (ALIAS_LIST
*)GetNextNode(&mAliasList
.Link
, &Node
->Link
)
893 ASSERT(Node
->CommandString
!= NULL
);
894 ASSERT(Node
->Alias
!= NULL
);
895 if (gUnicodeCollation
->StriColl(
898 Node
->CommandString
) == 0
902 if (gUnicodeCollation
->StriColl(
914 Function to determine current state of ECHO. Echo determines if lines from scripts
915 and ECHO commands are enabled.
917 @retval TRUE Echo is currently enabled
918 @retval FALSE Echo is currently disabled
922 ShellCommandGetEchoState(
930 Function to set current state of ECHO. Echo determines if lines from scripts
931 and ECHO commands are enabled.
933 If State is TRUE, Echo will be enabled.
934 If State is FALSE, Echo will be disabled.
936 @param[in] State How to set echo.
940 ShellCommandSetEchoState(
948 Indicate that the current shell or script should exit.
950 @param[in] ScriptOnly TRUE if exiting a script; FALSE otherwise.
951 @param[in] ErrorCode The 64 bit error code to return.
955 ShellCommandRegisterExit (
956 IN BOOLEAN ScriptOnly
,
957 IN CONST UINT64 ErrorCode
960 mExitRequested
= (BOOLEAN
)(!mExitRequested
);
961 if (mExitRequested
) {
962 mExitScript
= ScriptOnly
;
966 mExitCode
= ErrorCode
;
970 Retrieve the Exit indicator.
972 @retval TRUE Exit was indicated.
973 @retval FALSE Exis was not indicated.
977 ShellCommandGetExit (
981 return (mExitRequested
);
985 Retrieve the Exit code.
987 If ShellCommandGetExit returns FALSE than the return from this is undefined.
989 @return the value passed into RegisterExit.
993 ShellCommandGetExitCode (
1000 Retrieve the Exit script indicator.
1002 If ShellCommandGetExit returns FALSE than the return from this is undefined.
1004 @retval TRUE ScriptOnly was indicated.
1005 @retval FALSE ScriptOnly was not indicated.
1009 ShellCommandGetScriptExit (
1013 return (mExitScript
);
1017 Function to cleanup all memory from a SCRIPT_FILE structure.
1019 @param[in] Script The pointer to the structure to cleanup.
1023 DeleteScriptFileStruct (
1024 IN SCRIPT_FILE
*Script
1029 if (Script
== NULL
) {
1033 for (LoopVar
= 0 ; LoopVar
< Script
->Argc
; LoopVar
++) {
1034 SHELL_FREE_NON_NULL(Script
->Argv
[LoopVar
]);
1036 if (Script
->Argv
!= NULL
) {
1037 SHELL_FREE_NON_NULL(Script
->Argv
);
1039 Script
->CurrentCommand
= NULL
;
1040 while (!IsListEmpty (&Script
->CommandList
)) {
1041 Script
->CurrentCommand
= (SCRIPT_COMMAND_LIST
*)GetFirstNode(&Script
->CommandList
);
1042 if (Script
->CurrentCommand
!= NULL
) {
1043 RemoveEntryList(&Script
->CurrentCommand
->Link
);
1044 if (Script
->CurrentCommand
->Cl
!= NULL
) {
1045 SHELL_FREE_NON_NULL(Script
->CurrentCommand
->Cl
);
1047 if (Script
->CurrentCommand
->Data
!= NULL
) {
1048 SHELL_FREE_NON_NULL(Script
->CurrentCommand
->Data
);
1050 SHELL_FREE_NON_NULL(Script
->CurrentCommand
);
1053 SHELL_FREE_NON_NULL(Script
->ScriptName
);
1054 SHELL_FREE_NON_NULL(Script
);
1058 Function to return a pointer to the currently running script file object.
1060 @retval NULL A script file is not currently running.
1061 @return A pointer to the current script file object.
1065 ShellCommandGetCurrentScriptFile (
1069 SCRIPT_FILE_LIST
*List
;
1070 if (IsListEmpty (&mScriptList
.Link
)) {
1073 List
= ((SCRIPT_FILE_LIST
*)GetFirstNode(&mScriptList
.Link
));
1074 return (List
->Data
);
1078 Function to set a new script as the currently running one.
1080 This function will correctly stack and unstack nested scripts.
1082 @param[in] Script Pointer to new script information structure. if NULL
1083 will remove and de-allocate the top-most Script structure.
1085 @return A pointer to the current running script file after this
1086 change. NULL if removing the final script.
1090 ShellCommandSetNewScript (
1091 IN SCRIPT_FILE
*Script OPTIONAL
1094 SCRIPT_FILE_LIST
*Node
;
1095 if (Script
== NULL
) {
1096 if (IsListEmpty (&mScriptList
.Link
)) {
1099 Node
= (SCRIPT_FILE_LIST
*)GetFirstNode(&mScriptList
.Link
);
1100 RemoveEntryList(&Node
->Link
);
1101 DeleteScriptFileStruct(Node
->Data
);
1104 Node
= AllocateZeroPool(sizeof(SCRIPT_FILE_LIST
));
1108 Node
->Data
= Script
;
1109 InsertHeadList(&mScriptList
.Link
, &Node
->Link
);
1111 return (ShellCommandGetCurrentScriptFile());
1115 Function to generate the next default mapping name.
1117 If the return value is not NULL then it must be callee freed.
1119 @param Type What kind of mapping name to make.
1121 @retval NULL a memory allocation failed.
1122 @return a new map name string
1126 ShellCommandCreateNewMappingName(
1127 IN CONST SHELL_MAPPING_TYPE Type
1131 ASSERT(Type
< MappingTypeMax
);
1135 String
= AllocateZeroPool(PcdGet8(PcdShellMapNameLength
) * sizeof(String
[0]));
1138 PcdGet8(PcdShellMapNameLength
) * sizeof(String
[0]),
1139 Type
== MappingTypeFileSystem
?L
"FS%d:":L
"BLK%d:",
1140 Type
== MappingTypeFileSystem
?mFsMaxCount
++:mBlkMaxCount
++);
1146 Function to add a map node to the list of map items and update the "path" environment variable (optionally).
1148 If Path is TRUE (during initialization only), the path environment variable will also be updated to include
1149 default paths on the new map name...
1151 Path should be FALSE when this function is called from the protocol SetMap function.
1153 @param[in] Name The human readable mapped name.
1154 @param[in] DevicePath The Device Path for this map.
1155 @param[in] Flags The Flags attribute for this map item.
1156 @param[in] Path TRUE to update path, FALSE to skip this step (should only be TRUE during initialization).
1158 @retval EFI_SUCCESS The addition was sucessful.
1159 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
1160 @retval EFI_INVALID_PARAMETER A parameter was invalid.
1164 ShellCommandAddMapItemAndUpdatePath(
1165 IN CONST CHAR16
*Name
,
1166 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
1167 IN CONST UINT64 Flags
,
1168 IN CONST BOOLEAN Path
1172 SHELL_MAP_LIST
*MapListNode
;
1173 CONST CHAR16
*OriginalPath
;
1179 OriginalPath
= NULL
;
1180 Status
= EFI_SUCCESS
;
1182 MapListNode
= AllocateZeroPool(sizeof(SHELL_MAP_LIST
));
1183 if (MapListNode
== NULL
) {
1184 Status
= EFI_OUT_OF_RESOURCES
;
1186 MapListNode
->Flags
= Flags
;
1187 MapListNode
->MapName
= AllocateCopyPool(StrSize(Name
), Name
);
1188 MapListNode
->DevicePath
= DuplicateDevicePath(DevicePath
);
1189 if ((MapListNode
->MapName
== NULL
) || (MapListNode
->DevicePath
== NULL
)){
1190 Status
= EFI_OUT_OF_RESOURCES
;
1192 InsertTailList(&gShellMapList
.Link
, &MapListNode
->Link
);
1195 if (EFI_ERROR(Status
)) {
1196 if (MapListNode
!= NULL
) {
1197 if (MapListNode
->DevicePath
!= NULL
) {
1198 FreePool(MapListNode
->DevicePath
);
1200 if (MapListNode
->MapName
!= NULL
) {
1201 FreePool(MapListNode
->MapName
);
1203 FreePool(MapListNode
);
1207 // Since there was no error and Path was TRUE
1208 // Now add the correct path for that mapping
1210 OriginalPath
= gEfiShellProtocol
->GetEnv(L
"path");
1211 ASSERT((NewPath
== NULL
&& NewPathSize
== 0) || (NewPath
!= NULL
));
1212 if (OriginalPath
!= NULL
) {
1213 StrnCatGrow(&NewPath
, &NewPathSize
, OriginalPath
, 0);
1215 StrnCatGrow(&NewPath
, &NewPathSize
, L
".\\", 0);
1217 StrnCatGrow(&NewPath
, &NewPathSize
, L
";", 0);
1218 StrnCatGrow(&NewPath
, &NewPathSize
, Name
, 0);
1219 StrnCatGrow(&NewPath
, &NewPathSize
, L
"\\efi\\tools\\;", 0);
1220 StrnCatGrow(&NewPath
, &NewPathSize
, Name
, 0);
1221 StrnCatGrow(&NewPath
, &NewPathSize
, L
"\\efi\\boot\\;", 0);
1222 StrnCatGrow(&NewPath
, &NewPathSize
, Name
, 0);
1223 StrnCatGrow(&NewPath
, &NewPathSize
, L
"\\", 0);
1225 Status
= gEfiShellProtocol
->SetEnv(L
"path", NewPath
, TRUE
);
1226 ASSERT_EFI_ERROR(Status
);
1233 Creates the default map names for each device path in the system with
1234 a protocol depending on the Type.
1236 Creates the consistent map names for each device path in the system with
1237 a protocol depending on the Type.
1239 Note: This will reset all mappings in the system("map -r").
1241 Also sets up the default path environment variable if Type is FileSystem.
1243 @retval EFI_SUCCESS All map names were created sucessfully.
1244 @retval EFI_NOT_FOUND No protocols were found in the system.
1245 @return Error returned from gBS->LocateHandle().
1251 ShellCommandCreateInitialMappingsAndPaths(
1256 EFI_HANDLE
*HandleList
;
1258 EFI_DEVICE_PATH_PROTOCOL
**DevicePathList
;
1259 CHAR16
*NewDefaultName
;
1260 CHAR16
*NewConsistName
;
1261 EFI_DEVICE_PATH_PROTOCOL
**ConsistMappingTable
;
1262 SHELL_MAP_LIST
*MapListNode
;
1267 // Reset the static members back to zero
1272 gEfiShellProtocol
->SetEnv(L
"path", L
"", TRUE
);
1275 // First empty out the existing list.
1277 if (!IsListEmpty(&gShellMapList
.Link
)) {
1278 for ( MapListNode
= (SHELL_MAP_LIST
*)GetFirstNode(&gShellMapList
.Link
)
1279 ; !IsListEmpty(&gShellMapList
.Link
)
1280 ; MapListNode
= (SHELL_MAP_LIST
*)GetFirstNode(&gShellMapList
.Link
)
1282 RemoveEntryList(&MapListNode
->Link
);
1283 SHELL_FREE_NON_NULL(MapListNode
->DevicePath
);
1284 SHELL_FREE_NON_NULL(MapListNode
->MapName
);
1285 SHELL_FREE_NON_NULL(MapListNode
->CurrentDirectoryPath
);
1286 FreePool(MapListNode
);
1291 // Find each handle with Simple File System
1293 HandleList
= GetHandleListByProtocol(&gEfiSimpleFileSystemProtocolGuid
);
1294 if (HandleList
!= NULL
) {
1296 // Do a count of the handles
1298 for (Count
= 0 ; HandleList
[Count
] != NULL
; Count
++);
1301 // Get all Device Paths
1303 DevicePathList
= AllocateZeroPool(sizeof(EFI_DEVICE_PATH_PROTOCOL
*) * Count
);
1304 ASSERT(DevicePathList
!= NULL
);
1306 for (Count
= 0 ; HandleList
[Count
] != NULL
; Count
++) {
1307 DevicePathList
[Count
] = DevicePathFromHandle(HandleList
[Count
]);
1311 // Sort all DevicePaths
1313 PerformQuickSort(DevicePathList
, Count
, sizeof(EFI_DEVICE_PATH_PROTOCOL
*), DevicePathCompare
);
1315 ShellCommandConsistMappingInitialize(&ConsistMappingTable
);
1317 // Assign new Mappings to all...
1319 for (Count
= 0 ; HandleList
[Count
] != NULL
; Count
++) {
1321 // Get default name first
1323 NewDefaultName
= ShellCommandCreateNewMappingName(MappingTypeFileSystem
);
1324 ASSERT(NewDefaultName
!= NULL
);
1325 Status
= ShellCommandAddMapItemAndUpdatePath(NewDefaultName
, DevicePathList
[Count
], 0, TRUE
);
1326 ASSERT_EFI_ERROR(Status
);
1327 FreePool(NewDefaultName
);
1330 // Now do consistent name
1332 NewConsistName
= ShellCommandConsistMappingGenMappingName(DevicePathList
[Count
], ConsistMappingTable
);
1333 if (NewConsistName
!= NULL
) {
1334 Status
= ShellCommandAddMapItemAndUpdatePath(NewConsistName
, DevicePathList
[Count
], 0, FALSE
);
1335 ASSERT_EFI_ERROR(Status
);
1336 FreePool(NewConsistName
);
1340 ShellCommandConsistMappingUnInitialize(ConsistMappingTable
);
1342 SHELL_FREE_NON_NULL(HandleList
);
1343 SHELL_FREE_NON_NULL(DevicePathList
);
1351 // Find each handle with Block Io
1353 HandleList
= GetHandleListByProtocol(&gEfiBlockIoProtocolGuid
);
1354 if (HandleList
!= NULL
) {
1355 for (Count
= 0 ; HandleList
[Count
] != NULL
; Count
++);
1358 // Get all Device Paths
1360 DevicePathList
= AllocateZeroPool(sizeof(EFI_DEVICE_PATH_PROTOCOL
*) * Count
);
1361 ASSERT(DevicePathList
!= NULL
);
1363 for (Count
= 0 ; HandleList
[Count
] != NULL
; Count
++) {
1364 DevicePathList
[Count
] = DevicePathFromHandle(HandleList
[Count
]);
1368 // Sort all DevicePaths
1370 PerformQuickSort(DevicePathList
, Count
, sizeof(EFI_DEVICE_PATH_PROTOCOL
*), DevicePathCompare
);
1373 // Assign new Mappings to all...
1375 for (Count
= 0 ; HandleList
[Count
] != NULL
; Count
++) {
1377 // Get default name first
1379 NewDefaultName
= ShellCommandCreateNewMappingName(MappingTypeBlockIo
);
1380 ASSERT(NewDefaultName
!= NULL
);
1381 Status
= ShellCommandAddMapItemAndUpdatePath(NewDefaultName
, DevicePathList
[Count
], 0, FALSE
);
1382 ASSERT_EFI_ERROR(Status
);
1383 FreePool(NewDefaultName
);
1386 SHELL_FREE_NON_NULL(HandleList
);
1387 SHELL_FREE_NON_NULL(DevicePathList
);
1388 } else if (Count
== (UINTN
)-1) {
1389 return (EFI_NOT_FOUND
);
1392 return (EFI_SUCCESS
);
1396 Add mappings for any devices without one. Do not change any existing maps.
1398 @retval EFI_SUCCESS The operation was successful.
1402 ShellCommandUpdateMapping (
1407 EFI_HANDLE
*HandleList
;
1409 EFI_DEVICE_PATH_PROTOCOL
**DevicePathList
;
1410 CHAR16
*NewDefaultName
;
1411 CHAR16
*NewConsistName
;
1412 EFI_DEVICE_PATH_PROTOCOL
**ConsistMappingTable
;
1415 Status
= EFI_SUCCESS
;
1418 // remove mappings that represent removed devices.
1422 // Find each handle with Simple File System
1424 HandleList
= GetHandleListByProtocol(&gEfiSimpleFileSystemProtocolGuid
);
1425 if (HandleList
!= NULL
) {
1427 // Do a count of the handles
1429 for (Count
= 0 ; HandleList
[Count
] != NULL
; Count
++);
1432 // Get all Device Paths
1434 DevicePathList
= AllocateZeroPool(sizeof(EFI_DEVICE_PATH_PROTOCOL
*) * Count
);
1435 if (DevicePathList
== NULL
) {
1436 return (EFI_OUT_OF_RESOURCES
);
1439 for (Count
= 0 ; HandleList
[Count
] != NULL
; Count
++) {
1440 DevicePathList
[Count
] = DevicePathFromHandle(HandleList
[Count
]);
1444 // Sort all DevicePaths
1446 PerformQuickSort(DevicePathList
, Count
, sizeof(EFI_DEVICE_PATH_PROTOCOL
*), DevicePathCompare
);
1448 ShellCommandConsistMappingInitialize(&ConsistMappingTable
);
1451 // Assign new Mappings to remainders
1453 for (Count
= 0 ; !EFI_ERROR(Status
) && HandleList
[Count
] != NULL
&& !EFI_ERROR(Status
); Count
++) {
1455 // Skip ones that already have
1457 if (gEfiShellProtocol
->GetMapFromDevicePath(&DevicePathList
[Count
]) != NULL
) {
1463 NewDefaultName
= ShellCommandCreateNewMappingName(MappingTypeFileSystem
);
1464 if (NewDefaultName
== NULL
) {
1465 Status
= EFI_OUT_OF_RESOURCES
;
1470 // Call shell protocol SetMap function now...
1472 Status
= gEfiShellProtocol
->SetMap(DevicePathList
[Count
], NewDefaultName
);
1474 if (!EFI_ERROR(Status
)) {
1476 // Now do consistent name
1478 NewConsistName
= ShellCommandConsistMappingGenMappingName(DevicePathList
[Count
], ConsistMappingTable
);
1479 if (NewConsistName
!= NULL
) {
1480 Status
= gEfiShellProtocol
->SetMap(DevicePathList
[Count
], NewConsistName
);
1481 FreePool(NewConsistName
);
1485 FreePool(NewDefaultName
);
1487 ShellCommandConsistMappingUnInitialize(ConsistMappingTable
);
1488 SHELL_FREE_NON_NULL(HandleList
);
1489 SHELL_FREE_NON_NULL(DevicePathList
);
1496 // Do it all over again for gEfiBlockIoProtocolGuid
1503 Converts a SHELL_FILE_HANDLE to an EFI_FILE_PROTOCOL*.
1505 @param[in] Handle The SHELL_FILE_HANDLE to convert.
1507 @return a EFI_FILE_PROTOCOL* representing the same file.
1511 ConvertShellHandleToEfiFileProtocol(
1512 IN CONST SHELL_FILE_HANDLE Handle
1515 return ((EFI_FILE_PROTOCOL
*)(Handle
));
1519 Converts a EFI_FILE_PROTOCOL* to an SHELL_FILE_HANDLE.
1521 @param[in] Handle The pointer to EFI_FILE_PROTOCOL to convert.
1522 @param[in] Path The path to the file for verification.
1524 @return A SHELL_FILE_HANDLE representing the same file.
1525 @retval NULL There was not enough memory.
1529 ConvertEfiFileProtocolToShellHandle(
1530 IN CONST EFI_FILE_PROTOCOL
*Handle
,
1531 IN CONST CHAR16
*Path
1534 SHELL_COMMAND_FILE_HANDLE
*Buffer
;
1535 BUFFER_LIST
*NewNode
;
1538 Buffer
= AllocateZeroPool(sizeof(SHELL_COMMAND_FILE_HANDLE
));
1539 if (Buffer
== NULL
) {
1542 NewNode
= AllocateZeroPool(sizeof(BUFFER_LIST
));
1543 if (NewNode
== NULL
) {
1544 SHELL_FREE_NON_NULL(Buffer
);
1547 Buffer
->FileHandle
= (EFI_FILE_PROTOCOL
*)Handle
;
1548 Buffer
->Path
= StrnCatGrow(&Buffer
->Path
, NULL
, Path
, 0);
1549 if (Buffer
->Path
== NULL
) {
1550 SHELL_FREE_NON_NULL(NewNode
);
1551 SHELL_FREE_NON_NULL(Buffer
);
1554 NewNode
->Buffer
= Buffer
;
1556 InsertHeadList(&mFileHandleList
.Link
, &NewNode
->Link
);
1558 return ((SHELL_FILE_HANDLE
)(Handle
));
1562 Find the path that was logged with the specified SHELL_FILE_HANDLE.
1564 @param[in] Handle The SHELL_FILE_HANDLE to query on.
1566 @return A pointer to the path for the file.
1570 ShellFileHandleGetPath(
1571 IN CONST SHELL_FILE_HANDLE Handle
1576 for (Node
= (BUFFER_LIST
*)GetFirstNode(&mFileHandleList
.Link
)
1577 ; !IsNull(&mFileHandleList
.Link
, &Node
->Link
)
1578 ; Node
= (BUFFER_LIST
*)GetNextNode(&mFileHandleList
.Link
, &Node
->Link
)
1580 if ((Node
->Buffer
) && (((SHELL_COMMAND_FILE_HANDLE
*)Node
->Buffer
)->FileHandle
== Handle
)){
1581 return (((SHELL_COMMAND_FILE_HANDLE
*)Node
->Buffer
)->Path
);
1588 Remove a SHELL_FILE_HANDLE from the list of SHELL_FILE_HANDLES.
1590 @param[in] Handle The SHELL_FILE_HANDLE to remove.
1592 @retval TRUE The item was removed.
1593 @retval FALSE The item was not found.
1597 ShellFileHandleRemove(
1598 IN CONST SHELL_FILE_HANDLE Handle
1603 for (Node
= (BUFFER_LIST
*)GetFirstNode(&mFileHandleList
.Link
)
1604 ; !IsNull(&mFileHandleList
.Link
, &Node
->Link
)
1605 ; Node
= (BUFFER_LIST
*)GetNextNode(&mFileHandleList
.Link
, &Node
->Link
)
1607 if ((Node
->Buffer
) && (((SHELL_COMMAND_FILE_HANDLE
*)Node
->Buffer
)->FileHandle
== Handle
)){
1608 RemoveEntryList(&Node
->Link
);
1609 SHELL_FREE_NON_NULL(((SHELL_COMMAND_FILE_HANDLE
*)Node
->Buffer
)->Path
);
1610 SHELL_FREE_NON_NULL(Node
->Buffer
);
1611 SHELL_FREE_NON_NULL(Node
);
1619 Function to determine if a SHELL_FILE_HANDLE is at the end of the file.
1621 This will NOT work on directories.
1623 If Handle is NULL, then ASSERT.
1625 @param[in] Handle the file handle
1627 @retval TRUE the position is at the end of the file
1628 @retval FALSE the position is not at the end of the file
1633 IN SHELL_FILE_HANDLE Handle
1636 EFI_FILE_INFO
*Info
;
1641 // ASSERT if Handle is NULL
1643 ASSERT(Handle
!= NULL
);
1645 gEfiShellProtocol
->GetFilePosition(Handle
, &Pos
);
1646 Info
= gEfiShellProtocol
->GetFileInfo (Handle
);
1647 gEfiShellProtocol
->SetFilePosition(Handle
, Pos
);
1653 if (Pos
== Info
->FileSize
) {
1665 Frees any BUFFER_LIST defined type.
1667 @param[in] List The BUFFER_LIST object to free.
1672 IN BUFFER_LIST
*List
1675 BUFFER_LIST
*BufferListEntry
;
1681 // enumerate through the buffer list and free all memory
1683 for ( BufferListEntry
= ( BUFFER_LIST
*)GetFirstNode(&List
->Link
)
1684 ; !IsListEmpty (&List
->Link
)
1685 ; BufferListEntry
= (BUFFER_LIST
*)GetFirstNode(&List
->Link
)
1687 RemoveEntryList(&BufferListEntry
->Link
);
1688 if (BufferListEntry
->Buffer
!= NULL
) {
1689 FreePool(BufferListEntry
->Buffer
);
1691 FreePool(BufferListEntry
);
1696 Dump some hexadecimal data to the screen.
1698 @param[in] Indent How many spaces to indent the output.
1699 @param[in] Offset The offset of the printing.
1700 @param[in] DataSize The size in bytes of UserData.
1701 @param[in] UserData The data to print out.
1722 while (DataSize
!= 0) {
1724 if (Size
> DataSize
) {
1728 for (Index
= 0; Index
< Size
; Index
+= 1) {
1729 TempByte
= Data
[Index
];
1730 Val
[Index
* 3 + 0] = Hex
[TempByte
>> 4];
1731 Val
[Index
* 3 + 1] = Hex
[TempByte
& 0xF];
1732 Val
[Index
* 3 + 2] = (CHAR8
) ((Index
== 7) ? '-' : ' ');
1733 Str
[Index
] = (CHAR8
) ((TempByte
< ' ' || TempByte
> 'z') ? '.' : TempByte
);
1738 ShellPrintEx(-1, -1, L
"%*a%08X: %-48a *%a*\r\n", Indent
, "", Offset
, Val
, Str
);