]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Include/Library/ShellLib.h
comment repairs.
[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
26 caller's responsibility to free the buffer\r
94b17fa1 27\r
28 @param FileHandle The file handle of the file for which information is \r
29 being requested.\r
30\r
31 @retval NULL information could not be retrieved.\r
32\r
33 @return the information about the file\r
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
45 @param FileHandle The file handle of the file for which information \r
46 is being set\r
47\r
48 @param FileInfo The infotmation to set.\r
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
125c2cf4 72 @param FilePath On input the device path to the file. On output \r
94b17fa1 73 the remaining device path.\r
74 @param DeviceHandle pointer to the system device handle.\r
75 @param FileHandle pointer to the file handle.\r
76 @param OpenMode the mode to open the file with.\r
77 @param Attributes the file's file attributes.\r
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
113 @param FileName pointer to file name\r
114 @param FileHandle pointer to the file handle.\r
115 @param OpenMode the mode to open the file with.\r
116 @param Attributes the file's file attributes.\r
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
145 This function create a directory\r
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
125c2cf4 151 @param DirectoryName Pointer to Directory name.\r
152 @param 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
125c2cf4 194 @param FileHandle The opened file handle.\r
195 @param ReadSize On input the size of buffer in bytes. On return \r
94b17fa1 196 the number of bytes written.\r
125c2cf4 197 @param 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
125c2cf4 225 @param FileHandle The opened file for writing.\r
94b17fa1 226\r
125c2cf4 227 @param BufferSize On input the number of bytes in Buffer. On output\r
94b17fa1 228 the number of bytes written.\r
229\r
125c2cf4 230 @param 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
125c2cf4 256 @param 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
125c2cf4 274 @param 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
298 @param FileHandle The file handle on which the position is being set\r
299\r
300 @param Position Byte position from begining of file\r
301\r
302 @retval EFI_SUCCESS Operation completed sucessfully.\r
303 @retval EFI_UNSUPPORTED the seek request for non-zero is not valid on \r
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
322 @param FileHandle The open file handle on which to get the position.\r
323 @param Position Byte position from begining of file.\r
324\r
325 @retval EFI_SUCCESS the operation completed sucessfully.\r
326 @retval INVALID_PARAMETER One of the parameters has an invalid value.\r
327 @retval EFI_UNSUPPORTED the request is not valid on directories.\r
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
341 @param FileHandle The file handle on which to flush data\r
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
94b17fa1 365 @param DirHandle The file handle of the directory to search\r
d2b4564b 366 @param 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
392 @param DirHandle the file handle of the directory\r
393 @param Buffer pointer to buffer for file's information\r
394 @param NoFile pointer to boolean when last file is found\r
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
125c2cf4 415 @param FileHandle The file handle from which size is retrieved.\r
416 @param 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
431 this function is useful to check whether the application is being asked to halt by the shell.\r
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
448 @param EnvKey The key name of the environment variable.\r
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
460 set the value of an environment variable\r
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
472 @param EnvKey The key name of the environment variable.\r
473 @param EnvVal The Value of the environment variable\r
474 @param Volatile Indicates whether the variable is non-volatile (FALSE) or volatile (TRUE).\r
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
125c2cf4 499 EnvironmentVariables and Status are only supported for UEFI Shell 2.0.\r
500 Output is only supported for pre-UEFI Shell 2.0\r
94b17fa1 501\r
a31bd33c 502 @param ImageHandle Parent image that is starting the operation.\r
503 @param CommandLine Pointer to null terminated command line.\r
504 @param Output True to display debug output. false to hide it.\r
505 @param EnvironmentVariables Optional pointer to array of environment variables\r
506 in the form "x=y". If NULL current set is used.\r
507 @param Status The status of the run command line.\r
94b17fa1 508\r
a31bd33c 509 @retval EFI_SUCCESS The operation completed sucessfully. Status\r
94b17fa1 510 contains the status code returned.\r
a31bd33c 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
a31bd33c 532 @param 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
535 @return != 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
a31bd33c 549 @param 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
125c2cf4 570 @param Arg Pointer to path string.\r
571 @param OpenMode Mode to open files with.\r
572 @param 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
a31bd33c 591 @param 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
609 @param FileName Filename string.\r
610\r
a31bd33c 611 @retval NULL The file was not found.\r
612 @return !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
a31bd33c 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
125c2cf4 645 @param CheckList Pointer to list of parameters to check.\r
646 @param CheckPackage Package of checked values.\r
a31bd33c 647 @param ProblemParam Optional pointer to pointer to unicode string for \r
94b17fa1 648 the paramater that caused failure.\r
125c2cf4 649 @param AutoPageBreak Will automatically set PageBreakEnabled.\r
94b17fa1 650\r
651 @retval EFI_SUCCESS The operation completed sucessfully.\r
a31bd33c 652 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r
653 @retval EFI_INVALID_PARAMETER A parameter was invalid.\r
654 @retval EFI_VOLUME_CORRUPTED The command line was corrupt. an argument was \r
655 duplicated. The duplicated command line argument \r
94b17fa1 656 was returned in ProblemParam if provided.\r
a31bd33c 657 @retval EFI_DEVICE_ERROR The commands contained 2 opposing arguments. One\r
94b17fa1 658 of the command line arguments was returned in \r
659 ProblemParam if provided.\r
125c2cf4 660 @retval EFI_NOT_FOUND A argument required a value that was missing. \r
a31bd33c 661 The invalid command line argument was returned in\r
94b17fa1 662 ProblemParam if provided.\r
663**/\r
664EFI_STATUS\r
665EFIAPI\r
2247dde4 666ShellCommandLineParseEx (\r
94b17fa1 667 IN CONST SHELL_PARAM_ITEM *CheckList,\r
668 OUT LIST_ENTRY **CheckPackage,\r
669 OUT CHAR16 **ProblemParam OPTIONAL,\r
2247dde4 670 IN BOOLEAN AutoPageBreak,\r
671 IN BOOLEAN AlwaysAllowNumbers\r
94b17fa1 672 );\r
673\r
a31bd33c 674/// make it easy to upgrade from older versions of the shell library.\r
2247dde4 675#define ShellCommandLineParse(CheckList,CheckPackage,ProblemParam,AutoPageBreak) ShellCommandLineParseEx(CheckList,CheckPackage,ProblemParam,AutoPageBreak,FALSE)\r
676\r
94b17fa1 677/**\r
678 Frees shell variable list that was returned from ShellCommandLineParse.\r
679\r
680 This function will free all the memory that was used for the CheckPackage\r
681 list of postprocessed shell arguments.\r
682\r
a31bd33c 683 If CheckPackage is NULL, then return.\r
94b17fa1 684\r
a31bd33c 685 @param CheckPackage The list to de-allocate.\r
94b17fa1 686 **/\r
687VOID\r
688EFIAPI\r
689ShellCommandLineFreeVarList (\r
690 IN LIST_ENTRY *CheckPackage\r
691 );\r
692\r
693/**\r
a31bd33c 694 Checks for presence of a flag parameter.\r
94b17fa1 695\r
696 flag arguments are in the form of "-<Key>" or "/<Key>", but do not have a value following the key\r
697\r
698 if CheckPackage is NULL then return FALSE.\r
a31bd33c 699 if KeyString is NULL then ASSERT().\r
94b17fa1 700 \r
a31bd33c 701 @param CheckPackage The package of parsed command line arguments.\r
702 @param KeyString The Key of the command line argument to check for.\r
94b17fa1 703\r
a31bd33c 704 @retval TRUE The flag is on the command line.\r
705 @retval FALSE The flag is not on the command line.\r
94b17fa1 706 **/\r
707BOOLEAN\r
708EFIAPI\r
709ShellCommandLineGetFlag (\r
710 IN CONST LIST_ENTRY *CheckPackage,\r
711 IN CHAR16 *KeyString\r
712 );\r
713\r
714/**\r
a31bd33c 715 Returns value from command line argument.\r
94b17fa1 716\r
a31bd33c 717 Value parameters are in the form of "-<Key> value" or "/<Key> value"\r
94b17fa1 718 \r
a31bd33c 719 If CheckPackage is NULL, then return NULL.\r
94b17fa1 720\r
a31bd33c 721 @param CheckPackage The package of parsed command line arguments.\r
722 @param KeyString The Key of the command line argument to check for.\r
94b17fa1 723\r
a31bd33c 724 @retval NULL The flag is not on the command line.\r
725 @retval !=NULL Pointer to unicode string of the value.\r
94b17fa1 726 **/\r
727CONST CHAR16*\r
728EFIAPI\r
729ShellCommandLineGetValue (\r
730 IN CONST LIST_ENTRY *CheckPackage,\r
731 IN CHAR16 *KeyString\r
732 );\r
733\r
734/**\r
a31bd33c 735 Returns raw value from command line argument.\r
94b17fa1 736\r
a31bd33c 737 Raw value parameters are in the form of "value" in a specific position in the list.\r
94b17fa1 738 \r
a31bd33c 739 If CheckPackage is NULL, then return NULL;\r
94b17fa1 740\r
a31bd33c 741 @param CheckPackage The package of parsed command line arguments.\r
742 @param Position The position of the value.\r
94b17fa1 743\r
a31bd33c 744 @retval NULL The flag is not on the command line.\r
745 @retval !=NULL Pointer to unicode string of the value.\r
94b17fa1 746 **/\r
747CONST CHAR16*\r
748EFIAPI\r
749ShellCommandLineGetRawValue (\r
750 IN CONST LIST_ENTRY *CheckPackage,\r
751 IN UINT32 Position\r
752 );\r
753\r
2247dde4 754/**\r
a31bd33c 755 Returns the number of command line value parameters that were parsed. \r
2247dde4 756 \r
a31bd33c 757 This will not include flags.\r
2247dde4 758\r
759 @retval (UINTN)-1 No parsing has ocurred\r
a31bd33c 760 @return The number of value parameters found\r
2247dde4 761**/\r
762UINTN\r
763EFIAPI\r
764ShellCommandLineGetCount(\r
765 VOID\r
766 );\r
767\r
d2b4564b 768/**\r
769 This function causes the shell library to initialize itself. If the shell library\r
770 is already initialized it will de-initialize all the current protocol poitners and\r
771 re-populate them again.\r
772\r
773 When the library is used with PcdShellLibAutoInitialize set to true this function\r
774 will return EFI_SUCCESS and perform no actions.\r
775\r
776 This function is intended for internal access for shell commands only.\r
777\r
778 @retval EFI_SUCCESS the initialization was complete sucessfully\r
779\r
780**/\r
781EFI_STATUS\r
782EFIAPI\r
783ShellInitialize (\r
125c2cf4 784 VOID\r
d2b4564b 785 );\r
786\r
b1f95a06 787/**\r
788 Print at a specific location on the screen.\r
789\r
790 This function will move the cursor to a given screen location, print the specified string, \r
a31bd33c 791 and return the cursor to the original location. \r
b1f95a06 792 \r
793 If -1 is specified for either the Row or Col the current screen location for BOTH \r
794 will be used and the cursor's position will not be moved back to an original location.\r
795\r
a31bd33c 796 If either Row or Col is out of range for the current console, then ASSERT.\r
797 If Format is NULL, then ASSERT.\r
b1f95a06 798\r
799 In addition to the standard %-based flags as supported by UefiLib Print() this supports \r
800 the following additional flags:\r
801 %N - Set output attribute to normal\r
802 %H - Set output attribute to highlight\r
803 %E - Set output attribute to error\r
804 %B - Set output attribute to blue color\r
805 %V - Set output attribute to green color\r
806\r
807 Note: The background color is controlled by the shell command cls.\r
808\r
809 @param[in] Row the row to print at\r
810 @param[in] Col the column to print at\r
811 @param[in] Format the format string\r
812\r
813 @return the number of characters printed to the screen\r
814**/\r
815\r
816UINTN\r
817EFIAPI\r
818ShellPrintEx(\r
819 IN INT32 Col OPTIONAL,\r
820 IN INT32 Row OPTIONAL,\r
821 IN CONST CHAR16 *Format,\r
822 ...\r
823 );\r
824\r
2247dde4 825/**\r
826 Print at a specific location on the screen.\r
827\r
828 This function will move the cursor to a given screen location, print the specified string, \r
829 and return the cursor to the original locaiton. \r
830 \r
831 If -1 is specified for either the Row or Col the current screen location for BOTH \r
832 will be used and the cursor's position will not be moved back to an original location.\r
833\r
834 if either Row or Col is out of range for the current console, then ASSERT\r
835 if Format is NULL, then ASSERT\r
836\r
837 In addition to the standard %-based flags as supported by UefiLib Print() this supports \r
838 the following additional flags:\r
839 %N - Set output attribute to normal\r
840 %H - Set output attribute to highlight\r
841 %E - Set output attribute to error\r
842 %B - Set output attribute to blue color\r
843 %V - Set output attribute to green color\r
844\r
845 Note: The background color is controlled by the shell command cls.\r
846\r
847 @param[in] Row the row to print at\r
848 @param[in] Col the column to print at\r
849 @param[in] HiiFormatStringId the format string Id for getting from Hii\r
850 @param[in] HiiFormatHandle the format string Handle for getting from Hii\r
851\r
852 @return the number of characters printed to the screen\r
853**/\r
854UINTN\r
855EFIAPI\r
856ShellPrintHiiEx(\r
857 IN INT32 Col OPTIONAL,\r
858 IN INT32 Row OPTIONAL,\r
859 IN CONST EFI_STRING_ID HiiFormatStringId,\r
860 IN CONST EFI_HANDLE HiiFormatHandle,\r
861 ...\r
862 );\r
863\r
864/**\r
a31bd33c 865 Function to determine if a given filename represents a directory.\r
2247dde4 866\r
867 @param[in] DirName Path to directory to test.\r
868\r
a31bd33c 869 @retval EFI_SUCCESS The Path represents a directory.\r
870 @retval EFI_NOT_FOUND The Path does not represent a directory.\r
871 @retval other The path failed to open.\r
2247dde4 872**/\r
873EFI_STATUS\r
874EFIAPI\r
875ShellIsDirectory(\r
876 IN CONST CHAR16 *DirName\r
877 );\r
878\r
a31bd33c 879/**\r
880 Function to determine if a given filename represents a file.\r
881\r
882 @param[in] Name Path to file to test.\r
883\r
884 @retval EFI_SUCCESS The Path represents a file.\r
885 @retval EFI_NOT_FOUND The Path does not represent a file.\r
886 @retval other The path failed to open.\r
887**/\r
888EFI_STATUS\r
889EFIAPI\r
890ShellIsFile(\r
891 IN CONST CHAR16 *Name\r
892 );\r
893\r
125c2cf4 894/**\r
895 Function to determine whether a string is decimal or hex representation of a number \r
896 and return the number converted from the string.\r
897\r
898 @param[in] String String representation of a number\r
899\r
a31bd33c 900 @return The unsigned integer result of the conversion.\r
125c2cf4 901**/\r
902UINTN\r
903EFIAPI\r
904ShellStrToUintn(\r
905 IN CONST CHAR16 *String\r
906 );\r
907\r
908/**\r
909 Safely append with automatic string resizing given length of Destination and \r
910 desired length of copy from Source.\r
911\r
a31bd33c 912 Append the first D characters of Source to the end of Destination, where D is \r
125c2cf4 913 the lesser of Count and the StrLen() of Source. If appending those D characters \r
914 will fit within Destination (whose Size is given as CurrentSize) and \r
915 still leave room for a null terminator, then those characters are appended, \r
916 starting at the original terminating null of Destination, and a new terminating \r
917 null is appended.\r
918\r
919 If appending D characters onto Destination will result in a overflow of the size\r
920 given in CurrentSize the string will be grown such that the copy can be performed\r
921 and CurrentSize will be updated to the new size.\r
922\r
923 If Source is NULL, there is nothing to append, just return the current buffer in \r
924 Destination.\r
925\r
a31bd33c 926 if Destination is NULL, then ASSERT().\r
125c2cf4 927 if Destination's current length (including NULL terminator) is already more then \r
a31bd33c 928 CurrentSize, then ASSERT().\r
125c2cf4 929\r
a31bd33c 930 @param[in,out] Destination The String to append onto.\r
931 @param[in,out] CurrentSize On call the number of bytes in Destination. On \r
125c2cf4 932 return possibly the new size (still in bytes). if NULL\r
933 then allocate whatever is needed.\r
a31bd33c 934 @param[in] Source The String to append from.\r
935 @param[in] Count Maximum number of characters to append. If 0 then \r
125c2cf4 936 all are appended.\r
937\r
a31bd33c 938 @return the Destination after apending the Source.\r
125c2cf4 939**/\r
940CHAR16* \r
941EFIAPI\r
942StrnCatGrow (\r
943 IN OUT CHAR16 **Destination,\r
944 IN OUT UINTN *CurrentSize,\r
945 IN CONST CHAR16 *Source,\r
946 IN UINTN Count\r
947 );\r
2247dde4 948\r
e9880e25 949#endif // __SHELL_LIB__\r