xref: /xnu-11215/bsd/vfs/vfs_conf.c (revision 1031c584)
1 /*
2  * Copyright (c) 2000-2019 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, 1993, 1995
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  *	@(#)vfs_conf.c	8.11 (Berkeley) 5/10/95
62  */
63 /*
64  * NOTICE: This file was modified by SPARTA, Inc. in 2005 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 #include <sys/param.h>
71 #include <sys/systm.h>
72 #include <sys/mount_internal.h>
73 #include <sys/vnode_internal.h>
74 
75 #include <nfs/nfs_conf.h>
76 
77 /*
78  * These define the root filesystem, device, and root filesystem type.
79  */
80 struct mount *rootfs;
81 struct vnode *rootvnode;
82 
83 #ifdef CONFIG_IMGSRC_ACCESS
84 struct vnode *imgsrc_rootvnodes[MAX_IMAGEBOOT_NESTING]; /* [0] -> source volume, [1] -> first disk image */
85 #endif /* CONFIG_IMGSRC_ACCESS */
86 
87 int (*mountroot)(void) = NULL;
88 
89 /*
90  * Set up the initial array of known filesystem types.
91  */
92 extern  struct vfsops mfs_vfsops;
93 extern  int mfs_mountroot(mount_t, vnode_t, vfs_context_t);     /* dead */
94 extern  struct vfsops afs_vfsops;
95 extern  struct vfsops null_vfsops;
96 extern  struct vfsops devfs_vfsops;
97 extern  const struct vfsops routefs_vfsops;
98 extern  struct vfsops nullfs_vfsops;
99 extern struct vfsops bindfs_vfsops;
100 
101 #if MOCKFS
102 extern  struct vfsops mockfs_vfsops;
103 extern  int mockfs_mountroot(mount_t, vnode_t, vfs_context_t);
104 #endif /* MOCKFS */
105 
106 enum fs_type_num {
107 	FT_DEVFS = 19,
108 	FT_SYNTHFS = 20,
109 	FT_ROUTEFS = 21,
110 	FT_NULLFS = 22,
111 	FT_BINDFS = 23,
112 	FT_MOCKFS  = 0x6D6F636B
113 };
114 
115 int fstypenumstart = FT_BINDFS + 1;
116 /*
117  * Set up the filesystem operations for vnodes.
118  */
119 static struct vfstable vfstbllist[] = {
120 	/* Device Filesystem */
121 #if DEVFS
122 #if CONFIG_MACF
123 	{
124 		.vfc_vfsops = &devfs_vfsops,
125 		.vfc_name = "devfs",
126 		.vfc_typenum = FT_DEVFS,
127 		.vfc_refcount = 0,
128 		.vfc_flags = MNT_MULTILABEL,
129 		.vfc_mountroot = NULL,
130 		.vfc_next = NULL,
131 		.vfc_reserved1 = 0,
132 		.vfc_reserved2 = 0,
133 		.vfc_vfsflags = VFC_VFSGENERICARGS | VFC_VFS64BITREADY,
134 		.vfc_descptr = NULL,
135 		.vfc_descsize = 0,
136 		.vfc_sysctl = NULL
137 	},
138 #else /* !CONFIG_MAC */
139 	{
140 		.vfc_vfsops = &devfs_vfsops,
141 		.vfc_name = "devfs",
142 		.vfc_typenum = FT_DEVFS,
143 		.vfc_refcount = 0,
144 		.vfc_flags = 0,
145 		.vfc_mountroot = NULL,
146 		.vfc_next = NULL,
147 		.vfc_reserved1 = 0,
148 		.vfc_reserved2 = 0,
149 		.vfc_vfsflags = VFC_VFSGENERICARGS | VFC_VFS64BITREADY,
150 		.vfc_descptr = NULL,
151 		.vfc_descsize = 0,
152 		.vfc_sysctl = NULL
153 	},
154 #endif /* CONFIG_MAC */
155 #endif /* DEVFS */
156 
157 #ifndef __LP64__
158 #endif /* __LP64__ */
159 
160 #if NULLFS
161 	{
162 		.vfc_vfsops = &nullfs_vfsops,
163 		.vfc_name = "nullfs",
164 		.vfc_typenum = FT_NULLFS,
165 		.vfc_refcount = 0,
166 		.vfc_flags = MNT_DONTBROWSE | MNT_RDONLY,
167 		.vfc_mountroot = NULL,
168 		.vfc_next = NULL,
169 		.vfc_reserved1 = 0,
170 		.vfc_reserved2 = 0,
171 		.vfc_vfsflags = VFC_VFS64BITREADY,
172 		.vfc_descptr = NULL,
173 		.vfc_descsize = 0,
174 		.vfc_sysctl = NULL
175 	},
176 #endif /* NULLFS */
177 
178 #if BINDFS
179 	{
180 		.vfc_vfsops = &bindfs_vfsops,
181 		.vfc_name = "bindfs",
182 		.vfc_typenum = FT_BINDFS,
183 		.vfc_refcount = 0,
184 		.vfc_flags = MNT_DONTBROWSE | MNT_RDONLY,
185 		.vfc_mountroot = NULL,
186 		.vfc_next = NULL,
187 		.vfc_reserved1 = 0,
188 		.vfc_reserved2 = 0,
189 		.vfc_vfsflags = VFC_VFS64BITREADY,
190 		.vfc_descptr = NULL,
191 		.vfc_descsize = 0,
192 		.vfc_sysctl = NULL
193 	},
194 #endif /* BINDFS */
195 
196 #if MOCKFS
197 	/* If we are configured for it, mockfs should always be the last standard entry (and thus the last FS we attempt mountroot with) */
198 	{
199 		.vfc_vfsops = &mockfs_vfsops,
200 		.vfc_name = "mockfs",
201 		.vfc_typenum = FT_MOCKFS,
202 		.vfc_refcount = 0,
203 		.vfc_flags = MNT_LOCAL,
204 		.vfc_mountroot = mockfs_mountroot,
205 		.vfc_next = NULL,
206 		.vfc_reserved1 = 0,
207 		.vfc_reserved2 = 0,
208 		.vfc_vfsflags = VFC_VFSGENERICARGS,
209 		.vfc_descptr = NULL,
210 		.vfc_descsize = 0,
211 		.vfc_sysctl = NULL
212 	},
213 #endif /* MOCKFS */
214 
215 #if ROUTEFS
216 	/* If we are configured for it, mockfs should always be the last standard entry (and thus the last FS we attempt mountroot with) */
217 	{
218 		.vfc_vfsops = &routefs_vfsops,
219 		.vfc_name = "routefs",
220 		.vfc_typenum = FT_ROUTEFS,
221 		.vfc_refcount = 0,
222 		.vfc_flags = MNT_LOCAL,
223 		.vfc_mountroot = NULL,
224 		.vfc_next = NULL,
225 		.vfc_reserved1 = 0,
226 		.vfc_reserved2 = 0,
227 		.vfc_vfsflags = VFC_VFSGENERICARGS | VFC_VFS64BITREADY,
228 		.vfc_descptr = NULL,
229 		.vfc_descsize = 0,
230 		.vfc_sysctl = NULL
231 	},
232 #endif /* ROUTEFS */
233 
234 	{
235 		.vfc_vfsops = NULL,
236 		.vfc_name = "<unassigned>",
237 		.vfc_typenum = 0,
238 		.vfc_refcount = 0,
239 		.vfc_flags = 0,
240 		.vfc_mountroot = NULL,
241 		.vfc_next = NULL,
242 		.vfc_reserved1 = 0,
243 		.vfc_reserved2 = 0,
244 		.vfc_vfsflags = 0,
245 		.vfc_descptr = NULL,
246 		.vfc_descsize = 0,
247 		.vfc_sysctl = NULL
248 	},
249 	{
250 		.vfc_vfsops = NULL,
251 		.vfc_name = "<unassigned>",
252 		.vfc_typenum = 0,
253 		.vfc_refcount = 0,
254 		.vfc_flags = 0,
255 		.vfc_mountroot = NULL,
256 		.vfc_next = NULL,
257 		.vfc_reserved1 = 0,
258 		.vfc_reserved2 = 0,
259 		.vfc_vfsflags = 0,
260 		.vfc_descptr = NULL,
261 		.vfc_descsize = 0,
262 		.vfc_sysctl = NULL
263 	},
264 };
265 
266 /*
267  * vfs_init will set maxvfstypenum to the highest defined type number.
268  */
269 const int maxvfsslots = sizeof(vfstbllist) / sizeof(struct vfstable);
270 int numused_vfsslots = 0;
271 int numregistered_fses = 0;
272 int maxvfstypenum = VT_NON + 1;
273 struct vfstable *vfsconf = vfstbllist;
274 
275 /*
276  *
277  * vfs_opv_descs enumerates the list of vnode classes, each with it's own
278  * vnode operation vector.  It is consulted at system boot to build operation
279  * vectors.  It is NULL terminated.
280  *
281  */
282 extern struct vnodeopv_desc mfs_vnodeop_opv_desc;
283 extern const struct vnodeopv_desc dead_vnodeop_opv_desc;
284 #if FIFO && SOCKETS
285 extern const struct vnodeopv_desc fifo_vnodeop_opv_desc;
286 #endif /* SOCKETS */
287 extern const struct vnodeopv_desc spec_vnodeop_opv_desc;
288 extern struct vnodeopv_desc null_vnodeop_opv_desc;
289 extern struct vnodeopv_desc devfs_vnodeop_opv_desc;
290 extern struct vnodeopv_desc devfs_spec_vnodeop_opv_desc;
291 #if FDESC
292 extern struct vnodeopv_desc devfs_devfd_vnodeop_opv_desc;
293 extern const struct vnodeopv_desc devfs_fdesc_vnodeop_opv_desc;
294 #endif /* FDESC */
295 
296 #if MOCKFS
297 extern const struct vnodeopv_desc mockfs_vnodeop_opv_desc;
298 #endif /* MOCKFS */
299 
300 extern const struct vnodeopv_desc nullfs_vnodeop_opv_desc;
301 extern const struct vnodeopv_desc bindfs_vnodeop_opv_desc;
302 
303 const struct vnodeopv_desc *vfs_opv_descs[] = {
304 	&dead_vnodeop_opv_desc,
305 #if FIFO && SOCKETS
306 	&fifo_vnodeop_opv_desc,
307 #endif
308 	&spec_vnodeop_opv_desc,
309 #if MFS
310 	&mfs_vnodeop_opv_desc,
311 #endif
312 #if DEVFS
313 	&devfs_vnodeop_opv_desc,
314 	&devfs_spec_vnodeop_opv_desc,
315 #if FDESC
316 	&devfs_devfd_vnodeop_opv_desc,
317 	&devfs_fdesc_vnodeop_opv_desc,
318 #endif /* FDESC */
319 #endif /* DEVFS */
320 #if NULLFS
321 	&nullfs_vnodeop_opv_desc,
322 #endif /* NULLFS */
323 #if BINDFS
324 	&bindfs_vnodeop_opv_desc,
325 #endif /* BINDFS */
326 #if MOCKFS
327 	&mockfs_vnodeop_opv_desc,
328 #endif /* MOCKFS */
329 	NULL
330 };
331