PageRenderTime 769ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/edk2/Clover/Patches_for_EDK2/ShellPkg/Include/Protocol/EfiShell.h

https://gitlab.com/envieidoc/Clover
C Header | 1138 lines | 326 code | 52 blank | 760 comment | 0 complexity | 85549bdc08d9de9d1a29c8a58b7dad4f MD5 | raw file
  1. /** @file
  2. EFI Shell protocol as defined in the UEFI Shell 2.0 specification including errata.
  3. (C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>
  4. Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
  5. This program and the accompanying materials
  6. are licensed and made available under the terms and conditions of the BSD License
  7. which accompanies this distribution. The full text of the license may be found at
  8. http://opensource.org/licenses/bsd-license.php
  9. THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
  11. **/
  12. #ifndef __EFI_SHELL_PROTOCOL__
  13. #define __EFI_SHELL_PROTOCOL__
  14. #include <ShellBase.h>
  15. #include <Guid/FileInfo.h>
  16. #define EFI_SHELL_PROTOCOL_GUID \
  17. { \
  18. 0x6302d008, 0x7f9b, 0x4f30, { 0x87, 0xac, 0x60, 0xc9, 0xfe, 0xf5, 0xda, 0x4e } \
  19. }
  20. // replaced EFI_LIST_ENTRY with LIST_ENTRY for simplicity.
  21. // they are identical outside of the name.
  22. typedef struct {
  23. LIST_ENTRY Link; ///< Linked list members.
  24. EFI_STATUS Status; ///< Status of opening the file. Valid only if Handle != NULL.
  25. CONST CHAR16 *FullName; ///< Fully qualified filename.
  26. CONST CHAR16 *FileName; ///< name of this file.
  27. SHELL_FILE_HANDLE Handle; ///< Handle for interacting with the opened file or NULL if closed.
  28. EFI_FILE_INFO *Info; ///< Pointer to the FileInfo struct for this file or NULL.
  29. } EFI_SHELL_FILE_INFO;
  30. /**
  31. Returns whether any script files are currently being processed.
  32. @retval TRUE There is at least one script file active.
  33. @retval FALSE No script files are active now.
  34. **/
  35. typedef
  36. BOOLEAN
  37. (EFIAPI *EFI_SHELL_BATCH_IS_ACTIVE) (
  38. VOID
  39. );
  40. /**
  41. Closes the file handle.
  42. This function closes a specified file handle. All 'dirty' cached file data is
  43. flushed to the device, and the file is closed. In all cases, the handle is
  44. closed.
  45. @param[in] FileHandle The file handle to be closed.
  46. @retval EFI_SUCCESS The file closed sucessfully.
  47. **/
  48. typedef
  49. EFI_STATUS
  50. (EFIAPI *EFI_SHELL_CLOSE_FILE)(
  51. IN SHELL_FILE_HANDLE FileHandle
  52. );
  53. /**
  54. Creates a file or directory by name.
  55. This function creates an empty new file or directory with the specified attributes and
  56. returns the new file's handle. If the file already exists and is read-only, then
  57. EFI_INVALID_PARAMETER will be returned.
  58. If the file already existed, it is truncated and its attributes updated. If the file is
  59. created successfully, the FileHandle is the file's handle, else, the FileHandle is NULL.
  60. If the file name begins with >v, then the file handle which is returned refers to the
  61. shell environment variable with the specified name. If the shell environment variable
  62. already exists and is non-volatile then EFI_INVALID_PARAMETER is returned.
  63. @param[in] FileName Pointer to NULL-terminated file path.
  64. @param[in] FileAttribs The new file's attrbiutes. The different attributes are
  65. described in EFI_FILE_PROTOCOL.Open().
  66. @param[out] FileHandle On return, points to the created file handle or directory's handle.
  67. @retval EFI_SUCCESS The file was opened. FileHandle points to the new file's handle.
  68. @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
  69. @retval EFI_UNSUPPORTED The file path could not be opened.
  70. @retval EFI_NOT_FOUND The specified file could not be found on the device, or could not
  71. file the file system on the device.
  72. @retval EFI_NO_MEDIA The device has no medium.
  73. @retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no
  74. longer supported.
  75. @retval EFI_DEVICE_ERROR The device reported an error or can't get the file path according
  76. the DirName.
  77. @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
  78. @retval EFI_WRITE_PROTECTED An attempt was made to create a file, or open a file for write
  79. when the media is write-protected.
  80. @retval EFI_ACCESS_DENIED The service denied access to the file.
  81. @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the file.
  82. @retval EFI_VOLUME_FULL The volume is full.
  83. **/
  84. typedef
  85. EFI_STATUS
  86. (EFIAPI *EFI_SHELL_CREATE_FILE)(
  87. IN CONST CHAR16 *FileName,
  88. IN UINT64 FileAttribs,
  89. OUT SHELL_FILE_HANDLE *FileHandle
  90. );
  91. /**
  92. Deletes the file specified by the file handle.
  93. This function closes and deletes a file. In all cases, the file handle is closed. If the file
  94. cannot be deleted, the warning code EFI_WARN_DELETE_FAILURE is returned, but the
  95. handle is still closed.
  96. @param[in] FileHandle The file handle to delete.
  97. @retval EFI_SUCCESS The file was closed and deleted and the handle was closed.
  98. @retval EFI_WARN_DELETE_FAILURE The handle was closed but the file was not deleted.
  99. **/
  100. typedef
  101. EFI_STATUS
  102. (EFIAPI *EFI_SHELL_DELETE_FILE)(
  103. IN SHELL_FILE_HANDLE FileHandle
  104. );
  105. /**
  106. Deletes the file specified by the file name.
  107. This function deletes a file.
  108. @param[in] FileName Points to the NULL-terminated file name.
  109. @retval EFI_SUCCESS The file was deleted.
  110. @retval EFI_WARN_DELETE_FAILURE The handle was closed but the file was not deleted.
  111. **/
  112. typedef
  113. EFI_STATUS
  114. (EFIAPI *EFI_SHELL_DELETE_FILE_BY_NAME)(
  115. IN CONST CHAR16 *FileName
  116. );
  117. /**
  118. Disables the page break output mode.
  119. **/
  120. typedef
  121. VOID
  122. (EFIAPI *EFI_SHELL_DISABLE_PAGE_BREAK) (
  123. VOID
  124. );
  125. /**
  126. Enables the page break output mode.
  127. **/
  128. typedef
  129. VOID
  130. (EFIAPI *EFI_SHELL_ENABLE_PAGE_BREAK) (
  131. VOID
  132. );
  133. /**
  134. Execute the command line.
  135. This function creates a nested instance of the shell and executes the specified
  136. command (CommandLine) with the specified environment (Environment). Upon return,
  137. the status code returned by the specified command is placed in StatusCode.
  138. If Environment is NULL, then the current environment is used and all changes made
  139. by the commands executed will be reflected in the current environment. If the
  140. Environment is non-NULL, then the changes made will be discarded.
  141. The CommandLine is executed from the current working directory on the current
  142. device.
  143. @param[in] ParentImageHandle A handle of the image that is executing the specified
  144. command line.
  145. @param[in] CommandLine Points to the NULL-terminated UCS-2 encoded string
  146. containing the command line. If NULL then the command-
  147. line will be empty.
  148. @param[in] Environment Points to a NULL-terminated array of environment
  149. variables with the format 'x=y', where x is the
  150. environment variable name and y is the value. If this
  151. is NULL, then the current shell environment is used.
  152. @param[out] ErrorCode Points to the status code returned by the command.
  153. @retval EFI_SUCCESS The command executed successfully. The status code
  154. returned by the command is pointed to by StatusCode.
  155. @retval EFI_INVALID_PARAMETER The parameters are invalid.
  156. @retval EFI_OUT_OF_RESOURCES Out of resources.
  157. @retval EFI_UNSUPPORTED Nested shell invocations are not allowed.
  158. **/
  159. typedef
  160. EFI_STATUS
  161. (EFIAPI *EFI_SHELL_EXECUTE) (
  162. IN EFI_HANDLE *ParentImageHandle,
  163. IN CHAR16 *CommandLine OPTIONAL,
  164. IN CHAR16 **Environment OPTIONAL,
  165. OUT EFI_STATUS *StatusCode OPTIONAL
  166. );
  167. /**
  168. Find files that match a specified pattern.
  169. This function searches for all files and directories that match the specified
  170. FilePattern. The FilePattern can contain wild-card characters. The resulting file
  171. information is placed in the file list FileList.
  172. The files in the file list are not opened. The OpenMode field is set to 0 and the FileInfo
  173. field is set to NULL.
  174. @param[in] FilePattern Points to a NULL-terminated shell file path, including wildcards.
  175. @param[out] FileList On return, points to the start of a file list containing the names
  176. of all matching files or else points to NULL if no matching files
  177. were found.
  178. @retval EFI_SUCCESS Files found.
  179. @retval EFI_NOT_FOUND No files found.
  180. @retval EFI_NO_MEDIA The device has no media.
  181. @retval EFI_DEVICE_ERROR The device reported an error.
  182. @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
  183. **/
  184. typedef
  185. EFI_STATUS
  186. (EFIAPI *EFI_SHELL_FIND_FILES)(
  187. IN CONST CHAR16 *FilePattern,
  188. OUT EFI_SHELL_FILE_INFO **FileList
  189. );
  190. /**
  191. Find all files in a specified directory.
  192. @param[in] FileDirHandle Handle of the directory to search.
  193. @param[out] FileList On return, points to the list of files in the directory
  194. or NULL if there are no files in the directory.
  195. @retval EFI_SUCCESS File information was returned successfully.
  196. @retval EFI_VOLUME_CORRUPTED The file system structures have been corrupted.
  197. @retval EFI_DEVICE_ERROR The device reported an error.
  198. @retval EFI_NO_MEDIA The device media is not present.
  199. **/
  200. typedef
  201. EFI_STATUS
  202. (EFIAPI *EFI_SHELL_FIND_FILES_IN_DIR)(
  203. IN SHELL_FILE_HANDLE FileDirHandle,
  204. OUT EFI_SHELL_FILE_INFO **FileList
  205. );
  206. /**
  207. Flushes data back to a device.
  208. This function flushes all modified data associated with a file to a device.
  209. @param[in] FileHandle The handle of the file to flush.
  210. @retval EFI_SUCCESS The data was flushed.
  211. @retval EFI_NO_MEDIA The device has no medium.
  212. @retval EFI_DEVICE_ERROR The device reported an error.
  213. @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
  214. @retval EFI_WRITE_PROTECTED The file or medium is write-protected.
  215. @retval EFI_ACCESS_DENIED The file was opened read-only.
  216. @retval EFI_VOLUME_FULL The volume is full.
  217. **/
  218. typedef
  219. EFI_STATUS
  220. (EFIAPI *EFI_SHELL_FLUSH_FILE)(
  221. IN SHELL_FILE_HANDLE FileHandle
  222. );
  223. /**
  224. Frees the file list.
  225. This function cleans up the file list and any related data structures. It has no
  226. impact on the files themselves.
  227. @param[in] FileList The file list to free. Type EFI_SHELL_FILE_INFO is
  228. defined in OpenFileList().
  229. @retval EFI_SUCCESS Free the file list successfully.
  230. **/
  231. typedef
  232. EFI_STATUS
  233. (EFIAPI *EFI_SHELL_FREE_FILE_LIST) (
  234. IN EFI_SHELL_FILE_INFO **FileList
  235. );
  236. /**
  237. Returns the current directory on the specified device.
  238. If FileSystemMapping is NULL, it returns the current working directory. If the
  239. FileSystemMapping is not NULL, it returns the current directory associated with the
  240. FileSystemMapping. In both cases, the returned name includes the file system
  241. mapping (i.e. fs0:\current-dir).
  242. Note that the current directory string should exclude the tailing backslash character.
  243. @param[in] FileSystemMapping A pointer to the file system mapping. If NULL,
  244. then the current working directory is returned.
  245. @retval !=NULL The current directory.
  246. @retval NULL Current directory does not exist.
  247. **/
  248. typedef
  249. CONST CHAR16 *
  250. (EFIAPI *EFI_SHELL_GET_CUR_DIR) (
  251. IN CONST CHAR16 *FileSystemMapping OPTIONAL
  252. );
  253. typedef UINT32 EFI_SHELL_DEVICE_NAME_FLAGS;
  254. #define EFI_DEVICE_NAME_USE_COMPONENT_NAME 0x00000001
  255. #define EFI_DEVICE_NAME_USE_DEVICE_PATH 0x00000002
  256. /**
  257. Gets the name of the device specified by the device handle.
  258. This function gets the user-readable name of the device specified by the device
  259. handle. If no user-readable name could be generated, then *BestDeviceName will be
  260. NULL and EFI_NOT_FOUND will be returned.
  261. If EFI_DEVICE_NAME_USE_COMPONENT_NAME is set, then the function will return the
  262. device's name using the EFI_COMPONENT_NAME2_PROTOCOL, if present on
  263. DeviceHandle.
  264. If EFI_DEVICE_NAME_USE_DEVICE_PATH is set, then the function will return the
  265. device's name using the EFI_DEVICE_PATH_PROTOCOL, if present on DeviceHandle.
  266. If both EFI_DEVICE_NAME_USE_COMPONENT_NAME and
  267. EFI_DEVICE_NAME_USE_DEVICE_PATH are set, then
  268. EFI_DEVICE_NAME_USE_COMPONENT_NAME will have higher priority.
  269. @param[in] DeviceHandle The handle of the device.
  270. @param[in] Flags Determines the possible sources of component names.
  271. @param[in] Language A pointer to the language specified for the device
  272. name, in the same format as described in the UEFI
  273. specification, Appendix M.
  274. @param[out] BestDeviceName On return, points to the callee-allocated NULL-
  275. terminated name of the device. If no device name
  276. could be found, points to NULL. The name must be
  277. freed by the caller...
  278. @retval EFI_SUCCESS Get the name successfully.
  279. @retval EFI_NOT_FOUND Fail to get the device name.
  280. **/
  281. typedef
  282. EFI_STATUS
  283. (EFIAPI *EFI_SHELL_GET_DEVICE_NAME) (
  284. IN EFI_HANDLE DeviceHandle,
  285. IN EFI_SHELL_DEVICE_NAME_FLAGS Flags,
  286. IN CHAR8 *Language,
  287. OUT CHAR16 **BestDeviceName
  288. );
  289. /**
  290. Gets the device path from the mapping.
  291. This function gets the device path associated with a mapping.
  292. @param[in] Mapping A pointer to the mapping
  293. @retval !=NULL Pointer to the device path that corresponds to the
  294. device mapping. The returned pointer does not need
  295. to be freed.
  296. @retval NULL There is no device path associated with the
  297. specified mapping.
  298. **/
  299. typedef
  300. CONST EFI_DEVICE_PATH_PROTOCOL *
  301. (EFIAPI *EFI_SHELL_GET_DEVICE_PATH_FROM_MAP) (
  302. IN CONST CHAR16 *Mapping
  303. );
  304. /**
  305. Converts a file system style name to a device path.
  306. This function converts a file system style name to a device path, by replacing any
  307. mapping references to the associated device path.
  308. @param[in] Path The pointer to the path.
  309. @return The pointer of the file path. The file path is callee
  310. allocated and should be freed by the caller.
  311. **/
  312. typedef
  313. EFI_DEVICE_PATH_PROTOCOL *
  314. (EFIAPI *EFI_SHELL_GET_DEVICE_PATH_FROM_FILE_PATH) (
  315. IN CONST CHAR16 *Path
  316. );
  317. /**
  318. Gets either a single or list of environment variables.
  319. If name is not NULL then this function returns the current value of the specified
  320. environment variable.
  321. If Name is NULL than a list of all environment variable names is returned. Each a
  322. NULL terminated string with a double NULL terminating the list.
  323. @param[in] Name A pointer to the environment variable name. If
  324. Name is NULL, then the function will return all
  325. of the defined shell environment variables. In
  326. the case where multiple environment variables are
  327. being returned, each variable will be terminated by
  328. a NULL, and the list will be terminated by a double
  329. NULL.
  330. @return A pointer to the returned string.
  331. The returned pointer does not need to be freed by the caller.
  332. @retval NULL The environment variable doesn't exist or there are
  333. no environment variables.
  334. **/
  335. typedef
  336. CONST CHAR16 *
  337. (EFIAPI *EFI_SHELL_GET_ENV) (
  338. IN CONST CHAR16 *Name OPTIONAL
  339. );
  340. /**
  341. Gets the environment variable and Attributes, or list of environment variables. Can be
  342. used instead of GetEnv().
  343. This function returns the current value of the specified environment variable and
  344. the Attributes. If no variable name was specified, then all of the known
  345. variables will be returned.
  346. @param[in] Name A pointer to the environment variable name. If Name is NULL,
  347. then the function will return all of the defined shell
  348. environment variables. In the case where multiple environment
  349. variables are being returned, each variable will be terminated
  350. by a NULL, and the list will be terminated by a double NULL.
  351. @param[out] Attributes If not NULL, a pointer to the returned attributes bitmask for
  352. the environment variable. In the case where Name is NULL, and
  353. multiple environment variables are being returned, Attributes
  354. is undefined.
  355. @retval NULL The environment variable doesn't exist.
  356. @return The environment variable's value. The returned pointer does not
  357. need to be freed by the caller.
  358. **/
  359. typedef
  360. CONST CHAR16 *
  361. (EFIAPI *EFI_SHELL_GET_ENV_EX) (
  362. IN CONST CHAR16 *Name,
  363. OUT UINT32 *Attributes OPTIONAL
  364. );
  365. /**
  366. Gets the file information from an open file handle.
  367. This function allocates a buffer to store the file's information. It's the caller's
  368. responsibility to free the buffer.
  369. @param[in] FileHandle A File Handle.
  370. @retval NULL Cannot get the file info.
  371. @return A pointer to a buffer with file information.
  372. **/
  373. typedef
  374. EFI_FILE_INFO *
  375. (EFIAPI *EFI_SHELL_GET_FILE_INFO)(
  376. IN SHELL_FILE_HANDLE FileHandle
  377. );
  378. /**
  379. Converts a device path to a file system-style path.
  380. This function converts a device path to a file system path by replacing part, or all, of
  381. the device path with the file-system mapping. If there are more than one application
  382. file system mappings, the one that most closely matches Path will be used.
  383. @param[in] Path The pointer to the device path.
  384. @return The pointer of the NULL-terminated file path. The path
  385. is callee-allocated and should be freed by the caller.
  386. **/
  387. typedef
  388. CHAR16 *
  389. (EFIAPI *EFI_SHELL_GET_FILE_PATH_FROM_DEVICE_PATH) (
  390. IN CONST EFI_DEVICE_PATH_PROTOCOL *Path
  391. );
  392. /**
  393. Gets a file's current position.
  394. This function returns the current file position for the file handle. For directories, the
  395. current file position has no meaning outside of the file system driver and as such, the
  396. operation is not supported.
  397. @param[in] FileHandle The file handle on which to get the current position.
  398. @param[out] Position Byte position from the start of the file.
  399. @retval EFI_SUCCESS Data was accessed.
  400. @retval EFI_UNSUPPORTED The request is not valid on open directories.
  401. **/
  402. typedef
  403. EFI_STATUS
  404. (EFIAPI *EFI_SHELL_GET_FILE_POSITION)(
  405. IN SHELL_FILE_HANDLE FileHandle,
  406. OUT UINT64 *Position
  407. );
  408. /**
  409. Gets the size of a file.
  410. This function returns the size of the file specified by FileHandle.
  411. @param[in] FileHandle The handle of the file.
  412. @param[out] Size The size of this file.
  413. @retval EFI_SUCCESS Get the file's size.
  414. @retval EFI_DEVICE_ERROR Can't access the file.
  415. **/
  416. typedef
  417. EFI_STATUS
  418. (EFIAPI *EFI_SHELL_GET_FILE_SIZE)(
  419. IN SHELL_FILE_HANDLE FileHandle,
  420. OUT UINT64 *Size
  421. );
  422. /**
  423. Get the GUID value from a human readable name.
  424. If GuidName is a known GUID name, then update Guid to have the correct value for
  425. that GUID.
  426. This function is only available when the major and minor versions in the
  427. EfiShellProtocol are greater than or equal to 2 and 1, respectively.
  428. @param[in] GuidName A pointer to the localized name for the GUID being queried.
  429. @param[out] Guid A pointer to the GUID structure to be filled in.
  430. @retval EFI_SUCCESS The operation was successful.
  431. @retval EFI_INVALID_PARAMETER Guid was NULL.
  432. @retval EFI_INVALID_PARAMETER GuidName was NULL.
  433. @retval EFI_NOT_FOUND GuidName is not a known GUID Name.
  434. **/
  435. typedef
  436. EFI_STATUS
  437. (EFIAPI *EFI_SHELL_GET_GUID_FROM_NAME)(
  438. IN CONST CHAR16 *GuidName,
  439. OUT EFI_GUID *Guid
  440. );
  441. /**
  442. Get the human readable name for a GUID from the value.
  443. If Guid is assigned a name, then update *GuidName to point to the name. The callee
  444. should not modify the value.
  445. This function is only available when the major and minor versions in the
  446. EfiShellProtocol are greater than or equal to 2 and 1, respectively.
  447. @param[in] Guid A pointer to the GUID being queried.
  448. @param[out] GuidName A pointer to a pointer the localized to name for the GUID being requested
  449. @retval EFI_SUCCESS The operation was successful.
  450. @retval EFI_INVALID_PARAMETER Guid was NULL.
  451. @retval EFI_INVALID_PARAMETER GuidName was NULL.
  452. @retval EFI_NOT_FOUND Guid is not assigned a name.
  453. **/
  454. typedef
  455. EFI_STATUS
  456. (EFIAPI *EFI_SHELL_GET_GUID_NAME)(
  457. IN CONST EFI_GUID *Guid,
  458. OUT CONST CHAR16 **GuidName
  459. );
  460. /**
  461. Return help information about a specific command.
  462. This function returns the help information for the specified command. The help text
  463. can be internal to the shell or can be from a UEFI Shell manual page.
  464. If Sections is specified, then each section name listed will be compared in a casesensitive
  465. manner, to the section names described in Appendix B. If the section exists,
  466. it will be appended to the returned help text. If the section does not exist, no
  467. information will be returned. If Sections is NULL, then all help text information
  468. available will be returned.
  469. @param[in] Command Points to the NULL-terminated UEFI Shell command name.
  470. @param[in] Sections Points to the NULL-terminated comma-delimited
  471. section names to return. If NULL, then all
  472. sections will be returned.
  473. @param[out] HelpText On return, points to a callee-allocated buffer
  474. containing all specified help text.
  475. @retval EFI_SUCCESS The help text was returned.
  476. @retval EFI_OUT_OF_RESOURCES The necessary buffer could not be allocated to hold the
  477. returned help text.
  478. @retval EFI_INVALID_PARAMETER HelpText is NULL.
  479. @retval EFI_NOT_FOUND There is no help text available for Command.
  480. **/
  481. typedef
  482. EFI_STATUS
  483. (EFIAPI *EFI_SHELL_GET_HELP_TEXT) (
  484. IN CONST CHAR16 *Command,
  485. IN CONST CHAR16 *Sections OPTIONAL,
  486. OUT CHAR16 **HelpText
  487. );
  488. /**
  489. Gets the mapping(s) that most closely matches the device path.
  490. This function gets the mapping which corresponds to the device path *DevicePath. If
  491. there is no exact match, then the mapping which most closely matches *DevicePath
  492. is returned, and *DevicePath is updated to point to the remaining portion of the
  493. device path. If there is an exact match, the mapping is returned and *DevicePath
  494. points to the end-of-device-path node.
  495. If there are multiple map names they will be semi-colon seperated in the
  496. NULL-terminated string.
  497. @param[in, out] DevicePath On entry, points to a device path pointer. On
  498. exit, updates the pointer to point to the
  499. portion of the device path after the mapping.
  500. @retval NULL No mapping was found.
  501. @retval !=NULL Pointer to NULL-terminated mapping. The buffer
  502. is callee allocated and should be freed by the caller.
  503. **/
  504. typedef
  505. CONST CHAR16 *
  506. (EFIAPI *EFI_SHELL_GET_MAP_FROM_DEVICE_PATH) (
  507. IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
  508. );
  509. /**
  510. Gets the enable status of the page break output mode.
  511. User can use this function to determine current page break mode.
  512. @retval TRUE The page break output mode is enabled.
  513. @retval FALSE The page break output mode is disabled.
  514. **/
  515. typedef
  516. BOOLEAN
  517. (EFIAPI *EFI_SHELL_GET_PAGE_BREAK) (
  518. VOID
  519. );
  520. /**
  521. Judges whether the active shell is the root shell.
  522. This function makes the user to know that whether the active Shell is the root shell.
  523. @retval TRUE The active Shell is the root Shell.
  524. @retval FALSE The active Shell is NOT the root Shell.
  525. **/
  526. typedef
  527. BOOLEAN
  528. (EFIAPI *EFI_SHELL_IS_ROOT_SHELL) (
  529. VOID
  530. );
  531. /**
  532. Opens a file or a directory by file name.
  533. This function opens the specified file in the specified OpenMode and returns a file
  534. handle.
  535. If the file name begins with '>v', then the file handle which is returned refers to the
  536. shell environment variable with the specified name. If the shell environment variable
  537. exists, is non-volatile and the OpenMode indicates EFI_FILE_MODE_WRITE, then
  538. EFI_INVALID_PARAMETER is returned.
  539. If the file name is '>i', then the file handle which is returned refers to the standard
  540. input. If the OpenMode indicates EFI_FILE_MODE_WRITE, then EFI_INVALID_PARAMETER
  541. is returned.
  542. If the file name is '>o', then the file handle which is returned refers to the standard
  543. output. If the OpenMode indicates EFI_FILE_MODE_READ, then EFI_INVALID_PARAMETER
  544. is returned.
  545. If the file name is '>e', then the file handle which is returned refers to the standard
  546. error. If the OpenMode indicates EFI_FILE_MODE_READ, then EFI_INVALID_PARAMETER
  547. is returned.
  548. If the file name is 'NUL', then the file handle that is returned refers to the standard NUL
  549. file. If the OpenMode indicates EFI_FILE_MODE_READ, then EFI_INVALID_PARAMETER is
  550. returned.
  551. If return EFI_SUCCESS, the FileHandle is the opened file's handle, else, the
  552. FileHandle is NULL.
  553. @param[in] FileName Points to the NULL-terminated UCS-2 encoded file name.
  554. @param[out] FileHandle On return, points to the file handle.
  555. @param[in] OpenMode File open mode. Either EFI_FILE_MODE_READ or
  556. EFI_FILE_MODE_WRITE from section 12.4 of the UEFI
  557. Specification.
  558. @retval EFI_SUCCESS The file was opened. FileHandle has the opened file's handle.
  559. @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value. FileHandle is NULL.
  560. @retval EFI_UNSUPPORTED Could not open the file path. FileHandle is NULL.
  561. @retval EFI_NOT_FOUND The specified file could not be found on the device or the file
  562. system could not be found on the device. FileHandle is NULL.
  563. @retval EFI_NO_MEDIA The device has no medium. FileHandle is NULL.
  564. @retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no
  565. longer supported. FileHandle is NULL.
  566. @retval EFI_DEVICE_ERROR The device reported an error or can't get the file path according
  567. the FileName. FileHandle is NULL.
  568. @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. FileHandle is NULL.
  569. @retval EFI_WRITE_PROTECTED An attempt was made to create a file, or open a file for write
  570. when the media is write-protected. FileHandle is NULL.
  571. @retval EFI_ACCESS_DENIED The service denied access to the file. FileHandle is NULL.
  572. @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the file. FileHandle
  573. is NULL.
  574. @retval EFI_VOLUME_FULL The volume is full. FileHandle is NULL.
  575. **/
  576. typedef
  577. EFI_STATUS
  578. (EFIAPI *EFI_SHELL_OPEN_FILE_BY_NAME) (
  579. IN CONST CHAR16 *FileName,
  580. OUT SHELL_FILE_HANDLE *FileHandle,
  581. IN UINT64 OpenMode
  582. );
  583. /**
  584. Opens the files that match the path specified.
  585. This function opens all of the files specified by Path. Wildcards are processed
  586. according to the rules specified in UEFI Shell 2.0 spec section 3.7.1. Each
  587. matching file has an EFI_SHELL_FILE_INFO structure created in a linked list.
  588. @param[in] Path A pointer to the path string.
  589. @param[in] OpenMode Specifies the mode used to open each file, EFI_FILE_MODE_READ or
  590. EFI_FILE_MODE_WRITE.
  591. @param[in, out] FileList Points to the start of a list of files opened.
  592. @retval EFI_SUCCESS Create the file list successfully.
  593. @return Can't create the file list.
  594. **/
  595. typedef
  596. EFI_STATUS
  597. (EFIAPI *EFI_SHELL_OPEN_FILE_LIST) (
  598. IN CHAR16 *Path,
  599. IN UINT64 OpenMode,
  600. IN OUT EFI_SHELL_FILE_INFO **FileList
  601. );
  602. /**
  603. Opens the root directory of a device.
  604. This function opens the root directory of a device and returns a file handle to it.
  605. @param[in] DevicePath Points to the device path corresponding to the device where the
  606. EFI_SIMPLE_FILE_SYSTEM_PROTOCOL is installed.
  607. @param[out] FileHandle On exit, points to the file handle corresponding to the root directory on the
  608. device.
  609. @retval EFI_SUCCESS Root opened successfully.
  610. @retval EFI_NOT_FOUND EFI_SIMPLE_FILE_SYSTEM could not be found or the root directory
  611. could not be opened.
  612. @retval EFI_VOLUME_CORRUPTED The data structures in the volume were corrupted.
  613. @retval EFI_DEVICE_ERROR The device had an error.
  614. **/
  615. typedef
  616. EFI_STATUS
  617. (EFIAPI *EFI_SHELL_OPEN_ROOT)(
  618. IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
  619. OUT SHELL_FILE_HANDLE *FileHandle
  620. );
  621. /**
  622. Opens the root directory of a device on a handle.
  623. This function opens the root directory of a device and returns a file handle to it.
  624. @param[in] DeviceHandle The handle of the device that contains the volume.
  625. @param[out] FileHandle On exit, points to the file handle corresponding to the root directory on the
  626. device.
  627. @retval EFI_SUCCESS Root opened successfully.
  628. @retval EFI_NOT_FOUND EFI_SIMPLE_FILE_SYSTEM could not be found or the root directory
  629. could not be opened.
  630. @retval EFI_VOLUME_CORRUPTED The data structures in the volume were corrupted.
  631. @retval EFI_DEVICE_ERROR The device had an error.
  632. **/
  633. typedef
  634. EFI_STATUS
  635. (EFIAPI *EFI_SHELL_OPEN_ROOT_BY_HANDLE)(
  636. IN EFI_HANDLE DeviceHandle,
  637. OUT SHELL_FILE_HANDLE *FileHandle
  638. );
  639. /**
  640. Reads data from the file.
  641. If FileHandle is not a directory, the function reads the requested number of bytes
  642. from the file at the file's current position and returns them in Buffer. If the read goes
  643. beyond the end of the file, the read length is truncated to the end of the file. The file's
  644. current position is increased by the number of bytes returned.
  645. If FileHandle is a directory, then an error is returned.
  646. @param[in] FileHandle The opened file handle for read.
  647. @param[in] ReadSize On input, the size of Buffer, in bytes. On output, the amount of data read.
  648. @param[in, out] Buffer The buffer in which data is read.
  649. @retval EFI_SUCCESS Data was read.
  650. @retval EFI_NO_MEDIA The device has no media.
  651. @retval EFI_DEVICE_ERROR The device reported an error.
  652. @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
  653. @retval EFI_BUFFER_TO_SMALL Buffer is too small. ReadSize contains required size.
  654. **/
  655. typedef
  656. EFI_STATUS
  657. (EFIAPI *EFI_SHELL_READ_FILE) (
  658. IN SHELL_FILE_HANDLE FileHandle,
  659. IN OUT UINTN *ReadSize,
  660. IN OUT VOID *Buffer
  661. );
  662. /**
  663. Register a GUID and a localized human readable name for it.
  664. If Guid is not assigned a name, then assign GuidName to Guid. This list of GUID
  665. names must be used whenever a shell command outputs GUID information.
  666. This function is only available when the major and minor versions in the
  667. EfiShellProtocol are greater than or equal to 2 and 1, respectively.
  668. @param[in] Guid A pointer to the GUID being registered.
  669. @param[in] GuidName A pointer to the localized name for the GUID being registered.
  670. @retval EFI_SUCCESS The operation was successful.
  671. @retval EFI_INVALID_PARAMETER Guid was NULL.
  672. @retval EFI_INVALID_PARAMETER GuidName was NULL.
  673. @retval EFI_ACCESS_DENIED Guid already is assigned a name.
  674. **/
  675. typedef
  676. EFI_STATUS
  677. (EFIAPI *EFI_SHELL_REGISTER_GUID_NAME)(
  678. IN CONST EFI_GUID *Guid,
  679. IN CONST CHAR16 *GuidName
  680. );
  681. /**
  682. Deletes the duplicate file names files in the given file list.
  683. @param[in] FileList A pointer to the first entry in the file list.
  684. @retval EFI_SUCCESS Always success.
  685. **/
  686. typedef
  687. EFI_STATUS
  688. (EFIAPI *EFI_SHELL_REMOVE_DUP_IN_FILE_LIST) (
  689. IN EFI_SHELL_FILE_INFO **FileList
  690. );
  691. /**
  692. Changes a shell command alias.
  693. This function creates an alias for a shell command.
  694. @param[in] Command Points to the NULL-terminated shell command or existing alias.
  695. @param[in] Alias Points to the NULL-terminated alias for the shell command. If this is NULL, and
  696. Command refers to an alias, that alias will be deleted.
  697. @param[in] Replace If TRUE and the alias already exists, then the existing alias will be replaced. If
  698. FALSE and the alias already exists, then the existing alias is unchanged and
  699. EFI_ACCESS_DENIED is returned.
  700. @param[in] Volatile if TRUE the Alias being set will be stored in a volatile fashion. if FALSE the
  701. Alias being set will be stored in a non-volatile fashion.
  702. @retval EFI_SUCCESS Alias created or deleted successfully.
  703. @retval EFI_ACCESS_DENIED The alias is a built-in alias or already existed and Replace was set to
  704. FALSE.
  705. **/
  706. typedef
  707. EFI_STATUS
  708. (EFIAPI *EFI_SHELL_SET_ALIAS)(
  709. IN CONST CHAR16 *Command,
  710. IN CONST CHAR16 *Alias,
  711. IN BOOLEAN Replace,
  712. IN BOOLEAN Volatile
  713. );
  714. /**
  715. This function returns the command associated with a alias or a list of all
  716. alias'.
  717. @param[in] Alias Points to the NULL-terminated shell alias.
  718. If this parameter is NULL, then all
  719. aliases will be returned in ReturnedData.
  720. @param[out] Volatile Upon return of a single command if TRUE indicates
  721. this is stored in a volatile fashion. FALSE otherwise.
  722. @return If Alias is not NULL, it will return a pointer to
  723. the NULL-terminated command for that alias.
  724. If Alias is NULL, ReturnedData points to a ';'
  725. delimited list of alias (e.g.
  726. ReturnedData = "dir;del;copy;mfp") that is NULL-terminated.
  727. @retval NULL An error ocurred.
  728. @retval NULL Alias was not a valid Alias.
  729. **/
  730. typedef
  731. CONST CHAR16 *
  732. (EFIAPI *EFI_SHELL_GET_ALIAS)(
  733. IN CONST CHAR16 *Alias,
  734. OUT BOOLEAN *Volatile OPTIONAL
  735. );
  736. /**
  737. Changes the current directory on the specified device.
  738. If the FileSystem is NULL, and the directory Dir does not contain a file system's
  739. mapped name, this function changes the current working directory. If FileSystem is
  740. NULL and the directory Dir contains a mapped name, then the current file system and
  741. the current directory on that file system are changed.
  742. If FileSystem is not NULL, and Dir is NULL, then this changes the current working file
  743. system.
  744. If FileSystem is not NULL and Dir is not NULL, then this function changes the current
  745. directory on the specified file system.
  746. If the current working directory or the current working file system is changed then the
  747. %cwd% environment variable will be updated.
  748. @param[in] FileSystem A pointer to the file system's mapped name. If NULL, then the current working
  749. directory is changed.
  750. @param[in] Dir Points to the NULL-terminated directory on the device specified by FileSystem.
  751. @retval NULL Current directory does not exist.
  752. @return The current directory.
  753. **/
  754. typedef
  755. EFI_STATUS
  756. (EFIAPI *EFI_SHELL_SET_CUR_DIR) (
  757. IN CONST CHAR16 *FileSystem OPTIONAL,
  758. IN CONST CHAR16 *Dir
  759. );
  760. /**
  761. Sets the environment variable.
  762. This function changes the current value of the specified environment variable. If the
  763. environment variable exists and the Value is an empty string, then the environment
  764. variable is deleted. If the environment variable exists and the Value is not an empty
  765. string, then the value of the environment variable is changed. If the environment
  766. variable does not exist and the Value is an empty string, there is no action. If the
  767. environment variable does not exist and the Value is a non-empty string, then the
  768. environment variable is created and assigned the specified value.
  769. For a description of volatile and non-volatile environment variables, see UEFI Shell
  770. 2.0 specification section 3.6.1.
  771. @param[in] Name Points to the NULL-terminated environment variable name.
  772. @param[in] Value Points to the NULL-terminated environment variable value. If the value is an
  773. empty string then the environment variable is deleted.
  774. @param[in] Volatile Indicates whether the variable is non-volatile (FALSE) or volatile (TRUE).
  775. @retval EFI_SUCCESS The environment variable was successfully updated.
  776. **/
  777. typedef
  778. EFI_STATUS
  779. (EFIAPI *EFI_SHELL_SET_ENV) (
  780. IN CONST CHAR16 *Name,
  781. IN CONST CHAR16 *Value,
  782. IN BOOLEAN Volatile
  783. );
  784. /**
  785. Sets the file information to an opened file handle.
  786. This function changes file information. All file information in the EFI_FILE_INFO
  787. struct will be updated to the passed in data.
  788. @param[in] FileHandle A file handle.
  789. @param[in] FileInfo Points to new file information.
  790. @retval EFI_SUCCESS The information was set.
  791. @retval EFI_NO_MEDIA The device has no medium.
  792. @retval EFI_DEVICE_ERROR The device reported an error.
  793. @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
  794. @retval EFI_WRITE_PROTECTED The file or medium is write-protected.
  795. @retval EFI_ACCESS_DENIED The file was opened read-only.
  796. @retval EFI_VOLUME_FULL The volume is full.
  797. @retval EFI_BAD_BUFFER_SIZE BufferSize is smaller than the size of EFI_FILE_INFO.
  798. **/
  799. typedef
  800. EFI_STATUS
  801. (EFIAPI *EFI_SHELL_SET_FILE_INFO)(
  802. IN SHELL_FILE_HANDLE FileHandle,
  803. IN CONST EFI_FILE_INFO *FileInfo
  804. );
  805. /**
  806. Sets a file's current position.
  807. This function sets the current file position for the handle to the position supplied. With
  808. the exception of seeking to position 0xFFFFFFFFFFFFFFFF, only absolute positioning is
  809. supported, and seeking past the end of the file is allowed (a subsequent write would
  810. grow the file). Seeking to position 0xFFFFFFFFFFFFFFFF causes the current position
  811. to be set to the end of the file.
  812. @param[in] FileHandle The file handle on which requested position will be set.
  813. @param[in] Position Byte position from the start of the file.
  814. @retval EFI_SUCCESS Data was written.
  815. @retval EFI_UNSUPPORTED The seek request for nonzero is not valid on open directories.
  816. **/
  817. typedef
  818. EFI_STATUS
  819. (EFIAPI *EFI_SHELL_SET_FILE_POSITION)(
  820. IN SHELL_FILE_HANDLE FileHandle,
  821. IN UINT64 Position
  822. );
  823. /**
  824. This function creates a mapping for a device path.
  825. @param[in] DevicePath Points to the device path. If this is NULL and Mapping points to a valid mapping,
  826. then the mapping will be deleted.
  827. @param[in] Mapping Points to the NULL-terminated mapping for the device path.
  828. @retval EFI_SUCCESS Mapping created or deleted successfully.
  829. @retval EFI_NO_MAPPING There is no handle that corresponds exactly to DevicePath. See the
  830. boot service function LocateDevicePath().
  831. @retval EFI_ACCESS_DENIED The mapping is a built-in alias.
  832. **/
  833. typedef
  834. EFI_STATUS
  835. (EFIAPI *EFI_SHELL_SET_MAP)(
  836. IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
  837. IN CONST CHAR16 *Mapping
  838. );
  839. /**
  840. Writes data to the file.
  841. This function writes the specified number of bytes to the file at the current file position.
  842. The current file position is advanced the actual number of bytes written, which is
  843. returned in BufferSize. Partial writes only occur when there has been a data error
  844. during the write attempt (such as "volume space full"). The file automatically grows to
  845. hold the data, if required.
  846. Direct writes to opened directories are not supported.
  847. @param[in] FileHandle The opened file handle for writing.
  848. @param[in, out] BufferSize On input, size of Buffer.
  849. @param[in] Buffer The buffer in which data to write.
  850. @retval EFI_SUCCESS Data was written.
  851. @retval EFI_UNSUPPORTED Writes to open directory are not supported.
  852. @retval EFI_NO_MEDIA The device has no media.
  853. @retval EFI_DEVICE_ERROR The device reported an error.
  854. @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
  855. @retval EFI_WRITE_PROTECTED The device is write-protected.
  856. @retval EFI_ACCESS_DENIED The file was open for read only.
  857. @retval EFI_VOLUME_FULL The volume is full.
  858. **/
  859. typedef
  860. EFI_STATUS
  861. (EFIAPI *EFI_SHELL_WRITE_FILE)(
  862. IN SHELL_FILE_HANDLE FileHandle,
  863. IN OUT UINTN *BufferSize,
  864. IN VOID *Buffer
  865. );
  866. //
  867. // EFI_SHELL_PROTOCOL has been updated since UEFI Shell Spec 2.0
  868. // Usage of this protocol will require version checking before attempting
  869. // to use any new members. There is no need to check the version for
  870. // members that existed in UEFI Shell Spec 2.0.
  871. //
  872. // Update below for any future UEFI Shell spec changes to this protocol.
  873. //
  874. // Check EFI_SHELL_PROTOCOL MajorVersion and MinorVersion:
  875. // if ((2 == gEfiShellProtocol->MajorVersion) &&
  876. // (0 == gEfiShellProtocol->MinorVersion)) {
  877. // //
  878. // // Cannot call:
  879. // // RegisterGuidName - UEFI Shell 2.1
  880. // // GetGuidName - UEFI Shell 2.1
  881. // // GetGuidFromName - UEFI Shell 2.1
  882. // // GetEnvEx - UEFI Shell 2.1
  883. // //
  884. // } else {
  885. // //
  886. // // Can use all members
  887. // //
  888. // }
  889. //
  890. typedef struct _EFI_SHELL_PROTOCOL {
  891. EFI_SHELL_EXECUTE Execute;
  892. EFI_SHELL_GET_ENV GetEnv;
  893. EFI_SHELL_SET_ENV SetEnv;
  894. EFI_SHELL_GET_ALIAS GetAlias;
  895. EFI_SHELL_SET_ALIAS SetAlias;
  896. EFI_SHELL_GET_HELP_TEXT GetHelpText;
  897. EFI_SHELL_GET_DEVICE_PATH_FROM_MAP GetDevicePathFromMap;
  898. EFI_SHELL_GET_MAP_FROM_DEVICE_PATH GetMapFromDevicePath;
  899. EFI_SHELL_GET_DEVICE_PATH_FROM_FILE_PATH GetDevicePathFromFilePath;
  900. EFI_SHELL_GET_FILE_PATH_FROM_DEVICE_PATH GetFilePathFromDevicePath;
  901. EFI_SHELL_SET_MAP SetMap;
  902. EFI_SHELL_GET_CUR_DIR GetCurDir;
  903. EFI_SHELL_SET_CUR_DIR SetCurDir;
  904. EFI_SHELL_OPEN_FILE_LIST OpenFileList;
  905. EFI_SHELL_FREE_FILE_LIST FreeFileList;
  906. EFI_SHELL_REMOVE_DUP_IN_FILE_LIST RemoveDupInFileList;
  907. EFI_SHELL_BATCH_IS_ACTIVE BatchIsActive;
  908. EFI_SHELL_IS_ROOT_SHELL IsRootShell;
  909. EFI_SHELL_ENABLE_PAGE_BREAK EnablePageBreak;
  910. EFI_SHELL_DISABLE_PAGE_BREAK DisablePageBreak;
  911. EFI_SHELL_GET_PAGE_BREAK GetPageBreak;
  912. EFI_SHELL_GET_DEVICE_NAME GetDeviceName;
  913. EFI_SHELL_GET_FILE_INFO GetFileInfo;
  914. EFI_SHELL_SET_FILE_INFO SetFileInfo;
  915. EFI_SHELL_OPEN_FILE_BY_NAME OpenFileByName;
  916. EFI_SHELL_CLOSE_FILE CloseFile;
  917. EFI_SHELL_CREATE_FILE CreateFile;
  918. EFI_SHELL_READ_FILE ReadFile;
  919. EFI_SHELL_WRITE_FILE WriteFile;
  920. EFI_SHELL_DELETE_FILE DeleteFile;
  921. EFI_SHELL_DELETE_FILE_BY_NAME DeleteFileByName;
  922. EFI_SHELL_GET_FILE_POSITION GetFilePosition;
  923. EFI_SHELL_SET_FILE_POSITION SetFilePosition;
  924. EFI_SHELL_FLUSH_FILE FlushFile;
  925. EFI_SHELL_FIND_FILES FindFiles;
  926. EFI_SHELL_FIND_FILES_IN_DIR FindFilesInDir;
  927. EFI_SHELL_GET_FILE_SIZE GetFileSize;
  928. EFI_SHELL_OPEN_ROOT OpenRoot;
  929. EFI_SHELL_OPEN_ROOT_BY_HANDLE OpenRootByHandle;
  930. EFI_EVENT ExecutionBreak;
  931. UINT32 MajorVersion;
  932. UINT32 MinorVersion;
  933. // Added for Shell 2.1
  934. EFI_SHELL_REGISTER_GUID_NAME RegisterGuidName;
  935. EFI_SHELL_GET_GUID_NAME GetGuidName;
  936. EFI_SHELL_GET_GUID_FROM_NAME GetGuidFromName;
  937. EFI_SHELL_GET_ENV_EX GetEnvEx;
  938. } EFI_SHELL_PROTOCOL;
  939. extern EFI_GUID gEfiShellProtocolGuid;
  940. enum ShellVersion {
  941. SHELL_MAJOR_VERSION = 2,
  942. SHELL_MINOR_VERSION = 2
  943. };
  944. #endif