Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed FFat::end. Fixes #3244 #3245

Merged
merged 3 commits into from
Sep 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions libraries/FFat/src/FFat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,20 @@ const esp_partition_t *check_ffat_partition(const char* label)

bool F_Fat::begin(bool formatOnFail, const char * basePath, uint8_t maxOpenFiles, const char * partitionLabel)
{
if(_wl_handle){
if(_wl_handle != WL_INVALID_HANDLE){
log_w("Already Mounted!");
return true;
lbernstone marked this conversation as resolved.
Show resolved Hide resolved
}

if (!check_ffat_partition(partitionLabel)) return false;
if (!check_ffat_partition(partitionLabel)){
log_e("No fat partition found on flash");
return false;
}

esp_vfs_fat_mount_config_t conf = {
.format_if_mount_failed = formatOnFail,
.max_files = maxOpenFiles
.max_files = maxOpenFiles,
.allocation_unit_size = CONFIG_WL_SECTOR_SIZE
};
esp_err_t err = esp_vfs_fat_spiflash_mount(basePath, partitionLabel, &conf, &_wl_handle);
if(err){
Expand All @@ -62,13 +66,13 @@ bool F_Fat::begin(bool formatOnFail, const char * basePath, uint8_t maxOpenFiles

void F_Fat::end()
{
if(_wl_handle){
if(_wl_handle != WL_INVALID_HANDLE){
esp_err_t err = esp_vfs_fat_spiflash_unmount(_impl->mountpoint(), _wl_handle);
if(err){
log_e("Unmounting FFat partition failed! Error: %d", err);
return;
}
_wl_handle = 0;
_wl_handle = WL_INVALID_HANDLE;
_impl->mountpoint(NULL);
}
}
Expand All @@ -77,7 +81,7 @@ bool F_Fat::format(bool full_wipe, char* partitionLabel)
{
esp_err_t result;
bool res = true;
if(_wl_handle){
if(_wl_handle != WL_INVALID_HANDLE){
log_w("Already Mounted!");
return false;
}
Expand All @@ -102,7 +106,8 @@ bool F_Fat::format(bool full_wipe, char* partitionLabel)
// Now do a mount with format_if_fail (which it will)
esp_vfs_fat_mount_config_t conf = {
.format_if_mount_failed = true,
.max_files = 1
.max_files = 1,
.allocation_unit_size = CONFIG_WL_SECTOR_SIZE
};
result = esp_vfs_fat_spiflash_mount("/format_ffat", partitionLabel, &conf, &temp_handle);
esp_vfs_fat_spiflash_unmount("/format_ffat", temp_handle);
Expand Down
2 changes: 1 addition & 1 deletion libraries/FFat/src/FFat.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class F_Fat : public FS
bool exists(const String& path);

private:
wl_handle_t _wl_handle;
wl_handle_t _wl_handle = WL_INVALID_HANDLE;
};

}
Expand Down