]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg/UefiFileHandleLib: Tolerate more Root handle FileNames
authorMarvin Haeuser <mhaeuser@outlook.de>
Sun, 20 Oct 2019 12:08:32 +0000 (20:08 +0800)
committerLiming Gao <liming.gao@intel.com>
Mon, 4 Nov 2019 00:52:57 +0000 (08:52 +0800)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2295

The current implementation of the FileHandleGetFileName() function
assumes that the Root directory always has the FileName '\0'.
However, the only requirement the UEFI specification defines is that
a prepended '\\' must be supported to access files and folders
relative to the Root directory.
This patch removes this assumption and supports constructing valid
paths for any value of FileName for the Root Directory.

In practice, this fixes compatibility issues with File System drivers
that report '\\' as the FileName of the Root directory, which
currently is both generating an invalid path ("\\\\") and resulting
in an EFI_NOT_FOUND result from the CurrentHandle->Open() call.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Marvin Haeuser <mhaeuser@outlook.de>
Reviewed-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Zhichao Gao <zhichao.gao@intel.com>
MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c

index 5dc893833a4667492ee33d0ae4643025f514ac24..28e28e5f67d5bc4d6cb81663b28c43470a26c2e0 100644 (file)
@@ -816,10 +816,25 @@ FileHandleGetFileName (
         Status = EFI_OUT_OF_RESOURCES;\r
         break;\r
       } else {\r
+        //\r
+        // Prepare to move to the parent directory.\r
+        // Also determine whether CurrentHandle refers to the Root directory.\r
+        //\r
+        Status = CurrentHandle->Open (CurrentHandle, &NextHigherHandle, L"..", EFI_FILE_MODE_READ, 0);\r
         //\r
         // We got info... do we have a name? if yes precede the current path with it...\r
         //\r
-        if (StrLen (FileInfo->FileName) == 0) {\r
+        if ((StrLen (FileInfo->FileName) == 0) || EFI_ERROR (Status)) {\r
+          //\r
+          // Both FileInfo->FileName being '\0' and EFI_ERROR() suggest that\r
+          // CurrentHandle refers to the Root directory.  As this loop ensures\r
+          // FullFileName is starting with '\\' at all times, signal success\r
+          // and exit the loop.\r
+          // While FileInfo->FileName could theoretically be a value other than\r
+          // '\0' or '\\', '\\' is guaranteed to be supported by the\r
+          // specification and hence its value can safely be ignored.\r
+          //\r
+          Status = EFI_SUCCESS;\r
           if (*FullFileName == NULL) {\r
             ASSERT((*FullFileName == NULL && Size == 0) || (*FullFileName != NULL));\r
             *FullFileName = StrnCatGrowLeft(FullFileName, &Size, L"\\", 0);\r
@@ -837,15 +852,11 @@ FileHandleGetFileName (
           FreePool(FileInfo);\r
         }\r
       }\r
+\r
+      FileHandleClose(CurrentHandle);\r
       //\r
       // Move to the parent directory\r
       //\r
-      Status = CurrentHandle->Open (CurrentHandle, &NextHigherHandle, L"..", EFI_FILE_MODE_READ, 0);\r
-      if (EFI_ERROR (Status)) {\r
-        break;\r
-      }\r
-\r
-      FileHandleClose(CurrentHandle);\r
       CurrentHandle = NextHigherHandle;\r
     }\r
   } else if (Status == EFI_NOT_FOUND) {\r