ShellProtocol.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938
  1. /** @file
  2. Member functions of EFI_SHELL_PROTOCOL and functions for creation,
  3. manipulation, and initialization of EFI_SHELL_PROTOCOL.
  4. (C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>
  5. Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
  6. SPDX-License-Identifier: BSD-2-Clause-Patent
  7. **/
  8. #ifndef _SHELL_PROTOCOL_HEADER_
  9. #define _SHELL_PROTOCOL_HEADER_
  10. #include "Shell.h"
  11. typedef struct {
  12. LIST_ENTRY Link;
  13. EFI_SHELL_PROTOCOL *Interface;
  14. EFI_HANDLE Handle;
  15. } SHELL_PROTOCOL_HANDLE_LIST;
  16. // flags values...
  17. #define SHELL_MAP_FLAGS_CONSIST BIT1
  18. /**
  19. Function to create and install on the current handle.
  20. Will overwrite any existing ShellProtocols in the system to be sure that
  21. the current shell is in control.
  22. This must be removed via calling CleanUpShellProtocol().
  23. @param[in, out] NewShell The pointer to the pointer to the structure
  24. to install.
  25. @retval EFI_SUCCESS The operation was successful.
  26. @return An error from LocateHandle, CreateEvent, or other core function.
  27. **/
  28. EFI_STATUS
  29. CreatePopulateInstallShellProtocol (
  30. IN OUT EFI_SHELL_PROTOCOL **NewShell
  31. );
  32. /**
  33. Opposite of CreatePopulateInstallShellProtocol.
  34. Free all memory and restore the system to the state it was in before calling
  35. CreatePopulateInstallShellProtocol.
  36. @param[in, out] NewShell The pointer to the new shell protocol structure.
  37. @retval EFI_SUCCESS The operation was successful.
  38. **/
  39. EFI_STATUS
  40. CleanUpShellProtocol (
  41. IN OUT EFI_SHELL_PROTOCOL *NewShell
  42. );
  43. /**
  44. Cleanup the shell environment.
  45. @param[in, out] NewShell The pointer to the new shell protocol structure.
  46. @retval EFI_SUCCESS The operation was successful.
  47. **/
  48. EFI_STATUS
  49. CleanUpShellEnvironment (
  50. IN OUT EFI_SHELL_PROTOCOL *NewShell
  51. );
  52. /**
  53. This function creates a mapping for a device path.
  54. @param DevicePath Points to the device path. If this is NULL and Mapping points to a valid mapping,
  55. then the mapping will be deleted.
  56. @param Mapping Points to the NULL-terminated mapping for the device path. Must end with a ':'
  57. @retval EFI_SUCCESS Mapping created or deleted successfully.
  58. @retval EFI_NO_MAPPING There is no handle that corresponds exactly to DevicePath. See the
  59. boot service function LocateDevicePath().
  60. @retval EFI_ACCESS_DENIED The mapping is a built-in alias.
  61. @retval EFI_INVALID_PARAMETER Mapping was NULL
  62. @retval EFI_INVALID_PARAMETER Mapping did not end with a ':'
  63. @retval EFI_INVALID_PARAMETER DevicePath was not pointing at a device that had a SIMPLE_FILE_SYSTEM_PROTOCOL installed.
  64. @retval EFI_NOT_FOUND There was no mapping found to delete
  65. @retval EFI_OUT_OF_RESOURCES Memory allocation failed
  66. **/
  67. EFI_STATUS
  68. EFIAPI
  69. EfiShellSetMap (
  70. IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL,
  71. IN CONST CHAR16 *Mapping
  72. );
  73. /**
  74. Gets the device path from the mapping.
  75. This function gets the device path associated with a mapping.
  76. @param Mapping A pointer to the mapping
  77. @retval !=NULL Pointer to the device path that corresponds to the
  78. device mapping. The returned pointer does not need
  79. to be freed.
  80. @retval NULL There is no device path associated with the
  81. specified mapping.
  82. **/
  83. CONST EFI_DEVICE_PATH_PROTOCOL *
  84. EFIAPI
  85. EfiShellGetDevicePathFromMap (
  86. IN CONST CHAR16 *Mapping
  87. );
  88. /**
  89. Gets the mapping that most closely matches the device path.
  90. This function gets the mapping which corresponds to the device path *DevicePath. If
  91. there is no exact match, then the mapping which most closely matches *DevicePath
  92. is returned, and *DevicePath is updated to point to the remaining portion of the
  93. device path. If there is an exact match, the mapping is returned and *DevicePath
  94. points to the end-of-device-path node.
  95. @param DevicePath On entry, points to a device path pointer. On
  96. exit, updates the pointer to point to the
  97. portion of the device path after the mapping.
  98. @retval NULL No mapping was found.
  99. @return !=NULL Pointer to NULL-terminated mapping. The buffer
  100. is callee allocated and should be freed by the caller.
  101. **/
  102. CONST CHAR16 *
  103. EFIAPI
  104. EfiShellGetMapFromDevicePath (
  105. IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
  106. );
  107. /**
  108. Converts a device path to a file system-style path.
  109. This function converts a device path to a file system path by replacing part, or all, of
  110. the device path with the file-system mapping. If there are more than one application
  111. file system mappings, the one that most closely matches Path will be used.
  112. @param Path The pointer to the device path
  113. @retval NULL the device path could not be found.
  114. @return all The pointer of the NULL-terminated file path. The path
  115. is callee-allocated and should be freed by the caller.
  116. **/
  117. CHAR16 *
  118. EFIAPI
  119. EfiShellGetFilePathFromDevicePath (
  120. IN CONST EFI_DEVICE_PATH_PROTOCOL *Path
  121. );
  122. /**
  123. Converts a file system style name to a device path.
  124. This function converts a file system style name to a device path, by replacing any
  125. mapping references to the associated device path.
  126. @param Path the pointer to the path
  127. @return all The pointer of the file path. The file path is callee
  128. allocated and should be freed by the caller.
  129. **/
  130. EFI_DEVICE_PATH_PROTOCOL *
  131. EFIAPI
  132. EfiShellGetDevicePathFromFilePath (
  133. IN CONST CHAR16 *Path
  134. );
  135. /**
  136. Gets the name of the device specified by the device handle.
  137. This function gets the user-readable name of the device specified by the device
  138. handle. If no user-readable name could be generated, then *BestDeviceName will be
  139. NULL and EFI_NOT_FOUND will be returned.
  140. If EFI_DEVICE_NAME_USE_COMPONENT_NAME is set, then the function will return the
  141. device's name using the EFI_COMPONENT_NAME2_PROTOCOL, if present on
  142. DeviceHandle.
  143. If EFI_DEVICE_NAME_USE_DEVICE_PATH is set, then the function will return the
  144. device's name using the EFI_DEVICE_PATH_PROTOCOL, if present on DeviceHandle.
  145. If both EFI_DEVICE_NAME_USE_COMPONENT_NAME and
  146. EFI_DEVICE_NAME_USE_DEVICE_PATH are set, then
  147. EFI_DEVICE_NAME_USE_COMPONENT_NAME will have higher priority.
  148. @param DeviceHandle The handle of the device.
  149. @param Flags Determines the possible sources of component names.
  150. Valid bits are:
  151. EFI_DEVICE_NAME_USE_COMPONENT_NAME
  152. EFI_DEVICE_NAME_USE_DEVICE_PATH
  153. @param Language A pointer to the language specified for the device
  154. name, in the same format as described in the UEFI
  155. specification, Appendix M
  156. @param BestDeviceName On return, points to the callee-allocated NULL-
  157. terminated name of the device. If no device name
  158. could be found, points to NULL. The name must be
  159. freed by the caller...
  160. @retval EFI_SUCCESS Get the name successfully.
  161. @retval EFI_NOT_FOUND Fail to get the device name.
  162. @retval EFI_INVALID_PARAMETER Flags did not have a valid bit set.
  163. @retval EFI_INVALID_PARAMETER BestDeviceName was NULL
  164. @retval EFI_INVALID_PARAMETER DeviceHandle was NULL
  165. **/
  166. EFI_STATUS
  167. EFIAPI
  168. EfiShellGetDeviceName (
  169. IN EFI_HANDLE DeviceHandle,
  170. IN EFI_SHELL_DEVICE_NAME_FLAGS Flags,
  171. IN CHAR8 *Language,
  172. OUT CHAR16 **BestDeviceName
  173. );
  174. /**
  175. Opens the root directory of a device on a handle
  176. This function opens the root directory of a device and returns a file handle to it.
  177. @param DeviceHandle The handle of the device that contains the volume.
  178. @param FileHandle On exit, points to the file handle corresponding to the root directory on the
  179. device.
  180. @retval EFI_SUCCESS Root opened successfully.
  181. @retval EFI_NOT_FOUND EFI_SIMPLE_FILE_SYSTEM could not be found or the root directory
  182. could not be opened.
  183. @retval EFI_VOLUME_CORRUPTED The data structures in the volume were corrupted.
  184. @retval EFI_DEVICE_ERROR The device had an error
  185. **/
  186. EFI_STATUS
  187. EFIAPI
  188. EfiShellOpenRootByHandle (
  189. IN EFI_HANDLE DeviceHandle,
  190. OUT SHELL_FILE_HANDLE *FileHandle
  191. );
  192. /**
  193. Opens the root directory of a device.
  194. This function opens the root directory of a device and returns a file handle to it.
  195. @param DevicePath Points to the device path corresponding to the device where the
  196. EFI_SIMPLE_FILE_SYSTEM_PROTOCOL is installed.
  197. @param FileHandle On exit, points to the file handle corresponding to the root directory on the
  198. device.
  199. @retval EFI_SUCCESS Root opened successfully.
  200. @retval EFI_NOT_FOUND EFI_SIMPLE_FILE_SYSTEM could not be found or the root directory
  201. could not be opened.
  202. @retval EFI_VOLUME_CORRUPTED The data structures in the volume were corrupted.
  203. @retval EFI_DEVICE_ERROR The device had an error
  204. **/
  205. EFI_STATUS
  206. EFIAPI
  207. EfiShellOpenRoot (
  208. IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
  209. OUT SHELL_FILE_HANDLE *FileHandle
  210. );
  211. /**
  212. Returns whether any script files are currently being processed.
  213. @retval TRUE There is at least one script file active.
  214. @retval FALSE No script files are active now.
  215. **/
  216. BOOLEAN
  217. EFIAPI
  218. EfiShellBatchIsActive (
  219. VOID
  220. );
  221. /**
  222. Worker function to open a file based on a device path. this will open the root
  223. of the volume and then traverse down to the file itself.
  224. @param DevicePath2 Device Path of the file
  225. @param FileHandle Pointer to the file upon a successful return
  226. @param OpenMode mode to open file in.
  227. @param Attributes the File Attributes to use when creating a new file
  228. @retval EFI_SUCCESS the file is open and FileHandle is valid
  229. @retval EFI_UNSUPPORTED the device path contained non-path elements
  230. @retval other an error occurred.
  231. **/
  232. EFI_STATUS
  233. InternalOpenFileDevicePath (
  234. IN OUT EFI_DEVICE_PATH_PROTOCOL *DevicePath2,
  235. OUT SHELL_FILE_HANDLE *FileHandle,
  236. IN UINT64 OpenMode,
  237. IN UINT64 Attributes OPTIONAL
  238. );
  239. /**
  240. Creates a file or directory by name.
  241. This function creates an empty new file or directory with the specified attributes and
  242. returns the new file's handle. If the file already exists and is read-only, then
  243. EFI_INVALID_PARAMETER will be returned.
  244. If the file already existed, it is truncated and its attributes updated. If the file is
  245. created successfully, the FileHandle is the file's handle, else, the FileHandle is NULL.
  246. If the file name begins with >v, then the file handle which is returned refers to the
  247. shell environment variable with the specified name. If the shell environment variable
  248. already exists and is non-volatile then EFI_INVALID_PARAMETER is returned.
  249. @param FileName Pointer to NULL-terminated file path
  250. @param FileAttribs The new file's attributes. the different attributes are
  251. described in EFI_FILE_PROTOCOL.Open().
  252. @param FileHandle On return, points to the created file handle or directory's handle
  253. @retval EFI_SUCCESS The file was opened. FileHandle points to the new file's handle.
  254. @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
  255. @retval EFI_UNSUPPORTED could not open the file path
  256. @retval EFI_NOT_FOUND the specified file could not be found on the devide, or could not
  257. file the file system on the device.
  258. @retval EFI_NO_MEDIA the device has no medium.
  259. @retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no
  260. longer supported.
  261. @retval EFI_DEVICE_ERROR The device reported an error or can't get the file path according
  262. the DirName.
  263. @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
  264. @retval EFI_WRITE_PROTECTED An attempt was made to create a file, or open a file for write
  265. when the media is write-protected.
  266. @retval EFI_ACCESS_DENIED The service denied access to the file.
  267. @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the file.
  268. @retval EFI_VOLUME_FULL The volume is full.
  269. **/
  270. EFI_STATUS
  271. EFIAPI
  272. EfiShellCreateFile (
  273. IN CONST CHAR16 *FileName,
  274. IN UINT64 FileAttribs,
  275. OUT SHELL_FILE_HANDLE *FileHandle
  276. );
  277. /**
  278. Opens a file or a directory by file name.
  279. This function opens the specified file in the specified OpenMode and returns a file
  280. handle.
  281. If the file name begins with >v, then the file handle which is returned refers to the
  282. shell environment variable with the specified name. If the shell environment variable
  283. exists, is non-volatile and the OpenMode indicates EFI_FILE_MODE_WRITE, then
  284. EFI_INVALID_PARAMETER is returned.
  285. If the file name is >i, then the file handle which is returned refers to the standard
  286. input. If the OpenMode indicates EFI_FILE_MODE_WRITE, then EFI_INVALID_PARAMETER
  287. is returned.
  288. If the file name is >o, then the file handle which is returned refers to the standard
  289. output. If the OpenMode indicates EFI_FILE_MODE_READ, then EFI_INVALID_PARAMETER
  290. is returned.
  291. If the file name is >e, then the file handle which is returned refers to the standard
  292. error. If the OpenMode indicates EFI_FILE_MODE_READ, then EFI_INVALID_PARAMETER
  293. is returned.
  294. If the file name is NUL, then the file handle that is returned refers to the standard NUL
  295. file. If the OpenMode indicates EFI_FILE_MODE_READ, then EFI_INVALID_PARAMETER is
  296. returned.
  297. If return EFI_SUCCESS, the FileHandle is the opened file's handle, else, the
  298. FileHandle is NULL.
  299. @param FileName Points to the NULL-terminated UCS-2 encoded file name.
  300. @param FileHandle On return, points to the file handle.
  301. @param OpenMode File open mode. Either EFI_FILE_MODE_READ or
  302. EFI_FILE_MODE_WRITE from section 12.4 of the UEFI
  303. Specification.
  304. @retval EFI_SUCCESS The file was opened. FileHandle has the opened file's handle.
  305. @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value. FileHandle is NULL.
  306. @retval EFI_UNSUPPORTED Could not open the file path. FileHandle is NULL.
  307. @retval EFI_NOT_FOUND The specified file could not be found on the device or the file
  308. system could not be found on the device. FileHandle is NULL.
  309. @retval EFI_NO_MEDIA The device has no medium. FileHandle is NULL.
  310. @retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no
  311. longer supported. FileHandle is NULL.
  312. @retval EFI_DEVICE_ERROR The device reported an error or can't get the file path according
  313. the FileName. FileHandle is NULL.
  314. @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. FileHandle is NULL.
  315. @retval EFI_WRITE_PROTECTED An attempt was made to create a file, or open a file for write
  316. when the media is write-protected. FileHandle is NULL.
  317. @retval EFI_ACCESS_DENIED The service denied access to the file. FileHandle is NULL.
  318. @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the file. FileHandle
  319. is NULL.
  320. @retval EFI_VOLUME_FULL The volume is full. FileHandle is NULL.
  321. **/
  322. EFI_STATUS
  323. EFIAPI
  324. EfiShellOpenFileByName (
  325. IN CONST CHAR16 *FileName,
  326. OUT SHELL_FILE_HANDLE *FileHandle,
  327. IN UINT64 OpenMode
  328. );
  329. /**
  330. Deletes the file specified by the file name.
  331. This function deletes a file.
  332. @param FileName Points to the NULL-terminated file name.
  333. @retval EFI_SUCCESS The file was closed and deleted, and the handle was closed.
  334. @retval EFI_WARN_DELETE_FAILURE The handle was closed but the file was not deleted.
  335. @sa EfiShellCreateFile
  336. @sa FileHandleDelete
  337. **/
  338. EFI_STATUS
  339. EFIAPI
  340. EfiShellDeleteFileByName (
  341. IN CONST CHAR16 *FileName
  342. );
  343. /**
  344. Disables the page break output mode.
  345. **/
  346. VOID
  347. EFIAPI
  348. EfiShellDisablePageBreak (
  349. VOID
  350. );
  351. /**
  352. Enables the page break output mode.
  353. **/
  354. VOID
  355. EFIAPI
  356. EfiShellEnablePageBreak (
  357. VOID
  358. );
  359. /**
  360. internal worker function to run a command via Device Path
  361. @param ParentImageHandle A handle of the image that is executing the specified
  362. command line.
  363. @param DevicePath device path of the file to execute
  364. @param CommandLine Points to the NULL-terminated UCS-2 encoded string
  365. containing the command line. If NULL then the command-
  366. line will be empty.
  367. @param Environment Points to a NULL-terminated array of environment
  368. variables with the format 'x=y', where x is the
  369. environment variable name and y is the value. If this
  370. is NULL, then the current shell environment is used.
  371. @param[out] StartImageStatus Returned status from gBS->StartImage.
  372. @retval EFI_SUCCESS The command executed successfully. The status code
  373. returned by the command is pointed to by StatusCode.
  374. @retval EFI_INVALID_PARAMETER The parameters are invalid.
  375. @retval EFI_OUT_OF_RESOURCES Out of resources.
  376. @retval EFI_UNSUPPORTED Nested shell invocations are not allowed.
  377. **/
  378. EFI_STATUS
  379. InternalShellExecuteDevicePath (
  380. IN CONST EFI_HANDLE *ParentImageHandle,
  381. IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
  382. IN CONST CHAR16 *CommandLine OPTIONAL,
  383. IN CONST CHAR16 **Environment OPTIONAL,
  384. OUT EFI_STATUS *StartImageStatus OPTIONAL
  385. );
  386. /**
  387. Execute the command line.
  388. This function creates a nested instance of the shell and executes the specified
  389. command (CommandLine) with the specified environment (Environment). Upon return,
  390. the status code returned by the specified command is placed in StatusCode.
  391. If Environment is NULL, then the current environment is used and all changes made
  392. by the commands executed will be reflected in the current environment. If the
  393. Environment is non-NULL, then the changes made will be discarded.
  394. The CommandLine is executed from the current working directory on the current
  395. device.
  396. @param ParentImageHandle A handle of the image that is executing the specified
  397. command line.
  398. @param CommandLine Points to the NULL-terminated UCS-2 encoded string
  399. containing the command line. If NULL then the command-
  400. line will be empty.
  401. @param Environment Points to a NULL-terminated array of environment
  402. variables with the format 'x=y', where x is the
  403. environment variable name and y is the value. If this
  404. is NULL, then the current shell environment is used.
  405. @param StatusCode Points to the status code returned by the command.
  406. @retval EFI_SUCCESS The command executed successfully. The status code
  407. returned by the command is pointed to by StatusCode.
  408. @retval EFI_INVALID_PARAMETER The parameters are invalid.
  409. @retval EFI_OUT_OF_RESOURCES Out of resources.
  410. @retval EFI_UNSUPPORTED Nested shell invocations are not allowed.
  411. **/
  412. EFI_STATUS
  413. EFIAPI
  414. EfiShellExecute (
  415. IN EFI_HANDLE *ParentImageHandle,
  416. IN CHAR16 *CommandLine OPTIONAL,
  417. IN CHAR16 **Environment OPTIONAL,
  418. OUT EFI_STATUS *StatusCode OPTIONAL
  419. );
  420. /**
  421. Utility cleanup function for EFI_SHELL_FILE_INFO objects.
  422. 1) frees all pointers (non-NULL)
  423. 2) Closes the SHELL_FILE_HANDLE
  424. @param FileListNode pointer to the list node to free
  425. **/
  426. VOID
  427. FreeShellFileInfoNode (
  428. IN EFI_SHELL_FILE_INFO *FileListNode
  429. );
  430. /**
  431. Frees the file list.
  432. This function cleans up the file list and any related data structures. It has no
  433. impact on the files themselves.
  434. @param FileList The file list to free. Type EFI_SHELL_FILE_INFO is
  435. defined in OpenFileList()
  436. @retval EFI_SUCCESS Free the file list successfully.
  437. @retval EFI_INVALID_PARAMETER FileList was NULL or *FileList was NULL;
  438. **/
  439. EFI_STATUS
  440. EFIAPI
  441. EfiShellFreeFileList (
  442. IN EFI_SHELL_FILE_INFO **FileList
  443. );
  444. /**
  445. Deletes the duplicate file names files in the given file list.
  446. This function deletes the reduplicate files in the given file list.
  447. @param FileList A pointer to the first entry in the file list.
  448. @retval EFI_SUCCESS Always success.
  449. @retval EFI_INVALID_PARAMETER FileList was NULL or *FileList was NULL;
  450. **/
  451. EFI_STATUS
  452. EFIAPI
  453. EfiShellRemoveDupInFileList (
  454. IN EFI_SHELL_FILE_INFO **FileList
  455. );
  456. /**
  457. Allocates and populates a EFI_SHELL_FILE_INFO structure. if any memory operation
  458. failed it will return NULL.
  459. @param[in] BasePath the Path to prepend onto filename for FullPath
  460. @param[in] Status Status member initial value.
  461. @param[in] FileName FileName member initial value.
  462. @param[in] Handle Handle member initial value.
  463. @param[in] Info Info struct to copy.
  464. **/
  465. EFI_SHELL_FILE_INFO *
  466. CreateAndPopulateShellFileInfo (
  467. IN CONST CHAR16 *BasePath,
  468. IN CONST EFI_STATUS Status,
  469. IN CONST CHAR16 *FileName,
  470. IN CONST SHELL_FILE_HANDLE Handle,
  471. IN CONST EFI_FILE_INFO *Info
  472. );
  473. /**
  474. Find all files in a specified directory.
  475. @param FileDirHandle Handle of the directory to search.
  476. @param FileList On return, points to the list of files in the directory
  477. or NULL if there are no files in the directory.
  478. @retval EFI_SUCCESS File information was returned successfully.
  479. @retval EFI_VOLUME_CORRUPTED The file system structures have been corrupted.
  480. @retval EFI_DEVICE_ERROR The device reported an error.
  481. @retval EFI_NO_MEDIA The device media is not present.
  482. @retval EFI_INVALID_PARAMETER The FileDirHandle was not a directory.
  483. **/
  484. EFI_STATUS
  485. EFIAPI
  486. EfiShellFindFilesInDir (
  487. IN SHELL_FILE_HANDLE FileDirHandle,
  488. OUT EFI_SHELL_FILE_INFO **FileList
  489. );
  490. /**
  491. Find files that match a specified pattern.
  492. This function searches for all files and directories that match the specified
  493. FilePattern. The FilePattern can contain wild-card characters. The resulting file
  494. information is placed in the file list FileList.
  495. Wildcards are processed
  496. according to the rules specified in UEFI Shell 2.0 spec section 3.7.1.
  497. The files in the file list are not opened. The OpenMode field is set to 0 and the FileInfo
  498. field is set to NULL.
  499. if *FileList is not NULL then it must be a pre-existing and properly initialized list.
  500. @param FilePattern Points to a NULL-terminated shell file path, including wildcards.
  501. @param FileList On return, points to the start of a file list containing the names
  502. of all matching files or else points to NULL if no matching files
  503. were found. only on a EFI_SUCCESS return will; this be non-NULL.
  504. @retval EFI_SUCCESS Files found. FileList is a valid list.
  505. @retval EFI_NOT_FOUND No files found.
  506. @retval EFI_NO_MEDIA The device has no media
  507. @retval EFI_DEVICE_ERROR The device reported an error
  508. @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted
  509. **/
  510. EFI_STATUS
  511. EFIAPI
  512. EfiShellFindFiles (
  513. IN CONST CHAR16 *FilePattern,
  514. OUT EFI_SHELL_FILE_INFO **FileList
  515. );
  516. /**
  517. Opens the files that match the path specified.
  518. This function opens all of the files specified by Path. Wildcards are processed
  519. according to the rules specified in UEFI Shell 2.0 spec section 3.7.1. Each
  520. matching file has an EFI_SHELL_FILE_INFO structure created in a linked list.
  521. @param Path A pointer to the path string.
  522. @param OpenMode Specifies the mode used to open each file, EFI_FILE_MODE_READ or
  523. EFI_FILE_MODE_WRITE.
  524. @param FileList Points to the start of a list of files opened.
  525. @retval EFI_SUCCESS Create the file list successfully.
  526. @return Others Can't create the file list.
  527. **/
  528. EFI_STATUS
  529. EFIAPI
  530. EfiShellOpenFileList (
  531. IN CHAR16 *Path,
  532. IN UINT64 OpenMode,
  533. IN OUT EFI_SHELL_FILE_INFO **FileList
  534. );
  535. /**
  536. Gets the environment variable.
  537. This function returns the current value of the specified environment variable.
  538. @param Name A pointer to the environment variable name
  539. @retval !=NULL The environment variable's value. The returned
  540. pointer does not need to be freed by the caller.
  541. @retval NULL The environment variable doesn't exist.
  542. **/
  543. CONST CHAR16 *
  544. EFIAPI
  545. EfiShellGetEnv (
  546. IN CONST CHAR16 *Name
  547. );
  548. /**
  549. Sets the environment variable.
  550. This function changes the current value of the specified environment variable. If the
  551. environment variable exists and the Value is an empty string, then the environment
  552. variable is deleted. If the environment variable exists and the Value is not an empty
  553. string, then the value of the environment variable is changed. If the environment
  554. variable does not exist and the Value is an empty string, there is no action. If the
  555. environment variable does not exist and the Value is a non-empty string, then the
  556. environment variable is created and assigned the specified value.
  557. For a description of volatile and non-volatile environment variables, see UEFI Shell
  558. 2.0 specification section 3.6.1.
  559. @param Name Points to the NULL-terminated environment variable name.
  560. @param Value Points to the NULL-terminated environment variable value. If the value is an
  561. empty string then the environment variable is deleted.
  562. @param Volatile Indicates whether the variable is non-volatile (FALSE) or volatile (TRUE).
  563. @retval EFI_SUCCESS The environment variable was successfully updated.
  564. **/
  565. EFI_STATUS
  566. EFIAPI
  567. EfiShellSetEnv (
  568. IN CONST CHAR16 *Name,
  569. IN CONST CHAR16 *Value,
  570. IN BOOLEAN Volatile
  571. );
  572. /**
  573. Returns the current directory on the specified device.
  574. If FileSystemMapping is NULL, it returns the current working directory. If the
  575. FileSystemMapping is not NULL, it returns the current directory associated with the
  576. FileSystemMapping. In both cases, the returned name includes the file system
  577. mapping (i.e. fs0:\current-dir).
  578. @param FileSystemMapping A pointer to the file system mapping. If NULL,
  579. then the current working directory is returned.
  580. @retval !=NULL The current directory.
  581. @retval NULL Current directory does not exist.
  582. **/
  583. CONST CHAR16 *
  584. EFIAPI
  585. EfiShellGetCurDir (
  586. IN CONST CHAR16 *FileSystemMapping OPTIONAL
  587. );
  588. /**
  589. Changes the current directory on the specified device.
  590. If the FileSystem is NULL, and the directory Dir does not contain a file system's
  591. mapped name, this function changes the current working directory. If FileSystem is
  592. NULL and the directory Dir contains a mapped name, then the current file system and
  593. the current directory on that file system are changed.
  594. If FileSystem is not NULL, and Dir is NULL, then this changes the current working file
  595. system.
  596. If FileSystem is not NULL and Dir is not NULL, then this function changes the current
  597. directory on the specified file system.
  598. If the current working directory or the current working file system is changed then the
  599. %cwd% environment variable will be updated
  600. @param FileSystem A pointer to the file system's mapped name. If NULL, then the current working
  601. directory is changed.
  602. @param Dir Points to the NULL-terminated directory on the device specified by FileSystem.
  603. @retval EFI_SUCCESS The operation was successful
  604. **/
  605. EFI_STATUS
  606. EFIAPI
  607. EfiShellSetCurDir (
  608. IN CONST CHAR16 *FileSystem OPTIONAL,
  609. IN CONST CHAR16 *Dir
  610. );
  611. /**
  612. Return help information about a specific command.
  613. This function returns the help information for the specified command. The help text
  614. can be internal to the shell or can be from a UEFI Shell manual page.
  615. If Sections is specified, then each section name listed will be compared in a casesensitive
  616. manner, to the section names described in Appendix B. If the section exists,
  617. it will be appended to the returned help text. If the section does not exist, no
  618. information will be returned. If Sections is NULL, then all help text information
  619. available will be returned.
  620. @param Command Points to the NULL-terminated UEFI Shell command name.
  621. @param Sections Points to the NULL-terminated comma-delimited
  622. section names to return. If NULL, then all
  623. sections will be returned.
  624. @param HelpText On return, points to a callee-allocated buffer
  625. containing all specified help text.
  626. @retval EFI_SUCCESS The help text was returned.
  627. @retval EFI_OUT_OF_RESOURCES The necessary buffer could not be allocated to hold the
  628. returned help text.
  629. @retval EFI_INVALID_PARAMETER HelpText is NULL
  630. @retval EFI_NOT_FOUND There is no help text available for Command.
  631. **/
  632. EFI_STATUS
  633. EFIAPI
  634. EfiShellGetHelpText (
  635. IN CONST CHAR16 *Command,
  636. IN CONST CHAR16 *Sections OPTIONAL,
  637. OUT CHAR16 **HelpText
  638. );
  639. /**
  640. Gets the enable status of the page break output mode.
  641. User can use this function to determine current page break mode.
  642. @retval TRUE The page break output mode is enabled
  643. @retval FALSE The page break output mode is disabled
  644. **/
  645. BOOLEAN
  646. EFIAPI
  647. EfiShellGetPageBreak (
  648. VOID
  649. );
  650. /**
  651. Judges whether the active shell is the root shell.
  652. This function makes the user to know that whether the active Shell is the root shell.
  653. @retval TRUE The active Shell is the root Shell.
  654. @retval FALSE The active Shell is NOT the root Shell.
  655. **/
  656. BOOLEAN
  657. EFIAPI
  658. EfiShellIsRootShell (
  659. VOID
  660. );
  661. /**
  662. This function returns the command associated with a alias or a list of all
  663. alias'.
  664. @param[in] Command Points to the NULL-terminated shell alias.
  665. If this parameter is NULL, then all
  666. aliases will be returned in ReturnedData.
  667. @param[out] Volatile upon return of a single command if TRUE indicates
  668. this is stored in a volatile fashion. FALSE otherwise.
  669. @return If Alias is not NULL, it will return a pointer to
  670. the NULL-terminated command for that alias.
  671. If Alias is NULL, ReturnedData points to a ';'
  672. delimited list of alias (e.g.
  673. ReturnedData = "dir;del;copy;mfp") that is NULL-terminated.
  674. @retval NULL an error occurred
  675. @retval NULL Alias was not a valid Alias
  676. **/
  677. CONST CHAR16 *
  678. EFIAPI
  679. EfiShellGetAlias (
  680. IN CONST CHAR16 *Command,
  681. OUT BOOLEAN *Volatile OPTIONAL
  682. );
  683. /**
  684. Changes a shell command alias.
  685. This function creates an alias for a shell command or if Alias is NULL it will delete an existing alias.
  686. this function does not check for built in alias'.
  687. @param[in] Command Points to the NULL-terminated shell command or existing alias.
  688. @param[in] Alias Points to the NULL-terminated alias for the shell command. If this is NULL, and
  689. Command refers to an alias, that alias will be deleted.
  690. @param[in] Volatile if TRUE the Alias being set will be stored in a volatile fashion. if FALSE the
  691. Alias being set will be stored in a non-volatile fashion.
  692. @retval EFI_SUCCESS Alias created or deleted successfully.
  693. @retval EFI_NOT_FOUND the Alias intended to be deleted was not found
  694. **/
  695. EFI_STATUS
  696. InternalSetAlias (
  697. IN CONST CHAR16 *Command,
  698. IN CONST CHAR16 *Alias OPTIONAL,
  699. IN BOOLEAN Volatile
  700. );
  701. /**
  702. Changes a shell command alias.
  703. This function creates an alias for a shell command or if Alias is NULL it will delete an existing alias.
  704. @param[in] Command Points to the NULL-terminated shell command or existing alias.
  705. @param[in] Alias Points to the NULL-terminated alias for the shell command. If this is NULL, and
  706. Command refers to an alias, that alias will be deleted.
  707. @param[in] Replace If TRUE and the alias already exists, then the existing alias will be replaced. If
  708. FALSE and the alias already exists, then the existing alias is unchanged and
  709. EFI_ACCESS_DENIED is returned.
  710. @param[in] Volatile if TRUE the Alias being set will be stored in a volatile fashion. if FALSE the
  711. Alias being set will be stored in a non-volatile fashion.
  712. @retval EFI_SUCCESS Alias created or deleted successfully.
  713. @retval EFI_NOT_FOUND the Alias intended to be deleted was not found
  714. @retval EFI_ACCESS_DENIED The alias is a built-in alias or already existed and Replace was set to
  715. FALSE.
  716. **/
  717. EFI_STATUS
  718. EFIAPI
  719. EfiShellSetAlias (
  720. IN CONST CHAR16 *Command,
  721. IN CONST CHAR16 *Alias OPTIONAL,
  722. IN BOOLEAN Replace,
  723. IN BOOLEAN Volatile
  724. );
  725. /**
  726. Utility cleanup function for EFI_SHELL_FILE_INFO objects.
  727. 1) frees all pointers (non-NULL)
  728. 2) Closes the SHELL_FILE_HANDLE
  729. @param FileListNode pointer to the list node to free
  730. **/
  731. VOID
  732. InternalFreeShellFileInfoNode (
  733. IN EFI_SHELL_FILE_INFO *FileListNode
  734. );
  735. /**
  736. Internal variable setting function. Allows for setting of the read only variables.
  737. @param Name Points to the NULL-terminated environment variable name.
  738. @param Value Points to the NULL-terminated environment variable value. If the value is an
  739. empty string then the environment variable is deleted.
  740. @param Volatile Indicates whether the variable is non-volatile (FALSE) or volatile (TRUE).
  741. @retval EFI_SUCCESS The environment variable was successfully updated.
  742. **/
  743. EFI_STATUS
  744. InternalEfiShellSetEnv (
  745. IN CONST CHAR16 *Name,
  746. IN CONST CHAR16 *Value,
  747. IN BOOLEAN Volatile
  748. );
  749. /**
  750. Function to start monitoring for CTRL-C using SimpleTextInputEx. This
  751. feature's enabled state was not known when the shell initially launched.
  752. @retval EFI_SUCCESS The feature is enabled.
  753. @retval EFI_OUT_OF_RESOURCES There is not enough memory available.
  754. **/
  755. EFI_STATUS
  756. InernalEfiShellStartMonitor (
  757. VOID
  758. );
  759. /**
  760. Notification function for keystrokes.
  761. @param[in] KeyData The key that was pressed.
  762. @retval EFI_SUCCESS The operation was successful.
  763. **/
  764. EFI_STATUS
  765. EFIAPI
  766. NotificationFunction (
  767. IN EFI_KEY_DATA *KeyData
  768. );
  769. #endif //_SHELL_PROTOCOL_HEADER_