2 Provides interface to shell functionality for shell commands and applications.
4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
5 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
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.
15 #if !defined(__SHELL_LIB__)
19 #include <Guid/FileInfo.h>
20 #include <Protocol/SimpleFileSystem.h>
21 #include <Protocol/LoadedImage.h>
22 #include <Protocol/EfiShellInterface.h>
23 #include <Protocol/EfiShellEnvironment2.h>
24 #include <Protocol/EfiShell.h>
25 #include <Protocol/EfiShellParameters.h>
28 This function will retrieve the information about the file for the handle
29 specified and store it in allocated pool memory.
31 This function allocates a buffer to store the file's information. It is the
32 caller's responsibility to free the buffer.
34 @param[in] FileHandle The file handle of the file for which information is
37 @retval NULL Information could not be retrieved.
39 @return The information about the file.
44 IN EFI_FILE_HANDLE FileHandle
48 This function will set the information about the file for the opened handle
51 @param[in] FileHandle The file handle of the file for which information
54 @param[in] FileInfo The infotmation to set.
56 @retval EFI_SUCCESS The information was set.
57 @retval EFI_UNSUPPORTED The InformationType is not known.
58 @retval EFI_NO_MEDIA The device has no medium.
59 @retval EFI_DEVICE_ERROR The device reported an error.
60 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
61 @retval EFI_WRITE_PROTECTED The file or medium is write protected.
62 @retval EFI_ACCESS_DENIED The file was opened read only.
63 @retval EFI_VOLUME_FULL The volume is full.
68 IN EFI_FILE_HANDLE FileHandle
,
69 IN EFI_FILE_INFO
*FileInfo
73 This function will open a file or directory referenced by DevicePath.
75 This function opens a file with the open mode according to the file path. The
76 Attributes is valid only for EFI_FILE_MODE_CREATE.
78 @param[in] FilePath On input the device path to the file. On output
79 the remaining device path.
80 @param[out] DeviceHandle Pointer to the system device handle.
81 @param[out] FileHandle Pointer to the file handle.
82 @param[in] OpenMode The mode to open the file with.
83 @param[in] Attributes The file's file attributes.
85 @retval EFI_SUCCESS The information was set.
86 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
87 @retval EFI_UNSUPPORTED Could not open the file path.
88 @retval EFI_NOT_FOUND The specified file could not be found on the
89 device or the file system could not be found on
91 @retval EFI_NO_MEDIA The device has no medium.
92 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the
93 medium is no longer supported.
94 @retval EFI_DEVICE_ERROR The device reported an error.
95 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
96 @retval EFI_WRITE_PROTECTED The file or medium is write protected.
97 @retval EFI_ACCESS_DENIED The file was opened read only.
98 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the
100 @retval EFI_VOLUME_FULL The volume is full.
104 ShellOpenFileByDevicePath(
105 IN OUT EFI_DEVICE_PATH_PROTOCOL
**FilePath
,
106 OUT EFI_HANDLE
*DeviceHandle
,
107 OUT EFI_FILE_HANDLE
*FileHandle
,
113 This function will open a file or directory referenced by filename.
115 If return is EFI_SUCCESS, the Filehandle is the opened file's handle;
116 otherwise, the Filehandle is NULL. The Attributes is valid only for
117 EFI_FILE_MODE_CREATE.
119 @param[in] FileName Pointer to file name.
120 @param[out] FileHandle Pointer to the file handle.
121 @param[in] OpenMode The mode to open the file with.
122 @param[in] Attributes The file's file attributes.
124 @retval EFI_SUCCESS The information was set.
125 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
126 @retval EFI_UNSUPPORTED Could not open the file path.
127 @retval EFI_NOT_FOUND The specified file could not be found on the
128 device or the file system could not be found
130 @retval EFI_NO_MEDIA The device has no medium.
131 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the
132 medium is no longer supported.
133 @retval EFI_DEVICE_ERROR The device reported an error.
134 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
135 @retval EFI_WRITE_PROTECTED The file or medium is write protected.
136 @retval EFI_ACCESS_DENIED The file was opened read only.
137 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the
139 @retval EFI_VOLUME_FULL The volume is full.
144 IN CONST CHAR16
*FilePath
,
145 OUT EFI_FILE_HANDLE
*FileHandle
,
151 This function creates a directory.
153 If return is EFI_SUCCESS, the Filehandle is the opened directory's handle;
154 otherwise, the Filehandle is NULL. If the directory already existed, this
155 function opens the existing directory.
157 @param[in] DirectoryName Pointer to Directory name.
158 @param[out] FileHandle Pointer to the file handle.
160 @retval EFI_SUCCESS The information was set.
161 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
162 @retval EFI_UNSUPPORTED Could not open the file path.
163 @retval EFI_NOT_FOUND The specified file could not be found on the
164 device or the file system could not be found
166 @retval EFI_NO_MEDIA The device has no medium.
167 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the
168 medium is no longer supported.
169 @retval EFI_DEVICE_ERROR The device reported an error.
170 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
171 @retval EFI_WRITE_PROTECTED The file or medium is write protected.
172 @retval EFI_ACCESS_DENIED The file was opened read only.
173 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the
175 @retval EFI_VOLUME_FULL The volume is full.
179 ShellCreateDirectory(
180 IN CONST CHAR16
*DirectoryName
,
181 OUT EFI_FILE_HANDLE
*FileHandle
185 This function reads information from an opened file.
187 If FileHandle is not a directory, the function reads the requested number of
188 bytes from the file at the file's current position and returns them in Buffer.
189 If the read goes beyond the end of the file, the read length is truncated to the
190 end of the file. The file's current position is increased by the number of bytes
191 returned. If FileHandle is a directory, the function reads the directory entry
192 at the file's current position and returns the entry in Buffer. If the Buffer
193 is not large enough to hold the current directory entry, then
194 EFI_BUFFER_TOO_SMALL is returned and the current file position is not updated.
195 BufferSize is set to be the size of the buffer needed to read the entry. On
196 success, the current position is updated to the next directory entry. If there
197 are no more directory entries, the read returns a zero-length buffer.
198 EFI_FILE_INFO is the structure returned as the directory entry.
200 @param[in] FileHandle The opened file handle.
201 @param[in] ReadSize On input the size of buffer in bytes. On return
202 the number of bytes written.
203 @param[out] Buffer The buffer to put read data into.
205 @retval EFI_SUCCESS Data was read.
206 @retval EFI_NO_MEDIA The device has no media.
207 @retval EFI_DEVICE_ERROR The device reported an error.
208 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
209 @retval EFI_BUFFER_TO_SMALL Buffer is too small. ReadSize contains required
216 IN EFI_FILE_HANDLE FileHandle
,
217 IN OUT UINTN
*ReadSize
,
222 Write data to a file.
224 This function writes the specified number of bytes to the file at the current
225 file position. The current file position is advanced the actual number of bytes
226 written, which is returned in BufferSize. Partial writes only occur when there
227 has been a data error during the write attempt (such as "volume space full").
228 The file is automatically grown to hold the data if required. Direct writes to
229 opened directories are not supported.
231 @param[in] FileHandle The opened file for writing.
233 @param[in] BufferSize On input the number of bytes in Buffer. On output
234 the number of bytes written.
236 @param[in] Buffer The buffer containing data to write is stored.
238 @retval EFI_SUCCESS Data was written.
239 @retval EFI_UNSUPPORTED Writes to an open directory are not supported.
240 @retval EFI_NO_MEDIA The device has no media.
241 @retval EFI_DEVICE_ERROR The device reported an error.
242 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
243 @retval EFI_WRITE_PROTECTED The device is write-protected.
244 @retval EFI_ACCESS_DENIED The file was open for read only.
245 @retval EFI_VOLUME_FULL The volume is full.
250 IN EFI_FILE_HANDLE FileHandle
,
251 IN OUT UINTN
*BufferSize
,
256 Close an open file handle.
258 This function closes a specified file handle. All "dirty" cached file data is
259 flushed to the device, and the file is closed. In all cases the handle is
262 @param[in] FileHandle The file handle to close.
264 @retval EFI_SUCCESS The file handle was closed sucessfully.
265 @retval INVALID_PARAMETER One of the parameters has an invalid value.
270 IN EFI_FILE_HANDLE
*FileHandle
274 Delete a file and close the handle
276 This function closes and deletes a file. In all cases the file handle is closed.
277 If the file cannot be deleted, the warning code EFI_WARN_DELETE_FAILURE is
278 returned, but the handle is still closed.
280 @param[in] FileHandle The file handle to delete.
282 @retval EFI_SUCCESS The file was closed sucessfully.
283 @retval EFI_WARN_DELETE_FAILURE The handle was closed, but the file was not
285 @retval INVALID_PARAMETER One of the parameters has an invalid value.
290 IN EFI_FILE_HANDLE
*FileHandle
294 Set the current position in a file.
296 This function sets the current file position for the handle to the position
297 supplied. With the exception of seeking to position 0xFFFFFFFFFFFFFFFF, only
298 absolute positioning is supported, and seeking past the end of the file is
299 allowed (a subsequent write would grow the file). Seeking to position
300 0xFFFFFFFFFFFFFFFF causes the current position to be set to the end of the file.
301 If FileHandle is a directory, the only position that may be set is zero. This
302 has the effect of starting the read process of the directory entries over.
304 @param[in] FileHandle The file handle on which the position is being set.
306 @param[in] Position Byte position from begining of file.
308 @retval EFI_SUCCESS Operation completed sucessfully.
309 @retval EFI_UNSUPPORTED The seek request for non-zero is not valid on
311 @retval INVALID_PARAMETER One of the parameters has an invalid value.
315 ShellSetFilePosition (
316 IN EFI_FILE_HANDLE FileHandle
,
321 Gets a file's current position
323 This function retrieves the current file position for the file handle. For
324 directories, the current file position has no meaning outside of the file
325 system driver and as such the operation is not supported. An error is returned
326 if FileHandle is a directory.
328 @param[in] FileHandle The open file handle on which to get the position.
329 @param[out] Position Byte position from begining of file.
331 @retval EFI_SUCCESS The operation completed sucessfully.
332 @retval INVALID_PARAMETER One of the parameters has an invalid value.
333 @retval EFI_UNSUPPORTED The request is not valid on directories.
337 ShellGetFilePosition (
338 IN EFI_FILE_HANDLE FileHandle
,
343 Flushes data on a file
345 This function flushes all modified data associated with a file to a device.
347 @param[in] FileHandle The file handle on which to flush data.
349 @retval EFI_SUCCESS The data was flushed.
350 @retval EFI_NO_MEDIA The device has no media.
351 @retval EFI_DEVICE_ERROR The device reported an error.
352 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
353 @retval EFI_WRITE_PROTECTED The file or medium is write protected.
354 @retval EFI_ACCESS_DENIED The file was opened for read only.
359 IN EFI_FILE_HANDLE FileHandle
363 Retrieves the first file from a directory
365 This function takes an open directory handle and gets the first file
366 in the directory's info. Caller can use ShellFindNextFile() to get
369 Caller must use FreePool on *Buffer opon completion of all file searching.
371 @param[in] DirHandle The file handle of the directory to search
372 @param[out] Buffer Pointer to pointer to buffer for file's information
374 @retval EFI_SUCCESS Found the first file.
375 @retval EFI_NOT_FOUND Cannot find the directory.
376 @retval EFI_NO_MEDIA The device has no media.
377 @retval EFI_DEVICE_ERROR The device reported an error.
378 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
379 @return ShellReadFile
384 IN EFI_FILE_HANDLE DirHandle
,
385 OUT EFI_FILE_INFO
**Buffer
389 Retrieves the next file in a directory.
391 To use this function, caller must call the ShellFindFirstFile() to get the
392 first file, and then use this function get other files. This function can be
393 called for several times to get each file's information in the directory. If
394 the call of ShellFindNextFile() got the last file in the directory, the next
395 call of this function has no file to get. *NoFile will be set to TRUE and the
396 data in Buffer is meaningless.
398 @param[in] DirHandle The file handle of the directory.
399 @param[out] Buffer Pointer to buffer for file's information.
400 @param[out] NoFile Pointer to boolean when last file is found.
402 @retval EFI_SUCCESS Found the next file.
403 @retval EFI_NO_MEDIA The device has no media.
404 @retval EFI_DEVICE_ERROR The device reported an error.
405 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
410 IN EFI_FILE_HANDLE DirHandle
,
411 OUT EFI_FILE_INFO
*Buffer
,
416 Retrieve the size of a file.
418 This function extracts the file size info from the FileHandle's EFI_FILE_INFO
421 @param[in] FileHandle The file handle from which size is retrieved.
422 @param[out] Size Pointer to size.
424 @retval EFI_SUCCESS The operation was completed sucessfully.
425 @retval EFI_DEVICE_ERROR Cannot access the file.
430 IN EFI_FILE_HANDLE FileHandle
,
435 Retrieves the status of the break execution flag
437 This function is useful to check whether the application is being asked to halt by the shell.
439 @retval TRUE the execution break is enabled
440 @retval FALSE the execution break is not enabled
444 ShellGetExecutionBreakFlag(
449 Return the value of an environment variable.
451 This function gets the value of the environment variable set by the
452 ShellSetEnvironmentVariable function.
454 @param[in] EnvKey The key name of the environment variable.
456 @retval NULL The named environment variable does not exist.
457 @return != NULL pointer to the value of the environment variable.
461 ShellGetEnvironmentVariable (
462 IN CONST CHAR16
*EnvKey
466 Set the value of an environment variable.
468 This function changes the current value of the specified environment variable. If the
469 environment variable exists and the Value is an empty string, then the environment
470 variable is deleted. If the environment variable exists and the Value is not an empty
471 string, then the value of the environment variable is changed. If the environment
472 variable does not exist and the Value is an empty string, there is no action. If the
473 environment variable does not exist and the Value is a non-empty string, then the
474 environment variable is created and assigned the specified value.
476 This is not supported pre-UEFI Shell 2.0.
478 @param[in] EnvKey The key name of the environment variable.
479 @param[in] EnvVal The Value of the environment variable
480 @param[in] Volatile Indicates whether the variable is non-volatile (FALSE) or volatile (TRUE).
482 @retval EFI_SUCCESS the operation was completed sucessfully
483 @retval EFI_UNSUPPORTED This operation is not allowed in pre UEFI 2.0 Shell environments
487 ShellSetEnvironmentVariable (
488 IN CONST CHAR16
*EnvKey
,
489 IN CONST CHAR16
*EnvVal
,
494 Cause the shell to parse and execute a command line.
496 This function creates a nested instance of the shell and executes the specified
497 command (CommandLine) with the specified environment (Environment). Upon return,
498 the status code returned by the specified command is placed in StatusCode.
499 If Environment is NULL, then the current environment is used and all changes made
500 by the commands executed will be reflected in the current environment. If the
501 Environment is non-NULL, then the changes made will be discarded.
502 The CommandLine is executed from the current working directory on the current
505 The EnvironmentVariables and Status parameters are ignored in a pre-UEFI Shell 2.0
506 environment. The values pointed to by the parameters will be unchanged by the
507 ShellExecute() function. The Output parameter has no effect in a
508 UEFI Shell 2.0 environment.
510 @param[in] ImageHandle Parent image that is starting the operation.
511 @param[in] CommandLine Pointer to NULL terminated command line.
512 @param[in] Output True to display debug output. False to hide it.
513 @param[in] EnvironmentVariables Optional pointer to array of environment variables
514 in the form "x=y". If NULL current set is used.
515 @param[out] Status The status of the run command line.
517 @retval EFI_SUCCESS The operation completed sucessfully. Status
518 contains the status code returned.
519 @retval EFI_INVALID_PARAMETER A parameter contains an invalid value.
520 @retval EFI_OUT_OF_RESOURCES Out of resources.
521 @retval EFI_UNSUPPORTED The operation is not allowed.
526 IN EFI_HANDLE
*ParentHandle
,
527 IN CHAR16
*CommandLine
,
529 IN CHAR16
**EnvironmentVariables
,
530 OUT EFI_STATUS
*Status
534 Retreives the current directory path.
536 If the DeviceName is NULL, it returns the current device's current directory
537 name. If the DeviceName is not NULL, it returns the current directory name
540 @param[in] DeviceName The name of the file system to get directory on.
542 @retval NULL The directory does not exist.
543 @retval != NULL The directory.
548 IN CHAR16
*DeviceName OPTIONAL
552 Sets (enabled or disabled) the page break mode.
554 When page break mode is enabled the screen will stop scrolling
555 and wait for operator input before scrolling a subsequent screen.
557 @param[in] CurrentState TRUE to enable and FALSE to disable.
561 ShellSetPageBreakMode (
562 IN BOOLEAN CurrentState
566 Opens a group of files based on a path.
568 This function uses the Arg to open all the matching files. Each matched
569 file has a SHELL_FILE_ARG structure to record the file information. These
570 structures are placed on the list ListHead. Users can get the SHELL_FILE_ARG
571 structures from ListHead to access each file. This function supports wildcards
572 and will process '?' and '*' as such. The list must be freed with a call to
573 ShellCloseFileMetaArg().
575 If you are NOT appending to an existing list *ListHead must be NULL. If
576 *ListHead is NULL then it must be callee freed.
578 @param[in] Arg Pointer to path string.
579 @param[in] OpenMode Mode to open files with.
580 @param[in] ListHead Head of linked list of results.
582 @retval EFI_SUCCESS The operation was sucessful and the list head
583 contains the list of opened files.
584 @retval != EFI_SUCCESS The operation failed.
586 @sa InternalShellConvertFileListType
590 ShellOpenFileMetaArg (
593 IN OUT EFI_SHELL_FILE_INFO
**ListHead
597 Free the linked list returned from ShellOpenFileMetaArg.
599 @param[in] ListHead The pointer to free.
601 @retval EFI_SUCCESS The operation was sucessful.
602 @retval EFI_INVALID_PARAMETER A parameter was invalid.
606 ShellCloseFileMetaArg (
607 IN OUT EFI_SHELL_FILE_INFO
**ListHead
611 Find a file by searching the CWD and then the path.
613 If FileName is NULL, then ASSERT.
615 If the return value is not NULL then the memory must be caller freed.
617 @param[in] FileName Filename string.
619 @retval NULL The file was not found.
620 @retval !NULL The path to the file.
625 IN CONST CHAR16
*FileName
629 Find a file by searching the CWD and then the path with a variable set of file
630 extensions. If the file is not found it will append each extension in the list
631 in the order provided and return the first one that is successful.
633 If FileName is NULL, then ASSERT.
634 If FileExtension is NULL, then behavior is identical to ShellFindFilePath.
636 If the return value is not NULL then the memory must be caller freed.
638 @param[in] FileName Filename string.
639 @param[in] FileExtension Semi-colon delimeted list of possible extensions.
641 @retval NULL The file was not found.
642 @retval !NULL The path to the file.
646 ShellFindFilePathEx (
647 IN CONST CHAR16
*FileName
,
648 IN CONST CHAR16
*FileExtension
652 TypeFlag
= 0, ///< A flag that is present or not present only (IE "-a").
653 TypeValue
, ///< A flag that has some data following it with a space (IE "-a 1").
654 TypePosition
, ///< Some data that did not follow a parameter (IE "filename.txt").
655 TypeStart
, ///< A flag that has variable value appended to the end (IE "-ad", "-afd", "-adf", etc...).
656 TypeDoubleValue
, ///< A flag that has 2 space seperated value data following it (IE "-a 1 2").
657 TypeMaxValue
, ///< A flag followed by all the command line data before the next flag.
667 /// Helper structure for no parameters (besides -? and -b)
668 extern SHELL_PARAM_ITEM EmptyParamList
[];
671 Checks the command line arguments passed against the list of valid ones.
672 Optionally removes NULL values first.
674 If no initialization is required, then return RETURN_SUCCESS.
676 @param[in] CheckList Pointer to list of parameters to check.
677 @param[out] CheckPackage Package of checked values.
678 @param[out] ProblemParam Optional pointer to pointer to unicode string for
679 the paramater that caused failure.
680 @param[in] AutoPageBreak Will automatically set PageBreakEnabled.
681 @param[in] AlwaysAllowNumbers Will never fail for number based flags.
683 @retval EFI_SUCCESS The operation completed sucessfully.
684 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
685 @retval EFI_INVALID_PARAMETER A parameter was invalid.
686 @retval EFI_VOLUME_CORRUPTED The command line was corrupt. An argument was
687 duplicated. The duplicated command line argument
688 was returned in ProblemParam if provided.
689 @retval EFI_DEVICE_ERROR The commands contained 2 opposing arguments. One
690 of the command line arguments was returned in
691 ProblemParam if provided.
692 @retval EFI_NOT_FOUND A argument required a value that was missing.
693 The invalid command line argument was returned in
694 ProblemParam if provided.
698 ShellCommandLineParseEx (
699 IN CONST SHELL_PARAM_ITEM
*CheckList
,
700 OUT LIST_ENTRY
**CheckPackage
,
701 OUT CHAR16
**ProblemParam OPTIONAL
,
702 IN BOOLEAN AutoPageBreak
,
703 IN BOOLEAN AlwaysAllowNumbers
706 /// Make it easy to upgrade from older versions of the shell library.
707 #define ShellCommandLineParse(CheckList,CheckPackage,ProblemParam,AutoPageBreak) ShellCommandLineParseEx(CheckList,CheckPackage,ProblemParam,AutoPageBreak,FALSE)
710 Frees shell variable list that was returned from ShellCommandLineParse.
712 This function will free all the memory that was used for the CheckPackage
713 list of postprocessed shell arguments.
715 If CheckPackage is NULL, then return.
717 @param[in] CheckPackage The list to de-allocate.
721 ShellCommandLineFreeVarList (
722 IN LIST_ENTRY
*CheckPackage
726 Checks for presence of a flag parameter.
728 Flag arguments are in the form of "-<Key>" or "/<Key>", but do not have a value following the key.
730 If CheckPackage is NULL then return FALSE.
731 If KeyString is NULL then ASSERT().
733 @param[in] CheckPackage The package of parsed command line arguments.
734 @param[in] KeyString The Key of the command line argument to check for.
736 @retval TRUE The flag is on the command line.
737 @retval FALSE The flag is not on the command line.
741 ShellCommandLineGetFlag (
742 IN CONST LIST_ENTRY
*CheckPackage
,
747 Returns value from command line argument.
749 Value parameters are in the form of "-<Key> value" or "/<Key> value".
751 If CheckPackage is NULL, then return NULL.
753 @param[in] CheckPackage The package of parsed command line arguments.
754 @param[in] KeyString The Key of the command line argument to check for.
756 @retval NULL The flag is not on the command line.
757 @retval !=NULL Pointer to unicode string of the value.
761 ShellCommandLineGetValue (
762 IN CONST LIST_ENTRY
*CheckPackage
,
767 Returns raw value from command line argument.
769 Raw value parameters are in the form of "value" in a specific position in the list.
771 If CheckPackage is NULL, then return NULL.
773 @param[in] CheckPackage The package of parsed command line arguments.
774 @param[in] Position The position of the value.
776 @retval NULL The flag is not on the command line.
777 @retval !=NULL Pointer to unicode string of the value.
781 ShellCommandLineGetRawValue (
782 IN CONST LIST_ENTRY
*CheckPackage
,
787 Returns the number of command line value parameters that were parsed.
789 This will not include flags.
791 @retval (UINTN)-1 No parsing has ocurred.
792 @return The number of value parameters found.
796 ShellCommandLineGetCount(
801 Determins if a parameter is duplicated.
803 If Param is not NULL then it will point to a callee allocated string buffer
804 with the parameter value if a duplicate is found.
806 If CheckPackage is NULL, then ASSERT.
808 @param[in] CheckPackage The package of parsed command line arguments.
809 @param[out] Param Upon finding one, a pointer to the duplicated parameter.
811 @retval EFI_SUCCESS No parameters were duplicated.
812 @retval EFI_DEVICE_ERROR A duplicate was found.
816 ShellCommandLineCheckDuplicate (
817 IN CONST LIST_ENTRY
*CheckPackage
,
822 This function causes the shell library to initialize itself. If the shell library
823 is already initialized it will de-initialize all the current protocol poitners and
824 re-populate them again.
826 When the library is used with PcdShellLibAutoInitialize set to true this function
827 will return EFI_SUCCESS and perform no actions.
829 This function is intended for internal access for shell commands only.
831 @retval EFI_SUCCESS the initialization was complete sucessfully
841 Print at a specific location on the screen.
843 This function will move the cursor to a given screen location and print the specified string.
845 If -1 is specified for either the Row or Col the current screen location for BOTH
848 If either Row or Col is out of range for the current console, then ASSERT.
849 If Format is NULL, then ASSERT.
851 In addition to the standard %-based flags as supported by UefiLib Print() this supports
852 the following additional flags:
853 %N - Set output attribute to normal
854 %H - Set output attribute to highlight
855 %E - Set output attribute to error
856 %B - Set output attribute to blue color
857 %V - Set output attribute to green color
859 Note: The background color is controlled by the shell command cls.
861 @param[in] Row The row to print at.
862 @param[in] Col The column to print at.
863 @param[in] Format The format string.
865 @return The number of characters printed to the screen.
871 IN INT32 Col OPTIONAL
,
872 IN INT32 Row OPTIONAL
,
873 IN CONST CHAR16
*Format
,
878 Print at a specific location on the screen.
880 This function will move the cursor to a given screen location and print the specified string.
882 If -1 is specified for either the Row or Col the current screen location for BOTH
885 If either Row or Col is out of range for the current console, then ASSERT.
886 If Format is NULL, then ASSERT.
888 In addition to the standard %-based flags as supported by UefiLib Print() this supports
889 the following additional flags:
890 %N - Set output attribute to normal.
891 %H - Set output attribute to highlight.
892 %E - Set output attribute to error.
893 %B - Set output attribute to blue color.
894 %V - Set output attribute to green color.
896 Note: The background color is controlled by the shell command cls.
898 @param[in] Row The row to print at.
899 @param[in] Col The column to print at.
900 @param[in] Language The language of the string to retrieve. If this parameter
901 is NULL, then the current platform language is used.
902 @param[in] HiiFormatStringId The format string Id for getting from Hii.
903 @param[in] HiiFormatHandle The format string Handle for getting from Hii.
905 @return the number of characters printed to the screen.
910 IN INT32 Col OPTIONAL
,
911 IN INT32 Row OPTIONAL
,
912 IN CONST CHAR8
*Language OPTIONAL
,
913 IN CONST EFI_STRING_ID HiiFormatStringId
,
914 IN CONST EFI_HANDLE HiiFormatHandle
,
919 Function to determine if a given filename represents a directory.
921 If DirName is NULL, then ASSERT.
923 @param[in] DirName Path to directory to test.
925 @retval EFI_SUCCESS The Path represents a directory.
926 @retval EFI_NOT_FOUND The Path does not represent a directory.
927 @retval other The path failed to open.
932 IN CONST CHAR16
*DirName
936 Function to determine if a given filename represents a file.
938 This will search the CWD only.
940 If Name is NULL, then ASSERT.
942 @param[in] Name Path to file to test.
944 @retval EFI_SUCCESS The Path represents a file.
945 @retval EFI_NOT_FOUND The Path does not represent a file.
946 @retval other The path failed to open.
951 IN CONST CHAR16
*Name
955 Function to determine if a given filename represents a file.
957 This will search the CWD and then the Path.
959 If Name is NULL, then ASSERT.
961 @param[in] Name Path to file to test.
963 @retval EFI_SUCCESS The Path represents a file.
964 @retval EFI_NOT_FOUND The Path does not represent a file.
965 @retval other The path failed to open.
970 IN CONST CHAR16
*Name
974 Function to determine whether a string is decimal or hex representation of a number
975 and return the number converted from the string.
977 @param[in] String String representation of a number
979 @return The unsigned integer result of the conversion.
984 IN CONST CHAR16
*String
988 Safely append with automatic string resizing given length of Destination and
989 desired length of copy from Source.
991 Append the first D characters of Source to the end of Destination, where D is
992 the lesser of Count and the StrLen() of Source. If appending those D characters
993 will fit within Destination (whose Size is given as CurrentSize) and
994 still leave room for a NULL terminator, then those characters are appended,
995 starting at the original terminating NULL of Destination, and a new terminating
998 If appending D characters onto Destination will result in a overflow of the size
999 given in CurrentSize the string will be grown such that the copy can be performed
1000 and CurrentSize will be updated to the new size.
1002 If Source is NULL, there is nothing to append, just return the current buffer in
1005 If Destination is NULL, then ASSERT().
1006 If Destination's current length (including NULL terminator) is already more than
1007 CurrentSize, then ASSERT().
1009 @param[in,out] Destination The String to append onto.
1010 @param[in,out] CurrentSize On call the number of bytes in Destination. On
1011 return possibly the new size (still in bytes). If NULL
1012 then allocate whatever is needed.
1013 @param[in] Source The String to append from.
1014 @param[in] Count Maximum number of characters to append. If 0 then
1017 @return The Destination after apending the Source.
1022 IN OUT CHAR16
**Destination
,
1023 IN OUT UINTN
*CurrentSize
,
1024 IN CONST CHAR16
*Source
,
1029 This is a find and replace function. Upon successful return the NewString is a copy of
1030 SourceString with each instance of FindTarget replaced with ReplaceWith.
1032 If SourceString and NewString overlap the behavior is undefined.
1034 If the string would grow bigger than NewSize it will halt and return error.
1036 @param[in] SourceString String with source buffer.
1037 @param[in,out] NewString String with resultant buffer.
1038 @param[in] NewSize Size in bytes of NewString.
1039 @param[in] FindTarget String to look for.
1040 @param[in] ReplaceWith String to replace FindTarget with.
1041 @param[in] SkipPreCarrot If TRUE will skip a FindTarget that has a '^'
1042 immediately before it.
1044 @retval EFI_INVALID_PARAMETER SourceString was NULL.
1045 @retval EFI_INVALID_PARAMETER NewString was NULL.
1046 @retval EFI_INVALID_PARAMETER FindTarget was NULL.
1047 @retval EFI_INVALID_PARAMETER ReplaceWith was NULL.
1048 @retval EFI_INVALID_PARAMETER FindTarget had length < 1.
1049 @retval EFI_INVALID_PARAMETER SourceString had length < 1.
1050 @retval EFI_BUFFER_TOO_SMALL NewSize was less than the minimum size to hold
1051 the new string (truncation occurred).
1052 @retval EFI_SUCCESS The string was sucessfully copied with replacement.
1057 ShellCopySearchAndReplace2(
1058 IN CHAR16 CONST
*SourceString
,
1059 IN CHAR16
*NewString
,
1061 IN CONST CHAR16
*FindTarget
,
1062 IN CONST CHAR16
*ReplaceWith
,
1063 IN CONST BOOLEAN SkipPreCarrot
1067 /// make upgrades easier from old version
1069 #define ShellLibCopySearchAndReplace(a,b,c,d,e) ShellCopySearchAndReplace2(a,b,c,d,e,FALSE)
1072 Check if a Unicode character is a hexadecimal character.
1074 This internal function checks if a Unicode character is a
1075 decimal character. The valid hexadecimal character is
1076 L'0' to L'9', L'a' to L'f', or L'A' to L'F'.
1078 @param[in] Char The character to check.
1080 @retval TRUE The Char is a hexadecmial character.
1081 @retval FALSE The Char is not a hexadecmial character.
1086 ShellIsHexaDecimalDigitCharacter (
1091 /// What type of answer is requested
1094 SHELL_PROMPT_REQUEST_TYPE_YES_NO
,
1095 SHELL_PROMPT_REQUEST_TYPE_YES_NO_CANCEL
,
1096 SHELL_PROMPT_REQUEST_TYPE_FREEFORM
,
1097 SHELL_PROMPT_REQUEST_TYPE_QUIT_CONTINUE
,
1098 SHELL_PROMPT_REQUEST_TYPE_YES_NO_ALL_CANCEL
,
1099 SHELL_PROMPT_REQUEST_TYPE_ENTER_TO_COMTINUE
,
1100 SHELL_PROMPT_REQUEST_TYPE_ANYKEY_TO_COMTINUE
,
1101 SHELL_PROMPT_REQUEST_TYPE_MAX
1102 } SHELL_PROMPT_REQUEST_TYPE
;
1105 /// what answer was given
1108 SHELL_PROMPT_RESPONSE_YES
,
1109 SHELL_PROMPT_RESPONSE_NO
,
1110 SHELL_PROMPT_RESPONSE_CANCEL
,
1111 SHELL_PROMPT_RESPONSE_QUIT
,
1112 SHELL_PROMPT_RESPONSE_CONTINUE
,
1113 SHELL_PROMPT_RESPONSE_ALL
,
1114 SHELL_PROMPT_RESPONSE_MAX
1115 } SHELL_PROMPT_RESPONSE
;
1118 Prompt the user and return the resultant answer to the requestor.
1120 This function will display the requested question on the shell prompt and then
1121 wait for an apropriate answer to be input from the console.
1123 if the SHELL_PROMPT_REQUEST_TYPE is SHELL_PROMPT_REQUEST_TYPE_YESNO, SHELL_PROMPT_REQUEST_TYPE_QUIT_CONTINUE
1124 or SHELL_PROMPT_REQUEST_TYPE_YESNOCANCEL then *Response is of type SHELL_PROMPT_RESPONSE.
1126 if the SHELL_PROMPT_REQUEST_TYPE is SHELL_PROMPT_REQUEST_TYPE_FREEFORM then *Response is of type
1129 In either case *Response must be callee freed if Response was not NULL;
1131 @param Type What type of question is asked. This is used to filter the input
1132 to prevent invalid answers to question.
1133 @param Prompt Pointer to string prompt to use to request input.
1134 @param Response Pointer to Response which will be populated upon return.
1136 @retval EFI_SUCCESS The operation was sucessful.
1137 @retval EFI_UNSUPPORTED The operation is not supported as requested.
1138 @retval EFI_INVALID_PARAMETER A parameter was invalid.
1139 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
1140 @return other The operation failed.
1144 ShellPromptForResponse (
1145 IN SHELL_PROMPT_REQUEST_TYPE Type
,
1146 IN CHAR16
*Prompt OPTIONAL
,
1147 IN OUT VOID
**Response OPTIONAL
1151 Prompt the user and return the resultant answer to the requestor.
1153 This function is the same as ShellPromptForResponse, except that the prompt is
1154 automatically pulled from HII.
1156 @param Type What type of question is asked. This is used to filter the input
1157 to prevent invalid answers to question.
1158 @param Prompt Pointer to string prompt to use to request input.
1159 @param Response Pointer to Response which will be populated upon return.
1161 @retval EFI_SUCCESS the operation was sucessful.
1162 @return other the operation failed.
1164 @sa ShellPromptForResponse
1168 ShellPromptForResponseHii (
1169 IN SHELL_PROMPT_REQUEST_TYPE Type
,
1170 IN CONST EFI_STRING_ID HiiFormatStringId
,
1171 IN CONST EFI_HANDLE HiiFormatHandle
,
1172 IN OUT VOID
**Response
1176 #endif // __SHELL_LIB__