mirror of
https://github.com/wiiu-env/libfat.git
synced 2024-11-26 03:44:15 +01:00
bypass cache fill on write
This commit is contained in:
parent
b7dcf2ce33
commit
bf2d7d1130
@ -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) {
|
||||||
|
|
||||||
src += (secs_to_write*BYTES_PER_READ);
|
secs_to_write = entry->sector - sector;
|
||||||
sector += secs_to_write;
|
|
||||||
numSectors -= secs_to_write;
|
|
||||||
|
|
||||||
entry->dirty = true;
|
_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;
|
||||||
|
|
||||||
|
if(secs_to_write>numSectors) secs_to_write = numSectors;
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user