]> git.saurik.com Git - apple/xnu.git/blob - bsd/man/man2/getfsstat.2
xnu-1504.15.3.tar.gz
[apple/xnu.git] / bsd / man / man2 / getfsstat.2
1 .\" $NetBSD: getfsstat.2,v 1.6 1995/06/29 11:40:44 cgd Exp $
2 .\"
3 .\" Copyright (c) 1989, 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
5 .\"
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
8 .\" are met:
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. All advertising materials mentioning features or use of this software
15 .\" must display the following acknowledgement:
16 .\" This product includes software developed by the University of
17 .\" California, Berkeley and its contributors.
18 .\" 4. Neither the name of the University nor the names of its contributors
19 .\" may be used to endorse or promote products derived from this software
20 .\" without specific prior written permission.
21 .\"
22 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" SUCH DAMAGE.
33 .\"
34 .\" @(#)getfsstat.2 8.1 (Berkeley) 6/9/93
35 .\"
36 .Dd Oct 28, 2008
37 .Dt GETFSSTAT 2
38 .Os
39 .Sh NAME
40 .Nm getfsstat
41 .Nd get list of all mounted file systems
42 .Sh SYNOPSIS
43 .Fd #include <sys/param.h>
44 .Fd #include <sys/ucred.h>
45 .Fd #include <sys/mount.h>
46 .Ft int
47 .Fn getfsstat "struct statfs *buf" "int bufsize" "int flags"
48 .Sh TRANSITIIONAL SYNOPSIS (NOW DEPRECATED)
49 .Ft int
50 .br
51 .Fn getfsstat64 "struct statfs64 *buf" "int bufsize" "int flags" ;
52 .Sh DESCRIPTION
53 The
54 .Fn getfsstat
55 function returns information about all mounted file systems.
56 The
57 .Fa buf
58 argument is a pointer to an array of
59 .Xr statfs
60 structures.
61 .Pp
62 As of Mac OS X 10.6, the default size of the
63 .Ft ino_t
64 type is 64 bits (the macro
65 .Dv _DARWIN_FEATURE_64_BIT_INODE
66 will be defined).
67 While there is no
68 .Ft ino_t
69 type used in the
70 .Xr statfs
71 structure, the changes to
72 .Fn getfsstat
73 are grouped together with the 64-bit inode changes.
74 The string fields in the
75 .Xr statfs
76 structure are larger and the variant symbol
77 .Li _getfsstat$INODE64
78 will be automatically used.
79 The
80 .Xr statfs
81 structure is defined as:
82 .Bd -literal
83 typedef struct { int32_t val[2]; } fsid_t;
84
85 #define MFSTYPENAMELEN 16 /* length of fs type name including null */
86 #define MAXPATHLEN 1024
87 #define MNAMELEN MAXPATHLEN
88
89 struct statfs { /* when _DARWIN_FEATURE_64_BIT_INODE is defined */
90 uint32_t f_bsize; /* fundamental file system block size */
91 int32_t f_iosize; /* optimal transfer block size */
92 uint64_t f_blocks; /* total data blocks in file system */
93 uint64_t f_bfree; /* free blocks in fs */
94 uint64_t f_bavail; /* free blocks avail to non-superuser */
95 uint64_t f_files; /* total file nodes in file system */
96 uint64_t f_ffree; /* free file nodes in fs */
97 fsid_t f_fsid; /* file system id */
98 uid_t f_owner; /* user that mounted the filesystem */
99 uint32_t f_type; /* type of filesystem */
100 uint32_t f_flags; /* copy of mount exported flags */
101 uint32_t f_fssubtype; /* fs sub-type (flavor) */
102 char f_fstypename[MFSTYPENAMELEN]; /* fs type name */
103 char f_mntonname[MAXPATHLEN]; /* directory on which mounted */
104 char f_mntfromname[MAXPATHLEN]; /* mounted filesystem */
105 uint32_t f_reserved[8]; /* For future use */
106 };
107 .Ed
108 .Pp
109 (In 10.5, 64-bit
110 .Ft ino_t ,
111 larger
112 .Xr statfs
113 structure and variant symbol were available if the macro
114 .Dv _DARWIN_USE_64_BIT_INODE
115 is defined before any header files are included; this macro is optional in
116 10.6.)
117 .Pp
118 If the macro
119 .Dv _DARWIN_NO_64_BIT_INODE
120 is defined before any header files are included, or if the deployment target
121 is less than 10.6, the legacy
122 .Xr statfs
123 structure will be in effect.
124 The
125 .Ft ino_t
126 type will be 32 bits (the
127 .Dv _DARWIN_FEATURE_64_BIT_INODE
128 macro will not be defined), the strings in the
129 .Xr statfs
130 structure will be their smaller legacy size (and long mount paths may no longer
131 fit) and the undecorated symbol
132 .Li _getfsstat
133 will be used.
134 This legacy
135 .Fa statfs
136 structure is defined as:
137 .Bd -literal
138 #define MFSNAMELEN 15 /* length of fs type name, not inc. nul */
139 #define MNAMELEN 90 /* length of buffer for returned name */
140
141 struct statfs { /* when _DARWIN_FEATURE_64_BIT_INODE is NOT defined */
142 short f_otype; /* type of file system (reserved: zero) */
143 short f_oflags; /* copy of mount flags (reserved: zero) */
144 long f_bsize; /* fundamental file system block size */
145 long f_iosize; /* optimal transfer block size */
146 long f_blocks; /* total data blocks in file system */
147 long f_bfree; /* free blocks in fs */
148 long f_bavail; /* free blocks avail to non-superuser */
149 long f_files; /* total file nodes in file system */
150 long f_ffree; /* free file nodes in fs */
151 fsid_t f_fsid; /* file system id */
152 uid_t f_owner; /* user that mounted the file system */
153 short f_reserved1; /* reserved for future use */
154 short f_type; /* type of file system (reserved) */
155 long f_flags; /* copy of mount flags (reserved) */
156 long f_reserved2[2]; /* reserved for future use */
157 char f_fstypename[MFSNAMELEN]; /* fs type name */
158 char f_mntonname[MNAMELEN]; /* directory on which mounted */
159 char f_mntfromname[MNAMELEN]; /* mounted file system */
160 char f_reserved3; /* reserved for future use */
161 long f_reserved4[4]; /* reserved for future use */
162 };
163 .Ed
164 .Pp
165 Fields that are undefined for a particular file system are set to -1.
166 The buffer is filled with an array of
167 .Fa statfs
168 structures, one for each mounted file system
169 up to the size specified by
170 .Fa bufsize .
171 .Pp
172 If
173 .Fa buf
174 is given as NULL,
175 .Fn getfsstat
176 returns just the number of mounted file systems.
177 .Pp
178 If
179 .Fa flags
180 is set to
181 .Dv MNT_NOWAIT ,
182 .Fn getfsstat
183 will directly return the information retained in the kernel
184 to avoid delays caused by waiting for updated information from
185 a file system that is perhaps temporarily unable to respond.
186 Some of the information returned may be out of date, however; if
187 .Fa flags
188 is set to
189 .Dv MNT_WAIT
190 or
191 .Dv MNT_DWAIT
192 instead,
193 .Fn getfsstat
194 will request updated information from each mounted filesystem before
195 returning.
196 .Sh RETURN VALUES
197 Upon successful completion, the number of
198 .Fa statfs
199 structures is returned.
200 Otherwise, -1 is returned and the global variable
201 .Va errno
202 is set to indicate the error.
203 .Sh ERRORS
204 .Fn Getfsstat
205 fails if one or more of the following are true:
206 .Bl -tag -width Er
207 .It Bq Er EFAULT
208 The
209 .Fa buf
210 argument points to an invalid address.
211 .It Bq Er EIO
212 An
213 .Tn I/O
214 error occurred while reading from or writing to the file system.
215 .El
216 .Sh TRANSITIONAL DESCRIPTION (NOW DEPRECATED)
217 The
218 .Fn getfsstat64
219 routine is equivalent to the default
220 .Fn getfstat
221 (when
222 .Dv _DARWIN_FEATURE_64_BIT_INODE
223 is defined), so there is no longer any reason to use it (it will be removed
224 in the future).
225 .Sh SEE ALSO
226 .Xr statfs 2 ,
227 .Xr fstab 5 ,
228 .Xr mount 8
229 .Sh HISTORY
230 The
231 .Fn getfsstat
232 function first appeared in 4.4BSD.