mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Refactoring of FS::info (#779)
This commit is contained in:
parent
d7e340fe14
commit
d0a944e417
@ -174,11 +174,11 @@ bool FS::format() {
|
|||||||
return _impl->format();
|
return _impl->format();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FS::info(uint32_t *total, uint32_t *used){
|
bool FS::info(FSInfo& info){
|
||||||
if (!_impl) {
|
if (!_impl) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return _impl->info(total,used);
|
return _impl->info(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
File FS::open(const String& path, const char* mode) {
|
File FS::open(const String& path, const char* mode) {
|
||||||
|
@ -85,6 +85,15 @@ protected:
|
|||||||
DirImplPtr _impl;
|
DirImplPtr _impl;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct FSInfo {
|
||||||
|
size_t totalBytes;
|
||||||
|
size_t usedBytes;
|
||||||
|
size_t blockSize;
|
||||||
|
size_t pageSize;
|
||||||
|
size_t maxOpenFiles;
|
||||||
|
size_t maxPathLength;
|
||||||
|
};
|
||||||
|
|
||||||
class FS
|
class FS
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -93,7 +102,7 @@ public:
|
|||||||
bool begin();
|
bool begin();
|
||||||
|
|
||||||
bool format();
|
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 char* path, const char* mode);
|
||||||
File open(const String& path, const char* mode);
|
File open(const String& path, const char* mode);
|
||||||
@ -123,6 +132,7 @@ using fs::SeekMode;
|
|||||||
using fs::SeekSet;
|
using fs::SeekSet;
|
||||||
using fs::SeekCur;
|
using fs::SeekCur;
|
||||||
using fs::SeekEnd;
|
using fs::SeekEnd;
|
||||||
|
using fs::FSInfo;
|
||||||
|
|
||||||
extern FS SPIFFS;
|
extern FS SPIFFS;
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ class FSImpl {
|
|||||||
public:
|
public:
|
||||||
virtual bool begin() = 0;
|
virtual bool begin() = 0;
|
||||||
virtual bool format() = 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 FileImplPtr open(const char* path, OpenMode openMode, AccessMode accessMode) = 0;
|
||||||
virtual bool exists(const char* path) = 0;
|
virtual bool exists(const char* path) = 0;
|
||||||
virtual DirImplPtr openDir(const char* path) = 0;
|
virtual DirImplPtr openDir(const char* path) = 0;
|
||||||
|
@ -71,11 +71,15 @@ public:
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
bool info(FSInfo& info) override {
|
||||||
bool info(uint32_t *total, uint32_t *used) override{
|
info.maxOpenFiles = _maxOpenFds;
|
||||||
auto rc = SPIFFS_info(&_fs, total, used);
|
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) {
|
if (rc != SPIFFS_OK) {
|
||||||
DEBUGV("SPIFFS_format: rc=%d, err=%d\r\n", rc, _fs.err_code);
|
DEBUGV("SPIFFS_info: rc=%d, err=%d\r\n", rc, _fs.err_code);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -266,6 +266,32 @@ SPIFFS.rename(pathFrom, pathTo)
|
|||||||
Renames file from `pathFrom` to `pathTo`. Paths must be absolute. Returns *true*
|
Renames file from `pathFrom` to `pathTo`. Paths must be absolute. Returns *true*
|
||||||
if file was renamed successfully.
|
if file was renamed successfully.
|
||||||
|
|
||||||
|
#### info
|
||||||
|
|
||||||
|
```c++
|
||||||
|
FSInfo fs_info;
|
||||||
|
SPIFFS.info(fs_info);
|
||||||
|
```
|
||||||
|
|
||||||
|
Fills [FSInfo structure](#filesystem-information-structure) with information about
|
||||||
|
the file system. Returns `true` is successful, `false` otherwise.
|
||||||
|
|
||||||
|
### Filesystem information structure
|
||||||
|
|
||||||
|
```c++
|
||||||
|
struct FSInfo {
|
||||||
|
size_t totalBytes;
|
||||||
|
size_t usedBytes;
|
||||||
|
size_t blockSize;
|
||||||
|
size_t pageSize;
|
||||||
|
size_t maxOpenFiles;
|
||||||
|
size_t maxPathLength;
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
This is the structure which may be filled using FS::info method. Field names
|
||||||
|
are self-explanatory.
|
||||||
|
|
||||||
### Directory object (Dir)
|
### Directory object (Dir)
|
||||||
|
|
||||||
The purpose of *Dir* object is to iterate over files inside a directory.
|
The purpose of *Dir* object is to iterate over files inside a directory.
|
||||||
|
@ -111,6 +111,21 @@ void setup() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
FSInfo info;
|
||||||
|
if (!SPIFFS.info(info)) {
|
||||||
|
fail("info failed");
|
||||||
|
}
|
||||||
|
Serial.printf("Total: %u\nUsed: %u\nBlock: %u\nPage: %u\nMax open files: %u\nMax path len: %u\n",
|
||||||
|
info.totalBytes,
|
||||||
|
info.usedBytes,
|
||||||
|
info.blockSize,
|
||||||
|
info.pageSize,
|
||||||
|
info.maxOpenFiles,
|
||||||
|
info.maxPathLength
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
if (!SPIFFS.format()) {
|
if (!SPIFFS.format()) {
|
||||||
fail("format failed");
|
fail("format failed");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user