Skip to content

Add a FS::check() optional method #6340

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

Merged
merged 5 commits into from
Jul 27, 2019
Merged
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
7 changes: 7 additions & 0 deletions cores/esp8266/FS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions cores/esp8266/FS.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions cores/esp8266/FSImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions cores/esp8266/spiffs_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 25 additions & 0 deletions doc/filesystem.rst
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,31 @@ 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/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
<https://github.com/esp8266/Arduino/pull/6340#discussion_r307042268>` for more info.

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)
----------------------

Expand Down