vfs_mount.c revision 47423
1/* 2 * Copyright (c) 1989, 1993, 1995 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.26 1998/09/14 19:56:40 sos 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 "opt_bootp.h" 55#include "opt_mfs.h" 56 57#include <sys/param.h> /* dev_t (types.h)*/ 58#include <sys/kernel.h> 59#include <sys/systm.h> /* rootvp*/ 60#include <sys/proc.h> /* curproc*/ 61#include <sys/vnode.h> /* NULLVP*/ 62#include <sys/mount.h> /* struct mount*/ 63#include <sys/malloc.h> /* M_MOUNT*/ 64 65/* 66 * GLOBALS 67 */ 68 69MALLOC_DEFINE(M_MOUNT, "mount", "vfs mount struct"); 70 71/* 72 * These define the root filesystem, device, and root filesystem type. 73 */ 74dev_t rootdevs[] = { NODEV, NODEV }; 75char *rootdevnames[2]; 76struct vnode *rootvnode; 77char *mountrootfsname; 78#ifdef BOOTP 79extern void bootpc_init __P((void)); 80#endif 81 82/* 83 * vfs_init() will set maxvfsconf 84 * to the highest defined type number. 85 */ 86int maxvfsconf; 87struct vfsconf *vfsconf; 88 89/* 90 * Common root mount code shared by all filesystems 91 */ 92#define ROOTNAME "root_device" 93 94/* 95 * vfs_mountrootfs 96 * 97 * Common entry point for root mounts 98 * 99 * PARAMETERS: 100 * NONE 101 * 102 * RETURNS: 0 Success 103 * !0 error number (errno.h) 104 * 105 * LOCK STATE: 106 * ENTRY 107 * <no locks held> 108 * EXIT 109 * <no locks held> 110 * 111 * NOTES: 112 * This code is currently supported only for use for 113 * the FFS file system type. This is a matter of 114 * fixing the other file systems, not this code! 115 */ 116static void 117vfs_mountrootfs(void *unused) 118{ 119 struct mount *mp; 120 int err; 121 struct proc *p = curproc; /* XXX */ 122#ifndef MFS_ROOT 123 int i; 124 dev_t orootdev; 125#endif 126 127#ifdef BOOTP 128 bootpc_init(); 129#endif 130 /* 131 * New root mount structure 132 */ 133 if ((err = vfs_rootmountalloc(mountrootfsname, ROOTNAME, &mp))) { 134 printf("error %d: ", err); 135 panic("cannot mount root\n"); 136 return ; 137 } 138 mp->mnt_flag |= MNT_ROOTFS; 139 140 /* 141 * Attempt the mount 142 */ 143#ifdef MFS_ROOT 144 err = VFS_MOUNT(mp, NULL, NULL, NULL, p); 145#else 146 err = ENXIO; 147 orootdev = rootdev; 148 if (rootdevs[0] == NODEV) 149 rootdevs[0] = rootdev; 150 for (i = 0; i < sizeof(rootdevs) / sizeof(rootdevs[0]); i++) { 151 if (rootdevs[i] == NODEV) 152 break; 153 rootdev = rootdevs[i]; 154 if (rootdev != orootdev) { 155 printf("changing root device to %s\n", rootdevnames[i]); 156 orootdev = rootdev; 157 } 158 strncpy(mp->mnt_stat.f_mntfromname, 159 rootdevnames[i] ? rootdevnames[i] : ROOTNAME, MNAMELEN - 1); 160 err = VFS_MOUNT(mp, NULL, NULL, NULL, p); 161 if (err != ENXIO) 162 break; 163 } 164#endif 165 if (err) { 166 /* 167 * XXX should ask the user for the name in some cases. 168 * Why do we call vfs_unbusy() here and not after ENXIO 169 * is returned above? 170 */ 171 vfs_unbusy(mp, p); 172 /* 173 * free mount struct before failing 174 * (hardly worthwhile with the PANIC eh?) 175 */ 176 free( mp, M_MOUNT); 177 printf("error %d: ", err); 178 panic("cannot mount root (2)\n"); 179 return; 180 } 181 182 simple_lock(&mountlist_slock); 183 184 /* 185 * Add fs to list of mounted file systems 186 */ 187 CIRCLEQ_INSERT_HEAD(&mountlist, mp, mnt_list); 188 189 simple_unlock(&mountlist_slock); 190 vfs_unbusy(mp, p); 191 192 /* root mount, update system time from FS specific data*/ 193 inittodr(mp->mnt_time); 194 return; 195} 196 197SYSINIT(mountroot, SI_SUB_MOUNT_ROOT, SI_ORDER_FIRST, vfs_mountrootfs, NULL) 198 199