Skip to content

Commit c6bfec9

Browse files
Add a FS::check() optional method (#6340)
* 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. * Update doc w/more gc() info and link
1 parent d2fde8d commit c6bfec9

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-0
lines changed

cores/esp8266/FS.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,13 @@ bool FS::gc() {
272272
return _impl->gc();
273273
}
274274

275+
bool FS::check() {
276+
if (!_impl) {
277+
return false;
278+
}
279+
return _impl->check();
280+
}
281+
275282
bool FS::format() {
276283
if (!_impl) {
277284
return false;

cores/esp8266/FS.h

+2
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,9 @@ class FS
221221
bool rmdir(const char* path);
222222
bool rmdir(const String& path);
223223

224+
// Low-level FS routines, not needed by most applications
224225
bool gc();
226+
bool check();
225227

226228
friend class ::SDClass; // More of a frenemy, but SD needs internal implementation to get private FAT bits
227229
protected:

cores/esp8266/FSImpl.h

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class FSImpl {
8585
virtual bool mkdir(const char* path) = 0;
8686
virtual bool rmdir(const char* path) = 0;
8787
virtual bool gc() { return true; } // May not be implemented in all file systems.
88+
virtual bool check() { return true; } // May not be implemented in all file systems.
8889
};
8990

9091
} // namespace fs

cores/esp8266/spiffs_api.h

+5
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,11 @@ class SPIFFSImpl : public FSImpl
219219
return SPIFFS_gc_quick( &_fs, 0 ) == SPIFFS_OK;
220220
}
221221

222+
bool check() override
223+
{
224+
return SPIFFS_check(&_fs) == SPIFFS_OK;
225+
}
226+
222227
protected:
223228
friend class SPIFFSFileImpl;
224229
friend class SPIFFSDirImpl;

doc/filesystem.rst

+25
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,31 @@ block size - ``pageSize`` — filesystem logical page size - ``maxOpenFiles``
402402
``maxPathLength`` — max file name length (including one byte for zero
403403
termination)
404404

405+
gc
406+
~~
407+
408+
.. code:: cpp
409+
410+
SPIFFS.gc()
411+
412+
Only implemented in SPIFFS. Performs a quick garbage collection operation on SPIFFS,
413+
possibly making writes perform faster/better in the future. On very full or very fragmented
414+
filesystems, using this call can avoid or reduce issues where SPIFFS reports free space
415+
but is unable to write additional data to a file. See `this discussion
416+
<https://github.com/esp8266/Arduino/pull/6340#discussion_r307042268>` for more info.
417+
418+
check
419+
~~~~~
420+
421+
.. code:: cpp
422+
423+
SPIFFS.begin();
424+
SPIFFS.check();
425+
426+
Only implemented in SPIFFS. Performs an in-depth check of the filesystem metadata and
427+
correct what is repairable. Not normally needed, and not guaranteed to actually fix
428+
anything should there be corruption.
429+
405430
Directory object (Dir)
406431
----------------------
407432

0 commit comments

Comments
 (0)