xref: /openbsd-src/sys/kern/vfs_init.c (revision b55f20ad4b4ba253aab91cd9f1defbdc0f3d73f5)
1 /*	$OpenBSD: vfs_init.c,v 1.30 2012/08/23 06:12:49 deraadt Exp $	*/
2 /*	$NetBSD: vfs_init.c,v 1.6 1996/02/09 19:00:58 christos Exp $	*/
3 
4 /*
5  * Copyright (c) 1989, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * This code is derived from software contributed
9  * to Berkeley by John Heidemann of the UCLA Ficus project.
10  *
11  * Source: * @(#)i405_init.c 2.10 92/04/27 UCLA Ficus project
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright
19  *    notice, this list of conditions and the following disclaimer in the
20  *    documentation and/or other materials provided with the distribution.
21  * 3. Neither the name of the University nor the names of its contributors
22  *    may be used to endorse or promote products derived from this software
23  *    without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  *
37  *	@(#)vfs_init.c	8.3 (Berkeley) 1/4/94
38  */
39 
40 #include <sys/param.h>
41 #include <sys/mount.h>
42 #include <sys/vnode.h>
43 #include <sys/systm.h>
44 #include <sys/pool.h>
45 
46 struct pool namei_pool;
47 
48 /* This defines the root filesystem. */
49 struct vnode *rootvnode;
50 
51 /* Set up the filesystem operations for vnodes. */
52 #ifdef FFS
53 extern	const struct vfsops ffs_vfsops;
54 #endif
55 
56 #ifdef MFS
57 extern	const struct vfsops mfs_vfsops;
58 #endif
59 
60 #ifdef MSDOSFS
61 extern	const struct vfsops msdosfs_vfsops;
62 #endif
63 
64 #ifdef NFSCLIENT
65 extern	const struct vfsops nfs_vfsops;
66 #endif
67 
68 #ifdef PROCFS
69 extern	const struct vfsops procfs_vfsops;
70 #endif
71 
72 #ifdef CD9660
73 extern	const struct vfsops cd9660_vfsops;
74 #endif
75 
76 #ifdef EXT2FS
77 extern	const struct vfsops ext2fs_vfsops;
78 #endif
79 
80 #ifdef NTFS
81 extern  const struct vfsops ntfs_vfsops;
82 #endif
83 
84 #ifdef UDF
85 extern  const struct vfsops udf_vfsops;
86 #endif
87 
88 /* Set up the filesystem operations for vnodes. */
89 static struct vfsconf vfsconflist[] = {
90 #ifdef FFS
91         { &ffs_vfsops, MOUNT_FFS, 1, 0, MNT_LOCAL, NULL },
92 #endif
93 
94 #ifdef MFS
95         { &mfs_vfsops, MOUNT_MFS, 3, 0, MNT_LOCAL, NULL },
96 #endif
97 
98 #ifdef EXT2FS
99 	{ &ext2fs_vfsops, MOUNT_EXT2FS, 17, 0, MNT_LOCAL, NULL },
100 #endif
101 
102 #ifdef CD9660
103         { &cd9660_vfsops, MOUNT_CD9660, 14, 0, MNT_LOCAL, NULL },
104 #endif
105 
106 #ifdef MSDOSFS
107         { &msdosfs_vfsops, MOUNT_MSDOS, 4, 0, MNT_LOCAL, NULL },
108 #endif
109 
110 #ifdef NFSCLIENT
111         { &nfs_vfsops, MOUNT_NFS, 2, 0, 0, NULL },
112 #endif
113 
114 #ifdef PROCFS
115         { &procfs_vfsops, MOUNT_PROCFS, 12, 0, 0, NULL },
116 #endif
117 
118 #ifdef NTFS
119 	{ &ntfs_vfsops, MOUNT_NTFS, 6, 0, MNT_LOCAL, NULL },
120 #endif
121 
122 #ifdef UDF
123 	{ &udf_vfsops, MOUNT_UDF, 13, 0, MNT_LOCAL, NULL },
124 #endif
125 };
126 
127 
128 /*
129  * Initially the size of the list, vfsinit will set maxvfsconf
130  * to the highest defined type number.
131  */
132 int maxvfsconf = sizeof(vfsconflist) / sizeof(struct vfsconf);
133 struct vfsconf *vfsconf = vfsconflist;
134 
135 /* Initialize the vnode structures and initialize each file system type. */
136 void
137 vfsinit(void)
138 {
139 	int i;
140 	struct vfsconf *vfsconflist;
141 	int vfsconflistlen;
142 
143 	pool_init(&namei_pool, MAXPATHLEN, 0, 0, 0, "namei",
144 	    &pool_allocator_nointr);
145 
146 	/* Initialize the vnode table. */
147 	vntblinit();
148 
149 	/* Initialize the vnode name cache. */
150 	nchinit();
151 
152 	/*
153 	 * Stop using vfsconf and maxvfsconf as a temporary storage,
154 	 * set them to their correct values now.
155 	 */
156 	vfsconflist = vfsconf;
157 	vfsconflistlen = maxvfsconf;
158 	vfsconf = NULL;
159 	maxvfsconf = 0;
160 
161 	for (i = 0; i < vfsconflistlen; i++)
162 		vfs_register(&vfsconflist[i]);
163 }
164