1STATVFS(3) Linux Programmer's Manual STATVFS(3)
2
3
4
6 statvfs, fstatvfs - get filesystem statistics
7
9 #include <sys/statvfs.h>
10
11 int statvfs(const char *restrict path, struct statvfs *restrict buf);
12 int fstatvfs(int fd, struct statvfs *buf);
13
15 The function statvfs() returns information about a mounted filesystem.
16 path is the pathname of any file within the mounted filesystem. buf is
17 a pointer to a statvfs structure defined approximately as follows:
18
19 struct statvfs {
20 unsigned long f_bsize; /* Filesystem block size */
21 unsigned long f_frsize; /* Fragment size */
22 fsblkcnt_t f_blocks; /* Size of fs in f_frsize units */
23 fsblkcnt_t f_bfree; /* Number of free blocks */
24 fsblkcnt_t f_bavail; /* Number of free blocks for
25 unprivileged users */
26 fsfilcnt_t f_files; /* Number of inodes */
27 fsfilcnt_t f_ffree; /* Number of free inodes */
28 fsfilcnt_t f_favail; /* Number of free inodes for
29 unprivileged users */
30 unsigned long f_fsid; /* Filesystem ID */
31 unsigned long f_flag; /* Mount flags */
32 unsigned long f_namemax; /* Maximum filename length */
33 };
34
35 Here the types fsblkcnt_t and fsfilcnt_t are defined in <sys/types.h>.
36 Both used to be unsigned long.
37
38 The field f_flag is a bit mask indicating various options that were em‐
39 ployed when mounting this filesystem. It contains zero or more of the
40 following flags:
41
42 ST_MANDLOCK
43 Mandatory locking is permitted on the filesystem (see fcntl(2)).
44
45 ST_NOATIME
46 Do not update access times; see mount(2).
47
48 ST_NODEV
49 Disallow access to device special files on this filesystem.
50
51 ST_NODIRATIME
52 Do not update directory access times; see mount(2).
53
54 ST_NOEXEC
55 Execution of programs is disallowed on this filesystem.
56
57 ST_NOSUID
58 The set-user-ID and set-group-ID bits are ignored by exec(3) for
59 executable files on this filesystem
60
61 ST_RDONLY
62 This filesystem is mounted read-only.
63
64 ST_RELATIME
65 Update atime relative to mtime/ctime; see mount(2).
66
67 ST_SYNCHRONOUS
68 Writes are synched to the filesystem immediately (see the de‐
69 scription of O_SYNC in open(2)).
70
71 It is unspecified whether all members of the returned struct have mean‐
72 ingful values on all filesystems.
73
74 fstatvfs() returns the same information about an open file referenced
75 by descriptor fd.
76
78 On success, zero is returned. On error, -1 is returned, and errno is
79 set to indicate the error.
80
82 EACCES (statvfs()) Search permission is denied for a component of the
83 path prefix of path. (See also path_resolution(7).)
84
85 EBADF (fstatvfs()) fd is not a valid open file descriptor.
86
87 EFAULT Buf or path points to an invalid address.
88
89 EINTR This call was interrupted by a signal; see signal(7).
90
91 EIO An I/O error occurred while reading from the filesystem.
92
93 ELOOP (statvfs()) Too many symbolic links were encountered in trans‐
94 lating path.
95
96 ENAMETOOLONG
97 (statvfs()) path is too long.
98
99 ENOENT (statvfs()) The file referred to by path does not exist.
100
101 ENOMEM Insufficient kernel memory was available.
102
103 ENOSYS The filesystem does not support this call.
104
105 ENOTDIR
106 (statvfs()) A component of the path prefix of path is not a di‐
107 rectory.
108
109 EOVERFLOW
110 Some values were too large to be represented in the returned
111 struct.
112
114 For an explanation of the terms used in this section, see at‐
115 tributes(7).
116
117 ┌────────────────────────────────────────────┬───────────────┬─────────┐
118 │Interface │ Attribute │ Value │
119 ├────────────────────────────────────────────┼───────────────┼─────────┤
120 │statvfs(), fstatvfs() │ Thread safety │ MT-Safe │
121 └────────────────────────────────────────────┴───────────────┴─────────┘
122
124 POSIX.1-2001, POSIX.1-2008.
125
126 Only the ST_NOSUID and ST_RDONLY flags of the f_flag field are speci‐
127 fied in POSIX.1. To obtain definitions of the remaining flags, one
128 must define _GNU_SOURCE.
129
131 The Linux kernel has system calls statfs(2) and fstatfs(2) to support
132 this library call.
133
134 In glibc versions before 2.13, statvfs() populated the bits of the
135 f_flag field by scanning the mount options shown in /proc/mounts. How‐
136 ever, starting with Linux 2.6.36, the underlying statfs(2) system call
137 provides the necessary information via the f_flags field, and since
138 glibc version 2.13, the statvfs() function will use information from
139 that field rather than scanning /proc/mounts.
140
141 The glibc implementations of
142
143 pathconf(path, _PC_REC_XFER_ALIGN);
144 pathconf(path, _PC_ALLOC_SIZE_MIN);
145 pathconf(path, _PC_REC_MIN_XFER_SIZE);
146
147 respectively use the f_frsize, f_frsize, and f_bsize fields returned by
148 a call to statvfs() with the argument path.
149
151 statfs(2)
152
154 This page is part of release 5.12 of the Linux man-pages project. A
155 description of the project, information about reporting bugs, and the
156 latest version of this page, can be found at
157 https://www.kernel.org/doc/man-pages/.
158
159
160
161Linux 2021-03-22 STATVFS(3)