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