ShellCommandLib.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  1. /** @file
  2. Provides interface to shell internal functions for shell commands.
  3. This library is for use ONLY by shell commands linked into the shell application.
  4. This library will not function if it is used for UEFI Shell 2.0 Applications.
  5. Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
  6. (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
  7. (C) Copyright 2013-2014 Hewlett-Packard Development Company, L.P.<BR>
  8. SPDX-License-Identifier: BSD-2-Clause-Patent
  9. **/
  10. #ifndef _SHELL_COMMAND_LIB_
  11. #define _SHELL_COMMAND_LIB_
  12. #include <Uefi.h>
  13. #include <Protocol/Shell.h>
  14. #include <Protocol/ShellParameters.h>
  15. #include <Protocol/UnicodeCollation.h>
  16. #include <Protocol/SimpleFileSystem.h>
  17. #include <Library/UefiBootServicesTableLib.h>
  18. //
  19. // The extern global protocol poionters.
  20. //
  21. extern EFI_UNICODE_COLLATION_PROTOCOL *gUnicodeCollation;
  22. extern CONST CHAR16 *SupportLevel[];
  23. //
  24. // The map list objects.
  25. //
  26. typedef struct {
  27. LIST_ENTRY Link;
  28. EFI_DEVICE_PATH_PROTOCOL *DevicePath;
  29. CHAR16 *MapName;
  30. CHAR16 *CurrentDirectoryPath;
  31. UINT64 Flags;
  32. } SHELL_MAP_LIST;
  33. /// List of Mappings - DeviceName and Drive Letter(ism).
  34. extern SHELL_MAP_LIST gShellMapList;
  35. /// Pointer to node of current directory in the mMapList.
  36. extern SHELL_MAP_LIST *gShellCurMapping;
  37. /**
  38. Returns the help MAN fileName for a given shell command.
  39. @retval !NULL The unicode string of the MAN filename.
  40. @retval NULL An error ocurred.
  41. **/
  42. typedef
  43. CONST CHAR16 *
  44. (EFIAPI *SHELL_GET_MAN_FILENAME)(
  45. VOID
  46. );
  47. /**
  48. Runs a shell command on a given command line.
  49. The specific operation of a given shell command is specified in the UEFI Shell
  50. Specification 2.0, or in the source of the given command.
  51. Upon completion of the command run the shell protocol and environment variables
  52. may have been updated due to the operation.
  53. @param[in] ImageHandle The ImageHandle to the app, or NULL if
  54. the command built into shell.
  55. @param[in] SystemTable The pointer to the system table.
  56. @retval RETURN_SUCCESS The shell command was sucessful.
  57. @retval RETURN_UNSUPPORTED The command is not supported.
  58. **/
  59. typedef
  60. SHELL_STATUS
  61. (EFIAPI *SHELL_RUN_COMMAND)(
  62. IN EFI_HANDLE ImageHandle,
  63. IN EFI_SYSTEM_TABLE *SystemTable
  64. );
  65. /**
  66. Registers the handlers of type SHELL_RUN_COMMAND and
  67. SHELL_GET_MAN_FILENAME for each shell command.
  68. If the ShellSupportLevel is greater than the value of
  69. PcdShellSupportLevel, then return RETURN_UNSUPPORTED.
  70. Registers the the handlers specified by GetHelpInfoHandler and CommandHandler
  71. with the command specified by CommandString. If the command named by
  72. CommandString has already been registered, then return
  73. RETURN_ALREADY_STARTED.
  74. If there are not enough resources available to register the handlers, then
  75. RETURN_OUT_OF_RESOURCES is returned.
  76. If CommandString is NULL, then ASSERT().
  77. If GetHelpInfoHandler is NULL, then ASSERT().
  78. If CommandHandler is NULL, then ASSERT().
  79. If ProfileName is NULL, then ASSERT().
  80. @param[in] CommandString The pointer to the command name. This is the
  81. name to look for on the command line in
  82. the shell.
  83. @param[in] CommandHandler The pointer to a function that runs the
  84. specified command.
  85. @param[in] GetManFileName The pointer to a function that provides man
  86. filename.
  87. @param[in] ShellMinSupportLevel The minimum Shell Support Level which has this
  88. function.
  89. @param[in] ProfileName The profile name to require for support of this
  90. function.
  91. @param[in] CanAffectLE Indicates whether this command's return value
  92. can change the LASTERROR environment variable.
  93. @param[in] HiiHandle The handle of this command's HII entry.
  94. @param[in] ManFormatHelp The HII locator for the help text.
  95. @retval RETURN_SUCCESS The handlers were registered.
  96. @retval RETURN_OUT_OF_RESOURCES There are not enough resources available to
  97. register the shell command.
  98. @retval RETURN_UNSUPPORTED The ShellMinSupportLevel was higher than the
  99. currently allowed support level.
  100. @retval RETURN_ALREADY_STARTED The CommandString represents a command that
  101. is already registered. Only one handler set for
  102. a given command is allowed.
  103. @sa SHELL_GET_MAN_FILENAME
  104. @sa SHELL_RUN_COMMAND
  105. **/
  106. RETURN_STATUS
  107. EFIAPI
  108. ShellCommandRegisterCommandName (
  109. IN CONST CHAR16 *CommandString,
  110. IN SHELL_RUN_COMMAND CommandHandler,
  111. IN SHELL_GET_MAN_FILENAME GetManFileName,
  112. IN UINT32 ShellMinSupportLevel,
  113. IN CONST CHAR16 *ProfileName,
  114. IN CONST BOOLEAN CanAffectLE,
  115. IN CONST EFI_HII_HANDLE HiiHandle,
  116. IN CONST EFI_STRING_ID ManFormatHelp
  117. );
  118. /**
  119. Checks if a command string has been registered for CommandString, and if so, it runs
  120. the previously registered handler for that command with the command line.
  121. If CommandString is NULL, then ASSERT().
  122. If Sections is specified, then each section name listed will be compared in a case sensitive
  123. manner to the section names described in Appendix B UEFI Shell 2.0 Specification. If the section exists,
  124. it is appended to the returned help text. If the section does not exist, no
  125. information is returned. If Sections is NULL, then all help text information
  126. available is returned.
  127. @param[in] CommandString The pointer to the command name. This is the name
  128. found on the command line in the shell.
  129. @param[in, out] RetVal The pointer to the return value from the command handler.
  130. @param[in, out] CanAffectLE Indicates whether this command's return value
  131. needs to be placed into LASTERROR environment variable.
  132. @retval RETURN_SUCCESS The handler was run.
  133. @retval RETURN_NOT_FOUND The CommandString did not match a registered
  134. command name.
  135. @sa SHELL_RUN_COMMAND
  136. **/
  137. RETURN_STATUS
  138. EFIAPI
  139. ShellCommandRunCommandHandler (
  140. IN CONST CHAR16 *CommandString,
  141. IN OUT SHELL_STATUS *RetVal,
  142. IN OUT BOOLEAN *CanAffectLE OPTIONAL
  143. );
  144. /**
  145. Checks if a command string has been registered for CommandString, and if so, it
  146. returns the MAN filename specified for that command.
  147. If CommandString is NULL, then ASSERT().
  148. @param[in] CommandString The pointer to the command name. This is the name
  149. found on the command line in the shell.
  150. @retval NULL The CommandString was not a registered command.
  151. @retval other The name of the MAN file.
  152. @sa SHELL_GET_MAN_FILENAME
  153. **/
  154. CONST CHAR16 *
  155. EFIAPI
  156. ShellCommandGetManFileNameHandler (
  157. IN CONST CHAR16 *CommandString
  158. );
  159. typedef struct {
  160. LIST_ENTRY Link;
  161. CHAR16 *CommandString;
  162. } COMMAND_LIST;
  163. /**
  164. Get the list of all available shell internal commands. This is a linked list,
  165. via the LIST_ENTRY structure. Enumerate through it using the BaseLib linked
  166. list functions. Do not modify the values.
  167. @param[in] Sort TRUE to alphabetically sort the values first. FALSE otherwise.
  168. @return A linked list of all available shell commands.
  169. **/
  170. CONST COMMAND_LIST *
  171. EFIAPI
  172. ShellCommandGetCommandList (
  173. IN CONST BOOLEAN Sort
  174. );
  175. typedef struct {
  176. LIST_ENTRY Link;
  177. CHAR16 *CommandString;
  178. CHAR16 *Alias;
  179. } ALIAS_LIST;
  180. /**
  181. Registers aliases to be set as part of the initialization of the shell application.
  182. If Command is NULL, then ASSERT().
  183. If Alias is NULL, then ASSERT().
  184. @param[in] Command The pointer to the Command.
  185. @param[in] Alias The pointer to Alias.
  186. @retval RETURN_SUCCESS The handlers were registered.
  187. @retval RETURN_OUT_OF_RESOURCES There are not enough resources available to
  188. register the shell command.
  189. **/
  190. RETURN_STATUS
  191. EFIAPI
  192. ShellCommandRegisterAlias (
  193. IN CONST CHAR16 *Command,
  194. IN CONST CHAR16 *Alias
  195. );
  196. /**
  197. Get the list of all shell alias commands. This is a linked list,
  198. via LIST_ENTRY structure. Enumerate through it using the BaseLib linked
  199. list functions. Do not modify the values.
  200. @return A linked list of all requested shell aliases.
  201. **/
  202. CONST ALIAS_LIST *
  203. EFIAPI
  204. ShellCommandGetInitAliasList (
  205. VOID
  206. );
  207. /**
  208. Determine if a given alias is on the list of built in aliases.
  209. @param[in] Alias The alias to test for.
  210. @retval TRUE The alias is a built in alias.
  211. @retval FALSE The alias is not a built in alias.
  212. **/
  213. BOOLEAN
  214. EFIAPI
  215. ShellCommandIsOnAliasList (
  216. IN CONST CHAR16 *Alias
  217. );
  218. /**
  219. Checks if a command is already on the list.
  220. @param[in] CommandString The command string to check for on the list.
  221. @retval TRUE CommandString represents a registered command.
  222. @retval FALSE CommandString does not represent a registered command.
  223. **/
  224. BOOLEAN
  225. EFIAPI
  226. ShellCommandIsCommandOnList (
  227. IN CONST CHAR16 *CommandString
  228. );
  229. /**
  230. Get the help text for a command.
  231. @param[in] CommandString The command name.
  232. @retval NULL No help text was found.
  233. @return The string of the help text. The caller required to free.
  234. **/
  235. CHAR16 *
  236. EFIAPI
  237. ShellCommandGetCommandHelp (
  238. IN CONST CHAR16 *CommandString
  239. );
  240. /**
  241. Function to make sure that the above pointers are valid.
  242. **/
  243. EFI_STATUS
  244. EFIAPI
  245. CommandInit (
  246. VOID
  247. );
  248. /**
  249. Function to determine current state of ECHO. Echo determines if lines from scripts
  250. and ECHO commands are enabled.
  251. @retval TRUE Echo is currently enabled.
  252. @retval FALSE Echo is currently disabled.
  253. **/
  254. BOOLEAN
  255. EFIAPI
  256. ShellCommandGetEchoState (
  257. VOID
  258. );
  259. /**
  260. Function to set current state of ECHO. Echo determines if lines from scripts
  261. and ECHO commands are enabled.
  262. @param[in] State TRUE to enable Echo, FALSE otherwise.
  263. **/
  264. VOID
  265. EFIAPI
  266. ShellCommandSetEchoState (
  267. IN BOOLEAN State
  268. );
  269. /**
  270. Indicate that the current shell or script should exit.
  271. @param[in] ScriptOnly TRUE if exiting a script; FALSE otherwise.
  272. @param[in] ErrorCode The 64 bit error code to return.
  273. **/
  274. VOID
  275. EFIAPI
  276. ShellCommandRegisterExit (
  277. IN BOOLEAN ScriptOnly,
  278. IN CONST UINT64 ErrorCode
  279. );
  280. /**
  281. Retrieve the Exit code.
  282. @return the value passed into RegisterExit.
  283. **/
  284. UINT64
  285. EFIAPI
  286. ShellCommandGetExitCode (
  287. VOID
  288. );
  289. /**
  290. Retrieve the Exit indicator.
  291. @retval TRUE Exit was indicated.
  292. @retval FALSE Exit was not indicated.
  293. **/
  294. BOOLEAN
  295. EFIAPI
  296. ShellCommandGetExit (
  297. VOID
  298. );
  299. /**
  300. Retrieve the Exit script indicator.
  301. If ShellCommandGetExit returns FALSE, then the return from this is undefined.
  302. @retval TRUE ScriptOnly was indicated.
  303. @retval FALSE ScriptOnly was not indicated.
  304. **/
  305. BOOLEAN
  306. EFIAPI
  307. ShellCommandGetScriptExit (
  308. VOID
  309. );
  310. typedef struct {
  311. LIST_ENTRY Link; ///< List enumerator items.
  312. UINTN Line; ///< What line of the script file this was on.
  313. CHAR16 *Cl; ///< The original command line.
  314. VOID *Data; ///< The data structure format dependant upon Command. (not always used)
  315. BOOLEAN Reset; ///< Reset the command (it must be treated like a initial run (but it may have data already))
  316. } SCRIPT_COMMAND_LIST;
  317. typedef struct {
  318. CHAR16 *ScriptName; ///< The filename of this script.
  319. CHAR16 **Argv; ///< The parmameters to the script file.
  320. UINTN Argc; ///< The count of parameters.
  321. LIST_ENTRY CommandList; ///< The script converted to a list of commands (SCRIPT_COMMAND_LIST objects).
  322. SCRIPT_COMMAND_LIST *CurrentCommand; ///< The command currently being operated. If !=NULL must be a member of CommandList.
  323. LIST_ENTRY SubstList; ///< A list of current script loop alias' (ALIAS_LIST objects) (Used for the for %-based replacement).
  324. } SCRIPT_FILE;
  325. /**
  326. Function to return a pointer to the currently running script file object.
  327. @retval NULL A script file is not currently running.
  328. @return A pointer to the current script file object.
  329. **/
  330. SCRIPT_FILE *
  331. EFIAPI
  332. ShellCommandGetCurrentScriptFile (
  333. VOID
  334. );
  335. /**
  336. Function to set a new script as the currently running one.
  337. This function will correctly stack and unstack nested scripts.
  338. @param[in] Script The pointer to new script information structure. If NULL,
  339. it removes and de-allocates the topmost Script structure.
  340. @return A pointer to the current running script file after this
  341. change. It is NULL if removing the final script.
  342. **/
  343. SCRIPT_FILE *
  344. EFIAPI
  345. ShellCommandSetNewScript (
  346. IN SCRIPT_FILE *Script OPTIONAL
  347. );
  348. /**
  349. Function to cleanup all memory from a SCRIPT_FILE structure.
  350. @param[in] Script The pointer to the structure to cleanup.
  351. **/
  352. VOID
  353. EFIAPI
  354. DeleteScriptFileStruct (
  355. IN SCRIPT_FILE *Script
  356. );
  357. /**
  358. Function to get the current Profile string.
  359. This is used to retrieve what profiles were installed.
  360. @retval NULL There are no installed profiles.
  361. @return A semicolon-delimited list of profiles.
  362. **/
  363. CONST CHAR16 *
  364. EFIAPI
  365. ShellCommandGetProfileList (
  366. VOID
  367. );
  368. typedef enum {
  369. MappingTypeFileSystem,
  370. MappingTypeBlockIo,
  371. MappingTypeMax
  372. } SHELL_MAPPING_TYPE;
  373. /**
  374. Function to generate the next default mapping name.
  375. If the return value is not NULL then it must be callee freed.
  376. @param Type What kind of mapping name to make.
  377. @retval NULL a memory allocation failed.
  378. @return a new map name string
  379. **/
  380. CHAR16 *
  381. EFIAPI
  382. ShellCommandCreateNewMappingName (
  383. IN CONST SHELL_MAPPING_TYPE Type
  384. );
  385. /**
  386. Function to initialize the table for creating consistent map names.
  387. @param[out] Table The pointer to pointer to pointer to DevicePathProtocol object.
  388. @retval EFI_SUCCESS The table was created successfully.
  389. **/
  390. EFI_STATUS
  391. EFIAPI
  392. ShellCommandConsistMappingInitialize (
  393. EFI_DEVICE_PATH_PROTOCOL ***Table
  394. );
  395. /**
  396. Function to uninitialize the table for creating consistent map names.
  397. The parameter must have been received from ShellCommandConsistMappingInitialize.
  398. @param[out] Table The pointer to pointer to DevicePathProtocol object.
  399. @retval EFI_SUCCESS The table was deleted successfully.
  400. **/
  401. EFI_STATUS
  402. EFIAPI
  403. ShellCommandConsistMappingUnInitialize (
  404. EFI_DEVICE_PATH_PROTOCOL **Table
  405. );
  406. /**
  407. Create a consistent mapped name for the device specified by DevicePath
  408. based on the Table.
  409. This must be called after ShellCommandConsistMappingInitialize() and
  410. before ShellCommandConsistMappingUnInitialize() is called.
  411. @param[in] DevicePath The pointer to the dev path for the device.
  412. @param[in] Table The Table of mapping information.
  413. @retval NULL A consistent mapped name could not be created.
  414. @return A pointer to a string allocated from pool with the device name.
  415. **/
  416. CHAR16 *
  417. EFIAPI
  418. ShellCommandConsistMappingGenMappingName (
  419. IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
  420. IN EFI_DEVICE_PATH_PROTOCOL **Table
  421. );
  422. /**
  423. Function to search the list of mappings for the first matching node on the
  424. list based on the MapKey.
  425. @param[in] MapKey The pointer to the string key to search for in the map.
  426. @return the node on the list.
  427. **/
  428. SHELL_MAP_LIST *
  429. EFIAPI
  430. ShellCommandFindMapItem (
  431. IN CONST CHAR16 *MapKey
  432. );
  433. /**
  434. Function to add a map node to the list of map items and update the "path" environment variable (optionally).
  435. If Path is TRUE (during initialization only), the path environment variable will also be updated to include
  436. default paths on the new map name...
  437. Path should be FALSE when this function is called from the protocol SetMap function.
  438. @param[in] Name The human readable mapped name.
  439. @param[in] DevicePath The Device Path for this map.
  440. @param[in] Flags The Flags attribute for this map item.
  441. @param[in] Path TRUE to update path, FALSE to skip this step (should only be TRUE during initialization).
  442. @retval EFI_SUCCESS The addition was sucessful.
  443. @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
  444. @retval EFI_INVALID_PARAMETER A parameter was invalid.
  445. **/
  446. EFI_STATUS
  447. EFIAPI
  448. ShellCommandAddMapItemAndUpdatePath (
  449. IN CONST CHAR16 *Name,
  450. IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
  451. IN CONST UINT64 Flags,
  452. IN CONST BOOLEAN Path
  453. );
  454. /**
  455. Creates the default map names for each device path in the system with
  456. a protocol depending on the Type.
  457. Also sets up the default path environment variable if Type is FileSystem.
  458. @retval EFI_SUCCESS All map names were created sucessfully.
  459. @retval EFI_NOT_FOUND No protocols were found in the system.
  460. @return Error returned from gBS->LocateHandle().
  461. @sa LocateHandle
  462. **/
  463. EFI_STATUS
  464. EFIAPI
  465. ShellCommandCreateInitialMappingsAndPaths (
  466. VOID
  467. );
  468. /**
  469. Add mappings for any devices without one. Do not change any existing maps.
  470. @retval EFI_SUCCESS The operation was successful.
  471. **/
  472. EFI_STATUS
  473. EFIAPI
  474. ShellCommandUpdateMapping (
  475. VOID
  476. );
  477. /**
  478. Converts a SHELL_FILE_HANDLE to an EFI_FILE_PROTOCOL*.
  479. @param[in] Handle The SHELL_FILE_HANDLE to convert.
  480. @return a EFI_FILE_PROTOCOL* representing the same file.
  481. **/
  482. EFI_FILE_PROTOCOL *
  483. EFIAPI
  484. ConvertShellHandleToEfiFileProtocol (
  485. IN CONST SHELL_FILE_HANDLE Handle
  486. );
  487. /**
  488. Remove a SHELL_FILE_HANDLE frmo the list of SHELL_FILE_HANDLES.
  489. @param[in] Handle The SHELL_FILE_HANDLE to remove.
  490. @retval TRUE The item was removed.
  491. @retval FALSE The item was not found.
  492. **/
  493. BOOLEAN
  494. EFIAPI
  495. ShellFileHandleRemove (
  496. IN CONST SHELL_FILE_HANDLE Handle
  497. );
  498. /**
  499. Converts a EFI_FILE_PROTOCOL* to an SHELL_FILE_HANDLE.
  500. @param[in] Handle The pointer to EFI_FILE_PROTOCOL to convert.
  501. @param[in] Path The path to the file for verification.
  502. @return a SHELL_FILE_HANDLE representing the same file.
  503. **/
  504. SHELL_FILE_HANDLE
  505. EFIAPI
  506. ConvertEfiFileProtocolToShellHandle (
  507. IN CONST EFI_FILE_PROTOCOL *Handle,
  508. IN CONST CHAR16 *Path
  509. );
  510. /**
  511. Find the path that was logged with the specified SHELL_FILE_HANDLE.
  512. @param[in] Handle The SHELL_FILE_HANDLE to query on.
  513. @return A pointer to the path for the file.
  514. **/
  515. CONST CHAR16 *
  516. EFIAPI
  517. ShellFileHandleGetPath (
  518. IN CONST SHELL_FILE_HANDLE Handle
  519. );
  520. /**
  521. Function to determine if a SHELL_FILE_HANDLE is at the end of the file.
  522. This will NOT work on directories.
  523. If Handle is NULL, then ASSERT.
  524. @param[in] Handle the file handle
  525. @retval TRUE the position is at the end of the file
  526. @retval FALSE the position is not at the end of the file
  527. **/
  528. BOOLEAN
  529. EFIAPI
  530. ShellFileHandleEof (
  531. IN SHELL_FILE_HANDLE Handle
  532. );
  533. typedef struct {
  534. LIST_ENTRY Link;
  535. void *Buffer;
  536. } BUFFER_LIST;
  537. /**
  538. Frees any BUFFER_LIST defined type.
  539. @param[in] List The pointer to the list head.
  540. **/
  541. VOID
  542. EFIAPI
  543. FreeBufferList (
  544. IN BUFFER_LIST *List
  545. );
  546. /**
  547. Function printing hex output to the console.
  548. @param[in] Indent Number of spaces to indent.
  549. @param[in] Offset Offset to start with.
  550. @param[in] DataSize Length of data.
  551. @param[in] UserData Pointer to some data.
  552. **/
  553. VOID
  554. EFIAPI
  555. DumpHex (
  556. IN UINTN Indent,
  557. IN UINTN Offset,
  558. IN UINTN DataSize,
  559. IN VOID *UserData
  560. );
  561. /**
  562. Dump HEX data into buffer.
  563. @param[in] Buffer HEX data to be dumped in Buffer.
  564. @param[in] Indent How many spaces to indent the output.
  565. @param[in] Offset The offset of the printing.
  566. @param[in] DataSize The size in bytes of UserData.
  567. @param[in] UserData The data to print out.
  568. **/
  569. CHAR16 *
  570. EFIAPI
  571. CatSDumpHex (
  572. IN CHAR16 *Buffer,
  573. IN UINTN Indent,
  574. IN UINTN Offset,
  575. IN UINTN DataSize,
  576. IN VOID *UserData
  577. );
  578. //
  579. // Determines the ordering operation for ShellSortFileList().
  580. //
  581. typedef enum {
  582. //
  583. // Sort the EFI_SHELL_FILE_INFO objects by the FileName field, in increasing
  584. // order, using gUnicodeCollation->StriColl().
  585. //
  586. ShellSortFileListByFileName,
  587. //
  588. // Sort the EFI_SHELL_FILE_INFO objects by the FullName field, in increasing
  589. // order, using gUnicodeCollation->StriColl().
  590. //
  591. ShellSortFileListByFullName,
  592. ShellSortFileListMax
  593. } SHELL_SORT_FILE_LIST;
  594. /**
  595. Sort an EFI_SHELL_FILE_INFO list, optionally moving duplicates to a separate
  596. list.
  597. @param[in,out] FileList The list of EFI_SHELL_FILE_INFO objects to sort.
  598. If FileList is NULL on input, then FileList is
  599. considered an empty, hence already sorted, list.
  600. Otherwise, if (*FileList) is NULL on input, then
  601. EFI_INVALID_PARAMETER is returned.
  602. Otherwise, the caller is responsible for having
  603. initialized (*FileList)->Link with
  604. InitializeListHead(). No other fields in the
  605. (**FileList) head element are accessed by this
  606. function.
  607. On output, (*FileList) is sorted according to Order.
  608. If Duplicates is NULL on input, then duplicate
  609. elements are preserved, sorted stably, on
  610. (*FileList). If Duplicates is not NULL on input,
  611. then duplicates are moved (stably sorted) to the
  612. new, dynamically allocated (*Duplicates) list.
  613. @param[out] Duplicates If Duplicates is NULL on input, (*FileList) will be
  614. a monotonically ordered list on output, with
  615. duplicates stably sorted.
  616. If Duplicates is not NULL on input, (*FileList) will
  617. be a strictly monotonically oredered list on output,
  618. with duplicates separated (stably sorted) to
  619. (*Duplicates). All fields except Link will be
  620. zero-initialized in the (**Duplicates) head element.
  621. If no duplicates exist, then (*Duplicates) is set to
  622. NULL on output.
  623. @param[in] Order Determines the comparison operation between
  624. EFI_SHELL_FILE_INFO objects.
  625. @retval EFI_INVALID_PARAMETER (UINTN)Order is greater than or equal to
  626. (UINTN)ShellSortFileListMax. Neither the
  627. (*FileList) nor the (*Duplicates) list has
  628. been modified.
  629. @retval EFI_INVALID_PARAMETER (*FileList) was NULL on input. Neither the
  630. (*FileList) nor the (*Duplicates) list has
  631. been modified.
  632. @retval EFI_OUT_OF_RESOURCES Memory allocation failed. Neither the
  633. (*FileList) nor the (*Duplicates) list has
  634. been modified.
  635. @retval EFI_SUCCESS Sorting successful, including the case when
  636. FileList is NULL on input.
  637. **/
  638. EFI_STATUS
  639. EFIAPI
  640. ShellSortFileList (
  641. IN OUT EFI_SHELL_FILE_INFO **FileList,
  642. OUT EFI_SHELL_FILE_INFO **Duplicates OPTIONAL,
  643. IN SHELL_SORT_FILE_LIST Order
  644. );
  645. #endif //_SHELL_COMMAND_LIB_