]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/mount_internal.h
xnu-7195.101.1.tar.gz
[apple/xnu.git] / bsd / sys / mount_internal.h
CommitLineData
91447636 1/*
cb323159 2 * Copyright (c) 2000-2018 Apple Inc. All rights reserved.
5d5c5d0d 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 5 *
2d21ac55
A
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.
0a7de745 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
0a7de745 17 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
0a7de745 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
91447636
A
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 */
2d21ac55
A
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 */
91447636
A
69
70#ifndef _SYS_MOUNT_INTERNAL_H_
0a7de745 71#define _SYS_MOUNT_INTERNAL_H_
91447636
A
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>
0a7de745
A
83#include <sys/socket.h> /* XXX for AF_MAX */
84#include <sys/vfs_context.h> /* XXX for AF_MAX */
91447636
A
85#include <sys/mount.h>
86#include <sys/cdefs.h>
fe8ab488 87#include <sys/sysctl.h>
91447636 88
2d21ac55
A
89struct label;
90
b0d623f7
A
91#if defined(__i386__) || defined(__x86_64__)
92typedef uint64_t pending_io_t;
93#define INCR_PENDING_IO(a, b) OSAddAtomic64((int64_t)(a), (int64_t *)&(b));
94#else
95typedef uint32_t pending_io_t;
96#define INCR_PENDING_IO(a, b) OSAddAtomic((int32_t)(a), (int32_t *)&(b));
97#endif
98
99
91447636
A
100/*
101 * Structure per mounted file system. Each mounted file system has an
102 * array of operations and an instance record. The file systems are
103 * put on a doubly linked list.
104 */
105TAILQ_HEAD(vnodelst, vnode);
106
107struct mount {
cb323159
A
108 TAILQ_ENTRY(mount) mnt_list; /* mount list */
109 int32_t mnt_count; /* reference on the mount */
110 lck_mtx_t mnt_mlock; /* mutex that protects mount point */
f427ee49
A
111 const struct vfsops * XNU_PTRAUTH_SIGNED_PTR("mount.vfsops") mnt_op; /* operations on fs */
112 struct vfstable * XNU_PTRAUTH_SIGNED_PTR("mount.mnt_vtable") mnt_vtable; /* configuration info */
113 struct vnode * XNU_PTRAUTH_SIGNED_PTR("mount.mnt_vnodecovered") mnt_vnodecovered; /* vnode we mounted on */
cb323159
A
114 struct vnodelst mnt_vnodelist; /* list of vnodes this mount */
115 struct vnodelst mnt_workerqueue; /* list of vnodes this mount */
116 struct vnodelst mnt_newvnodes; /* list of vnodes this mount */
117 uint32_t mnt_flag; /* flags */
f427ee49 118 uint32_t mnt_kern_flag; /* kernel only flags. NOTE: See mnt_supl_kern_flags below! */
cb323159
A
119 uint32_t mnt_compound_ops; /* Available compound operations */
120 uint32_t mnt_lflag; /* mount life cycle flags */
121 uint32_t mnt_maxsymlinklen; /* max size of short symlink */
122 struct vfsstatfs mnt_vfsstat; /* cache of filesystem stats */
123 qaddr_t mnt_data; /* private data */
91447636 124 /* Cached values of the IO constraints for the device */
cb323159
A
125 uint32_t mnt_maxreadcnt; /* Max. byte count for read */
126 uint32_t mnt_maxwritecnt; /* Max. byte count for write */
127 uint32_t mnt_segreadcnt; /* Max. segment count for read */
128 uint32_t mnt_segwritecnt; /* Max. segment count for write */
129 uint32_t mnt_maxsegreadsize; /* Max. segment read size */
130 uint32_t mnt_maxsegwritesize; /* Max. segment write size */
131 uint32_t mnt_alignmentmask; /* Mask of bits that aren't addressable via DMA */
132 uint32_t mnt_devblocksize; /* the underlying device block size */
133 uint32_t mnt_ioqueue_depth; /* the maxiumum number of commands a device can accept */
134 uint32_t mnt_ioscale; /* scale the various throttles/limits imposed on the amount of I/O in flight */
135 uint32_t mnt_ioflags; /* flags for underlying device */
136 uint32_t mnt_minsaturationbytecount; /* if non-zero, mininum amount of writes (in bytes) needed to max out throughput */
137 pending_io_t mnt_pending_write_size __attribute__((aligned(sizeof(pending_io_t)))); /* byte count of pending writes */
138 pending_io_t mnt_pending_read_size __attribute__((aligned(sizeof(pending_io_t)))); /* byte count of pending reads */
139 struct timeval mnt_last_write_issued_timestamp;
140 struct timeval mnt_last_write_completed_timestamp;
141 int64_t mnt_max_swappin_available;
142
143 lck_rw_t mnt_rwlock; /* mutex readwrite lock */
144 lck_mtx_t mnt_renamelock; /* mutex that serializes renames that change shape of tree */
145 vnode_t mnt_devvp; /* the device mounted on for local file systems */
146 uint32_t mnt_devbsdunit; /* the BSD unit number of the device */
147 uint64_t mnt_throttle_mask; /* the throttle mask of what devices will be affected by I/O from this mnt */
148 void *mnt_throttle_info; /* used by the throttle code */
149 int32_t mnt_crossref; /* refernces to cover lookups crossing into mp */
150 int32_t mnt_iterref; /* refernces to cover iterations; drained makes it -ve */
6d2010ae 151#if CONFIG_TRIGGERS
cb323159
A
152 int32_t mnt_numtriggers; /* num of trigger vnodes for this mount */
153 vfs_trigger_callback_t *mnt_triggercallback;
154 void *mnt_triggerdata;
6d2010ae 155#endif
0a7de745 156 /* XXX 3762912 hack to support HFS filesystem 'owner' */
cb323159
A
157 uid_t mnt_fsowner;
158 gid_t mnt_fsgroup;
2d21ac55 159
f427ee49
A
160 struct label * XNU_PTRAUTH_SIGNED_PTR("mount.mnt_mntlabel") mnt_mntlabel; /* MAC mount label */
161 struct label * XNU_PTRAUTH_SIGNED_PTR("mount.mnt_fslabel") mnt_fslabel; /* MAC default fs label */
2d21ac55
A
162
163 /*
164 * cache the rootvp of the last mount point
165 * in the chain in the mount struct pointed
166 * to by the vnode sitting in '/'
167 * this cache is used to shortcircuit the
168 * mount chain traversal and allows us
169 * to traverse to the true underlying rootvp
170 * in 1 easy step inside of 'cache_lookup_path'
171 *
172 * make sure to validate against the cached vid
173 * in case the rootvp gets stolen away since
174 * we don't take an explicit long term reference
175 * on it when we mount it
176 */
cb323159
A
177 vnode_t mnt_realrootvp;
178 uint32_t mnt_realrootvp_vid;
2d21ac55
A
179 /*
180 * bumped each time a mount or unmount
181 * occurs... its used to invalidate
182 * 'mnt_realrootvp' from the cache
183 */
cb323159 184 uint32_t mnt_generation;
0a7de745
A
185 /*
186 * if 'MNTK_AUTH_CACHE_TIMEOUT' is
2d21ac55
A
187 * set, then 'mnt_authcache_ttl' is
188 * the time-to-live for the per-vnode authentication cache
189 * on this mount... if zero, no cache is maintained...
190 * if 'MNTK_AUTH_CACHE_TIMEOUT' isn't set, its the
191 * time-to-live for the cached lookup right for
192 * volumes marked 'MNTK_AUTH_OPAQUE'.
193 */
cb323159
A
194 int mnt_authcache_ttl;
195 char fstypename_override[MFSTYPENAMELEN];
39037602 196
cb323159 197 uint32_t mnt_iobufinuse;
813fb2f6 198
cb323159 199 void *mnt_disk_conditioner_info;
5ba3f43e 200
cb323159 201 lck_mtx_t mnt_iter_lock; /* mutex that protects iteration of vnodes */
f427ee49
A
202
203 uint64_t mnt_mount_id; /* system-wide unique mount ID */
204 uint32_t mnt_supl_kern_flag; /* Supplemental kernel-only mount flags */
91447636 205};
2d21ac55
A
206
207/*
208 * default number of seconds to keep cached lookup
209 * rights valid on mounts marked MNTK_AUTH_OPAQUE
210 */
0a7de745 211#define CACHED_LOOKUP_RIGHT_TTL 2
2d21ac55
A
212
213/*
214 * ioflags
215 */
0a7de745
A
216#define MNT_IOFLAGS_FUA_SUPPORTED 0x00000001
217#define MNT_IOFLAGS_UNMAP_SUPPORTED 0x00000002
218#define MNT_IOFLAGS_IOSCHED_SUPPORTED 0x00000004
219#define MNT_IOFLAGS_CSUNMAP_SUPPORTED 0x00000008
220#define MNT_IOFLAGS_SWAPPIN_SUPPORTED 0x00000010
221#define MNT_IOFLAGS_FUSION_DRIVE 0x00000020
cb323159 222#define MNT_IOFLAGS_PERIPHERAL_DRIVE 0x00000040 /* External: Attached directly to the system (USB,TBT,FW,etc.) */
2d21ac55 223
b0d623f7
A
224/*
225 * ioqueue depth for devices that don't report one
226 */
0a7de745 227#define MNT_DEFAULT_IOQUEUE_DEPTH 32
b0d623f7 228
d9a64523
A
229/*
230 * mnt_ioscale value for the given ioqueue depth
231 */
0a7de745 232#define MNT_IOSCALE(ioqueue_depth) ((ioqueue_depth + (MNT_DEFAULT_IOQUEUE_DEPTH - 1)) / MNT_DEFAULT_IOQUEUE_DEPTH)
d9a64523 233
91447636
A
234/* mount point to which dead vps point to */
235extern struct mount * dead_mountp;
236
237/*
238 * Internal filesystem control flags stored in mnt_kern_flag.
239 *
240 * MNTK_UNMOUNT locks the mount entry so that name lookup cannot proceed
241 * past the mount point. This keeps the subtree stable during mounts
242 * and unmounts.
243 *
244 * Note: We are counting down on new bit assignments. This is
245 * because the bits here were broken out from the high bits
246 * of the mount flags.
247 */
f427ee49
A
248#define MNTK_SYSTEM 0x00000040 /* Volume associated with system volume (do not allow unmount) */
249#define MNTK_NOSWAP 0x00000080 /* swap files cannot be used on this mount */
0a7de745 250#define MNTK_SWAP_MOUNT 0x00000100 /* we are swapping to this mount */
f427ee49 251#define MNTK_DENY_READDIREXT 0x00000200 /* Deny Extended-style readdir's for this volume */
0a7de745 252#define MNTK_PERMIT_UNMOUNT 0x00000400 /* Allow (non-forced) unmounts by UIDs other than the one that mounted the volume */
6d2010ae 253#define MNTK_TYPENAME_OVERRIDE 0x00000800 /* override the fstypename for statfs() */
0a7de745 254#define MNTK_KERNEL_MOUNT 0x00001000 /* mount came from kernel side */
b7266188 255#ifdef CONFIG_IMGSRC_ACCESS
0a7de745 256#define MNTK_HAS_MOVED 0x00002000
b7266188 257#endif /* CONFIG_IMGSRC_ACCESS */
f427ee49 258#define MNTK_BACKS_ROOT 0x00004000 /* mount contains a disk image backing the root filesystem - therefore it mustn't be unmounted */
0a7de745
A
259#define MNTK_AUTH_CACHE_TTL 0x00008000 /* rights cache has TTL - TTL of 0 disables cache */
260#define MNTK_PATH_FROM_ID 0x00010000 /* mounted file system supports id-to-path lookups */
261#define MNTK_UNMOUNT_PREFLIGHT 0x00020000 /* mounted file system wants preflight check during unmount */
262#define MNTK_NAMED_STREAMS 0x00040000 /* mounted file system supports Named Streams VNOPs */
263#define MNTK_EXTENDED_ATTRS 0x00080000 /* mounted file system supports Extended Attributes VNOPs */
264#define MNTK_LOCK_LOCAL 0x00100000 /* advisory locking is done above the VFS itself */
265#define MNTK_VIRTUALDEV 0x00200000 /* mounted on a virtual device i.e. a disk image */
f427ee49 266#define MNTK_ROOTDEV 0x00400000 /* this filesystem resides on the same device as the root - appears unused as of 2020 */
0a7de745
A
267#define MNTK_SSD 0x00800000 /* underlying device is of the solid state variety */
268#define MNTK_UNMOUNT 0x01000000 /* unmount in progress */
f427ee49 269#define MNTK_MWAIT 0x02000000 /* waiting for unmount to finish - appears unused as of 2020 */
0a7de745 270#define MNTK_WANTRDWR 0x04000000 /* upgrade to read/write requested */
f427ee49
A
271#define MNTK_SYSTEMDATA 0x08000000 /* volume is a Data volume tightly linked with System root volume. Firmlinks, etc */
272#define MNTK_DIR_HARDLINKS 0x10000000 /* mounted file system supports directory hard links */
273#define MNTK_AUTH_OPAQUE 0x20000000 /* authorisation decisions are not made locally */
274#define MNTK_AUTH_OPAQUE_ACCESS 0x40000000 /* VNOP_ACCESS is reliable for remote auth */
0a7de745 275#define MNTK_EXTENDED_SECURITY 0x80000000 /* extended security supported */
91447636 276
f427ee49
A
277
278/*
279 * Internal supplemental FS control flags stored in mnt_supl_kern_flag
280 *
281 * NOTE: The 32 bits in the above-mentioned 32bit flag word (mnt_kern_flag) have been
282 * exhausted, so this is intended as a supplement.
283 */
284#define MNTK_SUPL_BASESYSTEM 0x00000001
285
286
287/*
288 * Mount Lifecycle Flags (stored in mnt_lflag)
289 */
0a7de745
A
290#define MNT_LNOTRESP 0x00000001 /* mount not responding */
291#define MNT_LUNMOUNT 0x00000002 /* mount in unmount */
292#define MNT_LFORCE 0x00000004 /* mount in forced unmount */
293#define MNT_LDRAIN 0x00000008 /* mount in drain */
294#define MNT_LITER 0x00000010 /* mount in iteration */
295#define MNT_LNEWVN 0x00000020 /* mount has new vnodes created */
296#define MNT_LWAIT 0x00000040 /* wait for unmount op */
f427ee49 297#define MNT_LMOUNT 0x00000080 /* not finished mounting */
0a7de745
A
298#define MNT_LDEAD 0x00000100 /* mount already unmounted*/
299#define MNT_LNOSUB 0x00000200 /* submount - no recursion */
91447636
A
300
301
302/*
303 * Generic file handle
304 */
0a7de745
A
305#define NFS_MAX_FH_SIZE NFSV4_MAX_FH_SIZE
306#define NFSV4_MAX_FH_SIZE 128
307#define NFSV3_MAX_FH_SIZE 64
308#define NFSV2_MAX_FH_SIZE 32
f427ee49
A
309
310#ifdef MALLOC_DECLARE
311MALLOC_DECLARE(M_FHANDLE);
312#endif
313
91447636 314struct fhandle {
0a7de745
A
315 unsigned int fh_len; /* length of file handle */
316 unsigned char fh_data[NFS_MAX_FH_SIZE]; /* file handle value */
91447636 317};
0a7de745 318typedef struct fhandle fhandle_t;
91447636
A
319
320
321
322/*
323 * Filesystem configuration information. One of these exists for each
324 * type of filesystem supported by the kernel. These are searched at
325 * mount time to identify the requested filesystem.
326 */
327struct vfstable {
cb323159 328 const struct vfsops *vfc_vfsops;/* filesystem operations vector */
0a7de745
A
329 char vfc_name[MFSNAMELEN]; /* filesystem type name */
330 int vfc_typenum; /* historic filesystem type number */
331 int vfc_refcount; /* number mounted of this type */
332 int vfc_flags; /* permanent flags */
333 int (*vfc_mountroot)(mount_t, vnode_t, vfs_context_t); /* if != NULL, routine to mount root */
334 struct vfstable *vfc_next; /* next in list */
335 int32_t vfc_reserved1;
b0d623f7 336 int32_t vfc_reserved2;
0a7de745
A
337 int vfc_vfsflags; /* for optional types */
338 void * vfc_descptr; /* desc table allocated address */
339 int vfc_descsize; /* size allocated for desc table */
340 struct sysctl_oid *vfc_sysctl; /* dynamically registered sysctl node */
91447636
A
341};
342
2d21ac55 343/* vfc_vfsflags: */
0a7de745
A
344#define VFC_VFSLOCALARGS 0x002
345#define VFC_VFSGENERICARGS 0x004
346#define VFC_VFSNATIVEXATTR 0x010
39037602 347#define VFC_VFSCANMOUNTROOT 0x020
0a7de745
A
348#define VFC_VFSPREFLIGHT 0x040
349#define VFC_VFSREADDIR_EXTENDED 0x080
350#define VFC_VFS64BITREADY 0x100
351#define VFC_VFSNOMACLABEL 0x1000
352#define VFC_VFSVNOP_PAGEINV2 0x2000
353#define VFC_VFSVNOP_PAGEOUTV2 0x4000
354#define VFC_VFSVNOP_NOUPDATEID_RENAME 0x8000
355#define VFC_VFSVNOP_SECLUDE_RENAME 0x10000
356
357extern int maxvfstypenum; /* highest defined filesystem type */
358extern struct vfstable *vfsconf; /* head of list of filesystem types */
359extern const int maxvfsslots; /* Maximum statically allocated slots available to be used */
360extern int numused_vfsslots; /* number of statically allocated slots already used */
361extern int numregistered_fses; /* number of total registered filesystems */
91447636
A
362
363/* the following two are xnu private */
0a7de745
A
364struct vfstable * vfstable_add(struct vfstable *);
365int vfstable_del(struct vfstable *);
91447636
A
366
367
368struct vfsmount_args {
369 union {
370 struct {
371 char * mnt_fspec;
372 void * mnt_fsdata;
373 } mnt_localfs_args;
374 struct {
0a7de745 375 void * mnt_fsdata; /* FS specific */
91447636
A
376 } mnt_remotefs_args;
377 } mountfs_args;
378};
379
380
381/*
b0d623f7 382 * LP64 *user* version of statfs structure.
91447636
A
383 * NOTE - must be kept in sync with struct statfs in mount.h
384 */
b0d623f7 385struct user64_statfs {
0a7de745
A
386 short f_otype; /* TEMPORARY SHADOW COPY OF f_type */
387 short f_oflags; /* TEMPORARY SHADOW COPY OF f_flags */
388 user64_long_t f_bsize; /* fundamental file system block size */
389 user64_long_t f_iosize; /* optimal transfer block size */
390 user64_long_t f_blocks; /* total data blocks in file system */
391 user64_long_t f_bfree; /* free blocks in fs */
392 user64_long_t f_bavail; /* free blocks avail to non-superuser */
393 user64_long_t f_files; /* total file nodes in file system */
394 user64_long_t f_ffree; /* free file nodes in fs */
395 fsid_t f_fsid; /* file system id */
396 uid_t f_owner; /* user that mounted the filesystem */
cb323159 397 short f_reserved1; /* spare for later */
0a7de745 398 short f_type; /* type of filesystem */
cb323159
A
399 user64_long_t f_flags; /* copy of mount exported flags */
400 user64_long_t f_reserved2[2]; /* reserved for future use */
0a7de745
A
401 char f_fstypename[MFSNAMELEN]; /* fs type name */
402 char f_mntonname[MNAMELEN]; /* directory on which mounted */
403 char f_mntfromname[MNAMELEN];/* mounted filesystem */
404 char f_reserved3; /* For alignment */
405 user64_long_t f_reserved4[4]; /* For future use */
b0d623f7
A
406};
407
408/*
409 * ILP32 *user* version of statfs structure.
410 * NOTE - must be kept in sync with struct statfs in mount.h
411 */
412struct user32_statfs {
0a7de745
A
413 short f_otype; /* TEMPORARY SHADOW COPY OF f_type */
414 short f_oflags; /* TEMPORARY SHADOW COPY OF f_flags */
415 user32_long_t f_bsize; /* fundamental file system block size */
416 user32_long_t f_iosize; /* optimal transfer block size */
417 user32_long_t f_blocks; /* total data blocks in file system */
418 user32_long_t f_bfree; /* free blocks in fs */
419 user32_long_t f_bavail; /* free blocks avail to non-superuser */
420 user32_long_t f_files; /* total file nodes in file system */
421 user32_long_t f_ffree; /* free file nodes in fs */
422 fsid_t f_fsid; /* file system id */
423 uid_t f_owner; /* user that mounted the filesystem */
424 short f_reserved1; /* spare for later */
425 short f_type; /* type of filesystem */
426 user32_long_t f_flags; /* copy of mount exported flags */
427 user32_long_t f_reserved2[2]; /* reserved for future use */
428 char f_fstypename[MFSNAMELEN]; /* fs type name */
429 char f_mntonname[MNAMELEN]; /* directory on which mounted */
430 char f_mntfromname[MNAMELEN];/* mounted filesystem */
431 char f_reserved3; /* For alignment */
432 user32_long_t f_reserved4[4]; /* For future use */
91447636
A
433};
434
593a1d5f 435/*
6d2010ae
A
436 * throttle I/Os are affected only by normal I/Os happening on the same spindle. Currently we use a 64-bit integer to
437 * represent what devices are affected, so we can handle at most 64 different spindles. Since
438 * throttled I/O is usually useful in non-server environment only, this number is enough in most cases.
593a1d5f 439 */
6d2010ae 440#define LOWPRI_MAX_NUM_DEV 64
593a1d5f 441
91447636
A
442__BEGIN_DECLS
443
b0d623f7 444extern uint32_t mount_generation;
91447636
A
445extern TAILQ_HEAD(mntlist, mount) mountlist;
446void mount_list_lock(void);
447void mount_list_unlock(void);
448void mount_lock_init(mount_t);
449void mount_lock_destroy(mount_t);
450void mount_lock(mount_t);
b0d623f7 451void mount_lock_spin(mount_t);
91447636 452void mount_unlock(mount_t);
813fb2f6
A
453void mount_iterate_lock(mount_t);
454void mount_iterate_unlock(mount_t);
91447636
A
455void mount_lock_renames(mount_t);
456void mount_unlock_renames(mount_t);
457void mount_ref(mount_t, int);
458void mount_drop(mount_t, int);
2d21ac55 459int mount_refdrain(mount_t);
91447636
A
460
461/* vfs_rootmountalloc should be kept as a private api */
462errno_t vfs_rootmountalloc(const char *, const char *, mount_t *mpp);
91447636 463
f427ee49
A
464int vfs_mount_recovery(void);
465
466typedef uint32_t vfs_switch_root_flags_t;
467#define VFSSR_VIRTUALDEV_PROHIBITED 0x01 /* Not allowed to pivot into virtual devices (disk images).
468 * This is really just because we don't have a great way to find
469 * the filesystem that backs the image in order to set
470 * MNTK_BACKS_ROOT on it, which would prevent even forced-unmounts.
471 * Also, lots of disk images are backed by userspace processes,
472 * which also seems like a bad idea for the root filesystem. */
473
474int vfs_switch_root(const char *, const char *, vfs_switch_root_flags_t);
cb323159 475
0a7de745 476int vfs_mountroot(void);
c3c9b80d 477void vfs_unmountall(int only_non_system);
0a7de745
A
478int safedounmount(struct mount *, int, vfs_context_t);
479int dounmount(struct mount *, int, int, vfs_context_t);
480void dounmount_submounts(struct mount *, int, vfs_context_t);
91447636 481
6d2010ae 482/* xnu internal api */
91447636 483void mount_dropcrossref(mount_t, vnode_t, int);
91447636
A
484mount_t mount_lookupby_volfsid(int, int);
485mount_t mount_list_lookupby_fsid(fsid_t *, int, int);
b0d623f7 486int mount_list_add(mount_t);
2d21ac55 487void mount_list_remove(mount_t);
91447636
A
488int mount_iterref(mount_t, int);
489int mount_isdrained(mount_t, int);
490void mount_iterdrop(mount_t);
491void mount_iterdrain(mount_t);
492void mount_iterreset(mount_t);
493
cb323159 494/* These flags are used as flag bits in the `internal_flags` argument to mount_common */
6d2010ae 495/* Private NFS spi */
0a7de745
A
496#define KERNEL_MOUNT_NOAUTH 0x01 /* Don't check the UID of the directory we are mounting on */
497#define KERNEL_MOUNT_PERMIT_UNMOUNT 0x02 /* Allow (non-forced) unmounts by users other the one who mounted the volume */
39037602 498/* used by snapshot mounting SPI */
0a7de745 499#define KERNEL_MOUNT_SNAPSHOT 0x04 /* Mounting a snapshot */
cb323159
A
500#define KERNEL_MOUNT_DATAVOL 0x08 /* mount the data volume */
501#define KERNEL_MOUNT_VMVOL 0x10 /* mount the VM volume */
f427ee49
A
502#define KERNEL_MOUNT_PREBOOTVOL 0x20 /* mount the Preboot volume */
503#define KERNEL_MOUNT_RECOVERYVOL 0x40 /* mount the Recovery volume */
504#define KERNEL_MOUNT_BASESYSTEMROOT 0x80 /* mount a base root volume "instead of" the full root volume (only used during bsd_init) */
c3c9b80d 505#define KERNEL_MOUNT_DEVFS 0x100 /* kernel startup mount of devfs */
f427ee49
A
506
507/* mask for checking if any of the "mount volume by role" flags are set */
508#define KERNEL_MOUNT_VOLBYROLE_MASK (KERNEL_MOUNT_DATAVOL | KERNEL_MOUNT_VMVOL | KERNEL_MOUNT_PREBOOTVOL | KERNEL_MOUNT_RECOVERYVOL)
cb323159
A
509
510
490019cf 511#if NFSCLIENT || DEVFS || ROUTEFS
6d2010ae
A
512/*
513 * NOTE: kernel_mount() does not force MNT_NOSUID, MNT_NOEXEC, or MNT_NODEC for non-privileged
514 * mounting credentials, as the mount(2) system call does.
515 */
516int kernel_mount(char *, vnode_t, vnode_t, const char *, void *, size_t, int, uint32_t, vfs_context_t);
517boolean_t vfs_iskernelmount(mount_t);
518#endif
519
39037602 520/* Throttled I/O API. KPI/SPI is in systm.h. */
39236c6e 521
316670eb 522int throttle_get_io_policy(struct uthread **ut);
39236c6e 523int throttle_get_passive_io_policy(struct uthread **ut);
39236c6e
A
524void *throttle_info_update_by_mount(mount_t mp);
525void rethrottle_thread(uthread_t ut);
fe8ab488 526
593a1d5f 527
6d2010ae
A
528/* throttled I/O helper function */
529/* convert the lowest bit to a device index */
530extern int num_trailing_0(uint64_t n);
531
fe8ab488 532/* sync lock */
d9a64523 533extern int sync_timeout_seconds;
fe8ab488 534
f427ee49
A
535extern zone_t mount_zone;
536
91447636
A
537__END_DECLS
538
539#endif /* !_SYS_MOUNT_INTERNAL_H_ */