From d7c6c5e949c83241fc107593ac63174cb78354cf Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Fri, 23 Jul 2021 12:52:47 -0700 Subject: [PATCH] Make multiple FS begin calls noops() SDFS/LittleFS 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 https://github.com/earlephilhower/ESP8266Audio/issues/407 --- libraries/LittleFS/src/LittleFS.h | 3 +++ libraries/SDFS/src/SDFS.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/libraries/LittleFS/src/LittleFS.h b/libraries/LittleFS/src/LittleFS.h index 162b6729b5..65d70aac32 100644 --- a/libraries/LittleFS/src/LittleFS.h +++ b/libraries/LittleFS/src/LittleFS.h @@ -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; diff --git a/libraries/SDFS/src/SDFS.h b/libraries/SDFS/src/SDFS.h index 8a5c0ff52b..2bc1dc972c 100644 --- a/libraries/SDFS/src/SDFS.h +++ b/libraries/SDFS/src/SDFS.h @@ -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) {