]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellLib/UefiShellLib.c
ShellPkg/UefiShellLib: rebase ShellOpenFileByDevicePath() to UefiLib API
[mirror_edk2.git] / ShellPkg / Library / UefiShellLib / UefiShellLib.c
index e53985e2d71406a45970fd618927f36e280dc0a9..f04adbb63ffe650a9a0b77b06d5e324a57dbcc4b 100644 (file)
@@ -472,7 +472,6 @@ ShellSetFileInfo (
 \r
   @param  FilePath        on input the device path to the file.  On output\r
                           the remaining device path.\r
-  @param  DeviceHandle    pointer to the system device handle.\r
   @param  FileHandle      pointer to the file handle.\r
   @param  OpenMode        the mode to open the file with.\r
   @param  Attributes      the file's file attributes.\r
@@ -498,7 +497,6 @@ EFI_STATUS
 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
@@ -506,13 +504,9 @@ ShellOpenFileByDevicePath(
 {\r
   CHAR16                          *FileName;\r
   EFI_STATUS                      Status;\r
-  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *EfiSimpleFileSystemProtocol;\r
-  EFI_FILE_PROTOCOL               *Handle1;\r
-  EFI_FILE_PROTOCOL               *Handle2;\r
-  CHAR16                          *FnafPathName;\r
-  UINTN                           PathLen;\r
+  EFI_FILE_PROTOCOL               *File;\r
 \r
-  if (FilePath == NULL || FileHandle == NULL || DeviceHandle == NULL) {\r
+  if (FilePath == NULL || FileHandle == NULL) {\r
     return (EFI_INVALID_PARAMETER);\r
   }\r
 \r
@@ -536,117 +530,15 @@ ShellOpenFileByDevicePath(
   //\r
   // use old shell method.\r
   //\r
-  Status = gBS->LocateDevicePath (&gEfiSimpleFileSystemProtocolGuid,\r
-                                  FilePath,\r
-                                  DeviceHandle);\r
+  Status = EfiOpenFileByDevicePath (FilePath, &File, OpenMode, Attributes);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
-  Status = gBS->OpenProtocol(*DeviceHandle,\r
-                             &gEfiSimpleFileSystemProtocolGuid,\r
-                             (VOID**)&EfiSimpleFileSystemProtocol,\r
-                             gImageHandle,\r
-                             NULL,\r
-                             EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-  Status = EfiSimpleFileSystemProtocol->OpenVolume(EfiSimpleFileSystemProtocol, &Handle1);\r
-  if (EFI_ERROR (Status)) {\r
-    FileHandle = NULL;\r
-    return Status;\r
-  }\r
-\r
-  //\r
-  // go down directories one node at a time.\r
-  //\r
-  while (!IsDevicePathEnd (*FilePath)) {\r
-    //\r
-    // For file system access each node should be a file path component\r
-    //\r
-    if (DevicePathType    (*FilePath) != MEDIA_DEVICE_PATH ||\r
-        DevicePathSubType (*FilePath) != MEDIA_FILEPATH_DP\r
-       ) {\r
-      FileHandle = NULL;\r
-      return (EFI_INVALID_PARAMETER);\r
-    }\r
-    //\r
-    // Open this file path node\r
-    //\r
-    Handle2  = Handle1;\r
-    Handle1 = NULL;\r
-\r
-    //\r
-    // File Name Alignment Fix (FNAF)\r
-    // Handle2->Open may be incapable of handling a unaligned CHAR16 data.\r
-    // The structure pointed to by FilePath may be not CHAR16 aligned.\r
-    // This code copies the potentially unaligned PathName data from the\r
-    // FilePath structure to the aligned FnafPathName for use in the\r
-    // calls to Handl2->Open.\r
-    //\r
-\r
-    //\r
-    // Determine length of PathName, in bytes.\r
-    //\r
-    PathLen = DevicePathNodeLength (*FilePath) - SIZE_OF_FILEPATH_DEVICE_PATH;\r
-\r
-    //\r
-    // Allocate memory for the aligned copy of the string Extra allocation is to allow for forced alignment\r
-    // Copy bytes from possibly unaligned location to aligned location\r
-    //\r
-    FnafPathName = AllocateCopyPool(PathLen, (UINT8 *)((FILEPATH_DEVICE_PATH*)*FilePath)->PathName);\r
-    if (FnafPathName == NULL) {\r
-      return EFI_OUT_OF_RESOURCES;\r
-    }\r
-\r
-    //\r
-    // Try to test opening an existing file\r
-    //\r
-    Status = Handle2->Open (\r
-                          Handle2,\r
-                          &Handle1,\r
-                          FnafPathName,\r
-                          OpenMode &~EFI_FILE_MODE_CREATE,\r
-                          0\r
-                         );\r
-\r
-    //\r
-    // see if the error was that it needs to be created\r
-    //\r
-    if ((EFI_ERROR (Status)) && (OpenMode != (OpenMode &~EFI_FILE_MODE_CREATE))) {\r
-      Status = Handle2->Open (\r
-                            Handle2,\r
-                            &Handle1,\r
-                            FnafPathName,\r
-                            OpenMode,\r
-                            Attributes\r
-                           );\r
-    }\r
-\r
-    //\r
-    // Free the alignment buffer\r
-    //\r
-    FreePool(FnafPathName);\r
-\r
-    //\r
-    // Close the last node\r
-    //\r
-    Handle2->Close (Handle2);\r
-\r
-    if (EFI_ERROR(Status)) {\r
-      return (Status);\r
-    }\r
-\r
-    //\r
-    // Get the next node\r
-    //\r
-    *FilePath = NextDevicePathNode (*FilePath);\r
-  }\r
 \r
   //\r
   // This is a weak spot since if the undefined SHELL_FILE_HANDLE format changes this must change also!\r
   //\r
-  *FileHandle = (VOID*)Handle1;\r
+  *FileHandle = (VOID*)File;\r
   return (EFI_SUCCESS);\r
 }\r
 \r
@@ -690,7 +582,6 @@ ShellOpenFileByName(
   IN UINT64                     Attributes\r
   )\r
 {\r
-  EFI_HANDLE                    DeviceHandle;\r
   EFI_DEVICE_PATH_PROTOCOL      *FilePath;\r
   EFI_STATUS                    Status;\r
   EFI_FILE_INFO                 *FileInfo;\r
@@ -774,7 +665,6 @@ ShellOpenFileByName(
   FilePath = mEfiShellEnvironment2->NameToPath ((CHAR16*)FileName);\r
   if (FilePath != NULL) {\r
     return (ShellOpenFileByDevicePath(&FilePath,\r
-                                      &DeviceHandle,\r
                                       FileHandle,\r
                                       OpenMode,\r
                                       Attributes));\r
@@ -2158,22 +2048,22 @@ InternalCommandLineParse (
       }\r
       CurrentItemPackage->Value = NewValue;\r
       if (ValueSize == 0) {\r
-        StrCpyS( CurrentItemPackage->Value, \r
-                  CurrentValueSize/sizeof(CHAR16), \r
+        StrCpyS( CurrentItemPackage->Value,\r
+                  CurrentValueSize/sizeof(CHAR16),\r
                   Argv[LoopCounter]\r
                   );\r
       } else {\r
-        StrCatS( CurrentItemPackage->Value, \r
-                  CurrentValueSize/sizeof(CHAR16), \r
+        StrCatS( CurrentItemPackage->Value,\r
+                  CurrentValueSize/sizeof(CHAR16),\r
                   L" "\r
                   );\r
-        StrCatS( CurrentItemPackage->Value, \r
-                  CurrentValueSize/sizeof(CHAR16), \r
+        StrCatS( CurrentItemPackage->Value,\r
+                  CurrentValueSize/sizeof(CHAR16),\r
                   Argv[LoopCounter]\r
                   );\r
       }\r
       ValueSize += StrSize(Argv[LoopCounter]) + sizeof(CHAR16);\r
-      \r
+\r
       GetItemValue--;\r
       if (GetItemValue == 0) {\r
         InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);\r
@@ -2732,10 +2622,10 @@ InternalPrintTo (
     return (gEfiShellProtocol->WriteFile(gEfiShellParametersProtocol->StdOut, &Size, (VOID*)String));\r
   }\r
   if (mEfiShellInterface          != NULL) {\r
-    if (mEfiShellInterface->RedirArgc == 0) { \r
+    if (mEfiShellInterface->RedirArgc == 0) {\r
     //\r
     // Divide in half for old shell.  Must be string length not size.\r
-      // \r
+      //\r
       Size /=2;  // Divide in half only when no redirection.\r
     }\r
     return (mEfiShellInterface->StdOut->Write(mEfiShellInterface->StdOut,          &Size, (VOID*)String));\r
@@ -3173,7 +3063,7 @@ ShellHexStrToUintn(
   if (!EFI_ERROR(ShellConvertStringToUint64(String, &RetVal, TRUE, TRUE))) {\r
     return ((UINTN)RetVal);\r
   }\r
-  \r
+\r
   return ((UINTN)(-1));\r
 }\r
 \r
@@ -3312,7 +3202,7 @@ StrnCatGrow (
   if (*Destination == NULL) {\r
     return (NULL);\r
   }\r
-  \r
+\r
   StrnCatS(*Destination, NewSize/sizeof(CHAR16), Source, Count);\r
   return *Destination;\r
 }\r
@@ -3944,7 +3834,7 @@ InternalShellStrDecimalToUint64 (
   Result = 0;\r
 \r
   //\r
-  // Stop upon space if requested \r
+  // Stop upon space if requested\r
   // (if the whole value was 0)\r
   //\r
   if (StopAtSpace && *String == L' ') {\r
@@ -4255,7 +4145,7 @@ ShellFileHandleReadLine(
 \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
+  @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
@@ -4269,33 +4159,33 @@ ShellPrintHelp (
   IN BOOLEAN          PrintCommandText\r
   )\r
 {\r
-       EFI_STATUS          Status;\r
-       CHAR16              *OutText;\r
-         \r
-       OutText = NULL;\r
-       \r
+  EFI_STATUS          Status;\r
+  CHAR16              *OutText;\r
+\r
+  OutText = NULL;\r
+\r
   //\r
   // Get the string to print based\r
   //\r
-       Status = gEfiShellProtocol->GetHelpText (CommandToGetHelpOn, SectionToGetHelpOn, &OutText);\r
-  \r
+  Status = gEfiShellProtocol->GetHelpText (CommandToGetHelpOn, SectionToGetHelpOn, &OutText);\r
+\r
   //\r
   // make sure we got a valid string\r
   //\r
   if (EFI_ERROR(Status)){\r
     return Status;\r
-       } \r
+  }\r
   if (OutText == NULL || StrLen(OutText) == 0) {\r
-    return EFI_NOT_FOUND;  \r
-       }\r
-  \r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
   //\r
   // Chop off trailing stuff we dont need\r
   //\r
   while (OutText[StrLen(OutText)-1] == L'\r' || OutText[StrLen(OutText)-1] == L'\n' || OutText[StrLen(OutText)-1] == L' ') {\r
     OutText[StrLen(OutText)-1] = CHAR_NULL;\r
   }\r
-  \r
+\r
   //\r
   // Print this out to the console\r
   //\r
@@ -4304,17 +4194,17 @@ ShellPrintHelp (
   } else {\r
     ShellPrintEx(-1, -1, L"%N%s\r\n", OutText);\r
   }\r
-  \r
+\r
   SHELL_FREE_NON_NULL(OutText);\r
 \r
-       return EFI_SUCCESS;\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
   Function to delete a file by name\r
-  \r
+\r
   @param[in]       FileName       Pointer to file name to delete.\r
-  \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
@@ -4341,26 +4231,26 @@ ShellDeleteFileByName(
 {\r
   EFI_STATUS                Status;\r
   SHELL_FILE_HANDLE         FileHandle;\r
-  \r
+\r
   Status = ShellFileExists(FileName);\r
-  \r
+\r
   if (Status == EFI_SUCCESS){\r
     Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0x0);\r
     if (Status == EFI_SUCCESS){\r
       Status = ShellDeleteFile(&FileHandle);\r
     }\r
-  } \r
+  }\r
 \r
   return(Status);\r
-  \r
+\r
 }\r
 \r
 /**\r
   Cleans off all the quotes in the string.\r
 \r
   @param[in]     OriginalString   pointer to the string to be cleaned.\r
-  @param[out]   CleanString      The new string with all quotes removed. \r
-                                                  Memory allocated in the function and free \r
+  @param[out]   CleanString      The new string with all quotes removed.\r
+                                                  Memory allocated in the function and free\r
                                                   by caller.\r
 \r
   @retval EFI_SUCCESS   The operation was successful.\r
@@ -4372,7 +4262,7 @@ InternalShellStripQuotes (
   )\r
 {\r
   CHAR16            *Walker;\r
-  \r
+\r
   if (OriginalString == NULL || CleanString == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r