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