1 /* 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * Copyright (c) 1995 Artisoft, Inc. All Rights Reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed by the University of 17 * California, Berkeley and its contributors. 18 * 4. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)vfs_conf.c 8.8 (Berkeley) 3/31/94 35 * $Id: vfs_conf.c,v 1.9 1995/09/09 18:10:15 davidg Exp $ 36 */ 37 38 /* 39 * PURPOSE: This file abstracts the root mounting interface from 40 * the per file system semantics for handling mounts, 41 * the overall intent of which is to move the BSD 42 * internals dependence out of the FS code, both to 43 * make the FS code more portable and to free up some 44 * of the BSD internals so that they may more easily 45 * be changed. 46 * 47 * NOTE1: Code is single entry/single exit to aid debugging 48 * and conversion for kernel multithreading. 49 * 50 * NOTE2: Code notes lock state in headers on entry and exit 51 * as an aid to conversion for kernel multithreading 52 * on SMP reentrancy 53 */ 54 #include <sys/param.h> /* dev_t (types.h)*/ 55 #include <sys/systm.h> /* rootvp*/ 56 #include <sys/proc.h> /* curproc*/ 57 #include <sys/vnode.h> /* NULLVP*/ 58 #include <sys/mount.h> /* struct mount*/ 59 #include <sys/malloc.h> /* M_MOUNT*/ 60 61 /* 62 * GLOBALS 63 */ 64 int (*mountroot) __P((void *)); 65 struct vnode *rootvnode; 66 struct vfsops *mountrootvfsops; 67 68 69 /* 70 * Common root mount code shared by all filesystems 71 */ 72 #define ROOTDIR "/" 73 #define ROOTNAME "root_device" 74 75 76 77 /* 78 * vfs_mountroot 79 * 80 * Common entry point for root mounts 81 * 82 * PARAMETERS: 83 * data pointer to the vfs_ops for the FS type mounting 84 * 85 * RETURNS: 0 Success 86 * !0 error number (errno.h) 87 * 88 * LOCK STATE: 89 * ENTRY 90 * <no locks held> 91 * EXIT 92 * <no locks held> 93 * 94 * NOTES: 95 * This code is currently supported only for use for 96 * the FFS file system type. This is a matter of 97 * fixing the other file systems, not this code! 98 */ 99 int 100 vfs_mountroot(data) 101 void *data; /* file system function table*/ 102 { 103 struct mount *mp; 104 u_int size; 105 int err = 0; 106 struct proc *p = curproc; /* XXX */ 107 struct vfsops *mnt_op = (struct vfsops *)data; 108 109 /* 110 * New root mount structure 111 */ 112 mp = malloc((u_long)sizeof(struct mount), M_MOUNT, M_WAITOK); 113 bzero((char *)mp, (u_long)sizeof(struct mount)); 114 mp->mnt_op = mnt_op; 115 mp->mnt_flag = MNT_ROOTFS; 116 mp->mnt_vnodecovered = NULLVP; 117 118 /* 119 * Lock mount point 120 */ 121 if( ( err = vfs_lock(mp)) != 0) 122 goto error_1; 123 124 /* Save "last mounted on" info for mount point (NULL pad)*/ 125 copystr( ROOTDIR, /* mount point*/ 126 mp->mnt_stat.f_mntonname, /* save area*/ 127 MNAMELEN - 1, /* max size*/ 128 &size); /* real size*/ 129 bzero( mp->mnt_stat.f_mntonname + size, MNAMELEN - size); 130 131 /* Save "mounted from" info for mount point (NULL pad)*/ 132 copystr( ROOTNAME, /* device name*/ 133 mp->mnt_stat.f_mntfromname, /* save area*/ 134 MNAMELEN - 1, /* max size*/ 135 &size); /* real size*/ 136 bzero( mp->mnt_stat.f_mntfromname + size, MNAMELEN - size); 137 138 /* 139 * Attempt the mount 140 */ 141 err = VFS_MOUNT( mp, NULL, NULL, NULL, p); 142 if( err) 143 goto error_2; 144 145 /* Add fs to list of mounted file systems*/ 146 CIRCLEQ_INSERT_TAIL( &mountlist, mp, mnt_list); 147 148 /* Unlock mount point*/ 149 vfs_unlock(mp); 150 151 /* root mount, update system time from FS specific data*/ 152 inittodr( mp->mnt_time); 153 154 goto success; 155 156 157 error_2: /* mount error*/ 158 159 /* unlock before failing*/ 160 vfs_unlock( mp); 161 162 error_1: /* lock error*/ 163 164 /* free mount struct before failing*/ 165 free( mp, M_MOUNT); 166 167 success: 168 return( err); 169 } 170 171 172 /* 173 * EOF -- This file has not been truncated. 174 */ 175