1 /* $OpenBSD: vfs_init.c,v 1.39 2017/12/11 05:27:40 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/namei.h> 43 #include <sys/vnode.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 CD9660 69 extern const struct vfsops cd9660_vfsops; 70 #endif 71 72 #ifdef EXT2FS 73 extern const struct vfsops ext2fs_vfsops; 74 #endif 75 76 #ifdef NTFS 77 extern const struct vfsops ntfs_vfsops; 78 #endif 79 80 #ifdef UDF 81 extern const struct vfsops udf_vfsops; 82 #endif 83 84 #ifdef FUSE 85 extern const struct vfsops fusefs_vfsops; 86 #endif 87 88 #ifdef TMPFS 89 extern const struct vfsops tmpfs_vfsops; 90 #endif 91 92 /* Set up the filesystem operations for vnodes. */ 93 static struct vfsconf vfsconflist[] = { 94 #ifdef FFS 95 { &ffs_vfsops, MOUNT_FFS, 1, 0, MNT_LOCAL, NULL, 96 sizeof(struct ufs_args) }, 97 #endif 98 99 #ifdef MFS 100 { &mfs_vfsops, MOUNT_MFS, 3, 0, MNT_LOCAL, NULL, 101 sizeof(struct mfs_args) }, 102 #endif 103 104 #ifdef EXT2FS 105 { &ext2fs_vfsops, MOUNT_EXT2FS, 17, 0, MNT_LOCAL, NULL, 106 sizeof(struct ufs_args) }, 107 #endif 108 109 #ifdef CD9660 110 { &cd9660_vfsops, MOUNT_CD9660, 14, 0, MNT_LOCAL, NULL, 111 sizeof(struct iso_args) }, 112 #endif 113 114 #ifdef MSDOSFS 115 { &msdosfs_vfsops, MOUNT_MSDOS, 4, 0, MNT_LOCAL, NULL, 116 sizeof(struct msdosfs_args) }, 117 #endif 118 119 #ifdef NFSCLIENT 120 { &nfs_vfsops, MOUNT_NFS, 2, 0, 0, NULL, 121 sizeof(struct nfs_args) }, 122 #endif 123 124 #ifdef NTFS 125 { &ntfs_vfsops, MOUNT_NTFS, 6, 0, MNT_LOCAL, NULL, 126 sizeof(struct ntfs_args) }, 127 #endif 128 129 #ifdef UDF 130 { &udf_vfsops, MOUNT_UDF, 13, 0, MNT_LOCAL, NULL, 131 sizeof(struct iso_args) }, 132 #endif 133 134 #ifdef FUSE 135 { &fusefs_vfsops, MOUNT_FUSEFS, 18, 0, MNT_LOCAL, NULL, 136 sizeof(struct fusefs_args) }, 137 #endif 138 139 #ifdef TMPFS 140 { &tmpfs_vfsops, MOUNT_TMPFS, 19, 0, MNT_LOCAL, NULL, 141 sizeof(struct tmpfs_args) }, 142 #endif 143 }; 144 145 146 /* 147 * Initially the size of the list, vfsinit will set maxvfsconf 148 * to the highest defined type number. 149 */ 150 int maxvfsconf = sizeof(vfsconflist) / sizeof(struct vfsconf); 151 struct vfsconf *vfsconf = vfsconflist; 152 153 /* Initialize the vnode structures and initialize each file system type. */ 154 void 155 vfsinit(void) 156 { 157 int i; 158 struct vfsconf *vfsconflist; 159 int vfsconflistlen; 160 161 pool_init(&namei_pool, MAXPATHLEN, 0, IPL_NONE, PR_WAITOK, "namei", 162 NULL); 163 164 /* Initialize the vnode table. */ 165 vntblinit(); 166 167 /* Initialize the vnode name cache. */ 168 nchinit(); 169 170 /* 171 * Stop using vfsconf and maxvfsconf as a temporary storage, 172 * set them to their correct values now. 173 */ 174 vfsconflist = vfsconf; 175 vfsconflistlen = maxvfsconf; 176 vfsconf = NULL; 177 maxvfsconf = 0; 178 179 for (i = 0; i < vfsconflistlen; i++) 180 vfs_register(&vfsconflist[i]); 181 } 182