forked from espressif/esp-idf
Merge branch 'fix/fatfs_rw_mount_ro_image' into 'master'
feat(storage/fatfs): increase log legibility for fatfs mount Closes IDF-12569 See merge request espressif/esp-idf!37407
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -81,14 +81,38 @@ vfs_fat_spiflash_ctx_t* get_vfs_fat_spiflash_ctx(wl_handle_t wlhandle)
|
|||||||
static esp_err_t s_f_mount_rw(FATFS *fs, const char *drv, const esp_vfs_fat_mount_config_t *mount_config, vfs_fat_x_ctx_flags_t *out_flags, size_t sec_num)
|
static esp_err_t s_f_mount_rw(FATFS *fs, const char *drv, const esp_vfs_fat_mount_config_t *mount_config, vfs_fat_x_ctx_flags_t *out_flags, size_t sec_num)
|
||||||
{
|
{
|
||||||
FRESULT fresult = f_mount(fs, drv, 1);
|
FRESULT fresult = f_mount(fs, drv, 1);
|
||||||
if (fresult != FR_OK) {
|
if (fresult == FR_OK) {
|
||||||
ESP_LOGW(TAG, "f_mount failed (%d)", fresult);
|
if (out_flags) {
|
||||||
|
*out_flags &= ~FORMATTED_DURING_LAST_MOUNT; // reset flag
|
||||||
|
}
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
bool need_mount_again = (fresult == FR_NO_FILESYSTEM || fresult == FR_INT_ERR) && mount_config->format_if_mount_failed;
|
const char *msg = "Unknown";
|
||||||
if (!need_mount_again) {
|
const char *note = "";
|
||||||
|
bool recoverable = false;
|
||||||
|
|
||||||
|
switch (fresult) {
|
||||||
|
case FR_NO_FILESYSTEM:
|
||||||
|
msg = "No filesystem detected";
|
||||||
|
note = "(This may indicate corrupt FS, or attempt to mount read-only fatfsgen image for write)";
|
||||||
|
recoverable = true;
|
||||||
|
break;
|
||||||
|
case FR_INT_ERR:
|
||||||
|
msg = "Assertion failed";
|
||||||
|
recoverable = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!recoverable || !mount_config->format_if_mount_failed) {
|
||||||
|
ESP_LOGE(TAG, "f_mount failed with error: \"%s\" [%d]. %s", msg, fresult, note);
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ESP_LOGW(TAG, "FatFS mount (f_mount) failed with error: \"%s\" [%d]. Retrying after format...", msg, fresult);
|
||||||
|
|
||||||
const size_t workbuf_size = 4096;
|
const size_t workbuf_size = 4096;
|
||||||
void *workbuf = ff_memalloc(workbuf_size);
|
void *workbuf = ff_memalloc(workbuf_size);
|
||||||
if (workbuf == NULL) {
|
if (workbuf == NULL) {
|
||||||
@@ -116,11 +140,7 @@ static esp_err_t s_f_mount_rw(FATFS *fs, const char *drv, const esp_vfs_fat_moun
|
|||||||
ESP_LOGI(TAG, "Mounting again");
|
ESP_LOGI(TAG, "Mounting again");
|
||||||
fresult = f_mount(fs, drv, 1);
|
fresult = f_mount(fs, drv, 1);
|
||||||
ESP_RETURN_ON_FALSE(fresult == FR_OK, ESP_FAIL, TAG, "f_mount failed after formatting (%d)", fresult);
|
ESP_RETURN_ON_FALSE(fresult == FR_OK, ESP_FAIL, TAG, "f_mount failed after formatting (%d)", fresult);
|
||||||
} else {
|
|
||||||
if (out_flags) {
|
|
||||||
*out_flags &= ~FORMATTED_DURING_LAST_MOUNT; // reset flag
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user