1 /* $OpenBSD: vfs_init.c,v 1.42 2019/04/02 13:07:28 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 | MNT_SWAPPABLE, 97 sizeof(struct ufs_args) }, 98 #endif 99 100 #ifdef MFS 101 { &mfs_vfsops, MOUNT_MFS, 3, 0, MNT_LOCAL, 102 sizeof(struct mfs_args) }, 103 #endif 104 105 #ifdef EXT2FS 106 { &ext2fs_vfsops, MOUNT_EXT2FS, 17, 0, MNT_LOCAL | MNT_SWAPPABLE, 107 sizeof(struct ufs_args) }, 108 #endif 109 110 #ifdef CD9660 111 { &cd9660_vfsops, MOUNT_CD9660, 14, 0, MNT_LOCAL, 112 sizeof(struct iso_args) }, 113 #endif 114 115 #ifdef MSDOSFS 116 { &msdosfs_vfsops, MOUNT_MSDOS, 4, 0, MNT_LOCAL | MNT_SWAPPABLE, 117 sizeof(struct msdosfs_args) }, 118 #endif 119 120 #ifdef NFSCLIENT 121 { &nfs_vfsops, MOUNT_NFS, 2, 0, MNT_SWAPPABLE, 122 sizeof(struct nfs_args) }, 123 #endif 124 125 #ifdef NTFS 126 { &ntfs_vfsops, MOUNT_NTFS, 6, 0, MNT_LOCAL, 127 sizeof(struct ntfs_args) }, 128 #endif 129 130 #ifdef UDF 131 { &udf_vfsops, MOUNT_UDF, 13, 0, MNT_LOCAL, 132 sizeof(struct iso_args) }, 133 #endif 134 135 #ifdef FUSE 136 { &fusefs_vfsops, MOUNT_FUSEFS, 18, 0, MNT_LOCAL, 137 sizeof(struct fusefs_args) }, 138 #endif 139 140 #ifdef TMPFS 141 { &tmpfs_vfsops, MOUNT_TMPFS, 19, 0, MNT_LOCAL, 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 153 /* Initialize the vnode structures and initialize each file system type. */ 154 void 155 vfsinit(void) 156 { 157 struct vfsconf *vfsp; 158 int i; 159 160 pool_init(&namei_pool, MAXPATHLEN, 0, IPL_NONE, PR_WAITOK, "namei", 161 NULL); 162 163 /* Initialize the vnode table. */ 164 vntblinit(); 165 166 /* Initialize the vnode name cache. */ 167 nchinit(); 168 169 maxvfsconf = 0; 170 for (i = 0; i < nitems(vfsconflist); i++) { 171 vfsp = &vfsconflist[i]; 172 if (vfsp->vfc_typenum > maxvfsconf) 173 maxvfsconf = vfsp->vfc_typenum; 174 if (vfsp->vfc_vfsops->vfs_init != NULL) 175 (*vfsp->vfc_vfsops->vfs_init)(vfsp); 176 } 177 } 178 179 struct vfsconf * 180 vfs_byname(const char *name) 181 { 182 int i; 183 184 for (i = 0; i < nitems(vfsconflist); i++) { 185 if (strcmp(vfsconflist[i].vfc_name, name) == 0) 186 return &vfsconflist[i]; 187 } 188 return NULL; 189 } 190 191 struct vfsconf * 192 vfs_bytypenum(int typenum) 193 { 194 int i; 195 196 for (i = 0; i < nitems(vfsconflist); i++) { 197 if (vfsconflist[i].vfc_typenum == typenum) 198 return &vfsconflist[i]; 199 } 200 return NULL; 201 } 202