File tree Expand file tree Collapse file tree
libraries/Adafruit_LittleFS/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -239,6 +239,34 @@ bool Adafruit_LittleFS::rmdir_r (char const *filepath)
239239 return LFS_ERR_OK == err;
240240}
241241
242+ static int _lfs_count (void *p, lfs_block_t block) {
243+ (void ) block;
244+ *(size_t *)p += 1 ;
245+ return 0 ;
246+ }
247+
248+ size_t Adafruit_LittleFS::usedBlocks () {
249+ _lockFS ();
250+
251+ size_t block_used = 0 ;
252+ lfs_traverse (&_lfs, _lfs_count, &block_used);
253+
254+ _unlockFS ();
255+ return block_used;
256+ }
257+
258+ size_t Adafruit_LittleFS::usedBytes () {
259+ if (nullptr == _lfs_cfg)
260+ return 0 ;
261+ return _lfs_cfg->block_size * usedBlocks ();
262+ }
263+
264+ size_t Adafruit_LittleFS::totalBytes () {
265+ if (nullptr == _lfs_cfg)
266+ return 0 ;
267+ return _lfs_cfg->block_size * _lfs_cfg->block_count ;
268+ }
269+
242270// ------------- Debug -------------//
243271#if CFG_DEBUG
244272
Original file line number Diff line number Diff line change @@ -70,6 +70,10 @@ class Adafruit_LittleFS
7070 // format file system
7171 bool format (void );
7272
73+ size_t usedBlocks ();
74+ size_t usedBytes ();
75+ size_t totalBytes ();
76+
7377 /* ------------------------------------------------------------------*/
7478 /* INTERNAL USAGE ONLY
7579 * Although declare as public, it is meant to be invoked by internal
You can’t perform that action at this time.
0 commit comments