I/O Caching Helper Subsystem.
The IO Cache abstracts caching of disk sectors away from the device driver to reduce code duplication and allow a central location for disk cache management that can be flushed simply by the kernel, without having to ask each driver to do it indivitually.
Go to the source code of this file.
Typedefs | |
typedef struct sIOCache | tIOCache |
IO Cache Handle. | |
typedef int(* | tIOCache_WriteCallback )(Uint32 ID, Uint64 Sector, void *Buffer) |
Write Callback. | |
Enumerations | |
enum | eIOCache_Modess { IOCACHE_WRITEBACK, IOCACHE_DELAYWRITE, IOCACHE_VIRTUAL } |
I/O Cache handling modes. More... | |
Functions | |
tIOCache * | IOCache_Create (tIOCache_WriteCallback Write, Uint32 ID, int SectorSize, int CacheSize) |
Creates a new IO Cache. | |
int | IOCache_Read (tIOCache *Cache, Uint64 Sector, void *Buffer) |
Reads from a cached sector. | |
int | IOCache_Add (tIOCache *Cache, Uint64 Sector, void *Buffer) |
Adds a sector to the cache. | |
int | IOCache_Write (tIOCache *Cache, Uint64 Sector, void *Buffer) |
Writes to a cached sector. | |
void | IOCache_Flush (tIOCache *Cache) |
Flush altered sectors out to the device. | |
void | IOCache_Destroy (tIOCache *Cache) |
Flushes the cache and then removes it. |
typedef int(* tIOCache_WriteCallback)(Uint32 ID, Uint64 Sector, void *Buffer) |
Write Callback.
Called to write a sector back to the device
enum eIOCache_Modess |
I/O Cache handling modes.
IOCACHE_WRITEBACK |
Writeback. Transparently writes data straight to the device when the cache is written to. |
IOCACHE_DELAYWRITE |
Delay Write. Only writes when instructed to (by IOCache_Flush) or when a cached sector is being reallocated. |
IOCACHE_VIRTUAL |
Virtual - No Writes. Changes to the cache contents are only reflected in memory, any calls to IOCache_Flush will silently return without doing anything and if a sector is reallocated, all changes will be lost |
Adds a sector to the cache.
Cache | Cache handle returned by IOCache_Create | |
Sector | Sector's ID number | |
Buffer | Data to cache |
tIOCache* IOCache_Create | ( | tIOCache_WriteCallback | Write, | |
Uint32 | ID, | |||
int | SectorSize, | |||
int | CacheSize | |||
) |
Creates a new IO Cache.
Write | Function to call to write a sector to the device | |
ID | ID to pass to Write | |
SectorSize | Size of a cached sector | |
CacheSize | Maximum number of objects that can be in the cache at one time |
void IOCache_Destroy | ( | tIOCache * | Cache | ) |
Flushes the cache and then removes it.
Cache | Cache handle returned by IOCache_Create |
IOCache_Destroy writes all changed sectors to the device and then deallocates the cache for other systems to use.
void IOCache_Flush | ( | tIOCache * | Cache | ) |
Flush altered sectors out to the device.
Cache | Cache handle returned by IOCache_Create |
This will call the cache's write callback on each altered sector to flush the write cache.
Reads from a cached sector.
Cache | Cache handle returned by IOCache_Create | |
Sector | Sector's ID number | |
Buffer | Destination for the data read |
Writes to a cached sector.
Cache | Cache handle returned by IOCache_Create | |
Sector | Sector's ID number | |
Buffer | Data to write to the cache |
If the sector is in the cache, it is updated. Wether the Write callback is called depends on the selected caching behaviour.