mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #17634 from benpicco/pkg/fatfs-statvfs
pkg/fatfs: implement statvfs()
This commit is contained in:
commit
25882133f8
@ -122,6 +122,31 @@ static int _umount(vfs_mount_t *mountp)
|
||||
return fatfs_err_to_errno(res);
|
||||
}
|
||||
|
||||
static int _statvfs(vfs_mount_t *mountp, const char *restrict path, struct statvfs *restrict buf)
|
||||
{
|
||||
(void)path;
|
||||
fatfs_desc_t *fs_desc = (fatfs_desc_t *)mountp->private_data;
|
||||
mtd_dev_t *mtd = fs_desc->dev;
|
||||
DWORD nclst;
|
||||
FATFS *fs;
|
||||
|
||||
int res = f_getfree(fs_desc->abs_path_str_buff, &nclst, &fs);
|
||||
if (res != FR_OK) {
|
||||
return fatfs_err_to_errno(res);
|
||||
}
|
||||
|
||||
unsigned sector_size = mtd->page_size * mtd->pages_per_sector;
|
||||
|
||||
buf->f_bsize = fs->csize * sector_size;
|
||||
buf->f_frsize = fs->csize * sector_size;
|
||||
buf->f_blocks = mtd->sector_count / fs->csize;
|
||||
buf->f_bfree = nclst;
|
||||
buf->f_bavail = nclst;
|
||||
buf->f_namemax = FF_USE_LFN ? FF_LFN_BUF : FF_SFN_BUF;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _unlink(vfs_mount_t *mountp, const char *name)
|
||||
{
|
||||
fatfs_desc_t *fs_desc = (fatfs_desc_t *)mountp->private_data;
|
||||
@ -497,6 +522,7 @@ static const vfs_file_system_ops_t fatfs_fs_ops = {
|
||||
.mkdir = _mkdir,
|
||||
.rmdir = _rmdir,
|
||||
.stat = vfs_sysop_stat_from_fstat,
|
||||
.statvfs = _statvfs,
|
||||
};
|
||||
|
||||
static const vfs_file_ops_t fatfs_file_ops = {
|
||||
|
Loading…
Reference in New Issue
Block a user