Get filesystem information, given a file descriptor
int fstatvfs( int fildes,
struct statvfs *buf );
int fstatvfs64( int fildes,
struct statvfs64 *buf );
- The descriptor for a file that resides on the filesystem that you
want to get information about.
- A pointer to a buffer where the function can store information about the
filesystem; see below.
Use the -l c option to
to link against this library.
This library is usually included automatically.
The fstatvfs() function returns a “generic superblock”
describing a filesystem; you can use it to get information about
The fstatvfs64() function is a 64-bit version of
statvfs() and statvfs64()
functions are similar, but they take a path name instead of a
The fildes argument is an open file descriptor,
obtained from a successful call to
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
The buf argument is a pointer to a statvfs or
structure that's filled by the function. It contains at least:
- unsigned long f_bsize
- The preferred filesystem blocksize.
- unsigned long f_frsize
- The fundamental filesystem blocksize (if supported)
- fsblkcnt_t f_blocks
- The total number of blocks on the filesystem, in units of
- fsblkcnt_t f_bfree
- The total number of free blocks.
- fsblkcnt_t f_bavail
- The number of free blocks available to a nonsuperuser.
- fsfilcnt_t f_files
- The total number of file nodes (inodes).
- fsfilcnt_t f_ffree
- The total number of free file nodes.
- fsfilcnt_t f_favail
- The number of inodes available to a nonsuperuser.
- unsigned long f_fsid
- The filesystem ID (currently the device ID).
- char f_basetype
- The type of the target filesystem, as a null-terminated string.
- unsigned long f_flag
- A bitmask of flags; the function can set these flags (the
_MOUNT_* and ST_* bits are equivalent):
||The filesystem is read-only.
||The filesystem doesn't permit the loading of executables.
||The filesystem doesn't support
||You can't create files on the filesystem.
||The off_t type is limited to 32 bits.
||The filesystem doesn't support the logging of file access times.
- unsigned long f_namemax
- The maximum filename length.
The values returned for f_files, f_ffree, and
f_favail depend on the filesystem:
- These filesystems embed inodes in directories, so the number of files
is limited by the amount of disk space, so basically there's no limit.
They don't count the number of files created either, so they set all
these fields to 0.
- These filesystems have a fixed inodes table,
so they fill in these fields.
- Read-only fsystems always set f_ffree and f_favail
Where possible or known, they try to set f_files:
- fs-mac.so knows exactly
- fs-nt.so provides an upper bound based on the current size
of the Master File Table (MFT)
- fs-udf.so knows when it's a UDF that's mounted;
ISO formats don't indicate that information, so f_files is
set to 0
- fs-cd.so sets it to 0
- The CIFS filesystem sets these fields to 0.
- Flash filesystem drivers estimate the values of these fields, based on the
amount of free space.
- An error occurred
- The fildes argument isn't an open file descriptor.
- The buf argument points to an illegal address.
- A signal was caught during execution.
- An I/O error occurred while reading the filesystem.
- One of the values to be returned can't be represented correctly in the
structure pointed to by buf.
POSIX 1003.1 XSI;