mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-12 01:53:07 +03:00
Refactoring of FS::info (#779)
This commit is contained in:
@ -174,11 +174,11 @@ bool FS::format() {
|
||||
return _impl->format();
|
||||
}
|
||||
|
||||
bool FS::info(uint32_t *total, uint32_t *used){
|
||||
bool FS::info(FSInfo& info){
|
||||
if (!_impl) {
|
||||
return false;
|
||||
}
|
||||
return _impl->info(total,used);
|
||||
return _impl->info(info);
|
||||
}
|
||||
|
||||
File FS::open(const String& path, const char* mode) {
|
||||
|
@ -85,6 +85,15 @@ protected:
|
||||
DirImplPtr _impl;
|
||||
};
|
||||
|
||||
struct FSInfo {
|
||||
size_t totalBytes;
|
||||
size_t usedBytes;
|
||||
size_t blockSize;
|
||||
size_t pageSize;
|
||||
size_t maxOpenFiles;
|
||||
size_t maxPathLength;
|
||||
};
|
||||
|
||||
class FS
|
||||
{
|
||||
public:
|
||||
@ -93,7 +102,7 @@ public:
|
||||
bool begin();
|
||||
|
||||
bool format();
|
||||
bool info(uint32_t *total, uint32_t *used);
|
||||
bool info(FSInfo& info);
|
||||
|
||||
File open(const char* path, const char* mode);
|
||||
File open(const String& path, const char* mode);
|
||||
@ -123,6 +132,7 @@ using fs::SeekMode;
|
||||
using fs::SeekSet;
|
||||
using fs::SeekCur;
|
||||
using fs::SeekEnd;
|
||||
using fs::FSInfo;
|
||||
|
||||
extern FS SPIFFS;
|
||||
|
||||
|
@ -64,7 +64,7 @@ class FSImpl {
|
||||
public:
|
||||
virtual bool begin() = 0;
|
||||
virtual bool format() = 0;
|
||||
virtual bool info(uint32_t *total, uint32_t *used) = 0;
|
||||
virtual bool info(FSInfo& info) = 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;
|
||||
|
@ -71,11 +71,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);
|
||||
bool info(FSInfo& info) override {
|
||||
info.maxOpenFiles = _maxOpenFds;
|
||||
info.blockSize = _blockSize;
|
||||
info.pageSize = _pageSize;
|
||||
info.maxOpenFiles = _maxOpenFds;
|
||||
info.maxPathLength = SPIFFS_OBJ_NAME_LEN;
|
||||
auto rc = SPIFFS_info(&_fs, &info.totalBytes, &info.usedBytes);
|
||||
if (rc != SPIFFS_OK) {
|
||||
DEBUGV("SPIFFS_info: rc=%d, err=%d\r\n", rc, _fs.err_code);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user