1STATFS(2) Linux Programmer's Manual STATFS(2)
2
3
4
6 statfs, fstatfs - get file system statistics
7
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
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 struct statfs {
20 long f_type; /* type of file system (see below) */
21 long f_bsize; /* optimal transfer block size */
22 long f_blocks; /* total data blocks in file system */
23 long f_bfree; /* free blocks in fs */
24 long f_bavail; /* free blocks avail to non-superuser */
25 long f_files; /* total file nodes in file system */
26 long f_ffree; /* free file nodes in fs */
27 fsid_t f_fsid; /* file system id */
28 long f_namelen; /* maximum length of filenames */
29 };
30
31 File system types:
32
33 ADFS_SUPER_MAGIC 0xadf5
34 AFFS_SUPER_MAGIC 0xADFF
35 BEFS_SUPER_MAGIC 0x42465331
36 BFS_MAGIC 0x1BADFACE
37 CIFS_MAGIC_NUMBER 0xFF534D42
38 CODA_SUPER_MAGIC 0x73757245
39 COH_SUPER_MAGIC 0x012FF7B7
40 CRAMFS_MAGIC 0x28cd3d45
41 DEVFS_SUPER_MAGIC 0x1373
42 EFS_SUPER_MAGIC 0x00414A53
43 EXT_SUPER_MAGIC 0x137D
44 EXT2_OLD_SUPER_MAGIC 0xEF51
45 EXT2_SUPER_MAGIC 0xEF53
46 EXT3_SUPER_MAGIC 0xEF53
47 HFS_SUPER_MAGIC 0x4244
48 HPFS_SUPER_MAGIC 0xF995E849
49 HUGETLBFS_MAGIC 0x958458f6
50 ISOFS_SUPER_MAGIC 0x9660
51 JFFS2_SUPER_MAGIC 0x72b6
52 JFS_SUPER_MAGIC 0x3153464a
53 MINIX_SUPER_MAGIC 0x137F /* orig. minix */
54 MINIX_SUPER_MAGIC2 0x138F /* 30 char minix */
55 MINIX2_SUPER_MAGIC 0x2468 /* minix V2 */
56 MINIX2_SUPER_MAGIC2 0x2478 /* minix V2, 30 char names */
57 MSDOS_SUPER_MAGIC 0x4d44
58 NCP_SUPER_MAGIC 0x564c
59 NFS_SUPER_MAGIC 0x6969
60 NTFS_SB_MAGIC 0x5346544e
61 OPENPROM_SUPER_MAGIC 0x9fa1
62 PROC_SUPER_MAGIC 0x9fa0
63 QNX4_SUPER_MAGIC 0x002f
64 REISERFS_SUPER_MAGIC 0x52654973
65 ROMFS_MAGIC 0x7275
66 SMB_SUPER_MAGIC 0x517B
67 SYSV2_SUPER_MAGIC 0x012FF7B6
68 SYSV4_SUPER_MAGIC 0x012FF7B5
69 TMPFS_MAGIC 0x01021994
70 UDF_SUPER_MAGIC 0x15013346
71 UFS_MAGIC 0x00011954
72 USBDEVICE_SUPER_MAGIC 0x9fa2
73 VXFS_SUPER_MAGIC 0xa501FCF5
74 XENIX_SUPER_MAGIC 0x012FF7B4
75 XFS_SUPER_MAGIC 0x58465342
76 _XIAFS_SUPER_MAGIC 0x012FD16D
77
78 Nobody knows what f_fsid is supposed to contain (but see below).
79
80 Fields that are undefined for a particular file system are set to 0.
81 fstatfs() returns the same information about an open file referenced by
82 descriptor fd.
83
85 On success, zero is returned. On error, -1 is returned, and errno is
86 set appropriately.
87
89 EACCES (statfs()) Search permission is denied for a component of the
90 path prefix of path. (See also path_resolution(7).)
91
92 EBADF (fstatfs()) fd is not a valid open file descriptor.
93
94 EFAULT buf or path points to an invalid address.
95
96 EINTR This call was interrupted by a signal.
97
98 EIO An I/O error occurred while reading from the file system.
99
100 ELOOP (statfs()) Too many symbolic links were encountered in translatā
101 ing path.
102
103 ENAMETOOLONG
104 (statfs()) path is too long.
105
106 ENOENT (statfs()) The file referred to by path does not exist.
107
108 ENOMEM Insufficient kernel memory was available.
109
110 ENOSYS The file system does not support this call.
111
112 ENOTDIR
113 (statfs()) A component of the path prefix of path is not a
114 directory.
115
116 EOVERFLOW
117 Some values were too large to be represented in the returned
118 struct.
119
121 Linux-specific. The Linux statfs() was inspired by the 4.4BSD one (but
122 they do not use the same structure).
123
125 The kernel has system calls statfs(), fstatfs(), statfs64(), and
126 fstatfs64() to support this library call.
127
128 Some systems only have <sys/vfs.h>, other systems also have
129 <sys/statfs.h>, where the former includes the latter. So it seems
130 including the former is the best choice.
131
132 LSB has deprecated the library calls statfs() and fstatfs() and tells
133 us to use statvfs(2) and fstatvfs(2) instead.
134
135 The f_fsid field
136 Solaris, Irix and POSIX have a system call statvfs(2) that returns a
137 struct statvfs (defined in <sys/statvfs.h>) containing an unsigned long
138 f_fsid. Linux, SunOS, HP-UX, 4.4BSD have a system call statfs() that
139 returns a struct statfs (defined in <sys/vfs.h>) containing a fsid_t
140 f_fsid, where fsid_t is defined as struct { int val[2]; }. The same
141 holds for FreeBSD, except that it uses the include file <sys/mount.h>.
142
143 The general idea is that f_fsid contains some random stuff such that
144 the pair (f_fsid,ino) uniquely determines a file. Some OSes use (a
145 variation on) the device number, or the device number combined with the
146 file-system type. Several OSes restrict giving out the f_fsid field to
147 the superuser only (and zero it for unprivileged users), because this
148 field is used in the filehandle of the file system when NFS-exported,
149 and giving it out is a security concern.
150
151 Under some OSes the fsid can be used as second argument to the sysfs()
152 system call.
153
155 stat(2), statvfs(2), path_resolution(7)
156
158 This page is part of release 3.22 of the Linux man-pages project. A
159 description of the project, and information about reporting bugs, can
160 be found at http://www.kernel.org/doc/man-pages/.
161
162
163
164Linux 2004-06-23 STATFS(2)