]> 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 8ca9808c593f7231327f3a3e2a91c228dd60c85b..63ab71fb2baa09acf5f4ce2582f03a30cefe95b1 100644 (file)
@@ -1,7 +1,7 @@
 /**@file\r
 \r
-Copyright (c) 2006 - 2009, 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
@@ -544,6 +544,7 @@ Returns:
   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
@@ -613,10 +614,12 @@ Returns:
   //\r
   // Find the first file under it\r
   //\r
+  Size  = StrSize (PrivateFile->FilePath);\r
+  Size += StrSize (L"\\*");\r
   Status = gBS->AllocatePool (\r
                   EfiBootServicesData,\r
-                  StrSize (PrivateFile->FilePath) + StrSize (L"\\*"),\r
-                  &TempFileName\r
+                  Size,\r
+                  (VOID **)&TempFileName\r
                   );\r
   if (EFI_ERROR (Status)) {\r
     goto Done;\r
@@ -808,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
@@ -822,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
@@ -1309,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
@@ -1368,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
@@ -1476,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
@@ -1691,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
@@ -1778,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
@@ -1870,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
@@ -1972,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
@@ -1997,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
@@ -2005,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
@@ -2013,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
@@ -2061,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
@@ -2109,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
@@ -2290,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
@@ -2388,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
@@ -2442,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
@@ -2669,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
@@ -2771,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
@@ -2786,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
@@ -2801,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
@@ -2846,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
@@ -2869,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