From 320a747890d529f14f3842d08e4427f843120cae Mon Sep 17 00:00:00 2001 From: luc Date: Thu, 22 Oct 2015 11:22:32 +0800 Subject: [PATCH] Add SPIFFS wrapper for info function this allow to display total space and used space on SPIFFS --- cores/esp8266/FS.cpp | 7 +++++++ cores/esp8266/FS.h | 1 + cores/esp8266/FSImpl.h | 1 + cores/esp8266/spiffs_api.cpp | 9 +++++++++ 4 files changed, 18 insertions(+) diff --git a/cores/esp8266/FS.cpp b/cores/esp8266/FS.cpp index e3158713d..5691c2573 100644 --- a/cores/esp8266/FS.cpp +++ b/cores/esp8266/FS.cpp @@ -174,6 +174,13 @@ bool FS::format() { return _impl->format(); } +bool FS::info(uint32_t *total, uint32_t *used){ + if (!_impl) { + return false; + } + return _impl->info(total,used); +} + File FS::open(const String& path, const char* mode) { return open(path.c_str(), mode); } diff --git a/cores/esp8266/FS.h b/cores/esp8266/FS.h index d7a170d1d..c03e50619 100644 --- a/cores/esp8266/FS.h +++ b/cores/esp8266/FS.h @@ -93,6 +93,7 @@ public: bool begin(); bool format(); + bool info(uint32_t *total, uint32_t *used); File open(const char* path, const char* mode); File open(const String& path, const char* mode); diff --git a/cores/esp8266/FSImpl.h b/cores/esp8266/FSImpl.h index b95bafcfc..a1124b285 100644 --- a/cores/esp8266/FSImpl.h +++ b/cores/esp8266/FSImpl.h @@ -64,6 +64,7 @@ class FSImpl { public: virtual bool begin() = 0; virtual bool format() = 0; + virtual bool info(uint32_t *total, uint32_t *used) = 0; virtual FileImplPtr open(const char* path, OpenMode openMode, AccessMode accessMode) = 0; virtual bool exists(const char* path) = 0; virtual DirImplPtr openDir(const char* path) = 0; diff --git a/cores/esp8266/spiffs_api.cpp b/cores/esp8266/spiffs_api.cpp index 4de08c405..f60a2d094 100644 --- a/cores/esp8266/spiffs_api.cpp +++ b/cores/esp8266/spiffs_api.cpp @@ -76,6 +76,15 @@ public: return true; } + bool info(uint32_t *total, uint32_t *used) override{ + auto rc = SPIFFS_info(&_fs, total, used); + if (rc != SPIFFS_OK) { + DEBUGV("SPIFFS_format: rc=%d, err=%d\r\n", rc, _fs.err_code); + return false; + } + return true; + } + bool remove(const char* path) override { char tmpName[SPIFFS_OBJ_NAME_LEN]; strlcpy(tmpName, path, sizeof(tmpName));