Debian Codegraph @

upstream/debian-unstable/man2/statfs.2

raw
1 .\" Copyright 2003, Andries E. Brouwer <[email protected]>
2 .\" Copyright, the authors of the Linux man-pages project
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .TH statfs 2 2026-02-08 "Linux man-pages 6.18"
7 .SH NAME
8 statfs, fstatfs \- get filesystem statistics
9 .SH LIBRARY
10 Standard C library
11 .RI ( libc ,\~ \-lc )
12 .SH SYNOPSIS
13 .nf
14 .BR "#include <sys/vfs.h> " "/* or <sys/statfs.h> */"
15 .P
16 .BI "int statfs(const char *" path ", struct statfs *" buf );
17 .BI "int fstatfs(int " fd ", struct statfs *" buf );
18 .fi
19 .P
20 Unless you need the
21 .I f_type
22 field, you should use the standard
23 .BR statvfs (3)
24 interface instead.
25 .SH DESCRIPTION
26 The
27 .BR statfs ()
28 system call returns information about a mounted filesystem.
29 .I path
30 is the pathname of any file within the mounted filesystem.
31 .I buf
32 is a pointer to a
33 .I statfs
34 structure defined approximately as follows:
35 .P
36 .in +4n
37 .EX
38 struct statfs {
39 __fsword_t f_type; /* Type of filesystem (see below) */
40 __fsword_t f_bsize; /* Optimal transfer block size */
41 fsblkcnt_t f_blocks; /* Total data blocks in filesystem */
42 fsblkcnt_t f_bfree; /* Free blocks in filesystem */
43 fsblkcnt_t f_bavail; /* Free blocks available to
44 unprivileged user */
45 fsfilcnt_t f_files; /* Total inodes in filesystem */
46 fsfilcnt_t f_ffree; /* Free inodes in filesystem */
47 fsid_t f_fsid; /* Filesystem ID */
48 __fsword_t f_namelen; /* Maximum length of filenames */
49 __fsword_t f_frsize; /* Fragment size (since Linux 2.6) */
50 __fsword_t f_flags; /* Mount flags of filesystem
51 (since Linux 2.6.36) */
52 __fsword_t f_spare[xxx];
53 /* Padding bytes reserved for future use */
54 };
55 .EE
56 .in
57 .P
58 The following filesystem types may appear in
59 .IR f_type :
60 .P
61 .in +4n
62 .EX
63 ADFS_SUPER_MAGIC 0xadf5
64 AFFS_SUPER_MAGIC 0xadff
65 AFS_SUPER_MAGIC 0x5346414f
66 ANON_INODE_FS_MAGIC 0x09041934 /* Anonymous inode FS (for
67 pseudofiles that have no name;
68 e.g., epoll, signalfd, bpf) */
69 AUTOFS_SUPER_MAGIC 0x0187
70 BDEVFS_MAGIC 0x62646576
71 BEFS_SUPER_MAGIC 0x42465331
72 BFS_MAGIC 0x1badface
73 BINFMTFS_MAGIC 0x42494e4d
74 BPF_FS_MAGIC 0xcafe4a11
75 BTRFS_SUPER_MAGIC 0x9123683e
76 BTRFS_TEST_MAGIC 0x73727279
77 CGROUP_SUPER_MAGIC 0x27e0eb /* Cgroup pseudo FS */
78 CGROUP2_SUPER_MAGIC 0x63677270 /* Cgroup v2 pseudo FS */
79 CIFS_MAGIC_NUMBER 0xff534d42
80 CODA_SUPER_MAGIC 0x73757245
81 COH_SUPER_MAGIC 0x012ff7b7
82 CRAMFS_MAGIC 0x28cd3d45
83 DEBUGFS_MAGIC 0x64626720
84 DEVFS_SUPER_MAGIC 0x1373 /* Linux 2.6.17 and earlier */
85 DEVPTS_SUPER_MAGIC 0x1cd1
86 ECRYPTFS_SUPER_MAGIC 0xf15f
87 EFIVARFS_MAGIC 0xde5e81e4
88 EFS_SUPER_MAGIC 0x00414a53
89 EXT_SUPER_MAGIC 0x137d /* Linux 2.0 and earlier */
90 EXT2_OLD_SUPER_MAGIC 0xef51
91 EXT2_SUPER_MAGIC 0xef53
92 EXT3_SUPER_MAGIC 0xef53
93 EXT4_SUPER_MAGIC 0xef53
94 F2FS_SUPER_MAGIC 0xf2f52010
95 FUSE_SUPER_MAGIC 0x65735546
96 FUTEXFS_SUPER_MAGIC 0xbad1dea /* Unused */
97 HFS_SUPER_MAGIC 0x4244
98 HOSTFS_SUPER_MAGIC 0x00c0ffee
99 HPFS_SUPER_MAGIC 0xf995e849
100 HUGETLBFS_MAGIC 0x958458f6
101 ISOFS_SUPER_MAGIC 0x9660
102 JFFS2_SUPER_MAGIC 0x72b6
103 JFS_SUPER_MAGIC 0x3153464a
104 MINIX_SUPER_MAGIC 0x137f /* original minix FS */
105 MINIX_SUPER_MAGIC2 0x138f /* 30 char minix FS */
106 MINIX2_SUPER_MAGIC 0x2468 /* minix V2 FS */
107 MINIX2_SUPER_MAGIC2 0x2478 /* minix V2 FS, 30 char names */
108 MINIX3_SUPER_MAGIC 0x4d5a /* minix V3 FS, 60 char names */
109 MQUEUE_MAGIC 0x19800202 /* POSIX message queue FS */
110 MSDOS_SUPER_MAGIC 0x4d44
111 MTD_INODE_FS_MAGIC 0x11307854
112 NCP_SUPER_MAGIC 0x564c
113 NFS_SUPER_MAGIC 0x6969
114 NILFS_SUPER_MAGIC 0x3434
115 NSFS_MAGIC 0x6e736673
116 NTFS_SB_MAGIC 0x5346544e
117 OCFS2_SUPER_MAGIC 0x7461636f
118 OPENPROM_SUPER_MAGIC 0x9fa1
119 OVERLAYFS_SUPER_MAGIC 0x794c7630
120 PIPEFS_MAGIC 0x50495045
121 PROC_SUPER_MAGIC 0x9fa0 /* /proc FS */
122 PSTOREFS_MAGIC 0x6165676c
123 QNX4_SUPER_MAGIC 0x002f
124 QNX6_SUPER_MAGIC 0x68191122
125 RAMFS_MAGIC 0x858458f6
126 REISERFS_SUPER_MAGIC 0x52654973
127 ROMFS_MAGIC 0x7275
128 SECURITYFS_MAGIC 0x73636673
129 SELINUX_MAGIC 0xf97cff8c
130 SMACK_MAGIC 0x43415d53
131 SMB_SUPER_MAGIC 0x517b
132 SMB2_MAGIC_NUMBER 0xfe534d42
133 SOCKFS_MAGIC 0x534f434b
134 SQUASHFS_MAGIC 0x73717368
135 SYSFS_MAGIC 0x62656572
136 SYSV2_SUPER_MAGIC 0x012ff7b6
137 SYSV4_SUPER_MAGIC 0x012ff7b5
138 TMPFS_MAGIC 0x01021994
139 TRACEFS_MAGIC 0x74726163
140 UDF_SUPER_MAGIC 0x15013346
141 UFS_MAGIC 0x00011954
142 USBDEVICE_SUPER_MAGIC 0x9fa2
143 V9FS_MAGIC 0x01021997
144 VXFS_SUPER_MAGIC 0xa501fcf5
145 XENFS_SUPER_MAGIC 0xabba1974
146 XENIX_SUPER_MAGIC 0x012ff7b4
147 XFS_SUPER_MAGIC 0x58465342
148 _XIAFS_SUPER_MAGIC 0x012fd16d /* Linux 2.0 and earlier */
149 .EE
150 .in
151 .P
152 Most of these MAGIC constants are defined in
153 .IR /usr/include/linux/magic.h ,
154 and some are hardcoded in kernel sources.
155 .P
156 The
157 .I f_flags
158 field is a bit mask indicating mount options for the filesystem.
159 It contains zero or more of the following bits:
160 .\" XXX Keep this list in sync with statvfs(3)
161 .TP
162 .B ST_MANDLOCK
163 Mandatory locking is permitted on the filesystem (see
164 .BR fcntl (2)).
165 .TP
166 .B ST_NOATIME
167 Do not update access times;
168 see
169 .BR mount (2).
170 .TP
171 .B ST_NODEV
172 Disallow access to device special files on this filesystem.
173 .TP
174 .B ST_NODIRATIME
175 Do not update directory access times;
176 see
177 .BR mount (2).
178 .TP
179 .B ST_NOEXEC
180 Execution of programs is disallowed on this filesystem.
181 .TP
182 .B ST_NOSUID
183 The set-user-ID and set-group-ID bits are ignored by
184 .BR exec (3)
185 for executable files on this filesystem
186 .TP
187 .B ST_RDONLY
188 This filesystem is mounted read-only.
189 .TP
190 .B ST_RELATIME
191 Update atime relative to mtime/ctime;
192 see
193 .BR mount (2).
194 .TP
195 .B ST_SYNCHRONOUS
196 Writes are synched to the filesystem immediately (see the description of
197 .B O_SYNC
198 in
199 .BR open (2)).
200 .TP
201 .BR ST_NOSYMFOLLOW " (since Linux 5.10)"
202 .\" dab741e0e02bd3c4f5e2e97be74b39df2523fc6e
203 Symbolic links are not followed when resolving paths;
204 see
205 .BR mount (2).
206 .P
207 Nobody knows what
208 .I f_fsid
209 is supposed to contain (but see below).
210 .P
211 Fields that are undefined for a particular filesystem are set to 0.
212 .P
213 .BR fstatfs ()
214 returns the same information about an open file referenced by descriptor
215 .IR fd .
216 .SH RETURN VALUE
217 On success, zero is returned.
218 On error, \-1 is returned, and
219 .I errno
220 is set to indicate the error.
221 .SH ERRORS
222 .TP
223 .B EACCES
224 .RB ( statfs ())
225 Search permission is denied for a component of the path prefix of
226 .IR path .
227 (See also
228 .BR path_resolution (7).)
229 .TP
230 .B EBADF
231 .RB ( fstatfs ())
232 .I fd
233 is not a valid open file descriptor.
234 .TP
235 .B EFAULT
236 .I buf
237 or
238 .I path
239 points to an invalid address.
240 .TP
241 .B EINTR
242 The call was interrupted by a signal;
243 see
244 .BR signal (7).
245 .TP
246 .B EIO
247 An I/O error occurred while reading from the filesystem.
248 .TP
249 .B ELOOP
250 .RB ( statfs ())
251 Too many symbolic links were encountered in translating
252 .IR path .
253 .TP
254 .B ENAMETOOLONG
255 .RB ( statfs ())
256 .I path
257 is too long.
258 .TP
259 .B ENOENT
260 .RB ( statfs ())
261 The file referred to by
262 .I path
263 does not exist.
264 .TP
265 .B ENOMEM
266 Insufficient kernel memory was available.
267 .TP
268 .B ENOSYS
269 The filesystem does not support this call.
270 .TP
271 .B ENOTDIR
272 .RB ( statfs ())
273 A component of the path prefix of
274 .I path
275 is not a directory.
276 .TP
277 .B EOVERFLOW
278 Some values were too large to be represented in the returned struct.
279 .SH VERSIONS
280 .SS The f_fsid field
281 Solaris, Irix, and POSIX have a system call
282 .BR statvfs (2)
283 that returns a
284 .I "struct statvfs"
285 (defined in
286 .IR <sys/statvfs.h> )
287 containing an
288 .I "unsigned long"
289 .IR f_fsid .
290 Linux, SunOS, HP-UX, 4.4BSD have a system call
291 .BR statfs ()
292 that returns a
293 .I "struct statfs"
294 (defined in
295 .IR <sys/vfs.h> )
296 containing a
297 .I fsid_t
298 .IR f_fsid ,
299 where
300 .I fsid_t
301 is defined as
302 .IR "struct { int val[2]; }" .
303 The same holds for FreeBSD, except that it uses the include file
304 .IR <sys/mount.h> .
305 .P
306 The general idea is that
307 .I f_fsid
308 contains some random stuff such that the pair
309 .RI ( f_fsid , ino )
310 uniquely determines a file.
311 Some operating systems use (a variation on) the device number,
312 or the device number combined with the filesystem type.
313 Several operating systems restrict giving out the
314 .I f_fsid
315 field to the superuser only (and zero it for unprivileged users),
316 because this field is used in the filehandle of the filesystem
317 when NFS-exported, and giving it out is a security concern.
318 .P
319 Under some operating systems, the
320 .I fsid
321 can be used as the second argument to the
322 .BR sysfs (2)
323 system call.
324 .SH STANDARDS
325 Linux.
326 .SH HISTORY
327 The Linux
328 .BR statfs ()
329 was inspired by the 4.4BSD one
330 (but they do not use the same structure).
331 .P
332 The original Linux
333 .BR statfs ()
334 and
335 .BR fstatfs ()
336 system calls were not designed with extremely large file sizes in mind.
337 Subsequently, Linux 2.6
338 added new
339 .BR statfs64 ()
340 and
341 .BR fstatfs64 ()
342 system calls that employ a new structure,
343 .IR statfs64 .
344 The new structure contains the same fields as the original
345 .I statfs
346 structure, but the sizes of various fields are increased,
347 to accommodate large file sizes.
348 The glibc
349 .BR statfs ()
350 and
351 .BR fstatfs ()
352 wrapper functions transparently deal with the kernel differences.
353 .P
354 LSB has deprecated the library calls
355 .BR statfs ()
356 and
357 .BR fstatfs ()
358 and tells us to use
359 .BR statvfs (3)
360 and
361 .BR fstatvfs (3)
362 instead.
363 .SH NOTES
364 The
365 .I __fsword_t
366 type used for various fields in the
367 .I statfs
368 structure definition is a glibc internal type,
369 not intended for public use.
370 This leaves the programmer in a bit of a conundrum when trying to copy
371 or compare these fields to local variables in a program.
372 Using
373 .I "unsigned\ int"
374 for such variables suffices on most systems.
375 .P
376 Some systems have only
377 .IR <sys/vfs.h> ,
378 other systems also have
379 .IR <sys/statfs.h> ,
380 where the former includes the latter.
381 So it seems
382 including the former is the best choice.
383 .SH BUGS
384 From Linux 2.6.38 up to and including Linux 3.1,
385 .\" broken in commit ff0c7d15f9787b7e8c601533c015295cc68329f8
386 .\" fixed in commit d70ef97baf048412c395bb5d65791d8fe133a52b
387 .BR fstatfs ()
388 failed with the error
389 .B ENOSYS
390 for file descriptors created by
391 .BR pipe (2).
392 .SH SEE ALSO
393 .BR stat (2),
394 .BR statvfs (3),
395 .BR path_resolution (7)