ShellParametersProtocol.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /** @file
  2. Member functions of EFI_SHELL_PARAMETERS_PROTOCOL and functions for creation,
  3. manipulation, and initialization of EFI_SHELL_PARAMETERS_PROTOCOL.
  4. Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #ifndef _SHELL_PARAMETERS_PROTOCOL_PROVIDER_HEADER_
  8. #define _SHELL_PARAMETERS_PROTOCOL_PROVIDER_HEADER_
  9. #include "Shell.h"
  10. typedef enum {
  11. Internal_Command,
  12. Script_File_Name,
  13. Efi_Application,
  14. File_Sys_Change,
  15. Unknown_Invalid
  16. } SHELL_OPERATION_TYPES;
  17. /**
  18. creates a new EFI_SHELL_PARAMETERS_PROTOCOL instance and populates it and then
  19. installs it on our handle and if there is an existing version of the protocol
  20. that one is cached for removal later.
  21. @param[in, out] NewShellParameters on a successful return, a pointer to pointer
  22. to the newly installed interface.
  23. @param[in, out] RootShellInstance on a successful return, pointer to boolean.
  24. TRUE if this is the root shell instance.
  25. @retval EFI_SUCCESS the operation completed successfully.
  26. @return other the operation failed.
  27. @sa ReinstallProtocolInterface
  28. @sa InstallProtocolInterface
  29. @sa ParseCommandLineToArgs
  30. **/
  31. EFI_STATUS
  32. CreatePopulateInstallShellParametersProtocol (
  33. IN OUT EFI_SHELL_PARAMETERS_PROTOCOL **NewShellParameters,
  34. IN OUT BOOLEAN *RootShellInstance
  35. );
  36. /**
  37. frees all memory used by creation and installation of shell parameters protocol
  38. and if there was an old version installed it will restore that one.
  39. @param NewShellParameters the interface of EFI_SHELL_PARAMETERS_PROTOCOL that is
  40. being cleaned up.
  41. @retval EFI_SUCCESS the cleanup was successful
  42. @return other the cleanup failed
  43. @sa ReinstallProtocolInterface
  44. @sa UninstallProtocolInterface
  45. **/
  46. EFI_STATUS
  47. CleanUpShellParametersProtocol (
  48. IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *NewShellParameters
  49. );
  50. /**
  51. Function will replace the current Argc and Argv in the ShellParameters protocol
  52. structure by parsing NewCommandLine. The current values are returned to the
  53. user.
  54. @param[in, out] ShellParameters pointer to parameter structure to modify
  55. @param[in] NewCommandLine the new command line to parse and use
  56. @param[in] Type the type of operation.
  57. @param[out] OldArgv pointer to old list of parameters
  58. @param[out] OldArgc pointer to old number of items in Argv list
  59. @retval EFI_SUCCESS operation was successful, Argv and Argc are valid
  60. @return EFI_INVALID_PARAMETER some parameters are invalid
  61. @retval EFI_OUT_OF_RESOURCES a memory allocation failed.
  62. **/
  63. EFI_STATUS
  64. UpdateArgcArgv (
  65. IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,
  66. IN CONST CHAR16 *NewCommandLine,
  67. IN SHELL_OPERATION_TYPES Type,
  68. OUT CHAR16 ***OldArgv,
  69. OUT UINTN *OldArgc
  70. );
  71. /**
  72. Function will replace the current Argc and Argv in the ShellParameters protocol
  73. structure with Argv and Argc. The current values are de-allocated and the
  74. OldArgv must not be deallocated by the caller.
  75. @param[in, out] ShellParameters pointer to parameter structure to modify
  76. @param[in] OldArgv pointer to old list of parameters
  77. @param[in] OldArgc pointer to old number of items in Argv list
  78. **/
  79. VOID
  80. RestoreArgcArgv (
  81. IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,
  82. IN CHAR16 ***OldArgv,
  83. IN UINTN *OldArgc
  84. );
  85. typedef struct {
  86. EFI_SIMPLE_TEXT_INPUT_PROTOCOL *ConIn;
  87. EFI_HANDLE ConInHandle;
  88. EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut;
  89. EFI_HANDLE ConOutHandle;
  90. EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ErrOut;
  91. EFI_HANDLE ErrOutHandle;
  92. } SYSTEM_TABLE_INFO;
  93. /**
  94. Function will replace the current StdIn and StdOut in the ShellParameters protocol
  95. structure by parsing NewCommandLine. The current values are returned to the
  96. user.
  97. This will also update the system table.
  98. @param[in, out] ShellParameters Pointer to parameter structure to modify.
  99. @param[in] NewCommandLine The new command line to parse and use.
  100. @param[out] OldStdIn Pointer to old StdIn.
  101. @param[out] OldStdOut Pointer to old StdOut.
  102. @param[out] OldStdErr Pointer to old StdErr.
  103. @param[out] SystemTableInfo Pointer to old system table information.
  104. @retval EFI_SUCCESS Operation was successful, Argv and Argc are valid.
  105. @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
  106. **/
  107. EFI_STATUS
  108. UpdateStdInStdOutStdErr (
  109. IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,
  110. IN CHAR16 *NewCommandLine,
  111. OUT SHELL_FILE_HANDLE *OldStdIn,
  112. OUT SHELL_FILE_HANDLE *OldStdOut,
  113. OUT SHELL_FILE_HANDLE *OldStdErr,
  114. OUT SYSTEM_TABLE_INFO *SystemTableInfo
  115. );
  116. /**
  117. Function will replace the current StdIn and StdOut in the ShellParameters protocol
  118. structure with StdIn and StdOut. The current values are de-allocated.
  119. @param[in, out] ShellParameters Pointer to parameter structure to modify.
  120. @param[in] OldStdIn Pointer to old StdIn.
  121. @param[in] OldStdOut Pointer to old StdOut.
  122. @param[in] OldStdErr Pointer to old StdErr.
  123. @param[in] SystemTableInfo Pointer to old system table information.
  124. **/
  125. EFI_STATUS
  126. RestoreStdInStdOutStdErr (
  127. IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,
  128. IN SHELL_FILE_HANDLE *OldStdIn,
  129. IN SHELL_FILE_HANDLE *OldStdOut,
  130. IN SHELL_FILE_HANDLE *OldStdErr,
  131. IN SYSTEM_TABLE_INFO *SystemTableInfo
  132. );
  133. /**
  134. function to populate Argc and Argv.
  135. This function parses the CommandLine and divides it into standard C style Argc/Argv
  136. parameters for inclusion in EFI_SHELL_PARAMETERS_PROTOCOL. this supports space
  137. delimited and quote surrounded parameter definition.
  138. @param[in] CommandLine String of command line to parse
  139. @param[in] StripQuotation if TRUE then strip the quotation marks surrounding
  140. the parameters.
  141. @param[in, out] Argv pointer to array of strings; one for each parameter
  142. @param[in, out] Argc pointer to number of strings in Argv array
  143. @return EFI_SUCCESS the operation was successful
  144. @return EFI_INVALID_PARAMETER some parameters are invalid
  145. @return EFI_OUT_OF_RESOURCES a memory allocation failed.
  146. **/
  147. EFI_STATUS
  148. ParseCommandLineToArgs (
  149. IN CONST CHAR16 *CommandLine,
  150. IN BOOLEAN StripQuotation,
  151. IN OUT CHAR16 ***Argv,
  152. IN OUT UINTN *Argc
  153. );
  154. /**
  155. return the next parameter from a command line string;
  156. This function moves the next parameter from Walker into TempParameter and moves
  157. Walker up past that parameter for recursive calling. When the final parameter
  158. is moved *Walker will be set to NULL;
  159. Temp Parameter must be large enough to hold the parameter before calling this
  160. function.
  161. @param[in, out] Walker pointer to string of command line. Adjusted to
  162. remaining command line on return
  163. @param[in, out] TempParameter pointer to string of command line item extracted.
  164. @param[in] Length Length of (*TempParameter) in bytes
  165. @param[in] StripQuotation if TRUE then strip the quotation marks surrounding
  166. the parameters.
  167. @return EFI_INVALID_PARAMETER A required parameter was NULL or pointed to a NULL or empty string.
  168. @return EFI_NOT_FOUND A closing " could not be found on the specified string
  169. **/
  170. EFI_STATUS
  171. GetNextParameter (
  172. IN OUT CHAR16 **Walker,
  173. IN OUT CHAR16 **TempParameter,
  174. IN CONST UINTN Length,
  175. IN BOOLEAN StripQuotation
  176. );
  177. #endif //_SHELL_PARAMETERS_PROTOCOL_PROVIDER_HEADER_