1statfs(2) System Calls Manual statfs(2)
2
3
4
6 statfs, fstatfs - get filesystem statistics
7
9 Standard C library (libc, -lc)
10
12 #include <sys/vfs.h> /* or <sys/statfs.h> */
13
14 [[deprecated]] int statfs(const char *path, struct statfs *buf);
15 [[deprecated]] int fstatfs(int fd, struct statfs *buf);
16
18 The statfs() system call returns information about a mounted filesys‐
19 tem. path is the pathname of any file within the mounted filesystem.
20 buf is a pointer to a statfs structure defined approximately as fol‐
21 lows:
22
23 struct statfs {
24 __fsword_t f_type; /* Type of filesystem (see below) */
25 __fsword_t f_bsize; /* Optimal transfer block size */
26 fsblkcnt_t f_blocks; /* Total data blocks in filesystem */
27 fsblkcnt_t f_bfree; /* Free blocks in filesystem */
28 fsblkcnt_t f_bavail; /* Free blocks available to
29 unprivileged user */
30 fsfilcnt_t f_files; /* Total inodes in filesystem */
31 fsfilcnt_t f_ffree; /* Free inodes in filesystem */
32 fsid_t f_fsid; /* Filesystem ID */
33 __fsword_t f_namelen; /* Maximum length of filenames */
34 __fsword_t f_frsize; /* Fragment size (since Linux 2.6) */
35 __fsword_t f_flags; /* Mount flags of filesystem
36 (since Linux 2.6.36) */
37 __fsword_t f_spare[xxx];
38 /* Padding bytes reserved for future use */
39 };
40
41 The following filesystem types may appear in f_type:
42
43 ADFS_SUPER_MAGIC 0xadf5
44 AFFS_SUPER_MAGIC 0xadff
45 AFS_SUPER_MAGIC 0x5346414f
46 ANON_INODE_FS_MAGIC 0x09041934 /* Anonymous inode FS (for
47 pseudofiles that have no name;
48 e.g., epoll, signalfd, bpf) */
49 AUTOFS_SUPER_MAGIC 0x0187
50 BDEVFS_MAGIC 0x62646576
51 BEFS_SUPER_MAGIC 0x42465331
52 BFS_MAGIC 0x1badface
53 BINFMTFS_MAGIC 0x42494e4d
54 BPF_FS_MAGIC 0xcafe4a11
55 BTRFS_SUPER_MAGIC 0x9123683e
56 BTRFS_TEST_MAGIC 0x73727279
57 CGROUP_SUPER_MAGIC 0x27e0eb /* Cgroup pseudo FS */
58 CGROUP2_SUPER_MAGIC 0x63677270 /* Cgroup v2 pseudo FS */
59 CIFS_MAGIC_NUMBER 0xff534d42
60 CODA_SUPER_MAGIC 0x73757245
61 COH_SUPER_MAGIC 0x012ff7b7
62 CRAMFS_MAGIC 0x28cd3d45
63 DEBUGFS_MAGIC 0x64626720
64 DEVFS_SUPER_MAGIC 0x1373 /* Linux 2.6.17 and earlier */
65 DEVPTS_SUPER_MAGIC 0x1cd1
66 ECRYPTFS_SUPER_MAGIC 0xf15f
67 EFIVARFS_MAGIC 0xde5e81e4
68 EFS_SUPER_MAGIC 0x00414a53
69 EXT_SUPER_MAGIC 0x137d /* Linux 2.0 and earlier */
70 EXT2_OLD_SUPER_MAGIC 0xef51
71 EXT2_SUPER_MAGIC 0xef53
72 EXT3_SUPER_MAGIC 0xef53
73 EXT4_SUPER_MAGIC 0xef53
74 F2FS_SUPER_MAGIC 0xf2f52010
75 FUSE_SUPER_MAGIC 0x65735546
76 FUTEXFS_SUPER_MAGIC 0xbad1dea /* Unused */
77 HFS_SUPER_MAGIC 0x4244
78 HOSTFS_SUPER_MAGIC 0x00c0ffee
79 HPFS_SUPER_MAGIC 0xf995e849
80 HUGETLBFS_MAGIC 0x958458f6
81 ISOFS_SUPER_MAGIC 0x9660
82 JFFS2_SUPER_MAGIC 0x72b6
83 JFS_SUPER_MAGIC 0x3153464a
84 MINIX_SUPER_MAGIC 0x137f /* original minix FS */
85 MINIX_SUPER_MAGIC2 0x138f /* 30 char minix FS */
86 MINIX2_SUPER_MAGIC 0x2468 /* minix V2 FS */
87 MINIX2_SUPER_MAGIC2 0x2478 /* minix V2 FS, 30 char names */
88 MINIX3_SUPER_MAGIC 0x4d5a /* minix V3 FS, 60 char names */
89 MQUEUE_MAGIC 0x19800202 /* POSIX message queue FS */
90 MSDOS_SUPER_MAGIC 0x4d44
91 MTD_INODE_FS_MAGIC 0x11307854
92 NCP_SUPER_MAGIC 0x564c
93 NFS_SUPER_MAGIC 0x6969
94 NILFS_SUPER_MAGIC 0x3434
95 NSFS_MAGIC 0x6e736673
96 NTFS_SB_MAGIC 0x5346544e
97 OCFS2_SUPER_MAGIC 0x7461636f
98 OPENPROM_SUPER_MAGIC 0x9fa1
99 OVERLAYFS_SUPER_MAGIC 0x794c7630
100 PIPEFS_MAGIC 0x50495045
101 PROC_SUPER_MAGIC 0x9fa0 /* /proc FS */
102 PSTOREFS_MAGIC 0x6165676c
103 QNX4_SUPER_MAGIC 0x002f
104 QNX6_SUPER_MAGIC 0x68191122
105 RAMFS_MAGIC 0x858458f6
106 REISERFS_SUPER_MAGIC 0x52654973
107 ROMFS_MAGIC 0x7275
108 SECURITYFS_MAGIC 0x73636673
109 SELINUX_MAGIC 0xf97cff8c
110 SMACK_MAGIC 0x43415d53
111 SMB_SUPER_MAGIC 0x517b
112 SMB2_MAGIC_NUMBER 0xfe534d42
113 SOCKFS_MAGIC 0x534f434b
114 SQUASHFS_MAGIC 0x73717368
115 SYSFS_MAGIC 0x62656572
116 SYSV2_SUPER_MAGIC 0x012ff7b6
117 SYSV4_SUPER_MAGIC 0x012ff7b5
118 TMPFS_MAGIC 0x01021994
119 TRACEFS_MAGIC 0x74726163
120 UDF_SUPER_MAGIC 0x15013346
121 UFS_MAGIC 0x00011954
122 USBDEVICE_SUPER_MAGIC 0x9fa2
123 V9FS_MAGIC 0x01021997
124 VXFS_SUPER_MAGIC 0xa501fcf5
125 XENFS_SUPER_MAGIC 0xabba1974
126 XENIX_SUPER_MAGIC 0x012ff7b4
127 XFS_SUPER_MAGIC 0x58465342
128 _XIAFS_SUPER_MAGIC 0x012fd16d /* Linux 2.0 and earlier */
129
130 Most of these MAGIC constants are defined in /usr/in‐
131 clude/linux/magic.h, and some are hardcoded in kernel sources.
132
133 The f_flags field is a bit mask indicating mount options for the
134 filesystem. It contains zero or more of the following bits:
135
136 ST_MANDLOCK
137 Mandatory locking is permitted on the filesystem (see fcntl(2)).
138
139 ST_NOATIME
140 Do not update access times; see mount(2).
141
142 ST_NODEV
143 Disallow access to device special files on this filesystem.
144
145 ST_NODIRATIME
146 Do not update directory access times; see mount(2).
147
148 ST_NOEXEC
149 Execution of programs is disallowed on this filesystem.
150
151 ST_NOSUID
152 The set-user-ID and set-group-ID bits are ignored by exec(3) for
153 executable files on this filesystem
154
155 ST_RDONLY
156 This filesystem is mounted read-only.
157
158 ST_RELATIME
159 Update atime relative to mtime/ctime; see mount(2).
160
161 ST_SYNCHRONOUS
162 Writes are synched to the filesystem immediately (see the de‐
163 scription of O_SYNC in open(2)).
164
165 ST_NOSYMFOLLOW (since Linux 5.10)
166 Symbolic links are not followed when resolving paths; see
167 mount(2).
168
169 Nobody knows what f_fsid is supposed to contain (but see below).
170
171 Fields that are undefined for a particular filesystem are set to 0.
172
173 fstatfs() returns the same information about an open file referenced by
174 descriptor fd.
175
177 On success, zero is returned. On error, -1 is returned, and errno is
178 set to indicate the error.
179
181 EACCES (statfs()) Search permission is denied for a component of the
182 path prefix of path. (See also path_resolution(7).)
183
184 EBADF (fstatfs()) fd is not a valid open file descriptor.
185
186 EFAULT buf or path points to an invalid address.
187
188 EINTR The call was interrupted by a signal; see signal(7).
189
190 EIO An I/O error occurred while reading from the filesystem.
191
192 ELOOP (statfs()) Too many symbolic links were encountered in translat‐
193 ing path.
194
195 ENAMETOOLONG
196 (statfs()) path is too long.
197
198 ENOENT (statfs()) The file referred to by path does not exist.
199
200 ENOMEM Insufficient kernel memory was available.
201
202 ENOSYS The filesystem does not support this call.
203
204 ENOTDIR
205 (statfs()) A component of the path prefix of path is not a di‐
206 rectory.
207
208 EOVERFLOW
209 Some values were too large to be represented in the returned
210 struct.
211
213 The f_fsid field
214 Solaris, Irix, and POSIX have a system call statvfs(2) that returns a
215 struct statvfs (defined in <sys/statvfs.h>) containing an unsigned long
216 f_fsid. Linux, SunOS, HP-UX, 4.4BSD have a system call statfs() that
217 returns a struct statfs (defined in <sys/vfs.h>) containing a fsid_t
218 f_fsid, where fsid_t is defined as struct { int val[2]; }. The same
219 holds for FreeBSD, except that it uses the include file <sys/mount.h>.
220
221 The general idea is that f_fsid contains some random stuff such that
222 the pair (f_fsid,ino) uniquely determines a file. Some operating sys‐
223 tems use (a variation on) the device number, or the device number com‐
224 bined with the filesystem type. Several operating systems restrict
225 giving out the f_fsid field to the superuser only (and zero it for un‐
226 privileged users), because this field is used in the filehandle of the
227 filesystem when NFS-exported, and giving it out is a security concern.
228
229 Under some operating systems, the fsid can be used as the second argu‐
230 ment to the sysfs(2) system call.
231
233 Linux.
234
236 The Linux statfs() was inspired by the 4.4BSD one (but they do not use
237 the same structure).
238
239 The original Linux statfs() and fstatfs() system calls were not de‐
240 signed with extremely large file sizes in mind. Subsequently, Linux
241 2.6 added new statfs64() and fstatfs64() system calls that employ a new
242 structure, statfs64. The new structure contains the same fields as the
243 original statfs structure, but the sizes of various fields are in‐
244 creased, to accommodate large file sizes. The glibc statfs() and fs‐
245 tatfs() wrapper functions transparently deal with the kernel differ‐
246 ences.
247
248 LSB has deprecated the library calls statfs() and fstatfs() and tells
249 us to use statvfs(3) and fstatvfs(3) instead.
250
252 The __fsword_t type used for various fields in the statfs structure
253 definition is a glibc internal type, not intended for public use. This
254 leaves the programmer in a bit of a conundrum when trying to copy or
255 compare these fields to local variables in a program. Using un‐
256 signed int for such variables suffices on most systems.
257
258 Some systems have only <sys/vfs.h>, other systems also have
259 <sys/statfs.h>, where the former includes the latter. So it seems in‐
260 cluding the former is the best choice.
261
263 From Linux 2.6.38 up to and including Linux 3.1, fstatfs() failed with
264 the error ENOSYS for file descriptors created by pipe(2).
265
267 stat(2), statvfs(3), path_resolution(7)
268
269
270
271Linux man-pages 6.04 2023-03-30 statfs(2)