1statfs(2)                     System Calls Manual                    statfs(2)
2
3
4

NAME

6       statfs, fstatfs - get filesystem statistics
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <sys/vfs.h>    /* or <sys/statfs.h> */
13
14       int statfs(const char *path, struct statfs *buf);
15       int fstatfs(int fd, struct statfs *buf);
16
17       Unless  you  need  the  f_type  field,  you  should  use  the  standard
18       statvfs(3) interface instead.
19

DESCRIPTION

21       The statfs() system call returns information about a  mounted  filesys‐
22       tem.   path  is the pathname of any file within the mounted filesystem.
23       buf is a pointer to a statfs structure defined  approximately  as  fol‐
24       lows:
25
26           struct statfs {
27               __fsword_t f_type;    /* Type of filesystem (see below) */
28               __fsword_t f_bsize;   /* Optimal transfer block size */
29               fsblkcnt_t f_blocks;  /* Total data blocks in filesystem */
30               fsblkcnt_t f_bfree;   /* Free blocks in filesystem */
31               fsblkcnt_t f_bavail;  /* Free blocks available to
32                                        unprivileged user */
33               fsfilcnt_t f_files;   /* Total inodes in filesystem */
34               fsfilcnt_t f_ffree;   /* Free inodes in filesystem */
35               fsid_t     f_fsid;    /* Filesystem ID */
36               __fsword_t f_namelen; /* Maximum length of filenames */
37               __fsword_t f_frsize;  /* Fragment size (since Linux 2.6) */
38               __fsword_t f_flags;   /* Mount flags of filesystem
39                                        (since Linux 2.6.36) */
40               __fsword_t f_spare[xxx];
41                               /* Padding bytes reserved for future use */
42           };
43
44       The following filesystem types may appear in f_type:
45
46           ADFS_SUPER_MAGIC      0xadf5
47           AFFS_SUPER_MAGIC      0xadff
48           AFS_SUPER_MAGIC       0x5346414f
49           ANON_INODE_FS_MAGIC   0x09041934 /* Anonymous inode FS (for
50                                               pseudofiles that have no name;
51                                               e.g., epoll, signalfd, bpf) */
52           AUTOFS_SUPER_MAGIC    0x0187
53           BDEVFS_MAGIC          0x62646576
54           BEFS_SUPER_MAGIC      0x42465331
55           BFS_MAGIC             0x1badface
56           BINFMTFS_MAGIC        0x42494e4d
57           BPF_FS_MAGIC          0xcafe4a11
58           BTRFS_SUPER_MAGIC     0x9123683e
59           BTRFS_TEST_MAGIC      0x73727279
60           CGROUP_SUPER_MAGIC    0x27e0eb   /* Cgroup pseudo FS */
61           CGROUP2_SUPER_MAGIC   0x63677270 /* Cgroup v2 pseudo FS */
62           CIFS_MAGIC_NUMBER     0xff534d42
63           CODA_SUPER_MAGIC      0x73757245
64           COH_SUPER_MAGIC       0x012ff7b7
65           CRAMFS_MAGIC          0x28cd3d45
66           DEBUGFS_MAGIC         0x64626720
67           DEVFS_SUPER_MAGIC     0x1373     /* Linux 2.6.17 and earlier */
68           DEVPTS_SUPER_MAGIC    0x1cd1
69           ECRYPTFS_SUPER_MAGIC  0xf15f
70           EFIVARFS_MAGIC        0xde5e81e4
71           EFS_SUPER_MAGIC       0x00414a53
72           EXT_SUPER_MAGIC       0x137d     /* Linux 2.0 and earlier */
73           EXT2_OLD_SUPER_MAGIC  0xef51
74           EXT2_SUPER_MAGIC      0xef53
75           EXT3_SUPER_MAGIC      0xef53
76           EXT4_SUPER_MAGIC      0xef53
77           F2FS_SUPER_MAGIC      0xf2f52010
78           FUSE_SUPER_MAGIC      0x65735546
79           FUTEXFS_SUPER_MAGIC   0xbad1dea  /* Unused */
80           HFS_SUPER_MAGIC       0x4244
81           HOSTFS_SUPER_MAGIC    0x00c0ffee
82           HPFS_SUPER_MAGIC      0xf995e849
83           HUGETLBFS_MAGIC       0x958458f6
84           ISOFS_SUPER_MAGIC     0x9660
85           JFFS2_SUPER_MAGIC     0x72b6
86           JFS_SUPER_MAGIC       0x3153464a
87           MINIX_SUPER_MAGIC     0x137f     /* original minix FS */
88           MINIX_SUPER_MAGIC2    0x138f     /* 30 char minix FS */
89           MINIX2_SUPER_MAGIC    0x2468     /* minix V2 FS */
90           MINIX2_SUPER_MAGIC2   0x2478     /* minix V2 FS, 30 char names */
91           MINIX3_SUPER_MAGIC    0x4d5a     /* minix V3 FS, 60 char names */
92           MQUEUE_MAGIC          0x19800202 /* POSIX message queue FS */
93           MSDOS_SUPER_MAGIC     0x4d44
94           MTD_INODE_FS_MAGIC    0x11307854
95           NCP_SUPER_MAGIC       0x564c
96           NFS_SUPER_MAGIC       0x6969
97           NILFS_SUPER_MAGIC     0x3434
98           NSFS_MAGIC            0x6e736673
99           NTFS_SB_MAGIC         0x5346544e
100           OCFS2_SUPER_MAGIC     0x7461636f
101           OPENPROM_SUPER_MAGIC  0x9fa1
102           OVERLAYFS_SUPER_MAGIC 0x794c7630
103           PIPEFS_MAGIC          0x50495045
104           PROC_SUPER_MAGIC      0x9fa0     /* /proc FS */
105           PSTOREFS_MAGIC        0x6165676c
106           QNX4_SUPER_MAGIC      0x002f
107           QNX6_SUPER_MAGIC      0x68191122
108           RAMFS_MAGIC           0x858458f6
109           REISERFS_SUPER_MAGIC  0x52654973
110           ROMFS_MAGIC           0x7275
111           SECURITYFS_MAGIC      0x73636673
112           SELINUX_MAGIC         0xf97cff8c
113           SMACK_MAGIC           0x43415d53
114           SMB_SUPER_MAGIC       0x517b
115           SMB2_MAGIC_NUMBER     0xfe534d42
116           SOCKFS_MAGIC          0x534f434b
117           SQUASHFS_MAGIC        0x73717368
118           SYSFS_MAGIC           0x62656572
119           SYSV2_SUPER_MAGIC     0x012ff7b6
120           SYSV4_SUPER_MAGIC     0x012ff7b5
121           TMPFS_MAGIC           0x01021994
122           TRACEFS_MAGIC         0x74726163
123           UDF_SUPER_MAGIC       0x15013346
124           UFS_MAGIC             0x00011954
125           USBDEVICE_SUPER_MAGIC 0x9fa2
126           V9FS_MAGIC            0x01021997
127           VXFS_SUPER_MAGIC      0xa501fcf5
128           XENFS_SUPER_MAGIC     0xabba1974
129           XENIX_SUPER_MAGIC     0x012ff7b4
130           XFS_SUPER_MAGIC       0x58465342
131           _XIAFS_SUPER_MAGIC    0x012fd16d /* Linux 2.0 and earlier */
132
133       Most    of    these   MAGIC   constants   are   defined   in   /usr/in‐
134       clude/linux/magic.h, and some are hardcoded in kernel sources.
135
136       The f_flags field is a  bit  mask  indicating  mount  options  for  the
137       filesystem.  It contains zero or more of the following bits:
138
139       ST_MANDLOCK
140              Mandatory locking is permitted on the filesystem (see fcntl(2)).
141
142       ST_NOATIME
143              Do not update access times; see mount(2).
144
145       ST_NODEV
146              Disallow access to device special files on this filesystem.
147
148       ST_NODIRATIME
149              Do not update directory access times; see mount(2).
150
151       ST_NOEXEC
152              Execution of programs is disallowed on this filesystem.
153
154       ST_NOSUID
155              The set-user-ID and set-group-ID bits are ignored by exec(3) for
156              executable files on this filesystem
157
158       ST_RDONLY
159              This filesystem is mounted read-only.
160
161       ST_RELATIME
162              Update atime relative to mtime/ctime; see mount(2).
163
164       ST_SYNCHRONOUS
165              Writes are synched to the filesystem immediately  (see  the  de‐
166              scription of O_SYNC in open(2)).
167
168       ST_NOSYMFOLLOW (since Linux 5.10)
169              Symbolic  links  are  not  followed  when  resolving  paths; see
170              mount(2).
171
172       Nobody knows what f_fsid is supposed to contain (but see below).
173
174       Fields that are undefined for a particular filesystem are set to 0.
175
176       fstatfs() returns the same information about an open file referenced by
177       descriptor fd.
178

RETURN VALUE

180       On  success,  zero is returned.  On error, -1 is returned, and errno is
181       set to indicate the error.
182

ERRORS

184       EACCES (statfs()) Search permission is denied for a  component  of  the
185              path prefix of path.  (See also path_resolution(7).)
186
187       EBADF  (fstatfs()) fd is not a valid open file descriptor.
188
189       EFAULT buf or path points to an invalid address.
190
191       EINTR  The call was interrupted by a signal; see signal(7).
192
193       EIO    An I/O error occurred while reading from the filesystem.
194
195       ELOOP  (statfs()) Too many symbolic links were encountered in translat‐
196              ing path.
197
198       ENAMETOOLONG
199              (statfs()) path is too long.
200
201       ENOENT (statfs()) The file referred to by path does not exist.
202
203       ENOMEM Insufficient kernel memory was available.
204
205       ENOSYS The filesystem does not support this call.
206
207       ENOTDIR
208              (statfs()) A component of the path prefix of path is not  a  di‐
209              rectory.
210
211       EOVERFLOW
212              Some  values  were  too  large to be represented in the returned
213              struct.
214

VERSIONS

216   The f_fsid field
217       Solaris, Irix, and POSIX have a system call statvfs(2) that  returns  a
218       struct statvfs (defined in <sys/statvfs.h>) containing an unsigned long
219       f_fsid.  Linux, SunOS, HP-UX, 4.4BSD have a system call  statfs()  that
220       returns  a  struct  statfs (defined in <sys/vfs.h>) containing a fsid_t
221       f_fsid, where fsid_t is defined as struct { int val[2];  }.   The  same
222       holds for FreeBSD, except that it uses the include file <sys/mount.h>.
223
224       The  general  idea  is that f_fsid contains some random stuff such that
225       the pair (f_fsid,ino) uniquely determines a file.  Some operating  sys‐
226       tems  use (a variation on) the device number, or the device number com‐
227       bined with the filesystem type.   Several  operating  systems  restrict
228       giving  out the f_fsid field to the superuser only (and zero it for un‐
229       privileged users), because this field is used in the filehandle of  the
230       filesystem when NFS-exported, and giving it out is a security concern.
231
232       Under  some operating systems, the fsid can be used as the second argu‐
233       ment to the sysfs(2) system call.
234

STANDARDS

236       Linux.
237

HISTORY

239       The Linux statfs() was inspired by the 4.4BSD one (but they do not  use
240       the same structure).
241
242       The  original  Linux  statfs()  and fstatfs() system calls were not de‐
243       signed with extremely large file sizes in  mind.   Subsequently,  Linux
244       2.6 added new statfs64() and fstatfs64() system calls that employ a new
245       structure, statfs64.  The new structure contains the same fields as the
246       original  statfs  structure,  but  the  sizes of various fields are in‐
247       creased, to accommodate large file sizes.  The glibc statfs()  and  fs‐
248       tatfs()  wrapper  functions  transparently deal with the kernel differ‐
249       ences.
250
251       LSB has deprecated the library calls statfs() and fstatfs()  and  tells
252       us to use statvfs(3) and fstatvfs(3) instead.
253

NOTES

255       The  __fsword_t  type  used  for various fields in the statfs structure
256       definition is a glibc internal type, not intended for public use.  This
257       leaves  the  programmer  in a bit of a conundrum when trying to copy or
258       compare these fields to  local  variables  in  a  program.   Using  un‐
259       signed int for such variables suffices on most systems.
260
261       Some   systems   have   only   <sys/vfs.h>,  other  systems  also  have
262       <sys/statfs.h>, where the former includes the latter.  So it seems  in‐
263       cluding the former is the best choice.
264

BUGS

266       From  Linux 2.6.38 up to and including Linux 3.1, fstatfs() failed with
267       the error ENOSYS for file descriptors created by pipe(2).
268

SEE ALSO

270       stat(2), statvfs(3), path_resolution(7)
271
272
273
274Linux man-pages 6.05              2023-07-18                         statfs(2)
Impressum