/* Flush all the dirty cache back, include the FAT cache and the Data cache. */
EFI_STATUS FatVolumeFlushCache(IN FAT_VOLUME *Volume, IN FAT_TASK *Task)
/* Flush all the dirty cache back, include the FAT cache and the Data cache. */
EFI_STATUS FatVolumeFlushCache(IN FAT_VOLUME *Volume, IN FAT_TASK *Task)
{
  EFI_STATUS       Status;
  CACHE_DATA_TYPE  CacheDataType;
  UINTN            GroupIndex;
  UINTN            GroupMask;
  DISK_CACHE       *DiskCache;
  CACHE_TAG        *CacheTag;
  for (CacheDataType = (CACHE_DATA_TYPE)0; CacheDataType < CacheMaxType; CacheDataType++) {
    DiskCache = &Volume->DiskCache[CacheDataType];
    if (DiskCache->Dirty) {
      GroupMask = DiskCache->GroupMask;
      for (GroupIndex = 0; GroupIndex <= GroupMask; GroupIndex++) {
        CacheTag = &DiskCache->CacheTag[GroupIndex];
        if ((CacheTag->RealSize > 0) && CacheTag->Dirty) {
          Status = FatExchangeCachePage (Volume, CacheDataType, WriteDisk, CacheTag, Task);
          if (EFI_ERROR (Status)) {
            return Status;
          }
        }
      }
      DiskCache->Dirty = FALSE;
    }
  }
  Status = Volume->BlockIo->FlushBlocks (Volume->BlockIo);
  return Status;
}