[Previous] [Contents] [Next]

statvfs(), statvfs64()

Get filesystem information

Synopsis:

#include <sys/statvfs.h>

int statvfs( const char *path,
             struct statvfs *buf );

int statvfs64( const char *path,
               struct statvfs64 *buf );

Library:

libc

Description:

The statvfs() function returns a "generic superblock" describing a filesystem; it can be used to acquire information about mounted filesystems. The statvfs64() is a 64-bit version of statvfs().

The path argument names a file that resides on the filesystem. The filesystem type is known to the operating system. Read, write, or execute permission for the named file isn't required, but all directories listed in the path name leading to the file must be searchable.

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 blocksize.
u_long f_frsize
Fundamental filesystem blocksize (if supported)
fsblkcnt_t f_blocks
Total # of blocks on filesystem, in units of f_frsize.
fsblkcnt_t f_bfree
Total # of free blocks.
fsblkcnt_t f_bavail
Number of free blocks available to a nonsuperuser.
fsfilcnt_t f_files
Total number of file nodes (inodes).
fsfilcnt_t f_ffree
Total number of free file nodes.
fsfilcnt_t f_favail
Number of inodes avail to a nonsuperuser.
u_long f_fsid
Filesystem ID (dev for now).
char f_basetype[FSTYPSZ]
Target filesystem type name, as a null-terminated string.
u_long f_flag
Bitmask of flags.
u_long f_namemax
Maximum filename length.
char f_fstr[32]
Filesystem-specific string.

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:

ST_RDONLY
Read-only filesystem.
ST_NOSUID
The filesystem doesn't support setuid/setgid semantics.

Returns:

0
Success.
-1
An error occurred; errno is set.

Errors:

EACCES
Search permission is denied on a component of the path prefix.
EFAULT
The path or buf argument points to an illegal address.
EINTR
A signal was caught during execution.
EIO
An I/O error occurred while reading the filesystem.
ELOOP
Too many symbolic links were encountered in translating path.
EMULTIHOP
Components of path require hopping to multiple remote machines and the filesystem type doesn't allow it.
ENAMETOOLONG
The length of a path component exceeds {NAME_MAX} characters, or the length of path exceeds {PATH_MAX} characters.
ENOENT
Either a component of the path prefix or the file referred to by path doesn't exist.
ENOLINK
The path argument points to a remote machine and the link to that machine is no longer active.
ENOTDIR
A component of the path prefix of path isn't a directory.
EOVERFLOW
One of the values to be returned can't be represented correctly in the structure pointed to by buf.

Classification:

statvfs() is standard Unix; statvfs64() is for large-file support

Safety:
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes

Caveats:

The values returned for f_files, f_ffree, and f_favail might not be valid for NFS-mounted filesystems.

See also:

chmod(), chown(), creat(), dup(), fcntl(), fstatvfs(), fstatvfs64(), link(), mknod(), open(), pipe(), read(), time(), unlink(), utime(), write()


[Previous] [Contents] [Next]