From f9084603de5556b29281c8ca26576addc336806f Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Mon, 26 Jul 2021 12:58:40 -0700 Subject: [PATCH] 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 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 162b6729b..65d70aac3 100644 --- a/libraries/LittleFS/src/LittleFS.h +++ b/libraries/LittleFS/src/LittleFS.h @@ -183,6 +183,9 @@ public: } 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 8a5c0ff52..2bc1dc972 100644 --- a/libraries/SDFS/src/SDFS.h +++ b/libraries/SDFS/src/SDFS.h @@ -149,7 +149,7 @@ public: bool begin() override { if (_mounted) { - end(); + return true; } _mounted = _fs.begin(_cfg._csPin, _cfg._spiSettings); if (!_mounted && _cfg._autoFormat) {