]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/mount_internal.h
xnu-1504.9.17.tar.gz
[apple/xnu.git] / bsd / sys / mount_internal.h
1 /*
2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
29 /*
30 * Copyright (c) 1989, 1991, 1993
31 * The Regents of the University of California. All rights reserved.
32 *
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
35 * are met:
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. All advertising materials mentioning features or use of this software
42 * must display the following acknowledgement:
43 * This product includes software developed by the University of
44 * California, Berkeley and its contributors.
45 * 4. Neither the name of the University nor the names of its contributors
46 * may be used to endorse or promote products derived from this software
47 * without specific prior written permission.
48 *
49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * SUCH DAMAGE.
60 *
61 * @(#)mount.h 8.21 (Berkeley) 5/20/95
62 */
63 /*
64 * NOTICE: This file was modified by McAfee Research in 2004 to introduce
65 * support for mandatory and extensible security protections. This notice
66 * is included in support of clause 2.2 (b) of the Apple Public License,
67 * Version 2.0.
68 */
69
70 #ifndef _SYS_MOUNT_INTERNAL_H_
71 #define _SYS_MOUNT_INTERNAL_H_
72
73 #include <sys/appleapiopts.h>
74 #ifndef KERNEL
75 #include <sys/ucred.h>
76 #else
77 #include <sys/kernel_types.h>
78 #include <sys/namei.h>
79 #endif
80 #include <sys/queue.h>
81 #include <sys/lock.h>
82 #include <net/radix.h>
83 #include <sys/socket.h> /* XXX for AF_MAX */
84 #include <sys/vfs_context.h> /* XXX for AF_MAX */
85 #include <sys/mount.h>
86 #include <sys/cdefs.h>
87
88 struct label;
89
90 #if defined(__i386__) || defined(__x86_64__)
91 typedef uint64_t pending_io_t;
92 #define INCR_PENDING_IO(a, b) OSAddAtomic64((int64_t)(a), (int64_t *)&(b));
93 #else
94 typedef uint32_t pending_io_t;
95 #define INCR_PENDING_IO(a, b) OSAddAtomic((int32_t)(a), (int32_t *)&(b));
96 #endif
97
98
99 /*
100 * Structure per mounted file system. Each mounted file system has an
101 * array of operations and an instance record. The file systems are
102 * put on a doubly linked list.
103 */
104 TAILQ_HEAD(vnodelst, vnode);
105
106 struct mount {
107 TAILQ_ENTRY(mount) mnt_list; /* mount list */
108 int32_t mnt_count; /* reference on the mount */
109 lck_mtx_t mnt_mlock; /* mutex that protects mount point */
110 struct vfsops *mnt_op; /* operations on fs */
111 struct vfstable *mnt_vtable; /* configuration info */
112 struct vnode *mnt_vnodecovered; /* vnode we mounted on */
113 struct vnodelst mnt_vnodelist; /* list of vnodes this mount */
114 struct vnodelst mnt_workerqueue; /* list of vnodes this mount */
115 struct vnodelst mnt_newvnodes; /* list of vnodes this mount */
116 uint32_t mnt_flag; /* flags */
117 uint32_t mnt_kern_flag; /* kernel only flags */
118 uint32_t mnt_lflag; /* mount life cycle flags */
119 uint32_t mnt_maxsymlinklen; /* max size of short symlink */
120 struct vfsstatfs mnt_vfsstat; /* cache of filesystem stats */
121 qaddr_t mnt_data; /* private data */
122 /* Cached values of the IO constraints for the device */
123 uint32_t mnt_maxreadcnt; /* Max. byte count for read */
124 uint32_t mnt_maxwritecnt; /* Max. byte count for write */
125 uint32_t mnt_segreadcnt; /* Max. segment count for read */
126 uint32_t mnt_segwritecnt; /* Max. segment count for write */
127 uint32_t mnt_maxsegreadsize; /* Max. segment read size */
128 uint32_t mnt_maxsegwritesize; /* Max. segment write size */
129 uint32_t mnt_alignmentmask; /* Mask of bits that aren't addressable via DMA */
130 uint32_t mnt_devblocksize; /* the underlying device block size */
131 uint32_t mnt_ioqueue_depth; /* the maxiumum number of commands a device can accept */
132 uint32_t mnt_ioscale; /* scale the various throttles/limits imposed on the amount of I/O in flight */
133 uint32_t mnt_ioflags; /* flags for underlying device */
134 pending_io_t mnt_pending_write_size; /* byte count of pending writes */
135 pending_io_t mnt_pending_read_size; /* byte count of pending reads */
136
137 lck_rw_t mnt_rwlock; /* mutex readwrite lock */
138 lck_mtx_t mnt_renamelock; /* mutex that serializes renames that change shape of tree */
139 vnode_t mnt_devvp; /* the device mounted on for local file systems */
140 uint32_t mnt_devbsdunit; /* the BSD unit number of the device */
141 void *mnt_throttle_info; /* used by the throttle code */
142 int32_t mnt_crossref; /* refernces to cover lookups crossing into mp */
143 int32_t mnt_iterref; /* refernces to cover iterations; drained makes it -ve */
144
145 /* XXX 3762912 hack to support HFS filesystem 'owner' */
146 uid_t mnt_fsowner;
147 gid_t mnt_fsgroup;
148
149 struct label *mnt_mntlabel; /* MAC mount label */
150 struct label *mnt_fslabel; /* MAC default fs label */
151
152 /*
153 * cache the rootvp of the last mount point
154 * in the chain in the mount struct pointed
155 * to by the vnode sitting in '/'
156 * this cache is used to shortcircuit the
157 * mount chain traversal and allows us
158 * to traverse to the true underlying rootvp
159 * in 1 easy step inside of 'cache_lookup_path'
160 *
161 * make sure to validate against the cached vid
162 * in case the rootvp gets stolen away since
163 * we don't take an explicit long term reference
164 * on it when we mount it
165 */
166 vnode_t mnt_realrootvp;
167 uint32_t mnt_realrootvp_vid;
168 /*
169 * bumped each time a mount or unmount
170 * occurs... its used to invalidate
171 * 'mnt_realrootvp' from the cache
172 */
173 uint32_t mnt_generation;
174 /*
175 * if 'MNTK_AUTH_CACHE_TIMEOUT' is
176 * set, then 'mnt_authcache_ttl' is
177 * the time-to-live for the per-vnode authentication cache
178 * on this mount... if zero, no cache is maintained...
179 * if 'MNTK_AUTH_CACHE_TIMEOUT' isn't set, its the
180 * time-to-live for the cached lookup right for
181 * volumes marked 'MNTK_AUTH_OPAQUE'.
182 */
183 int mnt_authcache_ttl;
184 /*
185 * The proc structure pointer and process ID form a
186 * sufficiently unique duple identifying the process
187 * hosting this mount point. Set by vfs_markdependency()
188 * and utilized in new_vnode() to avoid reclaiming vnodes
189 * with this dependency (radar 5192010).
190 */
191 pid_t mnt_dependent_pid;
192 void *mnt_dependent_process;
193 };
194
195 /*
196 * default number of seconds to keep cached lookup
197 * rights valid on mounts marked MNTK_AUTH_OPAQUE
198 */
199 #define CACHED_LOOKUP_RIGHT_TTL 2
200
201 /*
202 * ioflags
203 */
204 #define MNT_IOFLAGS_FUA_SUPPORTED 0x00000001
205
206 /*
207 * ioqueue depth for devices that don't report one
208 */
209 #define MNT_DEFAULT_IOQUEUE_DEPTH 32
210
211
212 /* XXX 3762912 hack to support HFS filesystem 'owner' */
213 #define vfs_setowner(_mp, _uid, _gid) do {(_mp)->mnt_fsowner = (_uid); (_mp)->mnt_fsgroup = (_gid); } while (0)
214
215
216 /* mount point to which dead vps point to */
217 extern struct mount * dead_mountp;
218
219 /*
220 * Internal filesystem control flags stored in mnt_kern_flag.
221 *
222 * MNTK_UNMOUNT locks the mount entry so that name lookup cannot proceed
223 * past the mount point. This keeps the subtree stable during mounts
224 * and unmounts.
225 *
226 * Note: We are counting down on new bit assignments. This is
227 * because the bits here were broken out from the high bits
228 * of the mount flags.
229 */
230 #ifdef CONFIG_IMGSRC_ACCESS
231 #define MNTK_HAS_MOVED 0x00002000
232 #define MNTK_BACKS_ROOT 0x00004000
233 #endif /* CONFIG_IMGSRC_ACCESS */
234 #define MNTK_AUTH_CACHE_TTL 0x00008000 /* rights cache has TTL - TTL of 0 disables cache */
235 #define MNTK_PATH_FROM_ID 0x00010000 /* mounted file system supports id-to-path lookups */
236 #define MNTK_UNMOUNT_PREFLIGHT 0x00020000 /* mounted file system wants preflight check during unmount */
237 #define MNTK_NAMED_STREAMS 0x00040000 /* mounted file system supports Named Streams VNOPs */
238 #define MNTK_EXTENDED_ATTRS 0x00080000 /* mounted file system supports Extended Attributes VNOPs */
239 #define MNTK_LOCK_LOCAL 0x00100000 /* advisory locking is done above the VFS itself */
240 #define MNTK_VIRTUALDEV 0x00200000 /* mounted on a virtual device i.e. a disk image */
241 #define MNTK_ROOTDEV 0x00400000 /* this filesystem resides on the same device as the root */
242 #define MNTK_SSD 0x00800000 /* underlying device is of the solid state variety */
243 #define MNTK_UNMOUNT 0x01000000 /* unmount in progress */
244 #define MNTK_MWAIT 0x02000000 /* waiting for unmount to finish */
245 #define MNTK_WANTRDWR 0x04000000 /* upgrade to read/write requested */
246 #if REV_ENDIAN_FS
247 #define MNT_REVEND 0x08000000 /* Reverse endian FS */
248 #endif /* REV_ENDIAN_FS */
249 #define MNTK_FRCUNMOUNT 0x10000000 /* Forced unmount wanted. */
250 #define MNTK_AUTH_OPAQUE 0x20000000 /* authorisation decisions are not made locally */
251 #define MNTK_AUTH_OPAQUE_ACCESS 0x40000000 /* VNOP_ACCESS is reliable for remote auth */
252 #define MNTK_EXTENDED_SECURITY 0x80000000 /* extended security supported */
253
254 #define MNT_LBUSY 0x00000001 /* mount is busy */
255 #define MNT_LUNMOUNT 0x00000002 /* mount in unmount */
256 #define MNT_LFORCE 0x00000004 /* mount in forced unmount */
257 #define MNT_LDRAIN 0x00000008 /* mount in drain */
258 #define MNT_LITER 0x00000010 /* mount in iteration */
259 #define MNT_LNEWVN 0x00000020 /* mount has new vnodes created */
260 #define MNT_LWAIT 0x00000040 /* wait for unmount op */
261 #define MNT_LITERWAIT 0x00000080 /* mount in iteration */
262 #define MNT_LDEAD 0x00000100 /* mount already unmounted*/
263
264
265 /*
266 * Generic file handle
267 */
268 #define NFS_MAX_FH_SIZE NFSV4_MAX_FH_SIZE
269 #define NFSV4_MAX_FH_SIZE 128
270 #define NFSV3_MAX_FH_SIZE 64
271 #define NFSV2_MAX_FH_SIZE 32
272 struct fhandle {
273 int fh_len; /* length of file handle */
274 unsigned char fh_data[NFS_MAX_FH_SIZE]; /* file handle value */
275 };
276 typedef struct fhandle fhandle_t;
277
278
279
280 /*
281 * Filesystem configuration information. One of these exists for each
282 * type of filesystem supported by the kernel. These are searched at
283 * mount time to identify the requested filesystem.
284 */
285 struct vfstable {
286 struct vfsops *vfc_vfsops; /* filesystem operations vector */
287 char vfc_name[MFSNAMELEN]; /* filesystem type name */
288 int vfc_typenum; /* historic filesystem type number */
289 int vfc_refcount; /* number mounted of this type */
290 int vfc_flags; /* permanent flags */
291 int (*vfc_mountroot)(mount_t, vnode_t, vfs_context_t); /* if != NULL, routine to mount root */
292 struct vfstable *vfc_next; /* next in list */
293 int32_t vfc_reserved1;
294 int32_t vfc_reserved2;
295 int vfc_vfsflags; /* for optional types */
296 void * vfc_descptr; /* desc table allocated address */
297 int vfc_descsize; /* size allocated for desc table */
298 };
299
300 /* vfc_vfsflags: */
301 #define VFC_VFSLOCALARGS 0x002
302 #define VFC_VFSGENERICARGS 0x004
303 #define VFC_VFSNATIVEXATTR 0x010
304 #define VFC_VFSDIRLINKS 0x020
305 #define VFC_VFSPREFLIGHT 0x040
306 #define VFC_VFSREADDIR_EXTENDED 0x080
307 #define VFC_VFS64BITREADY 0x100
308 #ifndef __LP64__
309 #define VFC_VFSTHREADSAFE 0x200
310 #endif /* __LP64__ */
311 #define VFC_VFSNOMACLABEL 0x1000
312 #define VFC_VFSVNOP_PAGEINV2 0x2000
313 #define VFC_VFSVNOP_PAGEOUTV2 0x4000
314
315
316 extern int maxvfsconf; /* highest defined filesystem type */
317 extern struct vfstable *vfsconf; /* head of list of filesystem types */
318 extern int maxvfsslots; /* Maximum slots available to be used */
319 extern int numused_vfsslots; /* number of slots already used */
320
321 /* the following two are xnu private */
322 struct vfstable * vfstable_add(struct vfstable *);
323 int vfstable_del(struct vfstable *);
324
325
326 struct vfsmount_args {
327 union {
328 struct {
329 char * mnt_fspec;
330 void * mnt_fsdata;
331 } mnt_localfs_args;
332 struct {
333 void * mnt_fsdata; /* FS specific */
334 } mnt_remotefs_args;
335 } mountfs_args;
336 };
337
338
339 /*
340 * LP64 *user* version of statfs structure.
341 * NOTE - must be kept in sync with struct statfs in mount.h
342 */
343 struct user64_statfs {
344 short f_otype; /* TEMPORARY SHADOW COPY OF f_type */
345 short f_oflags; /* TEMPORARY SHADOW COPY OF f_flags */
346 user64_long_t f_bsize; /* fundamental file system block size */
347 user64_long_t f_iosize; /* optimal transfer block size */
348 user64_long_t f_blocks; /* total data blocks in file system */
349 user64_long_t f_bfree; /* free blocks in fs */
350 user64_long_t f_bavail; /* free blocks avail to non-superuser */
351 user64_long_t f_files; /* total file nodes in file system */
352 user64_long_t f_ffree; /* free file nodes in fs */
353 fsid_t f_fsid; /* file system id */
354 uid_t f_owner; /* user that mounted the filesystem */
355 short f_reserved1; /* spare for later */
356 short f_type; /* type of filesystem */
357 user64_long_t f_flags; /* copy of mount exported flags */
358 user64_long_t f_reserved2[2]; /* reserved for future use */
359 char f_fstypename[MFSNAMELEN]; /* fs type name */
360 char f_mntonname[MNAMELEN]; /* directory on which mounted */
361 char f_mntfromname[MNAMELEN];/* mounted filesystem */
362 char f_reserved3; /* For alignment */
363 user64_long_t f_reserved4[4]; /* For future use */
364 };
365
366 /*
367 * ILP32 *user* version of statfs structure.
368 * NOTE - must be kept in sync with struct statfs in mount.h
369 */
370 struct user32_statfs {
371 short f_otype; /* TEMPORARY SHADOW COPY OF f_type */
372 short f_oflags; /* TEMPORARY SHADOW COPY OF f_flags */
373 user32_long_t f_bsize; /* fundamental file system block size */
374 user32_long_t f_iosize; /* optimal transfer block size */
375 user32_long_t f_blocks; /* total data blocks in file system */
376 user32_long_t f_bfree; /* free blocks in fs */
377 user32_long_t f_bavail; /* free blocks avail to non-superuser */
378 user32_long_t f_files; /* total file nodes in file system */
379 user32_long_t f_ffree; /* free file nodes in fs */
380 fsid_t f_fsid; /* file system id */
381 uid_t f_owner; /* user that mounted the filesystem */
382 short f_reserved1; /* spare for later */
383 short f_type; /* type of filesystem */
384 user32_long_t f_flags; /* copy of mount exported flags */
385 user32_long_t f_reserved2[2]; /* reserved for future use */
386 char f_fstypename[MFSNAMELEN]; /* fs type name */
387 char f_mntonname[MNAMELEN]; /* directory on which mounted */
388 char f_mntfromname[MNAMELEN];/* mounted filesystem */
389 char f_reserved3; /* For alignment */
390 user32_long_t f_reserved4[4]; /* For future use */
391 };
392
393 /*
394 * throttle I/Os are affected only by normal I/Os happening on the same bsd device node. For example, disk1s3 and
395 * disk1s5 are the same device node, while disk1s3 and disk2 are not (although disk2 might be a mounted disk image file
396 * and the disk image file resides on a partition in disk1). The following constant defines the maximum number of
397 * different bsd device nodes the algorithm can consider, and larger numbers are rounded by this maximum. Since
398 * throttled I/O is usually useful in non-server environment only, a small number 16 is enough in most cases
399 */
400 #define LOWPRI_MAX_NUM_DEV 16
401
402 __BEGIN_DECLS
403
404 extern uint32_t mount_generation;
405 extern TAILQ_HEAD(mntlist, mount) mountlist;
406 void mount_list_lock(void);
407 void mount_list_unlock(void);
408 void mount_lock_init(mount_t);
409 void mount_lock_destroy(mount_t);
410 void mount_lock(mount_t);
411 void mount_lock_spin(mount_t);
412 void mount_unlock(mount_t);
413 void mount_lock_renames(mount_t);
414 void mount_unlock_renames(mount_t);
415 void mount_ref(mount_t, int);
416 void mount_drop(mount_t, int);
417 int mount_refdrain(mount_t);
418
419 /* vfs_rootmountalloc should be kept as a private api */
420 errno_t vfs_rootmountalloc(const char *, const char *, mount_t *mpp);
421
422 int vfs_mountroot(void);
423 void vfs_unmountall(void);
424 int safedounmount(struct mount *, int, vfs_context_t);
425 int dounmount(struct mount *, int, int, vfs_context_t);
426
427 /* xnuy internal api */
428 void mount_dropcrossref(mount_t, vnode_t, int);
429 mount_t mount_lookupby_volfsid(int, int);
430 mount_t mount_list_lookupby_fsid(fsid_t *, int, int);
431 int mount_list_add(mount_t);
432 void mount_list_remove(mount_t);
433 int mount_iterref(mount_t, int);
434 int mount_isdrained(mount_t, int);
435 void mount_iterdrop(mount_t);
436 void mount_iterdrain(mount_t);
437 void mount_iterreset(mount_t);
438
439 /* throttled I/O api */
440 int throttle_get_io_policy(struct uthread **ut);
441 extern void throttle_lowpri_io(boolean_t ok_to_sleep);
442 int throttle_io_will_be_throttled(int lowpri_window_msecs, mount_t mp);
443
444 __END_DECLS
445
446 #endif /* !_SYS_MOUNT_INTERNAL_H_ */