Get filesystem information
#include <sys/statvfs.h>
int fstatvfs( int fildes,
struct statvfs *buf );
int fstatvfs64( int fildes,
struct statvfs64 *buf );
libc
The fstatvfs() function returns a "generic superblock" describing a filesystem; it can be used to acquire information about mounted filesystems. The fstatvfs64() is a 64-bit version of fstatvfs().
The fildes argument is an open file descriptor, obtained from a successful call to open(), creat(), dup(), fcntl(), or pipe(), for a file that resides on that filesystem. The filesystem type is known to the operating system. Read, write, or execute permission for the named file isn't required.
The buf argument is a pointer to a structure that's filled by the function. It contains at least:
u_long f_bsize; /* Preferred filesystem block
size */
u_long f_frsize; /* Fundamental filesystem block
(size if supported) */
fsblkcnt_t f_blocks; /* Total # of blocks on file
system in units of f_frsize */
fsblkcnt_t f_bfree; /* Total # of free blocks */
fsblkcnt_t f_bavail; /* # of free blocks avail to
non-superuser */
fsfilcnt_t f_files; /* Total # of file nodes
(inodes) */
fsfilcnt_t f_ffree; /* Total # of free file nodes */
fsfilcnt_t f_favail; /* # of inodes avail to
non-superuser */
u_long f_fsid; /* Filesystem ID (dev for now) */
char f_basetype[FSTYPSZ]; /* Target fs type name,
null-terminated */
u_long f_flag; /* Bitmask of flags */
u_long f_namemax; /* Maximum file name length */
char f_fstr[32]; /* Filesystem-specific string */
u_long f_filler[16]; /* Reserved for future expansion */
The f_basetype array contains a NULL-terminated FSType name of the mounted target.
The following flags can be returned in the f_flag field:
fstatvfs() is standard Unix; fstatvfs64() is for large-file support
| Safety: | |
|---|---|
| Cancellation point | No |
| Interrupt handler | No |
| Signal handler | Yes |
| Thread | Yes |
The values returned for f_files, f_ffree, and f_favail might not be valid for NFS-mounted filesystems.
chmod(), chown(), creat(), dup(), fcntl(), link(), mknod(), open(), pipe(), read(), statvfs(), statvfs64(), time(), unlink(), utime(), write()