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 *path, struct statvfs *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
39 employed when mounting this filesystem. It contains zero or more of
40 the 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
69 description 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 appropriately.
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
107 directory.
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
115 attributes(7).
116
117 ┌──────────────────────┬───────────────┬─────────┐
118 │Interface │ Attribute │ Value │
119 ├──────────────────────┼───────────────┼─────────┤
120 │statvfs(), fstatvfs() │ Thread safety │ MT-Safe │
121 └──────────────────────┴───────────────┴─────────┘
123 POSIX.1-2001, POSIX.1-2008.
124
125 Only the ST_NOSUID and ST_RDONLY flags of the f_flag field are speci‐
126 fied in POSIX.1. To obtain definitions of the remaining flags, one
127 must define _GNU_SOURCE.
128
130 The Linux kernel has system calls statfs(2) and fstatfs(2) to support
131 this library call.
132
133 In glibc versions before 2.13, statvfs() populated the bits of the
134 f_flag field by scanning the mount options shown in /proc/mounts. How‐
135 ever, starting with Linux 2.6.36, the underlying statfs(2) system call
136 provides the necessary information via the f_flags field, and since
137 glibc version 2.13, the statvfs() function will use information from
138 that field rather than scanning /proc/mounts.
139
140 The glibc implementations of
141
142 pathconf(path, _PC_REC_XFER_ALIGN);
143 pathconf(path, _PC_ALLOC_SIZE_MIN);
144 pathconf(path, _PC_REC_MIN_XFER_SIZE);
145
146 respectively use the f_frsize, f_frsize, and f_bsize fields returned by
147 a call to statvfs() with the argument path.
148
150 statfs(2)
151
153 This page is part of release 5.02 of the Linux man-pages project. A
154 description of the project, information about reporting bugs, and the
155 latest version of this page, can be found at
156 https://www.kernel.org/doc/man-pages/.
157
158
159
160Linux 2017-09-15 STATVFS(3)