vfs_mount.c revision 35323
1174604Sscottl/*
2174604Sscottl * Copyright (c) 1989, 1993, 1995
3174604Sscottl *	The Regents of the University of California.  All rights reserved.
4174604Sscottl * Copyright (c) 1995 Artisoft, Inc.  All Rights Reserved.
5174604Sscottl *
6174604Sscottl * Redistribution and use in source and binary forms, with or without
7174604Sscottl * modification, are permitted provided that the following conditions
8174604Sscottl * are met:
9174604Sscottl * 1. Redistributions of source code must retain the above copyright
10174604Sscottl *    notice, this list of conditions and the following disclaimer.
11174604Sscottl * 2. Redistributions in binary form must reproduce the above copyright
12174604Sscottl *    notice, this list of conditions and the following disclaimer in the
13174604Sscottl *    documentation and/or other materials provided with the distribution.
14174604Sscottl * 3. All advertising materials mentioning features or use of this software
15174604Sscottl *    must display the following acknowledgement:
16174604Sscottl *	This product includes software developed by the University of
17174604Sscottl *	California, Berkeley and its contributors.
18174604Sscottl * 4. Neither the name of the University nor the names of its contributors
19174604Sscottl *    may be used to endorse or promote products derived from this software
20174604Sscottl *    without specific prior written permission.
21174604Sscottl *
22174604Sscottl * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23174604Sscottl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24174604Sscottl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25174604Sscottl * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26227912Smarius * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27227912Smarius * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28227912Smarius * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29227912Smarius * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30174604Sscottl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31176018Sscottl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32174604Sscottl * SUCH DAMAGE.
33174604Sscottl *
34174604Sscottl *	@(#)vfs_conf.c	8.8 (Berkeley) 3/31/94
35174604Sscottl * $Id: vfs_conf.c,v 1.23 1998/04/19 23:31:57 julian Exp $
36174604Sscottl */
37174604Sscottl
38174604Sscottl/*
39237178Seadler * PURPOSE:	This file abstracts the root mounting interface from
40199043Smav *		the per file system semantics for handling mounts,
41199043Smav *		the overall intent of which is to move the BSD
42174604Sscottl *		internals dependence out of the FS code, both to
43174604Sscottl *		make the FS code more portable and to free up some
44174604Sscottl *		of the BSD internals so that they may more easily
45174604Sscottl *		be changed.
46174604Sscottl *
47174604Sscottl * NOTE1:	Code is single entry/single exit to aid debugging
48174604Sscottl *		and conversion for kernel multithreading.
49199043Smav *
50199043Smav * NOTE2:	Code notes lock state in headers on entry and exit
51199043Smav *		as an aid to conversion for kernel multithreading
52174604Sscottl *		on SMP reentrancy
53174604Sscottl */
54174604Sscottl#include "opt_devfs.h" /* for SLICE */
55174604Sscottl#include "opt_bootp.h"
56174604Sscottl
57174604Sscottl#include <sys/param.h>		/* dev_t (types.h)*/
58174604Sscottl#include <sys/kernel.h>
59174604Sscottl#include <sys/systm.h>		/* rootvp*/
60174604Sscottl#include <sys/proc.h>		/* curproc*/
61174604Sscottl#include <sys/vnode.h>		/* NULLVP*/
62174604Sscottl#include <sys/mount.h>		/* struct mount*/
63174604Sscottl#include <sys/malloc.h>		/* M_MOUNT*/
64174604Sscottl
65174604Sscottl/*
66174604Sscottl * GLOBALS
67174604Sscottl */
68174604Sscottl
69174604SscottlMALLOC_DEFINE(M_MOUNT, "mount", "vfs mount struct");
70174604Sscottl
71174604Sscottl/*
72174604Sscottl *  These define the root filesystem, device, and root filesystem type.
73174604Sscottl */
74174604Sscottlstatic struct mount *rootfs;
75174604Sscottlstruct vnode *rootvnode;
76174604Sscottlchar *mountrootfsname;
77174604Sscottl#ifdef SLICE
78174604Sscottlchar	rootdevice[32];
79174604Sscottl#endif /* SLICE */
80174604Sscottl#ifdef BOOTP
81174604Sscottlextern void bootpc_init __P((void));
82174604Sscottl#endif /* BOOTP */
83174604Sscottl
84174604Sscottl/*
85174604Sscottl * vfs_init() will set maxvfsconf
86174604Sscottl * to the highest defined type number.
87174604Sscottl */
88174604Sscottlint maxvfsconf;
89174604Sscottlstruct vfsconf *vfsconf;
90174604Sscottl
91174604Sscottl/*
92174604Sscottl * Common root mount code shared by all filesystems
93174604Sscottl */
94174604Sscottl#define ROOTNAME	"root_device"
95174604Sscottl
96174604Sscottl/*
97174604Sscottl * vfs_mountrootfs
98174604Sscottl *
99174604Sscottl * Common entry point for root mounts
100174604Sscottl *
101174604Sscottl * PARAMETERS:
102174604Sscottl * 		NONE
103174604Sscottl *
104174604Sscottl * RETURNS:	0	Success
105174604Sscottl *		!0	error number (errno.h)
106174604Sscottl *
107174604Sscottl * LOCK STATE:
108174604Sscottl *		ENTRY
109174604Sscottl *			<no locks held>
110174604Sscottl *		EXIT
111174604Sscottl *			<no locks held>
112174604Sscottl *
113174604Sscottl * NOTES:
114174604Sscottl *		This code is currently supported only for use for
115174604Sscottl *		the FFS file system type.  This is a matter of
116174604Sscottl *		fixing the other file systems, not this code!
117174604Sscottl */
118174604Sscottlstatic void
119174604Sscottlvfs_mountrootfs(void *unused)
120174604Sscottl{
121174604Sscottl	struct mount		*mp;
122174604Sscottl	int			err = 0;
123174604Sscottl	struct proc		*p = curproc;	/* XXX */
124174604Sscottl
125174604Sscottl#ifdef BOOTP
126174604Sscottl	bootpc_init();
127174604Sscottl#endif
128174604Sscottl	/*
129174604Sscottl	 *  New root mount structure
130174604Sscottl	 */
131174604Sscottl	if ((err = vfs_rootmountalloc(mountrootfsname, ROOTNAME, &mp))) {
132174604Sscottl		printf("error %d: ", err);
133174604Sscottl		panic("cannot mount root\n");
134174604Sscottl		return ;
135174604Sscottl	}
136174604Sscottl	mp->mnt_flag		|= MNT_ROOTFS;
137174604Sscottl
138174604Sscottl	/*
139174604Sscottl	 * Attempt the mount
140174604Sscottl	 */
141174604Sscottl	err = VFS_MOUNT(mp, NULL, NULL, NULL, p);
142174604Sscottl	/*
143174604Sscottl	 * rootdev may be bogus (slice field may be incorrect for disks)
144174604Sscottl	 * If slice field is nonzero, clear and retry.
145174604Sscottl	 *
146174604Sscottl	 * XXX Implicit knowledge of device minor number layout.
147174604Sscottl	 *     This is placeholder code until saner root mounts arrive with
148174604Sscottl	 *     DEVFS.
149174604Sscottl	 */
150174604Sscottl	if ((err == ENXIO) && (rootdev & 0xff0000)) {
151174604Sscottl		rootdev &= ~0xff0000;
152174604Sscottl		err = VFS_MOUNT(mp, NULL, NULL, NULL, p);
153174604Sscottl	}
154174604Sscottl	if (err) {
155174604Sscottl		vfs_unbusy(mp, p);
156174604Sscottl		/*
157174604Sscottl		 * free mount struct before failing
158174604Sscottl		 * (hardly worthwhile with the PANIC eh?)
159174604Sscottl		 */
160174604Sscottl		free( mp, M_MOUNT);
161174604Sscottl		printf("error %d: ", err);
162174604Sscottl		panic("cannot mount root (2)\n");
163174604Sscottl		return;
164174604Sscottl	}
165174604Sscottl
166174604Sscottl	simple_lock(&mountlist_slock);
167174604Sscottl
168174604Sscottl	/*
169174604Sscottl	 * Add fs to list of mounted file systems
170174604Sscottl	 */
171174604Sscottl	CIRCLEQ_INSERT_HEAD(&mountlist, mp, mnt_list);
172174604Sscottl
173174604Sscottl	simple_unlock(&mountlist_slock);
174174604Sscottl	vfs_unbusy(mp, p);
175174604Sscottl
176174604Sscottl	/* root mount, update system time from FS specific data*/
177174604Sscottl	inittodr(mp->mnt_time);
178250032Ssbruno	return;
179250032Ssbruno}
180174604Sscottl
181174604SscottlSYSINIT(mountroot, SI_SUB_MOUNT_ROOT, SI_ORDER_FIRST, vfs_mountrootfs, NULL)
182174604Sscottl
183174604Sscottl