diff --git a/libraries/FileSystem/src/InternalFS.cpp b/libraries/FileSystem/src/InternalFS.cpp index 0bf356c9..e580569b 100644 --- a/libraries/FileSystem/src/InternalFS.cpp +++ b/libraries/FileSystem/src/InternalFS.cpp @@ -193,6 +193,7 @@ LittleFS::LittleFS (void) _lfs_cfg.lookahead = 128; _begun = false; + _mounted = false; } LittleFS::~LittleFS () @@ -212,6 +213,8 @@ bool LittleFS::begin (void) { LOG_LV1("IFLASH", "Format internal file system"); this->format(false); + } else { + _mounted = true; } return true; @@ -226,10 +229,14 @@ bool LittleFS::format (bool eraseall) flash_nrf5x_erase(addr); } } - + if(_mounted) { + VERIFY_LFS(lfs_unmount(&_lfs), false); + } VERIFY_LFS(lfs_format(&_lfs, &_lfs_cfg), false); VERIFY_LFS(lfs_mount(&_lfs, &_lfs_cfg), false); + _mounted = true; + return true; } diff --git a/libraries/FileSystem/src/InternalFS.h b/libraries/FileSystem/src/InternalFS.h index 153bb423..248bd9e8 100644 --- a/libraries/FileSystem/src/InternalFS.h +++ b/libraries/FileSystem/src/InternalFS.h @@ -74,6 +74,7 @@ class LittleFS: public BluefruitFS::FileSystemClass struct lfs_config _lfs_cfg; lfs_t _lfs; bool _begun; + bool _mounted; BluefruitFS::File _open_file (char const *filepath, uint8_t mode); BluefruitFS::File _open_dir (char const *filepath);