Skip to content

Commit 4bd0913

Browse files
authored
Merge pull request #238 from jeremypoulter/littlefs_format_fix
Unmount the FS before formatting
2 parents f42cf4b + affe391 commit 4bd0913

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

libraries/FileSystem/src/InternalFS.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ LittleFS::LittleFS (void)
193193
_lfs_cfg.lookahead = 128;
194194

195195
_begun = false;
196+
_mounted = false;
196197
}
197198

198199
LittleFS::~LittleFS ()
@@ -212,6 +213,8 @@ bool LittleFS::begin (void)
212213
{
213214
LOG_LV1("IFLASH", "Format internal file system");
214215
this->format(false);
216+
} else {
217+
_mounted = true;
215218
}
216219

217220
return true;
@@ -226,10 +229,14 @@ bool LittleFS::format (bool eraseall)
226229
flash_nrf5x_erase(addr);
227230
}
228231
}
229-
232+
if(_mounted) {
233+
VERIFY_LFS(lfs_unmount(&_lfs), false);
234+
}
230235
VERIFY_LFS(lfs_format(&_lfs, &_lfs_cfg), false);
231236
VERIFY_LFS(lfs_mount(&_lfs, &_lfs_cfg), false);
232237

238+
_mounted = true;
239+
233240
return true;
234241
}
235242

libraries/FileSystem/src/InternalFS.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class LittleFS: public BluefruitFS::FileSystemClass
7474
struct lfs_config _lfs_cfg;
7575
lfs_t _lfs;
7676
bool _begun;
77+
bool _mounted;
7778

7879
BluefruitFS::File _open_file (char const *filepath, uint8_t mode);
7980
BluefruitFS::File _open_dir (char const *filepath);

0 commit comments

Comments
 (0)