]> git.proxmox.com Git - mirror_edk2.git/blobdiff - FatPkg/EnhancedFatDxe/Flush.c
UefiCpuPkg/PiSmmCpuDxeSmm: patch "gSmiStack" with PatchInstructionX86()
[mirror_edk2.git] / FatPkg / EnhancedFatDxe / Flush.c
index e058fa4cf876d48aa1d53e3f65c1fdc2b0c44ef2..9cb0d9ac189123bdcf93e64a58e53e7e3fe02dfc 100644 (file)
@@ -1,7 +1,8 @@
-/*++\r
+/** @file\r
+  Routines that check references and flush OFiles\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
@@ -10,52 +11,40 @@ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
 \r
-Module Name:\r
-\r
-  flush.c\r
+**/\r
 \r
-Abstract:\r
+#include "Fat.h"\r
 \r
-  Routines that check references and flush OFiles\r
+/**\r
 \r
-Revision History\r
+  Flushes all data associated with the file handle.\r
 \r
---*/\r
+  @param  FHand                 - Handle to file to flush.\r
+  @param  Token                 - A pointer to the token associated with the transaction.\r
 \r
-#include "Fat.h"\r
+  @retval EFI_SUCCESS           - Flushed the file successfully.\r
+  @retval EFI_WRITE_PROTECTED   - The volume is read only.\r
+  @retval EFI_ACCESS_DENIED     - The file is read only.\r
+  @return Others                - Flushing of the file failed.\r
 \r
+**/\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
-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
   FAT_IFILE   *IFile;\r
   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,36 +62,77 @@ 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
+/**\r
+\r
+  Flushes all data associated with the file handle.\r
+\r
+  @param  FHand                 - Handle to file to flush.\r
+\r
+  @retval EFI_SUCCESS           - Flushed the file successfully.\r
+  @retval EFI_WRITE_PROTECTED   - The volume is read only.\r
+  @retval EFI_ACCESS_DENIED     - The file is read only.\r
+  @return Others                - Flushing of the file failed.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
-FatClose (\r
-  IN EFI_FILE  *FHand\r
+FatFlush (\r
+  IN EFI_FILE_PROTOCOL  *FHand\r
   )\r
-/*++\r
+{\r
+  return FatFlushEx (FHand, NULL);\r
+}\r
 \r
-Routine Description:\r
+/**\r
 \r
   Flushes & Closes the file handle.\r
 \r
-Arguments:\r
-\r
-  FHand                 - Handle to the file to delete.\r
+  @param  FHand                 - Handle to the file to delete.\r
 \r
-Returns:\r
+  @retval EFI_SUCCESS           - Closed the file successfully.\r
 \r
-  EFI_SUCCESS           - Closed the file successfully.\r
-\r
---*/\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FatClose (\r
+  IN EFI_FILE_PROTOCOL  *FHand\r
+  )\r
 {\r
   FAT_IFILE   *IFile;\r
   FAT_OFILE   *OFile;\r
@@ -125,7 +155,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
@@ -134,25 +164,19 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \r
-EFI_STATUS\r
-FatIFileClose (\r
-  FAT_IFILE           *IFile\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
 \r
   Close the open file instance.\r
 \r
-Arguments:\r
-\r
-  IFile                 - Open file instance.\r
+  @param  IFile                 - Open file instance.\r
 \r
-Returns:\r
+  @retval EFI_SUCCESS           - Closed the file successfully.\r
 \r
-  EFI_SUCCESS           - Closed the file successfully.\r
-\r
---*/\r
+**/\r
+EFI_STATUS\r
+FatIFileClose (\r
+  FAT_IFILE           *IFile\r
+  )\r
 {\r
   FAT_OFILE   *OFile;\r
   FAT_VOLUME  *Volume;\r
@@ -162,6 +186,8 @@ Returns:
 \r
   ASSERT_VOLUME_LOCKED (Volume);\r
 \r
+  FatWaitNonblockingTask (IFile);\r
+\r
   //\r
   // Remove the IFile struct\r
   //\r
@@ -180,27 +206,21 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \r
-EFI_STATUS\r
-FatOFileFlush (\r
-  IN FAT_OFILE    *OFile\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
 \r
   Flush the data associated with an open file.\r
   In this implementation, only last Mod/Access time is updated.\r
 \r
-Arguments:\r
-\r
-  OFile                 - The open file.\r
+  @param  OFile                 - The open file.\r
 \r
-Returns:\r
+  @retval EFI_SUCCESS           - The OFile is flushed successfully.\r
+  @return Others                - An error occurred when flushing this OFile.\r
 \r
-  EFI_SUCCESS           - The OFile is flushed successfully.\r
-  Others                - An error occurred when flushing this OFile.\r
-\r
---*/\r
+**/\r
+EFI_STATUS\r
+FatOFileFlush (\r
+  IN FAT_OFILE    *OFile\r
+  )\r
 {\r
   EFI_STATUS    Status;\r
   FAT_OFILE     *Parent;\r
@@ -259,28 +279,22 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \r
-BOOLEAN\r
-FatCheckOFileRef (\r
-  IN FAT_OFILE   *OFile\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
 \r
   Check the references of the OFile.\r
   If the OFile (that is checked) is no longer\r
   referenced, then it is freed.\r
 \r
-Arguments:\r
+  @param  OFile                 - The OFile to be checked.\r
 \r
-  OFile                 - The OFile to be checked.\r
+  @retval TRUE                  - The OFile is not referenced and freed.\r
+  @retval FALSE                 - The OFile is kept.\r
 \r
-Returns:\r
-\r
-  TRUE                  - The OFile is not referenced and freed.\r
-  FALSE                 - The OFile is kept.\r
-\r
---*/\r
+**/\r
+BOOLEAN\r
+FatCheckOFileRef (\r
+  IN FAT_OFILE   *OFile\r
+  )\r
 {\r
   //\r
   // If the OFile is on the check ref list, remove it\r
@@ -307,29 +321,21 @@ Returns:
   return TRUE;\r
 }\r
 \r
-STATIC\r
-VOID\r
-FatCheckVolumeRef (\r
-  IN FAT_VOLUME   *Volume\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
 \r
   Check the references of all open files on the volume.\r
   Any open file (that is checked) that is no longer\r
   referenced, is freed - and it's parent open file\r
   is then referenced checked.\r
 \r
-Arguments:\r
-\r
-  Volume                - The volume to check the pending open file list.\r
-\r
-Returns:\r
+  @param  Volume                - The volume to check the pending open file list.\r
 \r
-  None\r
-\r
---*/\r
+**/\r
+STATIC\r
+VOID\r
+FatCheckVolumeRef (\r
+  IN FAT_VOLUME   *Volume\r
+  )\r
 {\r
   FAT_OFILE *OFile;\r
   FAT_OFILE *Parent;\r
@@ -355,33 +361,29 @@ Returns:
   }\r
 }\r
 \r
-EFI_STATUS\r
-FatCleanupVolume (\r
-  IN FAT_VOLUME       *Volume,\r
-  IN FAT_OFILE        *OFile,\r
-  IN EFI_STATUS       EfiStatus\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
 \r
   Set error status for a specific OFile, reference checking the volume.\r
   If volume is already marked as invalid, and all resources are freed\r
   after reference checking, the file system protocol is uninstalled and\r
   the volume structure is freed.\r
 \r
-Arguments:\r
-\r
-  Volume                - the Volume that is to be reference checked and unlocked.\r
-  OFile                 - the OFile whose permanent error code is to be set.\r
-  EfiStatus             - error code to be set.\r
-\r
-Returns:\r
+  @param  Volume                - the Volume that is to be reference checked and unlocked.\r
+  @param  OFile                 - the OFile whose permanent error code is to be set.\r
+  @param  EfiStatus             - error code to be set.\r
+  @param  Task                    point to task instance.\r
 \r
-  EFI_SUCCESS           - Clean up the volume successfully.\r
-  Others                - Cleaning up of the volume is failed.\r
+  @retval EFI_SUCCESS           - Clean up the volume successfully.\r
+  @return Others                - Cleaning up of the volume is failed.\r
 \r
---*/\r
+**/\r
+EFI_STATUS\r
+FatCleanupVolume (\r
+  IN FAT_VOLUME       *Volume,\r
+  IN FAT_OFILE        *OFile,\r
+  IN EFI_STATUS       EfiStatus,\r
+  IN FAT_TASK         *Task\r
+  )\r
 {\r
   EFI_STATUS  Status;\r
   //\r
@@ -402,7 +404,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, WriteDisk, Volume->FreeInfoPos, sizeof (FAT_INFO_SECTOR), &Volume->FatInfoSector, Task);\r
       if (EFI_ERROR (Status)) {\r
         return Status;\r
       }\r
@@ -410,9 +412,9 @@ Returns:
     //\r
     // Update that the volume is not dirty\r
     //\r
-    if (Volume->FatDirty && Volume->FatType != FAT12) {\r
+    if (Volume->FatDirty && Volume->FatType != Fat12) {\r
       Volume->FatDirty  = FALSE;\r
-      Status            = FatAccessVolumeDirty (Volume, WRITE_FAT, &Volume->NotDirtyValue);\r
+      Status            = FatAccessVolumeDirty (Volume, WriteFat, &Volume->NotDirtyValue);\r
       if (EFI_ERROR (Status)) {\r
         return Status;\r
       }\r
@@ -420,7 +422,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
@@ -439,27 +441,19 @@ Returns:
   return EfiStatus;\r
 }\r
 \r
+/**\r
+\r
+  Set the OFile and its child OFile with the error Status\r
+\r
+  @param  OFile                 - The OFile whose permanent error code is to be set.\r
+  @param  Status                - Error code to be set.\r
+\r
+**/\r
 VOID\r
 FatSetVolumeError (\r
   IN FAT_OFILE            *OFile,\r
   IN EFI_STATUS           Status\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Set the OFile and its child OFile with the error Status\r
-\r
-Arguments:\r
-\r
-  OFile                 - The OFile whose permanent error code is to be set.\r
-  Status                - Error code to be set.\r
-\r
-Returns:\r
-\r
-  None\r
-\r
---*/\r
 {\r
   LIST_ENTRY      *Link;\r
   FAT_OFILE       *ChildOFile;\r