From 006cd2af8832771b3a21bd49907daa505e6ee59a Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Wed, 17 Oct 2018 13:01:28 +0200 Subject: [PATCH 1/4] spiffs autoformat selector (true by default) --- cores/esp8266/Esp.cpp | 10 ++++++++++ cores/esp8266/Esp.h | 3 +++ cores/esp8266/spiffs_api.h | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/cores/esp8266/Esp.cpp b/cores/esp8266/Esp.cpp index 42715605c1..c23282fb41 100644 --- a/cores/esp8266/Esp.cpp +++ b/cores/esp8266/Esp.cpp @@ -574,3 +574,13 @@ String EspClass::getSketchMD5() result = md5.toString(); return result; } + +bool _spiffsAutoFormat = true; + +void EspClass::setAutoFormatSPIFFS (bool autoFormat) { + _spiffsAutoFormat = autoFormat; +} + +bool EspClass::getAutoFormatSPIFFS () { + return _spiffsAutoFormat; +} diff --git a/cores/esp8266/Esp.h b/cores/esp8266/Esp.h index b2ee09144b..09ed49e199 100644 --- a/cores/esp8266/Esp.h +++ b/cores/esp8266/Esp.h @@ -153,6 +153,9 @@ class EspClass { bool eraseConfig(); inline uint32_t getCycleCount(); + + bool getAutoFormatSPIFFS (); + void setAutoFormatSPIFFS (bool autoFormat); }; uint32_t EspClass::getCycleCount() diff --git a/cores/esp8266/spiffs_api.h b/cores/esp8266/spiffs_api.h index 4ce8d3e6ba..264aaa6b92 100644 --- a/cores/esp8266/spiffs_api.h +++ b/cores/esp8266/spiffs_api.h @@ -32,6 +32,7 @@ #include "spiffs/spiffs.h" #include "debug.h" #include "flash_utils.h" +#include "Esp.h" // ESP.getAutoFormatSPIFFS() using namespace fs; @@ -124,6 +125,9 @@ class SPIFFSImpl : public FSImpl if (_tryMount()) { return true; } + if (!ESP.getAutoFormatSPIFFS()) { + return false; + } auto rc = SPIFFS_format(&_fs); if (rc != SPIFFS_OK) { DEBUGV("SPIFFS_format: rc=%d, err=%d\r\n", rc, _fs.err_code); From a52d5e6f8e2027ee3776d085e2e62dd66aef1faa Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Wed, 17 Oct 2018 13:04:03 +0200 Subject: [PATCH 2/4] colors --- libraries/esp8266/keywords.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/esp8266/keywords.txt b/libraries/esp8266/keywords.txt index f6bb96b5d7..55c0303c9f 100644 --- a/libraries/esp8266/keywords.txt +++ b/libraries/esp8266/keywords.txt @@ -60,6 +60,8 @@ getResetInfo KEYWORD2 getResetInfoPtr KEYWORD2 eraseConfig KEYWORD2 getCycleCount KEYWORD2 +setAutoFormatSPIFFS KEYWORD2 +getAutoFormatSPIFFS KEYWORD2 ####################################### # Constants (LITERAL1) From cad852b89b5ebfa60ede1deb0384358d33a1a4c0 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Wed, 17 Oct 2018 13:17:27 +0200 Subject: [PATCH 3/4] doc --- doc/filesystem.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/filesystem.rst b/doc/filesystem.rst index 3e6fdeffbf..3f975ab5ae 100644 --- a/doc/filesystem.rst +++ b/doc/filesystem.rst @@ -136,6 +136,10 @@ This method mounts SPIFFS file system. It must be called before any other FS APIs are used. Returns *true* if file system was mounted successfully, false otherwise. +This will by default format filesystem when SPIFFS is used the first time. +Note that this can be disabled with a call to +``ESP.setAutoFormatSPIFFS(false);`` prior to ``SPIFFS.begin()``. + end ~~~ From 42eb24e732fdb2307601aaa262131d442f204535 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Wed, 17 Oct 2018 22:45:54 +0200 Subject: [PATCH 4/4] move variable, fix host test --- cores/esp8266/Esp.cpp | 4 +--- cores/esp8266/coredecls.h | 1 + cores/esp8266/spiffs_api.cpp | 2 ++ cores/esp8266/spiffs_api.h | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cores/esp8266/Esp.cpp b/cores/esp8266/Esp.cpp index c23282fb41..3f7aca01b5 100644 --- a/cores/esp8266/Esp.cpp +++ b/cores/esp8266/Esp.cpp @@ -25,7 +25,7 @@ #include "interrupts.h" #include "MD5Builder.h" #include "umm_malloc/umm_malloc.h" -#include "cont.h" +#include "coredecls.h" extern "C" { #include "user_interface.h" @@ -575,8 +575,6 @@ String EspClass::getSketchMD5() return result; } -bool _spiffsAutoFormat = true; - void EspClass::setAutoFormatSPIFFS (bool autoFormat) { _spiffsAutoFormat = autoFormat; } diff --git a/cores/esp8266/coredecls.h b/cores/esp8266/coredecls.h index 3ac87eee9f..ff7d02e075 100644 --- a/cores/esp8266/coredecls.h +++ b/cores/esp8266/coredecls.h @@ -12,6 +12,7 @@ extern "C" { #include // g_pcont declaration extern bool timeshift64_is_set; +extern bool _spiffsAutoFormat; void esp_yield(); void esp_schedule(); diff --git a/cores/esp8266/spiffs_api.cpp b/cores/esp8266/spiffs_api.cpp index 390a6412fd..85ef8b3583 100644 --- a/cores/esp8266/spiffs_api.cpp +++ b/cores/esp8266/spiffs_api.cpp @@ -23,6 +23,8 @@ */ #include "spiffs_api.h" +bool _spiffsAutoFormat = true; + using namespace fs; FileImplPtr SPIFFSImpl::open(const char* path, OpenMode openMode, AccessMode accessMode) diff --git a/cores/esp8266/spiffs_api.h b/cores/esp8266/spiffs_api.h index 264aaa6b92..7228af3970 100644 --- a/cores/esp8266/spiffs_api.h +++ b/cores/esp8266/spiffs_api.h @@ -32,7 +32,7 @@ #include "spiffs/spiffs.h" #include "debug.h" #include "flash_utils.h" -#include "Esp.h" // ESP.getAutoFormatSPIFFS() +#include "coredecls.h" // _spiffsAutoFormat using namespace fs; @@ -125,7 +125,7 @@ class SPIFFSImpl : public FSImpl if (_tryMount()) { return true; } - if (!ESP.getAutoFormatSPIFFS()) { + if (!_spiffsAutoFormat) { return false; } auto rc = SPIFFS_format(&_fs);