OSDN Git Service

LDP: Update original to LDP v3.68
[linuxjm/LDP_man-pages.git] / original / 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 2010-11-21 "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 .sp
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 function
39 .BR statfs ()
40 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
48 .in +4n
49 .nf
50 #if __WORDSIZE == 32            /* System word size */
51 # define __SWORD_TYPE           int
52 #else /* __WORDSIZE == 64 */
53 # define __SWORD_TYPE           long int
54 #endif
55
56 struct statfs {
57     __SWORD_TYPE f_type;    /* type of filesystem (see below) */
58     __SWORD_TYPE f_bsize;   /* optimal transfer block size */
59     fsblkcnt_t   f_blocks;  /* total data blocks in filesystem */
60     fsblkcnt_t   f_bfree;   /* free blocks in fs */
61     fsblkcnt_t   f_bavail;  /* free blocks available to
62                                unprivileged user */
63     fsfilcnt_t   f_files;   /* total file nodes in filesystem */
64     fsfilcnt_t   f_ffree;   /* free file nodes in fs */
65     fsid_t       f_fsid;    /* filesystem id */
66     __SWORD_TYPE f_namelen; /* maximum length of filenames */
67     __SWORD_TYPE f_frsize;  /* fragment size (since Linux 2.6) */
68     __SWORD_TYPE f_spare[5];
69 };
70
71 Filesystem types:
72
73    ADFS_SUPER_MAGIC      0xadf5
74    AFFS_SUPER_MAGIC      0xADFF
75    BEFS_SUPER_MAGIC      0x42465331
76    BFS_MAGIC             0x1BADFACE
77    CIFS_MAGIC_NUMBER     0xFF534D42
78    CODA_SUPER_MAGIC      0x73757245
79    COH_SUPER_MAGIC       0x012FF7B7
80    CRAMFS_MAGIC          0x28cd3d45
81    DEVFS_SUPER_MAGIC     0x1373
82    EFS_SUPER_MAGIC       0x00414A53
83    EXT_SUPER_MAGIC       0x137D
84    EXT2_OLD_SUPER_MAGIC  0xEF51
85    EXT2_SUPER_MAGIC      0xEF53
86    EXT3_SUPER_MAGIC      0xEF53
87    EXT4_SUPER_MAGIC      0xEF53
88    HFS_SUPER_MAGIC       0x4244
89    HPFS_SUPER_MAGIC      0xF995E849
90    HUGETLBFS_MAGIC       0x958458f6
91    ISOFS_SUPER_MAGIC     0x9660
92    JFFS2_SUPER_MAGIC     0x72b6
93    JFS_SUPER_MAGIC       0x3153464a
94    MINIX_SUPER_MAGIC     0x137F /* orig. minix */
95    MINIX_SUPER_MAGIC2    0x138F /* 30 char minix */
96    MINIX2_SUPER_MAGIC    0x2468 /* minix V2 */
97    MINIX2_SUPER_MAGIC2   0x2478 /* minix V2, 30 char names */
98    MSDOS_SUPER_MAGIC     0x4d44
99    NCP_SUPER_MAGIC       0x564c
100    NFS_SUPER_MAGIC       0x6969
101    NTFS_SB_MAGIC         0x5346544e
102    OPENPROM_SUPER_MAGIC  0x9fa1
103    PROC_SUPER_MAGIC      0x9fa0
104    QNX4_SUPER_MAGIC      0x002f
105    REISERFS_SUPER_MAGIC  0x52654973
106    ROMFS_MAGIC           0x7275
107    SMB_SUPER_MAGIC       0x517B
108    SYSV2_SUPER_MAGIC     0x012FF7B6
109    SYSV4_SUPER_MAGIC     0x012FF7B5
110    TMPFS_MAGIC           0x01021994
111    UDF_SUPER_MAGIC       0x15013346
112    UFS_MAGIC             0x00011954
113    USBDEVICE_SUPER_MAGIC 0x9fa2
114    VXFS_SUPER_MAGIC      0xa501FCF5
115    XENIX_SUPER_MAGIC     0x012FF7B4
116    XFS_SUPER_MAGIC       0x58465342
117    _XIAFS_SUPER_MAGIC    0x012FD16D
118 .fi
119 .in
120 .PP
121 Nobody knows what
122 .I f_fsid
123 is supposed to contain (but see below).
124 .PP
125 Fields that are undefined for a particular filesystem are set to 0.
126 .BR fstatfs ()
127 returns the same information about an open file referenced by descriptor
128 .IR fd .
129 .SH RETURN VALUE
130 On success, zero is returned.
131 On error, \-1 is returned, and
132 .I errno
133 is set appropriately.
134 .SH ERRORS
135 .TP
136 .B EACCES
137 .RB ( statfs ())
138 Search permission is denied for a component of the path prefix of
139 .IR path .
140 (See also
141 .BR path_resolution (7).)
142 .TP
143 .B EBADF
144 .RB ( fstatfs ())
145 .I fd
146 is not a valid open file descriptor.
147 .TP
148 .B EFAULT
149 .I buf
150 or
151 .I path
152 points to an invalid address.
153 .TP
154 .B EINTR
155 This call was interrupted by a signal.
156 .TP
157 .B EIO
158 An I/O error occurred while reading from the filesystem.
159 .TP
160 .B ELOOP
161 .RB ( statfs ())
162 Too many symbolic links were encountered in translating
163 .IR path .
164 .TP
165 .B ENAMETOOLONG
166 .RB ( statfs ())
167 .I path
168 is too long.
169 .TP
170 .B ENOENT
171 .RB ( statfs ())
172 The file referred to by
173 .I path
174 does not exist.
175 .TP
176 .B ENOMEM
177 Insufficient kernel memory was available.
178 .TP
179 .B ENOSYS
180 The filesystem does not support this call.
181 .TP
182 .B ENOTDIR
183 .RB ( statfs ())
184 A component of the path prefix of
185 .I path
186 is not a directory.
187 .TP
188 .B EOVERFLOW
189 Some values were too large to be represented in the returned struct.
190 .SH CONFORMING TO
191 Linux-specific.
192 The Linux
193 .BR statfs ()
194 was inspired by the 4.4BSD one
195 (but they do not use the same structure).
196 .SH NOTES
197 The original Linux
198 .BR statfs ()
199 and
200 .BR fstatfs ()
201 system calls were not designed with extremely large file sizes in mind.
202 Subsequently, Linux 2.6
203 added new
204 .BR statfs64 ()
205 and
206 .BR fstatfs64 ()
207 system calls that employ a new structure,
208 .IR statfs64 .
209 The new structure contains the same fields as the original
210 .I statfs
211 structure, but the sizes of various fields are increased,
212 to accommodate large file sizes.
213 The glibc
214 .BR statfs ()
215 and
216 .BR fstatfs ()
217 wrapper functions transparently deal with the kernel differences.
218
219 Some systems only have \fI<sys/vfs.h>\fP, other systems also have
220 \fI<sys/statfs.h>\fP, where the former includes the latter.
221 So it seems
222 including the former is the best choice.
223
224 LSB has deprecated the library calls
225 .BR statfs ()
226 and
227 .BR fstatfs ()
228 and tells us to use
229 .BR statvfs (2)
230 and
231 .BR fstatvfs (2)
232 instead.
233 .SS The f_fsid field
234 Solaris, Irix and POSIX have a system call
235 .BR statvfs (2)
236 that returns a
237 .I "struct statvfs"
238 (defined in
239 .IR <sys/statvfs.h> )
240 containing an
241 .I "unsigned long"
242 .IR f_fsid .
243 Linux, SunOS, HP-UX, 4.4BSD have a system call
244 .BR statfs ()
245 that returns a
246 .I "struct statfs"
247 (defined in
248 .IR <sys/vfs.h> )
249 containing a
250 .I fsid_t
251 .IR f_fsid ,
252 where
253 .I fsid_t
254 is defined as
255 .IR "struct { int val[2]; }" .
256 The same holds for FreeBSD, except that it uses the include file
257 .IR <sys/mount.h> .
258
259 The general idea is that
260 .I f_fsid
261 contains some random stuff such that the pair
262 .RI ( f_fsid , ino )
263 uniquely determines a file.
264 Some operating systems use (a variation on) the device number, or the device number
265 combined with the filesystem type.
266 Several OSes restrict giving out the
267 .I f_fsid
268 field to the superuser only (and zero it for unprivileged users),
269 because this field is used in the filehandle of the filesystem
270 when NFS-exported, and giving it out is a security concern.
271 .LP
272 Under some operating systems the
273 .I fsid
274 can be used as second argument to the
275 .BR sysfs (2)
276 system call.
277 .SH SEE ALSO
278 .BR stat (2),
279 .BR statvfs (2),
280 .BR path_resolution (7)
281 .SH COLOPHON
282 This page is part of release 3.68 of the Linux
283 .I man-pages
284 project.
285 A description of the project,
286 information about reporting bugs,
287 and the latest version of this page,
288 can be found at
289 \%http://www.kernel.org/doc/man\-pages/.