Skip to content

Commit 07af6cc

Browse files
Add a FS::check() optional method
Fixes esp8266#2634 Expose any low-level filesystem check operations for users, and add documentation on this and the gc() methods.
1 parent 705dd39 commit 07af6cc

File tree

5 files changed

+38
-0
lines changed

5 files changed

+38
-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

+23
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,29 @@ 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 in the future. Not normally needed by applications
414+
as SPIFFS will take care of things itself on writes.
415+
416+
check
417+
~~~~~
418+
419+
.. code:: cpp
420+
421+
SPIFFS.begin();
422+
SPIFFS.check();
423+
424+
Only implemented in SPIFFS. Performs an in-depth check of the filesystem metadata and
425+
correct what is repairable. Not normally needed, and not guaranteed to actually fix
426+
anything should there be corruption.
427+
405428
Directory object (Dir)
406429
----------------------
407430

0 commit comments

Comments
 (0)