Skip to content

spiffs auto format selector (true by default) #5255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion cores/esp8266/Esp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -574,3 +574,11 @@ String EspClass::getSketchMD5()
result = md5.toString();
return result;
}

void EspClass::setAutoFormatSPIFFS (bool autoFormat) {
_spiffsAutoFormat = autoFormat;
}

bool EspClass::getAutoFormatSPIFFS () {
return _spiffsAutoFormat;
}
3 changes: 3 additions & 0 deletions cores/esp8266/Esp.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ class EspClass {
bool eraseConfig();

inline uint32_t getCycleCount();

bool getAutoFormatSPIFFS ();
void setAutoFormatSPIFFS (bool autoFormat);
};

uint32_t EspClass::getCycleCount()
Expand Down
1 change: 1 addition & 0 deletions cores/esp8266/coredecls.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ extern "C" {
#include <cont.h> // g_pcont declaration

extern bool timeshift64_is_set;
extern bool _spiffsAutoFormat;

void esp_yield();
void esp_schedule();
Expand Down
2 changes: 2 additions & 0 deletions cores/esp8266/spiffs_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
#include "spiffs_api.h"

bool _spiffsAutoFormat = true;

using namespace fs;

FileImplPtr SPIFFSImpl::open(const char* path, OpenMode openMode, AccessMode accessMode)
Expand Down
4 changes: 4 additions & 0 deletions cores/esp8266/spiffs_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "spiffs/spiffs.h"
#include "debug.h"
#include "flash_utils.h"
#include "coredecls.h" // _spiffsAutoFormat

using namespace fs;

Expand Down Expand Up @@ -124,6 +125,9 @@ class SPIFFSImpl : public FSImpl
if (_tryMount()) {
return true;
}
if (!_spiffsAutoFormat) {
return false;
}
auto rc = SPIFFS_format(&_fs);
if (rc != SPIFFS_OK) {
DEBUGV("SPIFFS_format: rc=%d, err=%d\r\n", rc, _fs.err_code);
Expand Down
4 changes: 4 additions & 0 deletions doc/filesystem.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~

Expand Down
2 changes: 2 additions & 0 deletions libraries/esp8266/keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ getResetInfo KEYWORD2
getResetInfoPtr KEYWORD2
eraseConfig KEYWORD2
getCycleCount KEYWORD2
setAutoFormatSPIFFS KEYWORD2
getAutoFormatSPIFFS KEYWORD2

#######################################
# Constants (LITERAL1)
Expand Down