]>
Commit | Line | Data |
---|---|---|
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 | 10 | statfs, fstatfs \- get filesystem statistics |
1ad1ac79 AC |
11 | .SH LIBRARY |
12 | Standard 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 | 22 | The |
e511ffb6 | 23 | .BR statfs () |
22795e81 | 24 | system call returns information about a mounted filesystem. |
fea681da | 25 | .I path |
9ee4a2b6 | 26 | is the pathname of any file within the mounted filesystem. |
fea681da MK |
27 | .I buf |
28 | is a pointer to a | |
29 | .I statfs | |
30 | structure defined approximately as follows: | |
efeece04 | 31 | .PP |
bd191423 | 32 | .in +4n |
b8302363 | 33 | .EX |
fea681da | 34 | struct 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 |
54 | The following filesystem types may appear in |
55 | .IR f_type : | |
c7885256 MK |
56 | .PP |
57 | .in +4n | |
58 | .EX | |
59 | ADFS_SUPER_MAGIC 0xadf5 | |
60 | AFFS_SUPER_MAGIC 0xadff | |
61 | AFS_SUPER_MAGIC 0x5346414f | |
d7fb74b4 MK |
62 | ANON_INODE_FS_MAGIC 0x09041934 /* Anonymous inode FS (for |
63 | pseudofiles that have no name; | |
64 | e.g., epoll, signalfd, bpf) */ | |
c7885256 MK |
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 | |
d7fb74b4 MK |
73 | CGROUP_SUPER_MAGIC 0x27e0eb /* Cgroup pseudo FS */ |
74 | CGROUP2_SUPER_MAGIC 0x63677270 /* Cgroup v2 pseudo FS */ | |
c7885256 MK |
75 | CIFS_MAGIC_NUMBER 0xff534d42 |
76 | CODA_SUPER_MAGIC 0x73757245 | |
77 | COH_SUPER_MAGIC 0x012ff7b7 | |
78 | CRAMFS_MAGIC 0x28cd3d45 | |
79 | DEBUGFS_MAGIC 0x64626720 | |
0b79679d | 80 | DEVFS_SUPER_MAGIC 0x1373 /* Linux 2.6.17 and earlier */ |
c7885256 MK |
81 | DEVPTS_SUPER_MAGIC 0x1cd1 |
82 | ECRYPTFS_SUPER_MAGIC 0xf15f | |
83 | EFIVARFS_MAGIC 0xde5e81e4 | |
84 | EFS_SUPER_MAGIC 0x00414a53 | |
0b79679d | 85 | EXT_SUPER_MAGIC 0x137d /* Linux 2.0 and earlier */ |
c7885256 MK |
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 | |
d7fb74b4 | 92 | FUTEXFS_SUPER_MAGIC 0xbad1dea /* Unused */ |
c7885256 MK |
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 | |
d7fb74b4 MK |
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 */ | |
e1846db5 | 105 | MQUEUE_MAGIC 0x19800202 /* POSIX message queue FS */ |
c7885256 MK |
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 | |
d7fb74b4 | 117 | PROC_SUPER_MAGIC 0x9fa0 /* /proc FS */ |
c7885256 MK |
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 | |
9e918199 | 128 | SMB2_MAGIC_NUMBER 0xfe534d42 |
c7885256 MK |
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 | |
0b79679d | 144 | _XIAFS_SUPER_MAGIC 0x012fd16d /* Linux 2.0 and earlier */ |
b8302363 | 145 | .EE |
bd191423 | 146 | .in |
fea681da | 147 | .PP |
3c794803 | 148 | Most of these MAGIC constants are defined in |
de86e1ab AM |
149 | .IR /usr/include/linux/magic.h , |
150 | and some are hardcoded in kernel sources. | |
efeece04 | 151 | .PP |
1d652363 | 152 | The |
1ae6b2c7 | 153 | .I f_flags |
4c4fda8a | 154 | field is a bit mask indicating mount options for the filesystem. |
1d652363 MK |
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)). | |
527375b2 | 193 | .TP |
97ba2b53 MK |
194 | .BR ST_NOSYMFOLLOW " (since Linux 5.10)" |
195 | .\" dab741e0e02bd3c4f5e2e97be74b39df2523fc6e | |
196 | Symbolic links are not followed when resolving paths; see | |
527375b2 | 197 | .BR mount (2). |
3c794803 | 198 | .PP |
fea681da MK |
199 | Nobody knows what |
200 | .I f_fsid | |
201 | is supposed to contain (but see below). | |
202 | .PP | |
9ee4a2b6 | 203 | Fields that are undefined for a particular filesystem are set to 0. |
efeece04 | 204 | .PP |
e511ffb6 | 205 | .BR fstatfs () |
fea681da MK |
206 | returns the same information about an open file referenced by descriptor |
207 | .IR fd . | |
47297adb | 208 | .SH RETURN VALUE |
c13182ef MK |
209 | On success, zero is returned. |
210 | On error, \-1 is returned, and | |
fea681da | 211 | .I errno |
f6a4078b | 212 | is set to indicate the error. |
fea681da MK |
213 | .SH ERRORS |
214 | .TP | |
215 | .B EACCES | |
1e321034 | 216 | .RB ( statfs ()) |
fea681da MK |
217 | Search 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 |
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 | |
4c4fda8a | 234 | The call was interrupted by a signal; see |
bb14af39 | 235 | .BR signal (7). |
fea681da MK |
236 | .TP |
237 | .B EIO | |
9ee4a2b6 | 238 | An I/O error occurred while reading from the filesystem. |
fea681da MK |
239 | .TP |
240 | .B ELOOP | |
1e321034 | 241 | .RB ( statfs ()) |
fea681da MK |
242 | Too many symbolic links were encountered in translating |
243 | .IR path . | |
244 | .TP | |
245 | .B ENAMETOOLONG | |
1e321034 | 246 | .RB ( statfs ()) |
fea681da MK |
247 | .I path |
248 | is too long. | |
249 | .TP | |
250 | .B ENOENT | |
1e321034 | 251 | .RB ( statfs ()) |
fea681da MK |
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 | |
9ee4a2b6 | 260 | The filesystem does not support this call. |
fea681da MK |
261 | .TP |
262 | .B ENOTDIR | |
1e321034 | 263 | .RB ( statfs ()) |
fea681da MK |
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. | |
3113c7f3 | 270 | .SH STANDARDS |
8382f16d | 271 | Linux-specific. |
fea681da | 272 | The Linux |
e511ffb6 | 273 | .BR statfs () |
fea681da MK |
274 | was inspired by the 4.4BSD one |
275 | (but they do not use the same structure). | |
56bbbf8e | 276 | .SH NOTES |
dba3f0dd MK |
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. | |
efeece04 | 288 | .PP |
e283e006 MK |
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 () | |
56bbbf8e MK |
297 | and |
298 | .BR fstatfs64 () | |
e283e006 MK |
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. | |
efeece04 | 310 | .PP |
394a52fc | 311 | Some 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 | 313 | So it seems |
56bbbf8e | 314 | including the former is the best choice. |
efeece04 | 315 | .PP |
56bbbf8e MK |
316 | LSB has deprecated the library calls |
317 | .BR statfs () | |
318 | and | |
319 | .BR fstatfs () | |
320 | and tells us to use | |
ff9469c0 | 321 | .BR statvfs (3) |
56bbbf8e | 322 | and |
ff9469c0 | 323 | .BR fstatvfs (3) |
56bbbf8e MK |
324 | instead. |
325 | .SS The f_fsid field | |
735334d4 | 326 | Solaris, Irix, and POSIX have a system call |
fea681da MK |
327 | .BR statvfs (2) |
328 | that returns a | |
8478ee02 | 329 | .I "struct statvfs" |
fea681da | 330 | (defined in |
a9a13a50 | 331 | .IR <sys/statvfs.h> ) |
fea681da | 332 | containing an |
9ff08aad | 333 | .I "unsigned long" |
fea681da | 334 | .IR f_fsid . |
97c1eac8 | 335 | Linux, SunOS, HP-UX, 4.4BSD have a system call |
31e9a9ec | 336 | .BR statfs () |
fea681da | 337 | that returns a |
8478ee02 | 338 | .I "struct statfs" |
fea681da | 339 | (defined in |
a9a13a50 | 340 | .IR <sys/vfs.h> ) |
fea681da | 341 | containing a |
9ff08aad | 342 | .I fsid_t |
fea681da MK |
343 | .IR f_fsid , |
344 | where | |
345 | .I fsid_t | |
346 | is defined as | |
8478ee02 | 347 | .IR "struct { int val[2]; }" . |
fea681da | 348 | The same holds for FreeBSD, except that it uses the include file |
a9a13a50 | 349 | .IR <sys/mount.h> . |
efeece04 | 350 | .PP |
fea681da MK |
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. | |
f0b613ec MK |
356 | Some operating systems use (a variation on) the device number, |
357 | or the device number combined with the filesystem type. | |
cefc0362 | 358 | Several operating systems restrict giving out the |
fea681da | 359 | .I f_fsid |
7145b9a9 | 360 | field to the superuser only (and zero it for unprivileged users), |
9ee4a2b6 | 361 | because this field is used in the filehandle of the filesystem |
fea681da | 362 | when NFS-exported, and giving it out is a security concern. |
dd3568a1 | 363 | .PP |
795d8ab1 | 364 | Under some operating systems, the |
fea681da | 365 | .I fsid |
795d8ab1 | 366 | can be used as the second argument to the |
0b80cf56 | 367 | .BR sysfs (2) |
fea681da | 368 | system call. |
f28710c6 | 369 | .SH BUGS |
2e35bf6d | 370 | From 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 () | |
374 | failed with the error | |
375 | .B ENOSYS | |
376 | for 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) |