]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Nt32Pkg/WinNtSimpleFileSystemDxe/WinNtSimpleFileSystem.c
Correct the code to use SIZE_OF_EFI_FILE_INFO instead of sizeof (EFI_FILE_INFO) to...
[mirror_edk2.git] / Nt32Pkg / WinNtSimpleFileSystemDxe / WinNtSimpleFileSystem.c
index 7da3eef9ce580bc9a501c049ff14e2cc80d2a2e9..63ab71fb2baa09acf5f4ce2582f03a30cefe95b1 100644 (file)
@@ -1,7 +1,7 @@
 /**@file\r
 \r
-Copyright (c) 2006 - 2008, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2006 - 2011, 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
 http://opensource.org/licenses/bsd-license.php\r
@@ -504,7 +504,7 @@ EFI_STATUS
 EFIAPI\r
 WinNtSimpleFileSystemOpenVolume (\r
   IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL  *This,\r
-  OUT EFI_FILE                        **Root\r
+  OUT EFI_FILE_PROTOCOL               **Root\r
   )\r
 /*++\r
 \r
@@ -543,6 +543,8 @@ Returns:
   WIN_NT_SIMPLE_FILE_SYSTEM_PRIVATE *Private;\r
   WIN_NT_EFI_FILE_PRIVATE           *PrivateFile;\r
   EFI_TPL                           OldTpl;\r
+  CHAR16                            *TempFileName;\r
+  UINTN                             Size;\r
 \r
   if (This == NULL || Root == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -589,10 +591,49 @@ 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
+  Size  = StrSize (PrivateFile->FilePath);\r
+  Size += StrSize (L"\\*");\r
+  Status = gBS->AllocatePool (\r
+                  EfiBootServicesData,\r
+                  Size,\r
+                  (VOID **)&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
@@ -770,11 +811,11 @@ IsFileNameValid (
 EFI_STATUS\r
 EFIAPI\r
 WinNtSimpleFileSystemOpen (\r
-  IN  EFI_FILE  *This,\r
-  OUT EFI_FILE  **NewHandle,\r
-  IN  CHAR16    *FileName,\r
-  IN  UINT64    OpenMode,\r
-  IN  UINT64    Attributes\r
+  IN  EFI_FILE_PROTOCOL  *This,\r
+  OUT EFI_FILE_PROTOCOL  **NewHandle,\r
+  IN  CHAR16             *FileName,\r
+  IN  UINT64             OpenMode,\r
+  IN  UINT64             Attributes\r
   )\r
 /*++\r
 \r
@@ -784,7 +825,7 @@ Routine Description:
 \r
 Arguments:\r
 \r
-  This        - A pointer to the seource file location.\r
+  This        - A pointer to the source file location.\r
 \r
   NewHandle   - Pointer to storage for the new file handle.\r
 \r
@@ -822,7 +863,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
@@ -837,6 +877,7 @@ Returns:
   BOOLEAN                           LoopFinish;\r
   UINTN                             InfoSize;\r
   EFI_FILE_INFO                     *Info;\r
+  UINTN                             Size;\r
 \r
   //\r
   // Check for obvious invalid parameters.\r
@@ -883,20 +924,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
@@ -951,7 +978,10 @@ OpenRoot:
     StrCpy (NewPrivateFile->FilePath, PrivateFile->FilePath);\r
   }\r
 \r
-  NewPrivateFile->FileName = AllocatePool (StrSize (NewPrivateFile->FilePath) + StrSize (L"\\") + StrSize (FileName));\r
+  Size = StrSize (NewPrivateFile->FilePath);\r
+  Size += StrSize (L"\\");\r
+  Size += StrSize (FileName);\r
+  NewPrivateFile->FileName = AllocatePool (Size);\r
   if (NewPrivateFile->FileName == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
     goto Done;\r
@@ -1033,22 +1063,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
@@ -1058,8 +1083,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
@@ -1107,7 +1133,9 @@ OpenRoot:
   //\r
   if (NewPrivateFile->IsDirectoryPath) {\r
 \r
-    TempFileName = AllocatePool (StrSize (NewPrivateFile->FileName) + StrSize (L"\\*"));\r
+    Size  = StrSize (NewPrivateFile->FileName);\r
+    Size += StrSize (L"\\*");\r
+    TempFileName = AllocatePool (Size);\r
     if (TempFileName == NULL) {\r
       Status = EFI_OUT_OF_RESOURCES;\r
       goto Done;\r
@@ -1273,6 +1301,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
@@ -1281,7 +1312,7 @@ Done:
 EFI_STATUS\r
 EFIAPI\r
 WinNtSimpleFileSystemClose (\r
-  IN EFI_FILE  *This\r
+  IN EFI_FILE_PROTOCOL  *This\r
   )\r
 /*++\r
 \r
@@ -1340,7 +1371,7 @@ Returns:
 EFI_STATUS\r
 EFIAPI\r
 WinNtSimpleFileSystemDelete (\r
-  IN EFI_FILE  *This\r
+  IN EFI_FILE_PROTOCOL  *This\r
   )\r
 /*++\r
 \r
@@ -1448,9 +1479,9 @@ Returns:
 EFI_STATUS\r
 EFIAPI\r
 WinNtSimpleFileSystemRead (\r
-  IN     EFI_FILE  *This,\r
-  IN OUT UINTN     *BufferSize,\r
-  OUT    VOID      *Buffer\r
+  IN     EFI_FILE_PROTOCOL  *This,\r
+  IN OUT UINTN              *BufferSize,\r
+  OUT    VOID               *Buffer\r
   )\r
 /*++\r
 \r
@@ -1560,12 +1591,12 @@ Returns:
     }\r
 \r
     Status = PrivateFile->WinNtThunk->ReadFile (\r
-                                      PrivateFile->LHandle,\r
-                                      Buffer,\r
-                                      *BufferSize,\r
-                                      BufferSize,\r
-                                      NULL\r
-                                      ) ? EFI_SUCCESS : EFI_DEVICE_ERROR;\r
+                                        PrivateFile->LHandle,\r
+                                        Buffer,\r
+                                        *BufferSize,\r
+                                        (LPDWORD)BufferSize,\r
+                                        NULL\r
+                                        ) ? EFI_SUCCESS : EFI_DEVICE_ERROR;\r
     goto Done;\r
   }\r
 \r
@@ -1663,9 +1694,9 @@ Done:
 EFI_STATUS\r
 EFIAPI\r
 WinNtSimpleFileSystemWrite (\r
-  IN     EFI_FILE  *This,\r
-  IN OUT UINTN     *BufferSize,\r
-  IN     VOID      *Buffer\r
+  IN     EFI_FILE_PROTOCOL  *This,\r
+  IN OUT UINTN              *BufferSize,\r
+  IN     VOID               *Buffer\r
   )\r
 /*++\r
 \r
@@ -1731,12 +1762,12 @@ Returns:
   }\r
 \r
   Status = PrivateFile->WinNtThunk->WriteFile (\r
-                                    PrivateFile->LHandle,\r
-                                    Buffer,\r
-                                    *BufferSize,\r
-                                    BufferSize,\r
-                                    NULL\r
-                                    ) ? EFI_SUCCESS : EFI_DEVICE_ERROR;\r
+                                      PrivateFile->LHandle,\r
+                                      Buffer,\r
+                                      *BufferSize,\r
+                                      (LPDWORD)BufferSize,\r
+                                      NULL\r
+                                      ) ? EFI_SUCCESS : EFI_DEVICE_ERROR;\r
 \r
 Done:\r
   gBS->RestoreTPL (OldTpl);\r
@@ -1750,8 +1781,8 @@ Done:
 EFI_STATUS\r
 EFIAPI\r
 WinNtSimpleFileSystemSetPosition (\r
-  IN EFI_FILE  *This,\r
-  IN UINT64    Position\r
+  IN EFI_FILE_PROTOCOL  *This,\r
+  IN UINT64             Position\r
   )\r
 /*++\r
 \r
@@ -1780,6 +1811,7 @@ Returns:
   UINT32                  PosHigh;\r
   CHAR16                  *FileName;\r
   EFI_TPL                 OldTpl;\r
+  UINTN                   Size;\r
 \r
   if (This == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -1795,7 +1827,9 @@ Returns:
       goto Done;\r
     }\r
 \r
-    FileName = AllocatePool (StrSize (PrivateFile->FileName) + StrSize (L"\\*"));\r
+    Size  = StrSize (PrivateFile->FileName);\r
+    Size += StrSize (L"\\*");\r
+    FileName = AllocatePool (Size);\r
     if (FileName == NULL) {\r
       Status = EFI_OUT_OF_RESOURCES;\r
       goto Done;\r
@@ -1825,7 +1859,7 @@ Returns:
     } else {\r
       PosHigh = (UINT32) RShiftU64 (Position, 32);\r
 \r
-      PosLow  = PrivateFile->WinNtThunk->SetFilePointer (PrivateFile->LHandle, (ULONG) Position, &PosHigh, FILE_BEGIN);\r
+      PosLow  = PrivateFile->WinNtThunk->SetFilePointer (PrivateFile->LHandle, (ULONG) Position, (PLONG)&PosHigh, FILE_BEGIN);\r
     }\r
 \r
     Status = (PosLow == 0xFFFFFFFF) ? EFI_DEVICE_ERROR : EFI_SUCCESS;\r
@@ -1839,8 +1873,8 @@ Done:
 EFI_STATUS\r
 EFIAPI\r
 WinNtSimpleFileSystemGetPosition (\r
-  IN  EFI_FILE  *This,\r
-  OUT UINT64    *Position\r
+  IN  EFI_FILE_PROTOCOL   *This,\r
+  OUT UINT64              *Position\r
   )\r
 /*++\r
 \r
@@ -1888,11 +1922,11 @@ Returns:
 \r
     PositionHigh = 0;\r
     *Position = PrivateFile->WinNtThunk->SetFilePointer (\r
-                                          PrivateFile->LHandle,\r
-                                          0,\r
-                                          &PositionHigh,\r
-                                          FILE_CURRENT\r
-                                          );\r
+                                           PrivateFile->LHandle,\r
+                                           0,\r
+                                           (PLONG)&PositionHigh,\r
+                                           FILE_CURRENT\r
+                                           );\r
 \r
     Status = *Position == 0xffffffff ? EFI_DEVICE_ERROR : EFI_SUCCESS;\r
     if (EFI_ERROR (Status)) {\r
@@ -1941,11 +1975,6 @@ Returns:
   SYSTEMTIME                  SystemTime;\r
   CHAR16                      *RealFileName;\r
   CHAR16                      *TempPointer;\r
-  EFI_FILE_INFO               *DirInfo;\r
-  UINTN                       ReadSize;\r
-  UINT64                      Location;\r
-  EFI_STATUS                  DirStatus;\r
-\r
 \r
   Size        = SIZE_OF_EFI_FILE_INFO;\r
   NameSize    = StrSize (PrivateFile->FileName);\r
@@ -1966,6 +1995,7 @@ Returns:
     Info->FileSize      = FileInfo.nFileSizeLow;\r
     Info->PhysicalSize  = Info->FileSize;\r
 \r
+    PrivateFile->WinNtThunk->FileTimeToLocalFileTime(&FileInfo.ftCreationTime, &FileInfo.ftCreationTime);\r
     PrivateFile->WinNtThunk->FileTimeToSystemTime (&FileInfo.ftCreationTime, &SystemTime);\r
     Info->CreateTime.Year   = SystemTime.wYear;\r
     Info->CreateTime.Month  = (UINT8) SystemTime.wMonth;\r
@@ -1974,6 +2004,7 @@ Returns:
     Info->CreateTime.Minute = (UINT8) SystemTime.wMinute;\r
     Info->CreateTime.Second = (UINT8) SystemTime.wSecond;\r
 \r
+    PrivateFile->WinNtThunk->FileTimeToLocalFileTime(&FileInfo.ftLastAccessTime, &FileInfo.ftLastAccessTime);\r
     PrivateFile->WinNtThunk->FileTimeToSystemTime (&FileInfo.ftLastAccessTime, &SystemTime);\r
     Info->LastAccessTime.Year   = SystemTime.wYear;\r
     Info->LastAccessTime.Month  = (UINT8) SystemTime.wMonth;\r
@@ -1982,6 +2013,7 @@ Returns:
     Info->LastAccessTime.Minute = (UINT8) SystemTime.wMinute;\r
     Info->LastAccessTime.Second = (UINT8) SystemTime.wSecond;\r
 \r
+    PrivateFile->WinNtThunk->FileTimeToLocalFileTime(&FileInfo.ftLastWriteTime, &FileInfo.ftLastWriteTime);\r
     PrivateFile->WinNtThunk->FileTimeToSystemTime (&FileInfo.ftLastWriteTime, &SystemTime);\r
     Info->ModificationTime.Year   = SystemTime.wYear;\r
     Info->ModificationTime.Month  = (UINT8) SystemTime.wMonth;\r
@@ -2030,45 +2062,6 @@ Returns:
     } else {\r
       CopyMem ((CHAR8 *) Buffer + Size, RealFileName, NameSize);\r
     }\r
-\r
-    if (Info->Attribute & EFI_FILE_DIRECTORY) {\r
-      //\r
-      // The GetFileInformationByHandle.nFileSizeLow is bogus for dir so we \r
-      // need to do the same thing the caller would do to get the right value\r
-      //\r
-      ASSERT (PrivateFile->EfiFile.Read != NULL);\r
-      DirStatus = PrivateFile->EfiFile.GetPosition (&PrivateFile->EfiFile, &Location);\r
-      if (EFI_ERROR (DirStatus)) {\r
-        Location = 0;\r
-      }\r
-\r
-      PrivateFile->EfiFile.SetPosition (&PrivateFile->EfiFile, 0);\r
-      Info->FileSize = 0; \r
-      do {\r
-        ReadSize = 0;\r
-        DirInfo = NULL;\r
-        DirStatus = PrivateFile->EfiFile.Read (&PrivateFile->EfiFile, &ReadSize, DirInfo);\r
-        if (DirStatus == EFI_BUFFER_TOO_SMALL) {\r
-          DirInfo = AllocatePool (ReadSize);\r
-          if (DirInfo != NULL) {\r
-            //\r
-            // Read each dir entry to figure out how big the directory is\r
-            //\r
-            DirStatus = PrivateFile->EfiFile.Read (&PrivateFile->EfiFile, &ReadSize, DirInfo);\r
-            if (!EFI_ERROR (DirStatus) && (ReadSize != 0)) {\r
-              Info->FileSize += ReadSize;\r
-            }\r
-            FreePool (DirInfo);\r
-          }\r
-        }\r
-        \r
-      } while (!EFI_ERROR (DirStatus) && (ReadSize != 0));\r
-\r
-      //\r
-      // reset the file possition back to the previous location\r
-      //\r
-      PrivateFile->EfiFile.SetPosition (&PrivateFile->EfiFile, Location);\r
-    }\r
   }\r
 \r
   *BufferSize = ResultSize;\r
@@ -2078,10 +2071,10 @@ Returns:
 EFI_STATUS\r
 EFIAPI\r
 WinNtSimpleFileSystemGetInfo (\r
-  IN     EFI_FILE  *This,\r
-  IN     EFI_GUID  *InformationType,\r
-  IN OUT UINTN     *BufferSize,\r
-  OUT    VOID      *Buffer\r
+  IN     EFI_FILE_PROTOCOL  *This,\r
+  IN     EFI_GUID           *InformationType,\r
+  IN OUT UINTN              *BufferSize,\r
+  OUT    VOID               *Buffer\r
   )\r
 /*++\r
 \r
@@ -2199,10 +2192,10 @@ Returns:
     //\r
     NtStatus = PrivateFile->WinNtThunk->GetDiskFreeSpace (\r
                                           DriveNameFound ? DriveName : NULL,\r
-                                          &SectorsPerCluster,\r
-                                          &BytesPerSector,\r
-                                          &FreeClusters,\r
-                                          &TotalClusters\r
+                                          (LPDWORD)&SectorsPerCluster,\r
+                                          (LPDWORD)&BytesPerSector,\r
+                                          (LPDWORD)&FreeClusters,\r
+                                          (LPDWORD)&TotalClusters\r
                                           );\r
     if (DriveName) {\r
       FreePool (DriveName);\r
@@ -2259,7 +2252,7 @@ Done:
 EFI_STATUS\r
 EFIAPI\r
 WinNtSimpleFileSystemSetInfo (\r
-  IN EFI_FILE         *This,\r
+  IN EFI_FILE_PROTOCOL*This,\r
   IN EFI_GUID         *InformationType,\r
   IN UINTN            BufferSize,\r
   IN VOID             *Buffer\r
@@ -2331,6 +2324,7 @@ Returns:
   WIN32_FIND_DATA                   FindBuf;\r
   EFI_FILE_SYSTEM_INFO              *NewFileSystemInfo;\r
   EFI_TPL                           OldTpl;\r
+  UINTN                             Size;\r
 \r
   //\r
   // Check for invalid parameters.\r
@@ -2356,12 +2350,12 @@ Returns:
   // Set file system information.\r
   //\r
   if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) {\r
-    if (BufferSize < SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel)) {\r
+    NewFileSystemInfo = (EFI_FILE_SYSTEM_INFO *) Buffer;\r
+    if (BufferSize < SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (NewFileSystemInfo->VolumeLabel)) {\r
       Status = EFI_BAD_BUFFER_SIZE;\r
       goto Done;\r
     }\r
 \r
-    NewFileSystemInfo = (EFI_FILE_SYSTEM_INFO *) Buffer;\r
 \r
     FreePool (PrivateRoot->VolumeLabel);\r
     PrivateRoot->VolumeLabel = AllocatePool (StrSize (NewFileSystemInfo->VolumeLabel));\r
@@ -2410,7 +2404,7 @@ Returns:
   //\r
   NewFileInfo = (EFI_FILE_INFO *) Buffer;\r
 \r
-  if (NewFileInfo->Size <= sizeof (EFI_FILE_INFO) ||\r
+  if ((NewFileInfo->Size <= SIZE_OF_EFI_FILE_INFO) ||\r
       (NewFileInfo->Attribute &~(EFI_FILE_VALID_ATTR)) ||\r
       (sizeof (UINTN) == 4 && NewFileInfo->Size > 0xFFFFFFFF)\r
       ) {\r
@@ -2460,7 +2454,10 @@ Returns:
   // Make full pathname from new filename and rootpath.\r
   //\r
   if (NewFileInfo->FileName[0] == '\\') {\r
-    NewFileName = AllocatePool (StrSize (PrivateRoot->FilePath) + StrSize (L"\\") + StrSize (NewFileInfo->FileName));\r
+    Size  = StrSize (PrivateRoot->FilePath);\r
+    Size += StrSize (L"\\");\r
+    Size += StrSize (NewFileInfo->FileName);\r
+    NewFileName = AllocatePool (Size);\r
     if (NewFileName == NULL) {\r
       Status = EFI_OUT_OF_RESOURCES;\r
       goto Done;\r
@@ -2470,7 +2467,10 @@ Returns:
     StrCat (NewFileName, L"\\");\r
     StrCat (NewFileName, NewFileInfo->FileName + 1);\r
   } else {\r
-    NewFileName = AllocatePool (StrSize (PrivateFile->FilePath) + StrSize (L"\\") + StrSize (NewFileInfo->FileName));\r
+    Size  = StrSize (PrivateFile->FilePath);\r
+    Size += StrSize (L"\\");\r
+    Size += StrSize (NewFileInfo->FileName);\r
+    NewFileName = AllocatePool (Size);\r
     if (NewFileName == NULL) {\r
       Status = EFI_OUT_OF_RESOURCES;\r
       goto Done;\r
@@ -2588,7 +2588,9 @@ Returns:
 \r
       StrCpy (PrivateFile->FileName, NewFileName);\r
 \r
-      TempFileName = AllocatePool (StrSize (NewFileName) + StrSize (L"\\*"));\r
+      Size  =  StrSize (NewFileName);\r
+      Size += StrSize (L"\\*");\r
+      TempFileName = AllocatePool (Size);\r
 \r
       StrCpy (TempFileName, NewFileName);\r
 \r
@@ -2629,8 +2631,8 @@ Returns:
         FreePool (TempFileName);\r
       }\r
     } else {\r
+      Status    = EFI_ACCESS_DENIED;\r
 Reopen: ;\r
-      Status    = EFI_DEVICE_ERROR;\r
 \r
       NtStatus  = PrivateFile->WinNtThunk->SetFileAttributes (OldFileName, OldAttr);\r
 \r
@@ -2638,7 +2640,9 @@ Reopen: ;
         goto Done;\r
       }\r
 \r
-      TempFileName = AllocatePool (StrSize (OldFileName) + StrSize (L"\\*"));\r
+      Size =  StrSize (OldFileName);\r
+      Size += StrSize (L"\\*");\r
+      TempFileName = AllocatePool (Size);\r
 \r
       StrCpy (TempFileName, OldFileName);\r
 \r
@@ -2729,6 +2733,13 @@ Reopen: ;
       goto Done;\r
     }\r
 \r
+    if (!PrivateFile->WinNtThunk->LocalFileTimeToFileTime (\r
+                                    &NewCreationFileTime,\r
+                                    &NewCreationFileTime\r
+                                    )) {\r
+      goto Done;\r
+    }\r
+\r
     NewLastAccessSystemTime.wYear         = NewFileInfo->LastAccessTime.Year;\r
     NewLastAccessSystemTime.wMonth        = NewFileInfo->LastAccessTime.Month;\r
     NewLastAccessSystemTime.wDay          = NewFileInfo->LastAccessTime.Day;\r
@@ -2744,6 +2755,13 @@ Reopen: ;
       goto Done;\r
     }\r
 \r
+    if (!PrivateFile->WinNtThunk->LocalFileTimeToFileTime (\r
+                                    &NewLastAccessFileTime,\r
+                                    &NewLastAccessFileTime\r
+                                    )) {\r
+      goto Done;\r
+    }\r
+\r
     NewLastWriteSystemTime.wYear          = NewFileInfo->ModificationTime.Year;\r
     NewLastWriteSystemTime.wMonth         = NewFileInfo->ModificationTime.Month;\r
     NewLastWriteSystemTime.wDay           = NewFileInfo->ModificationTime.Day;\r
@@ -2759,6 +2777,13 @@ Reopen: ;
       goto Done;\r
     }\r
 \r
+    if (!PrivateFile->WinNtThunk->LocalFileTimeToFileTime (\r
+                                    &NewLastWriteFileTime,\r
+                                    &NewLastWriteFileTime\r
+                                    )) {\r
+      goto Done;\r
+    }\r
+\r
     if (!PrivateFile->WinNtThunk->SetFileTime (\r
                                     PrivateFile->IsDirectoryPath ? PrivateFile->DirHandle : PrivateFile->LHandle,\r
                                     &NewCreationFileTime,\r
@@ -2804,6 +2829,7 @@ Reopen: ;
   NtStatus = PrivateFile->WinNtThunk->SetFileAttributes (NewFileName, NewAttr);\r
 \r
   if (!NtStatus) {\r
+    Status    = EFI_DEVICE_ERROR;\r
     goto Reopen;\r
   }\r
 \r
@@ -2827,7 +2853,7 @@ Done:
 EFI_STATUS\r
 EFIAPI\r
 WinNtSimpleFileSystemFlush (\r
-  IN EFI_FILE  *This\r
+  IN EFI_FILE_PROTOCOL  *This\r
   )\r
 /*++\r
 \r