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