]> 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 eb8971febeca87c57825ed280a75e23d3c5b058c..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
@@ -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
@@ -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
@@ -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