1999-11-01 23:51:00 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1999 Michael Smith
|
|
|
|
* All rights reserved.
|
|
|
|
* Copyright (c) 1999 Poul-Henning Kamp
|
|
|
|
* All rights reserved.
|
1994-05-24 10:09:53 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
1999-11-01 23:51:00 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
1994-05-24 10:09:53 +00:00
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
1999-11-01 23:51:00 +00:00
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
1994-05-24 10:09:53 +00:00
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1999-11-01 23:51:00 +00:00
|
|
|
* $FreeBSD$
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
|
|
|
|
1995-08-28 09:19:25 +00:00
|
|
|
/*
|
1999-11-01 23:51:00 +00:00
|
|
|
* Locate and mount the root filesystem.
|
|
|
|
*
|
|
|
|
* The root filesystem is detailed in the kernel environment variable
|
|
|
|
* vfs.root.mountfrom, which is expected to be in the general format
|
1995-08-28 09:19:25 +00:00
|
|
|
*
|
1999-11-01 23:51:00 +00:00
|
|
|
* <vfsname>:[<path>]
|
|
|
|
* vfsname := the name of a VFS known to the kernel and capable
|
|
|
|
* of being mounted as root
|
|
|
|
* path := disk device name or other data used by the filesystem
|
|
|
|
* to locate its physical store
|
1995-08-28 09:19:25 +00:00
|
|
|
*
|
|
|
|
*/
|
1998-01-09 03:21:07 +00:00
|
|
|
|
2000-05-22 17:25:47 +00:00
|
|
|
#include "opt_rootdevname.h"
|
|
|
|
|
1999-11-01 23:51:00 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mutex.h>
|
1999-11-01 23:51:00 +00:00
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/reboot.h>
|
|
|
|
#include <sys/diskslice.h>
|
|
|
|
#include <sys/disklabel.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/cons.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/proc.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2000-03-20 16:28:35 +00:00
|
|
|
#include "opt_ddb.h"
|
2001-05-01 08:13:21 +00:00
|
|
|
|
2000-03-20 16:28:35 +00:00
|
|
|
#ifdef DDB
|
|
|
|
#include <ddb/ddb.h>
|
|
|
|
#endif
|
|
|
|
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <paths.h>
|
|
|
|
|
1999-11-01 23:51:00 +00:00
|
|
|
MALLOC_DEFINE(M_MOUNT, "mount", "vfs mount structure");
|
1997-02-10 02:22:35 +00:00
|
|
|
|
1999-11-01 23:51:00 +00:00
|
|
|
#define ROOTNAME "root_device"
|
1997-10-12 20:26:33 +00:00
|
|
|
|
1999-11-01 23:51:00 +00:00
|
|
|
struct vnode *rootvnode;
|
1995-08-28 09:19:25 +00:00
|
|
|
|
1999-11-04 01:40:18 +00:00
|
|
|
/*
|
|
|
|
* The root specifiers we will try if RB_CDROM is specified.
|
|
|
|
*/
|
|
|
|
static char *cdrom_rootdevnames[] = {
|
|
|
|
"cd9660:cd0a",
|
|
|
|
"cd9660:acd0a",
|
|
|
|
"cd9660:wcd0a",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
1999-11-01 23:51:00 +00:00
|
|
|
static void vfs_mountroot(void *junk);
|
|
|
|
static int vfs_mountroot_try(char *mountfrom);
|
|
|
|
static int vfs_mountroot_ask(void);
|
|
|
|
static void gets(char *cp);
|
1995-08-28 09:19:25 +00:00
|
|
|
|
1999-11-01 23:51:00 +00:00
|
|
|
/* legacy find-root code */
|
|
|
|
char *rootdevnames[2] = {NULL, NULL};
|
|
|
|
static int setrootbyname(char *name);
|
1995-08-28 09:19:25 +00:00
|
|
|
|
1999-11-03 11:02:47 +00:00
|
|
|
SYSINIT(mountroot, SI_SUB_MOUNT_ROOT, SI_ORDER_SECOND, vfs_mountroot, NULL);
|
1999-11-01 23:51:00 +00:00
|
|
|
|
1995-08-28 09:19:25 +00:00
|
|
|
/*
|
1999-11-01 23:51:00 +00:00
|
|
|
* Find and mount the root filesystem
|
1995-08-28 09:19:25 +00:00
|
|
|
*/
|
1997-12-01 11:34:41 +00:00
|
|
|
static void
|
1999-11-01 23:51:00 +00:00
|
|
|
vfs_mountroot(void *junk)
|
1995-08-28 09:19:25 +00:00
|
|
|
{
|
1999-11-04 01:40:18 +00:00
|
|
|
int i;
|
|
|
|
|
1999-11-01 23:51:00 +00:00
|
|
|
/*
|
|
|
|
* The root filesystem information is compiled in, and we are
|
|
|
|
* booted with instructions to use it.
|
|
|
|
*/
|
|
|
|
#ifdef ROOTDEVNAME
|
|
|
|
if ((boothowto & RB_DFLTROOT) &&
|
|
|
|
!vfs_mountroot_try(ROOTDEVNAME))
|
|
|
|
return;
|
1997-12-01 11:34:41 +00:00
|
|
|
#endif
|
1999-11-01 23:51:00 +00:00
|
|
|
/*
|
|
|
|
* We are booted with instructions to prompt for the root filesystem,
|
|
|
|
* or to use the compiled-in default when it doesn't exist.
|
1995-08-28 09:19:25 +00:00
|
|
|
*/
|
1999-11-01 23:51:00 +00:00
|
|
|
if (boothowto & (RB_DFLTROOT | RB_ASKNAME)) {
|
|
|
|
if (!vfs_mountroot_ask())
|
|
|
|
return;
|
1997-12-01 11:34:41 +00:00
|
|
|
}
|
1995-08-28 09:19:25 +00:00
|
|
|
|
1999-11-04 01:40:18 +00:00
|
|
|
/*
|
|
|
|
* We've been given the generic "use CDROM as root" flag. This is
|
|
|
|
* necessary because one media may be used in many different
|
|
|
|
* devices, so we need to search for them.
|
|
|
|
*/
|
|
|
|
if (boothowto & RB_CDROM) {
|
|
|
|
for (i = 0; cdrom_rootdevnames[i] != NULL; i++) {
|
|
|
|
if (!vfs_mountroot_try(cdrom_rootdevnames[i]))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-08-28 09:19:25 +00:00
|
|
|
/*
|
1999-11-01 23:51:00 +00:00
|
|
|
* Try to use the value read by the loader from /etc/fstab, or
|
|
|
|
* supplied via some other means. This is the preferred
|
|
|
|
* mechanism.
|
1999-09-19 06:24:21 +00:00
|
|
|
*/
|
1999-11-01 23:51:00 +00:00
|
|
|
if (!vfs_mountroot_try(getenv("vfs.root.mountfrom")))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try values that may have been computed by the machine-dependant
|
|
|
|
* legacy code.
|
|
|
|
*/
|
|
|
|
if (!vfs_mountroot_try(rootdevnames[0]))
|
|
|
|
return;
|
|
|
|
if (!vfs_mountroot_try(rootdevnames[1]))
|
|
|
|
return;
|
1999-09-19 06:24:21 +00:00
|
|
|
|
|
|
|
/*
|
1999-11-01 23:51:00 +00:00
|
|
|
* If we have a compiled-in default, and haven't already tried it, try
|
|
|
|
* it now.
|
1995-08-28 09:19:25 +00:00
|
|
|
*/
|
1999-11-01 23:51:00 +00:00
|
|
|
#ifdef ROOTDEVNAME
|
|
|
|
if (!(boothowto & RB_DFLTROOT))
|
1999-11-03 11:02:47 +00:00
|
|
|
if (!vfs_mountroot_try(ROOTDEVNAME))
|
|
|
|
return;
|
1999-11-01 23:51:00 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Everything so far has failed, prompt on the console if we haven't
|
|
|
|
* already tried that.
|
|
|
|
*/
|
|
|
|
if (!(boothowto & (RB_DFLTROOT | RB_ASKNAME)) && !vfs_mountroot_ask())
|
|
|
|
return;
|
|
|
|
panic("Root mount failed, startup aborted.");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mount (mountfrom) as the root filesystem.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
vfs_mountroot_try(char *mountfrom)
|
|
|
|
{
|
1999-11-03 11:02:47 +00:00
|
|
|
struct mount *mp;
|
1999-11-01 23:51:00 +00:00
|
|
|
char *vfsname, *path;
|
|
|
|
int error;
|
1999-11-05 02:45:50 +00:00
|
|
|
char patt[32];
|
1999-12-12 16:34:43 +00:00
|
|
|
int s;
|
1999-11-01 23:51:00 +00:00
|
|
|
|
1999-11-06 07:43:22 +00:00
|
|
|
vfsname = NULL;
|
|
|
|
path = NULL;
|
|
|
|
mp = NULL;
|
|
|
|
error = EINVAL;
|
1999-11-01 23:51:00 +00:00
|
|
|
|
|
|
|
if (mountfrom == NULL)
|
1999-11-21 08:05:50 +00:00
|
|
|
return(error); /* don't complain */
|
1999-11-01 23:51:00 +00:00
|
|
|
|
1999-12-12 16:34:43 +00:00
|
|
|
s = splcam(); /* Overkill, but annoying without it */
|
1999-11-01 23:51:00 +00:00
|
|
|
printf("Mounting root from %s\n", mountfrom);
|
1999-12-12 16:34:43 +00:00
|
|
|
splx(s);
|
1999-11-01 23:51:00 +00:00
|
|
|
|
|
|
|
/* parse vfs name and path */
|
|
|
|
vfsname = malloc(MFSNAMELEN, M_MOUNT, M_WAITOK);
|
|
|
|
path = malloc(MNAMELEN, M_MOUNT, M_WAITOK);
|
1999-11-03 11:02:47 +00:00
|
|
|
vfsname[0] = path[0] = 0;
|
1999-11-04 17:48:11 +00:00
|
|
|
sprintf(patt, "%%%d[a-z0-9]:%%%ds", MFSNAMELEN, MNAMELEN);
|
1999-11-03 11:02:47 +00:00
|
|
|
if (sscanf(mountfrom, patt, vfsname, path) < 1)
|
1999-11-01 23:51:00 +00:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* allocate a root mount */
|
1999-11-28 22:20:18 +00:00
|
|
|
error = vfs_rootmountalloc(vfsname, path[0] != 0 ? path : ROOTNAME,
|
|
|
|
&mp);
|
|
|
|
if (error != 0) {
|
1999-11-01 23:51:00 +00:00
|
|
|
printf("Can't allocate root mount for filesystem '%s': %d\n",
|
|
|
|
vfsname, error);
|
|
|
|
goto done;
|
1997-12-01 11:34:41 +00:00
|
|
|
}
|
1999-11-01 23:51:00 +00:00
|
|
|
mp->mnt_flag |= MNT_ROOTFS;
|
1995-08-28 09:19:25 +00:00
|
|
|
|
1999-11-01 23:51:00 +00:00
|
|
|
/* do our best to set rootdev */
|
1999-11-03 11:02:47 +00:00
|
|
|
if ((path[0] != 0) && setrootbyname(path))
|
1999-11-01 23:51:00 +00:00
|
|
|
printf("setrootbyname failed\n");
|
1997-12-01 11:34:41 +00:00
|
|
|
|
1999-11-26 20:08:44 +00:00
|
|
|
/* If the root device is a type "memory disk", mount RW */
|
1999-12-08 10:01:18 +00:00
|
|
|
if (rootdev != NODEV && devsw(rootdev) &&
|
|
|
|
(devsw(rootdev)->d_flags & D_MEMDISK))
|
1999-11-26 20:08:44 +00:00
|
|
|
mp->mnt_flag &= ~MNT_RDONLY;
|
|
|
|
|
2001-03-01 21:00:17 +00:00
|
|
|
/*
|
|
|
|
* Set the mount path to be something useful, because the
|
|
|
|
* filesystem code isn't responsible now for initialising
|
|
|
|
* f_mntonname unless they want to override the default
|
|
|
|
* (which is `path'.)
|
|
|
|
*/
|
|
|
|
strncpy(mp->mnt_stat.f_mntonname, "/", MNAMELEN);
|
|
|
|
|
1999-11-01 23:51:00 +00:00
|
|
|
error = VFS_MOUNT(mp, NULL, NULL, NULL, curproc);
|
|
|
|
|
|
|
|
done:
|
1999-11-05 19:28:07 +00:00
|
|
|
if (vfsname != NULL)
|
|
|
|
free(vfsname, M_MOUNT);
|
|
|
|
if (path != NULL)
|
|
|
|
free(path, M_MOUNT);
|
1999-11-01 23:51:00 +00:00
|
|
|
if (error != 0) {
|
1999-11-28 22:20:18 +00:00
|
|
|
if (mp != NULL) {
|
|
|
|
vfs_unbusy(mp, curproc);
|
1999-11-01 23:51:00 +00:00
|
|
|
free(mp, M_MOUNT);
|
1999-11-28 22:20:18 +00:00
|
|
|
}
|
1999-11-01 23:51:00 +00:00
|
|
|
printf("Root mount failed: %d\n", error);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* register with list of mounted filesystems */
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_lock(&mountlist_mtx);
|
1999-11-20 10:00:46 +00:00
|
|
|
TAILQ_INSERT_HEAD(&mountlist, mp, mnt_list);
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_unlock(&mountlist_mtx);
|
1999-11-01 23:51:00 +00:00
|
|
|
|
|
|
|
/* sanity check system clock against root filesystem timestamp */
|
|
|
|
inittodr(mp->mnt_time);
|
1999-11-03 11:02:47 +00:00
|
|
|
vfs_unbusy(mp, curproc);
|
1999-11-28 22:20:18 +00:00
|
|
|
}
|
1999-11-01 23:51:00 +00:00
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Spin prompting on the console for a suitable root filesystem
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
vfs_mountroot_ask(void)
|
|
|
|
{
|
|
|
|
char name[128];
|
|
|
|
int i;
|
|
|
|
dev_t dev;
|
|
|
|
|
|
|
|
for(;;) {
|
|
|
|
printf("\nManual root filesystem specification:\n");
|
|
|
|
printf(" <fstype>:<device> Mount <device> using filesystem <fstype>\n");
|
2000-12-09 09:35:55 +00:00
|
|
|
printf(" eg. ufs:%sda0s1a\n", _PATH_DEV);
|
1999-11-01 23:51:00 +00:00
|
|
|
printf(" ? List valid disk boot devices\n");
|
|
|
|
printf(" <empty line> Abort manual input\n");
|
2000-02-17 23:32:08 +00:00
|
|
|
printf("\nmountroot> ");
|
1999-11-01 23:51:00 +00:00
|
|
|
gets(name);
|
|
|
|
if (name[0] == 0)
|
|
|
|
return(1);
|
|
|
|
if (name[0] == '?') {
|
|
|
|
printf("Possibly valid devices for 'ufs' root:\n");
|
|
|
|
for (i = 0; i < NUMCDEVSW; i++) {
|
1999-12-08 10:01:18 +00:00
|
|
|
dev = makedev(i, 0);
|
1999-11-01 23:51:00 +00:00
|
|
|
if (devsw(dev) != NULL)
|
|
|
|
printf(" \"%s\"", devsw(dev)->d_name);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!vfs_mountroot_try(name))
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
}
|
1995-08-28 09:19:25 +00:00
|
|
|
|
1999-11-01 23:51:00 +00:00
|
|
|
static void
|
|
|
|
gets(char *cp)
|
|
|
|
{
|
|
|
|
char *lp;
|
|
|
|
int c;
|
1995-08-28 09:19:25 +00:00
|
|
|
|
1999-11-01 23:51:00 +00:00
|
|
|
lp = cp;
|
|
|
|
for (;;) {
|
|
|
|
printf("%c", c = cngetc() & 0177);
|
|
|
|
switch (c) {
|
|
|
|
case -1:
|
|
|
|
case '\n':
|
|
|
|
case '\r':
|
|
|
|
*lp++ = '\0';
|
|
|
|
return;
|
|
|
|
case '\b':
|
|
|
|
case '\177':
|
|
|
|
if (lp > cp) {
|
|
|
|
printf(" \b");
|
|
|
|
lp--;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
case '#':
|
|
|
|
lp--;
|
|
|
|
if (lp < cp)
|
|
|
|
lp = cp;
|
|
|
|
continue;
|
|
|
|
case '@':
|
|
|
|
case 'u' & 037:
|
|
|
|
lp = cp;
|
|
|
|
printf("%c", '\n');
|
|
|
|
continue;
|
|
|
|
default:
|
|
|
|
*lp++ = c;
|
|
|
|
}
|
|
|
|
}
|
1995-08-28 09:19:25 +00:00
|
|
|
}
|
1997-11-25 07:07:48 +00:00
|
|
|
|
1999-11-01 23:51:00 +00:00
|
|
|
/*
|
2000-03-20 16:28:35 +00:00
|
|
|
* Convert a given name to the dev_t of the disk-like device
|
|
|
|
* it refers to.
|
1999-11-01 23:51:00 +00:00
|
|
|
*/
|
2000-03-20 16:28:35 +00:00
|
|
|
dev_t
|
|
|
|
getdiskbyname(char *name) {
|
2000-08-24 15:36:55 +00:00
|
|
|
char *cp;
|
|
|
|
dev_t dev;
|
|
|
|
|
|
|
|
cp = name;
|
|
|
|
if (!bcmp(cp, "/dev/", 5))
|
|
|
|
cp += 5;
|
|
|
|
|
|
|
|
dev = NODEV;
|
2000-09-02 19:17:34 +00:00
|
|
|
EVENTHANDLER_INVOKE(dev_clone, cp, strlen(cp), &dev);
|
2000-08-24 15:36:55 +00:00
|
|
|
return (dev);
|
2000-03-20 16:28:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set rootdev to match (name), given that we expect it to
|
|
|
|
* refer to a disk-like device.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
setrootbyname(char *name)
|
|
|
|
{
|
|
|
|
dev_t diskdev;
|
|
|
|
|
|
|
|
diskdev = getdiskbyname(name);
|
|
|
|
if (diskdev != NODEV) {
|
|
|
|
rootdev = diskdev;
|
|
|
|
return (0);
|
1999-11-01 23:51:00 +00:00
|
|
|
}
|
2000-03-20 16:28:35 +00:00
|
|
|
|
|
|
|
return (1);
|
1999-11-01 23:51:00 +00:00
|
|
|
}
|
1997-11-25 07:07:48 +00:00
|
|
|
|
2000-03-20 16:28:35 +00:00
|
|
|
#ifdef DDB
|
|
|
|
DB_SHOW_COMMAND(disk, db_getdiskbyname)
|
|
|
|
{
|
|
|
|
dev_t dev;
|
|
|
|
|
|
|
|
if (modif[0] == '\0') {
|
|
|
|
db_error("usage: show disk/devicename");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
dev = getdiskbyname(modif);
|
|
|
|
if (dev != NODEV)
|
|
|
|
db_printf("dev_t = %p\n", dev);
|
|
|
|
else
|
|
|
|
db_printf("No disk device matched.\n");
|
|
|
|
}
|
|
|
|
#endif
|