mirror of
https://github.com/opentx/opentx.git
synced 2025-07-15 04:15:26 +03:00
[Horus] Attempt to fix the problem with some files after a massstorage session
This commit is contained in:
parent
76f0b306aa
commit
4221bfdf74
3 changed files with 30 additions and 11 deletions
|
@ -71,6 +71,11 @@ void DiskCacheBlock::free(DWORD sector, UINT count)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DiskCacheBlock::free()
|
||||||
|
{
|
||||||
|
endSector = 0;
|
||||||
|
}
|
||||||
|
|
||||||
bool DiskCacheBlock::empty() const
|
bool DiskCacheBlock::empty() const
|
||||||
{
|
{
|
||||||
return (endSector == 0);
|
return (endSector == 0);
|
||||||
|
@ -84,6 +89,16 @@ DiskCache::DiskCache():
|
||||||
blocks = new DiskCacheBlock[DISK_CACHE_BLOCKS_NUM];
|
blocks = new DiskCacheBlock[DISK_CACHE_BLOCKS_NUM];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DiskCache::clear()
|
||||||
|
{
|
||||||
|
lastBlock = 0;
|
||||||
|
stats.noHits = 0;
|
||||||
|
stats.noMisses = 0;
|
||||||
|
for (int n=0; n<DISK_CACHE_BLOCKS_NUM; ++n) {
|
||||||
|
blocks[n].free();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
DRESULT DiskCache::read(BYTE drv, BYTE * buff, DWORD sector, UINT count)
|
DRESULT DiskCache::read(BYTE drv, BYTE * buff, DWORD sector, UINT count)
|
||||||
{
|
{
|
||||||
// TODO: check if not caching first sectors would improve anything
|
// TODO: check if not caching first sectors would improve anything
|
||||||
|
|
|
@ -37,6 +37,7 @@ public:
|
||||||
bool read(BYTE* buff, DWORD sector, UINT count);
|
bool read(BYTE* buff, DWORD sector, UINT count);
|
||||||
DRESULT fill(BYTE drv, BYTE* buff, DWORD sector, UINT count);
|
DRESULT fill(BYTE drv, BYTE* buff, DWORD sector, UINT count);
|
||||||
void free(DWORD sector, UINT count);
|
void free(DWORD sector, UINT count);
|
||||||
|
void free();
|
||||||
bool empty() const;
|
bool empty() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -53,14 +54,15 @@ struct DiskCacheStats
|
||||||
|
|
||||||
class DiskCache
|
class DiskCache
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DiskCache();
|
DiskCache();
|
||||||
|
|
||||||
DRESULT read(BYTE drv, BYTE* buff, DWORD sector, UINT count);
|
DRESULT read(BYTE drv, BYTE* buff, DWORD sector, UINT count);
|
||||||
DRESULT write(BYTE drv, const BYTE* buff, DWORD sector, UINT count);
|
DRESULT write(BYTE drv, const BYTE* buff, DWORD sector, UINT count);
|
||||||
const DiskCacheStats & getStats() const;
|
const DiskCacheStats & getStats() const;
|
||||||
int getHitRate() const;
|
int getHitRate() const;
|
||||||
private:
|
void clear();
|
||||||
|
|
||||||
|
private:
|
||||||
DiskCacheStats stats;
|
DiskCacheStats stats;
|
||||||
uint32_t lastBlock;
|
uint32_t lastBlock;
|
||||||
DiskCacheBlock * blocks;
|
DiskCacheBlock * blocks;
|
||||||
|
|
|
@ -308,6 +308,8 @@ void sdMount()
|
||||||
{
|
{
|
||||||
TRACE("sdMount");
|
TRACE("sdMount");
|
||||||
|
|
||||||
|
diskCache.clear();
|
||||||
|
|
||||||
if (f_mount(&g_FATFS_Obj, "", 1) == FR_OK) {
|
if (f_mount(&g_FATFS_Obj, "", 1) == FR_OK) {
|
||||||
// call sdGetFreeSectors() now because f_getfree() takes a long time first time it's called
|
// call sdGetFreeSectors() now because f_getfree() takes a long time first time it's called
|
||||||
sdGetFreeSectors();
|
sdGetFreeSectors();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue