Fix Winnt file system will fail to read() a root "\" after call open().
authorgikidy <gikidy@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 2 Jul 2009 08:52:32 +0000 (08:52 +0000)
committergikidy <gikidy@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 2 Jul 2009 08:52:32 +0000 (08:52 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8725 6f19259b-4bc3-4df7-8a09-765794883524

Nt32Pkg/WinNtSimpleFileSystemDxe/WinNtSimpleFileSystem.c

index a5559bfc03f5eb9bdaf733d266c5207172b09ee0..8ca9808c593f7231327f3a3e2a91c228dd60c85b 100644 (file)
@@ -543,6 +543,7 @@ Returns:
   WIN_NT_SIMPLE_FILE_SYSTEM_PRIVATE *Private;\r
   WIN_NT_EFI_FILE_PRIVATE           *PrivateFile;\r
   EFI_TPL                           OldTpl;\r
+  CHAR16                            *TempFileName;\r
 \r
   if (This == NULL || Root == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -589,10 +590,47 @@ Returns:
   PrivateFile->EfiFile.GetInfo      = WinNtSimpleFileSystemGetInfo;\r
   PrivateFile->EfiFile.SetInfo      = WinNtSimpleFileSystemSetInfo;\r
   PrivateFile->EfiFile.Flush        = WinNtSimpleFileSystemFlush;\r
-  PrivateFile->LHandle              = INVALID_HANDLE_VALUE;\r
-  PrivateFile->DirHandle            = INVALID_HANDLE_VALUE;\r
   PrivateFile->IsValidFindBuf       = FALSE;\r
 \r
+  //\r
+  // Set DirHandle\r
+  //\r
+  PrivateFile->DirHandle = PrivateFile->WinNtThunk->CreateFile (\r
+                                                      PrivateFile->FilePath,\r
+                                                      GENERIC_READ,\r
+                                                      FILE_SHARE_READ | FILE_SHARE_WRITE,\r
+                                                      NULL,\r
+                                                      OPEN_EXISTING,\r
+                                                      FILE_FLAG_BACKUP_SEMANTICS,\r
+                                                      NULL\r
+                                                      );\r
+\r
+  if (PrivateFile->DirHandle == INVALID_HANDLE_VALUE) {\r
+    Status = EFI_NOT_FOUND;\r
+    goto Done;\r
+  }\r
+\r
+  //\r
+  // Find the first file under it\r
+  //\r
+  Status = gBS->AllocatePool (\r
+                  EfiBootServicesData,\r
+                  StrSize (PrivateFile->FilePath) + StrSize (L"\\*"),\r
+                  &TempFileName\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+  StrCpy (TempFileName, PrivateFile->FilePath);\r
+  StrCat (TempFileName, L"\\*");\r
+\r
+  PrivateFile->LHandle = PrivateFile->WinNtThunk->FindFirstFile (TempFileName, &PrivateFile->FindBuf);\r
+\r
+  if (PrivateFile->LHandle == INVALID_HANDLE_VALUE) {\r
+    PrivateFile->IsValidFindBuf = FALSE;\r
+  } else {\r
+    PrivateFile->IsValidFindBuf = TRUE;\r
+  }\r
   *Root = &PrivateFile->EfiFile;\r
 \r
   Status = EFI_SUCCESS;\r
@@ -822,7 +860,6 @@ Returns:
 // TODO:    EFI_INVALID_PARAMETER - add return value to function comment\r
 // TODO:    EFI_INVALID_PARAMETER - add return value to function comment\r
 {\r
-  EFI_FILE                          *Root;\r
   WIN_NT_EFI_FILE_PRIVATE           *PrivateFile;\r
   WIN_NT_EFI_FILE_PRIVATE           *NewPrivateFile;\r
   WIN_NT_SIMPLE_FILE_SYSTEM_PRIVATE *PrivateRoot;\r
@@ -884,20 +921,6 @@ Returns:
   StrCpy (TempFileName, FileName);\r
   FileName = TempFileName;\r
 \r
-  //\r
-  // BUGBUG: assume an open of root\r
-  // if current location, return current data\r
-  //\r
-  if (StrCmp (FileName, L"\\") == 0 || (StrCmp (FileName, L".") == 0 && PrivateFile->IsRootDirectory)) {\r
-    //\r
-    // BUGBUG: assume an open root\r
-    //\r
-OpenRoot:\r
-    Status          = WinNtSimpleFileSystemOpenVolume (PrivateFile->SimpleFileSystem, &Root);\r
-    NewPrivateFile  = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (Root);\r
-    goto Done;\r
-  }\r
-\r
   if (FileName[StrLen (FileName) - 1] == L'\\') {\r
     FileName[StrLen (FileName) - 1]  = 0;\r
   }\r
@@ -1037,22 +1060,17 @@ OpenRoot:
     }\r
   }\r
 \r
-  if (StrCmp (NewPrivateFile->FileName, PrivateRoot->FilePath) == 0) {\r
-    NewPrivateFile->IsRootDirectory = TRUE;\r
-    FreePool (NewPrivateFile->FilePath);\r
-    FreePool (NewPrivateFile->FileName);\r
-    FreePool (NewPrivateFile);\r
-    goto OpenRoot;\r
-  }\r
-\r
   RealFileName = NewPrivateFile->FileName;\r
   while (EfiStrChr (RealFileName, L'\\') != NULL) {\r
     RealFileName = EfiStrChr (RealFileName, L'\\') + 1;\r
   }\r
 \r
-  TempChar            = *(RealFileName - 1);\r
-  *(RealFileName - 1) = 0;\r
-\r
+  TempChar = 0;\r
+  if (RealFileName != NewPrivateFile->FileName) {\r
+    TempChar            = *(RealFileName - 1);\r
+    *(RealFileName - 1) = 0;\r
+    }\r
+  \r
   FreePool (NewPrivateFile->FilePath);\r
   NewPrivateFile->FilePath = NULL;\r
   NewPrivateFile->FilePath = AllocatePool (StrSize (NewPrivateFile->FileName));\r
@@ -1062,8 +1080,9 @@ OpenRoot:
   }\r
 \r
   StrCpy (NewPrivateFile->FilePath, NewPrivateFile->FileName);\r
-\r
-  *(RealFileName - 1)             = TempChar;\r
+  if (TempChar != 0) {\r
+    *(RealFileName - 1)             = TempChar;\r
+  }\r
 \r
   NewPrivateFile->IsRootDirectory = FALSE;\r
 \r
@@ -1279,6 +1298,9 @@ Done:
     }\r
   } else {\r
     *NewHandle = &NewPrivateFile->EfiFile;\r
+    if (StrCmp (NewPrivateFile->FileName, PrivateRoot->FilePath) == 0) {\r
+     NewPrivateFile->IsRootDirectory = TRUE;\r
+    }   \r
   }\r
 \r
   return Status;\r