1 /*	$OpenBSD: vfs_conf.c,v 1.27 2005/05/27 00:58:24 pedro Exp $	*/
2 /*	$NetBSD: vfs_conf.c,v 1.21.4.1 1995/11/01 00:06:26 jtc Exp $	*/
3 
4 /*
5  * Copyright (c) 1989, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the University nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  *	@(#)vfs_conf.c	8.8 (Berkeley) 3/31/94
33  */
34 
35 #include <sys/param.h>
36 #include <sys/mount.h>
37 #include <sys/vnode.h>
38 
39 #ifdef FFS
40 #include <ufs/ufs/quota.h>
41 #include <ufs/ufs/inode.h>
42 #include <ufs/ffs/ffs_extern.h>
43 #endif
44 
45 #ifdef LFS
46 #include <ufs/lfs/lfs_extern.h>
47 #endif
48 
49 #ifdef EXT2FS
50 #include <ufs/ext2fs/ext2fs_extern.h>
51 #endif
52 
53 #ifdef CD9660
54 #include <isofs/cd9660/iso.h>
55 #include <isofs/cd9660/cd9660_extern.h>
56 #endif
57 
58 #ifdef MFS
59 #include <ufs/mfs/mfs_extern.h>
60 #endif
61 
62 #ifdef NFSCLIENT
63 #include <sys/rwlock.h>		/*  XXX*/
64 #include <nfs/rpcv2.h>
65 #include <nfs/nfsproto.h>
66 #include <nfs/nfsnode.h>
67 #include <nfs/nfs.h>
68 #include <nfs/nfsmount.h>
69 #endif
70 
71 /*
72  * These define the root filesystem and device.
73  */
74 struct mount *rootfs;
75 struct vnode *rootvnode;
76 
77 /*
78  * Set up the filesystem operations for vnodes.
79  * The types are defined in mount.h.
80  */
81 
82 
83 #ifdef FFS
84 extern	const struct vfsops ffs_vfsops;
85 #endif
86 
87 #ifdef LFS
88 extern	const struct vfsops lfs_vfsops;
89 #endif
90 
91 #ifdef MFS
92 extern	const struct vfsops mfs_vfsops;
93 #endif
94 
95 #ifdef MSDOSFS
96 extern	const struct vfsops msdosfs_vfsops;
97 #endif
98 
99 #ifdef NFSCLIENT
100 extern	const struct vfsops nfs_vfsops;
101 #endif
102 
103 #ifdef FDESC
104 extern	const struct vfsops fdesc_vfsops;
105 #endif
106 
107 #ifdef PORTAL
108 extern	const struct vfsops portal_vfsops;
109 #endif
110 
111 #ifdef KERNFS
112 extern	const struct vfsops kernfs_vfsops;
113 #endif
114 
115 #ifdef PROCFS
116 extern	const struct vfsops procfs_vfsops;
117 #endif
118 
119 #ifdef CD9660
120 extern	const struct vfsops cd9660_vfsops;
121 #endif
122 
123 #ifdef ADOSFS
124 extern 	const struct vfsops adosfs_vfsops;
125 #endif
126 
127 #ifdef EXT2FS
128 extern	const struct vfsops ext2fs_vfsops;
129 #endif
130 
131 #ifdef XFS
132 extern  const struct vfsops xfs_vfsops;
133 #endif
134 
135 #ifdef NTFS
136 extern  const struct vfsops ntfs_vfsops;
137 #endif
138 
139 #ifdef UDF
140 extern  const struct vfsops udf_vfsops;
141 #endif
142 
143 /*
144  * Set up the filesystem operations for vnodes.
145  */
146 static struct vfsconf vfsconflist[] = {
147 
148         /* Fast Filesystem */
149 #ifdef FFS
150         { &ffs_vfsops, MOUNT_FFS, 1, 0, MNT_LOCAL, ffs_mountroot, NULL },
151 #endif
152 
153         /* Log-based Filesystem */
154 #ifdef LFS
155         { &lfs_vfsops, MOUNT_LFS, 5, 0, MNT_LOCAL, lfs_mountroot, NULL },
156 #endif
157 
158         /* Memory-based Filesystem */
159 #ifdef MFS
160         { &mfs_vfsops, MOUNT_MFS, 3, 0, MNT_LOCAL, mfs_mountroot, NULL },
161 #endif
162 
163 #ifdef EXT2FS
164 	{ &ext2fs_vfsops, MOUNT_EXT2FS, 17, 0, MNT_LOCAL, ext2fs_mountroot, NULL },
165 #endif
166         /* ISO9660 (aka CDROM) Filesystem */
167 #ifdef CD9660
168         { &cd9660_vfsops, MOUNT_CD9660, 14, 0, MNT_LOCAL, cd9660_mountroot, NULL },
169 #endif
170 
171         /* MSDOS Filesystem */
172 #ifdef MSDOSFS
173         { &msdosfs_vfsops, MOUNT_MSDOS, 4, 0, MNT_LOCAL, NULL, NULL },
174 #endif
175 
176         /* AmigaDOS Filesystem */
177 #ifdef ADOSFS
178         { &adosfs_vfsops, MOUNT_ADOSFS, 16, 0, MNT_LOCAL, NULL, NULL },
179 #endif
180 
181         /* Sun-compatible Network Filesystem */
182 #ifdef NFSCLIENT
183         { &nfs_vfsops, MOUNT_NFS, 2, 0, 0, nfs_mountroot, NULL },
184 #endif
185 
186 	/* XFS */
187 #ifdef XFS
188 	{ &xfs_vfsops, MOUNT_XFS, 21, 0, 0, NULL, NULL },
189 #endif
190 
191         /* /proc Filesystem */
192 #ifdef PROCFS
193         { &procfs_vfsops, MOUNT_PROCFS, 12, 0, 0, NULL, NULL },
194 #endif
195 
196         /* Portal Filesystem */
197 #ifdef PORTAL
198         { &portal_vfsops, MOUNT_PORTAL, 8, 0, 0, NULL, NULL },
199 #endif
200 
201         /* File Descriptor Filesystem */
202 #ifdef FDESC
203         { &fdesc_vfsops, MOUNT_FDESC, 7, 0, 0, NULL, NULL },
204 #endif
205 
206         /* Kernel Information Filesystem */
207 #ifdef KERNFS
208         { &kernfs_vfsops, MOUNT_KERNFS, 11, 0, 0, NULL, NULL },
209 #endif
210 
211 	/* NTFS Filesystem */
212 #ifdef NTFS
213 	{ &ntfs_vfsops, MOUNT_NTFS, 6, 0, MNT_LOCAL, NULL, NULL },
214 #endif
215 
216 	/* UDF Filesystem */
217 #ifdef UDF
218 	{ &udf_vfsops, MOUNT_UDF, 13, 0, MNT_LOCAL, NULL, NULL },
219 #endif
220 
221 };
222 
223 
224 /*
225  * Initially the size of the list, vfs_init will set maxvfsconf
226  * to the highest defined type number.
227  */
228 int maxvfsconf = sizeof(vfsconflist) / sizeof(struct vfsconf);
229 struct vfsconf *vfsconf = vfsconflist;
230 
231 
232 /*
233  * vfs_opv_descs enumerates the list of vnode classes, each with it's own
234  * vnode operation vector.  It is consulted at system boot to build operation
235  * vectors.  It is NULL terminated.
236  */
237 extern struct vnodeopv_desc sync_vnodeop_opv_desc;
238 extern struct vnodeopv_desc ffs_vnodeop_opv_desc;
239 extern struct vnodeopv_desc ffs_specop_opv_desc;
240 extern struct vnodeopv_desc ffs_fifoop_opv_desc;
241 extern struct vnodeopv_desc lfs_vnodeop_opv_desc;
242 extern struct vnodeopv_desc lfs_specop_opv_desc;
243 extern struct vnodeopv_desc lfs_fifoop_opv_desc;
244 extern struct vnodeopv_desc mfs_vnodeop_opv_desc;
245 extern struct vnodeopv_desc dead_vnodeop_opv_desc;
246 extern struct vnodeopv_desc fifo_vnodeop_opv_desc;
247 extern struct vnodeopv_desc spec_vnodeop_opv_desc;
248 extern struct vnodeopv_desc nfsv2_vnodeop_opv_desc;
249 extern struct vnodeopv_desc spec_nfsv2nodeop_opv_desc;
250 extern struct vnodeopv_desc fifo_nfsv2nodeop_opv_desc;
251 extern struct vnodeopv_desc fdesc_vnodeop_opv_desc;
252 extern struct vnodeopv_desc portal_vnodeop_opv_desc;
253 extern struct vnodeopv_desc kernfs_vnodeop_opv_desc;
254 extern struct vnodeopv_desc procfs_vnodeop_opv_desc;
255 extern struct vnodeopv_desc cd9660_vnodeop_opv_desc;
256 extern struct vnodeopv_desc cd9660_specop_opv_desc;
257 extern struct vnodeopv_desc cd9660_fifoop_opv_desc;
258 extern struct vnodeopv_desc msdosfs_vnodeop_opv_desc;
259 extern struct vnodeopv_desc adosfs_vnodeop_opv_desc;
260 extern struct vnodeopv_desc ext2fs_vnodeop_opv_desc;
261 extern struct vnodeopv_desc ext2fs_specop_opv_desc;
262 extern struct vnodeopv_desc ext2fs_fifoop_opv_desc;
263 extern struct vnodeopv_desc xfs_vnodeop_opv_desc;
264 extern struct vnodeopv_desc ntfs_vnodeop_opv_desc;
265 extern struct vnodeopv_desc udf_vnodeop_opv_desc;
266 
267 struct vnodeopv_desc *vfs_opv_descs[] = {
268 	&sync_vnodeop_opv_desc,
269 #ifdef FFS
270 	&ffs_vnodeop_opv_desc,
271 	&ffs_specop_opv_desc,
272 #ifdef FIFO
273 	&ffs_fifoop_opv_desc,
274 #endif
275 #endif
276 	&dead_vnodeop_opv_desc,
277 #ifdef FIFO
278 	&fifo_vnodeop_opv_desc,
279 #endif
280 	&spec_vnodeop_opv_desc,
281 #ifdef LFS
282 	&lfs_vnodeop_opv_desc,
283 	&lfs_specop_opv_desc,
284 #ifdef FIFO
285 	&lfs_fifoop_opv_desc,
286 #endif
287 #endif
288 #ifdef MFS
289 	&mfs_vnodeop_opv_desc,
290 #endif
291 #ifdef NFSCLIENT
292 	&nfsv2_vnodeop_opv_desc,
293 	&spec_nfsv2nodeop_opv_desc,
294 #ifdef FIFO
295 	&fifo_nfsv2nodeop_opv_desc,
296 #endif
297 #endif
298 #ifdef FDESC
299 	&fdesc_vnodeop_opv_desc,
300 #endif
301 #ifdef PORTAL
302 	&portal_vnodeop_opv_desc,
303 #endif
304 #ifdef KERNFS
305 	&kernfs_vnodeop_opv_desc,
306 #endif
307 #ifdef PROCFS
308 	&procfs_vnodeop_opv_desc,
309 #endif
310 #ifdef CD9660
311 	&cd9660_vnodeop_opv_desc,
312 	&cd9660_specop_opv_desc,
313 #ifdef FIFO
314 	&cd9660_fifoop_opv_desc,
315 #endif
316 #endif
317 #ifdef MSDOSFS
318 	&msdosfs_vnodeop_opv_desc,
319 #endif
320 #ifdef ADOSFS
321 	&adosfs_vnodeop_opv_desc,
322 #endif
323 #ifdef EXT2FS
324 	&ext2fs_vnodeop_opv_desc,
325 	&ext2fs_specop_opv_desc,
326 #ifdef FIFO
327 	&ext2fs_fifoop_opv_desc,
328 #endif
329 #endif
330 #ifdef XFS
331 	&xfs_vnodeop_opv_desc,
332 #endif
333 #ifdef NTFS
334 	&ntfs_vnodeop_opv_desc,
335 #endif
336 #ifdef UDF
337 	&udf_vnodeop_opv_desc,
338 #endif
339 
340 	NULL
341 };
342