5 * By thePowersGang (John Hodge)
9 * \brief I/O Caching Helper Subsystem
11 * The IO Cache abstracts caching of disk sectors away from the device
12 * driver to reduce code duplication and allow a central location for
13 * disk cache management that can be flushed simply by the kernel, without
14 * having to ask each driver to do it indivitually.
21 * \brief IO Cache Handle
23 typedef struct sIOCache tIOCache;
25 * \brief Write Callback
27 * Called to write a sector back to the device
29 typedef int (*tIOCache_WriteCallback)(Uint32 ID, Uint64 Sector, void *Buffer);
33 * \brief I/O Cache handling modes
35 enum eIOCache_Modess {
39 * Transparently writes data straight to the device when the cache
46 * Only writes when instructed to (by ::IOCache_Flush) or when a
47 * cached sector is being reallocated.
51 * \brief Virtual - No Writes
53 * Changes to the cache contents are only reflected in memory,
54 * any calls to ::IOCache_Flush will silently return without doing
55 * anything and if a sector is reallocated, all changes will be lost
62 * \brief Creates a new IO Cache
63 * \param Write Function to call to write a sector to the device
64 * \param ID ID to pass to \a Write
65 * \param SectorSize Size of a cached sector
66 * \param CacheSize Maximum number of objects that can be in the cache at one time
68 tIOCache *IOCache_Create( tIOCache_WriteCallback Write, Uint32 ID, int SectorSize, int CacheSize );
71 * \brief Reads from a cached sector
72 * \param Cache Cache handle returned by ::IOCache_Create
73 * \param Sector Sector's ID number
74 * \param Buffer Destination for the data read
75 * \return 1 if the data was read, 0 if the sector is not cached, -1 on error
77 int IOCache_Read( tIOCache *Cache, Uint64 Sector, void *Buffer );
80 * \brief Adds a sector to the cache
81 * \param Cache Cache handle returned by ::IOCache_Create
82 * \param Sector Sector's ID number
83 * \param Buffer Data to cache
84 * \return 1 on success, 0 if the sector is already cached, -1 on error
86 int IOCache_Add( tIOCache *Cache, Uint64 Sector, void *Buffer );
89 * \brief Writes to a cached sector
90 * \param Cache Cache handle returned by ::IOCache_Create
91 * \param Sector Sector's ID number
92 * \param Buffer Data to write to the cache
93 * \return 1 if the data was read, 0 if the sector is not cached, -1 on error
95 * If the sector is in the cache, it is updated.
96 * Wether the Write callback is called depends on the selected caching
99 int IOCache_Write( tIOCache *Cache, Uint64 Sector, void *Buffer );
102 * \brief Flush altered sectors out to the device
103 * \param Cache Cache handle returned by ::IOCache_Create
105 * This will call the cache's write callback on each altered sector
106 * to flush the write cache.
108 void IOCache_Flush( tIOCache *Cache );
111 * \brief Flushes the cache and then removes it
112 * \param Cache Cache handle returned by ::IOCache_Create
113 * \note After this is called \a Cache is no longer valid
115 * IOCache_Destroy writes all changed sectors to the device and then
116 * deallocates the cache for other systems to use.
118 void IOCache_Destroy( tIOCache *Cache );