2 Provides interface to shell internal functions for shell commands.
4 Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>
6 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<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.
18 #include "UefiShellCommandLib.h"
20 // STATIC local variables
21 STATIC SHELL_COMMAND_INTERNAL_LIST_ENTRY mCommandList
;
22 STATIC SCRIPT_FILE_LIST mScriptList
;
23 STATIC ALIAS_LIST mAliasList
;
24 STATIC BOOLEAN mEchoState
;
25 STATIC BOOLEAN mExitRequested
;
26 STATIC UINT64 mExitCode
;
27 STATIC BOOLEAN mExitScript
;
28 STATIC CHAR16
*mProfileList
;
29 STATIC UINTN mProfileListSize
;
30 STATIC UINTN mFsMaxCount
= 0;
31 STATIC UINTN mBlkMaxCount
= 0;
32 STATIC BUFFER_LIST mFileHandleList
;
34 STATIC CONST CHAR8 Hex
[] = {
53 // global variables required by library class.
54 EFI_UNICODE_COLLATION_PROTOCOL
*gUnicodeCollation
= NULL
;
55 SHELL_MAP_LIST gShellMapList
;
56 SHELL_MAP_LIST
*gShellCurDir
= NULL
;
58 CONST CHAR16
* SupportLevel
[] = {
66 Function to make sure that the global protocol pointers are valid.
67 must be called after constructor before accessing the pointers.
76 if (gUnicodeCollation
== NULL
) {
77 Status
= gBS
->LocateProtocol(&gEfiUnicodeCollation2ProtocolGuid
, NULL
, (VOID
**)&gUnicodeCollation
);
78 if (EFI_ERROR(Status
)) {
79 return (EFI_DEVICE_ERROR
);
86 Constructor for the Shell Command library.
88 Initialize the library and determine if the underlying is a UEFI Shell 2.0 or an EFI shell.
90 @param ImageHandle the image handle of the process
91 @param SystemTable the EFI System Table pointer
93 @retval EFI_SUCCESS the initialization was complete sucessfully
97 ShellCommandLibConstructor (
98 IN EFI_HANDLE ImageHandle
,
99 IN EFI_SYSTEM_TABLE
*SystemTable
103 InitializeListHead(&gShellMapList
.Link
);
104 InitializeListHead(&mCommandList
.Link
);
105 InitializeListHead(&mAliasList
.Link
);
106 InitializeListHead(&mScriptList
.Link
);
107 InitializeListHead(&mFileHandleList
.Link
);
110 mExitRequested
= FALSE
;
112 mProfileListSize
= 0;
115 if (gUnicodeCollation
== NULL
) {
116 Status
= gBS
->LocateProtocol(&gEfiUnicodeCollation2ProtocolGuid
, NULL
, (VOID
**)&gUnicodeCollation
);
117 if (EFI_ERROR(Status
)) {
118 return (EFI_DEVICE_ERROR
);
122 return (RETURN_SUCCESS
);
126 Frees list of file handles.
128 @param[in] List The list to free.
136 BUFFER_LIST
*BufferListEntry
;
142 // enumerate through the buffer list and free all memory
144 for ( BufferListEntry
= ( BUFFER_LIST
*)GetFirstNode(&List
->Link
)
145 ; !IsListEmpty (&List
->Link
)
146 ; BufferListEntry
= (BUFFER_LIST
*)GetFirstNode(&List
->Link
)
148 RemoveEntryList(&BufferListEntry
->Link
);
149 ASSERT(BufferListEntry
->Buffer
!= NULL
);
150 SHELL_FREE_NON_NULL(((SHELL_COMMAND_FILE_HANDLE
*)(BufferListEntry
->Buffer
))->Path
);
151 SHELL_FREE_NON_NULL(BufferListEntry
->Buffer
);
152 SHELL_FREE_NON_NULL(BufferListEntry
);
157 Destructor for the library. free any resources.
159 @param ImageHandle the image handle of the process
160 @param SystemTable the EFI System Table pointer
162 @retval RETURN_SUCCESS this function always returns success
166 ShellCommandLibDestructor (
167 IN EFI_HANDLE ImageHandle
,
168 IN EFI_SYSTEM_TABLE
*SystemTable
171 SHELL_COMMAND_INTERNAL_LIST_ENTRY
*Node
;
173 SCRIPT_FILE_LIST
*Node3
;
174 SHELL_MAP_LIST
*MapNode
;
176 // enumerate throught the list and free all the memory
178 while (!IsListEmpty (&mCommandList
.Link
)) {
179 Node
= (SHELL_COMMAND_INTERNAL_LIST_ENTRY
*)GetFirstNode(&mCommandList
.Link
);
180 RemoveEntryList(&Node
->Link
);
181 SHELL_FREE_NON_NULL(Node
->CommandString
);
183 DEBUG_CODE(Node
= NULL
;);
187 // enumerate through the alias list and free all memory
189 while (!IsListEmpty (&mAliasList
.Link
)) {
190 Node2
= (ALIAS_LIST
*)GetFirstNode(&mAliasList
.Link
);
191 RemoveEntryList(&Node2
->Link
);
192 SHELL_FREE_NON_NULL(Node2
->CommandString
);
193 SHELL_FREE_NON_NULL(Node2
->Alias
);
194 SHELL_FREE_NON_NULL(Node2
);
195 DEBUG_CODE(Node2
= NULL
;);
199 // enumerate throught the list and free all the memory
201 while (!IsListEmpty (&mScriptList
.Link
)) {
202 Node3
= (SCRIPT_FILE_LIST
*)GetFirstNode(&mScriptList
.Link
);
203 RemoveEntryList(&Node3
->Link
);
204 DeleteScriptFileStruct(Node3
->Data
);
209 // enumerate throught the mappings list and free all the memory
211 if (!IsListEmpty(&gShellMapList
.Link
)) {
212 for (MapNode
= (SHELL_MAP_LIST
*)GetFirstNode(&gShellMapList
.Link
)
213 ; !IsListEmpty (&gShellMapList
.Link
)
214 ; MapNode
= (SHELL_MAP_LIST
*)GetFirstNode(&gShellMapList
.Link
)
216 ASSERT(MapNode
!= NULL
);
217 RemoveEntryList(&MapNode
->Link
);
218 SHELL_FREE_NON_NULL(MapNode
->DevicePath
);
219 SHELL_FREE_NON_NULL(MapNode
->MapName
);
220 SHELL_FREE_NON_NULL(MapNode
->CurrentDirectoryPath
);
224 if (!IsListEmpty(&mFileHandleList
.Link
)){
225 FreeFileHandleList(&mFileHandleList
);
228 if (mProfileList
!= NULL
) {
229 FreePool(mProfileList
);
232 gUnicodeCollation
= NULL
;
235 return (RETURN_SUCCESS
);
239 Find a dynamic command protocol instance given a command name string.
241 @param CommandString the command name string
243 @return instance the command protocol instance, if dynamic command instance found
244 @retval NULL no dynamic command protocol instance found for name
246 CONST EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL
*
248 ShellCommandFindDynamicCommand (
249 IN CONST CHAR16
*CommandString
253 EFI_HANDLE
*CommandHandleList
;
254 EFI_HANDLE
*NextCommand
;
255 EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL
*DynamicCommand
;
257 CommandHandleList
= GetHandleListByProtocol(&gEfiShellDynamicCommandProtocolGuid
);
258 if (CommandHandleList
== NULL
) {
260 // not found or out of resources
265 for (NextCommand
= CommandHandleList
; *NextCommand
!= NULL
; NextCommand
++) {
266 Status
= gBS
->HandleProtocol(
268 &gEfiShellDynamicCommandProtocolGuid
,
269 (VOID
**)&DynamicCommand
272 if (EFI_ERROR(Status
)) {
276 if (gUnicodeCollation
->StriColl(
278 (CHAR16
*)CommandString
,
279 (CHAR16
*)DynamicCommand
->CommandName
) == 0
281 FreePool(CommandHandleList
);
282 return (DynamicCommand
);
286 FreePool(CommandHandleList
);
291 Checks if a command exists as a dynamic command protocol instance
293 @param[in] CommandString The command string to check for on the list.
297 ShellCommandDynamicCommandExists (
298 IN CONST CHAR16
*CommandString
301 return (BOOLEAN
) ((ShellCommandFindDynamicCommand(CommandString
) != NULL
));
305 Checks if a command is already on the internal command list.
307 @param[in] CommandString The command string to check for on the list.
311 ShellCommandIsCommandOnInternalList(
312 IN CONST CHAR16
*CommandString
315 SHELL_COMMAND_INTERNAL_LIST_ENTRY
*Node
;
318 // assert for NULL parameter
320 ASSERT(CommandString
!= NULL
);
323 // check for the command
325 for ( Node
= (SHELL_COMMAND_INTERNAL_LIST_ENTRY
*)GetFirstNode(&mCommandList
.Link
)
326 ; !IsNull(&mCommandList
.Link
, &Node
->Link
)
327 ; Node
= (SHELL_COMMAND_INTERNAL_LIST_ENTRY
*)GetNextNode(&mCommandList
.Link
, &Node
->Link
)
329 ASSERT(Node
->CommandString
!= NULL
);
330 if (gUnicodeCollation
->StriColl(
332 (CHAR16
*)CommandString
,
333 Node
->CommandString
) == 0
342 Checks if a command exists, either internally or through the dynamic command protocol.
344 @param[in] CommandString The command string to check for on the list.
348 ShellCommandIsCommandOnList(
349 IN CONST CHAR16
*CommandString
352 if (ShellCommandIsCommandOnInternalList(CommandString
)) {
356 return ShellCommandDynamicCommandExists(CommandString
);
360 Get the help text for a dynamic command.
362 @param[in] CommandString The command name.
364 @retval NULL No help text was found.
365 @return String of help text. Caller required to free.
369 ShellCommandGetDynamicCommandHelp(
370 IN CONST CHAR16
*CommandString
373 EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL
*DynamicCommand
;
375 DynamicCommand
= (EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL
*)ShellCommandFindDynamicCommand(CommandString
);
376 if (DynamicCommand
== NULL
) {
381 // TODO: how to get proper language?
383 return DynamicCommand
->GetHelp(DynamicCommand
, "en");
387 Get the help text for an internal command.
389 @param[in] CommandString The command name.
391 @retval NULL No help text was found.
392 @return String of help text. Caller reuiqred to free.
396 ShellCommandGetInternalCommandHelp(
397 IN CONST CHAR16
*CommandString
400 SHELL_COMMAND_INTERNAL_LIST_ENTRY
*Node
;
403 // assert for NULL parameter
405 ASSERT(CommandString
!= NULL
);
408 // check for the command
410 for ( Node
= (SHELL_COMMAND_INTERNAL_LIST_ENTRY
*)GetFirstNode(&mCommandList
.Link
)
411 ; !IsNull(&mCommandList
.Link
, &Node
->Link
)
412 ; Node
= (SHELL_COMMAND_INTERNAL_LIST_ENTRY
*)GetNextNode(&mCommandList
.Link
, &Node
->Link
)
414 ASSERT(Node
->CommandString
!= NULL
);
415 if (gUnicodeCollation
->StriColl(
417 (CHAR16
*)CommandString
,
418 Node
->CommandString
) == 0
420 return (HiiGetString(Node
->HiiHandle
, Node
->ManFormatHelp
, NULL
));
427 Get the help text for a command.
429 @param[in] CommandString The command name.
431 @retval NULL No help text was found.
432 @return String of help text.Caller reuiqred to free.
436 ShellCommandGetCommandHelp (
437 IN CONST CHAR16
*CommandString
441 HelpStr
= ShellCommandGetInternalCommandHelp(CommandString
);
443 if (HelpStr
== NULL
) {
444 HelpStr
= ShellCommandGetDynamicCommandHelp(CommandString
);
452 Registers handlers of type SHELL_RUN_COMMAND and
453 SHELL_GET_MAN_FILENAME for each shell command.
455 If the ShellSupportLevel is greater than the value of the
456 PcdShellSupportLevel then return RETURN_UNSUPPORTED.
458 Registers the handlers specified by GetHelpInfoHandler and CommandHandler
459 with the command specified by CommandString. If the command named by
460 CommandString has already been registered, then return
461 RETURN_ALREADY_STARTED.
463 If there are not enough resources available to register the handlers then
464 RETURN_OUT_OF_RESOURCES is returned.
466 If CommandString is NULL, then ASSERT().
467 If GetHelpInfoHandler is NULL, then ASSERT().
468 If CommandHandler is NULL, then ASSERT().
469 If ProfileName is NULL, then ASSERT().
471 @param[in] CommandString Pointer to the command name. This is the
472 name to look for on the command line in
474 @param[in] CommandHandler Pointer to a function that runs the
476 @param[in] GetManFileName Pointer to a function that provides man
478 @param[in] ShellMinSupportLevel minimum Shell Support Level which has this
480 @param[in] ProfileName profile name to require for support of this
482 @param[in] CanAffectLE indicates whether this command's return value
483 can change the LASTERROR environment variable.
484 @param[in] HiiHandle Handle of this command's HII entry.
485 @param[in] ManFormatHelp HII locator for the help text.
487 @retval RETURN_SUCCESS The handlers were registered.
488 @retval RETURN_OUT_OF_RESOURCES There are not enough resources available to
489 register the shell command.
490 @retval RETURN_UNSUPPORTED the ShellMinSupportLevel was higher than the
491 currently allowed support level.
492 @retval RETURN_ALREADY_STARTED The CommandString represents a command that
493 is already registered. Only 1 handler set for
494 a given command is allowed.
495 @sa SHELL_GET_MAN_FILENAME
496 @sa SHELL_RUN_COMMAND
500 ShellCommandRegisterCommandName (
501 IN CONST CHAR16
*CommandString
,
502 IN SHELL_RUN_COMMAND CommandHandler
,
503 IN SHELL_GET_MAN_FILENAME GetManFileName
,
504 IN UINT32 ShellMinSupportLevel
,
505 IN CONST CHAR16
*ProfileName
,
506 IN CONST BOOLEAN CanAffectLE
,
507 IN CONST EFI_HANDLE HiiHandle
,
508 IN CONST EFI_STRING_ID ManFormatHelp
511 SHELL_COMMAND_INTERNAL_LIST_ENTRY
*Node
;
512 SHELL_COMMAND_INTERNAL_LIST_ENTRY
*Command
;
513 SHELL_COMMAND_INTERNAL_LIST_ENTRY
*PrevCommand
;
514 INTN LexicalMatchValue
;
517 // Initialize local variables.
521 LexicalMatchValue
= 0;
524 // ASSERTs for NULL parameters
526 ASSERT(CommandString
!= NULL
);
527 ASSERT(GetManFileName
!= NULL
);
528 ASSERT(CommandHandler
!= NULL
);
529 ASSERT(ProfileName
!= NULL
);
532 // check for shell support level
534 if (PcdGet8(PcdShellSupportLevel
) < ShellMinSupportLevel
) {
535 return (RETURN_UNSUPPORTED
);
539 // check for already on the list
541 if (ShellCommandIsCommandOnList(CommandString
)) {
542 return (RETURN_ALREADY_STARTED
);
546 // allocate memory for new struct
548 Node
= AllocateZeroPool(sizeof(SHELL_COMMAND_INTERNAL_LIST_ENTRY
));
550 return RETURN_OUT_OF_RESOURCES
;
552 Node
->CommandString
= AllocateCopyPool(StrSize(CommandString
), CommandString
);
553 if (Node
->CommandString
== NULL
) {
555 return RETURN_OUT_OF_RESOURCES
;
558 Node
->GetManFileName
= GetManFileName
;
559 Node
->CommandHandler
= CommandHandler
;
560 Node
->LastError
= CanAffectLE
;
561 Node
->HiiHandle
= HiiHandle
;
562 Node
->ManFormatHelp
= ManFormatHelp
;
564 if ( StrLen(ProfileName
)>0
565 && ((mProfileList
!= NULL
566 && StrStr(mProfileList
, ProfileName
) == NULL
) || mProfileList
== NULL
)
568 ASSERT((mProfileList
== NULL
&& mProfileListSize
== 0) || (mProfileList
!= NULL
));
569 if (mProfileList
== NULL
) {
571 // If this is the first make a leading ';'
573 StrnCatGrow(&mProfileList
, &mProfileListSize
, L
";", 0);
575 StrnCatGrow(&mProfileList
, &mProfileListSize
, ProfileName
, 0);
576 StrnCatGrow(&mProfileList
, &mProfileListSize
, L
";", 0);
580 // Insert a new entry on top of the list
582 InsertHeadList (&mCommandList
.Link
, &Node
->Link
);
585 // Move a new registered command to its sorted ordered location in the list
587 for (Command
= (SHELL_COMMAND_INTERNAL_LIST_ENTRY
*)GetFirstNode (&mCommandList
.Link
),
588 PrevCommand
= (SHELL_COMMAND_INTERNAL_LIST_ENTRY
*)GetFirstNode (&mCommandList
.Link
)
589 ; !IsNull (&mCommandList
.Link
, &Command
->Link
)
590 ; Command
= (SHELL_COMMAND_INTERNAL_LIST_ENTRY
*)GetNextNode (&mCommandList
.Link
, &Command
->Link
)) {
593 // Get Lexical Comparison Value between PrevCommand and Command list entry
595 LexicalMatchValue
= gUnicodeCollation
->StriColl (
597 PrevCommand
->CommandString
,
598 Command
->CommandString
602 // Swap PrevCommand and Command list entry if PrevCommand list entry
603 // is alphabetically greater than Command list entry
605 if (LexicalMatchValue
> 0){
606 Command
= (SHELL_COMMAND_INTERNAL_LIST_ENTRY
*) SwapListEntries (&PrevCommand
->Link
, &Command
->Link
);
607 } else if (LexicalMatchValue
< 0) {
609 // PrevCommand entry is lexically lower than Command entry
615 return (RETURN_SUCCESS
);
619 Function to get the current Profile string.
621 @retval NULL There are no installed profiles.
622 @return A semi-colon delimited list of profiles.
626 ShellCommandGetProfileList (
630 return (mProfileList
);
634 Checks if a command string has been registered for CommandString and if so it runs
635 the previously registered handler for that command with the command line.
637 If CommandString is NULL, then ASSERT().
639 If Sections is specified, then each section name listed will be compared in a casesensitive
640 manner, to the section names described in Appendix B UEFI Shell 2.0 spec. If the section exists,
641 it will be appended to the returned help text. If the section does not exist, no
642 information will be returned. If Sections is NULL, then all help text information
643 available will be returned.
645 @param[in] CommandString Pointer to the command name. This is the name
646 found on the command line in the shell.
647 @param[in, out] RetVal Pointer to the return vaule from the command handler.
649 @param[in, out] CanAffectLE indicates whether this command's return value
650 needs to be placed into LASTERROR environment variable.
652 @retval RETURN_SUCCESS The handler was run.
653 @retval RETURN_NOT_FOUND The CommandString did not match a registered
655 @sa SHELL_RUN_COMMAND
659 ShellCommandRunCommandHandler (
660 IN CONST CHAR16
*CommandString
,
661 IN OUT SHELL_STATUS
*RetVal
,
662 IN OUT BOOLEAN
*CanAffectLE OPTIONAL
665 SHELL_COMMAND_INTERNAL_LIST_ENTRY
*Node
;
666 EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL
*DynamicCommand
;
669 // assert for NULL parameters
671 ASSERT(CommandString
!= NULL
);
674 // check for the command
676 for ( Node
= (SHELL_COMMAND_INTERNAL_LIST_ENTRY
*)GetFirstNode(&mCommandList
.Link
)
677 ; !IsNull(&mCommandList
.Link
, &Node
->Link
)
678 ; Node
= (SHELL_COMMAND_INTERNAL_LIST_ENTRY
*)GetNextNode(&mCommandList
.Link
, &Node
->Link
)
680 ASSERT(Node
->CommandString
!= NULL
);
681 if (gUnicodeCollation
->StriColl(
683 (CHAR16
*)CommandString
,
684 Node
->CommandString
) == 0
686 if (CanAffectLE
!= NULL
) {
687 *CanAffectLE
= Node
->LastError
;
689 if (RetVal
!= NULL
) {
690 *RetVal
= Node
->CommandHandler(NULL
, gST
);
692 Node
->CommandHandler(NULL
, gST
);
694 return (RETURN_SUCCESS
);
699 // An internal command was not found, try to find a dynamic command
701 DynamicCommand
= (EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL
*)ShellCommandFindDynamicCommand(CommandString
);
702 if (DynamicCommand
!= NULL
) {
703 if (RetVal
!= NULL
) {
704 *RetVal
= DynamicCommand
->Handler(DynamicCommand
, gST
, gEfiShellParametersProtocol
, gEfiShellProtocol
);
706 DynamicCommand
->Handler(DynamicCommand
, gST
, gEfiShellParametersProtocol
, gEfiShellProtocol
);
708 return (RETURN_SUCCESS
);
711 return (RETURN_NOT_FOUND
);
715 Checks if a command string has been registered for CommandString and if so it
716 returns the MAN filename specified for that command.
718 If CommandString is NULL, then ASSERT().
720 @param[in] CommandString Pointer to the command name. This is the name
721 found on the command line in the shell.\
723 @retval NULL the commandString was not a registered command.
724 @return other the name of the MAN file.
725 @sa SHELL_GET_MAN_FILENAME
729 ShellCommandGetManFileNameHandler (
730 IN CONST CHAR16
*CommandString
733 SHELL_COMMAND_INTERNAL_LIST_ENTRY
*Node
;
736 // assert for NULL parameters
738 ASSERT(CommandString
!= NULL
);
741 // check for the command
743 for ( Node
= (SHELL_COMMAND_INTERNAL_LIST_ENTRY
*)GetFirstNode(&mCommandList
.Link
)
744 ; !IsNull(&mCommandList
.Link
, &Node
->Link
)
745 ; Node
= (SHELL_COMMAND_INTERNAL_LIST_ENTRY
*)GetNextNode(&mCommandList
.Link
, &Node
->Link
)
747 ASSERT(Node
->CommandString
!= NULL
);
748 if (gUnicodeCollation
->StriColl(
750 (CHAR16
*)CommandString
,
751 Node
->CommandString
) == 0
753 return (Node
->GetManFileName());
760 Get the list of all available shell internal commands. This is a linked list
761 (via LIST_ENTRY structure). enumerate through it using the BaseLib linked
762 list functions. do not modify the values.
764 @param[in] Sort TRUE to alphabetically sort the values first. FALSE otherwise.
766 @return a Linked list of all available shell commands.
770 ShellCommandGetCommandList (
771 IN CONST BOOLEAN Sort
775 // return ((COMMAND_LIST*)(&mCommandList));
777 return ((COMMAND_LIST
*)(&mCommandList
));
781 Registers aliases to be set as part of the initialization of the shell application.
783 If Command is NULL, then ASSERT().
784 If Alias is NULL, then ASSERT().
786 @param[in] Command Pointer to the Command
787 @param[in] Alias Pointer to Alias
789 @retval RETURN_SUCCESS The handlers were registered.
790 @retval RETURN_OUT_OF_RESOURCES There are not enough resources available to
791 register the shell command.
795 ShellCommandRegisterAlias (
796 IN CONST CHAR16
*Command
,
797 IN CONST CHAR16
*Alias
801 ALIAS_LIST
*CommandAlias
;
802 ALIAS_LIST
*PrevCommandAlias
;
803 INTN LexicalMatchValue
;
808 ASSERT(Command
!= NULL
);
809 ASSERT(Alias
!= NULL
);
812 // allocate memory for new struct
814 Node
= AllocateZeroPool(sizeof(ALIAS_LIST
));
816 return RETURN_OUT_OF_RESOURCES
;
818 Node
->CommandString
= AllocateCopyPool(StrSize(Command
), Command
);
819 if (Node
->CommandString
== NULL
) {
821 return RETURN_OUT_OF_RESOURCES
;
823 Node
->Alias
= AllocateCopyPool(StrSize(Alias
), Alias
);
824 if (Node
->Alias
== NULL
) {
825 FreePool (Node
->CommandString
);
827 return RETURN_OUT_OF_RESOURCES
;
830 InsertHeadList (&mAliasList
.Link
, &Node
->Link
);
833 // Move a new pre-defined registered alias to its sorted ordered location in the list
835 for ( CommandAlias
= (ALIAS_LIST
*)GetFirstNode (&mAliasList
.Link
),
836 PrevCommandAlias
= (ALIAS_LIST
*)GetFirstNode (&mAliasList
.Link
)
837 ; !IsNull (&mAliasList
.Link
, &CommandAlias
->Link
)
838 ; CommandAlias
= (ALIAS_LIST
*) GetNextNode (&mAliasList
.Link
, &CommandAlias
->Link
) ) {
840 // Get Lexical comparison value between PrevCommandAlias and CommandAlias List Entry
842 LexicalMatchValue
= gUnicodeCollation
->StriColl (
844 PrevCommandAlias
->Alias
,
849 // Swap PrevCommandAlias and CommandAlias list entry if PrevCommandAlias list entry
850 // is alphabetically greater than CommandAlias list entry
852 if (LexicalMatchValue
> 0) {
853 CommandAlias
= (ALIAS_LIST
*) SwapListEntries (&PrevCommandAlias
->Link
, &CommandAlias
->Link
);
854 } else if (LexicalMatchValue
< 0) {
856 // PrevCommandAlias entry is lexically lower than CommandAlias entry
862 return (RETURN_SUCCESS
);
866 Get the list of all shell alias commands. This is a linked list
867 (via LIST_ENTRY structure). enumerate through it using the BaseLib linked
868 list functions. do not modify the values.
870 @return a Linked list of all requested shell alias'.
874 ShellCommandGetInitAliasList (
878 return (&mAliasList
);
882 Determine if a given alias is on the list of built in alias'.
884 @param[in] Alias The alias to test for
886 @retval TRUE The alias is a built in alias
887 @retval FALSE The alias is not a built in alias
891 ShellCommandIsOnAliasList(
892 IN CONST CHAR16
*Alias
898 // assert for NULL parameter
900 ASSERT(Alias
!= NULL
);
903 // check for the Alias
905 for ( Node
= (ALIAS_LIST
*)GetFirstNode(&mAliasList
.Link
)
906 ; !IsNull(&mAliasList
.Link
, &Node
->Link
)
907 ; Node
= (ALIAS_LIST
*)GetNextNode(&mAliasList
.Link
, &Node
->Link
)
909 ASSERT(Node
->CommandString
!= NULL
);
910 ASSERT(Node
->Alias
!= NULL
);
911 if (gUnicodeCollation
->StriColl(
914 Node
->CommandString
) == 0
918 if (gUnicodeCollation
->StriColl(
930 Function to determine current state of ECHO. Echo determines if lines from scripts
931 and ECHO commands are enabled.
933 @retval TRUE Echo is currently enabled
934 @retval FALSE Echo is currently disabled
938 ShellCommandGetEchoState(
946 Function to set current state of ECHO. Echo determines if lines from scripts
947 and ECHO commands are enabled.
949 If State is TRUE, Echo will be enabled.
950 If State is FALSE, Echo will be disabled.
952 @param[in] State How to set echo.
956 ShellCommandSetEchoState(
964 Indicate that the current shell or script should exit.
966 @param[in] ScriptOnly TRUE if exiting a script; FALSE otherwise.
967 @param[in] ErrorCode The 64 bit error code to return.
971 ShellCommandRegisterExit (
972 IN BOOLEAN ScriptOnly
,
973 IN CONST UINT64 ErrorCode
976 mExitRequested
= (BOOLEAN
)(!mExitRequested
);
977 if (mExitRequested
) {
978 mExitScript
= ScriptOnly
;
982 mExitCode
= ErrorCode
;
986 Retrieve the Exit indicator.
988 @retval TRUE Exit was indicated.
989 @retval FALSE Exis was not indicated.
993 ShellCommandGetExit (
997 return (mExitRequested
);
1001 Retrieve the Exit code.
1003 If ShellCommandGetExit returns FALSE than the return from this is undefined.
1005 @return the value passed into RegisterExit.
1009 ShellCommandGetExitCode (
1016 Retrieve the Exit script indicator.
1018 If ShellCommandGetExit returns FALSE than the return from this is undefined.
1020 @retval TRUE ScriptOnly was indicated.
1021 @retval FALSE ScriptOnly was not indicated.
1025 ShellCommandGetScriptExit (
1029 return (mExitScript
);
1033 Function to cleanup all memory from a SCRIPT_FILE structure.
1035 @param[in] Script The pointer to the structure to cleanup.
1039 DeleteScriptFileStruct (
1040 IN SCRIPT_FILE
*Script
1045 if (Script
== NULL
) {
1049 for (LoopVar
= 0 ; LoopVar
< Script
->Argc
; LoopVar
++) {
1050 SHELL_FREE_NON_NULL(Script
->Argv
[LoopVar
]);
1052 if (Script
->Argv
!= NULL
) {
1053 SHELL_FREE_NON_NULL(Script
->Argv
);
1055 Script
->CurrentCommand
= NULL
;
1056 while (!IsListEmpty (&Script
->CommandList
)) {
1057 Script
->CurrentCommand
= (SCRIPT_COMMAND_LIST
*)GetFirstNode(&Script
->CommandList
);
1058 if (Script
->CurrentCommand
!= NULL
) {
1059 RemoveEntryList(&Script
->CurrentCommand
->Link
);
1060 if (Script
->CurrentCommand
->Cl
!= NULL
) {
1061 SHELL_FREE_NON_NULL(Script
->CurrentCommand
->Cl
);
1063 if (Script
->CurrentCommand
->Data
!= NULL
) {
1064 SHELL_FREE_NON_NULL(Script
->CurrentCommand
->Data
);
1066 SHELL_FREE_NON_NULL(Script
->CurrentCommand
);
1069 SHELL_FREE_NON_NULL(Script
->ScriptName
);
1070 SHELL_FREE_NON_NULL(Script
);
1074 Function to return a pointer to the currently running script file object.
1076 @retval NULL A script file is not currently running.
1077 @return A pointer to the current script file object.
1081 ShellCommandGetCurrentScriptFile (
1085 SCRIPT_FILE_LIST
*List
;
1086 if (IsListEmpty (&mScriptList
.Link
)) {
1089 List
= ((SCRIPT_FILE_LIST
*)GetFirstNode(&mScriptList
.Link
));
1090 return (List
->Data
);
1094 Function to set a new script as the currently running one.
1096 This function will correctly stack and unstack nested scripts.
1098 @param[in] Script Pointer to new script information structure. if NULL
1099 will remove and de-allocate the top-most Script structure.
1101 @return A pointer to the current running script file after this
1102 change. NULL if removing the final script.
1106 ShellCommandSetNewScript (
1107 IN SCRIPT_FILE
*Script OPTIONAL
1110 SCRIPT_FILE_LIST
*Node
;
1111 if (Script
== NULL
) {
1112 if (IsListEmpty (&mScriptList
.Link
)) {
1115 Node
= (SCRIPT_FILE_LIST
*)GetFirstNode(&mScriptList
.Link
);
1116 RemoveEntryList(&Node
->Link
);
1117 DeleteScriptFileStruct(Node
->Data
);
1120 Node
= AllocateZeroPool(sizeof(SCRIPT_FILE_LIST
));
1124 Node
->Data
= Script
;
1125 InsertHeadList(&mScriptList
.Link
, &Node
->Link
);
1127 return (ShellCommandGetCurrentScriptFile());
1131 Function to generate the next default mapping name.
1133 If the return value is not NULL then it must be callee freed.
1135 @param Type What kind of mapping name to make.
1137 @retval NULL a memory allocation failed.
1138 @return a new map name string
1142 ShellCommandCreateNewMappingName(
1143 IN CONST SHELL_MAPPING_TYPE Type
1147 ASSERT(Type
< MappingTypeMax
);
1151 String
= AllocateZeroPool(PcdGet8(PcdShellMapNameLength
) * sizeof(String
[0]));
1154 PcdGet8(PcdShellMapNameLength
) * sizeof(String
[0]),
1155 Type
== MappingTypeFileSystem
?L
"FS%d:":L
"BLK%d:",
1156 Type
== MappingTypeFileSystem
?mFsMaxCount
++:mBlkMaxCount
++);
1162 Function to add a map node to the list of map items and update the "path" environment variable (optionally).
1164 If Path is TRUE (during initialization only), the path environment variable will also be updated to include
1165 default paths on the new map name...
1167 Path should be FALSE when this function is called from the protocol SetMap function.
1169 @param[in] Name The human readable mapped name.
1170 @param[in] DevicePath The Device Path for this map.
1171 @param[in] Flags The Flags attribute for this map item.
1172 @param[in] Path TRUE to update path, FALSE to skip this step (should only be TRUE during initialization).
1174 @retval EFI_SUCCESS The addition was sucessful.
1175 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
1176 @retval EFI_INVALID_PARAMETER A parameter was invalid.
1180 ShellCommandAddMapItemAndUpdatePath(
1181 IN CONST CHAR16
*Name
,
1182 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
1183 IN CONST UINT64 Flags
,
1184 IN CONST BOOLEAN Path
1188 SHELL_MAP_LIST
*MapListNode
;
1189 CONST CHAR16
*OriginalPath
;
1195 OriginalPath
= NULL
;
1196 Status
= EFI_SUCCESS
;
1198 MapListNode
= AllocateZeroPool(sizeof(SHELL_MAP_LIST
));
1199 if (MapListNode
== NULL
) {
1200 Status
= EFI_OUT_OF_RESOURCES
;
1202 MapListNode
->Flags
= Flags
;
1203 MapListNode
->MapName
= AllocateCopyPool(StrSize(Name
), Name
);
1204 MapListNode
->DevicePath
= DuplicateDevicePath(DevicePath
);
1205 if ((MapListNode
->MapName
== NULL
) || (MapListNode
->DevicePath
== NULL
)){
1206 Status
= EFI_OUT_OF_RESOURCES
;
1208 InsertTailList(&gShellMapList
.Link
, &MapListNode
->Link
);
1211 if (EFI_ERROR(Status
)) {
1212 if (MapListNode
!= NULL
) {
1213 if (MapListNode
->DevicePath
!= NULL
) {
1214 FreePool(MapListNode
->DevicePath
);
1216 if (MapListNode
->MapName
!= NULL
) {
1217 FreePool(MapListNode
->MapName
);
1219 FreePool(MapListNode
);
1223 // Since there was no error and Path was TRUE
1224 // Now add the correct path for that mapping
1226 OriginalPath
= gEfiShellProtocol
->GetEnv(L
"path");
1227 ASSERT((NewPath
== NULL
&& NewPathSize
== 0) || (NewPath
!= NULL
));
1228 if (OriginalPath
!= NULL
) {
1229 StrnCatGrow(&NewPath
, &NewPathSize
, OriginalPath
, 0);
1230 StrnCatGrow(&NewPath
, &NewPathSize
, L
";", 0);
1232 StrnCatGrow(&NewPath
, &NewPathSize
, Name
, 0);
1233 StrnCatGrow(&NewPath
, &NewPathSize
, L
"\\efi\\tools\\;", 0);
1234 StrnCatGrow(&NewPath
, &NewPathSize
, Name
, 0);
1235 StrnCatGrow(&NewPath
, &NewPathSize
, L
"\\efi\\boot\\;", 0);
1236 StrnCatGrow(&NewPath
, &NewPathSize
, Name
, 0);
1237 StrnCatGrow(&NewPath
, &NewPathSize
, L
"\\", 0);
1239 Status
= gEfiShellProtocol
->SetEnv(L
"path", NewPath
, TRUE
);
1240 ASSERT_EFI_ERROR(Status
);
1247 Creates the default map names for each device path in the system with
1248 a protocol depending on the Type.
1250 Creates the consistent map names for each device path in the system with
1251 a protocol depending on the Type.
1253 Note: This will reset all mappings in the system("map -r").
1255 Also sets up the default path environment variable if Type is FileSystem.
1257 @retval EFI_SUCCESS All map names were created sucessfully.
1258 @retval EFI_NOT_FOUND No protocols were found in the system.
1259 @return Error returned from gBS->LocateHandle().
1265 ShellCommandCreateInitialMappingsAndPaths(
1270 EFI_HANDLE
*HandleList
;
1272 EFI_DEVICE_PATH_PROTOCOL
**DevicePathList
;
1273 CHAR16
*NewDefaultName
;
1274 CHAR16
*NewConsistName
;
1275 EFI_DEVICE_PATH_PROTOCOL
**ConsistMappingTable
;
1276 SHELL_MAP_LIST
*MapListNode
;
1281 // Reset the static members back to zero
1286 gEfiShellProtocol
->SetEnv(L
"path", L
"", TRUE
);
1289 // First empty out the existing list.
1291 if (!IsListEmpty(&gShellMapList
.Link
)) {
1292 for ( MapListNode
= (SHELL_MAP_LIST
*)GetFirstNode(&gShellMapList
.Link
)
1293 ; !IsListEmpty(&gShellMapList
.Link
)
1294 ; MapListNode
= (SHELL_MAP_LIST
*)GetFirstNode(&gShellMapList
.Link
)
1296 RemoveEntryList(&MapListNode
->Link
);
1297 SHELL_FREE_NON_NULL(MapListNode
->DevicePath
);
1298 SHELL_FREE_NON_NULL(MapListNode
->MapName
);
1299 SHELL_FREE_NON_NULL(MapListNode
->CurrentDirectoryPath
);
1300 FreePool(MapListNode
);
1305 // Find each handle with Simple File System
1307 HandleList
= GetHandleListByProtocol(&gEfiSimpleFileSystemProtocolGuid
);
1308 if (HandleList
!= NULL
) {
1310 // Do a count of the handles
1312 for (Count
= 0 ; HandleList
[Count
] != NULL
; Count
++);
1315 // Get all Device Paths
1317 DevicePathList
= AllocateZeroPool(sizeof(EFI_DEVICE_PATH_PROTOCOL
*) * Count
);
1318 if (DevicePathList
== NULL
) {
1319 SHELL_FREE_NON_NULL (HandleList
);
1320 return EFI_OUT_OF_RESOURCES
;
1323 for (Count
= 0 ; HandleList
[Count
] != NULL
; Count
++) {
1324 DevicePathList
[Count
] = DevicePathFromHandle(HandleList
[Count
]);
1328 // Sort all DevicePaths
1330 PerformQuickSort(DevicePathList
, Count
, sizeof(EFI_DEVICE_PATH_PROTOCOL
*), DevicePathCompare
);
1332 ShellCommandConsistMappingInitialize(&ConsistMappingTable
);
1334 // Assign new Mappings to all...
1336 for (Count
= 0 ; HandleList
[Count
] != NULL
; Count
++) {
1338 // Get default name first
1340 NewDefaultName
= ShellCommandCreateNewMappingName(MappingTypeFileSystem
);
1341 ASSERT(NewDefaultName
!= NULL
);
1342 Status
= ShellCommandAddMapItemAndUpdatePath(NewDefaultName
, DevicePathList
[Count
], 0, TRUE
);
1343 ASSERT_EFI_ERROR(Status
);
1344 FreePool(NewDefaultName
);
1347 // Now do consistent name
1349 NewConsistName
= ShellCommandConsistMappingGenMappingName(DevicePathList
[Count
], ConsistMappingTable
);
1350 if (NewConsistName
!= NULL
) {
1351 Status
= ShellCommandAddMapItemAndUpdatePath(NewConsistName
, DevicePathList
[Count
], 0, FALSE
);
1352 ASSERT_EFI_ERROR(Status
);
1353 FreePool(NewConsistName
);
1357 ShellCommandConsistMappingUnInitialize(ConsistMappingTable
);
1359 SHELL_FREE_NON_NULL(HandleList
);
1360 SHELL_FREE_NON_NULL(DevicePathList
);
1368 // Find each handle with Block Io
1370 HandleList
= GetHandleListByProtocol(&gEfiBlockIoProtocolGuid
);
1371 if (HandleList
!= NULL
) {
1372 for (Count
= 0 ; HandleList
[Count
] != NULL
; Count
++);
1375 // Get all Device Paths
1377 DevicePathList
= AllocateZeroPool(sizeof(EFI_DEVICE_PATH_PROTOCOL
*) * Count
);
1378 if (DevicePathList
== NULL
) {
1379 SHELL_FREE_NON_NULL (HandleList
);
1380 return EFI_OUT_OF_RESOURCES
;
1383 for (Count
= 0 ; HandleList
[Count
] != NULL
; Count
++) {
1384 DevicePathList
[Count
] = DevicePathFromHandle(HandleList
[Count
]);
1388 // Sort all DevicePaths
1390 PerformQuickSort(DevicePathList
, Count
, sizeof(EFI_DEVICE_PATH_PROTOCOL
*), DevicePathCompare
);
1393 // Assign new Mappings to all...
1395 for (Count
= 0 ; HandleList
[Count
] != NULL
; Count
++) {
1397 // Get default name first
1399 NewDefaultName
= ShellCommandCreateNewMappingName(MappingTypeBlockIo
);
1400 ASSERT(NewDefaultName
!= NULL
);
1401 Status
= ShellCommandAddMapItemAndUpdatePath(NewDefaultName
, DevicePathList
[Count
], 0, FALSE
);
1402 ASSERT_EFI_ERROR(Status
);
1403 FreePool(NewDefaultName
);
1406 SHELL_FREE_NON_NULL(HandleList
);
1407 SHELL_FREE_NON_NULL(DevicePathList
);
1408 } else if (Count
== (UINTN
)-1) {
1409 return (EFI_NOT_FOUND
);
1412 return (EFI_SUCCESS
);
1416 Add mappings for any devices without one. Do not change any existing maps.
1418 @retval EFI_SUCCESS The operation was successful.
1422 ShellCommandUpdateMapping (
1427 EFI_HANDLE
*HandleList
;
1429 EFI_DEVICE_PATH_PROTOCOL
**DevicePathList
;
1430 CHAR16
*NewDefaultName
;
1431 CHAR16
*NewConsistName
;
1432 EFI_DEVICE_PATH_PROTOCOL
**ConsistMappingTable
;
1435 Status
= EFI_SUCCESS
;
1438 // remove mappings that represent removed devices.
1442 // Find each handle with Simple File System
1444 HandleList
= GetHandleListByProtocol(&gEfiSimpleFileSystemProtocolGuid
);
1445 if (HandleList
!= NULL
) {
1447 // Do a count of the handles
1449 for (Count
= 0 ; HandleList
[Count
] != NULL
; Count
++);
1452 // Get all Device Paths
1454 DevicePathList
= AllocateZeroPool(sizeof(EFI_DEVICE_PATH_PROTOCOL
*) * Count
);
1455 if (DevicePathList
== NULL
) {
1456 return (EFI_OUT_OF_RESOURCES
);
1459 for (Count
= 0 ; HandleList
[Count
] != NULL
; Count
++) {
1460 DevicePathList
[Count
] = DevicePathFromHandle(HandleList
[Count
]);
1464 // Sort all DevicePaths
1466 PerformQuickSort(DevicePathList
, Count
, sizeof(EFI_DEVICE_PATH_PROTOCOL
*), DevicePathCompare
);
1468 ShellCommandConsistMappingInitialize(&ConsistMappingTable
);
1471 // Assign new Mappings to remainders
1473 for (Count
= 0 ; !EFI_ERROR(Status
) && HandleList
[Count
] != NULL
&& !EFI_ERROR(Status
); Count
++) {
1475 // Skip ones that already have
1477 if (gEfiShellProtocol
->GetMapFromDevicePath(&DevicePathList
[Count
]) != NULL
) {
1483 NewDefaultName
= ShellCommandCreateNewMappingName(MappingTypeFileSystem
);
1484 if (NewDefaultName
== NULL
) {
1485 Status
= EFI_OUT_OF_RESOURCES
;
1490 // Call shell protocol SetMap function now...
1492 Status
= gEfiShellProtocol
->SetMap(DevicePathList
[Count
], NewDefaultName
);
1494 if (!EFI_ERROR(Status
)) {
1496 // Now do consistent name
1498 NewConsistName
= ShellCommandConsistMappingGenMappingName(DevicePathList
[Count
], ConsistMappingTable
);
1499 if (NewConsistName
!= NULL
) {
1500 Status
= gEfiShellProtocol
->SetMap(DevicePathList
[Count
], NewConsistName
);
1501 FreePool(NewConsistName
);
1505 FreePool(NewDefaultName
);
1507 ShellCommandConsistMappingUnInitialize(ConsistMappingTable
);
1508 SHELL_FREE_NON_NULL(HandleList
);
1509 SHELL_FREE_NON_NULL(DevicePathList
);
1516 // Do it all over again for gEfiBlockIoProtocolGuid
1523 Converts a SHELL_FILE_HANDLE to an EFI_FILE_PROTOCOL*.
1525 @param[in] Handle The SHELL_FILE_HANDLE to convert.
1527 @return a EFI_FILE_PROTOCOL* representing the same file.
1531 ConvertShellHandleToEfiFileProtocol(
1532 IN CONST SHELL_FILE_HANDLE Handle
1535 return ((EFI_FILE_PROTOCOL
*)(Handle
));
1539 Converts a EFI_FILE_PROTOCOL* to an SHELL_FILE_HANDLE.
1541 @param[in] Handle The pointer to EFI_FILE_PROTOCOL to convert.
1542 @param[in] Path The path to the file for verification.
1544 @return A SHELL_FILE_HANDLE representing the same file.
1545 @retval NULL There was not enough memory.
1549 ConvertEfiFileProtocolToShellHandle(
1550 IN CONST EFI_FILE_PROTOCOL
*Handle
,
1551 IN CONST CHAR16
*Path
1554 SHELL_COMMAND_FILE_HANDLE
*Buffer
;
1555 BUFFER_LIST
*NewNode
;
1558 Buffer
= AllocateZeroPool(sizeof(SHELL_COMMAND_FILE_HANDLE
));
1559 if (Buffer
== NULL
) {
1562 NewNode
= AllocateZeroPool(sizeof(BUFFER_LIST
));
1563 if (NewNode
== NULL
) {
1564 SHELL_FREE_NON_NULL(Buffer
);
1567 Buffer
->FileHandle
= (EFI_FILE_PROTOCOL
*)Handle
;
1568 Buffer
->Path
= StrnCatGrow(&Buffer
->Path
, NULL
, Path
, 0);
1569 if (Buffer
->Path
== NULL
) {
1570 SHELL_FREE_NON_NULL(NewNode
);
1571 SHELL_FREE_NON_NULL(Buffer
);
1574 NewNode
->Buffer
= Buffer
;
1576 InsertHeadList(&mFileHandleList
.Link
, &NewNode
->Link
);
1578 return ((SHELL_FILE_HANDLE
)(Handle
));
1582 Find the path that was logged with the specified SHELL_FILE_HANDLE.
1584 @param[in] Handle The SHELL_FILE_HANDLE to query on.
1586 @return A pointer to the path for the file.
1590 ShellFileHandleGetPath(
1591 IN CONST SHELL_FILE_HANDLE Handle
1596 for (Node
= (BUFFER_LIST
*)GetFirstNode(&mFileHandleList
.Link
)
1597 ; !IsNull(&mFileHandleList
.Link
, &Node
->Link
)
1598 ; Node
= (BUFFER_LIST
*)GetNextNode(&mFileHandleList
.Link
, &Node
->Link
)
1600 if ((Node
->Buffer
) && (((SHELL_COMMAND_FILE_HANDLE
*)Node
->Buffer
)->FileHandle
== Handle
)){
1601 return (((SHELL_COMMAND_FILE_HANDLE
*)Node
->Buffer
)->Path
);
1608 Remove a SHELL_FILE_HANDLE from the list of SHELL_FILE_HANDLES.
1610 @param[in] Handle The SHELL_FILE_HANDLE to remove.
1612 @retval TRUE The item was removed.
1613 @retval FALSE The item was not found.
1617 ShellFileHandleRemove(
1618 IN CONST SHELL_FILE_HANDLE Handle
1623 for (Node
= (BUFFER_LIST
*)GetFirstNode(&mFileHandleList
.Link
)
1624 ; !IsNull(&mFileHandleList
.Link
, &Node
->Link
)
1625 ; Node
= (BUFFER_LIST
*)GetNextNode(&mFileHandleList
.Link
, &Node
->Link
)
1627 if ((Node
->Buffer
) && (((SHELL_COMMAND_FILE_HANDLE
*)Node
->Buffer
)->FileHandle
== Handle
)){
1628 RemoveEntryList(&Node
->Link
);
1629 SHELL_FREE_NON_NULL(((SHELL_COMMAND_FILE_HANDLE
*)Node
->Buffer
)->Path
);
1630 SHELL_FREE_NON_NULL(Node
->Buffer
);
1631 SHELL_FREE_NON_NULL(Node
);
1639 Function to determine if a SHELL_FILE_HANDLE is at the end of the file.
1641 This will NOT work on directories.
1643 If Handle is NULL, then ASSERT.
1645 @param[in] Handle the file handle
1647 @retval TRUE the position is at the end of the file
1648 @retval FALSE the position is not at the end of the file
1653 IN SHELL_FILE_HANDLE Handle
1656 EFI_FILE_INFO
*Info
;
1661 // ASSERT if Handle is NULL
1663 ASSERT(Handle
!= NULL
);
1665 gEfiShellProtocol
->GetFilePosition(Handle
, &Pos
);
1666 Info
= gEfiShellProtocol
->GetFileInfo (Handle
);
1667 gEfiShellProtocol
->SetFilePosition(Handle
, Pos
);
1673 if (Pos
== Info
->FileSize
) {
1685 Frees any BUFFER_LIST defined type.
1687 @param[in] List The BUFFER_LIST object to free.
1692 IN BUFFER_LIST
*List
1695 BUFFER_LIST
*BufferListEntry
;
1701 // enumerate through the buffer list and free all memory
1703 for ( BufferListEntry
= ( BUFFER_LIST
*)GetFirstNode(&List
->Link
)
1704 ; !IsListEmpty (&List
->Link
)
1705 ; BufferListEntry
= (BUFFER_LIST
*)GetFirstNode(&List
->Link
)
1707 RemoveEntryList(&BufferListEntry
->Link
);
1708 if (BufferListEntry
->Buffer
!= NULL
) {
1709 FreePool(BufferListEntry
->Buffer
);
1711 FreePool(BufferListEntry
);
1716 Dump some hexadecimal data to the screen.
1718 @param[in] Indent How many spaces to indent the output.
1719 @param[in] Offset The offset of the printing.
1720 @param[in] DataSize The size in bytes of UserData.
1721 @param[in] UserData The data to print out.
1742 while (DataSize
!= 0) {
1744 if (Size
> DataSize
) {
1748 for (Index
= 0; Index
< Size
; Index
+= 1) {
1749 TempByte
= Data
[Index
];
1750 Val
[Index
* 3 + 0] = Hex
[TempByte
>> 4];
1751 Val
[Index
* 3 + 1] = Hex
[TempByte
& 0xF];
1752 Val
[Index
* 3 + 2] = (CHAR8
) ((Index
== 7) ? '-' : ' ');
1753 Str
[Index
] = (CHAR8
) ((TempByte
< ' ' || TempByte
> 'z') ? '.' : TempByte
);
1758 ShellPrintEx(-1, -1, L
"%*a%08X: %-48a *%a*\r\n", Indent
, "", Offset
, Val
, Str
);
1767 Dump HEX data into buffer.
1769 @param[in] Buffer HEX data to be dumped in Buffer.
1770 @param[in] Indent How many spaces to indent the output.
1771 @param[in] Offset The offset of the printing.
1772 @param[in] DataSize The size in bytes of UserData.
1773 @param[in] UserData The data to print out.
1795 while (DataSize
!= 0) {
1797 if (Size
> DataSize
) {
1801 for (Index
= 0; Index
< Size
; Index
+= 1) {
1802 TempByte
= Data
[Index
];
1803 Val
[Index
* 3 + 0] = Hex
[TempByte
>> 4];
1804 Val
[Index
* 3 + 1] = Hex
[TempByte
& 0xF];
1805 Val
[Index
* 3 + 2] = (CHAR8
) ((Index
== 7) ? '-' : ' ');
1806 Str
[Index
] = (CHAR8
) ((TempByte
< ' ' || TempByte
> 'z') ? '.' : TempByte
);
1811 TempRetVal
= CatSPrint (RetVal
, L
"%*a%08X: %-48a *%a*\r\n", Indent
, "", Offset
, Val
, Str
);
1812 SHELL_FREE_NON_NULL (RetVal
);
1813 RetVal
= TempRetVal
;