]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Include/Library/ShellLib.h
ShellPkg/HandleParsingLib: Add new API GetAllMappingGuids
[mirror_edk2.git] / ShellPkg / Include / Library / ShellLib.h
index 5f3c5588bba4b6122ed12e6263c98aaa9ad1749e..9b611d8016a8b54874f9657dcf1e612ce2596ef1 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Provides interface to shell functionality for shell commands and applications.\r
 \r
-  Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
 #include <Protocol/LoadedImage.h>\r
 #include <Protocol/EfiShellInterface.h>\r
 #include <Protocol/EfiShellEnvironment2.h>\r
-#include <Protocol/EfiShell.h>\r
-#include <Protocol/EfiShellParameters.h>\r
+#include <Protocol/Shell.h>\r
+#include <Protocol/ShellParameters.h>\r
+\r
+#define SHELL_FREE_NON_NULL(Pointer)  \\r
+  do {                                \\r
+    if ((Pointer) != NULL) {          \\r
+      FreePool((Pointer));            \\r
+      (Pointer) = NULL;               \\r
+    }                                 \\r
+  } while(FALSE)\r
 \r
 // (20 * (6+5+2))+1) unicode characters from EFI FAT spec (doubled for bytes)\r
 #define MAX_FILE_NAME_LEN 512\r
@@ -59,20 +67,20 @@ ShellGetFileInfo (
 \r
   @param[in]  FileInfo          The information to set.\r
 \r
-  @retval EFI_SUCCESS                  The information was set.\r
+  @retval EFI_SUCCESS           The information was set.\r
   @retval EFI_INVALID_PARAMETER A parameter was out of range or invalid.\r
   @retval EFI_UNSUPPORTED       The FileHandle does not support FileInfo.\r
-  @retval EFI_NO_MEDIA               The device has no medium.\r
-  @retval EFI_DEVICE_ERROR         The device reported an error.\r
-  @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
-  @retval EFI_WRITE_PROTECTED    The file or medium is write protected.\r
+  @retval EFI_NO_MEDIA          The device has no medium.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error.\r
+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
+  @retval EFI_WRITE_PROTECTED   The file or medium is write protected.\r
   @retval EFI_ACCESS_DENIED     The file was opened read only.\r
   @retval EFI_VOLUME_FULL       The volume is full.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 ShellSetFileInfo (\r
-  IN SHELL_FILE_HANDLE         FileHandle,\r
+  IN SHELL_FILE_HANDLE          FileHandle,\r
   IN EFI_FILE_INFO              *FileInfo\r
   );\r
 \r
@@ -89,31 +97,31 @@ ShellSetFileInfo (
   @param[in]    OpenMode         The mode to open the file with.\r
   @param[in]    Attributes       The file's file attributes.\r
 \r
-  @retval EFI_SUCCESS          The information was set.\r
-  @retval EFI_INVALID_PARAMETER        One of the parameters has an invalid value.\r
+  @retval EFI_SUCCESS         The information was set.\r
+  @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.\r
   @retval EFI_UNSUPPORTED       Could not open the file path.\r
-  @retval EFI_NOT_FOUND                The specified file could not be found on the\r
+  @retval EFI_NOT_FOUND         The specified file could not be found on the\r
                                 device or the file system could not be found on\r
                                 the device.\r
   @retval EFI_NO_MEDIA          The device has no medium.\r
   @retval EFI_MEDIA_CHANGED     The device has a different medium in it or the\r
                                 medium is no longer supported.\r
   @retval EFI_DEVICE_ERROR      The device reported an error.\r
-  @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
   @retval EFI_WRITE_PROTECTED   The file or medium is write protected.\r
   @retval EFI_ACCESS_DENIED     The file was opened read only.\r
-  @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the\r
+  @retval EFI_OUT_OF_RESOURCES  Not enough resources were available to open the\r
                                 file.\r
   @retval EFI_VOLUME_FULL       The volume is full.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 ShellOpenFileByDevicePath(\r
-  IN OUT EFI_DEVICE_PATH_PROTOCOL        **FilePath,\r
-  OUT EFI_HANDLE                       *DeviceHandle,\r
-  OUT SHELL_FILE_HANDLE                *FileHandle,\r
-  IN UINT64                            OpenMode,\r
-  IN UINT64                            Attributes\r
+  IN OUT EFI_DEVICE_PATH_PROTOCOL     **FilePath,\r
+  OUT EFI_HANDLE                      *DeviceHandle,\r
+  OUT SHELL_FILE_HANDLE               *FileHandle,\r
+  IN UINT64                           OpenMode,\r
+  IN UINT64                           Attributes\r
   );\r
 \r
 /**\r
@@ -128,30 +136,30 @@ ShellOpenFileByDevicePath(
   @param[in] OpenMode           The mode to open the file with.\r
   @param[in] Attributes         The file's file attributes.\r
 \r
-  @retval EFI_SUCCESS          The information was set.\r
-  @retval EFI_INVALID_PARAMETER        One of the parameters has an invalid value.\r
+  @retval EFI_SUCCESS         The information was set.\r
+  @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.\r
   @retval EFI_UNSUPPORTED       Could not open the file path.\r
-  @retval EFI_NOT_FOUND                The specified file could not be found on the\r
+  @retval EFI_NOT_FOUND         The specified file could not be found on the\r
                                 device or the file system could not be found\r
                                 on the device.\r
   @retval EFI_NO_MEDIA          The device has no medium.\r
   @retval EFI_MEDIA_CHANGED     The device has a different medium in it or the\r
                                 medium is no longer supported.\r
   @retval EFI_DEVICE_ERROR      The device reported an error.\r
-  @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
   @retval EFI_WRITE_PROTECTED   The file or medium is write protected.\r
   @retval EFI_ACCESS_DENIED     The file was opened read only.\r
-  @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the\r
+  @retval EFI_OUT_OF_RESOURCES  Not enough resources were available to open the\r
                                 file.\r
   @retval EFI_VOLUME_FULL       The volume is full.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 ShellOpenFileByName(\r
-  IN CONST CHAR16                          *FilePath,\r
+  IN CONST CHAR16               *FilePath,\r
   OUT SHELL_FILE_HANDLE         *FileHandle,\r
   IN UINT64                     OpenMode,\r
-  IN UINT64                            Attributes\r
+  IN UINT64                     Attributes\r
   );\r
 \r
 /**\r
@@ -164,20 +172,20 @@ ShellOpenFileByName(
   @param[in]  DirectoryName     The pointer to Directory name.\r
   @param[out] FileHandle        The pointer to the file handle.\r
 \r
-  @retval EFI_SUCCESS          The information was set.\r
-  @retval EFI_INVALID_PARAMETER        One of the parameters has an invalid value.\r
+  @retval EFI_SUCCESS         The information was set.\r
+  @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.\r
   @retval EFI_UNSUPPORTED       Could not open the file path.\r
-  @retval EFI_NOT_FOUND                The specified file could not be found on the\r
+  @retval EFI_NOT_FOUND         The specified file could not be found on the\r
                                 device, or the file system could not be found\r
                                 on the device.\r
   @retval EFI_NO_MEDIA          The device has no medium.\r
   @retval EFI_MEDIA_CHANGED     The device has a different medium in it or the\r
                                 medium is no longer supported.\r
   @retval EFI_DEVICE_ERROR      The device reported an error.\r
-  @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
   @retval EFI_WRITE_PROTECTED   The file or medium is write protected.\r
   @retval EFI_ACCESS_DENIED     The file was opened read only.\r
-  @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the\r
+  @retval EFI_OUT_OF_RESOURCES  Not enough resources were available to open the\r
                                 file.\r
   @retval EFI_VOLUME_FULL       The volume is full.\r
 **/\r
@@ -210,9 +218,9 @@ ShellCreateDirectory(
   @param[out] Buffer             The buffer to put read data into.\r
 \r
   @retval EFI_SUCCESS           Data was read.\r
-  @retval EFI_NO_MEDIA         The device has no media.\r
+  @retval EFI_NO_MEDIA          The device has no media.\r
   @retval EFI_DEVICE_ERROR      The device reported an error.\r
-  @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
   @retval EFI_BUFFER_TO_SMALL   Buffer is too small. ReadSize contains required\r
                                 size.\r
 \r
@@ -244,7 +252,7 @@ ShellReadFile(
 \r
   @retval EFI_SUCCESS           Data was written.\r
   @retval EFI_UNSUPPORTED       Writes to an open directory are not supported.\r
-  @retval EFI_NO_MEDIA         The device has no media.\r
+  @retval EFI_NO_MEDIA          The device has no media.\r
   @retval EFI_DEVICE_ERROR      The device reported an error.\r
   @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
   @retval EFI_WRITE_PROTECTED   The device is write-protected.\r
@@ -289,7 +297,7 @@ ShellCloseFile (
   @retval EFI_SUCCESS               The file was closed sucessfully.\r
   @retval EFI_WARN_DELETE_FAILURE   The handle was closed, but the file was not\r
                                     deleted.\r
-  @retval INVALID_PARAMETER                One of the parameters has an invalid value.\r
+  @retval INVALID_PARAMETER         One of the parameters has an invalid value.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -320,8 +328,8 @@ ShellDeleteFile (
 EFI_STATUS\r
 EFIAPI\r
 ShellSetFilePosition (\r
-  IN SHELL_FILE_HANDLE         FileHandle,\r
-  IN UINT64            Position\r
+  IN SHELL_FILE_HANDLE  FileHandle,\r
+  IN UINT64             Position\r
   );\r
 \r
 /**\r
@@ -366,16 +374,18 @@ ShellFlushFile (
   IN SHELL_FILE_HANDLE          FileHandle\r
   );\r
 \r
-/**\r
-  Retrieves the first file from a directory\r
+/** Retrieve first entry from a directory.\r
 \r
-  This function takes an open directory handle and gets the first file\r
-  in the directory's info. Caller can use ShellFindNextFile() to get\r
-  subsequent files.\r
+  This function takes an open directory handle and gets information from the\r
+  first entry in the directory.  A buffer is allocated to contain\r
+  the information and a pointer to the buffer is returned in *Buffer.  The\r
+  caller can use ShellFindNextFile() to get subsequent directory entries.\r
 \r
-  Caller must use FreePool on *Buffer opon completion of all file searching.\r
+  The buffer will be freed by ShellFindNextFile() when the last directory\r
+  entry is read.  Otherwise, the caller must free the buffer, using FreePool,\r
+  when finished with it.\r
 \r
-  @param[in] DirHandle          The file handle of the directory to search.\r
+  @param[in]  DirHandle         The file handle of the directory to search.\r
   @param[out] Buffer            The pointer to the buffer for the file's information.\r
 \r
   @retval EFI_SUCCESS           Found the first file.\r
@@ -383,41 +393,44 @@ ShellFlushFile (
   @retval EFI_NO_MEDIA          The device has no media.\r
   @retval EFI_DEVICE_ERROR      The device reported an error.\r
   @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
+  @return Others                Status of ShellGetFileInfo, ShellSetFilePosition,\r
+                                or ShellReadFile.\r
+\r
   @sa ShellReadFile\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 ShellFindFirstFile (\r
-  IN SHELL_FILE_HANDLE          DirHandle,\r
-  OUT EFI_FILE_INFO             **Buffer\r
+  IN      SHELL_FILE_HANDLE       DirHandle,\r
+     OUT  EFI_FILE_INFO         **Buffer\r
   );\r
 \r
-/**\r
-  Retrieves the next file in a directory.\r
+/** Retrieve next entries from a directory.\r
 \r
-  To use this function, caller must call the ShellFindFirstFile() to get the\r
-  first file, and then use this function get other files. This function can be\r
-  called for several times to get each file's information in the directory. If\r
-  the call of ShellFindNextFile() got the last file in the directory, the next\r
-  call of this function has no file to get. *NoFile will be set to TRUE, and the\r
-  data in Buffer is meaningless.\r
+  To use this function, the caller must first call the ShellFindFirstFile()\r
+  function to get the first directory entry.  Subsequent directory entries are\r
+  retrieved by using the ShellFindNextFile() function.  This function can\r
+  be called several times to get each entry from the directory.  If the call of\r
+  ShellFindNextFile() retrieved the last directory entry, the next call of\r
+  this function will set *NoFile to TRUE and free the buffer.\r
 \r
-  @param[in] DirHandle           The file handle of the directory.\r
-  @param[in, out] Buffer         The pointer to buffer for file's information.\r
-  @param[in, out] NoFile         The pointer to boolean when last file is found.\r
+  @param[in]  DirHandle         The file handle of the directory.\r
+  @param[in, out] Buffer        The pointer to buffer for file's information.\r
+  @param[in, out] NoFile        The pointer to boolean when last file is found.\r
 \r
   @retval EFI_SUCCESS           Found the next file.\r
   @retval EFI_NO_MEDIA          The device has no media.\r
   @retval EFI_DEVICE_ERROR      The device reported an error.\r
   @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
+\r
   @sa ShellReadFile\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 ShellFindNextFile(\r
-  IN SHELL_FILE_HANDLE           DirHandle,\r
-  IN OUT EFI_FILE_INFO           *Buffer,\r
-  IN OUT BOOLEAN                 *NoFile\r
+  IN      SHELL_FILE_HANDLE       DirHandle,\r
+  IN OUT  EFI_FILE_INFO          *Buffer,\r
+  IN OUT  BOOLEAN                *NoFile\r
   );\r
 \r
 /**\r
@@ -545,6 +558,8 @@ ShellExecute (
   name. If the DeviceName is not NULL, it returns the current directory name\r
   on specified drive.\r
 \r
+  Note that the current directory string should exclude the tailing backslash character.\r
+\r
   @param[in] DeviceName         The name of the file system to get directory on.\r
 \r
   @retval NULL                  The directory does not exist.\r
@@ -663,6 +678,7 @@ typedef enum {
   TypeStart,        ///< A flag that has variable value appended to the end (IE "-ad", "-afd", "-adf", etc...).\r
   TypeDoubleValue,  ///< A flag that has 2 space seperated value data following it (IE "-a 1 2").\r
   TypeMaxValue,     ///< A flag followed by all the command line data before the next flag.\r
+  TypeTimeValue,    ///< A flag that has a time value following it (IE "-a -5:00").\r
   TypeMax,\r
 } SHELL_PARAM_TYPE;\r
 \r
@@ -988,7 +1004,7 @@ ShellIsFileInPath(
   Function to determine whether a string is decimal or hex representation of a number\r
   and return the number converted from the string.\r
 \r
-  Note: this function cannot be used when (UINTN)(-1), (0xFFFFFFFF) may be a valid \r
+  Note: this function cannot be used when (UINTN)(-1), (0xFFFFFFFF) may be a valid\r
   result.  Use ShellConvertStringToUint64 instead.\r
 \r
   @param[in] String   String representation of a number.\r
@@ -1002,6 +1018,23 @@ ShellStrToUintn(
   IN CONST CHAR16 *String\r
   );\r
 \r
+/**\r
+  Function return the number converted from a hex representation of a number.\r
+\r
+  Note: this function cannot be used when (UINTN)(-1), (0xFFFFFFFF) may be a valid\r
+  result.  Use ShellConvertStringToUint64 instead.\r
+\r
+  @param[in] String   String representation of a number.\r
+\r
+  @return             The unsigned integer result of the conversion.\r
+  @retval (UINTN)(-1) An error occured.\r
+**/\r
+UINTN\r
+EFIAPI\r
+ShellHexStrToUintn(\r
+  IN CONST CHAR16 *String\r
+  );\r
+\r
 /**\r
   Safely append with automatic string resizing given length of Destination and\r
   desired length of copy from Source.\r
@@ -1153,7 +1186,7 @@ typedef enum {
   Prompt the user and return the resultant answer to the requestor.\r
 \r
   This function will display the requested question on the shell prompt and then\r
-  wait for an apropriate answer to be input from the console.\r
+  wait for an appropriate answer to be input from the console.\r
 \r
   If the SHELL_PROMPT_REQUEST_TYPE is SHELL_PROMPT_REQUEST_TYPE_YESNO, ShellPromptResponseTypeQuitContinue\r
   or SHELL_PROMPT_REQUEST_TYPE_YESNOCANCEL then *Response is of type SHELL_PROMPT_RESPONSE.\r
@@ -1235,9 +1268,9 @@ ShellIsHexOrDecimalNumber (
   @param[in] String       The string to evaluate.\r
   @param[out] Value       Upon a successful return the value of the conversion.\r
   @param[in] ForceHex     TRUE - always assume hex.\r
-  @param[in] StopAtSpace  TRUE to halt upon finding a space, FALSE to \r
+  @param[in] StopAtSpace  TRUE to halt upon finding a space, FALSE to\r
                           process the entire String.\r
-  \r
+\r
   @retval EFI_SUCCESS             The conversion was successful.\r
   @retval EFI_INVALID_PARAMETER   String contained an invalid character.\r
   @retval EFI_NOT_FOUND           String was a number, but Value was NULL.\r
@@ -1308,6 +1341,7 @@ ShellFileHandleReturnLine(
 \r
   @retval EFI_SUCCESS           The operation was successful.  The line is stored in\r
                                 Buffer.\r
+  @retval EFI_END_OF_FILE       There are no more lines in the file.\r
   @retval EFI_INVALID_PARAMETER Handle was NULL.\r
   @retval EFI_INVALID_PARAMETER Size was NULL.\r
   @retval EFI_BUFFER_TOO_SMALL  Size was not large enough to store the line.\r
@@ -1323,4 +1357,52 @@ ShellFileHandleReadLine(
   IN OUT BOOLEAN                *Ascii\r
   );\r
 \r
+/**\r
+  Function to delete a file by name\r
+  \r
+  @param[in]       FileName       Pointer to file name to delete.\r
+  \r
+  @retval EFI_SUCCESS             the file was deleted sucessfully\r
+  @retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not\r
+                                  deleted\r
+  @retval EFI_INVALID_PARAMETER   One of the parameters has an invalid value.\r
+  @retval EFI_NOT_FOUND           The specified file could not be found on the\r
+                                  device or the file system could not be found\r
+                                  on the device.\r
+  @retval EFI_NO_MEDIA            The device has no medium.\r
+  @retval EFI_MEDIA_CHANGED       The device has a different medium in it or the\r
+                                  medium is no longer supported.\r
+  @retval EFI_DEVICE_ERROR        The device reported an error.\r
+  @retval EFI_VOLUME_CORRUPTED    The file system structures are corrupted.\r
+  @retval EFI_WRITE_PROTECTED     The file or medium is write protected.\r
+  @retval EFI_ACCESS_DENIED       The file was opened read only.\r
+  @retval EFI_OUT_OF_RESOURCES    Not enough resources were available to open the\r
+                                  file.\r
+  @retval other                   The file failed to open\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ShellDeleteFileByName(\r
+  IN CONST CHAR16               *FileName\r
+  );\r
+\r
+/**\r
+  Function to print help file / man page content in the spec from the UEFI Shell protocol GetHelpText function.\r
+\r
+  @param[in] CommandToGetHelpOn  Pointer to a string containing the command name of help file to be printed.\r
+  @param[in] SectionToGetHelpOn  Pointer to the section specifier(s).\r
+  @param[in] PrintCommandText    If TRUE, prints the command followed by the help content, otherwise prints \r
+                                 the help content only.\r
+  @retval EFI_DEVICE_ERROR       The help data format was incorrect.\r
+  @retval EFI_NOT_FOUND          The help data could not be found.\r
+  @retval EFI_SUCCESS            The operation was successful.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ShellPrintHelp (\r
+  IN CONST CHAR16     *CommandToGetHelpOn,\r
+  IN CONST CHAR16     *SectionToGetHelpOn,\r
+  IN BOOLEAN          PrintCommandText\r
+  );\r
+\r
 #endif // __SHELL_LIB__\r