fix: reduce file system corruption from standalone Lua scripts (#5148)

Standalone Lua such as the DSM Forward Programming tool do a lot of file
system writing (logging) and appears to overrun some buffer in FafFs,
writing file data right into the FAT, thus corrupting the file system. 

Using FF_FS_TINY=1 seems to mitigate this significantly, but does not 
appear to completely resolve this.
This commit is contained in:
3djc
2024-06-21 10:09:09 +10:00
committed by GitHub
parent b8dc50562e
commit 1867e730b5
2 changed files with 10 additions and 16 deletions
@@ -270,15 +270,12 @@ static DRESULT sdio_read(BYTE lun, BYTE * buff, DWORD sector, UINT count)
res = _read_dma(buff, sector, count);
if (res != RES_OK) return res;
uint32_t timeout = HAL_GetTick();
while((HAL_GetTick() - timeout) < SD_TIMEOUT) {
if (sdio_check_card_state() == SD_TRANSFER_OK) {
return RES_OK;
}
if (sdio_check_card_state_with_timeout(SD_TIMEOUT) < 0) {
TRACE("SD getstatus timeout, s:%u c:%u", sector, (uint32_t)count);
return RES_ERROR;
}
TRACE("SD getstatus timeout, s:%u c:%u", sector, (uint32_t)count);
return RES_ERROR;
return RES_OK;
}
static DRESULT _write_dma(const BYTE *buff, DWORD sector, UINT count)
@@ -329,16 +326,13 @@ static DRESULT sdio_write(BYTE lun, const BYTE *buff, DWORD sector, UINT count)
res = _write_dma(buff, sector, count);
if (res != RES_OK) return res;
uint32_t timeout = HAL_GetTick();
while((HAL_GetTick() - timeout) < SD_TIMEOUT) {
if (sdio_check_card_state() == SD_TRANSFER_OK) {
return RES_OK;
}
if (sdio_check_card_state_with_timeout(SD_TIMEOUT) < 0) {
TRACE("SD getstatus timeout, s:%u c: %u", sector, (uint32_t)count);
return RES_ERROR;
}
TRACE("SD getstatus timeout, s:%u c: %u", sector, (uint32_t)count);
return RES_ERROR;
return RES_OK;
}
static DRESULT sdio_get_sector_count(DWORD* sectors)
+1 -1
View File
@@ -235,7 +235,7 @@
/ System Configurations
/---------------------------------------------------------------------------*/
#define FF_FS_TINY 0
#define FF_FS_TINY 1
/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny)
/ At the tiny configuration, size of file object (FIL) is shrinked FF_MAX_SS bytes.
/ Instead of private sector buffer eliminated from the file object, common sector