]> 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 62cb47960dd80ad31c717a32daba422963271cf0..63ab71fb2baa09acf5f4ce2582f03a30cefe95b1 100644 (file)
@@ -1,7 +1,7 @@
-/*++\r
+/**@file\r
 \r
-Copyright (c) 2006 - 2007, 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
@@ -22,7 +22,7 @@ Abstract:
 \r
   * Other names and brands may be claimed as the property of others.\r
 \r
---*/\r
+**/\r
 \r
 //\r
 // The package level header files this module uses\r
@@ -83,14 +83,13 @@ InitializeWinNtSimpleFileSystem(
   //\r
   // Install driver model protocol(s).\r
   //\r
-  Status = EfiLibInstallAllDriverProtocols (\r
+  Status = EfiLibInstallDriverBindingComponentName2 (\r
              ImageHandle,\r
              SystemTable,\r
              &gWinNtSimpleFileSystemDriverBinding,\r
              ImageHandle,\r
              &gWinNtSimpleFileSystemComponentName,\r
-             NULL,\r
-             NULL\r
+             &gWinNtSimpleFileSystemComponentName2\r
              );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
@@ -256,7 +255,7 @@ Returns:
   Status = gBS->OpenProtocol (\r
                   ControllerHandle,\r
                   &gEfiWinNtIoProtocolGuid,\r
-                  &WinNtIo,\r
+                  (VOID **) &WinNtIo,\r
                   This->DriverBindingHandle,\r
                   ControllerHandle,\r
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
@@ -329,7 +328,7 @@ Returns:
   Status = gBS->OpenProtocol (\r
                   ControllerHandle,\r
                   &gEfiWinNtIoProtocolGuid,\r
-                  &WinNtIo,\r
+                  (VOID **) &WinNtIo,\r
                   This->DriverBindingHandle,\r
                   ControllerHandle,\r
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
@@ -373,13 +372,22 @@ Returns:
 \r
   Private->ControllerNameTable = NULL;\r
 \r
-  AddUnicodeString (\r
+  AddUnicodeString2 (\r
     "eng",\r
     gWinNtSimpleFileSystemComponentName.SupportedLanguages,\r
     &Private->ControllerNameTable,\r
-    WinNtIo->EnvString\r
+    WinNtIo->EnvString,\r
+    TRUE\r
+    );\r
+  AddUnicodeString2 (\r
+    "en",\r
+    gWinNtSimpleFileSystemComponentName2.SupportedLanguages,\r
+    &Private->ControllerNameTable,\r
+    WinNtIo->EnvString,\r
+    FALSE\r
     );\r
 \r
+\r
   Status = gBS->InstallMultipleProtocolInterfaces (\r
                   &ControllerHandle,\r
                   &gEfiSimpleFileSystemProtocolGuid,\r
@@ -451,7 +459,7 @@ Returns:
   Status = gBS->OpenProtocol (\r
                   ControllerHandle,\r
                   &gEfiSimpleFileSystemProtocolGuid,\r
-                  &SimpleFileSystem,\r
+                  (VOID **) &SimpleFileSystem,\r
                   This->DriverBindingHandle,\r
                   ControllerHandle,\r
                   EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
@@ -496,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
@@ -535,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
@@ -581,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
@@ -609,14 +658,164 @@ Done:
   return Status;\r
 }\r
 \r
+/**\r
+  Count the number of Leading Dot in FileNameToken.\r
+\r
+  @param FileNameToken  A string representing a token in the path name.\r
+\r
+  @return  UINTN             The number of leading dot in the name.\r
+\r
+**/\r
+UINTN\r
+CountLeadingDots (\r
+  IN CONST CHAR16 * FileNameToken\r
+  )\r
+{\r
+  UINTN          Num;\r
+\r
+  Num = 0;\r
+  while (*FileNameToken == L'.') {\r
+    Num++;\r
+    FileNameToken++;\r
+  }\r
+  \r
+  return Num;\r
+}\r
+\r
+BOOLEAN \r
+IsFileNameTokenValid (\r
+  IN CONST CHAR16 * FileNameToken\r
+  )\r
+{\r
+  UINTN Num;\r
+  if (StrStr (FileNameToken, L"/") != NULL) {\r
+    //\r
+    // No L'/' in file name.\r
+    //\r
+    return FALSE;\r
+  } else {\r
+    //\r
+    // If Token has all dot, the number should not exceed 2\r
+    //\r
+    Num = CountLeadingDots (FileNameToken);\r
+\r
+    if (Num == StrLen (FileNameToken)) {\r
+      //\r
+      // If the FileNameToken only contains a number of L'.'.\r
+      //\r
+      if (Num > 2) {\r
+        return FALSE;\r
+      }\r
+    }\r
+  }\r
+\r
+  return TRUE;\r
+}\r
+\r
+/**\r
+  Return the first string token found in the indirect pointer a String named by FileName.\r
+\r
+  On input, FileName is a indirect pointer pointing to a String.\r
+  On output, FileName is a updated to point to the next character after the first\r
+  found L"\" or NULL if there is no L"\" found.\r
+\r
+  @param FileName  A indirect pointer pointing to a FileName.\r
+\r
+  @return  Token      The first string token found before a L"\".\r
+\r
+**/\r
+CHAR16 *\r
+GetNextFileNameToken (\r
+  IN OUT CONST CHAR16 ** FileName \r
+  )\r
+{\r
+  CHAR16 *SlashPos;\r
+  CHAR16 *Token;\r
+  UINTN  Offset;\r
+  ASSERT (**FileName != L'\\');\r
+  ASSERT (**FileName != L'\0');\r
+\r
+  SlashPos = StrStr (*FileName, L"\\");\r
+  if (SlashPos == NULL) {\r
+    Token = AllocateCopyPool (StrSize(*FileName), *FileName);\r
+    *FileName = NULL;\r
+  } else {\r
+    Offset = SlashPos - *FileName;\r
+    Token = AllocateZeroPool ((Offset + 1) * sizeof (CHAR16));\r
+    StrnCpy (Token, *FileName, Offset);\r
+    //\r
+    // Point *FileName to the next character after L'\'.\r
+    //\r
+    *FileName = *FileName + Offset + 1;\r
+  }\r
+\r
+  return Token;\r
+}\r
+\r
+/**\r
+  Check if a FileName contains only Valid Characters.\r
+\r
+  If FileName contains only a single L'\', return TRUE.\r
+  If FileName contains two adjacent L'\', return FALSE.\r
+  If FileName conatins L'/' , return FALSE.\r
+  If FielName contains more than two dots seperated with other FileName characters\r
+  by L'\', return FALSE. For example, L'.\...\filename.txt' is invalid path name. But L'..TwoDots\filename.txt' is valid path name.\r
+\r
+  @param FileName  The File Name String to check.\r
+\r
+  @return  TRUE        FileName only contains valid characters.\r
+  @return  FALSE       FileName contains at least one invalid character.\r
+\r
+**/\r
+\r
+BOOLEAN\r
+IsFileNameValid (\r
+  IN CONST CHAR16 *FileName \r
+  )\r
+{\r
+  CHAR16       *Token;\r
+  BOOLEAN      Valid;\r
+\r
+  //\r
+  // If FileName is just L'\', then it is a valid pathname. \r
+  //\r
+  if (StrCmp (FileName, L"\\") == 0) {\r
+    return TRUE;\r
+  }\r
+  //\r
+  // We don't support two or more adjacent L'\'.\r
+  //\r
+  if (StrStr (FileName, L"\\\\") != NULL) {\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // Is FileName has a leading L"\", skip to next character.\r
+  //\r
+  if (FileName [0] == L'\\') {\r
+    FileName++;\r
+  }\r
+\r
+  do {\r
+    Token = GetNextFileNameToken (&FileName);\r
+    Valid = IsFileNameTokenValid (Token);\r
+    FreePool (Token);\r
+    \r
+    if (!Valid)\r
+      return FALSE;\r
+  } while (FileName != NULL);\r
+\r
+  return TRUE;\r
+}\r
+\r
 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
@@ -664,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
@@ -679,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
@@ -725,29 +924,16 @@ 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
 \r
   //\r
-  // If file name does not equal to "." or "..",\r
+  // If file name does not equal to "." or ".." and not trailed with "\..",\r
   // then we trim the leading/trailing blanks and trailing dots\r
   //\r
-  if (StrCmp (FileName, L".") != 0 && StrCmp (FileName, L"..") != 0) {\r
+  if (StrCmp (FileName, L".") != 0 && StrCmp (FileName, L"..") != 0 && \r
+    ((StrLen (FileName) >= 3) ? (StrCmp (&FileName[StrLen (FileName) - 3], L"\\..") != 0) : TRUE)) {\r
     //\r
     // Trim leading blanks\r
     //\r
@@ -759,10 +945,10 @@ OpenRoot:
     }\r
     CutPrefix (FileName, Count);\r
     //\r
-    // Trim trailing dots and blanks\r
+    // Trim trailing blanks\r
     //\r
     for (TempFileName = FileName + StrLen (FileName) - 1;\r
-      TempFileName >= FileName && (*TempFileName == L' ' || *TempFileName == L'.');\r
+      TempFileName >= FileName && (*TempFileName == L' ');\r
       TempFileName--) {\r
       ;\r
     }\r
@@ -792,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
@@ -813,6 +1002,11 @@ OpenRoot:
     }\r
   }\r
 \r
+  if (!IsFileNameValid (NewPrivateFile->FileName)) {\r
+    Status = EFI_NOT_FOUND;\r
+    goto Done;\r
+  }\r
+\r
   //\r
   // Get rid of . and .., except leading . or ..\r
   //\r
@@ -869,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
@@ -894,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
@@ -943,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
@@ -1092,7 +1284,7 @@ OpenRoot:
     WinNtSimpleFileSystemSetInfo (&NewPrivateFile->EfiFile, &gEfiFileInfoGuid, InfoSize, Info);\r
   }\r
 \r
-Done: ;\r
+Done:\r
   FreePool (FileName);\r
 \r
   if (EFI_ERROR (Status)) {\r
@@ -1109,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
@@ -1117,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
@@ -1176,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
@@ -1243,7 +1438,6 @@ Returns:
   return Status;\r
 }\r
 \r
-STATIC\r
 VOID\r
 WinNtSystemTimeToEfiTime (\r
   IN SYSTEMTIME             *SystemTime,\r
@@ -1285,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
@@ -1397,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
@@ -1500,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
@@ -1568,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
@@ -1587,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
@@ -1617,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
@@ -1632,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
@@ -1662,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
@@ -1676,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
@@ -1725,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
@@ -1745,7 +1942,6 @@ Done:
   return Status;\r
 }\r
 \r
-STATIC\r
 EFI_STATUS\r
 WinNtSimpleFileSystemFileInfo (\r
   IN     WIN_NT_EFI_FILE_PRIVATE  *PrivateFile,\r
@@ -1779,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
@@ -1804,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
@@ -1812,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
@@ -1820,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
@@ -1868,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
@@ -1916,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
@@ -2037,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
@@ -2097,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
@@ -2169,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
@@ -2194,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
@@ -2248,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
@@ -2298,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
@@ -2308,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
@@ -2426,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
@@ -2467,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
@@ -2476,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
@@ -2567,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
@@ -2582,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
@@ -2597,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
@@ -2642,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
@@ -2665,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