TianoCore EDK2 master
Loading...
Searching...
No Matches
DiskCache.c File Reference
#include "Fat.h"

Go to the source code of this file.

Functions

STATIC VOID ClearCacheTagDirtyState (IN CACHE_TAG *CacheTag)
 
STATIC VOID SetBitInDirtyBlock (IN UINTN BitNumber, IN DIRTY_BLOCKS *DirtyBlocks)
 
STATIC BOOLEAN IsBitInBlockDirty (IN UINTN BitNumber, IN DIRTY_BLOCKS *DirtyBlocks)
 
STATIC VOID SetCacheTagDirty (IN DISK_CACHE *DiskCache, IN CACHE_TAG *CacheTag, IN UINTN Offset, IN UINTN Length)
 
STATIC EFI_STATUS CacheFatDiskIo (IN CACHE_TAG *CacheTag, IN CACHE_DATA_TYPE DataType, IN FAT_VOLUME *Volume, IN IO_MODE IoMode, IN UINT64 Offset, IN UINTN BufferSize, IN OUT VOID *Buffer, IN FAT_TASK *Task)
 
STATIC VOID FatFlushDataCacheRange (IN FAT_VOLUME *Volume, IN IO_MODE IoMode, IN UINTN StartPageNo, IN UINTN EndPageNo, OUT UINT8 *Buffer)
 
STATIC EFI_STATUS FatExchangeCachePage (IN FAT_VOLUME *Volume, IN CACHE_DATA_TYPE DataType, IN IO_MODE IoMode, IN CACHE_TAG *CacheTag, IN FAT_TASK *Task)
 
STATIC EFI_STATUS FatGetCachePage (IN FAT_VOLUME *Volume, IN CACHE_DATA_TYPE CacheDataType, IN UINTN PageNo, IN CACHE_TAG *CacheTag)
 
STATIC EFI_STATUS FatAccessUnalignedCachePage (IN FAT_VOLUME *Volume, IN CACHE_DATA_TYPE CacheDataType, IN IO_MODE IoMode, IN UINTN PageNo, IN UINTN Offset, IN UINTN Length, IN OUT VOID *Buffer)
 
EFI_STATUS FatAccessCache (IN FAT_VOLUME *Volume, IN CACHE_DATA_TYPE CacheDataType, IN IO_MODE IoMode, IN UINT64 Offset, IN UINTN BufferSize, IN OUT UINT8 *Buffer, IN FAT_TASK *Task)
 
EFI_STATUS FatVolumeFlushCache (IN FAT_VOLUME *Volume, IN FAT_TASK *Task)
 
EFI_STATUS FatInitializeDiskCache (IN FAT_VOLUME *Volume)
 

Detailed Description

Cache implementation for EFI FAT File system driver.

Copyright (c) 2005 - 2013, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file DiskCache.c.

Function Documentation

◆ CacheFatDiskIo()

STATIC EFI_STATUS CacheFatDiskIo ( IN CACHE_TAG CacheTag,
IN CACHE_DATA_TYPE  DataType,
IN FAT_VOLUME Volume,
IN IO_MODE  IoMode,
IN UINT64  Offset,
IN UINTN  BufferSize,
IN OUT VOID *  Buffer,
IN FAT_TASK Task 
)

Cache version of FatDiskIo for writing only those LBA's with dirty data.

Keep track of LBA blocks within a cache line. Allow reads from the disk to read the full cache line, and all writes to the cache line will update which Lba is dirty in DIRTY_BITS.

At flush time, when the cache line is written out, only write the blocks that are dirty, coalescing adjacent writes to a single FatDiskIo write.

Parameters
[in]CacheTag- Cache line to check for dirty bits from
[in]DataType- Type of Cache.
[in]Volume- FAT file system volume.
[in]IoMode- The access mode (disk read/write or cache access).
[in]Offset- The starting byte offset to read from.
[in]BufferSize- Size of Buffer.
[in,out]Buffer- Buffer containing read data.
[in]Taskpoint to task instance.
Return values
EFI_SUCCESS- The operation is performed successfully.
EFI_VOLUME_CORRUPTED- The access is
Returns
Others - The status of read/write the disk

Definition at line 146 of file DiskCache.c.

◆ ClearCacheTagDirtyState()

STATIC VOID ClearCacheTagDirtyState ( IN CACHE_TAG CacheTag)

Helper function to clear the dirty state of the cache line.

Parameters
[in]CacheTag- CacheTag to clear

Definition at line 19 of file DiskCache.c.

◆ FatAccessCache()

EFI_STATUS FatAccessCache ( IN FAT_VOLUME Volume,
IN CACHE_DATA_TYPE  CacheDataType,
IN IO_MODE  IoMode,
IN UINT64  Offset,
IN UINTN  BufferSize,
IN OUT UINT8 *  Buffer,
IN FAT_TASK Task 
)

Read BufferSize bytes from the position of Offset into Buffer, or write BufferSize bytes from Buffer into the position of Offset.

Base on the parameter of CACHE_DATA_TYPE, the data access will be divided into the access of FAT cache (CACHE_FAT) and the access of Data cache (CACHE_DATA):

  1. Access of FAT cache (CACHE_FAT): Access the data in the FAT cache, if there is cache page hit, just return the cache page; else update the related cache page and return the right cache page.
  2. Access of Data cache (CACHE_DATA): The access data will be divided into UnderRun data, Aligned data and OverRun data; The UnderRun data and OverRun data will be accessed by the Data cache, but the Aligned data will be accessed with disk directly.
Parameters
Volume- FAT file system volume.
CacheDataType- The type of cache: CACHE_DATA or CACHE_FAT.
IoMode- Indicate the type of disk access.
Offset- The starting byte offset to read from.
BufferSize- Size of Buffer.
Buffer- Buffer containing cache data.
Taskpoint to task instance.
Return values
EFI_SUCCESS- The data was accessed correctly.
EFI_MEDIA_CHANGED- The MediaId does not match the current device.
Returns
Others - An error occurred when accessing cache.

Definition at line 493 of file DiskCache.c.

◆ FatAccessUnalignedCachePage()

STATIC EFI_STATUS FatAccessUnalignedCachePage ( IN FAT_VOLUME Volume,
IN CACHE_DATA_TYPE  CacheDataType,
IN IO_MODE  IoMode,
IN UINTN  PageNo,
IN UINTN  Offset,
IN UINTN  Length,
IN OUT VOID *  Buffer 
)

Read Length bytes from the position of Offset into Buffer, or write Length bytes from Buffer into the position of Offset.

Parameters
Volume- FAT file system volume.
CacheDataType- The type of cache: CACHE_DATA or CACHE_FAT.
IoMode- Indicate the type of disk access.
PageNo- The number of unaligned cache page.
Offset- The starting byte of cache page.
Length- The number of bytes that is read or written
Buffer- Buffer containing cache data.
Return values
EFI_SUCCESS- The data was accessed correctly.
Returns
Others - An error occurred when accessing unaligned cache page.

Definition at line 426 of file DiskCache.c.

◆ FatExchangeCachePage()

STATIC EFI_STATUS FatExchangeCachePage ( IN FAT_VOLUME Volume,
IN CACHE_DATA_TYPE  DataType,
IN IO_MODE  IoMode,
IN CACHE_TAG CacheTag,
IN FAT_TASK Task 
)

Exchange the cache page with the image on the disk

Parameters
Volume- FAT file system volume.
DataType- Indicate the cache type.
IoMode- Indicate whether to load this page from disk or store this page to disk.
CacheTag- The Cache Tag for the current cache page.
Taskpoint to task instance.
Return values
EFI_SUCCESS- Cache page exchanged successfully.
Returns
Others - An error occurred when exchanging cache page.

Definition at line 298 of file DiskCache.c.

◆ FatFlushDataCacheRange()

STATIC VOID FatFlushDataCacheRange ( IN FAT_VOLUME Volume,
IN IO_MODE  IoMode,
IN UINTN  StartPageNo,
IN UINTN  EndPageNo,
OUT UINT8 *  Buffer 
)

This function is used by the Data Cache.

When this function is called by write command, all entries in this range are older than the contents in disk, so they are invalid; just mark them invalid.

When this function is called by read command, if any entry in this range is dirty, it means that the relative info directly read from media is older than than the info in the cache; So need to update the relative info in the Buffer.

Parameters
Volume- FAT file system volume.
IoMode- This function is called by read command or write command
StartPageNo- First PageNo to be checked in the cache.
EndPageNo- Last PageNo to be checked in the cache.
Buffer- The user buffer need to update. Only when doing the read command and there is dirty cache in the cache range, this parameter will be used.

Definition at line 232 of file DiskCache.c.

◆ FatGetCachePage()

STATIC EFI_STATUS FatGetCachePage ( IN FAT_VOLUME Volume,
IN CACHE_DATA_TYPE  CacheDataType,
IN UINTN  PageNo,
IN CACHE_TAG CacheTag 
)

Get one cache page by specified PageNo.

Parameters
Volume- FAT file system volume.
CacheDataType- The cache type: CACHE_FAT or CACHE_DATA.
PageNo- PageNo to match with the cache.
CacheTag- The Cache Tag for the current cache page.
Return values
EFI_SUCCESS- Get the cache page successfully.
Returns
other - An error occurred when accessing data.

Definition at line 370 of file DiskCache.c.

◆ FatInitializeDiskCache()

EFI_STATUS FatInitializeDiskCache ( IN FAT_VOLUME Volume)

Initialize the disk cache according to Volume's FatType.

Parameters
Volume- FAT file system volume.
Return values
EFI_SUCCESS- The disk cache is successfully initialized.
EFI_OUT_OF_RESOURCES- Not enough memory to allocate disk cache.

Definition at line 649 of file DiskCache.c.

◆ FatVolumeFlushCache()

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.

Parameters
Volume- FAT file system volume.
Taskpoint to task instance.
Return values
EFI_SUCCESS- Flush all the dirty cache back successfully
Returns
other - An error occurred when writing the data into the disk

Definition at line 595 of file DiskCache.c.

◆ IsBitInBlockDirty()

STATIC BOOLEAN IsBitInBlockDirty ( IN UINTN  BitNumber,
IN DIRTY_BLOCKS *  DirtyBlocks 
)

Helper function to check if a particular bit in a dirty block is marked dirty or not, so that it can be written to the disk if it is dirty.

Parameters
[in]BitNumber- Which bit to check in DirtyBlocks
[in]DirtyBlocks- Array of bits

Definition at line 71 of file DiskCache.c.

◆ SetBitInDirtyBlock()

STATIC VOID SetBitInDirtyBlock ( IN UINTN  BitNumber,
IN DIRTY_BLOCKS *  DirtyBlocks 
)

Helper function to set a bit in a dirty block. This is used to track which blocks to later write to disk.

Parameters
[in]BitNumber- Which bit to set in DirtyBlocks
[in]DirtyBlocks- Array of bits

Definition at line 42 of file DiskCache.c.

◆ SetCacheTagDirty()

STATIC VOID SetCacheTagDirty ( IN DISK_CACHE DiskCache,
IN CACHE_TAG CacheTag,
IN UINTN  Offset,
IN UINTN  Length 
)

Helper function to set a cache tag dirty for a given offset and length. Dirty blocks marked here will be flushed to disk when the file is closed.

Parameters
[in]DiskCache- DiskCache
[in]CacheTag- CacheTag to update
[in]Offset- Offset in the cache line to be marked modified
[in]Length- Length of the data to be marked modified

Definition at line 98 of file DiskCache.c.