NAME

SYNOPSIS

DESCRIPTION

The
statfs()
system call returns information about a mounted filesystem.
pathis the pathname of any file within the mounted filesystem.
bufis a pointer to a
statfsstructure defined approximately as follows:

(statfs())
Too many symbolic links were encountered in translating
path.

ENAMETOOLONG

(statfs())
pathis too long.

ENOENT

(statfs())
The file referred to by
pathdoes not exist.

ENOMEM

Insufficient kernel memory was available.

ENOSYS

The filesystem does not support this call.

ENOTDIR

(statfs())
A component of the path prefix of
pathis not a directory.

EOVERFLOW

Some values were too large to be represented in the returned struct.

CONFORMING TO

Linux-specific.
The Linux
statfs()
was inspired by the 4.4BSD one
(but they do not use the same structure).

NOTES

The
__fsword_ttype used for various fields in the
statfsstructure definition is a glibc internal type,
not intended for public use.
This leaves the programmer in a bit of a conundrum when trying to copy
or compare these fields to local variables in a program.
Using
unsigned intfor such variables suffices on most systems.

The original Linux
statfs()
and
fstatfs()
system calls were not designed with extremely large file sizes in mind.
Subsequently, Linux 2.6
added new
statfs64()
and
fstatfs64()
system calls that employ a new structure,
statfs64.
The new structure contains the same fields as the original
statfsstructure, but the sizes of various fields are increased,
to accommodate large file sizes.
The glibc
statfs()
and
fstatfs()
wrapper functions transparently deal with the kernel differences.

Some systems have only <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(2)
and
fstatvfs(2)
instead.

The f_fsid field

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_tis 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_fsidcontains some random stuff such that the pair
(f_fsid,ino)
uniquely determines a file.
Some operating systems use (a variation on) the device number,
or the device number combined with the filesystem type.
Several operating systems restrict giving out the
f_fsidfield 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 operating systems, the
fsidcan be used as the second argument to the
sysfs(2)
system call.

BUGS

From Linux 2.6.38 up to and including Linux 3.1,
fstatfs()
failed with the error
ENOSYSfor file descriptors created by
pipe(2).