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