The function
statfs() returns information about a mounted file system.
path is the pathname of any file within the mounted filesystem.
buf is a pointer to a
statfs structure defined approximately as follows:
struct statfs {
long f_type; /* type of filesystem (see below) */
long f_bsize; /* optimal transfer block size */
long f_blocks; /* total data blocks in file system */
long f_bfree; /* free blocks in fs */
long f_bavail; /* free blocks avail to non-superuser */
long f_files; /* total file nodes in file system */
long f_ffree; /* free file nodes in fs */
fsid_t f_fsid; /* file system id */
long f_namelen; /* maximum length of filenames */
};
Nobody knows what
f_fsid is supposed to contain (but see below).
Fields that are undefined for a particular file system are set to 0.
fstatfs() returns the same information about an open file referenced by descriptor
fd.
The kernel has system calls
statfs(),
fstatfs(),
statfs64(), and
fstatfs64() to support this library call.
Some systems only have <sys/vfs.h>, other systems also have
<sys/statfs.h>, where the former includes the latter. So it seems
including the former is the best choice.
LSB has deprecated the library calls
statfs() and
fstatfs() and tells us to use
statvfs() and
fstatvfs() instead.
Solaris, Irix and POSIX have a system call
statvfs(2)
that returns a
struct statvfs (defined in
<sys/statvfs.h>) containing an
unsigned longf_fsid. Linux, SunOS, HP-UX, 4.4BSD have a system call
statfs() that returns a
struct statfs (defined in
<sys/vfs.h>) containing a
fsid_tf_fsid, where
fsid_t is defined as
struct { int val[2]; }. The same holds for FreeBSD, except that it uses the include file
<sys/mount.h>.
The general idea is that
f_fsid contains some random stuff such that the pair
(f_fsid,ino) uniquely determines a file.
Some OSes use (a variation on) the device number, or the device number
combined with the filesystem type.
Several OSes restrict giving out the
f_fsid field to the superuser only (and zero it for unprivileged users),
because this field is used in the filehandle of the filesystem
when NFS-exported, and giving it out is a security concern.
Under some OSes the
fsid can be used as second parameter to the
sysfs() system call.