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