]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/mount.h
xnu-517.7.7.tar.gz
[apple/xnu.git] / bsd / sys / mount.h
1 /*
2 * Copyright (c) 2000-2004 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 #include <sys/appleapiopts.h>
62 #ifndef KERNEL
63 #include <sys/ucred.h>
64 #endif
65 #include <sys/queue.h>
66 #include <sys/lock.h>
67 #include <net/radix.h>
68 #include <sys/socket.h> /* XXX for AF_MAX */
69
70 typedef struct fsid { int32_t val[2]; } fsid_t; /* file system id type */
71
72 /*
73 * File identifier.
74 * These are unique per filesystem on a single machine.
75 */
76 #define MAXFIDSZ 16
77
78 struct fid {
79 u_short fid_len; /* length of data in bytes */
80 u_short fid_reserved; /* force longword alignment */
81 char fid_data[MAXFIDSZ]; /* data (variable length) */
82 };
83
84 /*
85 * file system statistics
86 */
87
88 #define MFSNAMELEN 15 /* length of fs type name, not inc. null */
89 #define MNAMELEN 90 /* length of buffer for returned name */
90
91 struct statfs {
92 short f_otype; /* TEMPORARY SHADOW COPY OF f_type */
93 short f_oflags; /* TEMPORARY SHADOW COPY OF f_flags */
94 long f_bsize; /* fundamental file system block size */
95 long f_iosize; /* optimal transfer block size */
96 long f_blocks; /* total data blocks in file system */
97 long f_bfree; /* free blocks in fs */
98 long f_bavail; /* free blocks avail to non-superuser */
99 long f_files; /* total file nodes in file system */
100 long f_ffree; /* free file nodes in fs */
101 fsid_t f_fsid; /* file system id */
102 uid_t f_owner; /* user that mounted the filesystem */
103 short f_reserved1; /* spare for later */
104 short f_type; /* type of filesystem */
105 long f_flags; /* copy of mount exported flags */
106 long f_reserved2[2]; /* reserved for future use */
107 char f_fstypename[MFSNAMELEN]; /* fs type name */
108 char f_mntonname[MNAMELEN]; /* directory on which mounted */
109 char f_mntfromname[MNAMELEN];/* mounted filesystem */
110 #if COMPAT_GETFSSTAT
111 char f_reserved3[0]; /* For alignment */
112 long f_reserved4[0]; /* For future use */
113 #else
114 char f_reserved3; /* For alignment */
115 long f_reserved4[4]; /* For future use */
116 #endif
117 };
118
119 #ifdef __APPLE_API_PRIVATE
120 /*
121 * Structure per mounted file system. Each mounted file system has an
122 * array of operations and an instance record. The file systems are
123 * put on a doubly linked list.
124 */
125 LIST_HEAD(vnodelst, vnode);
126
127 struct mount {
128 CIRCLEQ_ENTRY(mount) mnt_list; /* mount list */
129 struct vfsops *mnt_op; /* operations on fs */
130 struct vfsconf *mnt_vfc; /* configuration info */
131 struct vnode *mnt_vnodecovered; /* vnode we mounted on */
132 struct vnodelst mnt_vnodelist; /* list of vnodes this mount */
133 struct lock__bsd__ mnt_lock; /* mount structure lock */
134 int mnt_flag; /* flags */
135 int mnt_kern_flag; /* kernel only flags */
136 int mnt_maxsymlinklen; /* max size of short symlink */
137 struct statfs mnt_stat; /* cache of filesystem stats */
138 qaddr_t mnt_data; /* private data */
139 /* Cached values of the IO constraints for the device */
140 union {
141 u_int32_t mntu_maxreadcnt; /* Max. byte count for read */
142 void *mntu_xinfo_ptr; /* points at extended IO constraints */
143 } mnt_un; /* if MNTK_IO_XINFO is set */
144 #define mnt_maxreadcnt mnt_un.mntu_maxreadcnt
145 #define mnt_xinfo_ptr mnt_un.mntu_xinfo_ptr
146 u_int32_t mnt_maxwritecnt; /* Max. byte count for write */
147 u_int16_t mnt_segreadcnt; /* Max. segment count for read */
148 u_int16_t mnt_segwritecnt; /* Max. segment count for write */
149 };
150 #endif /* __APPLE_API_PRIVATE */
151
152 /*
153 * User specifiable flags.
154 *
155 * Unmount uses MNT_FORCE flag.
156 */
157 #define MNT_RDONLY 0x00000001 /* read only filesystem */
158 #define MNT_SYNCHRONOUS 0x00000002 /* file system written synchronously */
159 #define MNT_NOEXEC 0x00000004 /* can't exec from filesystem */
160 #define MNT_NOSUID 0x00000008 /* don't honor setuid bits on fs */
161 #define MNT_NODEV 0x00000010 /* don't interpret special files */
162 #define MNT_UNION 0x00000020 /* union with underlying filesystem */
163 #define MNT_ASYNC 0x00000040 /* file system written asynchronously */
164 #define MNT_DONTBROWSE 0x00100000 /* file system is not appropriate path to user data */
165 #define MNT_UNKNOWNPERMISSIONS 0x00200000 /* no known mapping for uid/gid in permissions information on disk */
166 #define MNT_AUTOMOUNTED 0x00400000 /* filesystem was mounted by automounter */
167 #define MNT_JOURNALED 0x00800000 /* filesystem is journaled */
168
169 /*
170 * NFS export related mount flags.
171 */
172 #define MNT_EXRDONLY 0x00000080 /* exported read only */
173 #define MNT_EXPORTED 0x00000100 /* file system is exported */
174 #define MNT_DEFEXPORTED 0x00000200 /* exported to the world */
175 #define MNT_EXPORTANON 0x00000400 /* use anon uid mapping for everyone */
176 #define MNT_EXKERB 0x00000800 /* exported with Kerberos uid mapping */
177
178 /*
179 * Flags set by internal operations.
180 */
181 #define MNT_LOCAL 0x00001000 /* filesystem is stored locally */
182 #define MNT_QUOTA 0x00002000 /* quotas are enabled on filesystem */
183 #define MNT_ROOTFS 0x00004000 /* identifies the root filesystem */
184 #define MNT_DOVOLFS 0x00008000 /* FS supports volfs */
185 #define MNT_FIXEDSCRIPTENCODING 0x10000000 /* FS supports only fixed script encoding [HFS] */
186
187 /*
188 * XXX I think that this could now become (~(MNT_CMDFLAGS))
189 * but the 'mount' program may need changing to handle this.
190 */
191 #define MNT_VISFLAGMASK (MNT_RDONLY | MNT_SYNCHRONOUS | MNT_NOEXEC | \
192 MNT_NOSUID | MNT_NODEV | MNT_UNION | \
193 MNT_ASYNC | MNT_EXRDONLY | MNT_EXPORTED | \
194 MNT_DEFEXPORTED | MNT_EXPORTANON| MNT_EXKERB | \
195 MNT_LOCAL | MNT_QUOTA | \
196 MNT_ROOTFS | MNT_DOVOLFS | MNT_DONTBROWSE | \
197 MNT_UNKNOWNPERMISSIONS | MNT_AUTOMOUNTED | MNT_JOURNALED | MNT_FIXEDSCRIPTENCODING )
198 /*
199 * External filesystem command modifier flags.
200 * Unmount can use the MNT_FORCE flag.
201 * XXX These are not STATES and really should be somewhere else.
202 * External filesystem control flags.
203 */
204 #define MNT_UPDATE 0x00010000 /* not a real mount, just an update */
205 #define MNT_DELEXPORT 0x00020000 /* delete export host lists */
206 #define MNT_RELOAD 0x00040000 /* reload filesystem data */
207 #define MNT_FORCE 0x00080000 /* force unmount or readonly change */
208 #define MNT_CMDFLAGS (MNT_UPDATE|MNT_DELEXPORT|MNT_RELOAD|MNT_FORCE)
209
210 /*
211 * Internal filesystem control flags stored in mnt_kern_flag.
212 *
213 * MNTK_UNMOUNT locks the mount entry so that name lookup cannot proceed
214 * past the mount point. This keeps the subtree stable during mounts
215 * and unmounts.
216 */
217 #define MNTK_VIRTUALDEV 0x00200000 /* mounted on a virtual device i.e. a disk image */
218 #define MNTK_ROOTDEV 0x00400000 /* this filesystem resides on the same device as the root */
219 #define MNTK_IO_XINFO 0x00800000 /* mnt_un.mntu_ioptr has a malloc associated with it */
220 #define MNTK_UNMOUNT 0x01000000 /* unmount in progress */
221 #define MNTK_MWAIT 0x02000000 /* waiting for unmount to finish */
222 #define MNTK_WANTRDWR 0x04000000 /* upgrade to read/write requested */
223 #if REV_ENDIAN_FS
224 #define MNT_REVEND 0x08000000 /* Reverse endian FS */
225 #endif /* REV_ENDIAN_FS */
226 #define MNTK_FRCUNMOUNT 0x10000000 /* Forced unmount wanted. */
227 /*
228 * Sysctl CTL_VFS definitions.
229 *
230 * Second level identifier specifies which filesystem. Second level
231 * identifier VFS_GENERIC returns information about all filesystems.
232 */
233 #define VFS_GENERIC 0 /* generic filesystem information */
234 #define VFS_NUMMNTOPS 1 /* int: total num of vfs mount/unmount operations */
235 /*
236 * Third level identifiers for VFS_GENERIC are given below; third
237 * level identifiers for specific filesystems are given in their
238 * mount specific header files.
239 */
240 #define VFS_MAXTYPENUM 1 /* int: highest defined filesystem type */
241 #define VFS_CONF 2 /* struct: vfsconf for filesystem given
242 as next argument */
243 #define VFS_FMOD_WATCH 3 /* block waiting for the next modified file */
244 #define VFS_FMOD_WATCH_ENABLE 4 /* 1==enable, 0==disable */
245
246 /*
247 * Flags for various system call interfaces.
248 *
249 * waitfor flags to vfs_sync() and getfsstat()
250 */
251 #define MNT_WAIT 1 /* synchronously wait for I/O to complete */
252 #define MNT_NOWAIT 2 /* start all I/O, but do not wait for it */
253
254 /*
255 * Generic file handle
256 */
257 struct fhandle {
258 fsid_t fh_fsid; /* File system id of mount point */
259 struct fid fh_fid; /* File sys specific id */
260 };
261 typedef struct fhandle fhandle_t;
262
263 /*
264 * Export arguments for local filesystem mount calls.
265 */
266 struct export_args {
267 int ex_flags; /* export related flags */
268 uid_t ex_root; /* mapping for root uid */
269 struct ucred ex_anon; /* mapping for anonymous user */
270 struct sockaddr *ex_addr; /* net address to which exported */
271 int ex_addrlen; /* and the net address length */
272 struct sockaddr *ex_mask; /* mask of valid bits in saddr */
273 int ex_masklen; /* and the smask length */
274 };
275
276 #ifdef __APPLE_API_UNSTABLE
277 /*
278 * Filesystem configuration information. One of these exists for each
279 * type of filesystem supported by the kernel. These are searched at
280 * mount time to identify the requested filesystem.
281 */
282 struct vfsconf {
283 struct vfsops *vfc_vfsops; /* filesystem operations vector */
284 char vfc_name[MFSNAMELEN]; /* filesystem type name */
285 int vfc_typenum; /* historic filesystem type number */
286 int vfc_refcount; /* number mounted of this type */
287 int vfc_flags; /* permanent flags */
288 int (*vfc_mountroot)(void); /* if != NULL, routine to mount root */
289 struct vfsconf *vfc_next; /* next in list */
290 };
291
292 #endif /*__APPLE_API_UNSTABLE */
293
294 struct vfsidctl {
295 int vc_vers; /* should be VFSIDCTL_VERS1 (below) */
296 fsid_t vc_fsid; /* fsid to operate on. */
297 void *vc_ptr; /* pointer to data structure. */
298 size_t vc_len; /* sizeof said structure. */
299 u_int32_t vc_spare[12]; /* spare (must be zero). */
300 };
301
302 /* vfsidctl API version. */
303 #define VFS_CTL_VERS1 0x01
304
305 /*
306 * New style VFS sysctls, do not reuse/conflict with the namespace for
307 * private sysctls.
308 */
309 #define VFS_CTL_STATFS 0x00010001 /* statfs */
310 #define VFS_CTL_UMOUNT 0x00010002 /* unmount */
311 #define VFS_CTL_QUERY 0x00010003 /* anything wrong? (vfsquery) */
312 #define VFS_CTL_NEWADDR 0x00010004 /* reconnect to new address */
313 #define VFS_CTL_TIMEO 0x00010005 /* set timeout for vfs notification */
314 #define VFS_CTL_NOLOCKS 0x00010006 /* disable file locking */
315
316 struct vfsquery {
317 u_int32_t vq_flags;
318 u_int32_t vq_spare[31];
319 };
320
321 /* vfsquery flags */
322 #define VQ_NOTRESP 0x0001 /* server down */
323 #define VQ_NEEDAUTH 0x0002 /* server bad auth */
324 #define VQ_LOWDISK 0x0004 /* we're low on space */
325 #define VQ_MOUNT 0x0008 /* new filesystem arrived */
326 #define VQ_UNMOUNT 0x0010 /* filesystem has left */
327 #define VQ_DEAD 0x0020 /* filesystem is dead, needs force unmount */
328 #define VQ_ASSIST 0x0040 /* filesystem needs assistance from external
329 program */
330 #define VQ_NOTRESPLOCK 0x0080 /* server lockd down */
331 #define VQ_FLAG0100 0x0100 /* placeholder */
332 #define VQ_FLAG0200 0x0200 /* placeholder */
333 #define VQ_FLAG0400 0x0400 /* placeholder */
334 #define VQ_FLAG0800 0x0800 /* placeholder */
335 #define VQ_FLAG1000 0x1000 /* placeholder */
336 #define VQ_FLAG2000 0x2000 /* placeholder */
337 #define VQ_FLAG4000 0x4000 /* placeholder */
338 #define VQ_FLAG8000 0x8000 /* placeholder */
339
340 #ifdef KERNEL
341 /* Point a sysctl request at a vfsidctl's data. */
342 #define VCTLTOREQ(vc, req) \
343 do { \
344 (req)->newptr = (vc)->vc_ptr; \
345 (req)->newlen = (vc)->vc_len; \
346 (req)->newidx = 0; \
347 } while (0)
348 #endif
349
350 #ifdef KERNEL
351 #ifdef __APPLE_API_UNSTABLE
352 extern int maxvfsconf; /* highest defined filesystem type */
353 extern struct vfsconf *vfsconf; /* head of list of filesystem types */
354 extern int maxvfsslots; /* Maximum slots available to be used */
355 extern int numused_vfsslots; /* number of slots already used */
356
357 int vfsconf_add __P((struct vfsconf *));
358 int vfsconf_del __P((char *));
359
360 /*
361 * Operations supported on mounted file system.
362 */
363 #ifdef __STDC__
364 struct nameidata;
365 struct mbuf;
366 #endif
367
368 struct vfsops {
369 int (*vfs_mount) __P((struct mount *mp, char *path, caddr_t data,
370 struct nameidata *ndp, struct proc *p));
371 int (*vfs_start) __P((struct mount *mp, int flags,
372 struct proc *p));
373 int (*vfs_unmount) __P((struct mount *mp, int mntflags,
374 struct proc *p));
375 int (*vfs_root) __P((struct mount *mp, struct vnode **vpp));
376 int (*vfs_quotactl) __P((struct mount *mp, int cmds, uid_t uid,
377 caddr_t arg, struct proc *p));
378 int (*vfs_statfs) __P((struct mount *mp, struct statfs *sbp,
379 struct proc *p));
380 int (*vfs_sync) __P((struct mount *mp, int waitfor,
381 struct ucred *cred, struct proc *p));
382 int (*vfs_vget) __P((struct mount *mp, void *ino,
383 struct vnode **vpp));
384 int (*vfs_fhtovp) __P((struct mount *mp, struct fid *fhp,
385 struct mbuf *nam, struct vnode **vpp,
386 int *exflagsp, struct ucred **credanonp));
387 int (*vfs_vptofh) __P((struct vnode *vp, struct fid *fhp));
388 int (*vfs_init) __P((struct vfsconf *));
389 int (*vfs_sysctl) __P((int *, u_int, void *, size_t *, void *,
390 size_t, struct proc *));
391 };
392
393 #define VFS_MOUNT(MP, PATH, DATA, NDP, P) \
394 (*(MP)->mnt_op->vfs_mount)(MP, PATH, DATA, NDP, P)
395 #define VFS_START(MP, FLAGS, P) (*(MP)->mnt_op->vfs_start)(MP, FLAGS, P)
396 #define VFS_UNMOUNT(MP, FORCE, P) (*(MP)->mnt_op->vfs_unmount)(MP, FORCE, P)
397 #define VFS_ROOT(MP, VPP) (*(MP)->mnt_op->vfs_root)(MP, VPP)
398 #define VFS_QUOTACTL(MP,C,U,A,P) (*(MP)->mnt_op->vfs_quotactl)(MP, C, U, A, P)
399 #define VFS_STATFS(MP, SBP, P) (*(MP)->mnt_op->vfs_statfs)(MP, SBP, P)
400 #define VFS_SYNC(MP, WAIT, C, P) (*(MP)->mnt_op->vfs_sync)(MP, WAIT, C, P)
401 #define VFS_VGET(MP, INO, VPP) (*(MP)->mnt_op->vfs_vget)(MP, INO, VPP)
402 #define VFS_FHTOVP(MP, FIDP, NAM, VPP, EXFLG, CRED) \
403 (*(MP)->mnt_op->vfs_fhtovp)(MP, FIDP, NAM, VPP, EXFLG, CRED)
404 #define VFS_VPTOFH(VP, FIDP) (*(VP)->v_mount->mnt_op->vfs_vptofh)(VP, FIDP)
405
406 /*
407 * Network address lookup element
408 */
409 struct netcred {
410 struct radix_node netc_rnodes[2];
411 int netc_exflags;
412 struct ucred netc_anon;
413 };
414
415 /*
416 * Network export information
417 */
418 struct netexport {
419 struct netcred ne_defexported; /* Default export */
420 struct radix_node_head *ne_rtable[AF_MAX+1]; /* Individual exports */
421 };
422
423 /*
424 * exported vnode operations
425 */
426 int vfs_busy __P((struct mount *, int, struct slock *, struct proc *));
427 int vfs_export __P((struct mount *, struct netexport *,
428 struct export_args *));
429 struct netcred *vfs_export_lookup __P((struct mount *, struct netexport *,
430 struct mbuf *));
431 void vfs_getnewfsid __P((struct mount *));
432 struct mount *vfs_getvfs __P((fsid_t *));
433 int vfs_mountedon __P((struct vnode *));
434 void vfs_unbusy __P((struct mount *, struct proc *));
435 #ifdef __APPLE_API_PRIVATE
436 int vfs_mountroot __P((void));
437 int vfs_rootmountalloc __P((char *, char *, struct mount **));
438 void vfs_unmountall __P((void));
439 int safedounmount(struct mount *, int, struct proc *);
440 int dounmount(struct mount *, int, struct proc *);
441 void vfs_event_signal(fsid_t *, u_int32_t, intptr_t);
442 void vfs_event_init(void);
443 #endif /* __APPLE_API_PRIVATE */
444 extern CIRCLEQ_HEAD(mntlist, mount) mountlist;
445 extern struct slock mountlist_slock;
446
447 #endif /* __APPLE_API_UNSTABLE */
448 #else /* !KERNEL */
449
450 #include <sys/cdefs.h>
451
452 __BEGIN_DECLS
453 int fhopen __P((const struct fhandle *, int));
454 int fstatfs __P((int, struct statfs *));
455 int getfh __P((const char *, fhandle_t *));
456 int getfsstat __P((struct statfs *, long, int));
457 int getmntinfo __P((struct statfs **, int));
458 int mount __P((const char *, const char *, int, void *));
459 int statfs __P((const char *, struct statfs *));
460 int unmount __P((const char *, int));
461 int getvfsbyname __P((const char *, struct vfsconf *));
462 __END_DECLS
463
464 #endif /* KERNEL */
465 #endif /* !_SYS_MOUNT_H_ */