[Previous] [Contents] [Next]

fstatvfs(), fstatvfs64()

Get filesystem information

Synopsis:

#include <sys/statvfs.h>

int fstatvfs( int fildes, 
              struct statvfs *buf );
int fstatvfs64( int fildes,
                struct statvfs64 *buf );

Library:

libc

Description:

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:

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:

EBADF
The fildes argument isn't an open file descriptor.
EFAULT
The buf argument points to an illegal address.
EINTR
A signal was caught during execution.
EIO
An I/O error occurred while reading the filesystem.
EOVERFLOW
One of the values to be returned can't be represented correctly in the structure pointed to by buf.

Classification:

fstatvfs() is standard Unix; fstatvfs64() 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(), link(), mknod(), open(), pipe(), read(), statvfs(), statvfs64(), time(), unlink(), utime(), write()


[Previous] [Contents] [Next]