]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - ShellPkg/Include/Library/ShellLib.h
comment repairs.
[mirror_edk2.git] / ShellPkg / Include / Library / ShellLib.h
... / ...
CommitLineData
1/** @file\r
2 Provides interface to shell functionality for shell commands and applications.\r
3\r
4Copyright (c) 2006 - 2009, Intel Corporation<BR>\r
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
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
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
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
50 @retval EFI_SUCCESS The information was set.\r
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
72 @param FilePath On input the device path to the file. On output \r
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
109 If return is EFI_SUCCESS, the Filehandle is the opened file's handle; \r
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
118 @retval EFI_SUCCESS The information was set.\r
119 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.\r
120 @retval EFI_UNSUPPORTED Could not open the file path. \r
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
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
126 medium is no longer supported.\r
127 @retval EFI_DEVICE_ERROR The device reported an error.\r
128 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
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
131 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the \r
132 file.\r
133 @retval EFI_VOLUME_FULL The volume is full.\r
134**/\r
135EFI_STATUS\r
136EFIAPI\r
137ShellOpenFileByName(\r
138 IN CONST CHAR16 *FilePath,\r
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
151 @param DirectoryName Pointer to Directory name.\r
152 @param FileHandle Pointer to the file handle.\r
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
156 @retval EFI_UNSUPPORTED Could not open the file path. \r
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
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
162 medium is no longer supported.\r
163 @retval EFI_DEVICE_ERROR The device reported an error.\r
164 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
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
167 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the \r
168 file.\r
169 @retval EFI_VOLUME_FULL The volume is full.\r
170**/\r
171EFI_STATUS\r
172EFIAPI\r
173ShellCreateDirectory(\r
174 IN CONST CHAR16 *DirectoryName,\r
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
182 bytes from the file at the file's current position and returns them in Buffer. \r
183 If the read goes beyond the end of the file, the read length is truncated to the\r
184 end of the file. The file's current position is increased by the number of bytes \r
185 returned. If FileHandle is a directory, the function reads the directory entry \r
186 at the file's current position and returns the entry in Buffer. If the Buffer \r
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
194 @param FileHandle The opened file handle.\r
195 @param ReadSize On input the size of buffer in bytes. On return \r
196 the number of bytes written.\r
197 @param Buffer The buffer to put read data into.\r
198\r
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
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
221 has been a data error during the write attempt (such as "volume space full"). \r
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
225 @param FileHandle The opened file for writing.\r
226\r
227 @param BufferSize On input the number of bytes in Buffer. On output\r
228 the number of bytes written.\r
229\r
230 @param Buffer The buffer containing data to write is stored.\r
231\r
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
240**/\r
241EFI_STATUS\r
242EFIAPI\r
243ShellWriteFile(\r
244 IN EFI_FILE_HANDLE FileHandle,\r
245 IN OUT UINTN *BufferSize,\r
246 IN VOID *Buffer\r
247 );\r
248\r
249/** \r
250 Close an open file handle.\r
251\r
252 This function closes a specified file handle. All "dirty" cached file data is \r
253 flushed to the device, and the file is closed. In all cases the handle is \r
254 closed.\r
255\r
256 @param FileHandle The file handle to close.\r
257\r
258 @retval EFI_SUCCESS The file handle was closed sucessfully.\r
259 @retval INVALID_PARAMETER One of the parameters has an invalid value.\r
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
274 @param FileHandle The file handle to delete.\r
275\r
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
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
363 Caller must use FreePool on *Buffer opon completion of all file searching.\r
364\r
365 @param DirHandle The file handle of the directory to search\r
366 @param Buffer Pointer to pointer to buffer for file's information\r
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
379 OUT EFI_FILE_INFO **Buffer\r
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
412 This function extracts the file size info from the FileHandle's EFI_FILE_INFO \r
413 data.\r
414\r
415 @param FileHandle The file handle from which size is retrieved.\r
416 @param Size Pointer to size.\r
417\r
418 @retval EFI_SUCCESS The operation was completed sucessfully.\r
419 @retval EFI_DEVICE_ERROR Cannot access the file.\r
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
443 Return the value of an environment variable.\r
444\r
445 This function gets the value of the environment variable set by the \r
446 ShellSetEnvironmentVariable function.\r
447\r
448 @param EnvKey The key name of the environment variable.\r
449\r
450 @retval NULL The named environment variable does not exist.\r
451 @return != NULL pointer to the value of the environment variable.\r
452**/\r
453CONST CHAR16*\r
454EFIAPI\r
455ShellGetEnvironmentVariable (\r
456 IN CONST CHAR16 *EnvKey\r
457 );\r
458\r
459/**\r
460 set the value of an environment variable\r
461\r
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
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
488 Cause the shell to parse and execute a command line.\r
489\r
490 This function creates a nested instance of the shell and executes the specified\r
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
498\r
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
501\r
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
508\r
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
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
526 Retreives the current directory path.\r
527\r
528 If the DeviceName is NULL, it returns the current device's current directory \r
529 name. If the DeviceName is not NULL, it returns the current directory name \r
530 on specified drive.\r
531\r
532 @param DeviceName The name of the file system to get directory on.\r
533\r
534 @retval NULL The directory does not exist.\r
535 @return != NULL The directory.\r
536**/\r
537CONST CHAR16*\r
538EFIAPI\r
539ShellGetCurrentDir (\r
540 IN CHAR16 *DeviceName OPTIONAL\r
541 );\r
542\r
543/**\r
544 Sets (enabled or disabled) the page break mode.\r
545\r
546 When page break mode is enabled the screen will stop scrolling \r
547 and wait for operator input before scrolling a subsequent screen.\r
548\r
549 @param CurrentState TRUE to enable and FALSE to disable.\r
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
564 and will process '?' and '*' as such. The list must be freed with a call to \r
565 ShellCloseFileMetaArg().\r
566\r
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
569\r
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
573\r
574 @retval EFI_SUCCESS The operation was sucessful and the list head \r
575 contains the list of opened files.\r
576 @retval != EFI_SUCCESS The operation failed.\r
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
589 Free the linked list returned from ShellOpenFileMetaArg.\r
590\r
591 @param ListHead The pointer to free.\r
592\r
593 @retval EFI_SUCCESS The operation was sucessful.\r
594 @retval EFI_INVALID_PARAMETER A parameter was invalid.\r
595**/\r
596EFI_STATUS\r
597EFIAPI\r
598ShellCloseFileMetaArg (\r
599 IN OUT EFI_SHELL_FILE_INFO **ListHead\r
600 );\r
601\r
602/**\r
603 Find a file by searching the CWD and then the path.\r
604\r
605 If FileName is NULL, then ASSERT.\r
606\r
607 If the return value is not NULL then the memory must be caller freed.\r
608\r
609 @param FileName Filename string.\r
610\r
611 @retval NULL The file was not found.\r
612 @return !NULL The path to the file.\r
613**/\r
614CHAR16 *\r
615EFIAPI\r
616ShellFindFilePath (\r
617 IN CONST CHAR16 *FileName\r
618 );\r
619\r
620typedef enum {\r
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
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
635\r
636/// Helper structure for no parameters (besides -? and -b)\r
637extern SHELL_PARAM_ITEM EmptyParamList[];\r
638\r
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
645 @param CheckList Pointer to list of parameters to check.\r
646 @param CheckPackage Package of checked values.\r
647 @param ProblemParam Optional pointer to pointer to unicode string for \r
648 the paramater that caused failure.\r
649 @param AutoPageBreak Will automatically set PageBreakEnabled.\r
650\r
651 @retval EFI_SUCCESS The operation completed sucessfully.\r
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
656 was returned in ProblemParam if provided.\r
657 @retval EFI_DEVICE_ERROR The commands contained 2 opposing arguments. One\r
658 of the command line arguments was returned in \r
659 ProblemParam if provided.\r
660 @retval EFI_NOT_FOUND A argument required a value that was missing. \r
661 The invalid command line argument was returned in\r
662 ProblemParam if provided.\r
663**/\r
664EFI_STATUS\r
665EFIAPI\r
666ShellCommandLineParseEx (\r
667 IN CONST SHELL_PARAM_ITEM *CheckList,\r
668 OUT LIST_ENTRY **CheckPackage,\r
669 OUT CHAR16 **ProblemParam OPTIONAL,\r
670 IN BOOLEAN AutoPageBreak,\r
671 IN BOOLEAN AlwaysAllowNumbers\r
672 );\r
673\r
674/// make it easy to upgrade from older versions of the shell library.\r
675#define ShellCommandLineParse(CheckList,CheckPackage,ProblemParam,AutoPageBreak) ShellCommandLineParseEx(CheckList,CheckPackage,ProblemParam,AutoPageBreak,FALSE)\r
676\r
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
683 If CheckPackage is NULL, then return.\r
684\r
685 @param CheckPackage The list to de-allocate.\r
686 **/\r
687VOID\r
688EFIAPI\r
689ShellCommandLineFreeVarList (\r
690 IN LIST_ENTRY *CheckPackage\r
691 );\r
692\r
693/**\r
694 Checks for presence of a flag parameter.\r
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
699 if KeyString is NULL then ASSERT().\r
700 \r
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
703\r
704 @retval TRUE The flag is on the command line.\r
705 @retval FALSE The flag is not on the command line.\r
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
715 Returns value from command line argument.\r
716\r
717 Value parameters are in the form of "-<Key> value" or "/<Key> value"\r
718 \r
719 If CheckPackage is NULL, then return NULL.\r
720\r
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
723\r
724 @retval NULL The flag is not on the command line.\r
725 @retval !=NULL Pointer to unicode string of the value.\r
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
735 Returns raw value from command line argument.\r
736\r
737 Raw value parameters are in the form of "value" in a specific position in the list.\r
738 \r
739 If CheckPackage is NULL, then return NULL;\r
740\r
741 @param CheckPackage The package of parsed command line arguments.\r
742 @param Position The position of the value.\r
743\r
744 @retval NULL The flag is not on the command line.\r
745 @retval !=NULL Pointer to unicode string of the value.\r
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
754/**\r
755 Returns the number of command line value parameters that were parsed. \r
756 \r
757 This will not include flags.\r
758\r
759 @retval (UINTN)-1 No parsing has ocurred\r
760 @return The number of value parameters found\r
761**/\r
762UINTN\r
763EFIAPI\r
764ShellCommandLineGetCount(\r
765 VOID\r
766 );\r
767\r
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
784 VOID\r
785 );\r
786\r
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
791 and return the cursor to the original location. \r
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
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
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
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
865 Function to determine if a given filename represents a directory.\r
866\r
867 @param[in] DirName Path to directory to test.\r
868\r
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
872**/\r
873EFI_STATUS\r
874EFIAPI\r
875ShellIsDirectory(\r
876 IN CONST CHAR16 *DirName\r
877 );\r
878\r
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
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
900 @return The unsigned integer result of the conversion.\r
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
912 Append the first D characters of Source to the end of Destination, where D is \r
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
926 if Destination is NULL, then ASSERT().\r
927 if Destination's current length (including NULL terminator) is already more then \r
928 CurrentSize, then ASSERT().\r
929\r
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
932 return possibly the new size (still in bytes). if NULL\r
933 then allocate whatever is needed.\r
934 @param[in] Source The String to append from.\r
935 @param[in] Count Maximum number of characters to append. If 0 then \r
936 all are appended.\r
937\r
938 @return the Destination after apending the Source.\r
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
948\r
949#endif // __SHELL_LIB__\r