Skip to content

Commit ca88fdc

Browse files
lbernstoneme-no-dev
authored andcommitted
Fixed FFat::end. Fixes #3244 (#3245)
* Fixed FFat::end. Fixes #3244 * Missed the handle check in format
1 parent f32083a commit ca88fdc

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

libraries/FFat/src/FFat.cpp

+12-7
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,20 @@ const esp_partition_t *check_ffat_partition(const char* label)
4040

4141
bool F_Fat::begin(bool formatOnFail, const char * basePath, uint8_t maxOpenFiles, const char * partitionLabel)
4242
{
43-
if(_wl_handle){
43+
if(_wl_handle != WL_INVALID_HANDLE){
4444
log_w("Already Mounted!");
4545
return true;
4646
}
4747

48-
if (!check_ffat_partition(partitionLabel)) return false;
48+
if (!check_ffat_partition(partitionLabel)){
49+
log_e("No fat partition found on flash");
50+
return false;
51+
}
4952

5053
esp_vfs_fat_mount_config_t conf = {
5154
.format_if_mount_failed = formatOnFail,
52-
.max_files = maxOpenFiles
55+
.max_files = maxOpenFiles,
56+
.allocation_unit_size = CONFIG_WL_SECTOR_SIZE
5357
};
5458
esp_err_t err = esp_vfs_fat_spiflash_mount(basePath, partitionLabel, &conf, &_wl_handle);
5559
if(err){
@@ -62,13 +66,13 @@ bool F_Fat::begin(bool formatOnFail, const char * basePath, uint8_t maxOpenFiles
6266

6367
void F_Fat::end()
6468
{
65-
if(_wl_handle){
69+
if(_wl_handle != WL_INVALID_HANDLE){
6670
esp_err_t err = esp_vfs_fat_spiflash_unmount(_impl->mountpoint(), _wl_handle);
6771
if(err){
6872
log_e("Unmounting FFat partition failed! Error: %d", err);
6973
return;
7074
}
71-
_wl_handle = 0;
75+
_wl_handle = WL_INVALID_HANDLE;
7276
_impl->mountpoint(NULL);
7377
}
7478
}
@@ -77,7 +81,7 @@ bool F_Fat::format(bool full_wipe, char* partitionLabel)
7781
{
7882
esp_err_t result;
7983
bool res = true;
80-
if(_wl_handle){
84+
if(_wl_handle != WL_INVALID_HANDLE){
8185
log_w("Already Mounted!");
8286
return false;
8387
}
@@ -102,7 +106,8 @@ bool F_Fat::format(bool full_wipe, char* partitionLabel)
102106
// Now do a mount with format_if_fail (which it will)
103107
esp_vfs_fat_mount_config_t conf = {
104108
.format_if_mount_failed = true,
105-
.max_files = 1
109+
.max_files = 1,
110+
.allocation_unit_size = CONFIG_WL_SECTOR_SIZE
106111
};
107112
result = esp_vfs_fat_spiflash_mount("/format_ffat", partitionLabel, &conf, &temp_handle);
108113
esp_vfs_fat_spiflash_unmount("/format_ffat", temp_handle);

libraries/FFat/src/FFat.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class F_Fat : public FS
3737
bool exists(const String& path);
3838

3939
private:
40-
wl_handle_t _wl_handle;
40+
wl_handle_t _wl_handle = WL_INVALID_HANDLE;
4141
};
4242

4343
}

0 commit comments

Comments
 (0)