]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Include/Library/ShellLib.h
eab8271ae9f0ee7bd27d1434acff80cd09e45897
[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
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 drive 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 @return != 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 Pptional 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 this function has no return value.
684
685 if CheckPackage is NULL, then return
686
687 @param CheckPackage the list to de-allocate
688 **/
689 VOID
690 EFIAPI
691 ShellCommandLineFreeVarList (
692 IN LIST_ENTRY *CheckPackage
693 );
694
695 /**
696 Checks for presence of a flag parameter
697
698 flag arguments are in the form of "-<Key>" or "/<Key>", but do not have a value following the key
699
700 if CheckPackage is NULL then return FALSE.
701 if KeyString is NULL then ASSERT()
702
703 @param CheckPackage The package of parsed command line arguments
704 @param KeyString the Key of the command line argument to check for
705
706 @retval TRUE the flag is on the command line
707 @retval FALSE the flag is not on the command line
708 **/
709 BOOLEAN
710 EFIAPI
711 ShellCommandLineGetFlag (
712 IN CONST LIST_ENTRY *CheckPackage,
713 IN CHAR16 *KeyString
714 );
715
716 /**
717 returns value from command line argument
718
719 value parameters are in the form of "-<Key> value" or "/<Key> value"
720
721 if CheckPackage is NULL, then return NULL;
722
723 @param CheckPackage The package of parsed command line arguments
724 @param KeyString the Key of the command line argument to check for
725
726 @retval NULL the flag is not on the command line
727 @return !=NULL pointer to unicode string of the value
728 **/
729 CONST CHAR16*
730 EFIAPI
731 ShellCommandLineGetValue (
732 IN CONST LIST_ENTRY *CheckPackage,
733 IN CHAR16 *KeyString
734 );
735
736 /**
737 returns raw value from command line argument
738
739 raw value parameters are in the form of "value" in a specific position in the list
740
741 if CheckPackage is NULL, then return NULL;
742
743 @param CheckPackage The package of parsed command line arguments
744 @param Position the position of the value
745
746 @retval NULL the flag is not on the command line
747 @return !=NULL pointer to unicode string of the value
748 **/
749 CONST CHAR16*
750 EFIAPI
751 ShellCommandLineGetRawValue (
752 IN CONST LIST_ENTRY *CheckPackage,
753 IN UINT32 Position
754 );
755
756 /**
757 returns the number of command line value parameters that were parsed.
758
759 this will not include flags.
760
761 @retval (UINTN)-1 No parsing has ocurred
762 @return other The number of value parameters found
763 **/
764 UINTN
765 EFIAPI
766 ShellCommandLineGetCount(
767 VOID
768 );
769
770 /**
771 This function causes the shell library to initialize itself. If the shell library
772 is already initialized it will de-initialize all the current protocol poitners and
773 re-populate them again.
774
775 When the library is used with PcdShellLibAutoInitialize set to true this function
776 will return EFI_SUCCESS and perform no actions.
777
778 This function is intended for internal access for shell commands only.
779
780 @retval EFI_SUCCESS the initialization was complete sucessfully
781
782 **/
783 EFI_STATUS
784 EFIAPI
785 ShellInitialize (
786 VOID
787 );
788
789 /**
790 Print at a specific location on the screen.
791
792 This function will move the cursor to a given screen location, print the specified string,
793 and return the cursor to the original locaiton.
794
795 If -1 is specified for either the Row or Col the current screen location for BOTH
796 will be used and the cursor's position will not be moved back to an original location.
797
798 if either Row or Col is out of range for the current console, then ASSERT
799 if Format is NULL, then ASSERT
800
801 In addition to the standard %-based flags as supported by UefiLib Print() this supports
802 the following additional flags:
803 %N - Set output attribute to normal
804 %H - Set output attribute to highlight
805 %E - Set output attribute to error
806 %B - Set output attribute to blue color
807 %V - Set output attribute to green color
808
809 Note: The background color is controlled by the shell command cls.
810
811 @param[in] Row the row to print at
812 @param[in] Col the column to print at
813 @param[in] Format the format string
814
815 @return the number of characters printed to the screen
816 **/
817
818 UINTN
819 EFIAPI
820 ShellPrintEx(
821 IN INT32 Col OPTIONAL,
822 IN INT32 Row OPTIONAL,
823 IN CONST CHAR16 *Format,
824 ...
825 );
826
827 /**
828 Print at a specific location on the screen.
829
830 This function will move the cursor to a given screen location, print the specified string,
831 and return the cursor to the original locaiton.
832
833 If -1 is specified for either the Row or Col the current screen location for BOTH
834 will be used and the cursor's position will not be moved back to an original location.
835
836 if either Row or Col is out of range for the current console, then ASSERT
837 if Format is NULL, then ASSERT
838
839 In addition to the standard %-based flags as supported by UefiLib Print() this supports
840 the following additional flags:
841 %N - Set output attribute to normal
842 %H - Set output attribute to highlight
843 %E - Set output attribute to error
844 %B - Set output attribute to blue color
845 %V - Set output attribute to green color
846
847 Note: The background color is controlled by the shell command cls.
848
849 @param[in] Row the row to print at
850 @param[in] Col the column to print at
851 @param[in] HiiFormatStringId the format string Id for getting from Hii
852 @param[in] HiiFormatHandle the format string Handle for getting from Hii
853
854 @return the number of characters printed to the screen
855 **/
856 UINTN
857 EFIAPI
858 ShellPrintHiiEx(
859 IN INT32 Col OPTIONAL,
860 IN INT32 Row OPTIONAL,
861 IN CONST EFI_STRING_ID HiiFormatStringId,
862 IN CONST EFI_HANDLE HiiFormatHandle,
863 ...
864 );
865
866 /**
867 Function to determine if a given filename represents a file or a directory.
868
869 @param[in] DirName Path to directory to test.
870
871 @retval EFI_SUCCESS The Path represents a directory
872 @retval EFI_NOT_FOUND The Path does not represent a directory
873 @return other The path failed to open
874 **/
875 EFI_STATUS
876 EFIAPI
877 ShellIsDirectory(
878 IN CONST CHAR16 *DirName
879 );
880
881 /**
882 Function to determine whether a string is decimal or hex representation of a number
883 and return the number converted from the string.
884
885 @param[in] String String representation of a number
886
887 @retval all the number
888 **/
889 UINTN
890 EFIAPI
891 ShellStrToUintn(
892 IN CONST CHAR16 *String
893 );
894
895 /**
896 Safely append with automatic string resizing given length of Destination and
897 desired length of copy from Source.
898
899 append the first D characters of Source to the end of Destination, where D is
900 the lesser of Count and the StrLen() of Source. If appending those D characters
901 will fit within Destination (whose Size is given as CurrentSize) and
902 still leave room for a null terminator, then those characters are appended,
903 starting at the original terminating null of Destination, and a new terminating
904 null is appended.
905
906 If appending D characters onto Destination will result in a overflow of the size
907 given in CurrentSize the string will be grown such that the copy can be performed
908 and CurrentSize will be updated to the new size.
909
910 If Source is NULL, there is nothing to append, just return the current buffer in
911 Destination.
912
913 if Destination is NULL, then ASSERT()
914 if Destination's current length (including NULL terminator) is already more then
915 CurrentSize, then ASSERT()
916
917 @param[in,out] Destination The String to append onto
918 @param[in,out] CurrentSize on call the number of bytes in Destination. On
919 return possibly the new size (still in bytes). if NULL
920 then allocate whatever is needed.
921 @param[in] Source The String to append from
922 @param[in] Count Maximum number of characters to append. if 0 then
923 all are appended.
924
925 @return Destination return the resultant string.
926 **/
927 CHAR16*
928 EFIAPI
929 StrnCatGrow (
930 IN OUT CHAR16 **Destination,
931 IN OUT UINTN *CurrentSize,
932 IN CONST CHAR16 *Source,
933 IN UINTN Count
934 );
935
936 #endif // __SHELL_LIB__