ShellLib.h 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431
  1. /** @file
  2. Provides interface to shell functionality for shell commands and applications.
  3. Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
  4. Copyright 2018 Dell Technologies.<BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #ifndef __SHELL_LIB__
  8. #define __SHELL_LIB__
  9. #include <Uefi.h>
  10. #include <Guid/FileInfo.h>
  11. #include <Protocol/SimpleFileSystem.h>
  12. #include <Protocol/LoadedImage.h>
  13. #include <Protocol/EfiShellInterface.h>
  14. #include <Protocol/EfiShellEnvironment2.h>
  15. #include <Protocol/Shell.h>
  16. #include <Protocol/ShellParameters.h>
  17. #define SHELL_FREE_NON_NULL(Pointer) \
  18. do { \
  19. if ((Pointer) != NULL) { \
  20. FreePool((Pointer)); \
  21. (Pointer) = NULL; \
  22. } \
  23. } while(FALSE)
  24. extern EFI_SHELL_PARAMETERS_PROTOCOL *gEfiShellParametersProtocol;
  25. extern EFI_SHELL_PROTOCOL *gEfiShellProtocol;
  26. /**
  27. Return a clean, fully-qualified version of an input path. If the return value
  28. is non-NULL the caller must free the memory when it is no longer needed.
  29. If asserts are disabled, and if the input parameter is NULL, NULL is returned.
  30. If there is not enough memory available to create the fully-qualified path or
  31. a copy of the input path, NULL is returned.
  32. If there is no working directory, a clean copy of Path is returned.
  33. Otherwise, the current file system or working directory (as appropriate) is
  34. prepended to Path and the resulting path is cleaned and returned.
  35. NOTE: If the input path is an empty string, then the current working directory
  36. (if it exists) is returned. In other words, an empty input path is treated
  37. exactly the same as ".".
  38. @param[in] Path A pointer to some file or directory path.
  39. @retval NULL The input path is NULL or out of memory.
  40. @retval non-NULL A pointer to a clean, fully-qualified version of Path.
  41. If there is no working directory, then a pointer to a
  42. clean, but not necessarily fully-qualified version of
  43. Path. The caller must free this memory when it is no
  44. longer needed.
  45. **/
  46. CHAR16 *
  47. EFIAPI
  48. FullyQualifyPath (
  49. IN CONST CHAR16 *Path
  50. );
  51. /**
  52. This function will retrieve the information about the file for the handle
  53. specified and store it in allocated pool memory.
  54. This function allocates a buffer to store the file's information. It is the
  55. caller's responsibility to free the buffer.
  56. @param[in] FileHandle The file handle of the file for which information is
  57. being requested.
  58. @retval NULL Information could not be retrieved.
  59. @return The information about the file.
  60. **/
  61. EFI_FILE_INFO *
  62. EFIAPI
  63. ShellGetFileInfo (
  64. IN SHELL_FILE_HANDLE FileHandle
  65. );
  66. /**
  67. This function sets the information about the file for the opened handle
  68. specified.
  69. @param[in] FileHandle The file handle of the file for which information
  70. is being set.
  71. @param[in] FileInfo The information to set.
  72. @retval EFI_SUCCESS The information was set.
  73. @retval EFI_INVALID_PARAMETER A parameter was out of range or invalid.
  74. @retval EFI_UNSUPPORTED The FileHandle does not support FileInfo.
  75. @retval EFI_NO_MEDIA The device has no medium.
  76. @retval EFI_DEVICE_ERROR The device reported an error.
  77. @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
  78. @retval EFI_WRITE_PROTECTED The file or medium is write protected.
  79. @retval EFI_ACCESS_DENIED The file was opened read only.
  80. @retval EFI_VOLUME_FULL The volume is full.
  81. **/
  82. EFI_STATUS
  83. EFIAPI
  84. ShellSetFileInfo (
  85. IN SHELL_FILE_HANDLE FileHandle,
  86. IN EFI_FILE_INFO *FileInfo
  87. );
  88. /**
  89. This function will open a file or directory referenced by DevicePath.
  90. This function opens a file with the open mode according to the file path. The
  91. Attributes is valid only for EFI_FILE_MODE_CREATE.
  92. @param[in, out] FilePath On input, the device path to the file. On output,
  93. the remaining device path.
  94. @param[out] FileHandle Pointer to the file handle.
  95. @param[in] OpenMode The mode to open the file with.
  96. @param[in] Attributes The file's file attributes.
  97. @retval EFI_SUCCESS The information was set.
  98. @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
  99. @retval EFI_UNSUPPORTED Could not open the file path.
  100. @retval EFI_NOT_FOUND The specified file could not be found on the
  101. device or the file system could not be found on
  102. the device.
  103. @retval EFI_NO_MEDIA The device has no medium.
  104. @retval EFI_MEDIA_CHANGED The device has a different medium in it or the
  105. medium is no longer supported.
  106. @retval EFI_DEVICE_ERROR The device reported an error.
  107. @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
  108. @retval EFI_WRITE_PROTECTED The file or medium is write protected.
  109. @retval EFI_ACCESS_DENIED The file was opened read only.
  110. @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the
  111. file.
  112. @retval EFI_VOLUME_FULL The volume is full.
  113. **/
  114. EFI_STATUS
  115. EFIAPI
  116. ShellOpenFileByDevicePath (
  117. IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath,
  118. OUT SHELL_FILE_HANDLE *FileHandle,
  119. IN UINT64 OpenMode,
  120. IN UINT64 Attributes
  121. );
  122. /**
  123. This function will open a file or directory referenced by filename.
  124. If return is EFI_SUCCESS, the Filehandle is the opened file's handle;
  125. otherwise, the Filehandle is NULL. Attributes is valid only for
  126. EFI_FILE_MODE_CREATE.
  127. @param[in] FileName The pointer to file name.
  128. @param[out] FileHandle The pointer to the file handle.
  129. @param[in] OpenMode The mode to open the file with.
  130. @param[in] Attributes The file's file attributes.
  131. @retval EFI_SUCCESS The information was set.
  132. @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
  133. @retval EFI_UNSUPPORTED Could not open the file path.
  134. @retval EFI_NOT_FOUND The specified file could not be found on the
  135. device or the file system could not be found
  136. on the device.
  137. @retval EFI_NO_MEDIA The device has no medium.
  138. @retval EFI_MEDIA_CHANGED The device has a different medium in it or the
  139. medium is no longer supported.
  140. @retval EFI_DEVICE_ERROR The device reported an error.
  141. @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
  142. @retval EFI_WRITE_PROTECTED The file or medium is write protected.
  143. @retval EFI_ACCESS_DENIED The file was opened read only.
  144. @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the
  145. file.
  146. @retval EFI_VOLUME_FULL The volume is full.
  147. **/
  148. EFI_STATUS
  149. EFIAPI
  150. ShellOpenFileByName (
  151. IN CONST CHAR16 *FileName,
  152. OUT SHELL_FILE_HANDLE *FileHandle,
  153. IN UINT64 OpenMode,
  154. IN UINT64 Attributes
  155. );
  156. /**
  157. This function creates a directory.
  158. If return is EFI_SUCCESS, the Filehandle is the opened directory's handle;
  159. otherwise, the Filehandle is NULL. If the directory already existed, this
  160. function opens the existing directory.
  161. @param[in] DirectoryName The pointer to Directory name.
  162. @param[out] FileHandle The pointer to the file handle.
  163. @retval EFI_SUCCESS The information was set.
  164. @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
  165. @retval EFI_UNSUPPORTED Could not open the file path.
  166. @retval EFI_NOT_FOUND The specified file could not be found on the
  167. device, or the file system could not be found
  168. on the device.
  169. @retval EFI_NO_MEDIA The device has no medium.
  170. @retval EFI_MEDIA_CHANGED The device has a different medium in it or the
  171. medium is no longer supported.
  172. @retval EFI_DEVICE_ERROR The device reported an error.
  173. @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
  174. @retval EFI_WRITE_PROTECTED The file or medium is write protected.
  175. @retval EFI_ACCESS_DENIED The file was opened read only.
  176. @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the
  177. file.
  178. @retval EFI_VOLUME_FULL The volume is full.
  179. **/
  180. EFI_STATUS
  181. EFIAPI
  182. ShellCreateDirectory (
  183. IN CONST CHAR16 *DirectoryName,
  184. OUT SHELL_FILE_HANDLE *FileHandle
  185. );
  186. /**
  187. This function reads information from an opened file.
  188. If FileHandle is not a directory, the function reads the requested number of
  189. bytes from the file at the file's current position and returns them in Buffer.
  190. If the read goes beyond the end of the file, the read length is truncated to the
  191. end of the file. The file's current position is increased by the number of bytes
  192. returned. If FileHandle is a directory, the function reads the directory entry
  193. at the file's current position and returns the entry in Buffer. If the Buffer
  194. is not large enough to hold the current directory entry, then
  195. EFI_BUFFER_TOO_SMALL is returned and the current file position is not updated.
  196. BufferSize is set to be the size of the buffer needed to read the entry. On
  197. success, the current position is updated to the next directory entry. If there
  198. are no more directory entries, the read returns a zero-length buffer.
  199. EFI_FILE_INFO is the structure returned as the directory entry.
  200. @param[in] FileHandle The opened file handle.
  201. @param[in, out] ReadSize On input the size of buffer in bytes. On return
  202. the number of bytes written.
  203. @param[out] Buffer The buffer to put read data into.
  204. @retval EFI_SUCCESS Data was read.
  205. @retval EFI_NO_MEDIA The device has no media.
  206. @retval EFI_DEVICE_ERROR The device reported an error.
  207. @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
  208. @retval EFI_BUFFER_TO_SMALL Buffer is too small. ReadSize contains required
  209. size.
  210. **/
  211. EFI_STATUS
  212. EFIAPI
  213. ShellReadFile (
  214. IN SHELL_FILE_HANDLE FileHandle,
  215. IN OUT UINTN *ReadSize,
  216. OUT VOID *Buffer
  217. );
  218. /**
  219. Write data to a file.
  220. This function writes the specified number of bytes to the file at the current
  221. file position. The current file position is advanced the actual number of bytes
  222. written, which is returned in BufferSize. Partial writes only occur when there
  223. has been a data error during the write attempt (such as "volume space full").
  224. The file is automatically grown to hold the data if required. Direct writes to
  225. opened directories are not supported.
  226. @param[in] FileHandle The opened file for writing.
  227. @param[in, out] BufferSize On input the number of bytes in Buffer. On output
  228. the number of bytes written.
  229. @param[in] Buffer The buffer containing data to write is stored.
  230. @retval EFI_SUCCESS Data was written.
  231. @retval EFI_UNSUPPORTED Writes to an open directory are not supported.
  232. @retval EFI_NO_MEDIA The device has no media.
  233. @retval EFI_DEVICE_ERROR The device reported an error.
  234. @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
  235. @retval EFI_WRITE_PROTECTED The device is write-protected.
  236. @retval EFI_ACCESS_DENIED The file was open for read only.
  237. @retval EFI_VOLUME_FULL The volume is full.
  238. **/
  239. EFI_STATUS
  240. EFIAPI
  241. ShellWriteFile (
  242. IN SHELL_FILE_HANDLE FileHandle,
  243. IN OUT UINTN *BufferSize,
  244. IN VOID *Buffer
  245. );
  246. /**
  247. Close an open file handle.
  248. This function closes a specified file handle. All "dirty" cached file data is
  249. flushed to the device, and the file is closed. In all cases the handle is
  250. closed.
  251. @param[in] FileHandle The file handle to close.
  252. @retval EFI_SUCCESS The file handle was closed sucessfully.
  253. @retval INVALID_PARAMETER One of the parameters has an invalid value.
  254. **/
  255. EFI_STATUS
  256. EFIAPI
  257. ShellCloseFile (
  258. IN SHELL_FILE_HANDLE *FileHandle
  259. );
  260. /**
  261. Delete a file and close the handle
  262. This function closes and deletes a file. In all cases the file handle is closed.
  263. If the file cannot be deleted, the warning code EFI_WARN_DELETE_FAILURE is
  264. returned, but the handle is still closed.
  265. @param[in] FileHandle The file handle to delete.
  266. @retval EFI_SUCCESS The file was closed sucessfully.
  267. @retval EFI_WARN_DELETE_FAILURE The handle was closed, but the file was not
  268. deleted.
  269. @retval INVALID_PARAMETER One of the parameters has an invalid value.
  270. **/
  271. EFI_STATUS
  272. EFIAPI
  273. ShellDeleteFile (
  274. IN SHELL_FILE_HANDLE *FileHandle
  275. );
  276. /**
  277. Set the current position in a file.
  278. This function sets the current file position for the handle to the position
  279. supplied. With the exception of seeking to position 0xFFFFFFFFFFFFFFFF, only
  280. absolute positioning is supported, and moving past the end of the file is
  281. allowed (a subsequent write would grow the file). Moving to position
  282. 0xFFFFFFFFFFFFFFFF causes the current position to be set to the end of the file.
  283. If FileHandle is a directory, the only position that may be set is zero. This
  284. has the effect of starting the read process of the directory entries over.
  285. @param[in] FileHandle The file handle on which the position is being set.
  286. @param[in] Position The byte position from the begining of the file.
  287. @retval EFI_SUCCESS Operation completed sucessfully.
  288. @retval EFI_UNSUPPORTED The seek request for non-zero is not valid on
  289. directories.
  290. @retval INVALID_PARAMETER One of the parameters has an invalid value.
  291. **/
  292. EFI_STATUS
  293. EFIAPI
  294. ShellSetFilePosition (
  295. IN SHELL_FILE_HANDLE FileHandle,
  296. IN UINT64 Position
  297. );
  298. /**
  299. Gets a file's current position
  300. This function retrieves the current file position for the file handle. For
  301. directories, the current file position has no meaning outside of the file
  302. system driver and as such the operation is not supported. An error is returned
  303. if FileHandle is a directory.
  304. @param[in] FileHandle The open file handle on which to get the position.
  305. @param[out] Position The byte position from the begining of the file.
  306. @retval EFI_SUCCESS The operation completed sucessfully.
  307. @retval INVALID_PARAMETER One of the parameters has an invalid value.
  308. @retval EFI_UNSUPPORTED The request is not valid on directories.
  309. **/
  310. EFI_STATUS
  311. EFIAPI
  312. ShellGetFilePosition (
  313. IN SHELL_FILE_HANDLE FileHandle,
  314. OUT UINT64 *Position
  315. );
  316. /**
  317. Flushes data on a file
  318. This function flushes all modified data associated with a file to a device.
  319. @param[in] FileHandle The file handle on which to flush data.
  320. @retval EFI_SUCCESS The data was flushed.
  321. @retval EFI_NO_MEDIA The device has no media.
  322. @retval EFI_DEVICE_ERROR The device reported an error.
  323. @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
  324. @retval EFI_WRITE_PROTECTED The file or medium is write protected.
  325. @retval EFI_ACCESS_DENIED The file was opened for read only.
  326. **/
  327. EFI_STATUS
  328. EFIAPI
  329. ShellFlushFile (
  330. IN SHELL_FILE_HANDLE FileHandle
  331. );
  332. /** Retrieve first entry from a directory.
  333. This function takes an open directory handle and gets information from the
  334. first entry in the directory. A buffer is allocated to contain
  335. the information and a pointer to the buffer is returned in *Buffer. The
  336. caller can use ShellFindNextFile() to get subsequent directory entries.
  337. The buffer will be freed by ShellFindNextFile() when the last directory
  338. entry is read. Otherwise, the caller must free the buffer, using FreePool,
  339. when finished with it.
  340. @param[in] DirHandle The file handle of the directory to search.
  341. @param[out] Buffer The pointer to the buffer for the file's information.
  342. @retval EFI_SUCCESS Found the first file.
  343. @retval EFI_NOT_FOUND Cannot find the directory.
  344. @retval EFI_NO_MEDIA The device has no media.
  345. @retval EFI_DEVICE_ERROR The device reported an error.
  346. @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
  347. @return Others Status of ShellGetFileInfo, ShellSetFilePosition,
  348. or ShellReadFile.
  349. @sa ShellReadFile
  350. **/
  351. EFI_STATUS
  352. EFIAPI
  353. ShellFindFirstFile (
  354. IN SHELL_FILE_HANDLE DirHandle,
  355. OUT EFI_FILE_INFO **Buffer
  356. );
  357. /** Retrieve next entries from a directory.
  358. To use this function, the caller must first call the ShellFindFirstFile()
  359. function to get the first directory entry. Subsequent directory entries are
  360. retrieved by using the ShellFindNextFile() function. This function can
  361. be called several times to get each entry from the directory. If the call of
  362. ShellFindNextFile() retrieved the last directory entry, the next call of
  363. this function will set *NoFile to TRUE and free the buffer.
  364. @param[in] DirHandle The file handle of the directory.
  365. @param[in, out] Buffer The pointer to buffer for file's information.
  366. @param[in, out] NoFile The pointer to boolean when last file is found.
  367. @retval EFI_SUCCESS Found the next file.
  368. @retval EFI_NO_MEDIA The device has no media.
  369. @retval EFI_DEVICE_ERROR The device reported an error.
  370. @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
  371. @sa ShellReadFile
  372. **/
  373. EFI_STATUS
  374. EFIAPI
  375. ShellFindNextFile (
  376. IN SHELL_FILE_HANDLE DirHandle,
  377. IN OUT EFI_FILE_INFO *Buffer,
  378. IN OUT BOOLEAN *NoFile
  379. );
  380. /**
  381. Retrieve the size of a file.
  382. This function extracts the file size info from the FileHandle's EFI_FILE_INFO
  383. data.
  384. @param[in] FileHandle The file handle from which size is retrieved.
  385. @param[out] Size The pointer to size.
  386. @retval EFI_SUCCESS The operation was completed sucessfully.
  387. @retval EFI_DEVICE_ERROR Cannot access the file.
  388. **/
  389. EFI_STATUS
  390. EFIAPI
  391. ShellGetFileSize (
  392. IN SHELL_FILE_HANDLE FileHandle,
  393. OUT UINT64 *Size
  394. );
  395. /**
  396. Retrieves the status of the break execution flag
  397. This function is useful to check whether the application is being asked to halt by the shell.
  398. @retval TRUE The execution break is enabled.
  399. @retval FALSE The execution break is not enabled.
  400. **/
  401. BOOLEAN
  402. EFIAPI
  403. ShellGetExecutionBreakFlag (
  404. VOID
  405. );
  406. /**
  407. Return the value of an environment variable.
  408. This function gets the value of the environment variable set by the
  409. ShellSetEnvironmentVariable function.
  410. @param[in] EnvKey The key name of the environment variable.
  411. @retval NULL The named environment variable does not exist.
  412. @return != NULL The pointer to the value of the environment variable.
  413. **/
  414. CONST CHAR16 *
  415. EFIAPI
  416. ShellGetEnvironmentVariable (
  417. IN CONST CHAR16 *EnvKey
  418. );
  419. /**
  420. Set the value of an environment variable.
  421. This function changes the current value of the specified environment variable. If the
  422. environment variable exists and the Value is an empty string, then the environment
  423. variable is deleted. If the environment variable exists and the Value is not an empty
  424. string, then the value of the environment variable is changed. If the environment
  425. variable does not exist and the Value is an empty string, there is no action. If the
  426. environment variable does not exist and the Value is a non-empty string, then the
  427. environment variable is created and assigned the specified value.
  428. This is not supported pre-UEFI Shell 2.0.
  429. @param[in] EnvKey The key name of the environment variable.
  430. @param[in] EnvVal The Value of the environment variable
  431. @param[in] Volatile Indicates whether the variable is non-volatile (FALSE) or volatile (TRUE).
  432. @retval EFI_SUCCESS The operation completed sucessfully
  433. @retval EFI_UNSUPPORTED This operation is not allowed in pre-UEFI 2.0 Shell environments.
  434. **/
  435. EFI_STATUS
  436. EFIAPI
  437. ShellSetEnvironmentVariable (
  438. IN CONST CHAR16 *EnvKey,
  439. IN CONST CHAR16 *EnvVal,
  440. IN BOOLEAN Volatile
  441. );
  442. /**
  443. Cause the shell to parse and execute a command line.
  444. This function creates a nested instance of the shell and executes the specified
  445. command (CommandLine) with the specified environment (Environment). Upon return,
  446. the status code returned by the specified command is placed in StatusCode.
  447. If Environment is NULL, then the current environment is used and all changes made
  448. by the commands executed will be reflected in the current environment. If the
  449. Environment is non-NULL, then the changes made will be discarded.
  450. The CommandLine is executed from the current working directory on the current
  451. device.
  452. The EnvironmentVariables and Status parameters are ignored in a pre-UEFI Shell 2.0
  453. environment. The values pointed to by the parameters will be unchanged by the
  454. ShellExecute() function. The Output parameter has no effect in a
  455. UEFI Shell 2.0 environment.
  456. @param[in] ParentHandle The parent image starting the operation.
  457. @param[in] CommandLine The pointer to a NULL terminated command line.
  458. @param[in] Output True to display debug output. False to hide it.
  459. @param[in] EnvironmentVariables Optional pointer to array of environment variables
  460. in the form "x=y". If NULL, the current set is used.
  461. @param[out] Status The status of the run command line.
  462. @retval EFI_SUCCESS The operation completed sucessfully. Status
  463. contains the status code returned.
  464. @retval EFI_INVALID_PARAMETER A parameter contains an invalid value.
  465. @retval EFI_OUT_OF_RESOURCES Out of resources.
  466. @retval EFI_UNSUPPORTED The operation is not allowed.
  467. **/
  468. EFI_STATUS
  469. EFIAPI
  470. ShellExecute (
  471. IN EFI_HANDLE *ParentHandle,
  472. IN CHAR16 *CommandLine,
  473. IN BOOLEAN Output,
  474. IN CHAR16 **EnvironmentVariables,
  475. OUT EFI_STATUS *Status
  476. );
  477. /**
  478. Retreives the current directory path.
  479. If the DeviceName is NULL, it returns the current device's current directory
  480. name. If the DeviceName is not NULL, it returns the current directory name
  481. on specified drive.
  482. Note that the current directory string should exclude the tailing backslash character.
  483. @param[in] DeviceName The name of the file system to get directory on.
  484. @retval NULL The directory does not exist.
  485. @retval != NULL The directory.
  486. **/
  487. CONST CHAR16 *
  488. EFIAPI
  489. ShellGetCurrentDir (
  490. IN CHAR16 *CONST DeviceName OPTIONAL
  491. );
  492. /**
  493. Sets (enabled or disabled) the page break mode.
  494. When page break mode is enabled the screen will stop scrolling
  495. and wait for operator input before scrolling a subsequent screen.
  496. @param[in] CurrentState TRUE to enable and FALSE to disable.
  497. **/
  498. VOID
  499. EFIAPI
  500. ShellSetPageBreakMode (
  501. IN BOOLEAN CurrentState
  502. );
  503. /**
  504. Opens a group of files based on a path.
  505. This function uses the Arg to open all the matching files. Each matched
  506. file has a SHELL_FILE_ARG structure to record the file information. These
  507. structures are placed on the list ListHead. Users can get the SHELL_FILE_ARG
  508. structures from ListHead to access each file. This function supports wildcards
  509. and will process '?' and '*' as such. The list must be freed with a call to
  510. ShellCloseFileMetaArg().
  511. If you are NOT appending to an existing list *ListHead must be NULL. If
  512. *ListHead is NULL then it must be callee freed.
  513. @param[in] Arg The pointer to path string.
  514. @param[in] OpenMode Mode to open files with.
  515. @param[in, out] ListHead Head of linked list of results.
  516. @retval EFI_SUCCESS The operation was sucessful and the list head
  517. contains the list of opened files.
  518. @retval != EFI_SUCCESS The operation failed.
  519. @sa InternalShellConvertFileListType
  520. **/
  521. EFI_STATUS
  522. EFIAPI
  523. ShellOpenFileMetaArg (
  524. IN CHAR16 *Arg,
  525. IN UINT64 OpenMode,
  526. IN OUT EFI_SHELL_FILE_INFO **ListHead
  527. );
  528. /**
  529. Free the linked list returned from ShellOpenFileMetaArg.
  530. @param[in, out] ListHead The pointer to free.
  531. @retval EFI_SUCCESS The operation was sucessful.
  532. @retval EFI_INVALID_PARAMETER A parameter was invalid.
  533. **/
  534. EFI_STATUS
  535. EFIAPI
  536. ShellCloseFileMetaArg (
  537. IN OUT EFI_SHELL_FILE_INFO **ListHead
  538. );
  539. /**
  540. Find a file by searching the CWD and then the path.
  541. If FileName is NULL, then ASSERT.
  542. If the return value is not NULL then the memory must be caller freed.
  543. @param[in] FileName Filename string.
  544. @retval NULL The file was not found.
  545. @retval !NULL The path to the file.
  546. **/
  547. CHAR16 *
  548. EFIAPI
  549. ShellFindFilePath (
  550. IN CONST CHAR16 *FileName
  551. );
  552. /**
  553. Find a file by searching the CWD and then the path with a variable set of file
  554. extensions. If the file is not found it will append each extension in the list
  555. in the order provided and return the first one that is successful.
  556. If FileName is NULL, then ASSERT.
  557. If FileExtension is NULL, then the behavior is identical to ShellFindFilePath.
  558. If the return value is not NULL then the memory must be caller freed.
  559. @param[in] FileName The filename string.
  560. @param[in] FileExtension Semicolon delimited list of possible extensions.
  561. @retval NULL The file was not found.
  562. @retval !NULL The path to the file.
  563. **/
  564. CHAR16 *
  565. EFIAPI
  566. ShellFindFilePathEx (
  567. IN CONST CHAR16 *FileName,
  568. IN CONST CHAR16 *FileExtension
  569. );
  570. typedef enum {
  571. TypeFlag = 0, ///< A flag that is present or not present only (IE "-a").
  572. TypeValue, ///< A flag that has some data following it with a space (IE "-a 1").
  573. TypePosition, ///< Some data that did not follow a parameter (IE "filename.txt").
  574. TypeStart, ///< A flag that has variable value appended to the end (IE "-ad", "-afd", "-adf", etc...).
  575. TypeDoubleValue, ///< A flag that has 2 space seperated value data following it (IE "-a 1 2").
  576. TypeMaxValue, ///< A flag followed by all the command line data before the next flag.
  577. TypeTimeValue, ///< A flag that has a time value following it (IE "-a -5:00").
  578. TypeMax,
  579. } SHELL_PARAM_TYPE;
  580. typedef struct {
  581. CHAR16 *Name;
  582. SHELL_PARAM_TYPE Type;
  583. } SHELL_PARAM_ITEM;
  584. /// Helper structure for no parameters (besides -? and -b)
  585. extern SHELL_PARAM_ITEM EmptyParamList[];
  586. /// Helper structure for -sfo only (besides -? and -b)
  587. extern SHELL_PARAM_ITEM SfoParamList[];
  588. /**
  589. Checks the command line arguments passed against the list of valid ones.
  590. Optionally removes NULL values first.
  591. If no initialization is required, then return RETURN_SUCCESS.
  592. @param[in] CheckList The pointer to list of parameters to check.
  593. @param[out] CheckPackage The package of checked values.
  594. @param[out] ProblemParam Optional pointer to pointer to unicode string for
  595. the paramater that caused failure.
  596. @param[in] AutoPageBreak Will automatically set PageBreakEnabled.
  597. @param[in] AlwaysAllowNumbers Will never fail for number based flags.
  598. @retval EFI_SUCCESS The operation completed sucessfully.
  599. @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
  600. @retval EFI_INVALID_PARAMETER A parameter was invalid.
  601. @retval EFI_VOLUME_CORRUPTED The command line was corrupt.
  602. @retval EFI_DEVICE_ERROR The commands contained 2 opposing arguments. One
  603. of the command line arguments was returned in
  604. ProblemParam if provided.
  605. @retval EFI_NOT_FOUND A argument required a value that was missing.
  606. The invalid command line argument was returned in
  607. ProblemParam if provided.
  608. **/
  609. EFI_STATUS
  610. EFIAPI
  611. ShellCommandLineParseEx (
  612. IN CONST SHELL_PARAM_ITEM *CheckList,
  613. OUT LIST_ENTRY **CheckPackage,
  614. OUT CHAR16 **ProblemParam OPTIONAL,
  615. IN BOOLEAN AutoPageBreak,
  616. IN BOOLEAN AlwaysAllowNumbers
  617. );
  618. /// Make it easy to upgrade from older versions of the shell library.
  619. #define ShellCommandLineParse(CheckList, CheckPackage, ProblemParam, AutoPageBreak) ShellCommandLineParseEx(CheckList,CheckPackage,ProblemParam,AutoPageBreak,FALSE)
  620. /**
  621. Frees shell variable list that was returned from ShellCommandLineParse.
  622. This function will free all the memory that was used for the CheckPackage
  623. list of postprocessed shell arguments.
  624. If CheckPackage is NULL, then return.
  625. @param[in] CheckPackage The list to de-allocate.
  626. **/
  627. VOID
  628. EFIAPI
  629. ShellCommandLineFreeVarList (
  630. IN LIST_ENTRY *CheckPackage
  631. );
  632. /**
  633. Checks for presence of a flag parameter.
  634. Flag arguments are in the form of "-<Key>" or "/<Key>", but do not have a value following the key.
  635. If CheckPackage is NULL then return FALSE.
  636. If KeyString is NULL then ASSERT().
  637. @param[in] CheckPackage The package of parsed command line arguments.
  638. @param[in] KeyString The Key of the command line argument to check for.
  639. @retval TRUE The flag is on the command line.
  640. @retval FALSE The flag is not on the command line.
  641. **/
  642. BOOLEAN
  643. EFIAPI
  644. ShellCommandLineGetFlag (
  645. IN CONST LIST_ENTRY *CONST CheckPackage,
  646. IN CONST CHAR16 *CONST KeyString
  647. );
  648. /**
  649. Returns value from command line argument.
  650. Value parameters are in the form of "-<Key> value" or "/<Key> value".
  651. If CheckPackage is NULL, then return NULL.
  652. @param[in] CheckPackage The package of parsed command line arguments.
  653. @param[in] KeyString The Key of the command line argument to check for.
  654. @retval NULL The flag is not on the command line.
  655. @retval !=NULL The pointer to unicode string of the value.
  656. **/
  657. CONST CHAR16 *
  658. EFIAPI
  659. ShellCommandLineGetValue (
  660. IN CONST LIST_ENTRY *CheckPackage,
  661. IN CHAR16 *KeyString
  662. );
  663. /**
  664. Returns raw value from command line argument.
  665. Raw value parameters are in the form of "value" in a specific position in the list.
  666. If CheckPackage is NULL, then return NULL.
  667. @param[in] CheckPackage The package of parsed command line arguments.
  668. @param[in] Position The position of the value.
  669. @retval NULL The flag is not on the command line.
  670. @retval !=NULL The pointer to unicode string of the value.
  671. **/
  672. CONST CHAR16 *
  673. EFIAPI
  674. ShellCommandLineGetRawValue (
  675. IN CONST LIST_ENTRY *CONST CheckPackage,
  676. IN UINTN Position
  677. );
  678. /**
  679. Returns the number of command line value parameters that were parsed.
  680. This will not include flags.
  681. @param[in] CheckPackage The package of parsed command line arguments.
  682. @retval (UINTN)-1 No parsing has occurred.
  683. @retval other The number of value parameters found.
  684. **/
  685. UINTN
  686. EFIAPI
  687. ShellCommandLineGetCount (
  688. IN CONST LIST_ENTRY *CheckPackage
  689. );
  690. /**
  691. Determines if a parameter is duplicated.
  692. If Param is not NULL, then it will point to a callee-allocated string buffer
  693. with the parameter value, if a duplicate is found.
  694. If CheckPackage is NULL, then ASSERT.
  695. @param[in] CheckPackage The package of parsed command line arguments.
  696. @param[out] Param Upon finding one, a pointer to the duplicated parameter.
  697. @retval EFI_SUCCESS No parameters were duplicated.
  698. @retval EFI_DEVICE_ERROR A duplicate was found.
  699. **/
  700. EFI_STATUS
  701. EFIAPI
  702. ShellCommandLineCheckDuplicate (
  703. IN CONST LIST_ENTRY *CheckPackage,
  704. OUT CHAR16 **Param
  705. );
  706. /**
  707. This function causes the shell library to initialize itself. If the shell library
  708. is already initialized it will de-initialize all the current protocol pointers and
  709. re-populate them again.
  710. When the library is used with PcdShellLibAutoInitialize set to true this function
  711. will return EFI_SUCCESS and perform no actions.
  712. This function is intended for internal access for shell commands only.
  713. @retval EFI_SUCCESS The initialization was complete sucessfully.
  714. **/
  715. EFI_STATUS
  716. EFIAPI
  717. ShellInitialize (
  718. VOID
  719. );
  720. /**
  721. Print at a specific location on the screen.
  722. This function will move the cursor to a given screen location and print the specified string.
  723. If -1 is specified for either the Row or Col the current screen location for BOTH
  724. will be used.
  725. If either Row or Col is out of range for the current console, then ASSERT.
  726. If Format is NULL, then ASSERT.
  727. In addition to the standard %-based flags as supported by UefiLib Print() this supports
  728. the following additional flags:
  729. %N - Set output attribute to normal
  730. %H - Set output attribute to highlight
  731. %E - Set output attribute to error
  732. %B - Set output attribute to blue color
  733. %V - Set output attribute to green color
  734. Note: The background color is controlled by the shell command cls.
  735. @param[in] Col The column to print at.
  736. @param[in] Row The row to print at.
  737. @param[in] Format The format string.
  738. @param[in] ... The variable argument list.
  739. @return EFI_SUCCESS The printing was successful.
  740. @return EFI_DEVICE_ERROR The console device reported an error.
  741. **/
  742. EFI_STATUS
  743. EFIAPI
  744. ShellPrintEx (
  745. IN INT32 Col OPTIONAL,
  746. IN INT32 Row OPTIONAL,
  747. IN CONST CHAR16 *Format,
  748. ...
  749. );
  750. /**
  751. Print at a specific location on the screen.
  752. This function will move the cursor to a given screen location and print the specified string.
  753. If -1 is specified for either the Row or Col the current screen location for BOTH
  754. will be used.
  755. If either Row or Col is out of range for the current console, then ASSERT.
  756. If Format is NULL, then ASSERT.
  757. In addition to the standard %-based flags as supported by UefiLib Print() this supports
  758. the following additional flags:
  759. %N - Set output attribute to normal.
  760. %H - Set output attribute to highlight.
  761. %E - Set output attribute to error.
  762. %B - Set output attribute to blue color.
  763. %V - Set output attribute to green color.
  764. Note: The background color is controlled by the shell command cls.
  765. @param[in] Col The column to print at.
  766. @param[in] Row The row to print at.
  767. @param[in] Language The language of the string to retrieve. If this parameter
  768. is NULL, then the current platform language is used.
  769. @param[in] HiiFormatStringId The format string Id for getting from Hii.
  770. @param[in] HiiFormatHandle The format string Handle for getting from Hii.
  771. @param[in] ... The variable argument list.
  772. @return EFI_SUCCESS The printing was successful.
  773. @return EFI_DEVICE_ERROR The console device reported an error.
  774. **/
  775. EFI_STATUS
  776. EFIAPI
  777. ShellPrintHiiEx (
  778. IN INT32 Col OPTIONAL,
  779. IN INT32 Row OPTIONAL,
  780. IN CONST CHAR8 *Language OPTIONAL,
  781. IN CONST EFI_STRING_ID HiiFormatStringId,
  782. IN CONST EFI_HII_HANDLE HiiFormatHandle,
  783. ...
  784. );
  785. /**
  786. Function to determine if a given filename represents a directory.
  787. If DirName is NULL, then ASSERT.
  788. @param[in] DirName Path to directory to test.
  789. @retval EFI_SUCCESS The Path represents a directory.
  790. @retval EFI_NOT_FOUND The Path does not represent a directory.
  791. @retval other The path failed to open.
  792. **/
  793. EFI_STATUS
  794. EFIAPI
  795. ShellIsDirectory (
  796. IN CONST CHAR16 *DirName
  797. );
  798. /**
  799. Function to determine if a given filename represents a file.
  800. This will search the CWD only.
  801. If Name is NULL, then ASSERT.
  802. @param[in] Name Path to file to test.
  803. @retval EFI_SUCCESS The Path represents a file.
  804. @retval EFI_NOT_FOUND The Path does not represent a file.
  805. @retval other The path failed to open.
  806. **/
  807. EFI_STATUS
  808. EFIAPI
  809. ShellIsFile (
  810. IN CONST CHAR16 *Name
  811. );
  812. /**
  813. Function to determine if a given filename represents a file.
  814. This will search the CWD and then the Path.
  815. If Name is NULL, then ASSERT.
  816. @param[in] Name Path to file to test.
  817. @retval EFI_SUCCESS The Path represents a file.
  818. @retval EFI_NOT_FOUND The Path does not represent a file.
  819. @retval other The path failed to open.
  820. **/
  821. EFI_STATUS
  822. EFIAPI
  823. ShellIsFileInPath (
  824. IN CONST CHAR16 *Name
  825. );
  826. /**
  827. Function to determine whether a string is decimal or hex representation of a number
  828. and return the number converted from the string.
  829. Note: this function cannot be used when (UINTN)(-1), (0xFFFFFFFF) may be a valid
  830. result. Use ShellConvertStringToUint64 instead.
  831. @param[in] String String representation of a number.
  832. @return The unsigned integer result of the conversion.
  833. @retval (UINTN)(-1) An error occurred.
  834. **/
  835. UINTN
  836. EFIAPI
  837. ShellStrToUintn (
  838. IN CONST CHAR16 *String
  839. );
  840. /**
  841. Function return the number converted from a hex representation of a number.
  842. Note: this function cannot be used when (UINTN)(-1), (0xFFFFFFFF) may be a valid
  843. result. Use ShellConvertStringToUint64 instead.
  844. @param[in] String String representation of a number.
  845. @return The unsigned integer result of the conversion.
  846. @retval (UINTN)(-1) An error occurred.
  847. **/
  848. UINTN
  849. EFIAPI
  850. ShellHexStrToUintn (
  851. IN CONST CHAR16 *String
  852. );
  853. /**
  854. Safely append with automatic string resizing given length of Destination and
  855. desired length of copy from Source.
  856. Append the first D characters of Source to the end of Destination, where D is
  857. the lesser of Count and the StrLen() of Source. If appending those D characters
  858. will fit within Destination (whose Size is given as CurrentSize) and
  859. still leave room for a NULL terminator, then those characters are appended,
  860. starting at the original terminating NULL of Destination, and a new terminating
  861. NULL is appended.
  862. If appending D characters onto Destination will result in a overflow of the size
  863. given in CurrentSize the string will be grown such that the copy can be performed
  864. and CurrentSize will be updated to the new size.
  865. If Source is NULL, there is nothing to append, so return the current buffer in
  866. Destination.
  867. If Destination is NULL, then ASSERT().
  868. If Destination's current length (including NULL terminator) is already more than
  869. CurrentSize, then ASSERT().
  870. @param[in, out] Destination The String to append onto.
  871. @param[in, out] CurrentSize On call, the number of bytes in Destination. On
  872. return, possibly the new size (still in bytes). If NULL,
  873. then allocate whatever is needed.
  874. @param[in] Source The String to append from.
  875. @param[in] Count The maximum number of characters to append. If 0, then
  876. all are appended.
  877. @return The Destination after appending the Source.
  878. **/
  879. CHAR16 *
  880. EFIAPI
  881. StrnCatGrow (
  882. IN OUT CHAR16 **Destination,
  883. IN OUT UINTN *CurrentSize,
  884. IN CONST CHAR16 *Source,
  885. IN UINTN Count
  886. );
  887. /**
  888. This is a find and replace function. Upon successful return the NewString is a copy of
  889. SourceString with each instance of FindTarget replaced with ReplaceWith.
  890. If SourceString and NewString overlap the behavior is undefined.
  891. If the string would grow bigger than NewSize it will halt and return error.
  892. @param[in] SourceString The string with source buffer.
  893. @param[in, out] NewString The string with resultant buffer.
  894. @param[in] NewSize The size in bytes of NewString.
  895. @param[in] FindTarget The string to look for.
  896. @param[in] ReplaceWith The string to replace FindTarget with.
  897. @param[in] SkipPreCarrot If TRUE will skip a FindTarget that has a '^'
  898. immediately before it.
  899. @param[in] ParameterReplacing If TRUE will add "" around items with spaces.
  900. @retval EFI_INVALID_PARAMETER SourceString was NULL.
  901. @retval EFI_INVALID_PARAMETER NewString was NULL.
  902. @retval EFI_INVALID_PARAMETER FindTarget was NULL.
  903. @retval EFI_INVALID_PARAMETER ReplaceWith was NULL.
  904. @retval EFI_INVALID_PARAMETER FindTarget had length < 1.
  905. @retval EFI_INVALID_PARAMETER SourceString had length < 1.
  906. @retval EFI_BUFFER_TOO_SMALL NewSize was less than the minimum size to hold
  907. the new string (truncation occurred).
  908. @retval EFI_SUCCESS The string was successfully copied with replacement.
  909. **/
  910. EFI_STATUS
  911. EFIAPI
  912. ShellCopySearchAndReplace (
  913. IN CHAR16 CONST *SourceString,
  914. IN OUT CHAR16 *NewString,
  915. IN UINTN NewSize,
  916. IN CONST CHAR16 *FindTarget,
  917. IN CONST CHAR16 *ReplaceWith,
  918. IN CONST BOOLEAN SkipPreCarrot,
  919. IN CONST BOOLEAN ParameterReplacing
  920. );
  921. /**
  922. Check if a Unicode character is a hexadecimal character.
  923. This internal function checks if a Unicode character is a
  924. numeric character. The valid hexadecimal characters are
  925. L'0' to L'9', L'a' to L'f', or L'A' to L'F'.
  926. @param Char The character to check against.
  927. @retval TRUE The Char is a hexadecmial character.
  928. @retval FALSE The Char is not a hexadecmial character.
  929. **/
  930. BOOLEAN
  931. EFIAPI
  932. ShellIsHexaDecimalDigitCharacter (
  933. IN CHAR16 Char
  934. );
  935. /**
  936. Check if a Unicode character is a decimal character.
  937. This internal function checks if a Unicode character is a
  938. decimal character. The valid characters are
  939. L'0' to L'9'.
  940. @param Char The character to check against.
  941. @retval TRUE The Char is a hexadecmial character.
  942. @retval FALSE The Char is not a hexadecmial character.
  943. **/
  944. BOOLEAN
  945. EFIAPI
  946. ShellIsDecimalDigitCharacter (
  947. IN CHAR16 Char
  948. );
  949. ///
  950. /// What type of answer is requested.
  951. ///
  952. typedef enum {
  953. ShellPromptResponseTypeYesNo,
  954. ShellPromptResponseTypeYesNoCancel,
  955. ShellPromptResponseTypeFreeform,
  956. ShellPromptResponseTypeQuitContinue,
  957. ShellPromptResponseTypeYesNoAllCancel,
  958. ShellPromptResponseTypeEnterContinue,
  959. ShellPromptResponseTypeAnyKeyContinue,
  960. ShellPromptResponseTypeMax
  961. } SHELL_PROMPT_REQUEST_TYPE;
  962. ///
  963. /// What answer was given.
  964. ///
  965. typedef enum {
  966. ShellPromptResponseYes,
  967. ShellPromptResponseNo,
  968. ShellPromptResponseCancel,
  969. ShellPromptResponseQuit,
  970. ShellPromptResponseContinue,
  971. ShellPromptResponseAll,
  972. ShellPromptResponseMax
  973. } SHELL_PROMPT_RESPONSE;
  974. /**
  975. Prompt the user and return the resultant answer to the requestor.
  976. This function will display the requested question on the shell prompt and then
  977. wait for an appropriate answer to be input from the console.
  978. If the SHELL_PROMPT_REQUEST_TYPE is SHELL_PROMPT_REQUEST_TYPE_YESNO, ShellPromptResponseTypeQuitContinue
  979. or SHELL_PROMPT_REQUEST_TYPE_YESNOCANCEL then *Response is of type SHELL_PROMPT_RESPONSE.
  980. If the SHELL_PROMPT_REQUEST_TYPE is ShellPromptResponseTypeFreeform then *Response is of type
  981. CHAR16*.
  982. In either case *Response must be callee freed if Response was not NULL;
  983. @param Type What type of question is asked. This is used to filter the input
  984. to prevent invalid answers to question.
  985. @param Prompt The pointer to a string prompt used to request input.
  986. @param Response The pointer to Response, which will be populated upon return.
  987. @retval EFI_SUCCESS The operation was successful.
  988. @retval EFI_UNSUPPORTED The operation is not supported as requested.
  989. @retval EFI_INVALID_PARAMETER A parameter was invalid.
  990. @return other The operation failed.
  991. **/
  992. EFI_STATUS
  993. EFIAPI
  994. ShellPromptForResponse (
  995. IN SHELL_PROMPT_REQUEST_TYPE Type,
  996. IN CHAR16 *Prompt OPTIONAL,
  997. IN OUT VOID **Response OPTIONAL
  998. );
  999. /**
  1000. Prompt the user and return the resultant answer to the requestor.
  1001. This function is the same as ShellPromptForResponse, except that the prompt is
  1002. automatically pulled from HII.
  1003. @param[in] Type What type of question is asked. This is used to filter the input
  1004. to prevent invalid answers to question.
  1005. @param[in] HiiFormatStringId The format string Id for getting from Hii.
  1006. @param[in] HiiFormatHandle The format string Handle for getting from Hii.
  1007. @param[in, out] Response The pointer to Response, which will be populated upon return.
  1008. @retval EFI_SUCCESS The operation was sucessful.
  1009. @return other The operation failed.
  1010. @sa ShellPromptForResponse
  1011. **/
  1012. EFI_STATUS
  1013. EFIAPI
  1014. ShellPromptForResponseHii (
  1015. IN SHELL_PROMPT_REQUEST_TYPE Type,
  1016. IN CONST EFI_STRING_ID HiiFormatStringId,
  1017. IN CONST EFI_HII_HANDLE HiiFormatHandle,
  1018. IN OUT VOID **Response
  1019. );
  1020. /**
  1021. Function to determin if an entire string is a valid number.
  1022. If Hex it must be preceeded with a 0x, 0X, or has ForceHex set TRUE.
  1023. @param[in] String The string to evaluate.
  1024. @param[in] ForceHex TRUE - always assume hex.
  1025. @param[in] StopAtSpace TRUE to halt upon finding a space, FALSE to keep going.
  1026. @retval TRUE It is all numeric (dec/hex) characters.
  1027. @retval FALSE There is a non-numeric character.
  1028. **/
  1029. BOOLEAN
  1030. EFIAPI
  1031. ShellIsHexOrDecimalNumber (
  1032. IN CONST CHAR16 *String,
  1033. IN CONST BOOLEAN ForceHex,
  1034. IN CONST BOOLEAN StopAtSpace
  1035. );
  1036. /**
  1037. Function to verify and convert a string to its numerical 64 bit representation.
  1038. If Hex it must be preceeded with a 0x, 0X, or has ForceHex set TRUE.
  1039. @param[in] String The string to evaluate.
  1040. @param[out] Value Upon a successful return the value of the conversion.
  1041. @param[in] ForceHex TRUE - always assume hex.
  1042. @param[in] StopAtSpace TRUE to halt upon finding a space, FALSE to
  1043. process the entire String.
  1044. @retval EFI_SUCCESS The conversion was successful.
  1045. @retval EFI_INVALID_PARAMETER String contained an invalid character.
  1046. @retval EFI_NOT_FOUND String was a number, but Value was NULL.
  1047. **/
  1048. EFI_STATUS
  1049. EFIAPI
  1050. ShellConvertStringToUint64 (
  1051. IN CONST CHAR16 *String,
  1052. OUT UINT64 *Value,
  1053. IN CONST BOOLEAN ForceHex,
  1054. IN CONST BOOLEAN StopAtSpace
  1055. );
  1056. /**
  1057. Function to determine if a given filename exists.
  1058. @param[in] Name Path to test.
  1059. @retval EFI_SUCCESS The Path represents a file.
  1060. @retval EFI_NOT_FOUND The Path does not represent a file.
  1061. @retval other The path failed to open.
  1062. **/
  1063. EFI_STATUS
  1064. EFIAPI
  1065. ShellFileExists (
  1066. IN CONST CHAR16 *Name
  1067. );
  1068. /**
  1069. Function to read a single line from a SHELL_FILE_HANDLE. The \n is not included in the returned
  1070. buffer. The returned buffer must be callee freed.
  1071. If the position upon start is 0, then the Ascii Boolean will be set. This should be
  1072. maintained and not changed for all operations with the same file.
  1073. @param[in] Handle SHELL_FILE_HANDLE to read from.
  1074. @param[in, out] Ascii Boolean value for indicating whether the file is
  1075. Ascii (TRUE) or UCS2 (FALSE).
  1076. @return The line of text from the file.
  1077. @sa ShellFileHandleReadLine
  1078. **/
  1079. CHAR16 *
  1080. EFIAPI
  1081. ShellFileHandleReturnLine (
  1082. IN SHELL_FILE_HANDLE Handle,
  1083. IN OUT BOOLEAN *Ascii
  1084. );
  1085. /**
  1086. Function to read a single line (up to but not including the \n) from a SHELL_FILE_HANDLE.
  1087. If the position upon start is 0, then the Ascii Boolean will be set. This should be
  1088. maintained and not changed for all operations with the same file.
  1089. @param[in] Handle SHELL_FILE_HANDLE to read from.
  1090. @param[in, out] Buffer The pointer to buffer to read into.
  1091. @param[in, out] Size The pointer to number of bytes in Buffer.
  1092. @param[in] Truncate If the buffer is large enough, this has no effect.
  1093. If the buffer is is too small and Truncate is TRUE,
  1094. the line will be truncated.
  1095. If the buffer is is too small and Truncate is FALSE,
  1096. then no read will occur.
  1097. @param[in, out] Ascii Boolean value for indicating whether the file is
  1098. Ascii (TRUE) or UCS2 (FALSE).
  1099. @retval EFI_SUCCESS The operation was successful. The line is stored in
  1100. Buffer.
  1101. @retval EFI_END_OF_FILE There are no more lines in the file.
  1102. @retval EFI_INVALID_PARAMETER Handle was NULL.
  1103. @retval EFI_INVALID_PARAMETER Size was NULL.
  1104. @retval EFI_BUFFER_TOO_SMALL Size was not large enough to store the line.
  1105. Size was updated to the minimum space required.
  1106. **/
  1107. EFI_STATUS
  1108. EFIAPI
  1109. ShellFileHandleReadLine (
  1110. IN SHELL_FILE_HANDLE Handle,
  1111. IN OUT CHAR16 *Buffer,
  1112. IN OUT UINTN *Size,
  1113. IN BOOLEAN Truncate,
  1114. IN OUT BOOLEAN *Ascii
  1115. );
  1116. /**
  1117. Function to delete a file by name
  1118. @param[in] FileName Pointer to file name to delete.
  1119. @retval EFI_SUCCESS the file was deleted sucessfully
  1120. @retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not
  1121. deleted
  1122. @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
  1123. @retval EFI_NOT_FOUND The specified file could not be found on the
  1124. device or the file system could not be found
  1125. on the device.
  1126. @retval EFI_NO_MEDIA The device has no medium.
  1127. @retval EFI_MEDIA_CHANGED The device has a different medium in it or the
  1128. medium is no longer supported.
  1129. @retval EFI_DEVICE_ERROR The device reported an error.
  1130. @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
  1131. @retval EFI_WRITE_PROTECTED The file or medium is write protected.
  1132. @retval EFI_ACCESS_DENIED The file was opened read only.
  1133. @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the
  1134. file.
  1135. @retval other The file failed to open
  1136. **/
  1137. EFI_STATUS
  1138. EFIAPI
  1139. ShellDeleteFileByName (
  1140. IN CONST CHAR16 *FileName
  1141. );
  1142. /**
  1143. Function to print help file / man page content in the spec from the UEFI Shell protocol GetHelpText function.
  1144. @param[in] CommandToGetHelpOn Pointer to a string containing the command name of help file to be printed.
  1145. @param[in] SectionToGetHelpOn Pointer to the section specifier(s).
  1146. @param[in] PrintCommandText If TRUE, prints the command followed by the help content, otherwise prints
  1147. the help content only.
  1148. @retval EFI_DEVICE_ERROR The help data format was incorrect.
  1149. @retval EFI_NOT_FOUND The help data could not be found.
  1150. @retval EFI_SUCCESS The operation was successful.
  1151. **/
  1152. EFI_STATUS
  1153. EFIAPI
  1154. ShellPrintHelp (
  1155. IN CONST CHAR16 *CommandToGetHelpOn,
  1156. IN CONST CHAR16 *SectionToGetHelpOn,
  1157. IN BOOLEAN PrintCommandText
  1158. );
  1159. #endif // __SHELL_LIB__