Skip to content

Commit

Permalink
Make multiple FS begin calls noops() SDFS/LittleFS (#8235)
Browse files Browse the repository at this point in the history
When LittleFS.begin() or SDFS.begin() is called after the filesystem is
already mounted, don't unmount/remount.  When an unmount happens, all old
Files become invalid (but the core doesn't know this), so you would end
up with random crashes in FS code.

Now, check for _mounted, and if so just return immediately from begin().
This mimics the original SPIFFS code.

Fixes earlephilhower/ESP8266Audio#407
  • Loading branch information
earlephilhower authored Jul 26, 2021
1 parent cfb6d50 commit f908460
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions libraries/LittleFS/src/LittleFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ class LittleFSImpl : public FSImpl
}

bool begin() override {
if (_mounted) {
return true;
}
if ((_blockSize <= 0) || (_size <= 0)) {
DEBUGV("LittleFS size is <= zero");
return false;
Expand Down
2 changes: 1 addition & 1 deletion libraries/SDFS/src/SDFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class SDFSImpl : public FSImpl

bool begin() override {
if (_mounted) {
end();
return true;
}
_mounted = _fs.begin(_cfg._csPin, _cfg._spiSettings);
if (!_mounted && _cfg._autoFormat) {
Expand Down

0 comments on commit f908460

Please sign in to comment.