2003-05-15 16:56:16 +04:00
|
|
|
/* $NetBSD: kern_subr.c,v 1.98 2003/05/15 12:56:16 dsl Exp $ */
|
1997-10-05 22:37:01 +04:00
|
|
|
|
|
|
|
/*-
|
2002-02-08 03:58:58 +03:00
|
|
|
* Copyright (c) 1997, 1998, 1999, 2002 The NetBSD Foundation, Inc.
|
1997-10-05 22:37:01 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
|
1999-05-09 17:48:44 +04:00
|
|
|
* NASA Ames Research Center, and by Luke Mewburn.
|
1997-10-05 22:37:01 +04: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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE 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.
|
|
|
|
*/
|
1994-06-29 10:29:24 +04:00
|
|
|
|
1994-05-17 08:21:49 +04:00
|
|
|
/*
|
1994-05-18 14:21:18 +04:00
|
|
|
* Copyright (c) 1982, 1986, 1991, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1994-05-17 08:21:49 +04:00
|
|
|
* (c) UNIX System Laboratories, Inc.
|
|
|
|
* All or some portions of this file are derived from material licensed
|
|
|
|
* to the University of California by American Telephone and Telegraph
|
|
|
|
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
|
|
|
|
* the permission of UNIX System Laboratories, Inc.
|
|
|
|
*
|
1997-01-31 05:31:33 +03:00
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed by the Computer Systems Engineering group
|
|
|
|
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
|
|
|
|
* contributed to Berkeley.
|
|
|
|
*
|
|
|
|
* All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Lawrence Berkeley Laboratory.
|
|
|
|
*
|
1994-05-17 08:21:49 +04: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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* 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.
|
|
|
|
*
|
1998-03-01 05:20:01 +03:00
|
|
|
* @(#)kern_subr.c 8.4 (Berkeley) 2/14/95
|
1994-05-17 08:21:49 +04:00
|
|
|
*/
|
|
|
|
|
2001-11-12 18:25:01 +03:00
|
|
|
#include <sys/cdefs.h>
|
2003-05-15 16:56:16 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: kern_subr.c,v 1.98 2003/05/15 12:56:16 dsl Exp $");
|
2001-11-12 18:25:01 +03:00
|
|
|
|
2002-02-08 03:58:58 +03:00
|
|
|
#include "opt_ddb.h"
|
1999-02-07 12:34:58 +03:00
|
|
|
#include "opt_md.h"
|
2002-06-17 20:22:50 +04:00
|
|
|
#include "opt_syscall_debug.h"
|
|
|
|
#include "opt_ktrace.h"
|
|
|
|
#include "opt_systrace.h"
|
1998-02-10 17:08:44 +03:00
|
|
|
|
1994-05-17 08:21:49 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/proc.h>
|
1994-05-18 14:21:18 +04:00
|
|
|
#include <sys/malloc.h>
|
1997-01-31 05:31:33 +03:00
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/reboot.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/disklabel.h>
|
1994-05-18 14:21:18 +04:00
|
|
|
#include <sys/queue.h>
|
2002-06-17 20:22:50 +04:00
|
|
|
#include <sys/systrace.h>
|
|
|
|
#include <sys/ktrace.h>
|
1994-05-17 08:21:49 +04:00
|
|
|
|
2002-07-20 07:58:24 +04:00
|
|
|
#include <uvm/uvm_extern.h>
|
|
|
|
|
1997-01-31 05:31:33 +03:00
|
|
|
#include <dev/cons.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
|
|
|
|
/* XXX these should eventually move to subr_autoconf.c */
|
2000-02-01 08:28:01 +03:00
|
|
|
static struct device *finddevice __P((const char *));
|
1999-06-08 00:16:08 +04:00
|
|
|
static struct device *getdisk __P((char *, int, int, dev_t *, int));
|
|
|
|
static struct device *parsedisk __P((char *, int, int, dev_t *));
|
1997-01-31 05:31:33 +03:00
|
|
|
|
2002-03-18 01:19:20 +03:00
|
|
|
/*
|
|
|
|
* A generic linear hook.
|
|
|
|
*/
|
|
|
|
struct hook_desc {
|
|
|
|
LIST_ENTRY(hook_desc) hk_list;
|
|
|
|
void (*hk_fn) __P((void *));
|
|
|
|
void *hk_arg;
|
|
|
|
};
|
|
|
|
typedef LIST_HEAD(, hook_desc) hook_list_t;
|
|
|
|
|
|
|
|
static void *hook_establish __P((hook_list_t *, void (*)(void *), void *));
|
|
|
|
static void hook_disestablish __P((hook_list_t *, void *));
|
|
|
|
static void hook_destroy __P((hook_list_t *));
|
|
|
|
static void hook_proc_run __P((hook_list_t *, struct proc *));
|
|
|
|
|
2003-02-01 09:23:35 +03:00
|
|
|
MALLOC_DEFINE(M_IOV, "iov", "large iov's");
|
|
|
|
|
1994-05-18 16:46:29 +04:00
|
|
|
int
|
1996-10-13 06:27:52 +04:00
|
|
|
uiomove(buf, n, uio)
|
2000-03-30 13:27:11 +04:00
|
|
|
void *buf;
|
2002-08-26 02:28:40 +04:00
|
|
|
size_t n;
|
2000-03-30 13:27:11 +04:00
|
|
|
struct uio *uio;
|
1994-05-17 08:21:49 +04:00
|
|
|
{
|
2000-03-30 13:27:11 +04:00
|
|
|
struct iovec *iov;
|
1994-05-17 08:21:49 +04:00
|
|
|
u_int cnt;
|
|
|
|
int error = 0;
|
1996-10-13 06:27:52 +04:00
|
|
|
char *cp = buf;
|
2000-05-27 05:43:27 +04:00
|
|
|
struct proc *p = uio->uio_procp;
|
|
|
|
|
2000-05-31 10:18:03 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
1994-05-17 08:21:49 +04:00
|
|
|
if (uio->uio_rw != UIO_READ && uio->uio_rw != UIO_WRITE)
|
|
|
|
panic("uiomove: mode");
|
|
|
|
#endif
|
|
|
|
while (n > 0 && uio->uio_resid) {
|
|
|
|
iov = uio->uio_iov;
|
|
|
|
cnt = iov->iov_len;
|
|
|
|
if (cnt == 0) {
|
|
|
|
uio->uio_iov++;
|
|
|
|
uio->uio_iovcnt--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (cnt > n)
|
|
|
|
cnt = n;
|
|
|
|
switch (uio->uio_segflg) {
|
|
|
|
|
|
|
|
case UIO_USERSPACE:
|
2003-01-18 13:06:22 +03:00
|
|
|
if (curlwp->l_cpu->ci_schedstate.spc_flags &
|
2000-05-27 01:19:19 +04:00
|
|
|
SPCF_SHOULDYIELD)
|
2003-01-18 13:06:22 +03:00
|
|
|
preempt(1);
|
2002-07-20 07:58:24 +04:00
|
|
|
if (__predict_true(p == curproc)) {
|
|
|
|
if (uio->uio_rw == UIO_READ)
|
|
|
|
error = copyout(cp, iov->iov_base, cnt);
|
|
|
|
else
|
|
|
|
error = copyin(iov->iov_base, cp, cnt);
|
|
|
|
} else {
|
|
|
|
if (uio->uio_rw == UIO_READ)
|
|
|
|
error = copyout_proc(p, cp,
|
|
|
|
iov->iov_base, cnt);
|
|
|
|
else
|
|
|
|
error = copyin_proc(p, iov->iov_base,
|
|
|
|
cp, cnt);
|
|
|
|
}
|
1994-05-17 08:21:49 +04:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UIO_SYSSPACE:
|
1998-02-05 10:59:28 +03:00
|
|
|
if (uio->uio_rw == UIO_READ)
|
|
|
|
error = kcopy(cp, iov->iov_base, cnt);
|
|
|
|
else
|
|
|
|
error = kcopy(iov->iov_base, cp, cnt);
|
|
|
|
if (error)
|
2000-03-01 06:50:04 +03:00
|
|
|
return (error);
|
1994-05-17 08:21:49 +04:00
|
|
|
break;
|
|
|
|
}
|
1999-02-10 20:03:26 +03:00
|
|
|
iov->iov_base = (caddr_t)iov->iov_base + cnt;
|
1994-05-17 08:21:49 +04:00
|
|
|
iov->iov_len -= cnt;
|
|
|
|
uio->uio_resid -= cnt;
|
|
|
|
uio->uio_offset += cnt;
|
|
|
|
cp += cnt;
|
2002-08-26 02:28:40 +04:00
|
|
|
KDASSERT(cnt <= n);
|
1994-05-17 08:21:49 +04:00
|
|
|
n -= cnt;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Give next character to user as result of read.
|
|
|
|
*/
|
1994-05-18 16:46:29 +04:00
|
|
|
int
|
1994-05-17 08:21:49 +04:00
|
|
|
ureadc(c, uio)
|
2000-03-30 13:27:11 +04:00
|
|
|
int c;
|
|
|
|
struct uio *uio;
|
1994-05-17 08:21:49 +04:00
|
|
|
{
|
2000-03-30 13:27:11 +04:00
|
|
|
struct iovec *iov;
|
1994-05-17 08:21:49 +04:00
|
|
|
|
1994-05-18 16:46:29 +04:00
|
|
|
if (uio->uio_resid <= 0)
|
|
|
|
panic("ureadc: non-positive resid");
|
1994-05-17 08:21:49 +04:00
|
|
|
again:
|
1994-05-18 16:46:29 +04:00
|
|
|
if (uio->uio_iovcnt <= 0)
|
|
|
|
panic("ureadc: non-positive iovcnt");
|
1994-05-17 08:21:49 +04:00
|
|
|
iov = uio->uio_iov;
|
1994-05-18 16:46:29 +04:00
|
|
|
if (iov->iov_len <= 0) {
|
1994-05-17 08:21:49 +04:00
|
|
|
uio->uio_iovcnt--;
|
|
|
|
uio->uio_iov++;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
switch (uio->uio_segflg) {
|
|
|
|
|
|
|
|
case UIO_USERSPACE:
|
|
|
|
if (subyte(iov->iov_base, c) < 0)
|
|
|
|
return (EFAULT);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UIO_SYSSPACE:
|
1998-05-08 22:18:55 +04:00
|
|
|
*(char *)iov->iov_base = c;
|
1994-05-17 08:21:49 +04:00
|
|
|
break;
|
|
|
|
}
|
1999-02-10 20:03:26 +03:00
|
|
|
iov->iov_base = (caddr_t)iov->iov_base + 1;
|
1994-05-17 08:21:49 +04:00
|
|
|
iov->iov_len--;
|
|
|
|
uio->uio_resid--;
|
|
|
|
uio->uio_offset++;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2002-07-20 07:58:24 +04:00
|
|
|
/*
|
|
|
|
* Like copyin(), but operates on an arbitrary process.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
copyin_proc(struct proc *p, const void *uaddr, void *kaddr, size_t len)
|
|
|
|
{
|
|
|
|
struct iovec iov;
|
|
|
|
struct uio uio;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (len == 0)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
iov.iov_base = kaddr;
|
|
|
|
iov.iov_len = len;
|
|
|
|
uio.uio_iov = &iov;
|
|
|
|
uio.uio_iovcnt = 1;
|
|
|
|
uio.uio_offset = (off_t)(intptr_t)uaddr;
|
|
|
|
uio.uio_resid = len;
|
|
|
|
uio.uio_segflg = UIO_SYSSPACE;
|
|
|
|
uio.uio_rw = UIO_READ;
|
|
|
|
uio.uio_procp = NULL;
|
|
|
|
|
|
|
|
/* XXXCDC: how should locking work here? */
|
|
|
|
if ((p->p_flag & P_WEXIT) || (p->p_vmspace->vm_refcnt < 1))
|
|
|
|
return (EFAULT);
|
|
|
|
p->p_vmspace->vm_refcnt++; /* XXX */
|
|
|
|
error = uvm_io(&p->p_vmspace->vm_map, &uio);
|
|
|
|
uvmspace_free(p->p_vmspace);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Like copyout(), but operates on an arbitrary process.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
copyout_proc(struct proc *p, const void *kaddr, void *uaddr, size_t len)
|
|
|
|
{
|
|
|
|
struct iovec iov;
|
|
|
|
struct uio uio;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (len == 0)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
iov.iov_base = (void *) kaddr; /* XXX cast away const */
|
|
|
|
iov.iov_len = len;
|
|
|
|
uio.uio_iov = &iov;
|
|
|
|
uio.uio_iovcnt = 1;
|
|
|
|
uio.uio_offset = (off_t)(intptr_t)uaddr;
|
|
|
|
uio.uio_resid = len;
|
|
|
|
uio.uio_segflg = UIO_SYSSPACE;
|
|
|
|
uio.uio_rw = UIO_WRITE;
|
|
|
|
uio.uio_procp = NULL;
|
|
|
|
|
|
|
|
/* XXXCDC: how should locking work here? */
|
|
|
|
if ((p->p_flag & P_WEXIT) || (p->p_vmspace->vm_refcnt < 1))
|
|
|
|
return (EFAULT);
|
|
|
|
p->p_vmspace->vm_refcnt++; /* XXX */
|
|
|
|
error = uvm_io(&p->p_vmspace->vm_map, &uio);
|
|
|
|
uvmspace_free(p->p_vmspace);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1994-05-18 14:21:18 +04:00
|
|
|
/*
|
|
|
|
* General routine to allocate a hash table.
|
1999-01-22 10:57:13 +03:00
|
|
|
* Allocate enough memory to hold at least `elements' list-head pointers.
|
|
|
|
* Return a pointer to the allocated space and set *hashmask to a pattern
|
|
|
|
* suitable for masking a value to use as an index into the returned array.
|
1994-05-18 14:21:18 +04:00
|
|
|
*/
|
|
|
|
void *
|
2000-11-08 17:25:23 +03:00
|
|
|
hashinit(elements, htype, mtype, mflags, hashmask)
|
2002-08-26 00:01:12 +04:00
|
|
|
u_int elements;
|
2000-11-08 17:25:23 +03:00
|
|
|
enum hashtype htype;
|
2003-02-01 09:23:35 +03:00
|
|
|
struct malloc_type *mtype;
|
|
|
|
int mflags;
|
1994-05-18 14:21:18 +04:00
|
|
|
u_long *hashmask;
|
|
|
|
{
|
2002-08-26 00:01:12 +04:00
|
|
|
u_long hashsize, i;
|
2000-11-08 17:25:23 +03:00
|
|
|
LIST_HEAD(, generic) *hashtbl_list;
|
|
|
|
TAILQ_HEAD(, generic) *hashtbl_tailq;
|
2002-08-26 00:01:12 +04:00
|
|
|
size_t esize;
|
2000-11-08 17:25:23 +03:00
|
|
|
void *p;
|
1994-05-18 14:21:18 +04:00
|
|
|
|
2002-08-26 00:01:12 +04:00
|
|
|
if (elements == 0)
|
1994-05-18 14:21:18 +04:00
|
|
|
panic("hashinit: bad cnt");
|
1999-01-22 10:57:13 +03:00
|
|
|
for (hashsize = 1; hashsize < elements; hashsize <<= 1)
|
1994-05-18 14:21:18 +04:00
|
|
|
continue;
|
2000-11-08 17:25:23 +03:00
|
|
|
|
|
|
|
switch (htype) {
|
|
|
|
case HASH_LIST:
|
|
|
|
esize = sizeof(*hashtbl_list);
|
|
|
|
break;
|
|
|
|
case HASH_TAILQ:
|
|
|
|
esize = sizeof(*hashtbl_tailq);
|
|
|
|
break;
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
default:
|
|
|
|
panic("hashinit: invalid table type");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2002-08-26 00:01:12 +04:00
|
|
|
if ((p = malloc(hashsize * esize, mtype, mflags)) == NULL)
|
2000-05-10 06:16:15 +04:00
|
|
|
return (NULL);
|
2000-11-08 17:25:23 +03:00
|
|
|
|
|
|
|
switch (htype) {
|
|
|
|
case HASH_LIST:
|
|
|
|
hashtbl_list = p;
|
|
|
|
for (i = 0; i < hashsize; i++)
|
|
|
|
LIST_INIT(&hashtbl_list[i]);
|
|
|
|
break;
|
|
|
|
case HASH_TAILQ:
|
|
|
|
hashtbl_tailq = p;
|
|
|
|
for (i = 0; i < hashsize; i++)
|
|
|
|
TAILQ_INIT(&hashtbl_tailq[i]);
|
|
|
|
break;
|
|
|
|
}
|
1994-05-18 14:21:18 +04:00
|
|
|
*hashmask = hashsize - 1;
|
2000-11-08 17:25:23 +03:00
|
|
|
return (p);
|
1994-05-18 14:21:18 +04:00
|
|
|
}
|
1995-06-01 00:41:44 +04:00
|
|
|
|
2000-03-16 20:19:53 +03:00
|
|
|
/*
|
|
|
|
* Free memory from hash table previosly allocated via hashinit().
|
|
|
|
*/
|
|
|
|
void
|
2000-11-08 17:25:23 +03:00
|
|
|
hashdone(hashtbl, mtype)
|
2000-03-16 20:19:53 +03:00
|
|
|
void *hashtbl;
|
2003-02-01 09:23:35 +03:00
|
|
|
struct malloc_type *mtype;
|
2000-03-16 20:19:53 +03:00
|
|
|
{
|
2000-05-10 06:14:41 +04:00
|
|
|
|
2000-11-08 17:25:23 +03:00
|
|
|
free(hashtbl, mtype);
|
2000-03-16 20:19:53 +03:00
|
|
|
}
|
|
|
|
|
1995-06-01 00:41:44 +04:00
|
|
|
|
2002-03-18 01:19:20 +03:00
|
|
|
static void *
|
|
|
|
hook_establish(list, fn, arg)
|
|
|
|
hook_list_t *list;
|
1995-06-01 00:41:44 +04:00
|
|
|
void (*fn) __P((void *));
|
|
|
|
void *arg;
|
|
|
|
{
|
2002-03-18 01:19:20 +03:00
|
|
|
struct hook_desc *hd;
|
1995-06-01 00:41:44 +04:00
|
|
|
|
2002-03-18 01:19:20 +03:00
|
|
|
hd = malloc(sizeof(*hd), M_DEVBUF, M_NOWAIT);
|
|
|
|
if (hd == NULL)
|
2000-03-01 06:50:04 +03:00
|
|
|
return (NULL);
|
1995-06-01 00:41:44 +04:00
|
|
|
|
2002-03-18 01:19:20 +03:00
|
|
|
hd->hk_fn = fn;
|
|
|
|
hd->hk_arg = arg;
|
|
|
|
LIST_INSERT_HEAD(list, hd, hk_list);
|
1995-06-01 00:41:44 +04:00
|
|
|
|
2002-03-18 01:19:20 +03:00
|
|
|
return (hd);
|
1995-06-01 00:41:44 +04:00
|
|
|
}
|
|
|
|
|
2002-03-18 01:19:20 +03:00
|
|
|
static void
|
|
|
|
hook_disestablish(list, vhook)
|
|
|
|
hook_list_t *list;
|
1995-06-01 00:41:44 +04:00
|
|
|
void *vhook;
|
|
|
|
{
|
|
|
|
#ifdef DIAGNOSTIC
|
2002-03-18 01:19:20 +03:00
|
|
|
struct hook_desc *hd;
|
1995-06-01 00:41:44 +04:00
|
|
|
|
2002-08-24 00:50:25 +04:00
|
|
|
LIST_FOREACH(hd, list, hk_list) {
|
2002-03-18 01:19:20 +03:00
|
|
|
if (hd == vhook)
|
1995-06-01 00:41:44 +04:00
|
|
|
break;
|
2002-08-24 00:50:25 +04:00
|
|
|
}
|
|
|
|
|
2002-03-18 01:19:20 +03:00
|
|
|
if (hd == NULL)
|
2002-08-24 00:50:25 +04:00
|
|
|
panic("hook_disestablish: hook %p not established", vhook);
|
1995-06-01 00:41:44 +04:00
|
|
|
#endif
|
2002-03-18 01:19:20 +03:00
|
|
|
LIST_REMOVE((struct hook_desc *)vhook, hk_list);
|
1996-11-24 03:42:31 +03:00
|
|
|
free(vhook, M_DEVBUF);
|
1995-06-01 00:41:44 +04:00
|
|
|
}
|
|
|
|
|
2002-03-18 01:19:20 +03:00
|
|
|
static void
|
|
|
|
hook_destroy(list)
|
|
|
|
hook_list_t *list;
|
|
|
|
{
|
|
|
|
struct hook_desc *hd;
|
|
|
|
|
2002-09-04 05:32:31 +04:00
|
|
|
while ((hd = LIST_FIRST(list)) != NULL) {
|
2002-03-18 01:19:20 +03:00
|
|
|
LIST_REMOVE(hd, hk_list);
|
|
|
|
free(hd, M_DEVBUF);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
hook_proc_run(list, p)
|
|
|
|
hook_list_t *list;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
struct hook_desc *hd;
|
|
|
|
|
|
|
|
for (hd = LIST_FIRST(list); hd != NULL; hd = LIST_NEXT(hd, hk_list)) {
|
|
|
|
((void (*) __P((struct proc *, void *)))*hd->hk_fn)(p,
|
|
|
|
hd->hk_arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "Shutdown hook" types, functions, and variables.
|
|
|
|
*
|
|
|
|
* Should be invoked immediately before the
|
|
|
|
* system is halted or rebooted, i.e. after file systems unmounted,
|
|
|
|
* after crash dump done, etc.
|
|
|
|
*
|
|
|
|
* Each shutdown hook is removed from the list before it's run, so that
|
|
|
|
* it won't be run again.
|
|
|
|
*/
|
|
|
|
|
|
|
|
hook_list_t shutdownhook_list;
|
|
|
|
|
|
|
|
void *
|
|
|
|
shutdownhook_establish(fn, arg)
|
|
|
|
void (*fn) __P((void *));
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
return hook_establish(&shutdownhook_list, fn, arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
shutdownhook_disestablish(vhook)
|
|
|
|
void *vhook;
|
|
|
|
{
|
2002-09-23 07:37:59 +04:00
|
|
|
hook_disestablish(&shutdownhook_list, vhook);
|
2002-03-18 01:19:20 +03:00
|
|
|
}
|
|
|
|
|
1995-06-01 00:41:44 +04:00
|
|
|
/*
|
|
|
|
* Run shutdown hooks. Should be invoked immediately before the
|
|
|
|
* system is halted or rebooted, i.e. after file systems unmounted,
|
|
|
|
* after crash dump done, etc.
|
1996-11-24 03:42:31 +03:00
|
|
|
*
|
|
|
|
* Each shutdown hook is removed from the list before it's run, so that
|
|
|
|
* it won't be run again.
|
1995-06-01 00:41:44 +04:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
doshutdownhooks()
|
|
|
|
{
|
2002-03-18 01:19:20 +03:00
|
|
|
struct hook_desc *dp;
|
1995-06-01 00:41:44 +04:00
|
|
|
|
2002-09-04 05:32:31 +04:00
|
|
|
while ((dp = LIST_FIRST(&shutdownhook_list)) != NULL) {
|
2002-03-18 01:19:20 +03:00
|
|
|
LIST_REMOVE(dp, hk_list);
|
|
|
|
(*dp->hk_fn)(dp->hk_arg);
|
1996-11-24 03:42:31 +03:00
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* Don't bother freeing the hook structure,, since we may
|
|
|
|
* be rebooting because of a memory corruption problem,
|
|
|
|
* and this might only make things worse. It doesn't
|
|
|
|
* matter, anyway, since the system is just about to
|
|
|
|
* reboot.
|
|
|
|
*/
|
|
|
|
free(dp, M_DEVBUF);
|
|
|
|
#endif
|
|
|
|
}
|
1995-06-01 00:41:44 +04:00
|
|
|
}
|
1997-01-31 05:31:33 +03:00
|
|
|
|
2002-03-18 01:19:20 +03:00
|
|
|
/*
|
|
|
|
* "Mountroot hook" types, functions, and variables.
|
|
|
|
*/
|
|
|
|
|
|
|
|
hook_list_t mountroothook_list;
|
|
|
|
|
|
|
|
void *
|
|
|
|
mountroothook_establish(fn, dev)
|
|
|
|
void (*fn) __P((struct device *));
|
|
|
|
struct device *dev;
|
|
|
|
{
|
|
|
|
return hook_establish(&mountroothook_list, (void (*)__P((void *)))fn,
|
|
|
|
dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mountroothook_disestablish(vhook)
|
|
|
|
void *vhook;
|
|
|
|
{
|
2002-09-23 07:37:59 +04:00
|
|
|
hook_disestablish(&mountroothook_list, vhook);
|
2002-03-18 01:19:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mountroothook_destroy()
|
|
|
|
{
|
|
|
|
hook_destroy(&mountroothook_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
domountroothook()
|
|
|
|
{
|
|
|
|
struct hook_desc *hd;
|
|
|
|
|
2002-08-24 00:50:25 +04:00
|
|
|
LIST_FOREACH(hd, &mountroothook_list, hk_list) {
|
2002-03-18 01:19:20 +03:00
|
|
|
if (hd->hk_arg == (void *)root_device) {
|
|
|
|
(*hd->hk_fn)(hd->hk_arg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
hook_list_t exechook_list;
|
|
|
|
|
|
|
|
void *
|
|
|
|
exechook_establish(fn, arg)
|
|
|
|
void (*fn) __P((struct proc *, void *));
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
return hook_establish(&exechook_list, (void (*) __P((void *)))fn, arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
exechook_disestablish(vhook)
|
|
|
|
void *vhook;
|
|
|
|
{
|
|
|
|
hook_disestablish(&exechook_list, vhook);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Run exec hooks.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
doexechooks(p)
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
hook_proc_run(&exechook_list, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
hook_list_t exithook_list;
|
|
|
|
|
|
|
|
void *
|
|
|
|
exithook_establish(fn, arg)
|
|
|
|
void (*fn) __P((struct proc *, void *));
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
return hook_establish(&exithook_list, (void (*) __P((void *)))fn, arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
exithook_disestablish(vhook)
|
|
|
|
void *vhook;
|
|
|
|
{
|
|
|
|
hook_disestablish(&exithook_list, vhook);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Run exit hooks.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
doexithooks(p)
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
hook_proc_run(&exithook_list, p);
|
|
|
|
}
|
|
|
|
|
2003-01-24 04:42:52 +03:00
|
|
|
hook_list_t forkhook_list;
|
|
|
|
|
|
|
|
void *
|
|
|
|
forkhook_establish(fn)
|
|
|
|
void (*fn) __P((struct proc *, struct proc *));
|
|
|
|
{
|
|
|
|
return hook_establish(&forkhook_list, (void (*) __P((void *)))fn, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
forkhook_disestablish(vhook)
|
|
|
|
void *vhook;
|
|
|
|
{
|
|
|
|
hook_disestablish(&forkhook_list, vhook);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Run fork hooks.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
doforkhooks(p2, p1)
|
|
|
|
struct proc *p2, *p1;
|
|
|
|
{
|
|
|
|
struct hook_desc *hd;
|
|
|
|
|
|
|
|
LIST_FOREACH(hd, &forkhook_list, hk_list) {
|
|
|
|
((void (*) __P((struct proc *, struct proc *)))*hd->hk_fn)
|
|
|
|
(p2, p1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-06-26 12:25:25 +04:00
|
|
|
/*
|
|
|
|
* "Power hook" types, functions, and variables.
|
2000-07-26 16:24:52 +04:00
|
|
|
* The list of power hooks is kept ordered with the last registered hook
|
|
|
|
* first.
|
|
|
|
* When running the hooks on power down the hooks are called in reverse
|
|
|
|
* registration order, when powering up in registration order.
|
1999-06-26 12:25:25 +04:00
|
|
|
*/
|
|
|
|
struct powerhook_desc {
|
2000-07-26 16:24:52 +04:00
|
|
|
CIRCLEQ_ENTRY(powerhook_desc) sfd_list;
|
1999-06-26 12:25:25 +04:00
|
|
|
void (*sfd_fn) __P((int, void *));
|
|
|
|
void *sfd_arg;
|
|
|
|
};
|
|
|
|
|
2000-07-26 16:24:52 +04:00
|
|
|
CIRCLEQ_HEAD(, powerhook_desc) powerhook_list =
|
|
|
|
CIRCLEQ_HEAD_INITIALIZER(powerhook_list);
|
1999-06-26 12:25:25 +04:00
|
|
|
|
|
|
|
void *
|
|
|
|
powerhook_establish(fn, arg)
|
|
|
|
void (*fn) __P((int, void *));
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct powerhook_desc *ndp;
|
|
|
|
|
|
|
|
ndp = (struct powerhook_desc *)
|
|
|
|
malloc(sizeof(*ndp), M_DEVBUF, M_NOWAIT);
|
|
|
|
if (ndp == NULL)
|
2000-03-01 06:50:04 +03:00
|
|
|
return (NULL);
|
1999-06-26 12:25:25 +04:00
|
|
|
|
|
|
|
ndp->sfd_fn = fn;
|
|
|
|
ndp->sfd_arg = arg;
|
2000-07-26 16:24:52 +04:00
|
|
|
CIRCLEQ_INSERT_HEAD(&powerhook_list, ndp, sfd_list);
|
1999-06-26 12:25:25 +04:00
|
|
|
|
|
|
|
return (ndp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
powerhook_disestablish(vhook)
|
|
|
|
void *vhook;
|
|
|
|
{
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
struct powerhook_desc *dp;
|
|
|
|
|
2000-07-26 16:24:52 +04:00
|
|
|
CIRCLEQ_FOREACH(dp, &powerhook_list, sfd_list)
|
1999-06-26 12:25:25 +04:00
|
|
|
if (dp == vhook)
|
2000-07-26 16:24:52 +04:00
|
|
|
goto found;
|
2002-08-24 00:50:25 +04:00
|
|
|
panic("powerhook_disestablish: hook %p not established", vhook);
|
2000-07-26 16:24:52 +04:00
|
|
|
found:
|
1999-06-26 12:25:25 +04:00
|
|
|
#endif
|
|
|
|
|
2000-07-26 16:24:52 +04:00
|
|
|
CIRCLEQ_REMOVE(&powerhook_list, (struct powerhook_desc *)vhook,
|
|
|
|
sfd_list);
|
1999-06-26 12:25:25 +04:00
|
|
|
free(vhook, M_DEVBUF);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Run power hooks.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
dopowerhooks(why)
|
|
|
|
int why;
|
|
|
|
{
|
|
|
|
struct powerhook_desc *dp;
|
|
|
|
|
2000-11-26 14:08:57 +03:00
|
|
|
if (why == PWR_RESUME || why == PWR_SOFTRESUME) {
|
2000-07-26 16:24:52 +04:00
|
|
|
CIRCLEQ_FOREACH_REVERSE(dp, &powerhook_list, sfd_list) {
|
|
|
|
(*dp->sfd_fn)(why, dp->sfd_arg);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
CIRCLEQ_FOREACH(dp, &powerhook_list, sfd_list) {
|
|
|
|
(*dp->sfd_fn)(why, dp->sfd_arg);
|
|
|
|
}
|
1999-06-26 12:25:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-01-31 05:31:33 +03:00
|
|
|
/*
|
|
|
|
* Determine the root device and, if instructed to, the root file system.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "md.h"
|
|
|
|
#if NMD == 0
|
|
|
|
#undef MEMORY_DISK_HOOKS
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MEMORY_DISK_HOOKS
|
1997-08-04 00:36:03 +04:00
|
|
|
static struct device fakemdrootdev[NMD];
|
1997-01-31 05:31:33 +03:00
|
|
|
#endif
|
|
|
|
|
2000-02-13 07:57:44 +03:00
|
|
|
#include "raid.h"
|
|
|
|
#if NRAID == 1
|
|
|
|
#define BOOT_FROM_RAID_HOOKS 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef BOOT_FROM_RAID_HOOKS
|
|
|
|
extern int numraid;
|
|
|
|
extern struct device *raidrootdev;
|
|
|
|
#endif
|
|
|
|
|
1997-01-31 05:31:33 +03:00
|
|
|
void
|
1999-06-08 00:16:08 +04:00
|
|
|
setroot(bootdv, bootpartition)
|
1997-01-31 05:31:33 +03:00
|
|
|
struct device *bootdv;
|
|
|
|
int bootpartition;
|
|
|
|
{
|
|
|
|
struct device *dv;
|
2000-01-25 12:23:59 +03:00
|
|
|
int len;
|
1998-02-22 15:53:53 +03:00
|
|
|
#ifdef MEMORY_DISK_HOOKS
|
|
|
|
int i;
|
|
|
|
#endif
|
1997-06-12 21:12:17 +04:00
|
|
|
dev_t nrootdev;
|
Fix crash dump device selection after the recent swap changes:
- If RB_ASKNAME, prompt for the dump device, defaulting to
partition 'b' of the root device, if the root device is a disk.
- Else, if dumpspec is set to "none", do not configure a dump device.
- Else, if dumpspec is set by config(8), attempt to use that device.
- Else, dumpspec is wildcarded or unspecified; if the root device is
a disk, select partition b. (which was the previous default dump
partition)
Note, dumps to a local disk now work even if root is on nfs.
1997-06-14 08:17:32 +04:00
|
|
|
dev_t ndumpdev = NODEV;
|
1997-01-31 05:31:33 +03:00
|
|
|
char buf[128];
|
|
|
|
const char *rootdevname;
|
Fix crash dump device selection after the recent swap changes:
- If RB_ASKNAME, prompt for the dump device, defaulting to
partition 'b' of the root device, if the root device is a disk.
- Else, if dumpspec is set to "none", do not configure a dump device.
- Else, if dumpspec is set by config(8), attempt to use that device.
- Else, dumpspec is wildcarded or unspecified; if the root device is
a disk, select partition b. (which was the previous default dump
partition)
Note, dumps to a local disk now work even if root is on nfs.
1997-06-14 08:17:32 +04:00
|
|
|
const char *dumpdevname;
|
|
|
|
struct device *rootdv = NULL; /* XXX gcc -Wuninitialized */
|
|
|
|
struct device *dumpdv = NULL;
|
1997-01-31 05:31:33 +03:00
|
|
|
struct ifnet *ifp;
|
|
|
|
const char *deffsname;
|
|
|
|
struct vfsops *vops;
|
|
|
|
|
1997-08-04 00:36:03 +04:00
|
|
|
#ifdef MEMORY_DISK_HOOKS
|
|
|
|
for (i = 0; i < NMD; i++) {
|
|
|
|
fakemdrootdev[i].dv_class = DV_DISK;
|
|
|
|
fakemdrootdev[i].dv_cfdata = NULL;
|
|
|
|
fakemdrootdev[i].dv_unit = i;
|
|
|
|
fakemdrootdev[i].dv_parent = NULL;
|
|
|
|
sprintf(fakemdrootdev[i].dv_xname, "md%d", i);
|
|
|
|
}
|
|
|
|
#endif /* MEMORY_DISK_HOOKS */
|
|
|
|
|
1997-02-24 15:20:47 +03:00
|
|
|
#ifdef MEMORY_DISK_IS_ROOT
|
1997-08-04 00:36:03 +04:00
|
|
|
bootdv = &fakemdrootdev[0];
|
1997-01-31 05:31:33 +03:00
|
|
|
bootpartition = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If NFS is specified as the file system, and we found
|
|
|
|
* a DV_DISK boot device (or no boot device at all), then
|
|
|
|
* find a reasonable network interface for "rootspec".
|
|
|
|
*/
|
|
|
|
vops = vfs_getopsbyname("nfs");
|
|
|
|
if (vops != NULL && vops->vfs_mountroot == mountroot &&
|
|
|
|
rootspec == NULL &&
|
|
|
|
(bootdv == NULL || bootdv->dv_class != DV_IFNET)) {
|
2002-08-24 00:50:25 +04:00
|
|
|
TAILQ_FOREACH(ifp, &ifnet, if_list) {
|
1997-01-31 05:31:33 +03:00
|
|
|
if ((ifp->if_flags &
|
|
|
|
(IFF_LOOPBACK|IFF_POINTOPOINT)) == 0)
|
|
|
|
break;
|
2002-08-24 00:50:25 +04:00
|
|
|
}
|
1997-01-31 05:31:33 +03:00
|
|
|
if (ifp == NULL) {
|
|
|
|
/*
|
|
|
|
* Can't find a suitable interface; ask the
|
|
|
|
* user.
|
|
|
|
*/
|
|
|
|
boothowto |= RB_ASKNAME;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Have a suitable interface; behave as if
|
|
|
|
* the user specified this interface.
|
|
|
|
*/
|
|
|
|
rootspec = (const char *)ifp->if_xname;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-05-25 23:20:30 +04:00
|
|
|
/*
|
|
|
|
* If wildcarded root and we the boot device wasn't determined,
|
|
|
|
* ask the user.
|
|
|
|
*/
|
|
|
|
if (rootspec == NULL && bootdv == NULL)
|
|
|
|
boothowto |= RB_ASKNAME;
|
|
|
|
|
1997-01-31 05:31:33 +03:00
|
|
|
top:
|
|
|
|
if (boothowto & RB_ASKNAME) {
|
Fix crash dump device selection after the recent swap changes:
- If RB_ASKNAME, prompt for the dump device, defaulting to
partition 'b' of the root device, if the root device is a disk.
- Else, if dumpspec is set to "none", do not configure a dump device.
- Else, if dumpspec is set by config(8), attempt to use that device.
- Else, dumpspec is wildcarded or unspecified; if the root device is
a disk, select partition b. (which was the previous default dump
partition)
Note, dumps to a local disk now work even if root is on nfs.
1997-06-14 08:17:32 +04:00
|
|
|
struct device *defdumpdv;
|
|
|
|
|
1997-01-31 05:31:33 +03:00
|
|
|
for (;;) {
|
|
|
|
printf("root device");
|
|
|
|
if (bootdv != NULL) {
|
|
|
|
printf(" (default %s", bootdv->dv_xname);
|
|
|
|
if (bootdv->dv_class == DV_DISK)
|
|
|
|
printf("%c", bootpartition + 'a');
|
|
|
|
printf(")");
|
|
|
|
}
|
|
|
|
printf(": ");
|
2000-05-08 20:30:57 +04:00
|
|
|
len = cngetsn(buf, sizeof(buf));
|
1997-01-31 05:31:33 +03:00
|
|
|
if (len == 0 && bootdv != NULL) {
|
|
|
|
strcpy(buf, bootdv->dv_xname);
|
|
|
|
len = strlen(buf);
|
|
|
|
}
|
|
|
|
if (len > 0 && buf[len - 1] == '*') {
|
|
|
|
buf[--len] = '\0';
|
1999-06-08 00:16:08 +04:00
|
|
|
dv = getdisk(buf, len, 1, &nrootdev, 0);
|
1997-01-31 05:31:33 +03:00
|
|
|
if (dv != NULL) {
|
|
|
|
rootdv = dv;
|
1997-06-12 21:12:17 +04:00
|
|
|
break;
|
1997-01-31 05:31:33 +03:00
|
|
|
}
|
|
|
|
}
|
1999-06-08 00:16:08 +04:00
|
|
|
dv = getdisk(buf, len, bootpartition, &nrootdev, 0);
|
1997-01-31 05:31:33 +03:00
|
|
|
if (dv != NULL) {
|
|
|
|
rootdv = dv;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Fix crash dump device selection after the recent swap changes:
- If RB_ASKNAME, prompt for the dump device, defaulting to
partition 'b' of the root device, if the root device is a disk.
- Else, if dumpspec is set to "none", do not configure a dump device.
- Else, if dumpspec is set by config(8), attempt to use that device.
- Else, dumpspec is wildcarded or unspecified; if the root device is
a disk, select partition b. (which was the previous default dump
partition)
Note, dumps to a local disk now work even if root is on nfs.
1997-06-14 08:17:32 +04:00
|
|
|
/*
|
|
|
|
* Set up the default dump device. If root is on
|
|
|
|
* a network device, there is no default dump
|
|
|
|
* device, since we don't support dumps to the
|
|
|
|
* network.
|
|
|
|
*/
|
|
|
|
if (rootdv->dv_class == DV_IFNET)
|
|
|
|
defdumpdv = NULL;
|
|
|
|
else
|
|
|
|
defdumpdv = rootdv;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
printf("dump device");
|
|
|
|
if (defdumpdv != NULL) {
|
|
|
|
/*
|
|
|
|
* Note, we know it's a disk if we get here.
|
|
|
|
*/
|
|
|
|
printf(" (default %sb)", defdumpdv->dv_xname);
|
|
|
|
}
|
|
|
|
printf(": ");
|
2000-05-08 20:30:57 +04:00
|
|
|
len = cngetsn(buf, sizeof(buf));
|
Fix crash dump device selection after the recent swap changes:
- If RB_ASKNAME, prompt for the dump device, defaulting to
partition 'b' of the root device, if the root device is a disk.
- Else, if dumpspec is set to "none", do not configure a dump device.
- Else, if dumpspec is set by config(8), attempt to use that device.
- Else, dumpspec is wildcarded or unspecified; if the root device is
a disk, select partition b. (which was the previous default dump
partition)
Note, dumps to a local disk now work even if root is on nfs.
1997-06-14 08:17:32 +04:00
|
|
|
if (len == 0) {
|
|
|
|
if (defdumpdv != NULL) {
|
|
|
|
ndumpdev = MAKEDISKDEV(major(nrootdev),
|
|
|
|
DISKUNIT(nrootdev), 1);
|
|
|
|
}
|
2000-01-25 06:42:36 +03:00
|
|
|
dumpdv = defdumpdv;
|
Fix crash dump device selection after the recent swap changes:
- If RB_ASKNAME, prompt for the dump device, defaulting to
partition 'b' of the root device, if the root device is a disk.
- Else, if dumpspec is set to "none", do not configure a dump device.
- Else, if dumpspec is set by config(8), attempt to use that device.
- Else, dumpspec is wildcarded or unspecified; if the root device is
a disk, select partition b. (which was the previous default dump
partition)
Note, dumps to a local disk now work even if root is on nfs.
1997-06-14 08:17:32 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (len == 4 && strcmp(buf, "none") == 0) {
|
2000-01-25 12:23:59 +03:00
|
|
|
dumpdv = NULL;
|
2000-01-25 06:42:36 +03:00
|
|
|
break;
|
Fix crash dump device selection after the recent swap changes:
- If RB_ASKNAME, prompt for the dump device, defaulting to
partition 'b' of the root device, if the root device is a disk.
- Else, if dumpspec is set to "none", do not configure a dump device.
- Else, if dumpspec is set by config(8), attempt to use that device.
- Else, dumpspec is wildcarded or unspecified; if the root device is
a disk, select partition b. (which was the previous default dump
partition)
Note, dumps to a local disk now work even if root is on nfs.
1997-06-14 08:17:32 +04:00
|
|
|
}
|
1999-06-08 00:16:08 +04:00
|
|
|
dv = getdisk(buf, len, 1, &ndumpdev, 1);
|
2000-01-25 12:23:59 +03:00
|
|
|
if (dv != NULL) {
|
Fix crash dump device selection after the recent swap changes:
- If RB_ASKNAME, prompt for the dump device, defaulting to
partition 'b' of the root device, if the root device is a disk.
- Else, if dumpspec is set to "none", do not configure a dump device.
- Else, if dumpspec is set by config(8), attempt to use that device.
- Else, dumpspec is wildcarded or unspecified; if the root device is
a disk, select partition b. (which was the previous default dump
partition)
Note, dumps to a local disk now work even if root is on nfs.
1997-06-14 08:17:32 +04:00
|
|
|
dumpdv = dv;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-01-31 05:31:33 +03:00
|
|
|
rootdev = nrootdev;
|
Fix crash dump device selection after the recent swap changes:
- If RB_ASKNAME, prompt for the dump device, defaulting to
partition 'b' of the root device, if the root device is a disk.
- Else, if dumpspec is set to "none", do not configure a dump device.
- Else, if dumpspec is set by config(8), attempt to use that device.
- Else, dumpspec is wildcarded or unspecified; if the root device is
a disk, select partition b. (which was the previous default dump
partition)
Note, dumps to a local disk now work even if root is on nfs.
1997-06-14 08:17:32 +04:00
|
|
|
dumpdev = ndumpdev;
|
1997-01-31 05:31:33 +03:00
|
|
|
|
1998-02-18 10:11:46 +03:00
|
|
|
for (vops = LIST_FIRST(&vfs_list); vops != NULL;
|
|
|
|
vops = LIST_NEXT(vops, vfs_list)) {
|
|
|
|
if (vops->vfs_mountroot != NULL &&
|
|
|
|
vops->vfs_mountroot == mountroot)
|
1998-03-01 05:20:01 +03:00
|
|
|
break;
|
1997-01-31 05:31:33 +03:00
|
|
|
}
|
1998-02-18 10:11:46 +03:00
|
|
|
|
|
|
|
if (vops == NULL) {
|
1997-01-31 05:31:33 +03:00
|
|
|
mountroot = NULL;
|
|
|
|
deffsname = "generic";
|
|
|
|
} else
|
1998-02-18 10:11:46 +03:00
|
|
|
deffsname = vops->vfs_name;
|
|
|
|
|
1997-01-31 05:31:33 +03:00
|
|
|
for (;;) {
|
|
|
|
printf("file system (default %s): ", deffsname);
|
2000-05-08 20:30:57 +04:00
|
|
|
len = cngetsn(buf, sizeof(buf));
|
1997-01-31 05:31:33 +03:00
|
|
|
if (len == 0)
|
|
|
|
break;
|
|
|
|
if (len == 4 && strcmp(buf, "halt") == 0)
|
1997-03-27 01:42:13 +03:00
|
|
|
cpu_reboot(RB_HALT, NULL);
|
2001-05-27 05:29:50 +04:00
|
|
|
else if (len == 6 && strcmp(buf, "reboot") == 0)
|
|
|
|
cpu_reboot(0, NULL);
|
2002-02-08 03:58:58 +03:00
|
|
|
#if defined(DDB)
|
|
|
|
else if (len == 3 && strcmp(buf, "ddb") == 0) {
|
|
|
|
console_debugger();
|
|
|
|
}
|
|
|
|
#endif
|
1997-01-31 05:31:33 +03:00
|
|
|
else if (len == 7 && strcmp(buf, "generic") == 0) {
|
|
|
|
mountroot = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
vops = vfs_getopsbyname(buf);
|
|
|
|
if (vops == NULL || vops->vfs_mountroot == NULL) {
|
|
|
|
printf("use one of: generic");
|
1998-02-18 10:11:46 +03:00
|
|
|
for (vops = LIST_FIRST(&vfs_list);
|
|
|
|
vops != NULL;
|
|
|
|
vops = LIST_NEXT(vops, vfs_list)) {
|
|
|
|
if (vops->vfs_mountroot != NULL)
|
|
|
|
printf(" %s", vops->vfs_name);
|
|
|
|
}
|
2002-02-08 03:58:58 +03:00
|
|
|
#if defined(DDB)
|
|
|
|
printf(" ddb");
|
|
|
|
#endif
|
2001-05-27 05:29:50 +04:00
|
|
|
printf(" halt reboot\n");
|
1997-01-31 05:31:33 +03:00
|
|
|
} else {
|
|
|
|
mountroot = vops->vfs_mountroot;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (rootspec == NULL) {
|
|
|
|
int majdev;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wildcarded root; use the boot device.
|
|
|
|
*/
|
Fix crash dump device selection after the recent swap changes:
- If RB_ASKNAME, prompt for the dump device, defaulting to
partition 'b' of the root device, if the root device is a disk.
- Else, if dumpspec is set to "none", do not configure a dump device.
- Else, if dumpspec is set by config(8), attempt to use that device.
- Else, dumpspec is wildcarded or unspecified; if the root device is
a disk, select partition b. (which was the previous default dump
partition)
Note, dumps to a local disk now work even if root is on nfs.
1997-06-14 08:17:32 +04:00
|
|
|
rootdv = bootdv;
|
|
|
|
|
2002-09-06 17:18:43 +04:00
|
|
|
majdev = devsw_name2blk(bootdv->dv_xname, NULL, 0);
|
1997-01-31 05:31:33 +03:00
|
|
|
if (majdev >= 0) {
|
|
|
|
/*
|
1997-06-12 21:12:17 +04:00
|
|
|
* Root is on a disk. `bootpartition' is root.
|
1997-01-31 05:31:33 +03:00
|
|
|
*/
|
|
|
|
rootdev = MAKEDISKDEV(majdev, bootdv->dv_unit,
|
|
|
|
bootpartition);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/*
|
1997-06-12 21:12:17 +04:00
|
|
|
* `root on <dev> ...'
|
1997-01-31 05:31:33 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If it's a network interface, we can bail out
|
|
|
|
* early.
|
|
|
|
*/
|
2000-02-01 08:28:01 +03:00
|
|
|
dv = finddevice(rootspec);
|
1997-01-31 05:31:33 +03:00
|
|
|
if (dv != NULL && dv->dv_class == DV_IFNET) {
|
Fix crash dump device selection after the recent swap changes:
- If RB_ASKNAME, prompt for the dump device, defaulting to
partition 'b' of the root device, if the root device is a disk.
- Else, if dumpspec is set to "none", do not configure a dump device.
- Else, if dumpspec is set by config(8), attempt to use that device.
- Else, dumpspec is wildcarded or unspecified; if the root device is
a disk, select partition b. (which was the previous default dump
partition)
Note, dumps to a local disk now work even if root is on nfs.
1997-06-14 08:17:32 +04:00
|
|
|
rootdv = dv;
|
|
|
|
goto haveroot;
|
1997-01-31 05:31:33 +03:00
|
|
|
}
|
|
|
|
|
2002-09-06 17:18:43 +04:00
|
|
|
rootdevname = devsw_blk2name(major(rootdev));
|
1997-01-31 05:31:33 +03:00
|
|
|
if (rootdevname == NULL) {
|
|
|
|
printf("unknown device major 0x%x\n", rootdev);
|
|
|
|
boothowto |= RB_ASKNAME;
|
|
|
|
goto top;
|
|
|
|
}
|
Abolition of bcopy, ovbcopy, bcmp, and bzero, phase one.
bcopy(x, y, z) -> memcpy(y, x, z)
ovbcopy(x, y, z) -> memmove(y, x, z)
bcmp(x, y, z) -> memcmp(x, y, z)
bzero(x, y) -> memset(x, 0, y)
1998-08-04 08:03:10 +04:00
|
|
|
memset(buf, 0, sizeof(buf));
|
1997-01-31 05:31:33 +03:00
|
|
|
sprintf(buf, "%s%d", rootdevname, DISKUNIT(rootdev));
|
|
|
|
|
2000-02-01 08:28:01 +03:00
|
|
|
rootdv = finddevice(buf);
|
Fix crash dump device selection after the recent swap changes:
- If RB_ASKNAME, prompt for the dump device, defaulting to
partition 'b' of the root device, if the root device is a disk.
- Else, if dumpspec is set to "none", do not configure a dump device.
- Else, if dumpspec is set by config(8), attempt to use that device.
- Else, dumpspec is wildcarded or unspecified; if the root device is
a disk, select partition b. (which was the previous default dump
partition)
Note, dumps to a local disk now work even if root is on nfs.
1997-06-14 08:17:32 +04:00
|
|
|
if (rootdv == NULL) {
|
1997-01-31 05:31:33 +03:00
|
|
|
printf("device %s (0x%x) not configured\n",
|
|
|
|
buf, rootdev);
|
|
|
|
boothowto |= RB_ASKNAME;
|
|
|
|
goto top;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Fix crash dump device selection after the recent swap changes:
- If RB_ASKNAME, prompt for the dump device, defaulting to
partition 'b' of the root device, if the root device is a disk.
- Else, if dumpspec is set to "none", do not configure a dump device.
- Else, if dumpspec is set by config(8), attempt to use that device.
- Else, dumpspec is wildcarded or unspecified; if the root device is
a disk, select partition b. (which was the previous default dump
partition)
Note, dumps to a local disk now work even if root is on nfs.
1997-06-14 08:17:32 +04:00
|
|
|
haveroot:
|
|
|
|
|
1997-01-31 05:31:33 +03:00
|
|
|
root_device = rootdv;
|
|
|
|
|
|
|
|
switch (rootdv->dv_class) {
|
|
|
|
case DV_IFNET:
|
2000-01-25 12:23:59 +03:00
|
|
|
printf("root on %s", rootdv->dv_xname);
|
Fix crash dump device selection after the recent swap changes:
- If RB_ASKNAME, prompt for the dump device, defaulting to
partition 'b' of the root device, if the root device is a disk.
- Else, if dumpspec is set to "none", do not configure a dump device.
- Else, if dumpspec is set by config(8), attempt to use that device.
- Else, dumpspec is wildcarded or unspecified; if the root device is
a disk, select partition b. (which was the previous default dump
partition)
Note, dumps to a local disk now work even if root is on nfs.
1997-06-14 08:17:32 +04:00
|
|
|
break;
|
1997-01-31 05:31:33 +03:00
|
|
|
|
|
|
|
case DV_DISK:
|
|
|
|
printf("root on %s%c", rootdv->dv_xname,
|
|
|
|
DISKPART(rootdev) + 'a');
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("can't determine root device\n");
|
|
|
|
boothowto |= RB_ASKNAME;
|
|
|
|
goto top;
|
|
|
|
}
|
Fix crash dump device selection after the recent swap changes:
- If RB_ASKNAME, prompt for the dump device, defaulting to
partition 'b' of the root device, if the root device is a disk.
- Else, if dumpspec is set to "none", do not configure a dump device.
- Else, if dumpspec is set by config(8), attempt to use that device.
- Else, dumpspec is wildcarded or unspecified; if the root device is
a disk, select partition b. (which was the previous default dump
partition)
Note, dumps to a local disk now work even if root is on nfs.
1997-06-14 08:17:32 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now configure the dump device.
|
2000-01-25 12:23:59 +03:00
|
|
|
*
|
Fix crash dump device selection after the recent swap changes:
- If RB_ASKNAME, prompt for the dump device, defaulting to
partition 'b' of the root device, if the root device is a disk.
- Else, if dumpspec is set to "none", do not configure a dump device.
- Else, if dumpspec is set by config(8), attempt to use that device.
- Else, dumpspec is wildcarded or unspecified; if the root device is
a disk, select partition b. (which was the previous default dump
partition)
Note, dumps to a local disk now work even if root is on nfs.
1997-06-14 08:17:32 +04:00
|
|
|
* If we haven't figured out the dump device, do so, with
|
|
|
|
* the following rules:
|
|
|
|
*
|
|
|
|
* (a) We already know dumpdv in the RB_ASKNAME case.
|
|
|
|
*
|
|
|
|
* (b) If dumpspec is set, try to use it. If the device
|
|
|
|
* is not available, punt.
|
|
|
|
*
|
|
|
|
* (c) If dumpspec is not set, the dump device is
|
|
|
|
* wildcarded or unspecified. If the root device
|
|
|
|
* is DV_IFNET, punt. Otherwise, use partition b
|
|
|
|
* of the root device.
|
|
|
|
*/
|
|
|
|
|
2000-01-25 12:23:59 +03:00
|
|
|
if (boothowto & RB_ASKNAME) { /* (a) */
|
|
|
|
if (dumpdv == NULL)
|
|
|
|
goto nodumpdev;
|
|
|
|
} else if (dumpspec != NULL) { /* (b) */
|
|
|
|
if (strcmp(dumpspec, "none") == 0 || dumpdev == NODEV) {
|
Fix crash dump device selection after the recent swap changes:
- If RB_ASKNAME, prompt for the dump device, defaulting to
partition 'b' of the root device, if the root device is a disk.
- Else, if dumpspec is set to "none", do not configure a dump device.
- Else, if dumpspec is set by config(8), attempt to use that device.
- Else, dumpspec is wildcarded or unspecified; if the root device is
a disk, select partition b. (which was the previous default dump
partition)
Note, dumps to a local disk now work even if root is on nfs.
1997-06-14 08:17:32 +04:00
|
|
|
/*
|
2000-01-25 12:23:59 +03:00
|
|
|
* Operator doesn't want a dump device.
|
|
|
|
* Or looks like they tried to pick a network
|
Fix crash dump device selection after the recent swap changes:
- If RB_ASKNAME, prompt for the dump device, defaulting to
partition 'b' of the root device, if the root device is a disk.
- Else, if dumpspec is set to "none", do not configure a dump device.
- Else, if dumpspec is set by config(8), attempt to use that device.
- Else, dumpspec is wildcarded or unspecified; if the root device is
a disk, select partition b. (which was the previous default dump
partition)
Note, dumps to a local disk now work even if root is on nfs.
1997-06-14 08:17:32 +04:00
|
|
|
* device. Oops.
|
|
|
|
*/
|
|
|
|
goto nodumpdev;
|
|
|
|
}
|
|
|
|
|
2002-09-06 17:18:43 +04:00
|
|
|
dumpdevname = devsw_blk2name(major(dumpdev));
|
Fix crash dump device selection after the recent swap changes:
- If RB_ASKNAME, prompt for the dump device, defaulting to
partition 'b' of the root device, if the root device is a disk.
- Else, if dumpspec is set to "none", do not configure a dump device.
- Else, if dumpspec is set by config(8), attempt to use that device.
- Else, dumpspec is wildcarded or unspecified; if the root device is
a disk, select partition b. (which was the previous default dump
partition)
Note, dumps to a local disk now work even if root is on nfs.
1997-06-14 08:17:32 +04:00
|
|
|
if (dumpdevname == NULL)
|
|
|
|
goto nodumpdev;
|
Abolition of bcopy, ovbcopy, bcmp, and bzero, phase one.
bcopy(x, y, z) -> memcpy(y, x, z)
ovbcopy(x, y, z) -> memmove(y, x, z)
bcmp(x, y, z) -> memcmp(x, y, z)
bzero(x, y) -> memset(x, 0, y)
1998-08-04 08:03:10 +04:00
|
|
|
memset(buf, 0, sizeof(buf));
|
Fix crash dump device selection after the recent swap changes:
- If RB_ASKNAME, prompt for the dump device, defaulting to
partition 'b' of the root device, if the root device is a disk.
- Else, if dumpspec is set to "none", do not configure a dump device.
- Else, if dumpspec is set by config(8), attempt to use that device.
- Else, dumpspec is wildcarded or unspecified; if the root device is
a disk, select partition b. (which was the previous default dump
partition)
Note, dumps to a local disk now work even if root is on nfs.
1997-06-14 08:17:32 +04:00
|
|
|
sprintf(buf, "%s%d", dumpdevname, DISKUNIT(dumpdev));
|
|
|
|
|
2000-02-01 08:28:01 +03:00
|
|
|
dumpdv = finddevice(buf);
|
|
|
|
if (dumpdv == NULL) {
|
Fix crash dump device selection after the recent swap changes:
- If RB_ASKNAME, prompt for the dump device, defaulting to
partition 'b' of the root device, if the root device is a disk.
- Else, if dumpspec is set to "none", do not configure a dump device.
- Else, if dumpspec is set by config(8), attempt to use that device.
- Else, dumpspec is wildcarded or unspecified; if the root device is
a disk, select partition b. (which was the previous default dump
partition)
Note, dumps to a local disk now work even if root is on nfs.
1997-06-14 08:17:32 +04:00
|
|
|
/*
|
|
|
|
* Device not configured.
|
|
|
|
*/
|
|
|
|
goto nodumpdev;
|
|
|
|
}
|
2000-01-25 12:23:59 +03:00
|
|
|
} else { /* (c) */
|
|
|
|
if (rootdv->dv_class == DV_IFNET)
|
|
|
|
goto nodumpdev;
|
|
|
|
else {
|
|
|
|
dumpdv = rootdv;
|
|
|
|
dumpdev = MAKEDISKDEV(major(rootdev),
|
|
|
|
dumpdv->dv_unit, 1);
|
|
|
|
}
|
Fix crash dump device selection after the recent swap changes:
- If RB_ASKNAME, prompt for the dump device, defaulting to
partition 'b' of the root device, if the root device is a disk.
- Else, if dumpspec is set to "none", do not configure a dump device.
- Else, if dumpspec is set by config(8), attempt to use that device.
- Else, dumpspec is wildcarded or unspecified; if the root device is
a disk, select partition b. (which was the previous default dump
partition)
Note, dumps to a local disk now work even if root is on nfs.
1997-06-14 08:17:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
printf(" dumps on %s%c\n", dumpdv->dv_xname, DISKPART(dumpdev) + 'a');
|
|
|
|
return;
|
|
|
|
|
|
|
|
nodumpdev:
|
|
|
|
dumpdev = NODEV;
|
2000-01-25 12:23:59 +03:00
|
|
|
printf("\n");
|
1997-01-31 05:31:33 +03:00
|
|
|
}
|
|
|
|
|
2000-02-01 08:28:01 +03:00
|
|
|
static struct device *
|
|
|
|
finddevice(name)
|
|
|
|
const char *name;
|
|
|
|
{
|
|
|
|
struct device *dv;
|
2000-02-13 07:57:44 +03:00
|
|
|
#ifdef BOOT_FROM_RAID_HOOKS
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for (j = 0; j < numraid; j++) {
|
|
|
|
if (strcmp(name, raidrootdev[j].dv_xname) == 0) {
|
|
|
|
dv = &raidrootdev[j];
|
2000-03-01 06:50:04 +03:00
|
|
|
return (dv);
|
2000-02-13 07:57:44 +03:00
|
|
|
}
|
|
|
|
}
|
2001-01-13 01:55:10 +03:00
|
|
|
#endif
|
2000-02-01 08:28:01 +03:00
|
|
|
|
|
|
|
for (dv = TAILQ_FIRST(&alldevs); dv != NULL;
|
|
|
|
dv = TAILQ_NEXT(dv, dv_list))
|
|
|
|
if (strcmp(dv->dv_xname, name) == 0)
|
|
|
|
break;
|
|
|
|
return (dv);
|
|
|
|
}
|
|
|
|
|
1997-01-31 05:31:33 +03:00
|
|
|
static struct device *
|
1999-06-08 00:16:08 +04:00
|
|
|
getdisk(str, len, defpart, devp, isdump)
|
1997-01-31 05:31:33 +03:00
|
|
|
char *str;
|
|
|
|
int len, defpart;
|
|
|
|
dev_t *devp;
|
Fix crash dump device selection after the recent swap changes:
- If RB_ASKNAME, prompt for the dump device, defaulting to
partition 'b' of the root device, if the root device is a disk.
- Else, if dumpspec is set to "none", do not configure a dump device.
- Else, if dumpspec is set by config(8), attempt to use that device.
- Else, dumpspec is wildcarded or unspecified; if the root device is
a disk, select partition b. (which was the previous default dump
partition)
Note, dumps to a local disk now work even if root is on nfs.
1997-06-14 08:17:32 +04:00
|
|
|
int isdump;
|
1997-01-31 05:31:33 +03:00
|
|
|
{
|
1997-08-04 00:36:03 +04:00
|
|
|
struct device *dv;
|
1997-08-06 20:57:33 +04:00
|
|
|
#ifdef MEMORY_DISK_HOOKS
|
1997-08-04 00:36:03 +04:00
|
|
|
int i;
|
1997-08-06 20:57:33 +04:00
|
|
|
#endif
|
2000-02-13 07:57:44 +03:00
|
|
|
#ifdef BOOT_FROM_RAID_HOOKS
|
|
|
|
int j;
|
|
|
|
#endif
|
1997-01-31 05:31:33 +03:00
|
|
|
|
1999-06-08 00:16:08 +04:00
|
|
|
if ((dv = parsedisk(str, len, defpart, devp)) == NULL) {
|
1997-01-31 05:31:33 +03:00
|
|
|
printf("use one of:");
|
|
|
|
#ifdef MEMORY_DISK_HOOKS
|
Fix crash dump device selection after the recent swap changes:
- If RB_ASKNAME, prompt for the dump device, defaulting to
partition 'b' of the root device, if the root device is a disk.
- Else, if dumpspec is set to "none", do not configure a dump device.
- Else, if dumpspec is set by config(8), attempt to use that device.
- Else, dumpspec is wildcarded or unspecified; if the root device is
a disk, select partition b. (which was the previous default dump
partition)
Note, dumps to a local disk now work even if root is on nfs.
1997-06-14 08:17:32 +04:00
|
|
|
if (isdump == 0)
|
1997-08-04 00:36:03 +04:00
|
|
|
for (i = 0; i < NMD; i++)
|
|
|
|
printf(" %s[a-%c]", fakemdrootdev[i].dv_xname,
|
|
|
|
'a' + MAXPARTITIONS - 1);
|
2000-02-13 07:57:44 +03:00
|
|
|
#endif
|
|
|
|
#ifdef BOOT_FROM_RAID_HOOKS
|
|
|
|
if (isdump == 0)
|
|
|
|
for (j = 0; j < numraid; j++)
|
2000-03-01 06:50:04 +03:00
|
|
|
printf(" %s[a-%c]", raidrootdev[j].dv_xname,
|
|
|
|
'a' + MAXPARTITIONS - 1);
|
1997-01-31 05:31:33 +03:00
|
|
|
#endif
|
2002-08-24 00:50:25 +04:00
|
|
|
TAILQ_FOREACH(dv, &alldevs, dv_list) {
|
1997-01-31 05:31:33 +03:00
|
|
|
if (dv->dv_class == DV_DISK)
|
|
|
|
printf(" %s[a-%c]", dv->dv_xname,
|
1997-02-01 03:39:14 +03:00
|
|
|
'a' + MAXPARTITIONS - 1);
|
Fix crash dump device selection after the recent swap changes:
- If RB_ASKNAME, prompt for the dump device, defaulting to
partition 'b' of the root device, if the root device is a disk.
- Else, if dumpspec is set to "none", do not configure a dump device.
- Else, if dumpspec is set by config(8), attempt to use that device.
- Else, dumpspec is wildcarded or unspecified; if the root device is
a disk, select partition b. (which was the previous default dump
partition)
Note, dumps to a local disk now work even if root is on nfs.
1997-06-14 08:17:32 +04:00
|
|
|
if (isdump == 0 && dv->dv_class == DV_IFNET)
|
1997-01-31 05:31:33 +03:00
|
|
|
printf(" %s", dv->dv_xname);
|
|
|
|
}
|
Fix crash dump device selection after the recent swap changes:
- If RB_ASKNAME, prompt for the dump device, defaulting to
partition 'b' of the root device, if the root device is a disk.
- Else, if dumpspec is set to "none", do not configure a dump device.
- Else, if dumpspec is set by config(8), attempt to use that device.
- Else, dumpspec is wildcarded or unspecified; if the root device is
a disk, select partition b. (which was the previous default dump
partition)
Note, dumps to a local disk now work even if root is on nfs.
1997-06-14 08:17:32 +04:00
|
|
|
if (isdump)
|
|
|
|
printf(" none");
|
2002-02-08 03:58:58 +03:00
|
|
|
#if defined(DDB)
|
|
|
|
printf(" ddb");
|
|
|
|
#endif
|
2001-05-27 05:29:50 +04:00
|
|
|
printf(" halt reboot\n");
|
1997-01-31 05:31:33 +03:00
|
|
|
}
|
|
|
|
return (dv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct device *
|
1999-06-08 00:16:08 +04:00
|
|
|
parsedisk(str, len, defpart, devp)
|
1997-01-31 05:31:33 +03:00
|
|
|
char *str;
|
|
|
|
int len, defpart;
|
|
|
|
dev_t *devp;
|
|
|
|
{
|
|
|
|
struct device *dv;
|
|
|
|
char *cp, c;
|
1997-08-06 20:57:33 +04:00
|
|
|
int majdev, part;
|
|
|
|
#ifdef MEMORY_DISK_HOOKS
|
|
|
|
int i;
|
|
|
|
#endif
|
1997-01-31 05:31:33 +03:00
|
|
|
if (len == 0)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
if (len == 4 && strcmp(str, "halt") == 0)
|
1997-03-27 01:42:13 +03:00
|
|
|
cpu_reboot(RB_HALT, NULL);
|
2001-05-27 05:29:50 +04:00
|
|
|
else if (len == 6 && strcmp(str, "reboot") == 0)
|
|
|
|
cpu_reboot(0, NULL);
|
2002-02-08 03:58:58 +03:00
|
|
|
#if defined(DDB)
|
|
|
|
else if (len == 3 && strcmp(str, "ddb") == 0)
|
|
|
|
console_debugger();
|
|
|
|
#endif
|
1997-01-31 05:31:33 +03:00
|
|
|
|
|
|
|
cp = str + len - 1;
|
|
|
|
c = *cp;
|
|
|
|
if (c >= 'a' && c <= ('a' + MAXPARTITIONS - 1)) {
|
|
|
|
part = c - 'a';
|
|
|
|
*cp = '\0';
|
|
|
|
} else
|
|
|
|
part = defpart;
|
|
|
|
|
|
|
|
#ifdef MEMORY_DISK_HOOKS
|
1997-08-04 00:36:03 +04:00
|
|
|
for (i = 0; i < NMD; i++)
|
|
|
|
if (strcmp(str, fakemdrootdev[i].dv_xname) == 0) {
|
|
|
|
dv = &fakemdrootdev[i];
|
|
|
|
goto gotdisk;
|
|
|
|
}
|
1997-01-31 05:31:33 +03:00
|
|
|
#endif
|
|
|
|
|
2000-02-01 08:28:01 +03:00
|
|
|
dv = finddevice(str);
|
|
|
|
if (dv != NULL) {
|
|
|
|
if (dv->dv_class == DV_DISK) {
|
1997-01-31 05:31:33 +03:00
|
|
|
#ifdef MEMORY_DISK_HOOKS
|
|
|
|
gotdisk:
|
|
|
|
#endif
|
2002-09-06 17:18:43 +04:00
|
|
|
majdev = devsw_name2blk(dv->dv_xname, NULL, 0);
|
1997-01-31 05:31:33 +03:00
|
|
|
if (majdev < 0)
|
|
|
|
panic("parsedisk");
|
|
|
|
*devp = MAKEDISKDEV(majdev, dv->dv_unit, part);
|
|
|
|
}
|
|
|
|
|
2000-02-01 08:28:01 +03:00
|
|
|
if (dv->dv_class == DV_IFNET)
|
1997-01-31 05:31:33 +03:00
|
|
|
*devp = NODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
*cp = c;
|
|
|
|
return (dv);
|
|
|
|
}
|
|
|
|
|
1999-05-09 17:48:44 +04:00
|
|
|
/*
|
1999-05-20 09:58:19 +04:00
|
|
|
* snprintf() `bytes' into `buf', reformatting it so that the number,
|
|
|
|
* plus a possible `x' + suffix extension) fits into len bytes (including
|
|
|
|
* the terminating NUL).
|
2000-03-01 06:51:29 +03:00
|
|
|
* Returns the number of bytes stored in buf, or -1 if there was a problem.
|
1999-05-20 09:58:19 +04:00
|
|
|
* E.g, given a len of 9 and a suffix of `B':
|
1999-05-09 17:48:44 +04:00
|
|
|
* bytes result
|
|
|
|
* ----- ------
|
1999-05-20 09:58:19 +04:00
|
|
|
* 99999 `99999 B'
|
2002-09-26 19:06:47 +04:00
|
|
|
* 100000 `97 kB'
|
|
|
|
* 66715648 `65152 kB'
|
1999-05-09 17:48:44 +04:00
|
|
|
* 252215296 `240 MB'
|
|
|
|
*/
|
|
|
|
int
|
2000-02-20 22:32:28 +03:00
|
|
|
humanize_number(buf, len, bytes, suffix, divisor)
|
1999-05-09 17:48:44 +04:00
|
|
|
char *buf;
|
|
|
|
size_t len;
|
|
|
|
u_int64_t bytes;
|
1999-05-20 09:58:19 +04:00
|
|
|
const char *suffix;
|
2000-02-20 22:32:28 +03:00
|
|
|
int divisor;
|
1999-05-09 17:48:44 +04:00
|
|
|
{
|
2002-09-27 22:37:43 +04:00
|
|
|
/* prefixes are: (none), kilo, Mega, Giga, Tera, Peta, Exa */
|
|
|
|
const char *prefixes;
|
2002-08-26 02:32:02 +04:00
|
|
|
int r;
|
1999-05-09 17:48:44 +04:00
|
|
|
u_int64_t max;
|
2002-08-26 02:32:02 +04:00
|
|
|
size_t i, suffixlen;
|
1999-05-09 17:48:44 +04:00
|
|
|
|
1999-05-20 09:58:19 +04:00
|
|
|
if (buf == NULL || suffix == NULL)
|
|
|
|
return (-1);
|
1999-05-09 17:48:44 +04:00
|
|
|
if (len > 0)
|
|
|
|
buf[0] = '\0';
|
1999-05-20 09:58:19 +04:00
|
|
|
suffixlen = strlen(suffix);
|
2002-09-27 22:37:43 +04:00
|
|
|
/* check if enough room for `x y' + suffix + `\0' */
|
1999-05-20 09:58:19 +04:00
|
|
|
if (len < 4 + suffixlen)
|
|
|
|
return (-1);
|
1999-05-09 17:48:44 +04:00
|
|
|
|
2002-09-27 22:37:43 +04:00
|
|
|
if (divisor == 1024) {
|
|
|
|
/*
|
|
|
|
* binary multiplies
|
|
|
|
* XXX IEC 60027-2 recommends Ki, Mi, Gi...
|
|
|
|
*/
|
|
|
|
prefixes = " KMGTPE";
|
|
|
|
} else
|
|
|
|
prefixes = " kMGTPE"; /* SI for decimal multiplies */
|
|
|
|
|
1999-05-20 09:58:19 +04:00
|
|
|
max = 1;
|
|
|
|
for (i = 0; i < len - suffixlen - 3; i++)
|
1999-05-09 17:48:44 +04:00
|
|
|
max *= 10;
|
2002-09-27 22:37:43 +04:00
|
|
|
for (i = 0; bytes >= max && prefixes[i + 1]; i++)
|
2000-02-20 22:32:28 +03:00
|
|
|
bytes /= divisor;
|
1999-05-09 17:48:44 +04:00
|
|
|
|
1999-06-02 09:53:56 +04:00
|
|
|
r = snprintf(buf, len, "%qu%s%c%s", (unsigned long long)bytes,
|
1999-05-20 09:58:19 +04:00
|
|
|
i == 0 ? "" : " ", prefixes[i], suffix);
|
1999-05-09 17:48:44 +04:00
|
|
|
|
|
|
|
return (r);
|
|
|
|
}
|
1999-05-20 09:58:19 +04:00
|
|
|
|
|
|
|
int
|
|
|
|
format_bytes(buf, len, bytes)
|
|
|
|
char *buf;
|
|
|
|
size_t len;
|
|
|
|
u_int64_t bytes;
|
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
size_t nlen;
|
|
|
|
|
2000-02-20 22:32:28 +03:00
|
|
|
rv = humanize_number(buf, len, bytes, "B", 1024);
|
1999-05-20 09:58:19 +04:00
|
|
|
if (rv != -1) {
|
|
|
|
/* nuke the trailing ` B' if it exists */
|
|
|
|
nlen = strlen(buf) - 2;
|
|
|
|
if (strcmp(&buf[nlen], " B") == 0)
|
|
|
|
buf[nlen] = '\0';
|
|
|
|
}
|
|
|
|
return (rv);
|
|
|
|
}
|
2002-06-17 20:22:50 +04:00
|
|
|
|
2002-11-11 13:43:54 +03:00
|
|
|
/*
|
|
|
|
* Start trace of particular system call. If process is being traced,
|
|
|
|
* this routine is called by MD syscall dispatch code just before
|
|
|
|
* a system call is actually executed.
|
|
|
|
* MD caller guarantees the passed 'code' is within the supported
|
|
|
|
* system call number range for emulation the process runs under.
|
|
|
|
*/
|
2002-06-17 20:22:50 +04:00
|
|
|
int
|
2003-01-18 13:06:22 +03:00
|
|
|
trace_enter(struct lwp *l, register_t code,
|
|
|
|
register_t realcode, const struct sysent *callp, void *args,
|
|
|
|
register_t rval[])
|
2002-06-17 20:22:50 +04:00
|
|
|
{
|
2003-01-18 13:06:22 +03:00
|
|
|
#if defined(KTRACE) || defined(SYSTRACE)
|
|
|
|
struct proc *p = l->l_proc;
|
|
|
|
#endif
|
|
|
|
|
2002-06-17 20:22:50 +04:00
|
|
|
#ifdef SYSCALL_DEBUG
|
2003-01-18 13:06:22 +03:00
|
|
|
scdebug_call(l, code, args);
|
2002-06-17 20:22:50 +04:00
|
|
|
#endif /* SYSCALL_DEBUG */
|
|
|
|
|
|
|
|
#ifdef KTRACE
|
|
|
|
if (KTRPOINT(p, KTR_SYSCALL))
|
2002-12-21 19:23:56 +03:00
|
|
|
ktrsyscall(p, code, realcode, callp, args);
|
2002-06-17 20:22:50 +04:00
|
|
|
#endif /* KTRACE */
|
|
|
|
|
|
|
|
#ifdef SYSTRACE
|
|
|
|
if (ISSET(p->p_flag, P_SYSTRACE))
|
|
|
|
return systrace_enter(p, code, args, rval);
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-11-11 13:43:54 +03:00
|
|
|
/*
|
|
|
|
* End trace of particular system call. If process is being traced,
|
|
|
|
* this routine is called by MD syscall dispatch code just after
|
|
|
|
* a system call finishes.
|
|
|
|
* MD caller guarantees the passed 'code' is within the supported
|
|
|
|
* system call number range for emulation the process runs under.
|
|
|
|
*/
|
2002-06-17 20:22:50 +04:00
|
|
|
void
|
2003-01-18 13:06:22 +03:00
|
|
|
trace_exit(struct lwp *l, register_t code, void *args, register_t rval[],
|
2002-06-17 20:22:50 +04:00
|
|
|
int error)
|
|
|
|
{
|
2003-01-18 13:06:22 +03:00
|
|
|
#if defined(KTRACE) || defined(SYSTRACE)
|
|
|
|
struct proc *p = l->l_proc;
|
|
|
|
#endif
|
|
|
|
|
2002-06-17 20:22:50 +04:00
|
|
|
#ifdef SYSCALL_DEBUG
|
2003-01-18 13:06:22 +03:00
|
|
|
scdebug_ret(l, code, error, rval);
|
2002-06-17 20:22:50 +04:00
|
|
|
#endif /* SYSCALL_DEBUG */
|
|
|
|
|
|
|
|
#ifdef KTRACE
|
|
|
|
if (KTRPOINT(p, KTR_SYSRET)) {
|
2003-01-18 13:06:22 +03:00
|
|
|
KERNEL_PROC_LOCK(l);
|
2003-05-15 16:56:16 +04:00
|
|
|
ktrsysret(p, code, error, rval);
|
2003-01-18 13:06:22 +03:00
|
|
|
KERNEL_PROC_UNLOCK(l);
|
2002-06-17 20:22:50 +04:00
|
|
|
}
|
|
|
|
#endif /* KTRACE */
|
|
|
|
|
|
|
|
#ifdef SYSTRACE
|
|
|
|
if (ISSET(p->p_flag, P_SYSTRACE))
|
|
|
|
systrace_exit(p, code, args, rval, error);
|
|
|
|
#endif
|
|
|
|
}
|