EfiShellEnvironment2.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968
  1. /** @file
  2. Defines for EFI shell environment 2 ported to EDK II build environment. (no spec)
  3. Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #ifndef _SHELL_ENVIRONMENT_2_PROTOCOL_H_
  7. #define _SHELL_ENVIRONMENT_2_PROTOCOL_H_
  8. #define DEFAULT_INIT_ROW 1
  9. #define DEFAULT_AUTO_LF FALSE
  10. /**
  11. This function is a prototype for a function that dumps information on a protocol
  12. to a given location. The location is dependant on the implementation. This is
  13. used when programatically adding shell commands.
  14. @param[in] Handle The handle the protocol is on.
  15. @param[in] Interface The interface to the protocol.
  16. **/
  17. typedef
  18. VOID
  19. (EFIAPI *SHELLENV_DUMP_PROTOCOL_INFO)(
  20. IN EFI_HANDLE Handle,
  21. IN VOID *Interface
  22. );
  23. /**
  24. This function is a prototype for each command internal to the EFI shell
  25. implementation. The specific command depends on the implementation. This is
  26. used when programatically adding shell commands.
  27. @param[in] ImageHandle The handle to the binary shell.
  28. @param[in] SystemTable The pointer to the system table.
  29. @retval EFI_SUCCESS The command completed.
  30. @retval other An error occurred. Any error is possible
  31. depending on the implementation of the shell
  32. command.
  33. **/
  34. typedef
  35. EFI_STATUS
  36. (EFIAPI *SHELLENV_INTERNAL_COMMAND)(
  37. IN EFI_HANDLE ImageHandle,
  38. IN EFI_SYSTEM_TABLE *SystemTable
  39. );
  40. /**
  41. This function is a prototype for one that gets a help string for a given command.
  42. This is used when programatically adding shell commands. Upon successful return
  43. the memory allocated is up to the caller to free.
  44. @param[in, out] Str Pointer to pointer to string to display for help.
  45. @retval EFI_SUCCESS The help string is in the parameter Str.
  46. **/
  47. typedef
  48. EFI_STATUS
  49. (EFIAPI *SHELLCMD_GET_LINE_HELP)(
  50. IN OUT CHAR16 **Str
  51. );
  52. /**
  53. Structure returned from functions that open multiple files.
  54. **/
  55. typedef struct {
  56. UINT32 Signature; ///< SHELL_FILE_ARG_SIGNATURE.
  57. LIST_ENTRY Link; ///< Linked list helper.
  58. EFI_STATUS Status; ///< File's status.
  59. EFI_FILE_HANDLE Parent; ///< What is the Parent file of this file.
  60. UINT64 OpenMode; ///< How was the file opened.
  61. CHAR16 *ParentName; ///< String representation of parent.
  62. EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath; ///< DevicePath for Parent.
  63. CHAR16 *FullName; ///< Path and file name for this file.
  64. CHAR16 *FileName; ///< File name for this file.
  65. EFI_FILE_HANDLE Handle; ///< Handle to this file.
  66. EFI_FILE_INFO *Info; ///< Pointer to file info for this file.
  67. } SHELL_FILE_ARG;
  68. /// Signature for SHELL_FILE_ARG.
  69. #define SHELL_FILE_ARG_SIGNATURE SIGNATURE_32 ('g', 'r', 'a', 'f')
  70. /**
  71. GUID for the shell environment2 and shell environment.
  72. **/
  73. #define SHELL_ENVIRONMENT_PROTOCOL_GUID \
  74. { \
  75. 0x47c7b221, 0xc42a, 0x11d2, {0x8e, 0x57, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b} \
  76. }
  77. /**
  78. GUID for the shell environment2 extension (main GUID above).
  79. **/
  80. #define EFI_SE_EXT_SIGNATURE_GUID \
  81. { \
  82. 0xd2c18636, 0x40e5, 0x4eb5, {0xa3, 0x1b, 0x36, 0x69, 0x5f, 0xd4, 0x2c, 0x87} \
  83. }
  84. #define EFI_SHELL_MAJOR_VER 0x00000001 ///< Major version of the EFI_SHELL_ENVIRONMENT2.
  85. #define EFI_SHELL_MINOR_VER 0x00000000 ///< Minor version of the EFI_SHELL_ENVIRONMENT2.
  86. /**
  87. Execute a command line.
  88. This function will run the CommandLine. This includes loading any required images,
  89. parsing any requires scripts, and if DebugOutput is TRUE printing errors
  90. encountered directly to the screen.
  91. @param[in] ParentImageHandle Handle of the image executing this operation.
  92. @param[in] CommandLine The string command line to execute.
  93. @param[in] DebugOutput TRUE indicates that errors should be printed directly.
  94. FALSE suppresses error messages.
  95. @retval EFI_SUCCESS The command line executed and completed.
  96. @retval EFI_ABORTED The operation aborted.
  97. @retval EFI_INVALID_PARAMETER A parameter did not have a valid value.
  98. @retval EFI_OUT_OF_RESOURCES A required memory allocation failed.
  99. @sa HandleProtocol
  100. **/
  101. typedef
  102. EFI_STATUS
  103. (EFIAPI *SHELLENV_EXECUTE)(
  104. IN EFI_HANDLE *ParentImageHandle,
  105. IN CHAR16 *CommandLine,
  106. IN BOOLEAN DebugOutput
  107. );
  108. /**
  109. This function returns a shell environment variable value.
  110. @param[in] Name The pointer to the string with the shell environment
  111. variable name.
  112. @retval NULL The shell environment variable's value could not be found.
  113. @retval !=NULL The value of the shell environment variable Name.
  114. **/
  115. typedef
  116. CHAR16 *
  117. (EFIAPI *SHELLENV_GET_ENV)(
  118. IN CHAR16 *Name
  119. );
  120. /**
  121. This function returns a shell environment map value.
  122. @param[in] Name The pointer to the string with the shell environment
  123. map name.
  124. @retval NULL The shell environment map's value could not be found.
  125. @retval !=NULL The value of the shell environment map Name.
  126. **/
  127. typedef
  128. CHAR16 *
  129. (EFIAPI *SHELLENV_GET_MAP)(
  130. IN CHAR16 *Name
  131. );
  132. /**
  133. This function will add an internal command to the shell interface.
  134. This will allocate all required memory, put the new command on the command
  135. list in the correct location.
  136. @param[in] Handler The handler function to call when the command gets called.
  137. @param[in] Cmd The command name.
  138. @param[in] GetLineHelp The function to call of type "get help" for this command.
  139. @retval EFI_SUCCESS The command is now part of the command list.
  140. @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
  141. @sa SHELLENV_INTERNAL_COMMAND
  142. @sa SHELLCMD_GET_LINE_HELP
  143. **/
  144. typedef
  145. EFI_STATUS
  146. (EFIAPI *SHELLENV_ADD_CMD)(
  147. IN SHELLENV_INTERNAL_COMMAND Handler,
  148. IN CHAR16 *Cmd,
  149. IN SHELLCMD_GET_LINE_HELP GetLineHelp
  150. );
  151. /**
  152. Internal interface to add protocol handlers.
  153. This function is for internal shell use only. This is how protocol handlers are added.
  154. This will get the current protocol info and add the new info or update existing info
  155. and then resave the info.
  156. @param[in] Protocol The pointer to the protocol's GUID.
  157. @param[in] DumpToken The function pointer to dump token function or
  158. NULL.
  159. @param[in] DumpInfo The function pointer to dump infomation function
  160. or NULL.
  161. @param[in] IdString The English name of the protocol.
  162. **/
  163. typedef
  164. VOID
  165. (EFIAPI *SHELLENV_ADD_PROT)(
  166. IN EFI_GUID *Protocol,
  167. IN SHELLENV_DUMP_PROTOCOL_INFO DumpToken OPTIONAL,
  168. IN SHELLENV_DUMP_PROTOCOL_INFO DumpInfo OPTIONAL,
  169. IN CHAR16 *IdString
  170. );
  171. /**
  172. This function finds a protocol handle by a GUID.
  173. This function will check for already known protocols by GUID and if one is
  174. found it will return the name of that protocol. If no name is found and
  175. GenId is TRUE it will generate ths string.
  176. @param[in] Protocol The GUID of the protocol to look for.
  177. @param[in] GenId Whether to generate a name string if it is not found.
  178. @return !NULL The Name of the protocol.
  179. @retval NULL The Name was not found, and GenId was not TRUE.
  180. **/
  181. typedef
  182. CHAR16 *
  183. (EFIAPI *SHELLENV_GET_PROT)(
  184. IN EFI_GUID *Protocol,
  185. IN BOOLEAN GenId
  186. );
  187. /**
  188. This function returns a string array containing the current directory on
  189. a given device.
  190. If DeviceName is specified, then return the current shell directory on that
  191. device. If DeviceName is NULL, then return the current directory on the
  192. current device. The caller us responsible to free the returned string when
  193. no longer required.
  194. @param[in] DeviceName The name of the device to get the current
  195. directory on, or NULL for current device.
  196. @return String array with the current directory on the current or specified device.
  197. **/
  198. typedef
  199. CHAR16 *
  200. (EFIAPI *SHELLENV_CUR_DIR)(
  201. IN CHAR16 *DeviceName OPTIONAL
  202. );
  203. /**
  204. This function will open a group of files that match the Arg path, including
  205. support for wildcard characters ('?' and '*') in the Arg path. If there are
  206. any wildcard characters in the path this function will find any and all files
  207. that match the wildcards. It returns a double linked list based on the
  208. LIST_ENTRY linked list structure. Use this in conjunction with the
  209. SHELL_FILE_ARG_SIGNATURE to get the SHELL_FILE_ARG structures that are returned.
  210. The memory allocated by the callee for this list is freed by making a call to
  211. SHELLENV_FREE_FILE_LIST.
  212. @param[in] Arg The pointer Path to files to open.
  213. @param[in, out] ListHead The pointer to the allocated and initialized list head
  214. upon which to append all opened file structures.
  215. @retval EFI_SUCCESS One or more files was opened and a struct of each file's
  216. information was appended to ListHead.
  217. @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
  218. @retval EFI_NOT_FOUND No matching files could be found.
  219. @sa SHELLENV_FREE_FILE_LIST
  220. **/typedef
  221. EFI_STATUS
  222. (EFIAPI *SHELLENV_FILE_META_ARG)(
  223. IN CHAR16 *Arg,
  224. IN OUT LIST_ENTRY *ListHead
  225. );
  226. /**
  227. This frees all of the nodes under the ListHead, but not ListHead itself.
  228. @param[in, out] ListHead Pointer to list to free all nodes of.
  229. @retval EFI_SUCCESS This function always returns EFI_SUCCESS.
  230. **/
  231. typedef
  232. EFI_STATUS
  233. (EFIAPI *SHELLENV_FREE_FILE_LIST)(
  234. IN OUT LIST_ENTRY *ListHead
  235. );
  236. /**
  237. This function creates a new instance of the ShellInterface protocol for use on
  238. the ImageHandle.
  239. This function is for internal shell usage. This will allocate and then populate
  240. EFI_SHELL_INTERFACE protocol. It is the caller's responsibility to free the
  241. memory.
  242. @param[in] ImageHandle The handle which will use the new ShellInterface
  243. protocol.
  244. @return The newly allocated shell interface protocol.
  245. **/
  246. typedef
  247. EFI_SHELL_INTERFACE *
  248. (EFIAPI *SHELLENV_NEW_SHELL)(
  249. IN EFI_HANDLE ImageHandle
  250. );
  251. /**
  252. This function determines whether a script file is currently being processed.
  253. A script file (.nsh file) can contain a series of commands and this is useful to
  254. know for some shell commands whether they are being run manually or as part of a
  255. script.
  256. @retval TRUE A script file is being processed.
  257. @retval FALSE A script file is not being processed.
  258. **/
  259. typedef
  260. BOOLEAN
  261. (EFIAPI *SHELLENV_BATCH_IS_ACTIVE)(
  262. VOID
  263. );
  264. /**
  265. This is an internal shell function to free any and all allocated resources.
  266. This should be called immediately prior to closing the shell.
  267. **/
  268. typedef
  269. VOID
  270. (EFIAPI *SHELLENV_FREE_RESOURCES)(
  271. VOID
  272. );
  273. /**
  274. This function enables the page break mode.
  275. This mode causes the output to pause after each complete screen to enable a
  276. user to more easily read it. If AutoWrap is TRUE, then rows with too many
  277. characters will be chopped and divided into 2 rows. If FALSE, then rows with
  278. too many characters may not be fully visible to the user on the screen.
  279. @param[in] StartRow The row number to start this on.
  280. @param[in] AutoWrap Whether to auto wrap rows that are too long.
  281. **/
  282. typedef
  283. VOID
  284. (EFIAPI *SHELLENV_ENABLE_PAGE_BREAK)(
  285. IN INT32 StartRow,
  286. IN BOOLEAN AutoWrap
  287. );
  288. /**
  289. This function disables the page break mode.
  290. Disabling this causes the output to print out exactly as coded, with no breaks
  291. for readability.
  292. **/
  293. typedef
  294. VOID
  295. (EFIAPI *SHELLENV_DISABLE_PAGE_BREAK)(
  296. VOID
  297. );
  298. /**
  299. Get the status of the page break output mode.
  300. @retval FALSE Page break output mode is not enabled.
  301. @retval TRUE Page break output mode is enabled.
  302. **/
  303. typedef
  304. BOOLEAN
  305. (EFIAPI *SHELLENV_GET_PAGE_BREAK)(
  306. VOID
  307. );
  308. /**
  309. This function sets the keys to filter for for the console in. The valid
  310. values to set are:
  311. #define EFI_OUTPUT_SCROLL 0x00000001
  312. #define EFI_OUTPUT_PAUSE 0x00000002
  313. #define EFI_EXECUTION_BREAK 0x00000004
  314. @param[in] KeyFilter The new key filter to use.
  315. **/
  316. typedef
  317. VOID
  318. (EFIAPI *SHELLENV_SET_KEY_FILTER)(
  319. IN UINT32 KeyFilter
  320. );
  321. /**
  322. This function gets the keys to filter for for the console in.
  323. The valid values to get are:
  324. #define EFI_OUTPUT_SCROLL 0x00000001
  325. #define EFI_OUTPUT_PAUSE 0x00000002
  326. #define EFI_EXECUTION_BREAK 0x00000004
  327. @retval The current filter mask.
  328. **/
  329. typedef
  330. UINT32
  331. (EFIAPI *SHELLENV_GET_KEY_FILTER)(
  332. VOID
  333. );
  334. /**
  335. This function determines if the shell application should break.
  336. This is used to inform a shell application that a break condition has been
  337. initiated. Long loops should check this to prevent delays to the break.
  338. @retval TRUE A break has been signaled. The application
  339. should exit with EFI_ABORTED as soon as possible.
  340. @retval FALSE Continue as normal.
  341. **/
  342. typedef
  343. BOOLEAN
  344. (EFIAPI *SHELLENV_GET_EXECUTION_BREAK)(
  345. VOID
  346. );
  347. /**
  348. This is an internal shell function used to increment the shell nesting level.
  349. **/
  350. typedef
  351. VOID
  352. (EFIAPI *SHELLENV_INCREMENT_SHELL_NESTING_LEVEL)(
  353. VOID
  354. );
  355. /**
  356. This is an internal shell function used to decrement the shell nesting level.
  357. **/
  358. typedef
  359. VOID
  360. (EFIAPI *SHELLENV_DECREMENT_SHELL_NESTING_LEVEL)(
  361. VOID
  362. );
  363. /**
  364. This function determines if the caller is running under the root shell.
  365. @retval TRUE The caller is running under the root shell.
  366. @retval FALSE The caller is not running under the root shell.
  367. **/
  368. typedef
  369. BOOLEAN
  370. (EFIAPI *SHELLENV_IS_ROOT_SHELL)(
  371. VOID
  372. );
  373. /**
  374. Close the console proxy to restore the original console.
  375. This is an internal shell function to handle shell cascading. It restores the
  376. original set of console protocols.
  377. @param[in] ConInHandle The handle of ConIn.
  378. @param[in, out] ConIn The pointer to the location to return the pointer to
  379. the original console input.
  380. @param[in] ConOutHandle The handle of ConOut
  381. @param[in, out] ConOut The pointer to the location to return the pointer to
  382. the original console output.
  383. **/
  384. typedef
  385. VOID
  386. (EFIAPI *SHELLENV_CLOSE_CONSOLE_PROXY)(
  387. IN EFI_HANDLE ConInHandle,
  388. IN OUT EFI_SIMPLE_TEXT_INPUT_PROTOCOL **ConIn,
  389. IN EFI_HANDLE ConOutHandle,
  390. IN OUT EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL **ConOut
  391. );
  392. //
  393. // declarations of handle enumerator
  394. //
  395. /**
  396. For ease of use the shell maps handle #'s to short numbers.
  397. This is only done on request for various internal commands and the references
  398. are immediately freed when the internal command completes.
  399. **/
  400. typedef
  401. VOID
  402. (EFIAPI *INIT_HANDLE_ENUMERATOR)(
  403. VOID
  404. );
  405. /**
  406. This is an internal shell function to enumerate the handle database.
  407. This function gets the next handle in the handle database. If no handles are
  408. found, EFI_NOT_FOUND is returned. If the previous Handle was the last handle,
  409. it is set to NULL before returning.
  410. This must be called after INIT_HANDLE_ENUMERATOR and before CLOSE_HANDLE_ENUMERATOR.
  411. @param[in, out] Handle The pointer to pointer to Handle. It is set
  412. on a sucessful return.
  413. @retval EFI_SUCCESS The next handle in the handle database is *Handle.
  414. @retval EFI_NOT_FOUND There is not another handle.
  415. **/
  416. typedef
  417. EFI_STATUS
  418. (EFIAPI *NEXT_HANDLE)(
  419. IN OUT EFI_HANDLE **Handle
  420. );
  421. /**
  422. This is an internal shell function to enumerate the handle database.
  423. This function skips the next SkipNum handles in the handle database. If there
  424. are not enough handles left to skip that many EFI_ACCESS_DENIED is returned and
  425. no skip is performed.
  426. This must be called after INIT_HANDLE_ENUMERATOR and before CLOSE_HANDLE_ENUMERATOR.
  427. @param[in] SkipNum How many handles to skip
  428. @retval EFI_SUCCESS The next handle in the handle database is *Handle
  429. @retval EFI_ACCESS_DENIED There are not SkipNum handles left in the database
  430. **/
  431. typedef
  432. EFI_STATUS
  433. (EFIAPI *SKIP_HANDLE)(
  434. IN UINTN SkipNum
  435. );
  436. /**
  437. This is an internal shell function to enumerate the handle database.
  438. This function resets the the handle database so that NEXT_HANDLE and SKIP_HANDLE
  439. will start from EnumIndex on the next call.
  440. This must be called after INIT_HANDLE_ENUMERATOR and before CLOSE_HANDLE_ENUMERATOR.
  441. @param[in] EnumIndex Where to start.
  442. @return The number of handles either read out or skipped before this reset.
  443. **/
  444. typedef
  445. UINTN
  446. (EFIAPI *RESET_HANDLE_ENUMERATOR)(
  447. IN UINTN EnumIndex
  448. );
  449. /**
  450. This is an internal shell function to enumerate the handle database.
  451. This must be called after INIT_HANDLE_ENUMERATOR.
  452. This function releases all memory and resources associated with the handle database.
  453. After this no other handle enumerator functions except INIT_HANDLE_ENUMERATOR will
  454. function properly.
  455. **/
  456. typedef
  457. VOID
  458. (EFIAPI *CLOSE_HANDLE_ENUMERATOR)(
  459. VOID
  460. );
  461. /**
  462. This is an internal shell function to enumerate the handle database.
  463. This function returns the number of handles in the handle database.
  464. This must be called after INIT_HANDLE_ENUMERATOR and before CLOSE_HANDLE_ENUMERATOR.
  465. @return The number of handles in the handle database.
  466. **/
  467. typedef
  468. UINTN
  469. (EFIAPI *GET_NUM)(
  470. VOID
  471. );
  472. /**
  473. Handle Enumerator structure.
  474. **/
  475. typedef struct {
  476. INIT_HANDLE_ENUMERATOR Init; ///< The pointer to INIT_HANDLE_ENUMERATOR function.
  477. NEXT_HANDLE Next; ///< The pointer to NEXT_HANDLE function.
  478. SKIP_HANDLE Skip; ///< The pointer to SKIP_HANDLE function.
  479. RESET_HANDLE_ENUMERATOR Reset; ///< The pointer to RESET_HANDLE_ENUMERATOR function.
  480. CLOSE_HANDLE_ENUMERATOR Close; ///< The pointer to CLOSE_HANDLE_ENUMERATOR function.
  481. GET_NUM GetNum; ///< The pointer to GET_NUM function.
  482. } HANDLE_ENUMERATOR;
  483. /**
  484. Signature for the PROTOCOL_INFO structure.
  485. **/
  486. #define PROTOCOL_INFO_SIGNATURE SIGNATURE_32 ('s', 'p', 'i', 'n')
  487. /**
  488. PROTOCOL_INFO structure for protocol enumerator functions.
  489. **/
  490. typedef struct {
  491. UINTN Signature; ///< PROTOCOL_INFO_SIGNATURE.
  492. LIST_ENTRY Link; ///< Standard linked list helper member.
  493. //
  494. // The parsing info for the protocol.
  495. //
  496. EFI_GUID ProtocolId; ///< The GUID for the protocol.
  497. CHAR16 *IdString; ///< The name of the protocol.
  498. SHELLENV_DUMP_PROTOCOL_INFO DumpToken; ///< The pointer to DumpToken function for the protocol.
  499. SHELLENV_DUMP_PROTOCOL_INFO DumpInfo; ///< The pointer to DumpInfo function for the protocol.
  500. //
  501. // Patabase info on which handles are supporting this protocol.
  502. //
  503. UINTN NoHandles; ///< The number of handles producing this protocol.
  504. EFI_HANDLE *Handles; ///< The array of handles.
  505. } PROTOCOL_INFO;
  506. //
  507. // Declarations of protocol info enumerator.
  508. //
  509. /**
  510. This is an internal shell function to initialize the protocol enumerator.
  511. This must be called before NEXT_PROTOCOL_INFO, SKIP_PROTOCOL_INFO,
  512. RESET_PROTOCOL_INFO_ENUMERATOR, and CLOSE_PROTOCOL_INFO_ENUMERATOR are
  513. called.
  514. **/
  515. typedef
  516. VOID
  517. (EFIAPI *INIT_PROTOCOL_INFO_ENUMERATOR)(
  518. VOID
  519. );
  520. /**
  521. This function is an internal shell function for enumeration of protocols.
  522. This function returns the next protocol on the list. If this is called
  523. immediately after initialization, it will return the first protocol on the list.
  524. If this is called immediately after reset, it will return the first protocol again.
  525. This cannot be called after CLOSE_PROTOCOL_INFO_ENUMERATOR, but it must be
  526. called after INIT_PROTOCOL_INFO_ENUMERATOR.
  527. @param[in, out] ProtocolInfo The pointer to pointer to protocol information structure.
  528. @retval EFI_SUCCESS The next protocol's information was sucessfully returned.
  529. @retval NULL There are no more protocols.
  530. **/
  531. typedef
  532. EFI_STATUS
  533. (EFIAPI *NEXT_PROTOCOL_INFO)(
  534. IN OUT PROTOCOL_INFO **ProtocolInfo
  535. );
  536. /**
  537. This function is an internal shell function for enumeration of protocols.
  538. This cannot be called after CLOSE_PROTOCOL_INFO_ENUMERATOR, but it must be
  539. called after INIT_PROTOCOL_INFO_ENUMERATOR.
  540. This function does nothing and always returns EFI_SUCCESS.
  541. @retval EFI_SUCCESS Always returned (see above).
  542. **/
  543. typedef
  544. EFI_STATUS
  545. (EFIAPI *SKIP_PROTOCOL_INFO)(
  546. IN UINTN SkipNum
  547. );
  548. /**
  549. This function is an internal shell function for enumeration of protocols.
  550. This cannot be called after CLOSE_PROTOCOL_INFO_ENUMERATOR, but it must be
  551. called after INIT_PROTOCOL_INFO_ENUMERATOR.
  552. This function resets the list of protocols such that the next one in the
  553. list is the begining of the list.
  554. **/
  555. typedef
  556. VOID
  557. (EFIAPI *RESET_PROTOCOL_INFO_ENUMERATOR)(
  558. VOID
  559. );
  560. /**
  561. This function is an internal shell function for enumeration of protocols.
  562. This must be called after INIT_PROTOCOL_INFO_ENUMERATOR. After this call
  563. no protocol enumerator calls except INIT_PROTOCOL_INFO_ENUMERATOR may be made.
  564. This function frees any memory or resources associated with the protocol
  565. enumerator.
  566. **/
  567. typedef
  568. VOID
  569. (EFIAPI *CLOSE_PROTOCOL_INFO_ENUMERATOR)(
  570. VOID
  571. );
  572. /**
  573. Protocol enumerator structure of function pointers.
  574. **/
  575. typedef struct {
  576. INIT_PROTOCOL_INFO_ENUMERATOR Init; ///< The pointer to INIT_PROTOCOL_INFO_ENUMERATOR function.
  577. NEXT_PROTOCOL_INFO Next; ///< The pointer to NEXT_PROTOCOL_INFO function.
  578. SKIP_PROTOCOL_INFO Skip; ///< The pointer to SKIP_PROTOCOL_INFO function.
  579. RESET_PROTOCOL_INFO_ENUMERATOR Reset; ///< The pointer to RESET_PROTOCOL_INFO_ENUMERATOR function.
  580. CLOSE_PROTOCOL_INFO_ENUMERATOR Close; ///< The pointer to CLOSE_PROTOCOL_INFO_ENUMERATOR function.
  581. } PROTOCOL_INFO_ENUMERATOR;
  582. /**
  583. This function is used to retrieve a user-friendly display name for a handle.
  584. If UseComponentName is TRUE then the component name protocol for this device
  585. or it's parent device (if required) will be used to obtain the name of the
  586. device. If UseDevicePath is TRUE it will get the human readable device path
  587. and return that. If both are TRUE it will try to use component name first
  588. and device path if that fails.
  589. It will use either ComponentName or ComponentName2 protocol, depending on
  590. what is present.
  591. This function will furthur verify whether the handle in question produced either
  592. EFI_DRIVER_CONFIGRATION_PROTOCOL or EFI_DRIVER_CONFIGURATION2_PROTOCOL and also
  593. whether the handle in question produced either EFI_DRIVER_DIAGNOSTICS_PROTOCOL or
  594. EFI_DRIVER_DIAGNOSTICS2_PROTOCOL.
  595. Upon successful return, the memory for *BestDeviceName is up to the caller to free.
  596. @param[in] DeviceHandle The device handle whose name is desired.
  597. @param[in] UseComponentName Whether to use the ComponentName protocol at all.
  598. @param[in] UseDevicePath Whether to use the DevicePath protocol at all.
  599. @param[in] Language The pointer to the language string to use.
  600. @param[in, out] BestDeviceName The pointer to pointer to string allocated with the name.
  601. @param[out] ConfigurationStatus The pointer to status for opening a Configuration protocol.
  602. @param[out] DiagnosticsStatus The pointer to status for opening a Diagnostics protocol.
  603. @param[in] Display Whether to Print this out to default Print location.
  604. @param[in] Indent How many characters to indent the printing.
  605. @retval EFI_SUCCESS This function always returns EFI_SUCCESS.
  606. **/
  607. typedef
  608. EFI_STATUS
  609. (EFIAPI *GET_DEVICE_NAME)(
  610. IN EFI_HANDLE DeviceHandle,
  611. IN BOOLEAN UseComponentName,
  612. IN BOOLEAN UseDevicePath,
  613. IN CHAR8 *Language,
  614. IN OUT CHAR16 **BestDeviceName,
  615. OUT EFI_STATUS *ConfigurationStatus,
  616. OUT EFI_STATUS *DiagnosticsStatus,
  617. IN BOOLEAN Display,
  618. IN UINTN Indent
  619. );
  620. #define EFI_SHELL_COMPATIBLE_MODE_VER L"1.1.1" ///< The string for lowest version this shell supports.
  621. #define EFI_SHELL_ENHANCED_MODE_VER L"1.1.2" ///< The string for highest version this shell supports.
  622. /**
  623. This function gets the shell mode as stored in the shell environment
  624. "efishellmode". It will not fail.
  625. @param[out] Mode Returns a string representing one of the
  626. 2 supported modes of the shell.
  627. @retval EFI_SUCCESS This function always returns success.
  628. **/
  629. typedef
  630. EFI_STATUS
  631. (EFIAPI *GET_SHELL_MODE)(
  632. OUT CHAR16 **Mode
  633. );
  634. /**
  635. Convert a file system style name to a device path.
  636. This function will convert a shell path name to a Device Path Protocol path.
  637. This function will allocate any required memory for this operation and it
  638. is the responsibility of the caller to free that memory when no longer required.
  639. If anything prevents the complete conversion free any allocated memory and
  640. return NULL.
  641. @param[in] Path The path to convert.
  642. @retval !NULL A pointer to the callee allocated Device Path.
  643. @retval NULL The operation could not be completed.
  644. **/
  645. typedef
  646. EFI_DEVICE_PATH_PROTOCOL *
  647. (EFIAPI *SHELLENV_NAME_TO_PATH)(
  648. IN CHAR16 *Path
  649. );
  650. /**
  651. Converts a device path into a file system map name.
  652. If DevPath is NULL, then ASSERT.
  653. This function looks through the shell environment map for a map whose device
  654. path matches the DevPath parameter. If one is found the Name is returned via
  655. Name parameter. If sucessful the caller must free the memory allocated for
  656. Name.
  657. This function will use the internal lock to prevent changes to the map during
  658. the lookup operation.
  659. @param[in] DevPath The device path to search for a name for.
  660. @param[in] ConsistMapping What state to verify map flag VAR_ID_CONSIST.
  661. @param[out] Name On sucessful return the name of that device path.
  662. @retval EFI_SUCCESS The DevPath was found and the name returned
  663. in Name.
  664. @retval EFI_OUT_OF_RESOURCES A required memory allocation failed.
  665. @retval EFI_UNSUPPORTED The DevPath was not found in the map.
  666. **/
  667. typedef
  668. EFI_STATUS
  669. (EFIAPI *SHELLENV_GET_FS_NAME)(
  670. IN EFI_DEVICE_PATH_PROTOCOL *DevPath,
  671. IN BOOLEAN ConsistMapping,
  672. OUT CHAR16 **Name
  673. );
  674. /**
  675. This function will open a group of files that match the Arg path, but will not
  676. support the wildcard characters ('?' and '*') in the Arg path. If there are
  677. any wildcard characters in the path this function will return
  678. EFI_INVALID_PARAMETER. The return is a double linked list based on the
  679. LIST_ENTRY linked list structure. Use this in conjunction with the
  680. SHELL_FILE_ARG_SIGNATURE to get the SHELL_FILE_ARG structures that are returned.
  681. The memory allocated by the callee for this list is freed by making a call to
  682. SHELLENV_FREE_FILE_LIST.
  683. @param[in] Arg The pointer to the path of the files to be opened.
  684. @param[in, out] ListHead The pointer to allocated and initialized list head
  685. upon which to append all the opened file structures.
  686. @retval EFI_SUCCESS One or more files was opened and a struct of each file's
  687. information was appended to ListHead.
  688. @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
  689. @retval EFI_NOT_FOUND No matching files could be found.
  690. @sa SHELLENV_FREE_FILE_LIST
  691. **/
  692. typedef
  693. EFI_STATUS
  694. (EFIAPI *SHELLENV_FILE_META_ARG_NO_WILDCARD)(
  695. IN CHAR16 *Arg,
  696. IN OUT LIST_ENTRY *ListHead
  697. );
  698. /**
  699. This function removes duplicate file listings from lists.
  700. This is a function for use with SHELLENV_FILE_META_ARG_NO_WILDCARD and
  701. SHELLENV_FILE_META_ARG. This function will verify that there are no duplicate
  702. files in the list of returned files. Any file listed twice will have one of its
  703. instances removed.
  704. @param[in] ListHead The pointer to linked list head that was returned from
  705. SHELLENV_FILE_META_ARG_NO_WILDCARD or
  706. SHELLENV_FILE_META_ARG.
  707. @retval EFI_SUCCESS This function always returns success.
  708. **/
  709. typedef
  710. EFI_STATUS
  711. (EFIAPI *SHELLENV_DEL_DUP_FILE)(
  712. IN LIST_ENTRY *ListHead
  713. );
  714. /**
  715. Converts a File System map name to a device path.
  716. If DevPath is NULL, then ASSERT().
  717. This function looks through the shell environment map for a map whose Name
  718. matches the Name parameter. If one is found, the device path pointer is
  719. updated to point to that file systems device path. The caller should not
  720. free the memory from that device path.
  721. This function will use the internal lock to prevent changes to the map during
  722. the lookup operation.
  723. @param[in] Name The pointer to the NULL terminated UNICODE string of the
  724. file system name.
  725. @param[out] DevPath The pointer to pointer to DevicePath. Only valid on
  726. successful return.
  727. @retval EFI_SUCCESS The conversion was successful, and the device
  728. path was returned.
  729. @retval EFI_NOT_FOUND The file system could not be found in the map.
  730. **/
  731. typedef
  732. EFI_STATUS
  733. (EFIAPI *SHELLENV_GET_FS_DEVICE_PATH)(
  734. IN CHAR16 *Name,
  735. OUT EFI_DEVICE_PATH_PROTOCOL **DevPath
  736. );
  737. /// EFI_SHELL_ENVIRONMENT2 protocol structure.
  738. typedef struct {
  739. SHELLENV_EXECUTE Execute;
  740. SHELLENV_GET_ENV GetEnv;
  741. SHELLENV_GET_MAP GetMap;
  742. SHELLENV_ADD_CMD AddCmd;
  743. SHELLENV_ADD_PROT AddProt;
  744. SHELLENV_GET_PROT GetProt;
  745. SHELLENV_CUR_DIR CurDir;
  746. SHELLENV_FILE_META_ARG FileMetaArg;
  747. SHELLENV_FREE_FILE_LIST FreeFileList;
  748. //
  749. // The following services are only used by the shell itself.
  750. //
  751. SHELLENV_NEW_SHELL NewShell;
  752. SHELLENV_BATCH_IS_ACTIVE BatchIsActive;
  753. SHELLENV_FREE_RESOURCES FreeResources;
  754. //
  755. // GUID to differentiate ShellEnvironment2 from ShellEnvironment.
  756. //
  757. EFI_GUID SESGuid;
  758. //
  759. // Major Version grows if shell environment interface has been changes.
  760. //
  761. UINT32 MajorVersion;
  762. UINT32 MinorVersion;
  763. SHELLENV_ENABLE_PAGE_BREAK EnablePageBreak;
  764. SHELLENV_DISABLE_PAGE_BREAK DisablePageBreak;
  765. SHELLENV_GET_PAGE_BREAK GetPageBreak;
  766. SHELLENV_SET_KEY_FILTER SetKeyFilter;
  767. SHELLENV_GET_KEY_FILTER GetKeyFilter;
  768. SHELLENV_GET_EXECUTION_BREAK GetExecutionBreak;
  769. SHELLENV_INCREMENT_SHELL_NESTING_LEVEL IncrementShellNestingLevel;
  770. SHELLENV_DECREMENT_SHELL_NESTING_LEVEL DecrementShellNestingLevel;
  771. SHELLENV_IS_ROOT_SHELL IsRootShell;
  772. SHELLENV_CLOSE_CONSOLE_PROXY CloseConsoleProxy;
  773. HANDLE_ENUMERATOR HandleEnumerator;
  774. PROTOCOL_INFO_ENUMERATOR ProtocolInfoEnumerator;
  775. GET_DEVICE_NAME GetDeviceName;
  776. GET_SHELL_MODE GetShellMode;
  777. SHELLENV_NAME_TO_PATH NameToPath;
  778. SHELLENV_GET_FS_NAME GetFsName;
  779. SHELLENV_FILE_META_ARG_NO_WILDCARD FileMetaArgNoWildCard;
  780. SHELLENV_DEL_DUP_FILE DelDupFileArg;
  781. SHELLENV_GET_FS_DEVICE_PATH GetFsDevicePath;
  782. } EFI_SHELL_ENVIRONMENT2;
  783. extern EFI_GUID gEfiShellEnvironment2Guid;
  784. extern EFI_GUID gEfiShellEnvironment2ExtGuid;
  785. #endif // _SHELL_ENVIRONMENT_2_PROTOCOL_H_