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