diff --git a/cores/esp8266/FS.cpp b/cores/esp8266/FS.cpp index 55bae8f5c..6ae11e178 100644 --- a/cores/esp8266/FS.cpp +++ b/cores/esp8266/FS.cpp @@ -167,6 +167,12 @@ bool FS::begin() { return _impl->begin(); } +void FS::end() { + if (_impl) { + _impl->end(); + } +} + bool FS::format() { if (!_impl) { return false; diff --git a/cores/esp8266/FS.h b/cores/esp8266/FS.h index 527e90b58..207f89c16 100644 --- a/cores/esp8266/FS.h +++ b/cores/esp8266/FS.h @@ -102,7 +102,8 @@ public: FS(FSImplPtr impl) : _impl(impl) { } bool begin(); - + void end(); + bool format(); bool info(FSInfo& info); diff --git a/cores/esp8266/FSImpl.h b/cores/esp8266/FSImpl.h index c96ea0721..e5694b5f6 100644 --- a/cores/esp8266/FSImpl.h +++ b/cores/esp8266/FSImpl.h @@ -63,6 +63,7 @@ public: class FSImpl { public: virtual bool begin() = 0; + virtual void end() = 0; virtual bool format() = 0; virtual bool info(FSInfo& info) = 0; virtual FileImplPtr open(const char* path, OpenMode openMode, AccessMode accessMode) = 0; diff --git a/cores/esp8266/spiffs_api.h b/cores/esp8266/spiffs_api.h index cf157da79..f98df1195 100644 --- a/cores/esp8266/spiffs_api.h +++ b/cores/esp8266/spiffs_api.h @@ -132,6 +132,14 @@ public: return _tryMount(); } + void end() override + { + if (SPIFFS_mounted(&_fs) == 0) { + return; + } + SPIFFS_unmount(&_fs); + } + bool format() override { if (_size == 0) { diff --git a/doc/filesystem.md b/doc/filesystem.md index d3dbebf5f..e7987d63c 100644 --- a/doc/filesystem.md +++ b/doc/filesystem.md @@ -7,6 +7,7 @@ title: File System * [Uploading files to file system](#uploading-files-to-file-system) * [File system object (SPIFFS)](#file-system-object-spiffs) * [begin](#begin) + * [end](#end) * [format](#format) * [open](#open) * [exists](#exists) @@ -86,6 +87,14 @@ 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. +### end + +```c++ +SPIFFS.end() +``` + +This method unmounts SPIFFS file system. Use this method before updating SPIFFS using OTA. + ### format ```c++