1statvfs(3)                 Library Functions Manual                 statvfs(3)
2
3
4

NAME

6       statvfs, fstatvfs - get filesystem statistics
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <sys/statvfs.h>
13
14       int statvfs(const char *restrict path, struct statvfs *restrict buf);
15       int fstatvfs(int fd, struct statvfs *buf);
16

DESCRIPTION

18       The  function statvfs() returns information about a mounted filesystem.
19       path is the pathname of any file within the mounted filesystem.  buf is
20       a pointer to a statvfs structure defined approximately as follows:
21
22           struct statvfs {
23               unsigned long  f_bsize;    /* Filesystem block size */
24               unsigned long  f_frsize;   /* Fragment size */
25               fsblkcnt_t     f_blocks;   /* Size of fs in f_frsize units */
26               fsblkcnt_t     f_bfree;    /* Number of free blocks */
27               fsblkcnt_t     f_bavail;   /* Number of free blocks for
28                                             unprivileged users */
29               fsfilcnt_t     f_files;    /* Number of inodes */
30               fsfilcnt_t     f_ffree;    /* Number of free inodes */
31               fsfilcnt_t     f_favail;   /* Number of free inodes for
32                                             unprivileged users */
33               unsigned long  f_fsid;     /* Filesystem ID */
34               unsigned long  f_flag;     /* Mount flags */
35               unsigned long  f_namemax;  /* Maximum filename length */
36           };
37
38       Here  the types fsblkcnt_t and fsfilcnt_t are defined in <sys/types.h>.
39       Both used to be unsigned long.
40
41       The field f_flag is a bit mask indicating various options that were em‐
42       ployed  when mounting this filesystem.  It contains zero or more of the
43       following flags:
44
45       ST_MANDLOCK
46              Mandatory locking is permitted on the filesystem (see fcntl(2)).
47
48       ST_NOATIME
49              Do not update access times; see mount(2).
50
51       ST_NODEV
52              Disallow access to device special files on this filesystem.
53
54       ST_NODIRATIME
55              Do not update directory access times; see mount(2).
56
57       ST_NOEXEC
58              Execution of programs is disallowed on this filesystem.
59
60       ST_NOSUID
61              The set-user-ID and set-group-ID bits are ignored by exec(3) for
62              executable files on this filesystem
63
64       ST_RDONLY
65              This filesystem is mounted read-only.
66
67       ST_RELATIME
68              Update atime relative to mtime/ctime; see mount(2).
69
70       ST_SYNCHRONOUS
71              Writes  are  synched  to the filesystem immediately (see the de‐
72              scription of O_SYNC in open(2)).
73
74       It is unspecified whether all members of the returned struct have mean‐
75       ingful values on all filesystems.
76
77       fstatvfs()  returns  the same information about an open file referenced
78       by descriptor fd.
79

RETURN VALUE

81       On success, zero is returned.  On error, -1 is returned, and  errno  is
82       set to indicate the error.
83

ERRORS

85       EACCES (statvfs())  Search  permission is denied for a component of the
86              path prefix of path.  (See also path_resolution(7).)
87
88       EBADF  (fstatvfs()) fd is not a valid open file descriptor.
89
90       EFAULT Buf or path points to an invalid address.
91
92       EINTR  This call was interrupted by a signal; see signal(7).
93
94       EIO    An I/O error occurred while reading from the filesystem.
95
96       ELOOP  (statvfs()) Too many symbolic links were encountered  in  trans‐
97              lating path.
98
99       ENAMETOOLONG
100              (statvfs()) path is too long.
101
102       ENOENT (statvfs()) The file referred to by path does not exist.
103
104       ENOMEM Insufficient kernel memory was available.
105
106       ENOSYS The filesystem does not support this call.
107
108       ENOTDIR
109              (statvfs())  A component of the path prefix of path is not a di‐
110              rectory.
111
112       EOVERFLOW
113              Some values were too large to be  represented  in  the  returned
114              struct.
115

ATTRIBUTES

117       For  an  explanation  of  the  terms  used  in  this  section,  see at‐
118       tributes(7).
119
120       ┌────────────────────────────────────────────┬───────────────┬─────────┐
121Interface                                   Attribute     Value   
122       ├────────────────────────────────────────────┼───────────────┼─────────┤
123statvfs(), fstatvfs()                       │ Thread safety │ MT-Safe │
124       └────────────────────────────────────────────┴───────────────┴─────────┘
125

VERSIONS

127       Only the  ST_NOSUID  and  ST_RDONLY  flags  of  the  f_flag  field  are
128       specified  in  POSIX.1.   To obtain definitions of the remaining flags,
129       one must define _GNU_SOURCE.
130

NOTES

132       The Linux kernel has system calls statfs(2) and fstatfs(2)  to  support
133       this library call.
134
135       The glibc implementations of
136
137           pathconf(path, _PC_REC_XFER_ALIGN);
138           pathconf(path, _PC_ALLOC_SIZE_MIN);
139           pathconf(path, _PC_REC_MIN_XFER_SIZE);
140
141       respectively use the f_frsize, f_frsize, and f_bsize fields returned by
142       a call to statvfs() with the argument path.
143
144       Under Linux, f_favail is always the same as f_ffree, and there's no way
145       for  a  filesystem to report otherwise.  This is not an issue, since no
146       filesystems with an inode root reservation exist.
147

STANDARDS

149       POSIX.1-2008.
150

HISTORY

152       POSIX.1-2001.
153
154       Before glibc 2.13, statvfs() populated the bits of the f_flag field  by
155       scanning  the  mount  options shown in /proc/mounts.  However, starting
156       with Linux 2.6.36, the underlying statfs(2) system  call  provides  the
157       necessary  information via the f_flags field, and since glibc 2.13, the
158       statvfs() function will use information from  that  field  rather  than
159       scanning /proc/mounts.
160

SEE ALSO

162       statfs(2)
163
164
165
166Linux man-pages 6.05              2023-07-20                        statvfs(3)
Impressum