1STATFS(2)                  Linux Programmer's Manual                 STATFS(2)
2
3
4

NAME

6       statfs, fstatfs - get file system statistics
7

SYNOPSIS

9       #include <sys/vfs.h>    /* or <sys/statfs.h> */
10
11       int statfs(const char *path, struct statfs *buf);
12       int fstatfs(int fd, struct statfs *buf);
13

DESCRIPTION

15       The  function statfs() returns information about a mounted file system.
16       path is the pathname of any file within the mounted file  system.   buf
17       is a pointer to a statfs structure defined approximately as follows:
18
19           #if __WORDSIZE == 32          /* System word size */
20           # define __SWORD_TYPE           int
21           #else /* __WORDSIZE == 64 */
22           # define __SWORD_TYPE         long int
23           #endif
24
25           struct statfs {
26               __SWORD_TYPE f_type;    /* type of file system (see below) */
27               __SWORD_TYPE f_bsize;   /* optimal transfer block size */
28               fsblkcnt_t   f_blocks;  /* total data blocks in file system */
29               fsblkcnt_t   f_bfree;   /* free blocks in fs */
30               fsblkcnt_t   f_bavail;  /* free blocks available to
31                                          unprivileged user */
32               fsfilcnt_t   f_files;   /* total file nodes in file system */
33               fsfilcnt_t   f_ffree;   /* free file nodes in fs */
34               fsid_t       f_fsid;    /* file system id */
35               __SWORD_TYPE f_namelen; /* maximum length of filenames */
36               __SWORD_TYPE f_frsize;  /* fragment size (since Linux 2.6) */
37               __SWORD_TYPE f_spare[5];
38           };
39
40           File system types:
41
42              ADFS_SUPER_MAGIC      0xadf5
43              AFFS_SUPER_MAGIC      0xADFF
44              BEFS_SUPER_MAGIC      0x42465331
45              BFS_MAGIC             0x1BADFACE
46              CIFS_MAGIC_NUMBER     0xFF534D42
47              CODA_SUPER_MAGIC      0x73757245
48              COH_SUPER_MAGIC       0x012FF7B7
49              CRAMFS_MAGIC          0x28cd3d45
50              DEVFS_SUPER_MAGIC     0x1373
51              EFS_SUPER_MAGIC       0x00414A53
52              EXT_SUPER_MAGIC       0x137D
53              EXT2_OLD_SUPER_MAGIC  0xEF51
54              EXT2_SUPER_MAGIC      0xEF53
55              EXT3_SUPER_MAGIC      0xEF53
56              EXT4_SUPER_MAGIC      0xEF53
57              HFS_SUPER_MAGIC       0x4244
58              HPFS_SUPER_MAGIC      0xF995E849
59              HUGETLBFS_MAGIC       0x958458f6
60              ISOFS_SUPER_MAGIC     0x9660
61              JFFS2_SUPER_MAGIC     0x72b6
62              JFS_SUPER_MAGIC       0x3153464a
63              MINIX_SUPER_MAGIC     0x137F /* orig. minix */
64              MINIX_SUPER_MAGIC2    0x138F /* 30 char minix */
65              MINIX2_SUPER_MAGIC    0x2468 /* minix V2 */
66              MINIX2_SUPER_MAGIC2   0x2478 /* minix V2, 30 char names */
67              MSDOS_SUPER_MAGIC     0x4d44
68              NCP_SUPER_MAGIC       0x564c
69              NFS_SUPER_MAGIC       0x6969
70              NTFS_SB_MAGIC         0x5346544e
71              OPENPROM_SUPER_MAGIC  0x9fa1
72              PROC_SUPER_MAGIC      0x9fa0
73              QNX4_SUPER_MAGIC      0x002f
74              REISERFS_SUPER_MAGIC  0x52654973
75              ROMFS_MAGIC           0x7275
76              SMB_SUPER_MAGIC       0x517B
77              SYSV2_SUPER_MAGIC     0x012FF7B6
78              SYSV4_SUPER_MAGIC     0x012FF7B5
79              TMPFS_MAGIC           0x01021994
80              UDF_SUPER_MAGIC       0x15013346
81              UFS_MAGIC             0x00011954
82              USBDEVICE_SUPER_MAGIC 0x9fa2
83              VXFS_SUPER_MAGIC      0xa501FCF5
84              XENIX_SUPER_MAGIC     0x012FF7B4
85              XFS_SUPER_MAGIC       0x58465342
86              _XIAFS_SUPER_MAGIC    0x012FD16D
87
88       Nobody knows what f_fsid is supposed to contain (but see below).
89
90       Fields  that  are  undefined for a particular file system are set to 0.
91       fstatfs() returns the same information about an open file referenced by
92       descriptor fd.
93

RETURN VALUE

95       On  success,  zero is returned.  On error, -1 is returned, and errno is
96       set appropriately.
97

ERRORS

99       EACCES (statfs()) Search permission is denied for a  component  of  the
100              path prefix of path.  (See also path_resolution(7).)
101
102       EBADF  (fstatfs()) fd is not a valid open file descriptor.
103
104       EFAULT buf or path points to an invalid address.
105
106       EINTR  This call was interrupted by a signal.
107
108       EIO    An I/O error occurred while reading from the file system.
109
110       ELOOP  (statfs()) Too many symbolic links were encountered in translat‐
111              ing path.
112
113       ENAMETOOLONG
114              (statfs()) path is too long.
115
116       ENOENT (statfs()) The file referred to by path does not exist.
117
118       ENOMEM Insufficient kernel memory was available.
119
120       ENOSYS The file system does not support this call.
121
122       ENOTDIR
123              (statfs()) A component of the path  prefix  of  path  is  not  a
124              directory.
125
126       EOVERFLOW
127              Some  values  were  too  large to be represented in the returned
128              struct.
129

CONFORMING TO

131       Linux-specific.  The Linux statfs() was inspired by the 4.4BSD one (but
132       they do not use the same structure).
133

NOTES

135       The  original  Linux  statfs()  and  fstatfs()  system  calls  were not
136       designed with extremely large file sizes in mind.  Subsequently,  Linux
137       2.6 added new statfs64() and fstatfs64() system calls that employ a new
138       structure, statfs64.  The new structure contains the same fields as the
139       original  statfs  structure,  but  the  sizes  of  various  fields  are
140       increased, to accommodate large file sizes.   The  glibc  statfs()  and
141       fstatfs()  wrapper functions transparently deal with the kernel differ‐
142       ences.
143
144       Some  systems  only  have  <sys/vfs.h>,   other   systems   also   have
145       <sys/statfs.h>,  where  the  former  includes  the latter.  So it seems
146       including the former is the best choice.
147
148       LSB has deprecated the library calls statfs() and fstatfs()  and  tells
149       us to use statvfs(2) and fstatvfs(2) instead.
150
151   The f_fsid field
152       Solaris,  Irix  and  POSIX have a system call statvfs(2) that returns a
153       struct statvfs (defined in <sys/statvfs.h>) containing an unsigned long
154       f_fsid.   Linux,  SunOS, HP-UX, 4.4BSD have a system call statfs() that
155       returns a struct statfs (defined in <sys/vfs.h>)  containing  a  fsid_t
156       f_fsid,  where  fsid_t  is defined as struct { int val[2]; }.  The same
157       holds for FreeBSD, except that it uses the include file <sys/mount.h>.
158
159       The general idea is that f_fsid contains some random  stuff  such  that
160       the  pair (f_fsid,ino) uniquely determines a file.  Some operating sys‐
161       tems use (a variation on) the device number, or the device number  com‐
162       bined  with the file-system type.  Several OSes restrict giving out the
163       f_fsid field to the  superuser  only  (and  zero  it  for  unprivileged
164       users), because this field is used in the filehandle of the file system
165       when NFS-exported, and giving it out is a security concern.
166
167       Under some operating systems the fsid can be used as second argument to
168       the sysfs(2) system call.
169

SEE ALSO

171       stat(2), statvfs(2), path_resolution(7)
172

COLOPHON

174       This  page  is  part of release 3.53 of the Linux man-pages project.  A
175       description of the project, and information about reporting  bugs,  can
176       be found at http://www.kernel.org/doc/man-pages/.
177
178
179
180Linux                             2010-11-21                         STATFS(2)
Impressum