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