Skip to content

Commit f908460

Browse files
Make multiple FS begin calls noops() SDFS/LittleFS (#8235)
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
1 parent cfb6d50 commit f908460

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

libraries/LittleFS/src/LittleFS.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ class LittleFSImpl : public FSImpl
183183
}
184184

185185
bool begin() override {
186+
if (_mounted) {
187+
return true;
188+
}
186189
if ((_blockSize <= 0) || (_size <= 0)) {
187190
DEBUGV("LittleFS size is <= zero");
188191
return false;

libraries/SDFS/src/SDFS.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class SDFSImpl : public FSImpl
149149

150150
bool begin() override {
151151
if (_mounted) {
152-
end();
152+
return true;
153153
}
154154
_mounted = _fs.begin(_cfg._csPin, _cfg._spiSettings);
155155
if (!_mounted && _cfg._autoFormat) {

0 commit comments

Comments
 (0)