]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/mount.h
dbb687214b50b74cc01c6ba25de7aa88b690ad4e
[apple/xnu.git] / bsd / sys / mount.h
1 /*
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
26 /*
27 * Copyright (c) 1989, 1991, 1993
28 * The Regents of the University of California. All rights reserved.
29 *
30 * Redistribution and use in source and binary forms, with or without
31 * modification, are permitted provided that the following conditions
32 * are met:
33 * 1. Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * 2. Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in the
37 * documentation and/or other materials provided with the distribution.
38 * 3. All advertising materials mentioning features or use of this software
39 * must display the following acknowledgement:
40 * This product includes software developed by the University of
41 * California, Berkeley and its contributors.
42 * 4. Neither the name of the University nor the names of its contributors
43 * may be used to endorse or promote products derived from this software
44 * without specific prior written permission.
45 *
46 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 * SUCH DAMAGE.
57 *
58 * @(#)mount.h 8.21 (Berkeley) 5/20/95
59 */
60
61 #ifndef _SYS_MOUNT_H_
62 #define _SYS_MOUNT_H_
63
64 #include <sys/appleapiopts.h>
65 #ifndef KERNEL
66 #include <sys/ucred.h>
67 #endif
68 #include <sys/queue.h>
69 #include <sys/lock.h>
70 #include <net/radix.h>
71 #include <sys/socket.h> /* XXX for AF_MAX */
72
73 typedef struct fsid { int32_t val[2]; } fsid_t; /* file system id type */
74
75 /*
76 * File identifier.
77 * These are unique per filesystem on a single machine.
78 */
79 #define MAXFIDSZ 16
80
81 struct fid {
82 u_short fid_len; /* length of data in bytes */
83 u_short fid_reserved; /* force longword alignment */
84 char fid_data[MAXFIDSZ]; /* data (variable length) */
85 };
86
87 /*
88 * file system statistics
89 */
90
91 #define MFSNAMELEN 15 /* length of fs type name, not inc. null */
92 #define MNAMELEN 90 /* length of buffer for returned name */
93
94 struct statfs {
95 short f_otype; /* TEMPORARY SHADOW COPY OF f_type */
96 short f_oflags; /* TEMPORARY SHADOW COPY OF f_flags */
97 long f_bsize; /* fundamental file system block size */
98 long f_iosize; /* optimal transfer block size */
99 long f_blocks; /* total data blocks in file system */
100 long f_bfree; /* free blocks in fs */
101 long f_bavail; /* free blocks avail to non-superuser */
102 long f_files; /* total file nodes in file system */
103 long f_ffree; /* free file nodes in fs */
104 fsid_t f_fsid; /* file system id */
105 uid_t f_owner; /* user that mounted the filesystem */
106 short f_reserved1; /* spare for later */
107 short f_type; /* type of filesystem */
108 long f_flags; /* copy of mount exported flags */
109 long f_reserved2[2]; /* reserved for future use */
110 char f_fstypename[MFSNAMELEN]; /* fs type name */
111 char f_mntonname[MNAMELEN]; /* directory on which mounted */
112 char f_mntfromname[MNAMELEN];/* mounted filesystem */
113 #if COMPAT_GETFSSTAT
114 char f_reserved3[0]; /* For alignment */
115 long f_reserved4[0]; /* For future use */
116 #else
117 char f_reserved3; /* For alignment */
118 long f_reserved4[4]; /* For future use */
119 #endif
120 };
121
122 #ifdef __APPLE_API_PRIVATE
123 /*
124 * Structure per mounted file system. Each mounted file system has an
125 * array of operations and an instance record. The file systems are
126 * put on a doubly linked list.
127 */
128 LIST_HEAD(vnodelst, vnode);
129
130 struct mount {
131 CIRCLEQ_ENTRY(mount) mnt_list; /* mount list */
132 struct vfsops *mnt_op; /* operations on fs */
133 struct vfsconf *mnt_vfc; /* configuration info */
134 struct vnode *mnt_vnodecovered; /* vnode we mounted on */
135 struct vnodelst mnt_vnodelist; /* list of vnodes this mount */
136 struct lock__bsd__ mnt_lock; /* mount structure lock */
137 int mnt_flag; /* flags */
138 int mnt_kern_flag; /* kernel only flags */
139 int mnt_maxsymlinklen; /* max size of short symlink */
140 struct statfs mnt_stat; /* cache of filesystem stats */
141 qaddr_t mnt_data; /* private data */
142 /* Cached values of the IO constraints for the device */
143 u_int32_t mnt_maxreadcnt; /* Max. byte count for read */
144 u_int32_t mnt_maxwritecnt; /* Max. byte count for write */
145 u_int16_t mnt_segreadcnt; /* Max. segment count for read */
146 u_int16_t mnt_segwritecnt; /* Max. segment count for write */
147 };
148 #endif /* __APPLE_API_PRIVATE */
149
150 /*
151 * User specifiable flags.
152 *
153 * Unmount uses MNT_FORCE flag.
154 */
155 #define MNT_RDONLY 0x00000001 /* read only filesystem */
156 #define MNT_SYNCHRONOUS 0x00000002 /* file system written synchronously */
157 #define MNT_NOEXEC 0x00000004 /* can't exec from filesystem */
158 #define MNT_NOSUID 0x00000008 /* don't honor setuid bits on fs */
159 #define MNT_NODEV 0x00000010 /* don't interpret special files */
160 #define MNT_UNION 0x00000020 /* union with underlying filesystem */
161 #define MNT_ASYNC 0x00000040 /* file system written asynchronously */
162 #define MNT_DONTBROWSE 0x00100000 /* file system is not appropriate path to user data */
163 #define MNT_UNKNOWNPERMISSIONS 0x00200000 /* no known mapping for uid/gid in permissions information on disk */
164 #define MNT_AUTOMOUNTED 0x00400000 /* filesystem was mounted by automounter */
165 #define MNT_JOURNALED 0x00800000 /* filesystem is journaled */
166
167 /*
168 * NFS export related mount flags.
169 */
170 #define MNT_EXRDONLY 0x00000080 /* exported read only */
171 #define MNT_EXPORTED 0x00000100 /* file system is exported */
172 #define MNT_DEFEXPORTED 0x00000200 /* exported to the world */
173 #define MNT_EXPORTANON 0x00000400 /* use anon uid mapping for everyone */
174 #define MNT_EXKERB 0x00000800 /* exported with Kerberos uid mapping */
175
176 /*
177 * Flags set by internal operations.
178 */
179 #define MNT_LOCAL 0x00001000 /* filesystem is stored locally */
180 #define MNT_QUOTA 0x00002000 /* quotas are enabled on filesystem */
181 #define MNT_ROOTFS 0x00004000 /* identifies the root filesystem */
182 #define MNT_DOVOLFS 0x00008000 /* FS supports volfs */
183 #define MNT_FIXEDSCRIPTENCODING 0x10000000 /* FS supports only fixed script encoding [HFS] */
184
185 /*
186 * XXX I think that this could now become (~(MNT_CMDFLAGS))
187 * but the 'mount' program may need changing to handle this.
188 */
189 #define MNT_VISFLAGMASK (MNT_RDONLY | MNT_SYNCHRONOUS | MNT_NOEXEC | \
190 MNT_NOSUID | MNT_NODEV | MNT_UNION | \
191 MNT_ASYNC | MNT_EXRDONLY | MNT_EXPORTED | \
192 MNT_DEFEXPORTED | MNT_EXPORTANON| MNT_EXKERB | \
193 MNT_LOCAL | MNT_QUOTA | \
194 MNT_ROOTFS | MNT_DOVOLFS | MNT_DONTBROWSE | \
195 MNT_UNKNOWNPERMISSIONS | MNT_AUTOMOUNTED | MNT_JOURNALED | MNT_FIXEDSCRIPTENCODING )
196 /*
197 * External filesystem command modifier flags.
198 * Unmount can use the MNT_FORCE flag.
199 * XXX These are not STATES and really should be somewhere else.
200 * External filesystem control flags.
201 */
202 #define MNT_UPDATE 0x00010000 /* not a real mount, just an update */
203 #define MNT_DELEXPORT 0x00020000 /* delete export host lists */
204 #define MNT_RELOAD 0x00040000 /* reload filesystem data */
205 #define MNT_FORCE 0x00080000 /* force unmount or readonly change */
206 #define MNT_CMDFLAGS (MNT_UPDATE|MNT_DELEXPORT|MNT_RELOAD|MNT_FORCE)
207
208 /*
209 * Internal filesystem control flags stored in mnt_kern_flag.
210 *
211 * MNTK_UNMOUNT locks the mount entry so that name lookup cannot proceed
212 * past the mount point. This keeps the subtree stable during mounts
213 * and unmounts.
214 */
215 #define MNTK_UNMOUNT 0x01000000 /* unmount in progress */
216 #define MNTK_MWAIT 0x02000000 /* waiting for unmount to finish */
217 #define MNTK_WANTRDWR 0x04000000 /* upgrade to read/write requested */
218 #if REV_ENDIAN_FS
219 #define MNT_REVEND 0x08000000 /* Reverse endian FS */
220 #endif /* REV_ENDIAN_FS */
221 /*
222 * Sysctl CTL_VFS definitions.
223 *
224 * Second level identifier specifies which filesystem. Second level
225 * identifier VFS_GENERIC returns information about all filesystems.
226 */
227 #define VFS_GENERIC 0 /* generic filesystem information */
228 #define VFS_NUMMNTOPS 1 /* int: total num of vfs mount/unmount operations */
229 /*
230 * Third level identifiers for VFS_GENERIC are given below; third
231 * level identifiers for specific filesystems are given in their
232 * mount specific header files.
233 */
234 #define VFS_MAXTYPENUM 1 /* int: highest defined filesystem type */
235 #define VFS_CONF 2 /* struct: vfsconf for filesystem given
236 as next argument */
237 /*
238 * Flags for various system call interfaces.
239 *
240 * waitfor flags to vfs_sync() and getfsstat()
241 */
242 #define MNT_WAIT 1 /* synchronously wait for I/O to complete */
243 #define MNT_NOWAIT 2 /* start all I/O, but do not wait for it */
244
245 /*
246 * Generic file handle
247 */
248 struct fhandle {
249 fsid_t fh_fsid; /* File system id of mount point */
250 struct fid fh_fid; /* File sys specific id */
251 };
252 typedef struct fhandle fhandle_t;
253
254 /*
255 * Export arguments for local filesystem mount calls.
256 */
257 struct export_args {
258 int ex_flags; /* export related flags */
259 uid_t ex_root; /* mapping for root uid */
260 struct ucred ex_anon; /* mapping for anonymous user */
261 struct sockaddr *ex_addr; /* net address to which exported */
262 int ex_addrlen; /* and the net address length */
263 struct sockaddr *ex_mask; /* mask of valid bits in saddr */
264 int ex_masklen; /* and the smask length */
265 };
266
267 #ifdef __APPLE_API_UNSTABLE
268 /*
269 * Filesystem configuration information. One of these exists for each
270 * type of filesystem supported by the kernel. These are searched at
271 * mount time to identify the requested filesystem.
272 */
273 struct vfsconf {
274 struct vfsops *vfc_vfsops; /* filesystem operations vector */
275 char vfc_name[MFSNAMELEN]; /* filesystem type name */
276 int vfc_typenum; /* historic filesystem type number */
277 int vfc_refcount; /* number mounted of this type */
278 int vfc_flags; /* permanent flags */
279 int (*vfc_mountroot)(void); /* if != NULL, routine to mount root */
280 struct vfsconf *vfc_next; /* next in list */
281 };
282
283 #endif /*__APPLE_API_UNSTABLE */
284
285 #ifdef KERNEL
286 #ifdef __APPLE_API_UNSTABLE
287 extern int maxvfsconf; /* highest defined filesystem type */
288 extern struct vfsconf *vfsconf; /* head of list of filesystem types */
289 extern int maxvfsslots; /* Maximum slots available to be used */
290 extern int numused_vfsslots; /* number of slots already used */
291
292 int vfsconf_add __P((struct vfsconf *));
293 int vfsconf_del __P((char *));
294
295 /*
296 * Operations supported on mounted file system.
297 */
298 #ifdef __STDC__
299 struct nameidata;
300 struct mbuf;
301 #endif
302
303 struct vfsops {
304 int (*vfs_mount) __P((struct mount *mp, char *path, caddr_t data,
305 struct nameidata *ndp, struct proc *p));
306 int (*vfs_start) __P((struct mount *mp, int flags,
307 struct proc *p));
308 int (*vfs_unmount) __P((struct mount *mp, int mntflags,
309 struct proc *p));
310 int (*vfs_root) __P((struct mount *mp, struct vnode **vpp));
311 int (*vfs_quotactl) __P((struct mount *mp, int cmds, uid_t uid,
312 caddr_t arg, struct proc *p));
313 int (*vfs_statfs) __P((struct mount *mp, struct statfs *sbp,
314 struct proc *p));
315 int (*vfs_sync) __P((struct mount *mp, int waitfor,
316 struct ucred *cred, struct proc *p));
317 int (*vfs_vget) __P((struct mount *mp, void *ino,
318 struct vnode **vpp));
319 int (*vfs_fhtovp) __P((struct mount *mp, struct fid *fhp,
320 struct mbuf *nam, struct vnode **vpp,
321 int *exflagsp, struct ucred **credanonp));
322 int (*vfs_vptofh) __P((struct vnode *vp, struct fid *fhp));
323 int (*vfs_init) __P((struct vfsconf *));
324 int (*vfs_sysctl) __P((int *, u_int, void *, size_t *, void *,
325 size_t, struct proc *));
326 };
327
328 #define VFS_MOUNT(MP, PATH, DATA, NDP, P) \
329 (*(MP)->mnt_op->vfs_mount)(MP, PATH, DATA, NDP, P)
330 #define VFS_START(MP, FLAGS, P) (*(MP)->mnt_op->vfs_start)(MP, FLAGS, P)
331 #define VFS_UNMOUNT(MP, FORCE, P) (*(MP)->mnt_op->vfs_unmount)(MP, FORCE, P)
332 #define VFS_ROOT(MP, VPP) (*(MP)->mnt_op->vfs_root)(MP, VPP)
333 #define VFS_QUOTACTL(MP,C,U,A,P) (*(MP)->mnt_op->vfs_quotactl)(MP, C, U, A, P)
334 #define VFS_STATFS(MP, SBP, P) (*(MP)->mnt_op->vfs_statfs)(MP, SBP, P)
335 #define VFS_SYNC(MP, WAIT, C, P) (*(MP)->mnt_op->vfs_sync)(MP, WAIT, C, P)
336 #define VFS_VGET(MP, INO, VPP) (*(MP)->mnt_op->vfs_vget)(MP, INO, VPP)
337 #define VFS_FHTOVP(MP, FIDP, NAM, VPP, EXFLG, CRED) \
338 (*(MP)->mnt_op->vfs_fhtovp)(MP, FIDP, NAM, VPP, EXFLG, CRED)
339 #define VFS_VPTOFH(VP, FIDP) (*(VP)->v_mount->mnt_op->vfs_vptofh)(VP, FIDP)
340
341 /*
342 * Network address lookup element
343 */
344 struct netcred {
345 struct radix_node netc_rnodes[2];
346 int netc_exflags;
347 struct ucred netc_anon;
348 };
349
350 /*
351 * Network export information
352 */
353 struct netexport {
354 struct netcred ne_defexported; /* Default export */
355 struct radix_node_head *ne_rtable[AF_MAX+1]; /* Individual exports */
356 };
357
358 /*
359 * exported vnode operations
360 */
361 int vfs_busy __P((struct mount *, int, struct slock *, struct proc *));
362 int vfs_export __P((struct mount *, struct netexport *,
363 struct export_args *));
364 struct netcred *vfs_export_lookup __P((struct mount *, struct netexport *,
365 struct mbuf *));
366 void vfs_getnewfsid __P((struct mount *));
367 struct mount *vfs_getvfs __P((fsid_t *));
368 int vfs_mountedon __P((struct vnode *));
369 void vfs_unbusy __P((struct mount *, struct proc *));
370 #ifdef __APPLE_API_PRIVATE
371 int vfs_mountroot __P((void));
372 int vfs_rootmountalloc __P((char *, char *, struct mount **));
373 void vfs_unmountall __P((void));
374 #endif /* __APPLE_API_PRIVATE */
375 extern CIRCLEQ_HEAD(mntlist, mount) mountlist;
376 extern struct slock mountlist_slock;
377
378 #endif /* __APPLE_API_UNSTABLE */
379 #else /* !KERNEL */
380
381 #include <sys/cdefs.h>
382
383 __BEGIN_DECLS
384 int fstatfs __P((int, struct statfs *));
385 int getfh __P((const char *, fhandle_t *));
386 int getfsstat __P((struct statfs *, long, int));
387 int getmntinfo __P((struct statfs **, int));
388 int mount __P((const char *, const char *, int, void *));
389 int statfs __P((const char *, struct statfs *));
390 int unmount __P((const char *, int));
391 int getvfsbyname __P((const char *, struct vfsconf *));
392 __END_DECLS
393
394 #endif /* KERNEL */
395 #endif /* !_SYS_MOUNT_H_ */