From 07af6ccaac0ad870183eab11f711cb3210642bb1 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Wed, 24 Jul 2019 13:56:03 -0700 Subject: [PATCH 1/2] Add a FS::check() optional method Fixes #2634 Expose any low-level filesystem check operations for users, and add documentation on this and the gc() methods. --- cores/esp8266/FS.cpp | 7 +++++++ cores/esp8266/FS.h | 2 ++ cores/esp8266/FSImpl.h | 1 + cores/esp8266/spiffs_api.h | 5 +++++ doc/filesystem.rst | 23 +++++++++++++++++++++++ 5 files changed, 38 insertions(+) diff --git a/cores/esp8266/FS.cpp b/cores/esp8266/FS.cpp index 7006a8afaf..d7baa43069 100644 --- a/cores/esp8266/FS.cpp +++ b/cores/esp8266/FS.cpp @@ -272,6 +272,13 @@ bool FS::gc() { return _impl->gc(); } +bool FS::check() { + if (!_impl) { + return false; + } + return _impl->check(); +} + bool FS::format() { if (!_impl) { return false; diff --git a/cores/esp8266/FS.h b/cores/esp8266/FS.h index f89d343d89..669287876d 100644 --- a/cores/esp8266/FS.h +++ b/cores/esp8266/FS.h @@ -221,7 +221,9 @@ class FS bool rmdir(const char* path); bool rmdir(const String& path); + // Low-level FS routines, not needed by most applications bool gc(); + bool check(); friend class ::SDClass; // More of a frenemy, but SD needs internal implementation to get private FAT bits protected: diff --git a/cores/esp8266/FSImpl.h b/cores/esp8266/FSImpl.h index 6caea9ca2f..b7cf4a7a65 100644 --- a/cores/esp8266/FSImpl.h +++ b/cores/esp8266/FSImpl.h @@ -85,6 +85,7 @@ class FSImpl { virtual bool mkdir(const char* path) = 0; virtual bool rmdir(const char* path) = 0; virtual bool gc() { return true; } // May not be implemented in all file systems. + virtual bool check() { return true; } // May not be implemented in all file systems. }; } // namespace fs diff --git a/cores/esp8266/spiffs_api.h b/cores/esp8266/spiffs_api.h index 0491508f4d..c297d7d232 100644 --- a/cores/esp8266/spiffs_api.h +++ b/cores/esp8266/spiffs_api.h @@ -219,6 +219,11 @@ class SPIFFSImpl : public FSImpl return SPIFFS_gc_quick( &_fs, 0 ) == SPIFFS_OK; } + bool check() override + { + return SPIFFS_check(&_fs) == SPIFFS_OK; + } + protected: friend class SPIFFSFileImpl; friend class SPIFFSDirImpl; diff --git a/doc/filesystem.rst b/doc/filesystem.rst index b7d8b421ef..8a6b54f90a 100644 --- a/doc/filesystem.rst +++ b/doc/filesystem.rst @@ -402,6 +402,29 @@ block size - ``pageSize`` — filesystem logical page size - ``maxOpenFiles`` ``maxPathLength`` — max file name length (including one byte for zero termination) +gc +~~ + +.. code:: cpp + + SPIFFS.gc() + +Only implemented in SPIFFS. Performs a quick garbage collection operation on SPIFFS, +possibly making writes perform faster in the future. Not normally needed by applications +as SPIFFS will take care of things itself on writes. + +check +~~~~~ + +.. code:: cpp + + SPIFFS.begin(); + SPIFFS.check(); + +Only implemented in SPIFFS. Performs an in-depth check of the filesystem metadata and +correct what is repairable. Not normally needed, and not guaranteed to actually fix +anything should there be corruption. + Directory object (Dir) ---------------------- From a92827207ad9dfce8b844b0d1610318c74c0a643 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Fri, 26 Jul 2019 16:30:59 -0700 Subject: [PATCH 2/2] Update doc w/more gc() info and link --- doc/filesystem.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/filesystem.rst b/doc/filesystem.rst index 8a6b54f90a..a56ff8fb0d 100644 --- a/doc/filesystem.rst +++ b/doc/filesystem.rst @@ -410,8 +410,10 @@ gc SPIFFS.gc() Only implemented in SPIFFS. Performs a quick garbage collection operation on SPIFFS, -possibly making writes perform faster in the future. Not normally needed by applications -as SPIFFS will take care of things itself on writes. +possibly making writes perform faster/better in the future. On very full or very fragmented +filesystems, using this call can avoid or reduce issues where SPIFFS reports free space +but is unable to write additional data to a file. See `this discussion +` for more info. check ~~~~~