
Untitled
By: a guest on
Jun 20th, 2010 | syntax:
C | size: 1.36 KB | hits: 130 | expires: Never
/*
The cache needs to be able to provide the following operating modes:
- read sector(s) to an already allocated buffer
NOTE: we can provide an hint to cache whether the sectors should be cached or not if it's not already in the cache
- write sectors(s) from an already filled buffer
NOTE: same remark
- read a sector and lock a buffer to it
- flag a locked sector as dirty
- clean a locked sector (write it back if needed)
- unlock a sector (maybe with a flag if it should be cleaned or not)
*/
struct sectorcache_entry
{
bool valid;
bool free;
int locks;
bool exclusive;
bool dirty;
unsigned long sector;
};
struct sectorcache_entry[SECTORCACHE_SIZE];
unsigned char sectorcache_buffer[SECTORCACHE_SIZE][SECTOR_SIZE];
void sectorcache_init(void);
int sectorcache_readthrough(IF_MD2(int drive,) unsigned long start, int count, void* buf, bool keepincache);
int sectorcache_writethrough(IF_MD2(int drive,) unsigned long start, int count, const void* buf, bool keepincache);
int sectorcache_lock(IF_MD2(int drive,) unsigned long sector, struct sectorcache_entry** handle, bool exclusive);
int sectorcache_unlock(struct sectorcache_entry** handle, bool clean, bool keepincache);
int sectorcache_markdirty(struct sectorcache_entry* handle);
int sectorcache_clean(struct sectorcache_entry* handle);
int sectorcache_clean_all(void);