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