Get the metadata/statistics for the file system that the path belongs to.
Syntax
#include <sys/statvfs.h>
int fstat (const char *path, struct statvfs *st);
Parameters
-
path
Path to the file system or file within it.
-
st
Pointer to a
statvfs
structure that will receive the information.
Return Value
The return value is null if successful. Otherwise, the return value is negative and errno is set:
-
ENOENT
No such file or directory.
-
ENOSYS
The system call is not supported for this file system, or not implemented.
Remarks
The statvfs
structure is as follows:
struct statvfs
{
unsigned long f_bsize;
unsigned long f_frsize;
fsblkcnt_t f_blocks;
fsblkcnt_t f_bfree;
fsblkcnt_t f_bavail;
fsfilcnt_t f_files;
fsfilcnt_t f_ffree;
fsfilcnt_t f_favail;
unsigned long f_fsid;
unsigned long f_flag;
unsigned long f_namemax;
};
Note that, being a microcontroller OS, most fields are left blank. The fields that will contain usable information are:
-
f_bsize
File system block size, usually the underlying storages sector size.
-
f_frsize
The size of the file system fragment size.
-
f_blocks
The size of the file system in
f_frsize
units. Use this to calculate the total space available. -
f_bfree
The number of free blocks.
-
f_bavail
The number of free blocks available to unprivileged users.
-
f_namemax
Maximum size of a filename supported by the file system.