]> git.saurik.com Git - apple/xnu.git/blob - bsd/vfs/vfs_conf.c
xnu-7195.101.1.tar.gz
[apple/xnu.git] / bsd / vfs / vfs_conf.c
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 nfs_vfsops;
95 extern int nfs_mountroot(void);
96 extern struct vfsops afs_vfsops;
97 extern struct vfsops null_vfsops;
98 extern struct vfsops devfs_vfsops;
99 extern const struct vfsops routefs_vfsops;
100 extern struct vfsops nullfs_vfsops;
101 extern struct vfsops bindfs_vfsops;
102
103 #if MOCKFS
104 extern struct vfsops mockfs_vfsops;
105 extern int mockfs_mountroot(mount_t, vnode_t, vfs_context_t);
106 #endif /* MOCKFS */
107
108 /*
109 * For nfs_mountroot(void) cast. nfs_mountroot ignores its parameters, if
110 * invoked through this table.
111 */
112 typedef int (*mountroot_t)(mount_t, vnode_t, vfs_context_t);
113
114 enum fs_type_num {
115 FT_NFS = 2,
116 FT_DEVFS = 19,
117 FT_SYNTHFS = 20,
118 FT_ROUTEFS = 21,
119 FT_NULLFS = 22,
120 FT_BINDFS = 23,
121 FT_MOCKFS = 0x6D6F636B
122 };
123
124 /*
125 * Set up the filesystem operations for vnodes.
126 */
127 static struct vfstable vfstbllist[] = {
128 /* Sun-compatible Network Filesystem */
129 #if CONFIG_NFS_CLIENT
130 {
131 .vfc_vfsops = &nfs_vfsops,
132 .vfc_name = "nfs",
133 .vfc_typenum = FT_NFS,
134 .vfc_refcount = 0,
135 .vfc_flags = 0,
136 .vfc_mountroot = NULL,
137 .vfc_next = NULL,
138 .vfc_reserved1 = 0,
139 .vfc_reserved2 = 0,
140 .vfc_vfsflags = VFC_VFSGENERICARGS | VFC_VFSPREFLIGHT | VFC_VFS64BITREADY | VFC_VFSREADDIR_EXTENDED,
141 .vfc_descptr = NULL,
142 .vfc_descsize = 0,
143 .vfc_sysctl = NULL
144 },
145 #endif /* CONFIG_NFS_CLIENT */
146
147 /* Device Filesystem */
148 #if DEVFS
149 #if CONFIG_MACF
150 {
151 .vfc_vfsops = &devfs_vfsops,
152 .vfc_name = "devfs",
153 .vfc_typenum = FT_DEVFS,
154 .vfc_refcount = 0,
155 .vfc_flags = MNT_MULTILABEL,
156 .vfc_mountroot = NULL,
157 .vfc_next = NULL,
158 .vfc_reserved1 = 0,
159 .vfc_reserved2 = 0,
160 .vfc_vfsflags = VFC_VFSGENERICARGS | VFC_VFS64BITREADY,
161 .vfc_descptr = NULL,
162 .vfc_descsize = 0,
163 .vfc_sysctl = NULL
164 },
165 #else /* !CONFIG_MAC */
166 {
167 .vfc_vfsops = &devfs_vfsops,
168 .vfc_name = "devfs",
169 .vfc_typenum = FT_DEVFS,
170 .vfc_refcount = 0,
171 .vfc_flags = 0,
172 .vfc_mountroot = NULL,
173 .vfc_next = NULL,
174 .vfc_reserved1 = 0,
175 .vfc_reserved2 = 0,
176 .vfc_vfsflags = VFC_VFSGENERICARGS | VFC_VFS64BITREADY,
177 .vfc_descptr = NULL,
178 .vfc_descsize = 0,
179 .vfc_sysctl = NULL
180 },
181 #endif /* CONFIG_MAC */
182 #endif /* DEVFS */
183
184 #ifndef __LP64__
185 #endif /* __LP64__ */
186
187 #if NULLFS
188 {
189 .vfc_vfsops = &nullfs_vfsops,
190 .vfc_name = "nullfs",
191 .vfc_typenum = FT_NULLFS,
192 .vfc_refcount = 0,
193 .vfc_flags = MNT_DONTBROWSE | MNT_RDONLY,
194 .vfc_mountroot = NULL,
195 .vfc_next = NULL,
196 .vfc_reserved1 = 0,
197 .vfc_reserved2 = 0,
198 .vfc_vfsflags = VFC_VFS64BITREADY,
199 .vfc_descptr = NULL,
200 .vfc_descsize = 0,
201 .vfc_sysctl = NULL
202 },
203 #endif /* NULLFS */
204
205 #if BINDFS
206 {
207 .vfc_vfsops = &bindfs_vfsops,
208 .vfc_name = "bindfs",
209 .vfc_typenum = FT_BINDFS,
210 .vfc_refcount = 0,
211 .vfc_flags = MNT_DONTBROWSE | MNT_RDONLY,
212 .vfc_mountroot = NULL,
213 .vfc_next = NULL,
214 .vfc_reserved1 = 0,
215 .vfc_reserved2 = 0,
216 .vfc_vfsflags = VFC_VFS64BITREADY,
217 .vfc_descptr = NULL,
218 .vfc_descsize = 0,
219 .vfc_sysctl = NULL
220 },
221 #endif /* BINDFS */
222
223 #if MOCKFS
224 /* If we are configured for it, mockfs should always be the last standard entry (and thus the last FS we attempt mountroot with) */
225 {
226 .vfc_vfsops = &mockfs_vfsops,
227 .vfc_name = "mockfs",
228 .vfc_typenum = FT_MOCKFS,
229 .vfc_refcount = 0,
230 .vfc_flags = MNT_LOCAL,
231 .vfc_mountroot = mockfs_mountroot,
232 .vfc_next = NULL,
233 .vfc_reserved1 = 0,
234 .vfc_reserved2 = 0,
235 .vfc_vfsflags = VFC_VFSGENERICARGS,
236 .vfc_descptr = NULL,
237 .vfc_descsize = 0,
238 .vfc_sysctl = NULL
239 },
240 #endif /* MOCKFS */
241
242 #if ROUTEFS
243 /* If we are configured for it, mockfs should always be the last standard entry (and thus the last FS we attempt mountroot with) */
244 {
245 .vfc_vfsops = &routefs_vfsops,
246 .vfc_name = "routefs",
247 .vfc_typenum = FT_ROUTEFS,
248 .vfc_refcount = 0,
249 .vfc_flags = MNT_LOCAL,
250 .vfc_mountroot = NULL,
251 .vfc_next = NULL,
252 .vfc_reserved1 = 0,
253 .vfc_reserved2 = 0,
254 .vfc_vfsflags = VFC_VFSGENERICARGS | VFC_VFS64BITREADY,
255 .vfc_descptr = NULL,
256 .vfc_descsize = 0,
257 .vfc_sysctl = NULL
258 },
259 #endif /* ROUTEFS */
260
261 {
262 .vfc_vfsops = NULL,
263 .vfc_name = "<unassigned>",
264 .vfc_typenum = 0,
265 .vfc_refcount = 0,
266 .vfc_flags = 0,
267 .vfc_mountroot = NULL,
268 .vfc_next = NULL,
269 .vfc_reserved1 = 0,
270 .vfc_reserved2 = 0,
271 .vfc_vfsflags = 0,
272 .vfc_descptr = NULL,
273 .vfc_descsize = 0,
274 .vfc_sysctl = NULL
275 },
276 {
277 .vfc_vfsops = NULL,
278 .vfc_name = "<unassigned>",
279 .vfc_typenum = 0,
280 .vfc_refcount = 0,
281 .vfc_flags = 0,
282 .vfc_mountroot = NULL,
283 .vfc_next = NULL,
284 .vfc_reserved1 = 0,
285 .vfc_reserved2 = 0,
286 .vfc_vfsflags = 0,
287 .vfc_descptr = NULL,
288 .vfc_descsize = 0,
289 .vfc_sysctl = NULL
290 },
291 };
292
293 /*
294 * vfs_init will set maxvfstypenum to the highest defined type number.
295 */
296 const int maxvfsslots = sizeof(vfstbllist) / sizeof(struct vfstable);
297 int numused_vfsslots = 0;
298 int numregistered_fses = 0;
299 int maxvfstypenum = VT_NON + 1;
300 struct vfstable *vfsconf = vfstbllist;
301
302 /*
303 *
304 * vfs_opv_descs enumerates the list of vnode classes, each with it's own
305 * vnode operation vector. It is consulted at system boot to build operation
306 * vectors. It is NULL terminated.
307 *
308 */
309 extern struct vnodeopv_desc mfs_vnodeop_opv_desc;
310 extern const struct vnodeopv_desc dead_vnodeop_opv_desc;
311 #if FIFO && SOCKETS
312 extern const struct vnodeopv_desc fifo_vnodeop_opv_desc;
313 #endif /* SOCKETS */
314 extern const struct vnodeopv_desc spec_vnodeop_opv_desc;
315 extern const struct vnodeopv_desc nfsv2_vnodeop_opv_desc;
316 extern const struct vnodeopv_desc spec_nfsv2nodeop_opv_desc;
317 extern const struct vnodeopv_desc fifo_nfsv2nodeop_opv_desc;
318 #if CONFIG_NFS4
319 extern const struct vnodeopv_desc nfsv4_vnodeop_opv_desc;
320 extern const struct vnodeopv_desc spec_nfsv4nodeop_opv_desc;
321 extern const struct vnodeopv_desc fifo_nfsv4nodeop_opv_desc;
322 #endif
323 extern struct vnodeopv_desc null_vnodeop_opv_desc;
324 extern struct vnodeopv_desc devfs_vnodeop_opv_desc;
325 extern struct vnodeopv_desc devfs_spec_vnodeop_opv_desc;
326 #if FDESC
327 extern struct vnodeopv_desc devfs_devfd_vnodeop_opv_desc;
328 extern const struct vnodeopv_desc devfs_fdesc_vnodeop_opv_desc;
329 #endif /* FDESC */
330
331 #if MOCKFS
332 extern const struct vnodeopv_desc mockfs_vnodeop_opv_desc;
333 #endif /* MOCKFS */
334
335 extern const struct vnodeopv_desc nullfs_vnodeop_opv_desc;
336 extern const struct vnodeopv_desc bindfs_vnodeop_opv_desc;
337
338 const struct vnodeopv_desc *vfs_opv_descs[] = {
339 &dead_vnodeop_opv_desc,
340 #if FIFO && SOCKETS
341 &fifo_vnodeop_opv_desc,
342 #endif
343 &spec_vnodeop_opv_desc,
344 #if MFS
345 &mfs_vnodeop_opv_desc,
346 #endif
347 #if CONFIG_NFS_CLIENT
348 &nfsv2_vnodeop_opv_desc,
349 &spec_nfsv2nodeop_opv_desc,
350 #if CONFIG_NFS4
351 &nfsv4_vnodeop_opv_desc,
352 &spec_nfsv4nodeop_opv_desc,
353 #endif
354 #if FIFO
355 &fifo_nfsv2nodeop_opv_desc,
356 #if CONFIG_NFS4
357 &fifo_nfsv4nodeop_opv_desc,
358 #endif /* CONFIG_NFS4 */
359 #endif /* FIFO */
360 #endif /* CONFIG_NFS_CLIENT */
361 #if DEVFS
362 &devfs_vnodeop_opv_desc,
363 &devfs_spec_vnodeop_opv_desc,
364 #if FDESC
365 &devfs_devfd_vnodeop_opv_desc,
366 &devfs_fdesc_vnodeop_opv_desc,
367 #endif /* FDESC */
368 #endif /* DEVFS */
369 #if NULLFS
370 &nullfs_vnodeop_opv_desc,
371 #endif /* NULLFS */
372 #if BINDFS
373 &bindfs_vnodeop_opv_desc,
374 #endif /* BINDFS */
375 #if MOCKFS
376 &mockfs_vnodeop_opv_desc,
377 #endif /* MOCKFS */
378 NULL
379 };