1 /* $OpenBSD: vfs_init.c,v 1.44 2024/05/20 09:11:21 mvs 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 static struct vfsconf vfsconflist[] = {
54 #ifdef FFS
55 { &ffs_vfsops, MOUNT_FFS, 1, 0, MNT_LOCAL | MNT_SWAPPABLE,
56 sizeof(struct ufs_args) },
57 #endif
58
59 #ifdef MFS
60 { &mfs_vfsops, MOUNT_MFS, 3, 0, MNT_LOCAL,
61 sizeof(struct mfs_args) },
62 #endif
63
64 #ifdef EXT2FS
65 { &ext2fs_vfsops, MOUNT_EXT2FS, 17, 0, MNT_LOCAL | MNT_SWAPPABLE,
66 sizeof(struct ufs_args) },
67 #endif
68
69 #ifdef CD9660
70 { &cd9660_vfsops, MOUNT_CD9660, 14, 0, MNT_LOCAL,
71 sizeof(struct iso_args) },
72 #endif
73
74 #ifdef MSDOSFS
75 { &msdosfs_vfsops, MOUNT_MSDOS, 4, 0, MNT_LOCAL | MNT_SWAPPABLE,
76 sizeof(struct msdosfs_args) },
77 #endif
78
79 #ifdef NFSCLIENT
80 { &nfs_vfsops, MOUNT_NFS, 2, 0, MNT_SWAPPABLE,
81 sizeof(struct nfs_args) },
82 #endif
83
84 #ifdef NTFS
85 { &ntfs_vfsops, MOUNT_NTFS, 6, 0, MNT_LOCAL,
86 sizeof(struct ntfs_args) },
87 #endif
88
89 #ifdef UDF
90 { &udf_vfsops, MOUNT_UDF, 13, 0, MNT_LOCAL,
91 sizeof(struct iso_args) },
92 #endif
93
94 #ifdef FUSE
95 { &fusefs_vfsops, MOUNT_FUSEFS, 18, 0, 0,
96 sizeof(struct fusefs_args) },
97 #endif
98
99 #ifdef TMPFS
100 { &tmpfs_vfsops, MOUNT_TMPFS, 19, 0, MNT_LOCAL,
101 sizeof(struct tmpfs_args) },
102 #endif
103 };
104
105
106 /*
107 * Initially the size of the list, vfsinit will set maxvfsconf
108 * to the highest defined type number.
109 */
110 int maxvfsconf = sizeof(vfsconflist) / sizeof(struct vfsconf);
111
112 /* Initialize the vnode structures and initialize each file system type. */
113 void
vfsinit(void)114 vfsinit(void)
115 {
116 struct vfsconf *vfsp;
117 int i;
118
119 pool_init(&namei_pool, MAXPATHLEN, 0, IPL_NONE, PR_WAITOK, "namei",
120 NULL);
121
122 /* Initialize the vnode table. */
123 vntblinit();
124
125 /* Initialize the vnode name cache. */
126 nchinit();
127
128 maxvfsconf = 0;
129 for (i = 0; i < nitems(vfsconflist); i++) {
130 vfsp = &vfsconflist[i];
131 if (vfsp->vfc_typenum > maxvfsconf)
132 maxvfsconf = vfsp->vfc_typenum;
133 if (vfsp->vfc_vfsops->vfs_init != NULL)
134 (*vfsp->vfc_vfsops->vfs_init)(vfsp);
135 }
136 }
137
138 struct vfsconf *
vfs_byname(const char * name)139 vfs_byname(const char *name)
140 {
141 int i;
142
143 for (i = 0; i < nitems(vfsconflist); i++) {
144 if (strcmp(vfsconflist[i].vfc_name, name) == 0)
145 return &vfsconflist[i];
146 }
147 return NULL;
148 }
149
150 struct vfsconf *
vfs_bytypenum(int typenum)151 vfs_bytypenum(int typenum)
152 {
153 int i;
154
155 for (i = 0; i < nitems(vfsconflist); i++) {
156 if (vfsconflist[i].vfc_typenum == typenum)
157 return &vfsconflist[i];
158 }
159 return NULL;
160 }
161