2 Member functions of EFI_SHELL_PARAMETERS_PROTOCOL and functions for creation,
3 manipulation, and initialization of EFI_SHELL_PARAMETERS_PROTOCOL.
5 Copyright (C) 2014, Red Hat, Inc.
6 (C) Copyright 2013 Hewlett-Packard Development Company, L.P.<BR>
7 Copyright (c) 2009 - 2015, 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.
21 Return the next parameter's end from a command line string.
23 @param[in] String the string to parse
28 IN CONST CHAR16
*String
32 CONST CHAR16
*CloseQuote
;
34 First
= FindFirstCharacter(String
, L
" \"", L
'^');
37 // nothing, all one parameter remaining
39 if (*First
== CHAR_NULL
) {
44 // If space before a quote (or neither found, i.e. both CHAR_NULL),
45 // then that's the end.
51 CloseQuote
= FindFirstCharacter (First
+1, L
"\"", L
'^');
54 // We did not find a terminator...
56 if (*CloseQuote
== CHAR_NULL
) {
60 return (FindEndOfParameter (CloseQuote
+1));
64 Return the next parameter from a command line string.
66 This function moves the next parameter from Walker into TempParameter and moves
67 Walker up past that parameter for recursive calling. When the final parameter
68 is moved *Walker will be set to NULL;
70 Temp Parameter must be large enough to hold the parameter before calling this
73 This will also remove all remaining ^ characters after processing.
75 @param[in, out] Walker pointer to string of command line. Adjusted to
76 reminaing command line on return
77 @param[in, out] TempParameter pointer to string of command line item extracted.
78 @param[in] Length buffer size of TempParameter.
80 @return EFI_INALID_PARAMETER A required parameter was NULL or pointed to a NULL or empty string.
81 @return EFI_NOT_FOUND A closing " could not be found on the specified string
86 IN OUT CHAR16
**Walker
,
87 IN OUT CHAR16
**TempParameter
,
91 CONST CHAR16
*NextDelim
;
95 ||TempParameter
== NULL
96 ||*TempParameter
== NULL
98 return (EFI_INVALID_PARAMETER
);
103 // make sure we dont have any leading spaces
105 while ((*Walker
)[0] == L
' ') {
110 // make sure we still have some params now...
112 if (StrLen(*Walker
) == 0) {
116 return (EFI_INVALID_PARAMETER
);
119 NextDelim
= FindEndOfParameter(*Walker
);
121 if (NextDelim
== NULL
){
125 return (EFI_NOT_FOUND
);
128 StrnCpyS(*TempParameter
, Length
/ sizeof(CHAR16
), (*Walker
), NextDelim
- *Walker
);
131 // Add a CHAR_NULL if we didnt get one via the copy
133 if (*NextDelim
!= CHAR_NULL
) {
134 (*TempParameter
)[NextDelim
- *Walker
] = CHAR_NULL
;
138 // Update Walker for the next iteration through the function
140 *Walker
= (CHAR16
*)NextDelim
;
143 // Remove any non-escaped quotes in the string
144 // Remove any remaining escape characters in the string
146 for (NextDelim
= FindFirstCharacter(*TempParameter
, L
"\"^", CHAR_NULL
)
147 ; *NextDelim
!= CHAR_NULL
148 ; NextDelim
= FindFirstCharacter(NextDelim
, L
"\"^", CHAR_NULL
)
150 if (*NextDelim
== L
'^') {
153 // eliminate the escape ^
155 CopyMem ((CHAR16
*)NextDelim
, NextDelim
+ 1, StrSize (NextDelim
+ 1));
157 } else if (*NextDelim
== L
'\"') {
160 // eliminate the unescaped quote
162 CopyMem ((CHAR16
*)NextDelim
, NextDelim
+ 1, StrSize (NextDelim
+ 1));
170 Function to populate Argc and Argv.
172 This function parses the CommandLine and divides it into standard C style Argc/Argv
173 parameters for inclusion in EFI_SHELL_PARAMETERS_PROTOCOL. this supports space
174 delimited and quote surrounded parameter definition.
176 All special character processing (alias, environment variable, redirection,
177 etc... must be complete before calling this API.
179 @param[in] CommandLine String of command line to parse
180 @param[in, out] Argv pointer to array of strings; one for each parameter
181 @param[in, out] Argc pointer to number of strings in Argv array
183 @return EFI_SUCCESS the operation was sucessful
184 @return EFI_OUT_OF_RESOURCES a memory allocation failed.
188 ParseCommandLineToArgs(
189 IN CONST CHAR16
*CommandLine
,
190 IN OUT CHAR16
***Argv
,
195 CHAR16
*TempParameter
;
200 ASSERT(Argc
!= NULL
);
201 ASSERT(Argv
!= NULL
);
203 if (CommandLine
== NULL
|| StrLen(CommandLine
)==0) {
206 return (EFI_SUCCESS
);
209 TrimSpaces(&(CHAR16
*)CommandLine
);
210 Size
= StrSize(CommandLine
);
211 TempParameter
= AllocateZeroPool(Size
);
212 if (TempParameter
== NULL
) {
213 return (EFI_OUT_OF_RESOURCES
);
217 , Walker
= (CHAR16
*)CommandLine
218 ; Walker
!= NULL
&& *Walker
!= CHAR_NULL
221 if (EFI_ERROR(GetNextParameter(&Walker
, &TempParameter
, Size
))) {
227 // lets allocate the pointer array
229 (*Argv
) = AllocateZeroPool((Count
)*sizeof(CHAR16
*));
231 SHELL_FREE_NON_NULL(TempParameter
);
232 return (EFI_OUT_OF_RESOURCES
);
236 Walker
= (CHAR16
*)CommandLine
;
237 while(Walker
!= NULL
&& *Walker
!= CHAR_NULL
) {
238 SetMem16(TempParameter
, Size
, CHAR_NULL
);
239 if (EFI_ERROR(GetNextParameter(&Walker
, &TempParameter
, Size
))) {
240 SHELL_FREE_NON_NULL(TempParameter
);
241 return (EFI_INVALID_PARAMETER
);
244 NewParam
= AllocateCopyPool(StrSize(TempParameter
), TempParameter
);
245 if (NewParam
== NULL
){
246 SHELL_FREE_NON_NULL(TempParameter
);
247 return (EFI_OUT_OF_RESOURCES
);
249 ((CHAR16
**)(*Argv
))[(*Argc
)] = NewParam
;
252 ASSERT(Count
>= (*Argc
));
253 SHELL_FREE_NON_NULL(TempParameter
);
254 return (EFI_SUCCESS
);
258 creates a new EFI_SHELL_PARAMETERS_PROTOCOL instance and populates it and then
259 installs it on our handle and if there is an existing version of the protocol
260 that one is cached for removal later.
262 @param[in, out] NewShellParameters on a successful return, a pointer to pointer
263 to the newly installed interface.
264 @param[in, out] RootShellInstance on a successful return, pointer to boolean.
265 TRUE if this is the root shell instance.
267 @retval EFI_SUCCESS the operation completed successfully.
268 @return other the operation failed.
269 @sa ReinstallProtocolInterface
270 @sa InstallProtocolInterface
271 @sa ParseCommandLineToArgs
275 CreatePopulateInstallShellParametersProtocol (
276 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
**NewShellParameters
,
277 IN OUT BOOLEAN
*RootShellInstance
281 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
282 CHAR16
*FullCommandLine
;
286 FullCommandLine
= NULL
;
290 // Assert for valid parameters
292 ASSERT(NewShellParameters
!= NULL
);
293 ASSERT(RootShellInstance
!= NULL
);
296 // See if we have a shell parameters placed on us
298 Status
= gBS
->OpenProtocol (
300 &gEfiShellParametersProtocolGuid
,
301 (VOID
**) &ShellInfoObject
.OldShellParameters
,
304 EFI_OPEN_PROTOCOL_GET_PROTOCOL
307 // if we don't then we must be the root shell (error is expected)
309 if (EFI_ERROR (Status
)) {
310 *RootShellInstance
= TRUE
;
314 // Allocate the new structure
316 *NewShellParameters
= AllocateZeroPool(sizeof(EFI_SHELL_PARAMETERS_PROTOCOL
));
317 if ((*NewShellParameters
) == NULL
) {
318 return (EFI_OUT_OF_RESOURCES
);
322 // get loaded image protocol
324 Status
= gBS
->OpenProtocol (
326 &gEfiLoadedImageProtocolGuid
,
327 (VOID
**) &LoadedImage
,
330 EFI_OPEN_PROTOCOL_GET_PROTOCOL
332 ASSERT_EFI_ERROR(Status
);
334 // Build the full command line
336 Status
= SHELL_GET_ENVIRONMENT_VARIABLE(L
"ShellOpt", &Size
, FullCommandLine
);
337 if (Status
== EFI_BUFFER_TOO_SMALL
) {
338 FullCommandLine
= AllocateZeroPool(Size
+ LoadedImage
->LoadOptionsSize
);
339 Status
= SHELL_GET_ENVIRONMENT_VARIABLE(L
"ShellOpt", &Size
, FullCommandLine
);
341 if (Status
== EFI_NOT_FOUND
) {
343 // no parameters via environment... ok
346 if (EFI_ERROR(Status
)) {
350 if (Size
== 0 && LoadedImage
->LoadOptionsSize
!= 0) {
351 ASSERT(FullCommandLine
== NULL
);
353 // Now we need to include a NULL terminator in the size.
355 Size
= LoadedImage
->LoadOptionsSize
+ sizeof(FullCommandLine
[0]);
356 FullCommandLine
= AllocateZeroPool(Size
);
358 if (FullCommandLine
!= NULL
) {
359 CopyMem (FullCommandLine
, LoadedImage
->LoadOptions
, LoadedImage
->LoadOptionsSize
);
361 // Populate Argc and Argv
363 Status
= ParseCommandLineToArgs(FullCommandLine
,
364 &(*NewShellParameters
)->Argv
,
365 &(*NewShellParameters
)->Argc
);
367 FreePool(FullCommandLine
);
369 ASSERT_EFI_ERROR(Status
);
371 (*NewShellParameters
)->Argv
= NULL
;
372 (*NewShellParameters
)->Argc
= 0;
376 // Populate the 3 faked file systems...
378 if (*RootShellInstance
) {
379 (*NewShellParameters
)->StdIn
= &FileInterfaceStdIn
;
380 (*NewShellParameters
)->StdOut
= &FileInterfaceStdOut
;
381 (*NewShellParameters
)->StdErr
= &FileInterfaceStdErr
;
382 Status
= gBS
->InstallProtocolInterface(&gImageHandle
,
383 &gEfiShellParametersProtocolGuid
,
384 EFI_NATIVE_INTERFACE
,
385 (VOID
*)(*NewShellParameters
));
388 // copy from the existing ones
390 (*NewShellParameters
)->StdIn
= ShellInfoObject
.OldShellParameters
->StdIn
;
391 (*NewShellParameters
)->StdOut
= ShellInfoObject
.OldShellParameters
->StdOut
;
392 (*NewShellParameters
)->StdErr
= ShellInfoObject
.OldShellParameters
->StdErr
;
393 Status
= gBS
->ReinstallProtocolInterface(gImageHandle
,
394 &gEfiShellParametersProtocolGuid
,
395 (VOID
*)ShellInfoObject
.OldShellParameters
,
396 (VOID
*)(*NewShellParameters
));
403 frees all memory used by createion and installation of shell parameters protocol
404 and if there was an old version installed it will restore that one.
406 @param NewShellParameters the interface of EFI_SHELL_PARAMETERS_PROTOCOL that is
409 @retval EFI_SUCCESS the cleanup was successful
410 @return other the cleanup failed
411 @sa ReinstallProtocolInterface
412 @sa UninstallProtocolInterface
416 CleanUpShellParametersProtocol (
417 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
*NewShellParameters
424 // If the old exists we need to restore it
426 if (ShellInfoObject
.OldShellParameters
!= NULL
) {
427 Status
= gBS
->ReinstallProtocolInterface(gImageHandle
,
428 &gEfiShellParametersProtocolGuid
,
429 (VOID
*)NewShellParameters
,
430 (VOID
*)ShellInfoObject
.OldShellParameters
);
431 DEBUG_CODE(ShellInfoObject
.OldShellParameters
= NULL
;);
434 // No old one, just uninstall us...
436 Status
= gBS
->UninstallProtocolInterface(gImageHandle
,
437 &gEfiShellParametersProtocolGuid
,
438 (VOID
*)NewShellParameters
);
440 if (NewShellParameters
->Argv
!= NULL
) {
441 for ( LoopCounter
= 0
442 ; LoopCounter
< NewShellParameters
->Argc
445 FreePool(NewShellParameters
->Argv
[LoopCounter
]);
447 FreePool(NewShellParameters
->Argv
);
449 FreePool(NewShellParameters
);
454 Determin if a file name represents a unicode file.
456 @param[in] FileName Pointer to the filename to open.
458 @retval EFI_SUCCESS The file is a unicode file.
459 @return An error upon failure.
464 IN CONST CHAR16
*FileName
467 SHELL_FILE_HANDLE Handle
;
469 UINT64 OriginalFilePosition
;
473 Status
= gEfiShellProtocol
->OpenFileByName(FileName
, &Handle
, EFI_FILE_MODE_READ
);
474 if (EFI_ERROR(Status
)) {
477 gEfiShellProtocol
->GetFilePosition(Handle
, &OriginalFilePosition
);
478 gEfiShellProtocol
->SetFilePosition(Handle
, 0);
479 CharSize
= sizeof(CHAR16
);
480 Status
= gEfiShellProtocol
->ReadFile(Handle
, &CharSize
, &CharBuffer
);
481 if (EFI_ERROR(Status
) || CharBuffer
!= gUnicodeFileTag
) {
482 Status
= EFI_BUFFER_TOO_SMALL
;
484 gEfiShellProtocol
->SetFilePosition(Handle
, OriginalFilePosition
);
485 gEfiShellProtocol
->CloseFile(Handle
);
490 Strips out quotes sections of a string.
492 All of the characters between quotes is replaced with spaces.
494 @param[in, out] TheString A pointer to the string to update.
499 IN OUT CHAR16
*TheString
504 for (RemoveNow
= FALSE
; TheString
!= NULL
&& *TheString
!= CHAR_NULL
; TheString
++) {
505 if (*TheString
== L
'^' && *(TheString
+ 1) == L
'\"') {
507 } else if (*TheString
== L
'\"') {
508 RemoveNow
= (BOOLEAN
)!RemoveNow
;
509 } else if (RemoveNow
) {
516 Calcualte the 32-bit CRC in a EFI table using the service provided by the
519 @param Hdr Pointer to an EFI standard header
524 IN OUT EFI_TABLE_HEADER
*Hdr
532 // If gBS->CalculateCrce32 () == CoreEfiNotAvailableYet () then
533 // Crc will come back as zero if we set it to zero here
536 gBS
->CalculateCrc32 ((UINT8
*)Hdr
, Hdr
->HeaderSize
, &Crc
);
541 Fix a string to only have the file name, removing starting at the first space of whatever is quoted.
543 @param[in] FileName The filename to start with.
545 @retval NULL FileName was invalid.
546 @return The modified FileName.
555 CHAR16
*TempLocation
;
557 if (FileName
== NULL
) {
561 if (FileName
[0] == L
'\"') {
563 if ((TempLocation
= StrStr(Copy
, L
"\"")) != NULL
) {
564 TempLocation
[0] = CHAR_NULL
;
568 while(Copy
[0] == L
' ') {
571 if ((TempLocation
= StrStr(Copy
, L
" ")) != NULL
) {
572 TempLocation
[0] = CHAR_NULL
;
576 if (Copy
[0] == CHAR_NULL
) {
584 Fix a string to only have the environment variable name, removing starting at the first space of whatever is quoted and removing the leading and trailing %.
586 @param[in] FileName The filename to start with.
588 @retval NULL FileName was invalid.
589 @return The modified FileName.
598 CHAR16
*TempLocation
;
602 if (FileName
[0] == L
'%') {
604 if ((TempLocation
= StrStr(Copy
, L
"%")) != NULL
) {
605 TempLocation
[0] = CHAR_NULL
;
609 return (FixFileName(Copy
));
613 Remove the unicode file tag from the begining of the file buffer since that will not be
616 @param[in] Handle Pointer to the handle of the file to be processed.
618 @retval EFI_SUCCESS The unicode file tag has been moved successfully.
623 IN SHELL_FILE_HANDLE
*Handle
629 CharSize
= sizeof(CHAR16
);
631 gEfiShellProtocol
->ReadFile(*Handle
, &CharSize
, &CharBuffer
);
632 if (CharBuffer
!= gUnicodeFileTag
) {
633 gEfiShellProtocol
->SetFilePosition(*Handle
, 0);
635 return (EFI_SUCCESS
);
639 Write the unicode file tag to the specified file.
641 It is the caller's responsibility to ensure that
642 ShellInfoObject.NewEfiShellProtocol has been initialized before calling this
645 @param[in] FileHandle The file to write the unicode file tag to.
647 @return Status code from ShellInfoObject.NewEfiShellProtocol->WriteFile.
651 IN SHELL_FILE_HANDLE FileHandle
658 FileTag
= gUnicodeFileTag
;
659 Size
= sizeof FileTag
;
660 Status
= ShellInfoObject
.NewEfiShellProtocol
->WriteFile (FileHandle
, &Size
,
662 ASSERT (EFI_ERROR (Status
) || Size
== sizeof FileTag
);
668 Funcion will replace the current StdIn and StdOut in the ShellParameters protocol
669 structure by parsing NewCommandLine. The current values are returned to the
672 This will also update the system table.
674 @param[in, out] ShellParameters Pointer to parameter structure to modify.
675 @param[in] NewCommandLine The new command line to parse and use.
676 @param[out] OldStdIn Pointer to old StdIn.
677 @param[out] OldStdOut Pointer to old StdOut.
678 @param[out] OldStdErr Pointer to old StdErr.
679 @param[out] SystemTableInfo Pointer to old system table information.
681 @retval EFI_SUCCESS Operation was sucessful, Argv and Argc are valid.
682 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
686 UpdateStdInStdOutStdErr(
687 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
*ShellParameters
,
688 IN CHAR16
*NewCommandLine
,
689 OUT SHELL_FILE_HANDLE
*OldStdIn
,
690 OUT SHELL_FILE_HANDLE
*OldStdOut
,
691 OUT SHELL_FILE_HANDLE
*OldStdErr
,
692 OUT SYSTEM_TABLE_INFO
*SystemTableInfo
695 CHAR16
*CommandLineCopy
;
696 CHAR16
*CommandLineWalker
;
697 CHAR16
*StdErrFileName
;
698 CHAR16
*StdOutFileName
;
699 CHAR16
*StdInFileName
;
700 CHAR16
*StdInVarName
;
701 CHAR16
*StdOutVarName
;
702 CHAR16
*StdErrVarName
;
704 SHELL_FILE_HANDLE TempHandle
;
713 CHAR16
*FirstLocation
;
719 StdOutVarName
= NULL
;
720 StdErrVarName
= NULL
;
721 StdErrFileName
= NULL
;
722 StdInFileName
= NULL
;
723 StdOutFileName
= NULL
;
726 CommandLineCopy
= NULL
;
727 FirstLocation
= NULL
;
729 if (ShellParameters
== NULL
|| SystemTableInfo
== NULL
|| OldStdIn
== NULL
|| OldStdOut
== NULL
|| OldStdErr
== NULL
) {
730 return (EFI_INVALID_PARAMETER
);
733 SystemTableInfo
->ConIn
= gST
->ConIn
;
734 SystemTableInfo
->ConInHandle
= gST
->ConsoleInHandle
;
735 SystemTableInfo
->ConOut
= gST
->ConOut
;
736 SystemTableInfo
->ConOutHandle
= gST
->ConsoleOutHandle
;
737 SystemTableInfo
->ErrOut
= gST
->StdErr
;
738 SystemTableInfo
->ErrOutHandle
= gST
->StandardErrorHandle
;
739 *OldStdIn
= ShellParameters
->StdIn
;
740 *OldStdOut
= ShellParameters
->StdOut
;
741 *OldStdErr
= ShellParameters
->StdErr
;
743 if (NewCommandLine
== NULL
) {
744 return (EFI_SUCCESS
);
747 CommandLineCopy
= StrnCatGrow(&CommandLineCopy
, NULL
, NewCommandLine
, 0);
748 if (CommandLineCopy
== NULL
) {
749 return (EFI_OUT_OF_RESOURCES
);
751 Status
= EFI_SUCCESS
;
753 FirstLocation
= CommandLineCopy
+ StrLen(CommandLineCopy
);
755 StripQuotes(CommandLineCopy
);
757 if (!IsListEmpty(&ShellInfoObject
.SplitList
.Link
)) {
758 Split
= (SPLIT_LIST
*)GetFirstNode(&ShellInfoObject
.SplitList
.Link
);
759 if (Split
!= NULL
&& Split
->SplitStdIn
!= NULL
) {
760 ShellParameters
->StdIn
= Split
->SplitStdIn
;
762 if (Split
!= NULL
&& Split
->SplitStdOut
!= NULL
) {
763 ShellParameters
->StdOut
= Split
->SplitStdOut
;
767 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 2>>v ")) != NULL
) {
768 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
769 SetMem16(CommandLineWalker
, 12, L
' ');
770 StdErrVarName
= CommandLineWalker
+= 6;
772 if (StrStr(CommandLineWalker
, L
" 2>>v ") != NULL
) {
773 Status
= EFI_NOT_FOUND
;
776 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1>>v ")) != NULL
) {
777 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
778 SetMem16(CommandLineWalker
, 12, L
' ');
779 StdOutVarName
= CommandLineWalker
+= 6;
781 if (StrStr(CommandLineWalker
, L
" 1>>v ") != NULL
) {
782 Status
= EFI_NOT_FOUND
;
784 } else if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" >>v ")) != NULL
) {
785 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
786 SetMem16(CommandLineWalker
, 10, L
' ');
787 StdOutVarName
= CommandLineWalker
+= 5;
789 if (StrStr(CommandLineWalker
, L
" >>v ") != NULL
) {
790 Status
= EFI_NOT_FOUND
;
792 } else if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" >v ")) != NULL
) {
793 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
794 SetMem16(CommandLineWalker
, 8, L
' ');
795 StdOutVarName
= CommandLineWalker
+= 4;
797 if (StrStr(CommandLineWalker
, L
" >v ") != NULL
) {
798 Status
= EFI_NOT_FOUND
;
801 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1>>a ")) != NULL
) {
802 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
803 SetMem16(CommandLineWalker
, 12, L
' ');
804 StdOutFileName
= CommandLineWalker
+= 6;
807 if (StrStr(CommandLineWalker
, L
" 1>>a ") != NULL
) {
808 Status
= EFI_NOT_FOUND
;
811 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1>> ")) != NULL
) {
812 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
813 SetMem16(CommandLineWalker
, 10, L
' ');
814 if (StdOutFileName
!= NULL
) {
815 Status
= EFI_INVALID_PARAMETER
;
817 StdOutFileName
= CommandLineWalker
+= 5;
820 if (StrStr(CommandLineWalker
, L
" 1>> ") != NULL
) {
821 Status
= EFI_NOT_FOUND
;
824 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" >> ")) != NULL
) {
825 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
826 SetMem16(CommandLineWalker
, 8, L
' ');
827 if (StdOutFileName
!= NULL
) {
828 Status
= EFI_INVALID_PARAMETER
;
830 StdOutFileName
= CommandLineWalker
+= 4;
833 if (StrStr(CommandLineWalker
, L
" >> ") != NULL
) {
834 Status
= EFI_NOT_FOUND
;
837 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" >>a ")) != NULL
) {
838 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
839 SetMem16(CommandLineWalker
, 10, L
' ');
840 if (StdOutFileName
!= NULL
) {
841 Status
= EFI_INVALID_PARAMETER
;
843 StdOutFileName
= CommandLineWalker
+= 5;
847 if (StrStr(CommandLineWalker
, L
" >>a ") != NULL
) {
848 Status
= EFI_NOT_FOUND
;
851 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1>a ")) != NULL
) {
852 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
853 SetMem16(CommandLineWalker
, 10, L
' ');
854 if (StdOutFileName
!= NULL
) {
855 Status
= EFI_INVALID_PARAMETER
;
857 StdOutFileName
= CommandLineWalker
+= 5;
861 if (StrStr(CommandLineWalker
, L
" 1>a ") != NULL
) {
862 Status
= EFI_NOT_FOUND
;
865 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" >a ")) != NULL
) {
866 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
867 SetMem16(CommandLineWalker
, 8, L
' ');
868 if (StdOutFileName
!= NULL
) {
869 Status
= EFI_INVALID_PARAMETER
;
871 StdOutFileName
= CommandLineWalker
+= 4;
875 if (StrStr(CommandLineWalker
, L
" >a ") != NULL
) {
876 Status
= EFI_NOT_FOUND
;
879 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 2>> ")) != NULL
) {
880 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
881 SetMem16(CommandLineWalker
, 10, L
' ');
882 if (StdErrFileName
!= NULL
) {
883 Status
= EFI_INVALID_PARAMETER
;
885 StdErrFileName
= CommandLineWalker
+= 5;
888 if (StrStr(CommandLineWalker
, L
" 2>> ") != NULL
) {
889 Status
= EFI_NOT_FOUND
;
893 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 2>v ")) != NULL
) {
894 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
895 SetMem16(CommandLineWalker
, 10, L
' ');
896 if (StdErrVarName
!= NULL
) {
897 Status
= EFI_INVALID_PARAMETER
;
899 StdErrVarName
= CommandLineWalker
+= 5;
902 if (StrStr(CommandLineWalker
, L
" 2>v ") != NULL
) {
903 Status
= EFI_NOT_FOUND
;
906 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1>v ")) != NULL
) {
907 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
908 SetMem16(CommandLineWalker
, 10, L
' ');
909 if (StdOutVarName
!= NULL
) {
910 Status
= EFI_INVALID_PARAMETER
;
912 StdOutVarName
= CommandLineWalker
+= 5;
915 if (StrStr(CommandLineWalker
, L
" 1>v ") != NULL
) {
916 Status
= EFI_NOT_FOUND
;
919 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 2>a ")) != NULL
) {
920 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
921 SetMem16(CommandLineWalker
, 10, L
' ');
922 if (StdErrFileName
!= NULL
) {
923 Status
= EFI_INVALID_PARAMETER
;
925 StdErrFileName
= CommandLineWalker
+= 5;
929 if (StrStr(CommandLineWalker
, L
" 2>a ") != NULL
) {
930 Status
= EFI_NOT_FOUND
;
933 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 2> ")) != NULL
) {
934 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
935 SetMem16(CommandLineWalker
, 8, L
' ');
936 if (StdErrFileName
!= NULL
) {
937 Status
= EFI_INVALID_PARAMETER
;
939 StdErrFileName
= CommandLineWalker
+= 4;
942 if (StrStr(CommandLineWalker
, L
" 2> ") != NULL
) {
943 Status
= EFI_NOT_FOUND
;
947 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1> ")) != NULL
) {
948 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
949 SetMem16(CommandLineWalker
, 8, L
' ');
950 if (StdOutFileName
!= NULL
) {
951 Status
= EFI_INVALID_PARAMETER
;
953 StdOutFileName
= CommandLineWalker
+= 4;
956 if (StrStr(CommandLineWalker
, L
" 1> ") != NULL
) {
957 Status
= EFI_NOT_FOUND
;
961 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" > ")) != NULL
) {
962 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
963 SetMem16(CommandLineWalker
, 6, L
' ');
964 if (StdOutFileName
!= NULL
) {
965 Status
= EFI_INVALID_PARAMETER
;
967 StdOutFileName
= CommandLineWalker
+= 3;
970 if (StrStr(CommandLineWalker
, L
" > ") != NULL
) {
971 Status
= EFI_NOT_FOUND
;
975 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" < ")) != NULL
) {
976 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
977 SetMem16(CommandLineWalker
, 6, L
' ');
978 if (StdInFileName
!= NULL
) {
979 Status
= EFI_INVALID_PARAMETER
;
981 StdInFileName
= CommandLineWalker
+= 3;
983 if (StrStr(CommandLineWalker
, L
" < ") != NULL
) {
984 Status
= EFI_NOT_FOUND
;
987 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" <a ")) != NULL
) {
988 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
989 SetMem16(CommandLineWalker
, 8, L
' ');
990 if (StdInFileName
!= NULL
) {
991 Status
= EFI_INVALID_PARAMETER
;
993 StdInFileName
= CommandLineWalker
+= 4;
996 if (StrStr(CommandLineWalker
, L
" <a ") != NULL
) {
997 Status
= EFI_NOT_FOUND
;
1000 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" <v ")) != NULL
) {
1001 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
1002 SetMem16(CommandLineWalker
, 8, L
' ');
1003 if (StdInVarName
!= NULL
) {
1004 Status
= EFI_INVALID_PARAMETER
;
1006 StdInVarName
= CommandLineWalker
+= 4;
1008 if (StrStr(CommandLineWalker
, L
" <v ") != NULL
) {
1009 Status
= EFI_NOT_FOUND
;
1014 // re-populate the string to support any filenames that were in quotes.
1016 StrnCpyS(CommandLineCopy
, StrSize(CommandLineCopy
)/sizeof(CHAR16
), NewCommandLine
, StrLen(NewCommandLine
));
1018 if (FirstLocation
!= CommandLineCopy
+ StrLen(CommandLineCopy
)
1019 && ((UINTN
)(FirstLocation
- CommandLineCopy
) < StrLen(NewCommandLine
))
1021 *(NewCommandLine
+ (UINTN
)(FirstLocation
- CommandLineCopy
)) = CHAR_NULL
;
1024 if (!EFI_ERROR(Status
)) {
1026 if (StdErrFileName
!= NULL
) {
1027 if ((StdErrFileName
= FixFileName(StdErrFileName
)) == NULL
) {
1028 Status
= EFI_INVALID_PARAMETER
;
1031 if (StdOutFileName
!= NULL
) {
1032 if ((StdOutFileName
= FixFileName(StdOutFileName
)) == NULL
) {
1033 Status
= EFI_INVALID_PARAMETER
;
1036 if (StdInFileName
!= NULL
) {
1037 if ((StdInFileName
= FixFileName(StdInFileName
)) == NULL
) {
1038 Status
= EFI_INVALID_PARAMETER
;
1041 if (StdErrVarName
!= NULL
) {
1042 if ((StdErrVarName
= FixVarName(StdErrVarName
)) == NULL
) {
1043 Status
= EFI_INVALID_PARAMETER
;
1046 if (StdOutVarName
!= NULL
) {
1047 if ((StdOutVarName
= FixVarName(StdOutVarName
)) == NULL
) {
1048 Status
= EFI_INVALID_PARAMETER
;
1051 if (StdInVarName
!= NULL
) {
1052 if ((StdInVarName
= FixVarName(StdInVarName
)) == NULL
) {
1053 Status
= EFI_INVALID_PARAMETER
;
1058 // Verify not the same and not duplicating something from a split
1062 // Check that no 2 filenames are the same
1064 (StdErrFileName
!= NULL
&& StdOutFileName
!= NULL
&& StringNoCaseCompare(&StdErrFileName
, &StdOutFileName
) == 0)
1065 ||(StdErrFileName
!= NULL
&& StdInFileName
!= NULL
&& StringNoCaseCompare(&StdErrFileName
, &StdInFileName
) == 0)
1066 ||(StdOutFileName
!= NULL
&& StdInFileName
!= NULL
&& StringNoCaseCompare(&StdOutFileName
, &StdInFileName
) == 0)
1068 // Check that no 2 variable names are the same
1070 ||(StdErrVarName
!= NULL
&& StdInVarName
!= NULL
&& StringNoCaseCompare(&StdErrVarName
, &StdInVarName
) == 0)
1071 ||(StdOutVarName
!= NULL
&& StdInVarName
!= NULL
&& StringNoCaseCompare(&StdOutVarName
, &StdInVarName
) == 0)
1072 ||(StdErrVarName
!= NULL
&& StdOutVarName
!= NULL
&& StringNoCaseCompare(&StdErrVarName
, &StdOutVarName
) == 0)
1074 // When a split (using | operator) is in place some are not allowed
1076 ||(Split
!= NULL
&& Split
->SplitStdIn
!= NULL
&& (StdInVarName
!= NULL
|| StdInFileName
!= NULL
))
1077 ||(Split
!= NULL
&& Split
->SplitStdOut
!= NULL
&& (StdOutVarName
!= NULL
|| StdOutFileName
!= NULL
))
1079 // Check that nothing is trying to be output to 2 locations.
1081 ||(StdErrFileName
!= NULL
&& StdErrVarName
!= NULL
)
1082 ||(StdOutFileName
!= NULL
&& StdOutVarName
!= NULL
)
1083 ||(StdInFileName
!= NULL
&& StdInVarName
!= NULL
)
1085 // Check for no volatile environment variables
1087 ||(StdErrVarName
!= NULL
&& !IsVolatileEnv(StdErrVarName
))
1088 ||(StdOutVarName
!= NULL
&& !IsVolatileEnv(StdOutVarName
))
1090 // Cant redirect during a reconnect operation.
1092 ||(StrStr(NewCommandLine
, L
"connect -r") != NULL
1093 && (StdOutVarName
!= NULL
|| StdOutFileName
!= NULL
|| StdErrFileName
!= NULL
|| StdErrVarName
!= NULL
))
1095 // Check that filetypes (Unicode/Ascii) do not change during an append
1097 ||(StdOutFileName
!= NULL
&& OutUnicode
&& OutAppend
&& (!EFI_ERROR(ShellFileExists(StdOutFileName
)) && EFI_ERROR(IsUnicodeFile(StdOutFileName
))))
1098 ||(StdErrFileName
!= NULL
&& ErrUnicode
&& ErrAppend
&& (!EFI_ERROR(ShellFileExists(StdErrFileName
)) && EFI_ERROR(IsUnicodeFile(StdErrFileName
))))
1099 ||(StdOutFileName
!= NULL
&& !OutUnicode
&& OutAppend
&& (!EFI_ERROR(ShellFileExists(StdOutFileName
)) && !EFI_ERROR(IsUnicodeFile(StdOutFileName
))))
1100 ||(StdErrFileName
!= NULL
&& !ErrUnicode
&& ErrAppend
&& (!EFI_ERROR(ShellFileExists(StdErrFileName
)) && !EFI_ERROR(IsUnicodeFile(StdErrFileName
))))
1102 Status
= EFI_INVALID_PARAMETER
;
1103 ShellParameters
->StdIn
= *OldStdIn
;
1104 ShellParameters
->StdOut
= *OldStdOut
;
1105 ShellParameters
->StdErr
= *OldStdErr
;
1106 } else if (!EFI_ERROR(Status
)){
1108 // Open the Std<Whatever> and we should not have conflicts here...
1114 if (StdErrFileName
!= NULL
) {
1117 // delete existing file.
1119 ShellInfoObject
.NewEfiShellProtocol
->DeleteFileByName(StdErrFileName
);
1121 Status
= ShellOpenFileByName(StdErrFileName
, &TempHandle
, EFI_FILE_MODE_WRITE
|EFI_FILE_MODE_READ
|EFI_FILE_MODE_CREATE
,0);
1122 if (!ErrAppend
&& ErrUnicode
&& !EFI_ERROR(Status
)) {
1123 Status
= WriteFileTag (TempHandle
);
1125 if (!ErrUnicode
&& !EFI_ERROR(Status
)) {
1126 TempHandle
= CreateFileInterfaceFile(TempHandle
, FALSE
);
1127 ASSERT(TempHandle
!= NULL
);
1129 if (!EFI_ERROR(Status
)) {
1130 ShellParameters
->StdErr
= TempHandle
;
1131 gST
->StdErr
= CreateSimpleTextOutOnFile(TempHandle
, &gST
->StandardErrorHandle
, gST
->StdErr
);
1138 if (!EFI_ERROR(Status
) && StdOutFileName
!= NULL
) {
1141 // delete existing file.
1143 ShellInfoObject
.NewEfiShellProtocol
->DeleteFileByName(StdOutFileName
);
1145 Status
= ShellOpenFileByName(StdOutFileName
, &TempHandle
, EFI_FILE_MODE_WRITE
|EFI_FILE_MODE_READ
|EFI_FILE_MODE_CREATE
,0);
1146 if (TempHandle
== NULL
) {
1147 Status
= EFI_INVALID_PARAMETER
;
1149 if (StrStr(StdOutFileName
, L
"NUL")==StdOutFileName
) {
1151 } else if (!OutAppend
&& OutUnicode
&& !EFI_ERROR(Status
)) {
1152 Status
= WriteFileTag (TempHandle
);
1153 } else if (OutAppend
) {
1154 Status
= ShellInfoObject
.NewEfiShellProtocol
->GetFileSize(TempHandle
, &FileSize
);
1155 if (!EFI_ERROR(Status
)) {
1157 // When appending to a new unicode file, write the file tag.
1158 // Otherwise (ie. when appending to a new ASCII file, or an
1159 // existent file with any encoding), just seek to the end.
1161 Status
= (FileSize
== 0 && OutUnicode
) ?
1162 WriteFileTag (TempHandle
) :
1163 ShellInfoObject
.NewEfiShellProtocol
->SetFilePosition (
1168 if (!OutUnicode
&& !EFI_ERROR(Status
)) {
1169 TempHandle
= CreateFileInterfaceFile(TempHandle
, FALSE
);
1170 ASSERT(TempHandle
!= NULL
);
1172 if (!EFI_ERROR(Status
)) {
1173 ShellParameters
->StdOut
= TempHandle
;
1174 gST
->ConOut
= CreateSimpleTextOutOnFile(TempHandle
, &gST
->ConsoleOutHandle
, gST
->ConOut
);
1182 if (!EFI_ERROR(Status
) && StdOutVarName
!= NULL
) {
1185 // delete existing variable.
1187 SHELL_SET_ENVIRONMENT_VARIABLE_V(StdOutVarName
, 0, L
"");
1189 TempHandle
= CreateFileInterfaceEnv(StdOutVarName
);
1190 ASSERT(TempHandle
!= NULL
);
1191 ShellParameters
->StdOut
= TempHandle
;
1192 gST
->ConOut
= CreateSimpleTextOutOnFile(TempHandle
, &gST
->ConsoleOutHandle
, gST
->ConOut
);
1198 if (!EFI_ERROR(Status
) && StdErrVarName
!= NULL
) {
1201 // delete existing variable.
1203 SHELL_SET_ENVIRONMENT_VARIABLE_V(StdErrVarName
, 0, L
"");
1205 TempHandle
= CreateFileInterfaceEnv(StdErrVarName
);
1206 ASSERT(TempHandle
!= NULL
);
1207 ShellParameters
->StdErr
= TempHandle
;
1208 gST
->StdErr
= CreateSimpleTextOutOnFile(TempHandle
, &gST
->StandardErrorHandle
, gST
->StdErr
);
1214 if (!EFI_ERROR(Status
) && StdInVarName
!= NULL
) {
1215 TempHandle
= CreateFileInterfaceEnv(StdInVarName
);
1216 if (TempHandle
== NULL
) {
1217 Status
= EFI_OUT_OF_RESOURCES
;
1220 TempHandle
= CreateFileInterfaceFile(TempHandle
, FALSE
);
1223 if (TempHandle
== NULL
|| ((EFI_FILE_PROTOCOL
*)TempHandle
)->Read(TempHandle
, &Size
, NULL
) != EFI_BUFFER_TOO_SMALL
) {
1224 Status
= EFI_INVALID_PARAMETER
;
1226 ShellParameters
->StdIn
= TempHandle
;
1227 gST
->ConIn
= CreateSimpleTextInOnFile(TempHandle
, &gST
->ConsoleInHandle
);
1233 // StdIn from a file
1235 if (!EFI_ERROR(Status
) && StdInFileName
!= NULL
) {
1236 Status
= ShellOpenFileByName(
1243 // Chop off the 0xFEFF if it's there...
1245 RemoveFileTag(&TempHandle
);
1246 } else if (!EFI_ERROR(Status
)) {
1248 // Create the ASCII->Unicode conversion layer
1250 TempHandle
= CreateFileInterfaceFile(TempHandle
, FALSE
);
1252 if (!EFI_ERROR(Status
)) {
1253 ShellParameters
->StdIn
= TempHandle
;
1254 gST
->ConIn
= CreateSimpleTextInOnFile(TempHandle
, &gST
->ConsoleInHandle
);
1259 FreePool(CommandLineCopy
);
1261 CalculateEfiHdrCrc(&gST
->Hdr
);
1263 if (gST
->ConIn
== NULL
||gST
->ConOut
== NULL
) {
1264 Status
= EFI_OUT_OF_RESOURCES
;
1267 if (Status
== EFI_NOT_FOUND
) {
1268 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SHELL_REDUNDA_REDIR
), ShellInfoObject
.HiiHandle
);
1269 } else if (EFI_ERROR(Status
)) {
1270 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SHELL_INVALID_REDIR
), ShellInfoObject
.HiiHandle
);
1277 Funcion will replace the current StdIn and StdOut in the ShellParameters protocol
1278 structure with StdIn and StdOut. The current values are de-allocated.
1280 @param[in, out] ShellParameters Pointer to parameter structure to modify.
1281 @param[in] OldStdIn Pointer to old StdIn.
1282 @param[in] OldStdOut Pointer to old StdOut.
1283 @param[in] OldStdErr Pointer to old StdErr.
1284 @param[in] SystemTableInfo Pointer to old system table information.
1288 RestoreStdInStdOutStdErr (
1289 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
*ShellParameters
,
1290 IN SHELL_FILE_HANDLE
*OldStdIn
,
1291 IN SHELL_FILE_HANDLE
*OldStdOut
,
1292 IN SHELL_FILE_HANDLE
*OldStdErr
,
1293 IN SYSTEM_TABLE_INFO
*SystemTableInfo
1298 if (ShellParameters
== NULL
1302 ||SystemTableInfo
== NULL
) {
1303 return (EFI_INVALID_PARAMETER
);
1305 if (!IsListEmpty(&ShellInfoObject
.SplitList
.Link
)) {
1306 Split
= (SPLIT_LIST
*)GetFirstNode(&ShellInfoObject
.SplitList
.Link
);
1310 if (ShellParameters
->StdIn
!= *OldStdIn
) {
1311 if ((Split
!= NULL
&& Split
->SplitStdIn
!= ShellParameters
->StdIn
) || Split
== NULL
) {
1312 gEfiShellProtocol
->CloseFile(ShellParameters
->StdIn
);
1314 ShellParameters
->StdIn
= *OldStdIn
;
1316 if (ShellParameters
->StdOut
!= *OldStdOut
) {
1317 if ((Split
!= NULL
&& Split
->SplitStdOut
!= ShellParameters
->StdOut
) || Split
== NULL
) {
1318 gEfiShellProtocol
->CloseFile(ShellParameters
->StdOut
);
1320 ShellParameters
->StdOut
= *OldStdOut
;
1322 if (ShellParameters
->StdErr
!= *OldStdErr
) {
1323 gEfiShellProtocol
->CloseFile(ShellParameters
->StdErr
);
1324 ShellParameters
->StdErr
= *OldStdErr
;
1327 if (gST
->ConIn
!= SystemTableInfo
->ConIn
) {
1328 CloseSimpleTextInOnFile(gST
->ConIn
);
1329 gST
->ConIn
= SystemTableInfo
->ConIn
;
1330 gST
->ConsoleInHandle
= SystemTableInfo
->ConInHandle
;
1332 if (gST
->ConOut
!= SystemTableInfo
->ConOut
) {
1333 CloseSimpleTextOutOnFile(gST
->ConOut
);
1334 gST
->ConOut
= SystemTableInfo
->ConOut
;
1335 gST
->ConsoleOutHandle
= SystemTableInfo
->ConOutHandle
;
1337 if (gST
->StdErr
!= SystemTableInfo
->ErrOut
) {
1338 CloseSimpleTextOutOnFile(gST
->StdErr
);
1339 gST
->StdErr
= SystemTableInfo
->ErrOut
;
1340 gST
->StandardErrorHandle
= SystemTableInfo
->ErrOutHandle
;
1343 CalculateEfiHdrCrc(&gST
->Hdr
);
1345 return (EFI_SUCCESS
);
1348 Funcion will replace the current Argc and Argv in the ShellParameters protocol
1349 structure by parsing NewCommandLine. The current values are returned to the
1352 If OldArgv or OldArgc is NULL then that value is not returned.
1354 @param[in, out] ShellParameters Pointer to parameter structure to modify.
1355 @param[in] NewCommandLine The new command line to parse and use.
1356 @param[out] OldArgv Pointer to old list of parameters.
1357 @param[out] OldArgc Pointer to old number of items in Argv list.
1359 @retval EFI_SUCCESS Operation was sucessful, Argv and Argc are valid.
1360 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
1365 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
*ShellParameters
,
1366 IN CONST CHAR16
*NewCommandLine
,
1367 OUT CHAR16
***OldArgv OPTIONAL
,
1368 OUT UINTN
*OldArgc OPTIONAL
1371 ASSERT(ShellParameters
!= NULL
);
1373 if (OldArgc
!= NULL
) {
1374 *OldArgc
= ShellParameters
->Argc
;
1376 if (OldArgc
!= NULL
) {
1377 *OldArgv
= ShellParameters
->Argv
;
1380 return (ParseCommandLineToArgs(NewCommandLine
, &(ShellParameters
->Argv
), &(ShellParameters
->Argc
)));
1384 Funcion will replace the current Argc and Argv in the ShellParameters protocol
1385 structure with Argv and Argc. The current values are de-allocated and the
1386 OldArgv must not be deallocated by the caller.
1388 @param[in, out] ShellParameters pointer to parameter structure to modify
1389 @param[in] OldArgv pointer to old list of parameters
1390 @param[in] OldArgc pointer to old number of items in Argv list
1395 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
*ShellParameters
,
1396 IN CHAR16
***OldArgv
,
1401 ASSERT(ShellParameters
!= NULL
);
1402 ASSERT(OldArgv
!= NULL
);
1403 ASSERT(OldArgc
!= NULL
);
1405 if (ShellParameters
->Argv
!= NULL
) {
1406 for ( LoopCounter
= 0
1407 ; LoopCounter
< ShellParameters
->Argc
1410 FreePool(ShellParameters
->Argv
[LoopCounter
]);
1412 FreePool(ShellParameters
->Argv
);
1414 ShellParameters
->Argv
= *OldArgv
;
1416 ShellParameters
->Argc
= *OldArgc
;