mirror of https://github.com/ARMmbed/mbed-os.git
Added littlefs statvfs implementation
parent
f1a9815876
commit
9dd3060d60
|
@ -336,8 +336,33 @@ int LittleFileSystem::stat(const char *name, struct stat *st)
|
|||
return lfs_toerror(err);
|
||||
}
|
||||
|
||||
int LittleFileSystem::statvfs(const char *path, struct statvfs *buf)
|
||||
static int lfs_statvfs_count(void *p, lfs_block_t b)
|
||||
{
|
||||
*(lfs_size_t *)p += 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LittleFileSystem::statvfs(const char *name, struct statvfs *st)
|
||||
{
|
||||
memset(st, 0, sizeof(struct statvfs));
|
||||
|
||||
lfs_size_t in_use = 0;
|
||||
_mutex.lock();
|
||||
LFS_INFO("statvfs(\"%s\", %p)", name, st);
|
||||
int err = lfs_traverse(&_lfs, lfs_statvfs_count, &in_use);
|
||||
LFS_INFO("statvfs -> %d", lfs_toerror(err));
|
||||
_mutex.unlock();
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
st->f_bsize = _config.block_size;
|
||||
st->f_frsize = _config.block_size;
|
||||
st->f_blocks = _config.block_count;
|
||||
st->f_bfree = _config.block_count - in_use;
|
||||
st->f_bavail = _config.block_count - in_use;
|
||||
st->f_namemax = LFS_NAME_MAX;
|
||||
return 0;
|
||||
}
|
||||
|
||||
////// File operations //////
|
||||
|
|
|
@ -149,7 +149,7 @@ public:
|
|||
* @param buf The stat buffer to write to
|
||||
* @return 0 on success, negative error code on failure
|
||||
*/
|
||||
virtual int statvfs(const char *path, struct statvfs *buf);
|
||||
virtual int statvfs(const char *path, struct statvfs *buf);
|
||||
|
||||
protected:
|
||||
/** Open a file on the filesystem
|
||||
|
|
Loading…
Reference in New Issue