X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ShellPkg%2FInclude%2FLibrary%2FShellLib.h;h=88020a06a89c57cc3540ee0a7a97dbc184b87e56;hb=9ed21946c76e430097e9c4e59b419af928e0cb8c;hp=6061262221c127e882ac6c101785db28a81f2b76;hpb=4bbdc0e1bd5807c00a33e30dfc208e0e86b4c236;p=mirror_edk2.git diff --git a/ShellPkg/Include/Library/ShellLib.h b/ShellPkg/Include/Library/ShellLib.h index 6061262221..88020a06a8 100644 --- a/ShellPkg/Include/Library/ShellLib.h +++ b/ShellPkg/Include/Library/ShellLib.h @@ -1,7 +1,7 @@ /** @file Provides interface to shell functionality for shell commands and applications. - Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.
+ Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -27,8 +27,8 @@ // (20 * (6+5+2))+1) unicode characters from EFI FAT spec (doubled for bytes) #define MAX_FILE_NAME_LEN 512 -extern EFI_SHELL_PARAMETERS_PROTOCOL *mEfiShellParametersProtocol; -extern EFI_SHELL_PROTOCOL *mEfiShellProtocol; +extern EFI_SHELL_PARAMETERS_PROTOCOL *gEfiShellParametersProtocol; +extern EFI_SHELL_PROTOCOL *gEfiShellProtocol; /** This function will retrieve the information about the file for the handle @@ -59,20 +59,20 @@ ShellGetFileInfo ( @param[in] FileInfo The information to set. - @retval EFI_SUCCESS The information was set. + @retval EFI_SUCCESS The information was set. @retval EFI_INVALID_PARAMETER A parameter was out of range or invalid. @retval EFI_UNSUPPORTED The FileHandle does not support FileInfo. - @retval EFI_NO_MEDIA The device has no medium. - @retval EFI_DEVICE_ERROR The device reported an error. - @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. - @retval EFI_WRITE_PROTECTED The file or medium is write protected. + @retval EFI_NO_MEDIA The device has no medium. + @retval EFI_DEVICE_ERROR The device reported an error. + @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. + @retval EFI_WRITE_PROTECTED The file or medium is write protected. @retval EFI_ACCESS_DENIED The file was opened read only. @retval EFI_VOLUME_FULL The volume is full. **/ EFI_STATUS EFIAPI ShellSetFileInfo ( - IN SHELL_FILE_HANDLE FileHandle, + IN SHELL_FILE_HANDLE FileHandle, IN EFI_FILE_INFO *FileInfo ); @@ -82,38 +82,38 @@ ShellSetFileInfo ( This function opens a file with the open mode according to the file path. The Attributes is valid only for EFI_FILE_MODE_CREATE. - @param[in,out] FilePath On input, the device path to the file. On output, - the remaining device path. - @param[out] DeviceHandle Pointer to the system device handle. - @param[out] FileHandle Pointer to the file handle. - @param[in] OpenMode The mode to open the file with. - @param[in] Attributes The file's file attributes. + @param[in, out] FilePath On input, the device path to the file. On output, + the remaining device path. + @param[out] DeviceHandle Pointer to the system device handle. + @param[out] FileHandle Pointer to the file handle. + @param[in] OpenMode The mode to open the file with. + @param[in] Attributes The file's file attributes. - @retval EFI_SUCCESS The information was set. - @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value. + @retval EFI_SUCCESS The information was set. + @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value. @retval EFI_UNSUPPORTED Could not open the file path. - @retval EFI_NOT_FOUND The specified file could not be found on the + @retval EFI_NOT_FOUND The specified file could not be found on the device or the file system could not be found on the device. @retval EFI_NO_MEDIA The device has no medium. @retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no longer supported. @retval EFI_DEVICE_ERROR The device reported an error. - @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. + @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. @retval EFI_WRITE_PROTECTED The file or medium is write protected. @retval EFI_ACCESS_DENIED The file was opened read only. - @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the + @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the file. @retval EFI_VOLUME_FULL The volume is full. **/ EFI_STATUS EFIAPI ShellOpenFileByDevicePath( - IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath, - OUT EFI_HANDLE *DeviceHandle, - OUT SHELL_FILE_HANDLE *FileHandle, - IN UINT64 OpenMode, - IN UINT64 Attributes + IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath, + OUT EFI_HANDLE *DeviceHandle, + OUT SHELL_FILE_HANDLE *FileHandle, + IN UINT64 OpenMode, + IN UINT64 Attributes ); /** @@ -128,30 +128,30 @@ ShellOpenFileByDevicePath( @param[in] OpenMode The mode to open the file with. @param[in] Attributes The file's file attributes. - @retval EFI_SUCCESS The information was set. - @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value. + @retval EFI_SUCCESS The information was set. + @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value. @retval EFI_UNSUPPORTED Could not open the file path. - @retval EFI_NOT_FOUND The specified file could not be found on the + @retval EFI_NOT_FOUND The specified file could not be found on the device or the file system could not be found on the device. @retval EFI_NO_MEDIA The device has no medium. @retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no longer supported. @retval EFI_DEVICE_ERROR The device reported an error. - @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. + @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. @retval EFI_WRITE_PROTECTED The file or medium is write protected. @retval EFI_ACCESS_DENIED The file was opened read only. - @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the + @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the file. @retval EFI_VOLUME_FULL The volume is full. **/ EFI_STATUS EFIAPI ShellOpenFileByName( - IN CONST CHAR16 *FilePath, + IN CONST CHAR16 *FilePath, OUT SHELL_FILE_HANDLE *FileHandle, IN UINT64 OpenMode, - IN UINT64 Attributes + IN UINT64 Attributes ); /** @@ -164,20 +164,20 @@ ShellOpenFileByName( @param[in] DirectoryName The pointer to Directory name. @param[out] FileHandle The pointer to the file handle. - @retval EFI_SUCCESS The information was set. - @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value. + @retval EFI_SUCCESS The information was set. + @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value. @retval EFI_UNSUPPORTED Could not open the file path. - @retval EFI_NOT_FOUND The specified file could not be found on the + @retval EFI_NOT_FOUND The specified file could not be found on the device, or the file system could not be found on the device. @retval EFI_NO_MEDIA The device has no medium. @retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no longer supported. @retval EFI_DEVICE_ERROR The device reported an error. - @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. + @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. @retval EFI_WRITE_PROTECTED The file or medium is write protected. @retval EFI_ACCESS_DENIED The file was opened read only. - @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the + @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the file. @retval EFI_VOLUME_FULL The volume is full. **/ @@ -204,15 +204,15 @@ ShellCreateDirectory( are no more directory entries, the read returns a zero-length buffer. EFI_FILE_INFO is the structure returned as the directory entry. - @param[in] FileHandle The opened file handle. - @param[in,out] ReadSize On input the size of buffer in bytes. On return - the number of bytes written. - @param[out] Buffer The buffer to put read data into. + @param[in] FileHandle The opened file handle. + @param[in, out] ReadSize On input the size of buffer in bytes. On return + the number of bytes written. + @param[out] Buffer The buffer to put read data into. @retval EFI_SUCCESS Data was read. - @retval EFI_NO_MEDIA The device has no media. + @retval EFI_NO_MEDIA The device has no media. @retval EFI_DEVICE_ERROR The device reported an error. - @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. + @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. @retval EFI_BUFFER_TO_SMALL Buffer is too small. ReadSize contains required size. @@ -235,16 +235,16 @@ ShellReadFile( The file is automatically grown to hold the data if required. Direct writes to opened directories are not supported. - @param[in] FileHandle The opened file for writing. + @param[in] FileHandle The opened file for writing. - @param[in,out] BufferSize On input the number of bytes in Buffer. On output - the number of bytes written. + @param[in, out] BufferSize On input the number of bytes in Buffer. On output + the number of bytes written. - @param[in] Buffer The buffer containing data to write is stored. + @param[in] Buffer The buffer containing data to write is stored. @retval EFI_SUCCESS Data was written. @retval EFI_UNSUPPORTED Writes to an open directory are not supported. - @retval EFI_NO_MEDIA The device has no media. + @retval EFI_NO_MEDIA The device has no media. @retval EFI_DEVICE_ERROR The device reported an error. @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. @retval EFI_WRITE_PROTECTED The device is write-protected. @@ -289,7 +289,7 @@ ShellCloseFile ( @retval EFI_SUCCESS The file was closed sucessfully. @retval EFI_WARN_DELETE_FAILURE The handle was closed, but the file was not deleted. - @retval INVALID_PARAMETER One of the parameters has an invalid value. + @retval INVALID_PARAMETER One of the parameters has an invalid value. **/ EFI_STATUS EFIAPI @@ -320,8 +320,8 @@ ShellDeleteFile ( EFI_STATUS EFIAPI ShellSetFilePosition ( - IN SHELL_FILE_HANDLE FileHandle, - IN UINT64 Position + IN SHELL_FILE_HANDLE FileHandle, + IN UINT64 Position ); /** @@ -366,16 +366,18 @@ ShellFlushFile ( IN SHELL_FILE_HANDLE FileHandle ); -/** - Retrieves the first file from a directory +/** Retrieve first entry from a directory. - This function takes an open directory handle and gets the first file - in the directory's info. Caller can use ShellFindNextFile() to get - subsequent files. + This function takes an open directory handle and gets information from the + first entry in the directory. A buffer is allocated to contain + the information and a pointer to the buffer is returned in *Buffer. The + caller can use ShellFindNextFile() to get subsequent directory entries. - Caller must use FreePool on *Buffer opon completion of all file searching. + The buffer will be freed by ShellFindNextFile() when the last directory + entry is read. Otherwise, the caller must free the buffer, using FreePool, + when finished with it. - @param[in] DirHandle The file handle of the directory to search. + @param[in] DirHandle The file handle of the directory to search. @param[out] Buffer The pointer to the buffer for the file's information. @retval EFI_SUCCESS Found the first file. @@ -383,41 +385,44 @@ ShellFlushFile ( @retval EFI_NO_MEDIA The device has no media. @retval EFI_DEVICE_ERROR The device reported an error. @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. + @return Others Status of ShellGetFileInfo, ShellSetFilePosition, + or ShellReadFile. + @sa ShellReadFile **/ EFI_STATUS EFIAPI ShellFindFirstFile ( - IN SHELL_FILE_HANDLE DirHandle, - OUT EFI_FILE_INFO **Buffer + IN SHELL_FILE_HANDLE DirHandle, + OUT EFI_FILE_INFO **Buffer ); -/** - Retrieves the next file in a directory. +/** Retrieve next entries from a directory. - To use this function, caller must call the ShellFindFirstFile() to get the - first file, and then use this function get other files. This function can be - called for several times to get each file's information in the directory. If - the call of ShellFindNextFile() got the last file in the directory, the next - call of this function has no file to get. *NoFile will be set to TRUE, and the - data in Buffer is meaningless. + To use this function, the caller must first call the ShellFindFirstFile() + function to get the first directory entry. Subsequent directory entries are + retrieved by using the ShellFindNextFile() function. This function can + be called several times to get each entry from the directory. If the call of + ShellFindNextFile() retrieved the last directory entry, the next call of + this function will set *NoFile to TRUE and free the buffer. - @param[in] DirHandle The file handle of the directory. - @param[in,out] Buffer The pointer to buffer for file's information. - @param[in,out] NoFile The pointer to boolean when last file is found. + @param[in] DirHandle The file handle of the directory. + @param[in, out] Buffer The pointer to buffer for file's information. + @param[in, out] NoFile The pointer to boolean when last file is found. @retval EFI_SUCCESS Found the next file. @retval EFI_NO_MEDIA The device has no media. @retval EFI_DEVICE_ERROR The device reported an error. @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. + @sa ShellReadFile **/ EFI_STATUS EFIAPI ShellFindNextFile( - IN SHELL_FILE_HANDLE DirHandle, - IN OUT EFI_FILE_INFO *Buffer, - IN OUT BOOLEAN *NoFile + IN SHELL_FILE_HANDLE DirHandle, + IN OUT EFI_FILE_INFO *Buffer, + IN OUT BOOLEAN *NoFile ); /** @@ -545,6 +550,8 @@ ShellExecute ( name. If the DeviceName is not NULL, it returns the current directory name on specified drive. + Note that the current directory string should exclude the tailing backslash character. + @param[in] DeviceName The name of the file system to get directory on. @retval NULL The directory does not exist. @@ -583,9 +590,9 @@ ShellSetPageBreakMode ( If you are NOT appending to an existing list *ListHead must be NULL. If *ListHead is NULL then it must be callee freed. - @param[in] Arg The pointer to path string. - @param[in] OpenMode Mode to open files with. - @param[in,out] ListHead Head of linked list of results. + @param[in] Arg The pointer to path string. + @param[in] OpenMode Mode to open files with. + @param[in, out] ListHead Head of linked list of results. @retval EFI_SUCCESS The operation was sucessful and the list head contains the list of opened files. @@ -604,7 +611,7 @@ ShellOpenFileMetaArg ( /** Free the linked list returned from ShellOpenFileMetaArg. - @param[in,out] ListHead The pointer to free. + @param[in, out] ListHead The pointer to free. @retval EFI_SUCCESS The operation was sucessful. @retval EFI_INVALID_PARAMETER A parameter was invalid. @@ -663,6 +670,7 @@ typedef enum { TypeStart, ///< A flag that has variable value appended to the end (IE "-ad", "-afd", "-adf", etc...). TypeDoubleValue, ///< A flag that has 2 space seperated value data following it (IE "-a 1 2"). TypeMaxValue, ///< A flag followed by all the command line data before the next flag. + TypeTimeValue, ///< A flag that has a time value following it (IE "-a -5:00"). TypeMax, } SHELL_PARAM_TYPE; @@ -988,7 +996,7 @@ ShellIsFileInPath( Function to determine whether a string is decimal or hex representation of a number and return the number converted from the string. - Note: this function cannot be used when (UINTN)(-1), (0xFFFFFFFF) may be a valid + Note: this function cannot be used when (UINTN)(-1), (0xFFFFFFFF) may be a valid result. Use ShellConvertStringToUint64 instead. @param[in] String String representation of a number. @@ -1002,6 +1010,23 @@ ShellStrToUintn( IN CONST CHAR16 *String ); +/** + Function return the number converted from a hex representation of a number. + + Note: this function cannot be used when (UINTN)(-1), (0xFFFFFFFF) may be a valid + result. Use ShellConvertStringToUint64 instead. + + @param[in] String String representation of a number. + + @return The unsigned integer result of the conversion. + @retval (UINTN)(-1) An error occured. +**/ +UINTN +EFIAPI +ShellHexStrToUintn( + IN CONST CHAR16 *String + ); + /** Safely append with automatic string resizing given length of Destination and desired length of copy from Source. @@ -1024,13 +1049,13 @@ ShellStrToUintn( If Destination's current length (including NULL terminator) is already more than CurrentSize, then ASSERT(). - @param[in,out] Destination The String to append onto. - @param[in,out] CurrentSize On call, the number of bytes in Destination. On - return, possibly the new size (still in bytes). If NULL, - then allocate whatever is needed. - @param[in] Source The String to append from. - @param[in] Count The maximum number of characters to append. If 0, then - all are appended. + @param[in, out] Destination The String to append onto. + @param[in, out] CurrentSize On call, the number of bytes in Destination. On + return, possibly the new size (still in bytes). If NULL, + then allocate whatever is needed. + @param[in] Source The String to append from. + @param[in] Count The maximum number of characters to append. If 0, then + all are appended. @return The Destination after appending the Source. **/ @@ -1051,14 +1076,14 @@ StrnCatGrow ( If the string would grow bigger than NewSize it will halt and return error. - @param[in] SourceString The string with source buffer. - @param[in,out] NewString The string with resultant buffer. - @param[in] NewSize The size in bytes of NewString. - @param[in] FindTarget The string to look for. - @param[in] ReplaceWith The string to replace FindTarget with. - @param[in] SkipPreCarrot If TRUE will skip a FindTarget that has a '^' - immediately before it. - @param[in] ParameterReplacing If TRUE will add "" around items with spaces. + @param[in] SourceString The string with source buffer. + @param[in, out] NewString The string with resultant buffer. + @param[in] NewSize The size in bytes of NewString. + @param[in] FindTarget The string to look for. + @param[in] ReplaceWith The string to replace FindTarget with. + @param[in] SkipPreCarrot If TRUE will skip a FindTarget that has a '^' + immediately before it. + @param[in] ParameterReplacing If TRUE will add "" around items with spaces. @retval EFI_INVALID_PARAMETER SourceString was NULL. @retval EFI_INVALID_PARAMETER NewString was NULL. @@ -1189,9 +1214,9 @@ ShellPromptForResponse ( @param[in] Type What type of question is asked. This is used to filter the input to prevent invalid answers to question. - @param[in] HiiFormatStringId The format string Id for getting from Hii. - @param[in] HiiFormatHandle The format string Handle for getting from Hii. - @param[out] Response The pointer to Response, which will be populated upon return. + @param[in] HiiFormatStringId The format string Id for getting from Hii. + @param[in] HiiFormatHandle The format string Handle for getting from Hii. + @param[in, out] Response The pointer to Response, which will be populated upon return. @retval EFI_SUCCESS The operation was sucessful. @return other The operation failed. @@ -1235,9 +1260,9 @@ ShellIsHexOrDecimalNumber ( @param[in] String The string to evaluate. @param[out] Value Upon a successful return the value of the conversion. @param[in] ForceHex TRUE - always assume hex. - @param[in] StopAtSpace TRUE to halt upon finding a space, FALSE to + @param[in] StopAtSpace TRUE to halt upon finding a space, FALSE to process the entire String. - + @retval EFI_SUCCESS The conversion was successful. @retval EFI_INVALID_PARAMETER String contained an invalid character. @retval EFI_NOT_FOUND String was a number, but Value was NULL. @@ -1266,4 +1291,110 @@ ShellFileExists( IN CONST CHAR16 *Name ); +/** + Function to read a single line from a SHELL_FILE_HANDLE. The \n is not included in the returned + buffer. The returned buffer must be callee freed. + + If the position upon start is 0, then the Ascii Boolean will be set. This should be + maintained and not changed for all operations with the same file. + + @param[in] Handle SHELL_FILE_HANDLE to read from. + @param[in, out] Ascii Boolean value for indicating whether the file is + Ascii (TRUE) or UCS2 (FALSE). + + @return The line of text from the file. + + @sa ShellFileHandleReadLine +**/ +CHAR16* +EFIAPI +ShellFileHandleReturnLine( + IN SHELL_FILE_HANDLE Handle, + IN OUT BOOLEAN *Ascii + ); + +/** + Function to read a single line (up to but not including the \n) from a SHELL_FILE_HANDLE. + + If the position upon start is 0, then the Ascii Boolean will be set. This should be + maintained and not changed for all operations with the same file. + + @param[in] Handle SHELL_FILE_HANDLE to read from. + @param[in, out] Buffer The pointer to buffer to read into. + @param[in, out] Size The pointer to number of bytes in Buffer. + @param[in] Truncate If the buffer is large enough, this has no effect. + If the buffer is is too small and Truncate is TRUE, + the line will be truncated. + If the buffer is is too small and Truncate is FALSE, + then no read will occur. + + @param[in, out] Ascii Boolean value for indicating whether the file is + Ascii (TRUE) or UCS2 (FALSE). + + @retval EFI_SUCCESS The operation was successful. The line is stored in + Buffer. + @retval EFI_END_OF_FILE There are no more lines in the file. + @retval EFI_INVALID_PARAMETER Handle was NULL. + @retval EFI_INVALID_PARAMETER Size was NULL. + @retval EFI_BUFFER_TOO_SMALL Size was not large enough to store the line. + Size was updated to the minimum space required. +**/ +EFI_STATUS +EFIAPI +ShellFileHandleReadLine( + IN SHELL_FILE_HANDLE Handle, + IN OUT CHAR16 *Buffer, + IN OUT UINTN *Size, + IN BOOLEAN Truncate, + IN OUT BOOLEAN *Ascii + ); + +/** + Function to delete a file by name + + @param[in] FileName Pointer to file name to delete. + + @retval EFI_SUCCESS the file was deleted sucessfully + @retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not + deleted + @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value. + @retval EFI_NOT_FOUND The specified file could not be found on the + device or the file system could not be found + on the device. + @retval EFI_NO_MEDIA The device has no medium. + @retval EFI_MEDIA_CHANGED The device has a different medium in it or the + medium is no longer supported. + @retval EFI_DEVICE_ERROR The device reported an error. + @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. + @retval EFI_WRITE_PROTECTED The file or medium is write protected. + @retval EFI_ACCESS_DENIED The file was opened read only. + @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the + file. + @retval other The file failed to open +**/ +EFI_STATUS +EFIAPI +ShellDeleteFileByName( + IN CONST CHAR16 *FileName + ); + +/** + Function to print help file / man page content in the spec from the UEFI Shell protocol GetHelpText function. + + @param[in] CommandToGetHelpOn Pointer to a string containing the command name of help file to be printed. + @param[in] SectionToGetHelpOn Pointer to the section specifier(s). + @param[in] PrintCommandText If TRUE, prints the command followed by the help content, otherwise prints + the help content only. + @retval EFI_DEVICE_ERROR The help data format was incorrect. + @retval EFI_NOT_FOUND The help data could not be found. + @retval EFI_SUCCESS The operation was successful. +**/ +EFI_STATUS +EFIAPI +ShellPrintHelp ( + IN CONST CHAR16 *CommandToGetHelpOn, + IN CONST CHAR16 *SectionToGetHelpOn, + IN BOOLEAN PrintCommandText + ); + #endif // __SHELL_LIB__