]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Include/Library/ShellLib.h
clean up comments
[mirror_edk2.git] / ShellPkg / Include / Library / ShellLib.h
CommitLineData
94b17fa1 1/** @file\r
2 Provides interface to shell functionality for shell commands and applications.\r
3\r
a31bd33c 4Copyright (c) 2006 - 2009, Intel Corporation<BR>\r
94b17fa1 5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#if !defined(__SHELL_LIB__)\r
16#define __SHELL_LIB__\r
17\r
18#include <Protocol/SimpleFileSystem.h>\r
94b17fa1 19#include <Protocol/EfiShell.h>\r
20\r
21/**\r
22 This function will retrieve the information about the file for the handle \r
23 specified and store it in allocated pool memory.\r
24\r
69817bf8 25 This function allocates a buffer to store the file's information. It is the \r
18cefebe 26 caller's responsibility to free the buffer.\r
94b17fa1 27\r
18cefebe 28 @param[in] FileHandle The file handle of the file for which information is \r
29 being requested.\r
94b17fa1 30\r
18cefebe 31 @retval NULL Information could not be retrieved.\r
94b17fa1 32\r
18cefebe 33 @return The information about the file.\r
94b17fa1 34**/\r
35EFI_FILE_INFO*\r
36EFIAPI\r
37ShellGetFileInfo (\r
38 IN EFI_FILE_HANDLE FileHandle\r
39 );\r
40\r
41/**\r
42 This function will set the information about the file for the opened handle \r
43 specified.\r
44\r
18cefebe 45 @param[in] FileHandle The file handle of the file for which information \r
a5bd42b9 46 is being set.\r
94b17fa1 47\r
18cefebe 48 @param[in] FileInfo The infotmation to set.\r
94b17fa1 49\r
9eb53ac3 50 @retval EFI_SUCCESS The information was set.\r
94b17fa1 51 @retval EFI_UNSUPPORTED The InformationType is not known.\r
52 @retval EFI_NO_MEDIA The device has no medium.\r
53 @retval EFI_DEVICE_ERROR The device reported an error.\r
54 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
55 @retval EFI_WRITE_PROTECTED The file or medium is write protected.\r
56 @retval EFI_ACCESS_DENIED The file was opened read only.\r
57 @retval EFI_VOLUME_FULL The volume is full.\r
58**/\r
59EFI_STATUS\r
60EFIAPI\r
61ShellSetFileInfo (\r
62 IN EFI_FILE_HANDLE FileHandle,\r
63 IN EFI_FILE_INFO *FileInfo\r
64 );\r
65\r
66/**\r
67 This function will open a file or directory referenced by DevicePath.\r
68\r
69 This function opens a file with the open mode according to the file path. The \r
70 Attributes is valid only for EFI_FILE_MODE_CREATE.\r
71\r
18cefebe 72 @param[in] FilePath On input the device path to the file. On output \r
73 the remaining device path.\r
74 @param[out] DeviceHandle Pointer to the system device handle.\r
75 @param[out] FileHandle Pointer to the file handle.\r
76 @param[in] OpenMode The mode to open the file with.\r
77 @param[in] Attributes The file's file attributes.\r
94b17fa1 78\r
79 @retval EFI_SUCCESS The information was set.\r
80 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.\r
81 @retval EFI_UNSUPPORTED Could not open the file path. \r
82 @retval EFI_NOT_FOUND The specified file could not be found on the \r
83 device or the file system could not be found on \r
84 the device.\r
85 @retval EFI_NO_MEDIA The device has no medium.\r
86 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the \r
87 medium is no longer supported.\r
88 @retval EFI_DEVICE_ERROR The device reported an error.\r
89 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
90 @retval EFI_WRITE_PROTECTED The file or medium is write protected.\r
91 @retval EFI_ACCESS_DENIED The file was opened read only.\r
92 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the \r
93 file.\r
94 @retval EFI_VOLUME_FULL The volume is full.\r
95**/\r
96EFI_STATUS\r
97EFIAPI\r
98ShellOpenFileByDevicePath(\r
99 IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath,\r
100 OUT EFI_HANDLE *DeviceHandle,\r
101 OUT EFI_FILE_HANDLE *FileHandle,\r
102 IN UINT64 OpenMode,\r
103 IN UINT64 Attributes\r
104 );\r
105\r
106/**\r
107 This function will open a file or directory referenced by filename.\r
108\r
69817bf8 109 If return is EFI_SUCCESS, the Filehandle is the opened file's handle; \r
94b17fa1 110 otherwise, the Filehandle is NULL. The Attributes is valid only for \r
111 EFI_FILE_MODE_CREATE.\r
112\r
18cefebe 113 @param[in] FileName Pointer to file name.\r
114 @param[out] FileHandle Pointer to the file handle.\r
115 @param[in] OpenMode The mode to open the file with.\r
116 @param[in] Attributes The file's file attributes.\r
94b17fa1 117\r
9eb53ac3 118 @retval EFI_SUCCESS The information was set.\r
94b17fa1 119 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.\r
9eb53ac3 120 @retval EFI_UNSUPPORTED Could not open the file path. \r
94b17fa1 121 @retval EFI_NOT_FOUND The specified file could not be found on the \r
122 device or the file system could not be found \r
123 on the device.\r
9eb53ac3 124 @retval EFI_NO_MEDIA The device has no medium.\r
125 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the \r
94b17fa1 126 medium is no longer supported.\r
9eb53ac3 127 @retval EFI_DEVICE_ERROR The device reported an error.\r
94b17fa1 128 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
9eb53ac3 129 @retval EFI_WRITE_PROTECTED The file or medium is write protected.\r
130 @retval EFI_ACCESS_DENIED The file was opened read only.\r
94b17fa1 131 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the \r
132 file.\r
9eb53ac3 133 @retval EFI_VOLUME_FULL The volume is full.\r
94b17fa1 134**/\r
135EFI_STATUS\r
136EFIAPI\r
137ShellOpenFileByName(\r
b82bfcc1 138 IN CONST CHAR16 *FilePath,\r
94b17fa1 139 OUT EFI_FILE_HANDLE *FileHandle,\r
140 IN UINT64 OpenMode,\r
141 IN UINT64 Attributes\r
142 );\r
143\r
144/**\r
18cefebe 145 This function creates a directory.\r
94b17fa1 146\r
147 If return is EFI_SUCCESS, the Filehandle is the opened directory's handle; \r
148 otherwise, the Filehandle is NULL. If the directory already existed, this \r
149 function opens the existing directory.\r
150\r
18cefebe 151 @param[in] DirectoryName Pointer to Directory name.\r
152 @param[out] FileHandle Pointer to the file handle.\r
94b17fa1 153\r
154 @retval EFI_SUCCESS The information was set.\r
155 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.\r
125c2cf4 156 @retval EFI_UNSUPPORTED Could not open the file path. \r
94b17fa1 157 @retval EFI_NOT_FOUND The specified file could not be found on the \r
158 device or the file system could not be found \r
159 on the device.\r
9eb53ac3 160 @retval EFI_NO_MEDIA The device has no medium.\r
161 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the \r
94b17fa1 162 medium is no longer supported.\r
9eb53ac3 163 @retval EFI_DEVICE_ERROR The device reported an error.\r
94b17fa1 164 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
9eb53ac3 165 @retval EFI_WRITE_PROTECTED The file or medium is write protected.\r
166 @retval EFI_ACCESS_DENIED The file was opened read only.\r
94b17fa1 167 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the \r
168 file.\r
9eb53ac3 169 @retval EFI_VOLUME_FULL The volume is full.\r
94b17fa1 170**/\r
171EFI_STATUS\r
172EFIAPI\r
173ShellCreateDirectory(\r
b82bfcc1 174 IN CONST CHAR16 *DirectoryName,\r
94b17fa1 175 OUT EFI_FILE_HANDLE *FileHandle\r
176 );\r
177\r
178/**\r
179 This function reads information from an opened file.\r
180\r
181 If FileHandle is not a directory, the function reads the requested number of \r
69817bf8 182 bytes from the file at the file's current position and returns them in Buffer. \r
94b17fa1 183 If the read goes beyond the end of the file, the read length is truncated to the\r
69817bf8 184 end of the file. The file's current position is increased by the number of bytes \r
94b17fa1 185 returned. If FileHandle is a directory, the function reads the directory entry \r
69817bf8 186 at the file's current position and returns the entry in Buffer. If the Buffer \r
94b17fa1 187 is not large enough to hold the current directory entry, then \r
188 EFI_BUFFER_TOO_SMALL is returned and the current file position is not updated. \r
189 BufferSize is set to be the size of the buffer needed to read the entry. On \r
190 success, the current position is updated to the next directory entry. If there \r
191 are no more directory entries, the read returns a zero-length buffer. \r
192 EFI_FILE_INFO is the structure returned as the directory entry.\r
193\r
18cefebe 194 @param[in] FileHandle The opened file handle.\r
195 @param[in] ReadSize On input the size of buffer in bytes. On return \r
94b17fa1 196 the number of bytes written.\r
18cefebe 197 @param[out] Buffer The buffer to put read data into.\r
94b17fa1 198\r
125c2cf4 199 @retval EFI_SUCCESS Data was read.\r
200 @retval EFI_NO_MEDIA The device has no media.\r
201 @retval EFI_DEVICE_ERROR The device reported an error.\r
202 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
203 @retval EFI_BUFFER_TO_SMALL Buffer is too small. ReadSize contains required \r
94b17fa1 204 size.\r
205\r
206**/\r
207EFI_STATUS\r
208EFIAPI\r
209ShellReadFile(\r
210 IN EFI_FILE_HANDLE FileHandle,\r
211 IN OUT UINTN *ReadSize,\r
212 OUT VOID *Buffer\r
213 );\r
214\r
215/**\r
216 Write data to a file.\r
217\r
218 This function writes the specified number of bytes to the file at the current \r
219 file position. The current file position is advanced the actual number of bytes \r
220 written, which is returned in BufferSize. Partial writes only occur when there \r
69817bf8 221 has been a data error during the write attempt (such as "volume space full"). \r
94b17fa1 222 The file is automatically grown to hold the data if required. Direct writes to \r
223 opened directories are not supported.\r
224\r
18cefebe 225 @param[in] FileHandle The opened file for writing.\r
94b17fa1 226\r
18cefebe 227 @param[in] BufferSize On input the number of bytes in Buffer. On output\r
94b17fa1 228 the number of bytes written.\r
229\r
18cefebe 230 @param[in] Buffer The buffer containing data to write is stored.\r
94b17fa1 231\r
125c2cf4 232 @retval EFI_SUCCESS Data was written.\r
233 @retval EFI_UNSUPPORTED Writes to an open directory are not supported.\r
234 @retval EFI_NO_MEDIA The device has no media.\r
235 @retval EFI_DEVICE_ERROR The device reported an error.\r
236 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
237 @retval EFI_WRITE_PROTECTED The device is write-protected.\r
238 @retval EFI_ACCESS_DENIED The file was open for read only.\r
239 @retval EFI_VOLUME_FULL The volume is full.\r
94b17fa1 240**/\r
241EFI_STATUS\r
242EFIAPI\r
243ShellWriteFile(\r
244 IN EFI_FILE_HANDLE FileHandle,\r
245 IN OUT UINTN *BufferSize,\r
08d7f8e8 246 IN VOID *Buffer\r
94b17fa1 247 );\r
248\r
249/** \r
250 Close an open file handle.\r
251\r
69817bf8 252 This function closes a specified file handle. All "dirty" cached file data is \r
94b17fa1 253 flushed to the device, and the file is closed. In all cases the handle is \r
254 closed.\r
255\r
18cefebe 256 @param[in] FileHandle The file handle to close.\r
94b17fa1 257\r
125c2cf4 258 @retval EFI_SUCCESS The file handle was closed sucessfully.\r
259 @retval INVALID_PARAMETER One of the parameters has an invalid value.\r
94b17fa1 260**/\r
261EFI_STATUS\r
262EFIAPI\r
263ShellCloseFile (\r
264 IN EFI_FILE_HANDLE *FileHandle\r
265 );\r
266\r
267/**\r
268 Delete a file and close the handle\r
269\r
270 This function closes and deletes a file. In all cases the file handle is closed.\r
271 If the file cannot be deleted, the warning code EFI_WARN_DELETE_FAILURE is \r
272 returned, but the handle is still closed.\r
273\r
18cefebe 274 @param[in] FileHandle The file handle to delete.\r
94b17fa1 275\r
125c2cf4 276 @retval EFI_SUCCESS The file was closed sucessfully.\r
277 @retval EFI_WARN_DELETE_FAILURE The handle was closed, but the file was not \r
278 deleted.\r
279 @retval INVALID_PARAMETER One of the parameters has an invalid value.\r
94b17fa1 280**/\r
281EFI_STATUS\r
282EFIAPI\r
283ShellDeleteFile (\r
284 IN EFI_FILE_HANDLE *FileHandle\r
285 );\r
286\r
287/**\r
288 Set the current position in a file.\r
289\r
290 This function sets the current file position for the handle to the position \r
291 supplied. With the exception of seeking to position 0xFFFFFFFFFFFFFFFF, only\r
292 absolute positioning is supported, and seeking past the end of the file is \r
293 allowed (a subsequent write would grow the file). Seeking to position \r
294 0xFFFFFFFFFFFFFFFF causes the current position to be set to the end of the file.\r
295 If FileHandle is a directory, the only position that may be set is zero. This \r
296 has the effect of starting the read process of the directory entries over.\r
297\r
18cefebe 298 @param[in] FileHandle The file handle on which the position is being set.\r
94b17fa1 299\r
18cefebe 300 @param[in] Position Byte position from begining of file.\r
94b17fa1 301\r
302 @retval EFI_SUCCESS Operation completed sucessfully.\r
18cefebe 303 @retval EFI_UNSUPPORTED The seek request for non-zero is not valid on \r
94b17fa1 304 directories.\r
305 @retval INVALID_PARAMETER One of the parameters has an invalid value.\r
306**/\r
307EFI_STATUS\r
308EFIAPI\r
309ShellSetFilePosition (\r
310 IN EFI_FILE_HANDLE FileHandle,\r
311 IN UINT64 Position\r
312 );\r
313\r
314/** \r
315 Gets a file's current position\r
316\r
317 This function retrieves the current file position for the file handle. For \r
318 directories, the current file position has no meaning outside of the file \r
319 system driver and as such the operation is not supported. An error is returned\r
320 if FileHandle is a directory.\r
321\r
18cefebe 322 @param[in] FileHandle The open file handle on which to get the position.\r
323 @param[out] Position Byte position from begining of file.\r
94b17fa1 324\r
18cefebe 325 @retval EFI_SUCCESS The operation completed sucessfully.\r
94b17fa1 326 @retval INVALID_PARAMETER One of the parameters has an invalid value.\r
18cefebe 327 @retval EFI_UNSUPPORTED The request is not valid on directories.\r
94b17fa1 328**/\r
329EFI_STATUS\r
330EFIAPI\r
331ShellGetFilePosition (\r
332 IN EFI_FILE_HANDLE FileHandle,\r
333 OUT UINT64 *Position\r
334 );\r
335\r
336/**\r
337 Flushes data on a file\r
338 \r
339 This function flushes all modified data associated with a file to a device.\r
340\r
18cefebe 341 @param[in] FileHandle The file handle on which to flush data.\r
94b17fa1 342\r
343 @retval EFI_SUCCESS The data was flushed.\r
344 @retval EFI_NO_MEDIA The device has no media.\r
345 @retval EFI_DEVICE_ERROR The device reported an error.\r
346 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
347 @retval EFI_WRITE_PROTECTED The file or medium is write protected.\r
348 @retval EFI_ACCESS_DENIED The file was opened for read only.\r
349**/\r
350EFI_STATUS\r
351EFIAPI\r
352ShellFlushFile (\r
353 IN EFI_FILE_HANDLE FileHandle\r
354 );\r
355\r
356/**\r
357 Retrieves the first file from a directory\r
358\r
359 This function takes an open directory handle and gets the first file \r
360 in the directory's info. Caller can use ShellFindNextFile() to get \r
361 subsequent files.\r
362\r
d2b4564b 363 Caller must use FreePool on *Buffer opon completion of all file searching.\r
364\r
18cefebe 365 @param[in] DirHandle The file handle of the directory to search\r
366 @param[out] Buffer Pointer to pointer to buffer for file's information\r
94b17fa1 367\r
368 @retval EFI_SUCCESS Found the first file.\r
369 @retval EFI_NOT_FOUND Cannot find the directory.\r
370 @retval EFI_NO_MEDIA The device has no media.\r
371 @retval EFI_DEVICE_ERROR The device reported an error.\r
372 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
373 @return ShellReadFile\r
374**/\r
375EFI_STATUS\r
376EFIAPI\r
377ShellFindFirstFile (\r
378 IN EFI_FILE_HANDLE DirHandle,\r
d2b4564b 379 OUT EFI_FILE_INFO **Buffer\r
94b17fa1 380 );\r
381\r
382/**\r
383 Retrieves the next file in a directory.\r
384\r
385 To use this function, caller must call the ShellFindFirstFile() to get the \r
386 first file, and then use this function get other files. This function can be \r
387 called for several times to get each file's information in the directory. If \r
388 the call of ShellFindNextFile() got the last file in the directory, the next \r
389 call of this function has no file to get. *NoFile will be set to TRUE and the \r
390 data in Buffer is meaningless. \r
391\r
18cefebe 392 @param[in] DirHandle The file handle of the directory.\r
393 @param[out] Buffer Pointer to buffer for file's information.\r
394 @param[out] NoFile Pointer to boolean when last file is found.\r
94b17fa1 395\r
396 @retval EFI_SUCCESS Found the next file.\r
397 @retval EFI_NO_MEDIA The device has no media.\r
398 @retval EFI_DEVICE_ERROR The device reported an error.\r
399 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
400**/\r
401EFI_STATUS\r
402EFIAPI\r
403ShellFindNextFile(\r
404 IN EFI_FILE_HANDLE DirHandle,\r
405 OUT EFI_FILE_INFO *Buffer,\r
406 OUT BOOLEAN *NoFile\r
407 );\r
408\r
409/**\r
410 Retrieve the size of a file.\r
411\r
69817bf8 412 This function extracts the file size info from the FileHandle's EFI_FILE_INFO \r
94b17fa1 413 data.\r
414\r
18cefebe 415 @param[in] FileHandle The file handle from which size is retrieved.\r
416 @param[out] Size Pointer to size.\r
94b17fa1 417\r
125c2cf4 418 @retval EFI_SUCCESS The operation was completed sucessfully.\r
a31bd33c 419 @retval EFI_DEVICE_ERROR Cannot access the file.\r
94b17fa1 420**/\r
421EFI_STATUS\r
422EFIAPI\r
423ShellGetFileSize (\r
424 IN EFI_FILE_HANDLE FileHandle,\r
425 OUT UINT64 *Size\r
426 );\r
427\r
428/**\r
429 Retrieves the status of the break execution flag\r
430\r
18cefebe 431 This function is useful to check whether the application is being asked to halt by the shell.\r
94b17fa1 432\r
433 @retval TRUE the execution break is enabled\r
434 @retval FALSE the execution break is not enabled\r
435**/\r
436BOOLEAN\r
437EFIAPI\r
438ShellGetExecutionBreakFlag(\r
439 VOID\r
440 );\r
441\r
442/**\r
125c2cf4 443 Return the value of an environment variable.\r
94b17fa1 444\r
125c2cf4 445 This function gets the value of the environment variable set by the \r
446 ShellSetEnvironmentVariable function.\r
94b17fa1 447\r
18cefebe 448 @param[in] EnvKey The key name of the environment variable.\r
94b17fa1 449\r
a31bd33c 450 @retval NULL The named environment variable does not exist.\r
125c2cf4 451 @return != NULL pointer to the value of the environment variable.\r
94b17fa1 452**/\r
453CONST CHAR16*\r
454EFIAPI\r
455ShellGetEnvironmentVariable (\r
9b3bf083 456 IN CONST CHAR16 *EnvKey\r
94b17fa1 457 );\r
458\r
459/**\r
18cefebe 460 Set the value of an environment variable.\r
94b17fa1 461\r
125c2cf4 462 This function changes the current value of the specified environment variable. If the\r
463 environment variable exists and the Value is an empty string, then the environment\r
464 variable is deleted. If the environment variable exists and the Value is not an empty\r
465 string, then the value of the environment variable is changed. If the environment\r
466 variable does not exist and the Value is an empty string, there is no action. If the\r
467 environment variable does not exist and the Value is a non-empty string, then the\r
468 environment variable is created and assigned the specified value.\r
94b17fa1 469\r
470 This is not supported pre-UEFI Shell 2.0.\r
471\r
18cefebe 472 @param[in] EnvKey The key name of the environment variable.\r
473 @param[in] EnvVal The Value of the environment variable\r
474 @param[in] Volatile Indicates whether the variable is non-volatile (FALSE) or volatile (TRUE).\r
94b17fa1 475\r
476 @retval EFI_SUCCESS the operation was completed sucessfully\r
477 @retval EFI_UNSUPPORTED This operation is not allowed in pre UEFI 2.0 Shell environments\r
478**/\r
479EFI_STATUS\r
480EFIAPI\r
481ShellSetEnvironmentVariable (\r
482 IN CONST CHAR16 *EnvKey,\r
483 IN CONST CHAR16 *EnvVal,\r
484 IN BOOLEAN Volatile\r
485 );\r
486\r
487/**\r
125c2cf4 488 Cause the shell to parse and execute a command line.\r
94b17fa1 489\r
490 This function creates a nested instance of the shell and executes the specified\r
125c2cf4 491 command (CommandLine) with the specified environment (Environment). Upon return,\r
492 the status code returned by the specified command is placed in StatusCode.\r
493 If Environment is NULL, then the current environment is used and all changes made\r
494 by the commands executed will be reflected in the current environment. If the\r
495 Environment is non-NULL, then the changes made will be discarded.\r
496 The CommandLine is executed from the current working directory on the current\r
497 device.\r
94b17fa1 498\r
18cefebe 499 EnvironmentVariables and Status are only supported for UEFI Shell 2.0 (or later).\r
125c2cf4 500 Output is only supported for pre-UEFI Shell 2.0\r
94b17fa1 501\r
18cefebe 502 @param[in] ImageHandle Parent image that is starting the operation.\r
503 @param[in] CommandLine Pointer to null terminated command line.\r
504 @param[in] Output True to display debug output. False to hide it.\r
505 @param[in] EnvironmentVariables Optional pointer to array of environment variables\r
506 in the form "x=y". If NULL current set is used.\r
507 @param[out] Status The status of the run command line.\r
94b17fa1 508\r
18cefebe 509 @retval EFI_SUCCESS The operation completed sucessfully. Status\r
510 contains the status code returned.\r
511 @retval EFI_INVALID_PARAMETER A parameter contains an invalid value.\r
512 @retval EFI_OUT_OF_RESOURCES Out of resources.\r
513 @retval EFI_UNSUPPORTED The operation is not allowed.\r
94b17fa1 514**/\r
515EFI_STATUS\r
516EFIAPI\r
517ShellExecute (\r
518 IN EFI_HANDLE *ParentHandle,\r
519 IN CHAR16 *CommandLine,\r
520 IN BOOLEAN Output,\r
521 IN CHAR16 **EnvironmentVariables,\r
522 OUT EFI_STATUS *Status\r
523 );\r
524\r
525/**\r
a31bd33c 526 Retreives the current directory path.\r
94b17fa1 527\r
69817bf8 528 If the DeviceName is NULL, it returns the current device's current directory \r
94b17fa1 529 name. If the DeviceName is not NULL, it returns the current directory name \r
530 on specified drive.\r
531\r
18cefebe 532 @param[in] DeviceName The name of the file system to get directory on.\r
94b17fa1 533\r
a31bd33c 534 @retval NULL The directory does not exist.\r
18cefebe 535 @retval != NULL The directory.\r
94b17fa1 536**/\r
537CONST CHAR16*\r
538EFIAPI\r
539ShellGetCurrentDir (\r
540 IN CHAR16 *DeviceName OPTIONAL\r
541 );\r
542\r
543/**\r
125c2cf4 544 Sets (enabled or disabled) the page break mode.\r
94b17fa1 545\r
125c2cf4 546 When page break mode is enabled the screen will stop scrolling \r
94b17fa1 547 and wait for operator input before scrolling a subsequent screen.\r
548\r
18cefebe 549 @param[in] CurrentState TRUE to enable and FALSE to disable.\r
94b17fa1 550**/\r
551VOID \r
552EFIAPI\r
553ShellSetPageBreakMode (\r
554 IN BOOLEAN CurrentState\r
555 );\r
556\r
557/**\r
558 Opens a group of files based on a path.\r
559\r
560 This function uses the Arg to open all the matching files. Each matched \r
561 file has a SHELL_FILE_ARG structure to record the file information. These \r
562 structures are placed on the list ListHead. Users can get the SHELL_FILE_ARG \r
563 structures from ListHead to access each file. This function supports wildcards\r
125c2cf4 564 and will process '?' and '*' as such. The list must be freed with a call to \r
94b17fa1 565 ShellCloseFileMetaArg().\r
566\r
eb646684 567 If you are NOT appending to an existing list *ListHead must be NULL. If \r
568 *ListHead is NULL then it must be callee freed.\r
94b17fa1 569\r
18cefebe 570 @param[in] Arg Pointer to path string.\r
571 @param[in] OpenMode Mode to open files with.\r
572 @param[in] ListHead Head of linked list of results.\r
94b17fa1 573\r
125c2cf4 574 @retval EFI_SUCCESS The operation was sucessful and the list head \r
575 contains the list of opened files.\r
a31bd33c 576 @retval != EFI_SUCCESS The operation failed.\r
94b17fa1 577\r
578 @sa InternalShellConvertFileListType\r
579**/\r
580EFI_STATUS\r
581EFIAPI\r
582ShellOpenFileMetaArg (\r
583 IN CHAR16 *Arg,\r
584 IN UINT64 OpenMode,\r
585 IN OUT EFI_SHELL_FILE_INFO **ListHead\r
586 );\r
587\r
588/**\r
a31bd33c 589 Free the linked list returned from ShellOpenFileMetaArg.\r
94b17fa1 590\r
18cefebe 591 @param[in] ListHead The pointer to free.\r
94b17fa1 592\r
a31bd33c 593 @retval EFI_SUCCESS The operation was sucessful.\r
594 @retval EFI_INVALID_PARAMETER A parameter was invalid.\r
94b17fa1 595**/\r
596EFI_STATUS\r
597EFIAPI\r
598ShellCloseFileMetaArg (\r
599 IN OUT EFI_SHELL_FILE_INFO **ListHead\r
600 );\r
601\r
125c2cf4 602/**\r
603 Find a file by searching the CWD and then the path.\r
604\r
a31bd33c 605 If FileName is NULL, then ASSERT.\r
125c2cf4 606\r
a31bd33c 607 If the return value is not NULL then the memory must be caller freed.\r
125c2cf4 608\r
18cefebe 609 @param[in] FileName Filename string.\r
125c2cf4 610\r
a31bd33c 611 @retval NULL The file was not found.\r
18cefebe 612 @retval !NULL The path to the file.\r
125c2cf4 613**/\r
614CHAR16 *\r
615EFIAPI\r
616ShellFindFilePath (\r
617 IN CONST CHAR16 *FileName\r
618 );\r
619\r
94b17fa1 620typedef enum {\r
18cefebe 621 TypeFlag = 0, ///< A flag that is present or not present only (IE "-a").\r
622 TypeValue, ///< A flag that has some data following it with a space (IE "-a 1").\r
623 TypePosition, ///< Some data that did not follow a parameter (IE "filename.txt").\r
624 TypeStart, ///< A flag that has variable value appended to the end (IE "-ad", "-afd", "-adf", etc...).\r
625 TypeDoubleValue, ///< A flag that has 2 space seperated value data following it (IE "-a 1 2").\r
626 TypeMaxValue, ///< A flag followed by all the command line data before the next flag.\r
94b17fa1 627 TypeMax,\r
628} ParamType;\r
629\r
630typedef struct {\r
631 CHAR16 *Name;\r
632 ParamType Type;\r
633} SHELL_PARAM_ITEM;\r
634\r
d2b4564b 635\r
636/// Helper structure for no parameters (besides -? and -b)\r
637extern SHELL_PARAM_ITEM EmptyParamList[];\r
638\r
94b17fa1 639/**\r
640 Checks the command line arguments passed against the list of valid ones. \r
641 Optionally removes NULL values first.\r
642 \r
643 If no initialization is required, then return RETURN_SUCCESS.\r
644 \r
18cefebe 645 @param[in] CheckList Pointer to list of parameters to check.\r
646 @param[out] CheckPackage Package of checked values.\r
647 @param[out] ProblemParam Optional pointer to pointer to unicode string for \r
94b17fa1 648 the paramater that caused failure.\r
18cefebe 649 @param[in] AutoPageBreak Will automatically set PageBreakEnabled.\r
650 @param[in] AlwaysAllowNumbers Will never fail for number based flags.\r
94b17fa1 651\r
652 @retval EFI_SUCCESS The operation completed sucessfully.\r
a31bd33c 653 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r
654 @retval EFI_INVALID_PARAMETER A parameter was invalid.\r
18cefebe 655 @retval EFI_VOLUME_CORRUPTED The command line was corrupt. An argument was \r
a31bd33c 656 duplicated. The duplicated command line argument \r
94b17fa1 657 was returned in ProblemParam if provided.\r
a31bd33c 658 @retval EFI_DEVICE_ERROR The commands contained 2 opposing arguments. One\r
94b17fa1 659 of the command line arguments was returned in \r
660 ProblemParam if provided.\r
125c2cf4 661 @retval EFI_NOT_FOUND A argument required a value that was missing. \r
a31bd33c 662 The invalid command line argument was returned in\r
94b17fa1 663 ProblemParam if provided.\r
664**/\r
665EFI_STATUS\r
666EFIAPI\r
2247dde4 667ShellCommandLineParseEx (\r
94b17fa1 668 IN CONST SHELL_PARAM_ITEM *CheckList,\r
669 OUT LIST_ENTRY **CheckPackage,\r
670 OUT CHAR16 **ProblemParam OPTIONAL,\r
2247dde4 671 IN BOOLEAN AutoPageBreak,\r
672 IN BOOLEAN AlwaysAllowNumbers\r
94b17fa1 673 );\r
674\r
18cefebe 675/// Make it easy to upgrade from older versions of the shell library.\r
2247dde4 676#define ShellCommandLineParse(CheckList,CheckPackage,ProblemParam,AutoPageBreak) ShellCommandLineParseEx(CheckList,CheckPackage,ProblemParam,AutoPageBreak,FALSE)\r
677\r
94b17fa1 678/**\r
679 Frees shell variable list that was returned from ShellCommandLineParse.\r
680\r
681 This function will free all the memory that was used for the CheckPackage\r
682 list of postprocessed shell arguments.\r
683\r
a31bd33c 684 If CheckPackage is NULL, then return.\r
94b17fa1 685\r
18cefebe 686 @param[in] CheckPackage The list to de-allocate.\r
94b17fa1 687 **/\r
688VOID\r
689EFIAPI\r
690ShellCommandLineFreeVarList (\r
691 IN LIST_ENTRY *CheckPackage\r
692 );\r
693\r
694/**\r
a31bd33c 695 Checks for presence of a flag parameter.\r
94b17fa1 696\r
18cefebe 697 Flag arguments are in the form of "-<Key>" or "/<Key>", but do not have a value following the key.\r
94b17fa1 698\r
18cefebe 699 If CheckPackage is NULL then return FALSE.\r
700 If KeyString is NULL then ASSERT().\r
94b17fa1 701 \r
18cefebe 702 @param[in] CheckPackage The package of parsed command line arguments.\r
703 @param[in] KeyString The Key of the command line argument to check for.\r
94b17fa1 704\r
a31bd33c 705 @retval TRUE The flag is on the command line.\r
706 @retval FALSE The flag is not on the command line.\r
94b17fa1 707 **/\r
708BOOLEAN\r
709EFIAPI\r
710ShellCommandLineGetFlag (\r
711 IN CONST LIST_ENTRY *CheckPackage,\r
712 IN CHAR16 *KeyString\r
713 );\r
714\r
715/**\r
a31bd33c 716 Returns value from command line argument.\r
94b17fa1 717\r
18cefebe 718 Value parameters are in the form of "-<Key> value" or "/<Key> value".\r
94b17fa1 719 \r
a31bd33c 720 If CheckPackage is NULL, then return NULL.\r
94b17fa1 721\r
36a9d672 722 @param[in] CheckPackage The package of parsed command line arguments.\r
723 @param[in] KeyString The Key of the command line argument to check for.\r
94b17fa1 724\r
a31bd33c 725 @retval NULL The flag is not on the command line.\r
726 @retval !=NULL Pointer to unicode string of the value.\r
94b17fa1 727 **/\r
728CONST CHAR16*\r
729EFIAPI\r
730ShellCommandLineGetValue (\r
731 IN CONST LIST_ENTRY *CheckPackage,\r
732 IN CHAR16 *KeyString\r
733 );\r
734\r
735/**\r
a31bd33c 736 Returns raw value from command line argument.\r
94b17fa1 737\r
a31bd33c 738 Raw value parameters are in the form of "value" in a specific position in the list.\r
94b17fa1 739 \r
36a9d672 740 If CheckPackage is NULL, then return NULL.\r
94b17fa1 741\r
36a9d672 742 @param[in] CheckPackage The package of parsed command line arguments.\r
743 @param[in] Position The position of the value.\r
94b17fa1 744\r
a31bd33c 745 @retval NULL The flag is not on the command line.\r
746 @retval !=NULL Pointer to unicode string of the value.\r
94b17fa1 747 **/\r
748CONST CHAR16*\r
749EFIAPI\r
750ShellCommandLineGetRawValue (\r
751 IN CONST LIST_ENTRY *CheckPackage,\r
752 IN UINT32 Position\r
753 );\r
754\r
2247dde4 755/**\r
a31bd33c 756 Returns the number of command line value parameters that were parsed. \r
2247dde4 757 \r
a31bd33c 758 This will not include flags.\r
2247dde4 759\r
18cefebe 760 @retval (UINTN)-1 No parsing has ocurred.\r
761 @return The number of value parameters found.\r
2247dde4 762**/\r
763UINTN\r
764EFIAPI\r
765ShellCommandLineGetCount(\r
766 VOID\r
767 );\r
768\r
36a9d672 769/**\r
770 Determins if a parameter is duplicated.\r
771\r
772 If Param is not NULL then it will point to a callee allocated string buffer \r
773 with the parameter value if a duplicate is found.\r
774\r
775 If CheckPackage is NULL, then ASSERT.\r
776\r
777 @param[in] CheckPackage The package of parsed command line arguments.\r
778 @param[out] Param Upon finding one, a pointer to the duplicated parameter.\r
779\r
780 @retval EFI_SUCCESS No parameters were duplicated.\r
781 @retval EFI_DEVICE_ERROR A duplicate was found.\r
782 **/\r
783EFI_STATUS\r
784EFIAPI\r
785ShellCommandLineCheckDuplicate (\r
786 IN CONST LIST_ENTRY *CheckPackage,\r
787 OUT CHAR16 **Param\r
788 );\r
789\r
d2b4564b 790/**\r
791 This function causes the shell library to initialize itself. If the shell library\r
792 is already initialized it will de-initialize all the current protocol poitners and\r
793 re-populate them again.\r
794\r
795 When the library is used with PcdShellLibAutoInitialize set to true this function\r
796 will return EFI_SUCCESS and perform no actions.\r
797\r
798 This function is intended for internal access for shell commands only.\r
799\r
800 @retval EFI_SUCCESS the initialization was complete sucessfully\r
801\r
802**/\r
803EFI_STATUS\r
804EFIAPI\r
805ShellInitialize (\r
125c2cf4 806 VOID\r
d2b4564b 807 );\r
808\r
b1f95a06 809/**\r
810 Print at a specific location on the screen.\r
811\r
a5bd42b9 812 This function will move the cursor to a given screen location and print the specified string.\r
b1f95a06 813 \r
814 If -1 is specified for either the Row or Col the current screen location for BOTH \r
a5bd42b9 815 will be used.\r
b1f95a06 816\r
a31bd33c 817 If either Row or Col is out of range for the current console, then ASSERT.\r
818 If Format is NULL, then ASSERT.\r
b1f95a06 819\r
820 In addition to the standard %-based flags as supported by UefiLib Print() this supports \r
821 the following additional flags:\r
822 %N - Set output attribute to normal\r
823 %H - Set output attribute to highlight\r
824 %E - Set output attribute to error\r
825 %B - Set output attribute to blue color\r
826 %V - Set output attribute to green color\r
827\r
828 Note: The background color is controlled by the shell command cls.\r
829\r
18cefebe 830 @param[in] Row The row to print at.\r
831 @param[in] Col The column to print at.\r
832 @param[in] Format The format string.\r
b1f95a06 833\r
18cefebe 834 @return The number of characters printed to the screen.\r
b1f95a06 835**/\r
836\r
837UINTN\r
838EFIAPI\r
839ShellPrintEx(\r
840 IN INT32 Col OPTIONAL,\r
841 IN INT32 Row OPTIONAL,\r
842 IN CONST CHAR16 *Format,\r
843 ...\r
844 );\r
845\r
2247dde4 846/**\r
847 Print at a specific location on the screen.\r
848\r
a5bd42b9 849 This function will move the cursor to a given screen location and print the specified string.\r
2247dde4 850 \r
851 If -1 is specified for either the Row or Col the current screen location for BOTH \r
a5bd42b9 852 will be used.\r
2247dde4 853\r
a5bd42b9 854 If either Row or Col is out of range for the current console, then ASSERT.\r
855 If Format is NULL, then ASSERT.\r
2247dde4 856\r
857 In addition to the standard %-based flags as supported by UefiLib Print() this supports \r
858 the following additional flags:\r
18cefebe 859 %N - Set output attribute to normal.\r
860 %H - Set output attribute to highlight.\r
861 %E - Set output attribute to error.\r
862 %B - Set output attribute to blue color.\r
863 %V - Set output attribute to green color.\r
2247dde4 864\r
865 Note: The background color is controlled by the shell command cls.\r
866\r
18cefebe 867 @param[in] Row The row to print at.\r
868 @param[in] Col The column to print at.\r
869 @param[in] HiiFormatStringId The format string Id for getting from Hii.\r
870 @param[in] HiiFormatHandle The format string Handle for getting from Hii.\r
2247dde4 871\r
18cefebe 872 @return the number of characters printed to the screen.\r
2247dde4 873**/\r
874UINTN\r
875EFIAPI\r
876ShellPrintHiiEx(\r
877 IN INT32 Col OPTIONAL,\r
878 IN INT32 Row OPTIONAL,\r
879 IN CONST EFI_STRING_ID HiiFormatStringId,\r
880 IN CONST EFI_HANDLE HiiFormatHandle,\r
881 ...\r
882 );\r
883\r
884/**\r
a31bd33c 885 Function to determine if a given filename represents a directory.\r
2247dde4 886\r
18cefebe 887 If DirName is NULL, then ASSERT.\r
888\r
2247dde4 889 @param[in] DirName Path to directory to test.\r
890\r
a31bd33c 891 @retval EFI_SUCCESS The Path represents a directory.\r
892 @retval EFI_NOT_FOUND The Path does not represent a directory.\r
893 @retval other The path failed to open.\r
2247dde4 894**/\r
895EFI_STATUS\r
896EFIAPI\r
897ShellIsDirectory(\r
898 IN CONST CHAR16 *DirName\r
899 );\r
900\r
a31bd33c 901/**\r
902 Function to determine if a given filename represents a file.\r
903\r
18cefebe 904 If Name is NULL, then ASSERT.\r
905\r
a31bd33c 906 @param[in] Name Path to file to test.\r
907\r
908 @retval EFI_SUCCESS The Path represents a file.\r
909 @retval EFI_NOT_FOUND The Path does not represent a file.\r
910 @retval other The path failed to open.\r
911**/\r
912EFI_STATUS\r
913EFIAPI\r
914ShellIsFile(\r
915 IN CONST CHAR16 *Name\r
916 );\r
917\r
125c2cf4 918/**\r
919 Function to determine whether a string is decimal or hex representation of a number \r
920 and return the number converted from the string.\r
921\r
922 @param[in] String String representation of a number\r
923\r
a31bd33c 924 @return The unsigned integer result of the conversion.\r
125c2cf4 925**/\r
926UINTN\r
927EFIAPI\r
928ShellStrToUintn(\r
929 IN CONST CHAR16 *String\r
930 );\r
931\r
932/**\r
933 Safely append with automatic string resizing given length of Destination and \r
934 desired length of copy from Source.\r
935\r
a31bd33c 936 Append the first D characters of Source to the end of Destination, where D is \r
125c2cf4 937 the lesser of Count and the StrLen() of Source. If appending those D characters \r
938 will fit within Destination (whose Size is given as CurrentSize) and \r
939 still leave room for a null terminator, then those characters are appended, \r
940 starting at the original terminating null of Destination, and a new terminating \r
941 null is appended.\r
942\r
943 If appending D characters onto Destination will result in a overflow of the size\r
944 given in CurrentSize the string will be grown such that the copy can be performed\r
945 and CurrentSize will be updated to the new size.\r
946\r
947 If Source is NULL, there is nothing to append, just return the current buffer in \r
948 Destination.\r
949\r
18cefebe 950 If Destination is NULL, then ASSERT().\r
951 If Destination's current length (including NULL terminator) is already more than \r
a31bd33c 952 CurrentSize, then ASSERT().\r
125c2cf4 953\r
a31bd33c 954 @param[in,out] Destination The String to append onto.\r
955 @param[in,out] CurrentSize On call the number of bytes in Destination. On \r
18cefebe 956 return possibly the new size (still in bytes). If NULL\r
125c2cf4 957 then allocate whatever is needed.\r
a31bd33c 958 @param[in] Source The String to append from.\r
959 @param[in] Count Maximum number of characters to append. If 0 then \r
125c2cf4 960 all are appended.\r
961\r
18cefebe 962 @return The Destination after apending the Source.\r
125c2cf4 963**/\r
964CHAR16* \r
965EFIAPI\r
966StrnCatGrow (\r
967 IN OUT CHAR16 **Destination,\r
968 IN OUT UINTN *CurrentSize,\r
969 IN CONST CHAR16 *Source,\r
970 IN UINTN Count\r
971 );\r
2247dde4 972\r
e9880e25 973#endif // __SHELL_LIB__\r