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