]> git.proxmox.com Git - mirror_edk2.git/blobdiff - FatPkg/EnhancedFatDxe/Flush.c
SecurityPkg: AuthVariableLib: Fix inconsistent CertDB case
[mirror_edk2.git] / FatPkg / EnhancedFatDxe / Flush.c
index e058fa4cf876d48aa1d53e3f65c1fdc2b0c44ef2..2c960f3b99e6620d5ace7ac56ff84121e26d7ad3 100644 (file)
@@ -1,7 +1,7 @@
 /*++\r
 \r
-Copyright (c) 2005 - 2007, Intel Corporation\r
-All rights reserved. This program and the accompanying materials are licensed and made available\r
+Copyright (c) 2005 - 2013, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials are licensed and made available\r
 under the terms and conditions of the BSD License which accompanies this\r
 distribution. The full text of the license may be found at\r
 http://opensource.org/licenses/bsd-license.php\r
@@ -26,8 +26,9 @@ Revision History
 \r
 EFI_STATUS\r
 EFIAPI\r
-FatFlush (\r
-  IN EFI_FILE  *FHand\r
+FatFlushEx (\r
+  IN EFI_FILE_PROTOCOL  *FHand,\r
+  IN EFI_FILE_IO_TOKEN  *Token\r
   )\r
 /*++\r
 \r
@@ -38,6 +39,7 @@ Routine Description:
 Arguments:\r
 \r
   FHand                 - Handle to file to flush.\r
+  Token                 - A pointer to the token associated with the transaction.\r
 \r
 Returns:\r
 \r
@@ -52,10 +54,12 @@ Returns:
   FAT_OFILE   *OFile;\r
   FAT_VOLUME  *Volume;\r
   EFI_STATUS  Status;\r
+  FAT_TASK    *Task;\r
 \r
   IFile   = IFILE_FROM_FHAND (FHand);\r
   OFile   = IFile->OFile;\r
   Volume  = OFile->Volume;\r
+  Task    = NULL;\r
 \r
   //\r
   // If the file has a permanent error, return it\r
@@ -73,20 +77,73 @@ Returns:
   if (IFile->ReadOnly) {\r
     return EFI_ACCESS_DENIED;\r
   }\r
+\r
+  if (Token == NULL) {\r
+    FatWaitNonblockingTask (IFile);\r
+  } else {\r
+    //\r
+    // Caller shouldn't call the non-blocking interfaces if the low layer doesn't support DiskIo2.\r
+    // But if it calls, the below check can avoid crash.\r
+    //\r
+    if (FHand->Revision < EFI_FILE_PROTOCOL_REVISION2) {\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+    Task = FatCreateTask (IFile, Token);\r
+    if (Task == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+  }\r
+\r
   //\r
   // Flush the OFile\r
   //\r
   FatAcquireLock ();\r
   Status  = FatOFileFlush (OFile);\r
-  Status  = FatCleanupVolume (OFile->Volume, OFile, Status);\r
+  Status  = FatCleanupVolume (OFile->Volume, OFile, Status, Task);\r
   FatReleaseLock ();\r
+\r
+  if (Token != NULL) {\r
+    if (!EFI_ERROR (Status)) {\r
+      Status = FatQueueTask (IFile, Task);\r
+    } else {\r
+      FatDestroyTask (Task);\r
+    }\r
+  }\r
+\r
   return Status;\r
 }\r
 \r
+EFI_STATUS\r
+EFIAPI\r
+FatFlush (\r
+  IN EFI_FILE_PROTOCOL  *FHand\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Flushes all data associated with the file handle.\r
+\r
+Arguments:\r
+\r
+  FHand                 - Handle to file to flush.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - Flushed the file successfully.\r
+  EFI_WRITE_PROTECTED   - The volume is read only.\r
+  EFI_ACCESS_DENIED     - The file is read only.\r
+  Others                - Flushing of the file failed.\r
+\r
+--*/\r
+{\r
+  return FatFlushEx (FHand, NULL);\r
+}\r
+\r
 EFI_STATUS\r
 EFIAPI\r
 FatClose (\r
-  IN EFI_FILE  *FHand\r
+  IN EFI_FILE_PROTOCOL  *FHand\r
   )\r
 /*++\r
 \r
@@ -125,7 +182,7 @@ Returns:
   //\r
   // Done. Unlock the volume\r
   //\r
-  FatCleanupVolume (Volume, OFile, EFI_SUCCESS);\r
+  FatCleanupVolume (Volume, OFile, EFI_SUCCESS, NULL);\r
   FatReleaseLock ();\r
 \r
   //\r
@@ -162,6 +219,8 @@ Returns:
 \r
   ASSERT_VOLUME_LOCKED (Volume);\r
 \r
+  FatWaitNonblockingTask (IFile);\r
+\r
   //\r
   // Remove the IFile struct\r
   //\r
@@ -359,7 +418,8 @@ EFI_STATUS
 FatCleanupVolume (\r
   IN FAT_VOLUME       *Volume,\r
   IN FAT_OFILE        *OFile,\r
-  IN EFI_STATUS       EfiStatus\r
+  IN EFI_STATUS       EfiStatus,\r
+  IN FAT_TASK         *Task\r
   )\r
 /*++\r
 \r
@@ -402,7 +462,7 @@ Returns:
     // indicates this a FAT32 volume\r
     //\r
     if (Volume->FreeInfoValid && Volume->FatDirty && Volume->FreeInfoPos) {\r
-      Status = FatDiskIo (Volume, WRITE_DISK, Volume->FreeInfoPos, sizeof (FAT_INFO_SECTOR), &Volume->FatInfoSector);\r
+      Status = FatDiskIo (Volume, WRITE_DISK, Volume->FreeInfoPos, sizeof (FAT_INFO_SECTOR), &Volume->FatInfoSector, Task);\r
       if (EFI_ERROR (Status)) {\r
         return Status;\r
       }\r
@@ -420,7 +480,7 @@ Returns:
     //\r
     // Flush all dirty cache entries to disk\r
     //\r
-    Status = FatVolumeFlushCache (Volume);\r
+    Status = FatVolumeFlushCache (Volume, Task);\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
     }\r