xref: /openbsd-src/sys/kern/vfs_init.c (revision 6d4b78c662d82b8af03c81f64c38fdba924e23b6)
1 /*	$OpenBSD: vfs_init.c,v 1.40 2018/09/16 11:41:44 visa 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/systm.h>
42 #include <sys/mount.h>
43 #include <sys/namei.h>
44 #include <sys/vnode.h>
45 #include <sys/pool.h>
46 
47 struct pool namei_pool;
48 
49 /* This defines the root filesystem. */
50 struct vnode *rootvnode;
51 
52 /* Set up the filesystem operations for vnodes. */
53 #ifdef FFS
54 extern	const struct vfsops ffs_vfsops;
55 #endif
56 
57 #ifdef MFS
58 extern	const struct vfsops mfs_vfsops;
59 #endif
60 
61 #ifdef MSDOSFS
62 extern	const struct vfsops msdosfs_vfsops;
63 #endif
64 
65 #ifdef NFSCLIENT
66 extern	const struct vfsops nfs_vfsops;
67 #endif
68 
69 #ifdef CD9660
70 extern	const struct vfsops cd9660_vfsops;
71 #endif
72 
73 #ifdef EXT2FS
74 extern	const struct vfsops ext2fs_vfsops;
75 #endif
76 
77 #ifdef NTFS
78 extern  const struct vfsops ntfs_vfsops;
79 #endif
80 
81 #ifdef UDF
82 extern  const struct vfsops udf_vfsops;
83 #endif
84 
85 #ifdef FUSE
86 extern const struct vfsops fusefs_vfsops;
87 #endif
88 
89 #ifdef TMPFS
90 extern  const struct vfsops tmpfs_vfsops;
91 #endif
92 
93 /* Set up the filesystem operations for vnodes. */
94 static struct vfsconf vfsconflist[] = {
95 #ifdef FFS
96         { &ffs_vfsops, MOUNT_FFS, 1, 0, MNT_LOCAL, NULL,
97 	    sizeof(struct ufs_args) },
98 #endif
99 
100 #ifdef MFS
101         { &mfs_vfsops, MOUNT_MFS, 3, 0, MNT_LOCAL, NULL,
102 	    sizeof(struct mfs_args) },
103 #endif
104 
105 #ifdef EXT2FS
106 	{ &ext2fs_vfsops, MOUNT_EXT2FS, 17, 0, MNT_LOCAL, NULL,
107 	    sizeof(struct ufs_args) },
108 #endif
109 
110 #ifdef CD9660
111         { &cd9660_vfsops, MOUNT_CD9660, 14, 0, MNT_LOCAL, NULL,
112 	    sizeof(struct iso_args) },
113 #endif
114 
115 #ifdef MSDOSFS
116         { &msdosfs_vfsops, MOUNT_MSDOS, 4, 0, MNT_LOCAL, NULL,
117 	    sizeof(struct msdosfs_args) },
118 #endif
119 
120 #ifdef NFSCLIENT
121         { &nfs_vfsops, MOUNT_NFS, 2, 0, 0, NULL,
122 	    sizeof(struct nfs_args) },
123 #endif
124 
125 #ifdef NTFS
126 	{ &ntfs_vfsops, MOUNT_NTFS, 6, 0, MNT_LOCAL, NULL,
127 	    sizeof(struct ntfs_args) },
128 #endif
129 
130 #ifdef UDF
131 	{ &udf_vfsops, MOUNT_UDF, 13, 0, MNT_LOCAL, NULL,
132 	    sizeof(struct iso_args) },
133 #endif
134 
135 #ifdef FUSE
136 	{ &fusefs_vfsops, MOUNT_FUSEFS, 18, 0, MNT_LOCAL, NULL,
137 	    sizeof(struct fusefs_args) },
138 #endif
139 
140 #ifdef TMPFS
141 	{ &tmpfs_vfsops, MOUNT_TMPFS, 19, 0, MNT_LOCAL, NULL,
142 	    sizeof(struct tmpfs_args) },
143 #endif
144 };
145 
146 
147 /*
148  * Initially the size of the list, vfsinit will set maxvfsconf
149  * to the highest defined type number.
150  */
151 int maxvfsconf = sizeof(vfsconflist) / sizeof(struct vfsconf);
152 struct vfsconf *vfsconf = vfsconflist;
153 
154 /* Initialize the vnode structures and initialize each file system type. */
155 void
156 vfsinit(void)
157 {
158 	int i;
159 	struct vfsconf *vfsconflist;
160 	int vfsconflistlen;
161 
162 	pool_init(&namei_pool, MAXPATHLEN, 0, IPL_NONE, PR_WAITOK, "namei",
163 	    NULL);
164 
165 	/* Initialize the vnode table. */
166 	vntblinit();
167 
168 	/* Initialize the vnode name cache. */
169 	nchinit();
170 
171 	/*
172 	 * Stop using vfsconf and maxvfsconf as a temporary storage,
173 	 * set them to their correct values now.
174 	 */
175 	vfsconflist = vfsconf;
176 	vfsconflistlen = maxvfsconf;
177 	vfsconf = NULL;
178 	maxvfsconf = 0;
179 
180 	for (i = 0; i < vfsconflistlen; i++)
181 		vfs_register(&vfsconflist[i]);
182 }
183 
184 struct vfsconf *
185 vfs_byname(const char *name)
186 {
187 	struct vfsconf *vfsp;
188 
189 	for (vfsp = vfsconf; vfsp != NULL; vfsp = vfsp->vfc_next) {
190 		if (strcmp(vfsp->vfc_name, name) == 0)
191 			break;
192 	}
193 	return vfsp;
194 }
195 
196 struct vfsconf *
197 vfs_bytypenum(int typenum)
198 {
199 	struct vfsconf *vfsp;
200 
201 	for (vfsp = vfsconf; vfsp != NULL; vfsp = vfsp->vfc_next) {
202 		if (vfsp->vfc_typenum == typenum)
203 			break;
204 	}
205 	return vfsp;
206 }
207