2 Provides interface to shell functionality for shell commands and applications.
4 Copyright (c) 2006 - 2010, 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
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 EnvironmentVariables and Status are only supported for UEFI Shell 2.0 (or later).
506 Output is only supported for pre-UEFI Shell 2.0
508 @param[in] ImageHandle Parent image that is starting the operation.
509 @param[in] CommandLine Pointer to null terminated command line.
510 @param[in] Output True to display debug output. False to hide it.
511 @param[in] EnvironmentVariables Optional pointer to array of environment variables
512 in the form "x=y". If NULL current set is used.
513 @param[out] Status The status of the run command line.
515 @retval EFI_SUCCESS The operation completed sucessfully. Status
516 contains the status code returned.
517 @retval EFI_INVALID_PARAMETER A parameter contains an invalid value.
518 @retval EFI_OUT_OF_RESOURCES Out of resources.
519 @retval EFI_UNSUPPORTED The operation is not allowed.
524 IN EFI_HANDLE
*ParentHandle
,
525 IN CHAR16
*CommandLine
,
527 IN CHAR16
**EnvironmentVariables
,
528 OUT EFI_STATUS
*Status
532 Retreives the current directory path.
534 If the DeviceName is NULL, it returns the current device's current directory
535 name. If the DeviceName is not NULL, it returns the current directory name
538 @param[in] DeviceName The name of the file system to get directory on.
540 @retval NULL The directory does not exist.
541 @retval != NULL The directory.
546 IN CHAR16
*DeviceName OPTIONAL
550 Sets (enabled or disabled) the page break mode.
552 When page break mode is enabled the screen will stop scrolling
553 and wait for operator input before scrolling a subsequent screen.
555 @param[in] CurrentState TRUE to enable and FALSE to disable.
559 ShellSetPageBreakMode (
560 IN BOOLEAN CurrentState
564 Opens a group of files based on a path.
566 This function uses the Arg to open all the matching files. Each matched
567 file has a SHELL_FILE_ARG structure to record the file information. These
568 structures are placed on the list ListHead. Users can get the SHELL_FILE_ARG
569 structures from ListHead to access each file. This function supports wildcards
570 and will process '?' and '*' as such. The list must be freed with a call to
571 ShellCloseFileMetaArg().
573 If you are NOT appending to an existing list *ListHead must be NULL. If
574 *ListHead is NULL then it must be callee freed.
576 @param[in] Arg Pointer to path string.
577 @param[in] OpenMode Mode to open files with.
578 @param[in] ListHead Head of linked list of results.
580 @retval EFI_SUCCESS The operation was sucessful and the list head
581 contains the list of opened files.
582 @retval != EFI_SUCCESS The operation failed.
584 @sa InternalShellConvertFileListType
588 ShellOpenFileMetaArg (
591 IN OUT EFI_SHELL_FILE_INFO
**ListHead
595 Free the linked list returned from ShellOpenFileMetaArg.
597 @param[in] ListHead The pointer to free.
599 @retval EFI_SUCCESS The operation was sucessful.
600 @retval EFI_INVALID_PARAMETER A parameter was invalid.
604 ShellCloseFileMetaArg (
605 IN OUT EFI_SHELL_FILE_INFO
**ListHead
609 Find a file by searching the CWD and then the path.
611 If FileName is NULL, then ASSERT.
613 If the return value is not NULL then the memory must be caller freed.
615 @param[in] FileName Filename string.
617 @retval NULL The file was not found.
618 @retval !NULL The path to the file.
623 IN CONST CHAR16
*FileName
627 Find a file by searching the CWD and then the path with a variable set of file
628 extensions. If the file is not found it will append each extension in the list
629 in the order provided and return the first one that is successful.
631 If FileName is NULL, then ASSERT.
632 If FileExtension is NULL, then behavior is identical to ShellFindFilePath.
634 If the return value is not NULL then the memory must be caller freed.
636 @param[in] FileName Filename string.
637 @param[in] FileExtension Semi-colon delimeted list of possible extensions.
639 @retval NULL The file was not found.
640 @retval !NULL The path to the file.
644 ShellFindFilePathEx (
645 IN CONST CHAR16
*FileName
,
646 IN CONST CHAR16
*FileExtension
650 TypeFlag
= 0, ///< A flag that is present or not present only (IE "-a").
651 TypeValue
, ///< A flag that has some data following it with a space (IE "-a 1").
652 TypePosition
, ///< Some data that did not follow a parameter (IE "filename.txt").
653 TypeStart
, ///< A flag that has variable value appended to the end (IE "-ad", "-afd", "-adf", etc...).
654 TypeDoubleValue
, ///< A flag that has 2 space seperated value data following it (IE "-a 1 2").
655 TypeMaxValue
, ///< A flag followed by all the command line data before the next flag.
665 /// Helper structure for no parameters (besides -? and -b)
666 extern SHELL_PARAM_ITEM EmptyParamList
[];
669 Checks the command line arguments passed against the list of valid ones.
670 Optionally removes NULL values first.
672 If no initialization is required, then return RETURN_SUCCESS.
674 @param[in] CheckList Pointer to list of parameters to check.
675 @param[out] CheckPackage Package of checked values.
676 @param[out] ProblemParam Optional pointer to pointer to unicode string for
677 the paramater that caused failure.
678 @param[in] AutoPageBreak Will automatically set PageBreakEnabled.
679 @param[in] AlwaysAllowNumbers Will never fail for number based flags.
681 @retval EFI_SUCCESS The operation completed sucessfully.
682 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
683 @retval EFI_INVALID_PARAMETER A parameter was invalid.
684 @retval EFI_VOLUME_CORRUPTED The command line was corrupt. An argument was
685 duplicated. The duplicated command line argument
686 was returned in ProblemParam if provided.
687 @retval EFI_DEVICE_ERROR The commands contained 2 opposing arguments. One
688 of the command line arguments was returned in
689 ProblemParam if provided.
690 @retval EFI_NOT_FOUND A argument required a value that was missing.
691 The invalid command line argument was returned in
692 ProblemParam if provided.
696 ShellCommandLineParseEx (
697 IN CONST SHELL_PARAM_ITEM
*CheckList
,
698 OUT LIST_ENTRY
**CheckPackage
,
699 OUT CHAR16
**ProblemParam OPTIONAL
,
700 IN BOOLEAN AutoPageBreak
,
701 IN BOOLEAN AlwaysAllowNumbers
704 /// Make it easy to upgrade from older versions of the shell library.
705 #define ShellCommandLineParse(CheckList,CheckPackage,ProblemParam,AutoPageBreak) ShellCommandLineParseEx(CheckList,CheckPackage,ProblemParam,AutoPageBreak,FALSE)
708 Frees shell variable list that was returned from ShellCommandLineParse.
710 This function will free all the memory that was used for the CheckPackage
711 list of postprocessed shell arguments.
713 If CheckPackage is NULL, then return.
715 @param[in] CheckPackage The list to de-allocate.
719 ShellCommandLineFreeVarList (
720 IN LIST_ENTRY
*CheckPackage
724 Checks for presence of a flag parameter.
726 Flag arguments are in the form of "-<Key>" or "/<Key>", but do not have a value following the key.
728 If CheckPackage is NULL then return FALSE.
729 If KeyString is NULL then ASSERT().
731 @param[in] CheckPackage The package of parsed command line arguments.
732 @param[in] KeyString The Key of the command line argument to check for.
734 @retval TRUE The flag is on the command line.
735 @retval FALSE The flag is not on the command line.
739 ShellCommandLineGetFlag (
740 IN CONST LIST_ENTRY
*CheckPackage
,
745 Returns value from command line argument.
747 Value parameters are in the form of "-<Key> value" or "/<Key> value".
749 If CheckPackage is NULL, then return NULL.
751 @param[in] CheckPackage The package of parsed command line arguments.
752 @param[in] KeyString The Key of the command line argument to check for.
754 @retval NULL The flag is not on the command line.
755 @retval !=NULL Pointer to unicode string of the value.
759 ShellCommandLineGetValue (
760 IN CONST LIST_ENTRY
*CheckPackage
,
765 Returns raw value from command line argument.
767 Raw value parameters are in the form of "value" in a specific position in the list.
769 If CheckPackage is NULL, then return NULL.
771 @param[in] CheckPackage The package of parsed command line arguments.
772 @param[in] Position The position of the value.
774 @retval NULL The flag is not on the command line.
775 @retval !=NULL Pointer to unicode string of the value.
779 ShellCommandLineGetRawValue (
780 IN CONST LIST_ENTRY
*CheckPackage
,
785 Returns the number of command line value parameters that were parsed.
787 This will not include flags.
789 @retval (UINTN)-1 No parsing has ocurred.
790 @return The number of value parameters found.
794 ShellCommandLineGetCount(
799 Determins if a parameter is duplicated.
801 If Param is not NULL then it will point to a callee allocated string buffer
802 with the parameter value if a duplicate is found.
804 If CheckPackage is NULL, then ASSERT.
806 @param[in] CheckPackage The package of parsed command line arguments.
807 @param[out] Param Upon finding one, a pointer to the duplicated parameter.
809 @retval EFI_SUCCESS No parameters were duplicated.
810 @retval EFI_DEVICE_ERROR A duplicate was found.
814 ShellCommandLineCheckDuplicate (
815 IN CONST LIST_ENTRY
*CheckPackage
,
820 This function causes the shell library to initialize itself. If the shell library
821 is already initialized it will de-initialize all the current protocol poitners and
822 re-populate them again.
824 When the library is used with PcdShellLibAutoInitialize set to true this function
825 will return EFI_SUCCESS and perform no actions.
827 This function is intended for internal access for shell commands only.
829 @retval EFI_SUCCESS the initialization was complete sucessfully
839 Print at a specific location on the screen.
841 This function will move the cursor to a given screen location and print the specified string.
843 If -1 is specified for either the Row or Col the current screen location for BOTH
846 If either Row or Col is out of range for the current console, then ASSERT.
847 If Format is NULL, then ASSERT.
849 In addition to the standard %-based flags as supported by UefiLib Print() this supports
850 the following additional flags:
851 %N - Set output attribute to normal
852 %H - Set output attribute to highlight
853 %E - Set output attribute to error
854 %B - Set output attribute to blue color
855 %V - Set output attribute to green color
857 Note: The background color is controlled by the shell command cls.
859 @param[in] Row The row to print at.
860 @param[in] Col The column to print at.
861 @param[in] Format The format string.
863 @return The number of characters printed to the screen.
869 IN INT32 Col OPTIONAL
,
870 IN INT32 Row OPTIONAL
,
871 IN CONST CHAR16
*Format
,
876 Print at a specific location on the screen.
878 This function will move the cursor to a given screen location and print the specified string.
880 If -1 is specified for either the Row or Col the current screen location for BOTH
883 If either Row or Col is out of range for the current console, then ASSERT.
884 If Format is NULL, then ASSERT.
886 In addition to the standard %-based flags as supported by UefiLib Print() this supports
887 the following additional flags:
888 %N - Set output attribute to normal.
889 %H - Set output attribute to highlight.
890 %E - Set output attribute to error.
891 %B - Set output attribute to blue color.
892 %V - Set output attribute to green color.
894 Note: The background color is controlled by the shell command cls.
896 @param[in] Row The row to print at.
897 @param[in] Col The column to print at.
898 @param[in] HiiFormatStringId The format string Id for getting from Hii.
899 @param[in] HiiFormatHandle The format string Handle for getting from Hii.
901 @return the number of characters printed to the screen.
906 IN INT32 Col OPTIONAL
,
907 IN INT32 Row OPTIONAL
,
908 IN CONST EFI_STRING_ID HiiFormatStringId
,
909 IN CONST EFI_HANDLE HiiFormatHandle
,
914 Function to determine if a given filename represents a directory.
916 If DirName is NULL, then ASSERT.
918 @param[in] DirName Path to directory to test.
920 @retval EFI_SUCCESS The Path represents a directory.
921 @retval EFI_NOT_FOUND The Path does not represent a directory.
922 @retval other The path failed to open.
927 IN CONST CHAR16
*DirName
931 Function to determine if a given filename represents a file.
933 This will search the CWD only.
935 If Name is NULL, then ASSERT.
937 @param[in] Name Path to file to test.
939 @retval EFI_SUCCESS The Path represents a file.
940 @retval EFI_NOT_FOUND The Path does not represent a file.
941 @retval other The path failed to open.
946 IN CONST CHAR16
*Name
950 Function to determine if a given filename represents a file.
952 This will search the CWD and then the Path.
954 If Name is NULL, then ASSERT.
956 @param[in] Name Path to file to test.
958 @retval EFI_SUCCESS The Path represents a file.
959 @retval EFI_NOT_FOUND The Path does not represent a file.
960 @retval other The path failed to open.
965 IN CONST CHAR16
*Name
969 Function to determine whether a string is decimal or hex representation of a number
970 and return the number converted from the string.
972 @param[in] String String representation of a number
974 @return The unsigned integer result of the conversion.
979 IN CONST CHAR16
*String
983 Safely append with automatic string resizing given length of Destination and
984 desired length of copy from Source.
986 Append the first D characters of Source to the end of Destination, where D is
987 the lesser of Count and the StrLen() of Source. If appending those D characters
988 will fit within Destination (whose Size is given as CurrentSize) and
989 still leave room for a null terminator, then those characters are appended,
990 starting at the original terminating null of Destination, and a new terminating
993 If appending D characters onto Destination will result in a overflow of the size
994 given in CurrentSize the string will be grown such that the copy can be performed
995 and CurrentSize will be updated to the new size.
997 If Source is NULL, there is nothing to append, just return the current buffer in
1000 If Destination is NULL, then ASSERT().
1001 If Destination's current length (including NULL terminator) is already more than
1002 CurrentSize, then ASSERT().
1004 @param[in,out] Destination The String to append onto.
1005 @param[in,out] CurrentSize On call the number of bytes in Destination. On
1006 return possibly the new size (still in bytes). If NULL
1007 then allocate whatever is needed.
1008 @param[in] Source The String to append from.
1009 @param[in] Count Maximum number of characters to append. If 0 then
1012 @return The Destination after apending the Source.
1017 IN OUT CHAR16
**Destination
,
1018 IN OUT UINTN
*CurrentSize
,
1019 IN CONST CHAR16
*Source
,
1024 This is a find and replace function. Upon successful return the NewString is a copy of
1025 SourceString with each instance of FindTarget replaced with ReplaceWith.
1027 If SourceString and NewString overlap the behavior is undefined.
1029 If the string would grow bigger than NewSize it will halt and return error.
1031 @param[in] SourceString String with source buffer.
1032 @param[in,out] NewString String with resultant buffer.
1033 @param[in] NewSize Size in bytes of NewString.
1034 @param[in] FindTarget String to look for.
1035 @param[in] ReplaceWith String to replace FindTarget with.
1036 @param[in] SkipPreCarrot If TRUE will skip a FindTarget that has a '^'
1037 immediately before it.
1039 @retval EFI_INVALID_PARAMETER SourceString was NULL.
1040 @retval EFI_INVALID_PARAMETER NewString was NULL.
1041 @retval EFI_INVALID_PARAMETER FindTarget was NULL.
1042 @retval EFI_INVALID_PARAMETER ReplaceWith was NULL.
1043 @retval EFI_INVALID_PARAMETER FindTarget had length < 1.
1044 @retval EFI_INVALID_PARAMETER SourceString had length < 1.
1045 @retval EFI_BUFFER_TOO_SMALL NewSize was less than the minimum size to hold
1046 the new string (truncation occurred).
1047 @retval EFI_SUCCESS The string was sucessfully copied with replacement.
1052 ShellCopySearchAndReplace2(
1053 IN CHAR16 CONST
*SourceString
,
1054 IN CHAR16
*NewString
,
1056 IN CONST CHAR16
*FindTarget
,
1057 IN CONST CHAR16
*ReplaceWith
,
1058 IN CONST BOOLEAN SkipPreCarrot
1062 /// make upgrades easier from old version
1064 #define ShellLibCopySearchAndReplace(a,b,c,d,e) ShellCopySearchAndReplace2(a,b,c,d,e,FALSE)
1067 Check if a Unicode character is a hexadecimal character.
1069 This internal function checks if a Unicode character is a
1070 decimal character. The valid hexadecimal character is
1071 L'0' to L'9', L'a' to L'f', or L'A' to L'F'.
1073 @param[in] Char The character to check.
1075 @retval TRUE The Char is a hexadecmial character.
1076 @retval FALSE The Char is not a hexadecmial character.
1081 ShellIsHexaDecimalDigitCharacter (
1085 #endif // __SHELL_LIB__