Merge branch 'bugfix/fatfs_sdmmc_cleanup' into 'master'
fat/sdmmc: unmount FATFS object on error Failure to call f_mount(NULL,...) makes FATFS attempt to clean up the old FS object upon next mount. If previous mount operation has failed, some parts of FS object may not be fully initialized, which will cause errors (such as attempting to delete a mutex which wasn’t allocated). Fixes TW11594. See merge request !679
This commit is contained in:
commit
937940c989
1 changed files with 4 additions and 1 deletions
|
@ -34,6 +34,7 @@ esp_err_t esp_vfs_fat_sdmmc_mount(const char* base_path,
|
||||||
{
|
{
|
||||||
const size_t workbuf_size = 4096;
|
const size_t workbuf_size = 4096;
|
||||||
void* workbuf = NULL;
|
void* workbuf = NULL;
|
||||||
|
FATFS* fs = NULL;
|
||||||
|
|
||||||
if (s_card != NULL) {
|
if (s_card != NULL) {
|
||||||
return ESP_ERR_INVALID_STATE;
|
return ESP_ERR_INVALID_STATE;
|
||||||
|
@ -82,7 +83,6 @@ esp_err_t esp_vfs_fat_sdmmc_mount(const char* base_path,
|
||||||
char drv[3] = {(char)('0' + pdrv), ':', 0};
|
char drv[3] = {(char)('0' + pdrv), ':', 0};
|
||||||
|
|
||||||
// connect FATFS to VFS
|
// connect FATFS to VFS
|
||||||
FATFS* fs;
|
|
||||||
err = esp_vfs_fat_register(base_path, drv, mount_config->max_files, &fs);
|
err = esp_vfs_fat_register(base_path, drv, mount_config->max_files, &fs);
|
||||||
if (err == ESP_ERR_INVALID_STATE) {
|
if (err == ESP_ERR_INVALID_STATE) {
|
||||||
// it's okay, already registered with VFS
|
// it's okay, already registered with VFS
|
||||||
|
@ -129,6 +129,9 @@ esp_err_t esp_vfs_fat_sdmmc_mount(const char* base_path,
|
||||||
fail:
|
fail:
|
||||||
sdmmc_host_deinit();
|
sdmmc_host_deinit();
|
||||||
free(workbuf);
|
free(workbuf);
|
||||||
|
if (fs) {
|
||||||
|
f_mount(NULL, drv, 0);
|
||||||
|
}
|
||||||
esp_vfs_fat_unregister_path(base_path);
|
esp_vfs_fat_unregister_path(base_path);
|
||||||
ff_diskio_unregister(pdrv);
|
ff_diskio_unregister(pdrv);
|
||||||
free(s_card);
|
free(s_card);
|
||||||
|
|
Loading…
Reference in a new issue