Skip to content

Commit c13bb1e

Browse files
Make multiple SDFS/LittleFS.begin calls noops (earlephilhower#262)
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().
1 parent c777dd1 commit c13bb1e

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
@@ -176,6 +176,9 @@ class LittleFSImpl : public FSImpl {
176176
}
177177

178178
bool begin() override {
179+
if (_mounted) {
180+
return true;
181+
}
179182
if (_size <= 0) {
180183
DEBUGV("LittleFS size is <= zero");
181184
return false;

libraries/SDFS/src/SDFS.h

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

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

0 commit comments

Comments
 (0)