fatfs: handle FR_INT_ERR as "filesystem corrupted"

FatFS library can sometimes return FR_INT_ERR if the filesystem is
corrupted. Propagate the error from VFS functions instead of
asserting, so that the application can handle the error. Also handle
the error during initialization of FatFS and format the filesystem if
it occurs.
This commit is contained in:
Ivan Grokhotkov 2019-08-26 17:00:24 +02:00
parent d9c02bc36c
commit 1b24b3663e
3 changed files with 5 additions and 5 deletions

View file

@ -255,9 +255,7 @@ static int fresult_to_errno(FRESULT fr)
{
switch(fr) {
case FR_DISK_ERR: return EIO;
case FR_INT_ERR:
assert(0 && "fatfs internal error");
return EIO;
case FR_INT_ERR: return EIO;
case FR_NOT_READY: return ENODEV;
case FR_NO_FILE: return ENOENT;
case FR_NO_PATH: return ENOENT;

View file

@ -111,7 +111,8 @@ esp_err_t esp_vfs_fat_sdmmc_mount(const char* base_path,
if (res != FR_OK) {
err = ESP_FAIL;
ESP_LOGW(TAG, "failed to mount card (%d)", res);
if (!(res == FR_NO_FILESYSTEM && mount_config->format_if_mount_failed)) {
if (!((res == FR_NO_FILESYSTEM || res == FR_INT_ERR)
&& mount_config->format_if_mount_failed)) {
goto fail;
}
ESP_LOGW(TAG, "partitioning card");

View file

@ -76,7 +76,8 @@ esp_err_t esp_vfs_fat_spiflash_mount(const char* base_path,
FRESULT fresult = f_mount(fs, drv, 1);
if (fresult != FR_OK) {
ESP_LOGW(TAG, "f_mount failed (%d)", fresult);
if (!(fresult == FR_NO_FILESYSTEM && mount_config->format_if_mount_failed)) {
if (!((fresult == FR_NO_FILESYSTEM || fresult == FR_INT_ERR)
&& mount_config->format_if_mount_failed)) {
result = ESP_FAIL;
goto fail;
}