mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-12 01:53:07 +03:00
Add FS::format (#702)
This commit is contained in:
@ -167,6 +167,13 @@ bool FS::begin() {
|
||||
return _impl->begin();
|
||||
}
|
||||
|
||||
bool FS::format() {
|
||||
if (!_impl) {
|
||||
return false;
|
||||
}
|
||||
return _impl->format();
|
||||
}
|
||||
|
||||
File FS::open(const String& path, const char* mode) {
|
||||
return open(path.c_str(), mode);
|
||||
}
|
||||
|
@ -92,6 +92,8 @@ public:
|
||||
|
||||
bool begin();
|
||||
|
||||
bool format();
|
||||
|
||||
File open(const char* path, const char* mode);
|
||||
File open(const String& path, const char* mode);
|
||||
|
||||
|
@ -63,6 +63,7 @@ public:
|
||||
class FSImpl {
|
||||
public:
|
||||
virtual bool begin() = 0;
|
||||
virtual bool format() = 0;
|
||||
virtual FileImplPtr open(const char* path, OpenMode openMode, AccessMode accessMode) = 0;
|
||||
virtual DirImplPtr openDir(const char* path) = 0;
|
||||
virtual bool rename(const char* pathFrom, const char* pathTo) = 0;
|
||||
|
@ -102,6 +102,25 @@ public:
|
||||
return _tryMount();
|
||||
}
|
||||
|
||||
bool format() override {
|
||||
bool wasMounted = (SPIFFS_mounted(&_fs) != 0);
|
||||
|
||||
if (_tryMount()) {
|
||||
SPIFFS_unmount(&_fs);
|
||||
}
|
||||
auto rc = SPIFFS_format(&_fs);
|
||||
if (rc != SPIFFS_OK) {
|
||||
DEBUGV("SPIFFS_format: rc=%d, err=%d\r\n", rc, _fs.err_code);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (wasMounted) {
|
||||
return _tryMount();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected:
|
||||
friend class SPIFFSFileImpl;
|
||||
friend class SPIFFSDirImpl;
|
||||
|
Reference in New Issue
Block a user