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