bypass cache fill on write

This commit is contained in:
Dave Murphy 2009-10-07 19:54:16 +00:00
parent b7dcf2ce33
commit bf2d7d1130

View File

@ -264,6 +264,34 @@ bool _FAT_cache_eraseWritePartialSector (CACHE* cache, const void* buffer, sec_t
return true; return true;
} }
static CACHE_ENTRY* _FAT_cache_findPage(CACHE *cache, sec_t sector, sec_t count) {
unsigned int i;
CACHE_ENTRY* cacheEntries = cache->cacheEntries;
unsigned int numberOfPages = cache->numberOfPages;
CACHE_ENTRY *entry = NULL;
sec_t lowest = UINT_MAX;
for(i=0;i<numberOfPages;i++) {
if (cacheEntries[i].sector != CACHE_FREE) {
bool intersect;
if (sector > cacheEntries[i].sector) {
intersect = sector - cacheEntries[i].sector < cacheEntries[i].count;
} else {
intersect = cacheEntries[i].sector - sector < count;
}
if ( intersect && (cacheEntries[i].sector < lowest)) {
lowest = cacheEntries[i].sector;
entry = &cacheEntries[i];
}
}
}
return entry;
}
bool _FAT_cache_writeSectors (CACHE* cache, sec_t sector, sec_t numSectors, const void* buffer) bool _FAT_cache_writeSectors (CACHE* cache, sec_t sector, sec_t numSectors, const void* buffer)
{ {
sec_t sec; sec_t sec;
@ -273,20 +301,37 @@ bool _FAT_cache_writeSectors (CACHE* cache, sec_t sector, sec_t numSectors, cons
while(numSectors>0) while(numSectors>0)
{ {
entry = _FAT_cache_getPage(cache,sector); entry = _FAT_cache_findPage(cache,sector,numSectors);
if(entry==NULL) return false;
sec = sector - entry->sector; if(entry!=NULL) {
secs_to_write = entry->count - sec;
if(secs_to_write>numSectors) secs_to_write = numSectors;
memcpy(entry->cache + (sec*BYTES_PER_READ),src,(secs_to_write*BYTES_PER_READ)); if ( entry->sector > sector) {
secs_to_write = entry->sector - sector;
_FAT_disc_writeSectors(cache->disc,sector,secs_to_write,src);
src += (secs_to_write*BYTES_PER_READ);
sector += secs_to_write;
numSectors -= secs_to_write;
}
sec = sector - entry->sector;
secs_to_write = entry->count - sec;
src += (secs_to_write*BYTES_PER_READ); if(secs_to_write>numSectors) secs_to_write = numSectors;
sector += secs_to_write;
numSectors -= secs_to_write;
entry->dirty = true; memcpy(entry->cache + (sec*BYTES_PER_READ),src,(secs_to_write*BYTES_PER_READ));
src += (secs_to_write*BYTES_PER_READ);
sector += secs_to_write;
numSectors -= secs_to_write;
entry->dirty = true;
} else {
_FAT_disc_writeSectors(cache->disc,sector,numSectors,src);
numSectors=0;
}
} }
return true; return true;
} }