Skip to content

Commit

Permalink
Add usedSize() and totalSize()
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulStoffregen committed Nov 13, 2020
1 parent afce590 commit a283a8b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/LittleFS.h
Expand Up @@ -205,13 +205,11 @@ class LittleFS : public FS
if (lfs_mkdir(&lfs, filepath) < 0) return false;
return true;
}

bool rename(const char *oldfilepath, const char *newfilepath) {
if (!configured) return false;
if (lfs_rename(&lfs, oldfilepath, newfilepath) < 0) return false;
return true;
}

bool remove(const char *filepath) {
if (!configured) return false;
if (lfs_remove(&lfs, filepath) < 0) return false;
Expand All @@ -220,6 +218,16 @@ class LittleFS : public FS
bool rmdir(const char *filepath) {
return remove(filepath);
}
uint64_t usedSize() {
if (!configured) return 0;
int blocks = lfs_fs_size(&lfs);
if (blocks < 0 || blocks > config.block_count) return totalSize();
return blocks * config.block_size;
}
uint64_t totalSize() {
if (!configured) return 0;
return config.block_count * config.block_size;
}
protected:
bool configured;
lfs_t lfs;
Expand Down

0 comments on commit a283a8b

Please sign in to comment.