OSDN Git Service

(split) LDP man-pages の original/ を v3.29 に更新。
[linuxjm/LDP_man-pages.git] / original / man2 / statfs.2
1 .\" Copyright (C) 2003 Andries Brouwer (aeb@cwi.nl)
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein.  The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .\" Modified 2003-08-17 by Walter Harms
24 .\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
25 .\"
26 .TH STATFS 2 2010-09-04 "Linux" "Linux Programmer's Manual"
27 .SH NAME
28 statfs, fstatfs \- get file system statistics
29 .SH SYNOPSIS
30 .BR "#include <sys/vfs.h>    " "/* or <sys/statfs.h> */"
31 .sp
32 .BI "int statfs(const char *" path ", struct statfs *" buf );
33 .br
34 .BI "int fstatfs(int " fd ", struct statfs *" buf );
35 .SH DESCRIPTION
36 The function
37 .BR statfs ()
38 returns information about a mounted file system.
39 .I path
40 is the pathname of any file within the mounted file system.
41 .I buf
42 is a pointer to a
43 .I statfs
44 structure defined approximately as follows:
45
46 .in +4n
47 .nf
48 #if __WORDSIZE == 32            /* System word size */
49 # define __SWORD_TYPE           int
50 #else /* __WORDSIZE == 64 */
51 # define __SWORD_TYPE           long int
52 #endif
53
54 struct statfs {
55     __SWORD_TYPE f_type;    /* type of file system (see below) */
56     __SWORD_TYPE f_bsize;   /* optimal transfer block size */
57     fsblkcnt_t   f_blocks;  /* total data blocks in file system */
58     fsblkcnt_t   f_bfree;   /* free blocks in fs */
59     fsblkcnt_t   f_bavail;  /* free blocks available to
60                                unprivileged user */
61     fsfilcnt_t   f_files;   /* total file nodes in file system */
62     fsfilcnt_t   f_ffree;   /* free file nodes in fs */
63     fsid_t       f_fsid;    /* file system id */
64     __SWORD_TYPE f_namelen; /* maximum length of filenames */
65     __SWORD_TYPE f_frsize;  /* fragment size (since Linux 2.6) */
66     __SWORD_TYPE f_spare[5];
67 };
68
69 File system types:
70
71    ADFS_SUPER_MAGIC      0xadf5
72    AFFS_SUPER_MAGIC      0xADFF
73    BEFS_SUPER_MAGIC      0x42465331
74    BFS_MAGIC             0x1BADFACE
75    CIFS_MAGIC_NUMBER     0xFF534D42
76    CODA_SUPER_MAGIC      0x73757245
77    COH_SUPER_MAGIC       0x012FF7B7
78    CRAMFS_MAGIC          0x28cd3d45
79    DEVFS_SUPER_MAGIC     0x1373
80    EFS_SUPER_MAGIC       0x00414A53
81    EXT_SUPER_MAGIC       0x137D
82    EXT2_OLD_SUPER_MAGIC  0xEF51
83    EXT2_SUPER_MAGIC      0xEF53
84    EXT3_SUPER_MAGIC      0xEF53
85    EXT4_SUPER_MAGIC      0xEF53
86    HFS_SUPER_MAGIC       0x4244
87    HPFS_SUPER_MAGIC      0xF995E849
88    HUGETLBFS_MAGIC       0x958458f6
89    ISOFS_SUPER_MAGIC     0x9660
90    JFFS2_SUPER_MAGIC     0x72b6
91    JFS_SUPER_MAGIC       0x3153464a
92    MINIX_SUPER_MAGIC     0x137F /* orig. minix */
93    MINIX_SUPER_MAGIC2    0x138F /* 30 char minix */
94    MINIX2_SUPER_MAGIC    0x2468 /* minix V2 */
95    MINIX2_SUPER_MAGIC2   0x2478 /* minix V2, 30 char names */
96    MSDOS_SUPER_MAGIC     0x4d44
97    NCP_SUPER_MAGIC       0x564c
98    NFS_SUPER_MAGIC       0x6969
99    NTFS_SB_MAGIC         0x5346544e
100    OPENPROM_SUPER_MAGIC  0x9fa1
101    PROC_SUPER_MAGIC      0x9fa0
102    QNX4_SUPER_MAGIC      0x002f
103    REISERFS_SUPER_MAGIC  0x52654973
104    ROMFS_MAGIC           0x7275
105    SMB_SUPER_MAGIC       0x517B
106    SYSV2_SUPER_MAGIC     0x012FF7B6
107    SYSV4_SUPER_MAGIC     0x012FF7B5
108    TMPFS_MAGIC           0x01021994
109    UDF_SUPER_MAGIC       0x15013346
110    UFS_MAGIC             0x00011954
111    USBDEVICE_SUPER_MAGIC 0x9fa2
112    VXFS_SUPER_MAGIC      0xa501FCF5
113    XENIX_SUPER_MAGIC     0x012FF7B4
114    XFS_SUPER_MAGIC       0x58465342
115    _XIAFS_SUPER_MAGIC    0x012FD16D
116 .fi
117 .in
118 .PP
119 Nobody knows what
120 .I f_fsid
121 is supposed to contain (but see below).
122 .PP
123 Fields that are undefined for a particular file system are set to 0.
124 .BR fstatfs ()
125 returns the same information about an open file referenced by descriptor
126 .IR fd .
127 .SH "RETURN VALUE"
128 On success, zero is returned.
129 On error, \-1 is returned, and
130 .I errno
131 is set appropriately.
132 .SH ERRORS
133 .TP
134 .B EACCES
135 .RB ( statfs ())
136 Search permission is denied for a component of the path prefix of
137 .IR path .
138 (See also
139 .BR path_resolution (7).)
140 .TP
141 .B EBADF
142 .RB ( fstatfs ())
143 .I fd
144 is not a valid open file descriptor.
145 .TP
146 .B EFAULT
147 .I buf
148 or
149 .I path
150 points to an invalid address.
151 .TP
152 .B EINTR
153 This call was interrupted by a signal.
154 .TP
155 .B EIO
156 An I/O error occurred while reading from the file system.
157 .TP
158 .B ELOOP
159 .RB ( statfs ())
160 Too many symbolic links were encountered in translating
161 .IR path .
162 .TP
163 .B ENAMETOOLONG
164 .RB ( statfs ())
165 .I path
166 is too long.
167 .TP
168 .B ENOENT
169 .RB ( statfs ())
170 The file referred to by
171 .I path
172 does not exist.
173 .TP
174 .B ENOMEM
175 Insufficient kernel memory was available.
176 .TP
177 .B ENOSYS
178 The file system does not support this call.
179 .TP
180 .B ENOTDIR
181 .RB ( statfs ())
182 A component of the path prefix of
183 .I path
184 is not a directory.
185 .TP
186 .B EOVERFLOW
187 Some values were too large to be represented in the returned struct.
188 .SH "CONFORMING TO"
189 Linux-specific.
190 The Linux
191 .BR statfs ()
192 was inspired by the 4.4BSD one
193 (but they do not use the same structure).
194 .SH NOTES
195 The kernel has system calls
196 .BR statfs (),
197 .BR fstatfs (),
198 .BR statfs64 (),
199 and
200 .BR fstatfs64 ()
201 to support this library call.
202
203 Some systems only have \fI<sys/vfs.h>\fP, other systems also have
204 \fI<sys/statfs.h>\fP, where the former includes the latter.
205 So it seems
206 including the former is the best choice.
207
208 LSB has deprecated the library calls
209 .BR statfs ()
210 and
211 .BR fstatfs ()
212 and tells us to use
213 .BR statvfs (2)
214 and
215 .BR fstatvfs (2)
216 instead.
217 .SS The f_fsid field
218 Solaris, Irix and POSIX have a system call
219 .BR statvfs (2)
220 that returns a
221 .I "struct statvfs"
222 (defined in
223 .IR <sys/statvfs.h> )
224 containing an
225 .I "unsigned long"
226 .IR f_fsid .
227 Linux, SunOS, HP-UX, 4.4BSD have a system call
228 .BR statfs ()
229 that returns a
230 .I "struct statfs"
231 (defined in
232 .IR <sys/vfs.h> )
233 containing a
234 .I fsid_t
235 .IR f_fsid ,
236 where
237 .I fsid_t
238 is defined as
239 .IR "struct { int val[2]; }" .
240 The same holds for FreeBSD, except that it uses the include file
241 .IR <sys/mount.h> .
242
243 The general idea is that
244 .I f_fsid
245 contains some random stuff such that the pair
246 .RI ( f_fsid , ino )
247 uniquely determines a file.
248 Some operating systems use (a variation on) the device number, or the device number
249 combined with the file-system type.
250 Several OSes restrict giving out the
251 .I f_fsid
252 field to the superuser only (and zero it for unprivileged users),
253 because this field is used in the filehandle of the file system
254 when NFS-exported, and giving it out is a security concern.
255 .LP
256 Under some OSes the
257 .I fsid
258 can be used as second argument to the
259 .BR sysfs ()
260 system call.
261 .SH "SEE ALSO"
262 .BR stat (2),
263 .BR statvfs (2),
264 .BR path_resolution (7)