fatfs: raw diskio: Fixed handling read-only filesystem

ff_ routines incorrectly reported disk state and caused whole fatfs
to lock-up when trying to write to read-only device.

Signed-off-by: Michal Jenikovsky <jendo@jmsystems.sk>
This commit is contained in:
Michal Jenikovsky
2023-08-10 11:56:02 +02:00
committed by Adam Múdry
parent 31b4b0a8d4
commit 1f6f5396f4

View File

@ -18,6 +18,7 @@ static const esp_partition_t* s_ff_raw_handles[FF_VOLUMES];
// Determine the sector size and sector count by parsing the boot sector // Determine the sector size and sector count by parsing the boot sector
static size_t s_sector_size[FF_VOLUMES]; static size_t s_sector_size[FF_VOLUMES];
static size_t s_sectors_count[FF_VOLUMES]; static size_t s_sectors_count[FF_VOLUMES];
static uint8_t s_initialized[FF_VOLUMES];
#define BPB_BytsPerSec 11 #define BPB_BytsPerSec 11
#define BPB_TotSec16 19 #define BPB_TotSec16 19
@ -56,12 +57,17 @@ DSTATUS ff_raw_initialize (BYTE pdrv)
s_sectors_count[pdrv] = sectors_count_tmp_32; s_sectors_count[pdrv] = sectors_count_tmp_32;
} }
return 0; s_initialized[pdrv] = true;
return STA_PROTECT;
} }
DSTATUS ff_raw_status (BYTE pdrv) DSTATUS ff_raw_status (BYTE pdrv)
{ {
return 0; DSTATUS status = STA_PROTECT;
if (!s_initialized[pdrv]) {
status |= STA_NOINIT | STA_NODISK;
}
return status;
} }
DRESULT ff_raw_read (BYTE pdrv, BYTE *buff, DWORD sector, UINT count) DRESULT ff_raw_read (BYTE pdrv, BYTE *buff, DWORD sector, UINT count)
@ -80,7 +86,7 @@ DRESULT ff_raw_read (BYTE pdrv, BYTE *buff, DWORD sector, UINT count)
DRESULT ff_raw_write (BYTE pdrv, const BYTE *buff, DWORD sector, UINT count) DRESULT ff_raw_write (BYTE pdrv, const BYTE *buff, DWORD sector, UINT count)
{ {
return RES_ERROR; return RES_WRPRT;
} }
DRESULT ff_raw_ioctl (BYTE pdrv, BYTE cmd, void *buff) DRESULT ff_raw_ioctl (BYTE pdrv, BYTE cmd, void *buff)