Change major()/minor() to return 32-bit types again, called
devmajor_t/devminor_t, as proposed on tech-kern. This avoids 64-bit arithmetics and 64-bit printf formats in parts of the kernel where it is not really useful, and helps clarity.
This commit is contained in:
parent
68d230573c
commit
d767912be3
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: stdlib.h,v 1.86 2009/01/11 03:04:12 christos Exp $ */
|
||||
/* $NetBSD: stdlib.h,v 1.87 2009/01/20 18:20:47 drochner Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
|
@ -281,7 +281,7 @@ int humanize_number(char *, size_t, int64_t, const char *, int, int);
|
|||
int dehumanize_number(const char *, int64_t *);
|
||||
|
||||
#ifndef __LIBC12_SOURCE__
|
||||
dev_t getdevmajor(const char *, mode_t) __RENAME(__getdevmajor50);
|
||||
devmajor_t getdevmajor(const char *, mode_t) __RENAME(__getdevmajor50);
|
||||
#endif
|
||||
int getloadavg(double [], int);
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: stdlib.h,v 1.2 2009/01/11 02:46:25 christos Exp $ */
|
||||
/* $NetBSD: stdlib.h,v 1.3 2009/01/20 18:20:48 drochner Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
|
@ -41,7 +41,7 @@ int __unsetenv13(const char *);
|
|||
__aconst char *devname(int32_t, mode_t);
|
||||
__aconst char *__devname50(dev_t, mode_t);
|
||||
int32_t getdevmajor(const char *, mode_t);
|
||||
dev_t __getdevmajor50(const char *, mode_t);
|
||||
devmajor_t __getdevmajor50(const char *, mode_t);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: devname.c,v 1.18 2009/01/11 02:46:27 christos Exp $ */
|
||||
/* $NetBSD: devname.c,v 1.19 2009/01/20 18:20:48 drochner Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
||||
|
@ -67,7 +67,7 @@
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)devname.c 8.2 (Berkeley) 4/29/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: devname.c,v 1.18 2009/01/11 02:46:27 christos Exp $");
|
||||
__RCSID("$NetBSD: devname.c,v 1.19 2009/01/20 18:20:48 drochner Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
|
@ -113,7 +113,8 @@ devname(dev, type)
|
|||
DBT data, key;
|
||||
DEVC *ptr, **pptr;
|
||||
static DEVC **devtb = NULL;
|
||||
static dev_t pts = (dev_t)~1;
|
||||
static devmajor_t pts;
|
||||
static int pts_valid = 0;
|
||||
|
||||
if (!db && !failure &&
|
||||
!(db = dbopen(_PATH_DEVDB, O_RDONLY, 0, DB_HASH, NULL))) {
|
||||
|
@ -165,13 +166,15 @@ devname(dev, type)
|
|||
return (NULL);
|
||||
ptr->valid = INVALID;
|
||||
if (type == S_IFCHR) {
|
||||
if (pts == (dev_t)~1)
|
||||
if (!pts_valid) {
|
||||
pts = getdevmajor("pts", S_IFCHR);
|
||||
if (pts != (dev_t)~0 && major(dev) == pts) {
|
||||
pts_valid = 1;
|
||||
}
|
||||
if (pts != NODEVMAJOR && major(dev) == pts) {
|
||||
(void)snprintf(ptr->name, sizeof(ptr->name),
|
||||
"%s%llu", _PATH_DEV_PTS +
|
||||
"%s%d", _PATH_DEV_PTS +
|
||||
sizeof(_PATH_DEV) - 1,
|
||||
(unsigned long long)minor(dev));
|
||||
minor(dev));
|
||||
ptr->valid = VALID;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: getdevmajor.c,v 1.3 2004/12/16 04:37:25 atatat Exp $ */
|
||||
/* $NetBSD: getdevmajor.c,v 1.4 2009/01/20 18:20:48 drochner Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2004 The NetBSD Foundation, Inc.
|
||||
|
@ -34,7 +34,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: getdevmajor.c,v 1.3 2004/12/16 04:37:25 atatat Exp $");
|
||||
__RCSID("$NetBSD: getdevmajor.c,v 1.4 2009/01/20 18:20:48 drochner Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
|
@ -51,13 +51,13 @@ __RCSID("$NetBSD: getdevmajor.c,v 1.3 2004/12/16 04:37:25 atatat Exp $");
|
|||
__weak_alias(getdevmajor,_getdevmajor)
|
||||
#endif
|
||||
|
||||
dev_t
|
||||
devmajor_t
|
||||
getdevmajor(const char *name, mode_t type)
|
||||
{
|
||||
struct kinfo_drivers kd[200], *kdp = &kd[0];
|
||||
int rc, i;
|
||||
size_t sz = sizeof(kd);
|
||||
dev_t n = (dev_t)~0;
|
||||
devmajor_t n = NODEVMAJOR;
|
||||
|
||||
if (type != S_IFCHR && type != S_IFBLK) {
|
||||
errno = EINVAL;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: drm_drv.c,v 1.20 2009/01/18 10:04:35 mrg Exp $ */
|
||||
/* $NetBSD: drm_drv.c,v 1.21 2009/01/20 18:20:48 drochner Exp $ */
|
||||
|
||||
/* drm_drv.h -- Generic driver template -*- linux-c -*-
|
||||
* Created: Thu Nov 23 03:10:50 2000 by gareth@valinux.com
|
||||
|
@ -34,7 +34,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: drm_drv.c,v 1.20 2009/01/18 10:04:35 mrg Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: drm_drv.c,v 1.21 2009/01/20 18:20:48 drochner Exp $");
|
||||
/*
|
||||
__FBSDID("$FreeBSD: src/sys/dev/drm/drm_drv.c,v 1.6 2006/09/07 23:04:47 anholt Exp $");
|
||||
*/
|
||||
|
@ -820,7 +820,7 @@ static int
|
|||
drm_modcmd(modcmd_t cmd, void *arg)
|
||||
{
|
||||
#ifdef _MODULE
|
||||
int bmajor = -1, cmajor = -1;
|
||||
devmajor_t bmajor = NODEVMAJOR, cmajor = NODEVMAJOR;
|
||||
|
||||
switch (cmd) {
|
||||
case MODULE_CMD_INIT:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: pud.c,v 1.6 2007/11/28 17:01:59 pooka Exp $ */
|
||||
/* $NetBSD: pud.c,v 1.7 2009/01/20 18:20:48 drochner Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
|
||||
|
@ -29,7 +29,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: pud.c,v 1.6 2007/11/28 17:01:59 pooka Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: pud.c,v 1.7 2009/01/20 18:20:48 drochner Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/conf.h>
|
||||
|
@ -175,7 +175,8 @@ static int
|
|||
pudconf_reg(struct pud_dev *pd, struct pud_conf_reg *pcr)
|
||||
{
|
||||
struct bdevsw *bsw;
|
||||
int cmajor, bmajor, error;
|
||||
devmajor_t cmajor, bmajor;
|
||||
int error;
|
||||
|
||||
if (pcr->pm_version != (PUD_DEVELVERSION | PUD_VERSION)) {
|
||||
printf("pud version mismatch %d vs %d\n",
|
||||
|
@ -189,7 +190,7 @@ pudconf_reg(struct pud_dev *pd, struct pud_conf_reg *pcr)
|
|||
bmajor = cmajor;
|
||||
} else {
|
||||
bsw = NULL;
|
||||
bmajor = -1;
|
||||
bmajor = NODEVMAJOR;
|
||||
}
|
||||
|
||||
pcr->pm_devname[PUD_DEVNAME_MAX] = '\0';
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: putter.c,v 1.18 2008/12/29 17:52:43 pooka Exp $ */
|
||||
/* $NetBSD: putter.c,v 1.19 2009/01/20 18:20:48 drochner Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2006, 2007 Antti Kantee. All Rights Reserved.
|
||||
|
@ -35,7 +35,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: putter.c,v 1.18 2008/12/29 17:52:43 pooka Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: putter.c,v 1.19 2009/01/20 18:20:48 drochner Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -619,7 +619,7 @@ static int
|
|||
putter_modcmd(modcmd_t cmd, void *arg)
|
||||
{
|
||||
#ifdef _MODULE
|
||||
int bmajor = -1, cmajor = -1;
|
||||
devmajor_t bmajor = NODEVMAJOR, cmajor = NODEVMAJOR;
|
||||
|
||||
switch (cmd) {
|
||||
case MODULE_CMD_INIT:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: ucom.c,v 1.78 2009/01/11 10:56:27 cegger Exp $ */
|
||||
/* $NetBSD: ucom.c,v 1.79 2009/01/20 18:20:48 drochner Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
|
||||
|
@ -34,7 +34,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: ucom.c,v 1.78 2009/01/11 10:56:27 cegger Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: ucom.c,v 1.79 2009/01/20 18:20:48 drochner Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -496,7 +496,7 @@ ucomclose(dev_t dev, int flag, int mode, struct lwp *l)
|
|||
struct ucom_softc *sc = device_lookup_private(&ucom_cd, UCOMUNIT(dev));
|
||||
struct tty *tp = sc->sc_tty;
|
||||
|
||||
DPRINTF(("ucomclose: unit=%"PRId64"\n", UCOMUNIT(dev)));
|
||||
DPRINTF(("ucomclose: unit=%d\n", UCOMUNIT(dev)));
|
||||
if (!ISSET(tp->t_state, TS_ISOPEN))
|
||||
return (0);
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: ucycom.c,v 1.24 2009/01/11 10:56:27 cegger Exp $ */
|
||||
/* $NetBSD: ucycom.c,v 1.25 2009/01/20 18:20:48 drochner Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2005 The NetBSD Foundation, Inc.
|
||||
|
@ -38,7 +38,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: ucycom.c,v 1.24 2009/01/11 10:56:27 cegger Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: ucycom.c,v 1.25 2009/01/20 18:20:48 drochner Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -306,7 +306,7 @@ ucycomopen(dev_t dev, int flag, int mode, struct lwp *l)
|
|||
struct tty *tp;
|
||||
int s, err;
|
||||
|
||||
DPRINTF(("ucycomopen: unit=%"PRId64"\n", UCYCOMUNIT(dev)));
|
||||
DPRINTF(("ucycomopen: unit=%d\n", UCYCOMUNIT(dev)));
|
||||
DPRINTF(("ucycomopen: sc=%p\n", sc));
|
||||
|
||||
if (sc == NULL)
|
||||
|
@ -419,7 +419,7 @@ ucycomclose(dev_t dev, int flag, int mode, struct lwp *l)
|
|||
device_lookup_private(&ucycom_cd, UCYCOMUNIT(dev));
|
||||
struct tty *tp = sc->sc_tty;
|
||||
|
||||
DPRINTF(("ucycomclose: unit=%"PRId64"\n", UCYCOMUNIT(dev)));
|
||||
DPRINTF(("ucycomclose: unit=%d\n", UCYCOMUNIT(dev)));
|
||||
if (!ISSET(tp->t_state, TS_ISOPEN))
|
||||
return (0);
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: ugen.c,v 1.100 2009/01/11 10:56:27 cegger Exp $ */
|
||||
/* $NetBSD: ugen.c,v 1.101 2009/01/20 18:20:48 drochner Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
|
||||
|
@ -37,7 +37,7 @@
|
|||
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.100 2009/01/11 10:56:27 cegger Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: ugen.c,v 1.101 2009/01/20 18:20:48 drochner Exp $");
|
||||
|
||||
#include "opt_ugen_bulk_ra_wb.h"
|
||||
#include "opt_compat_netbsd.h"
|
||||
|
@ -503,7 +503,7 @@ ugenclose(dev_t dev, int flag, int mode, struct lwp *l)
|
|||
|
||||
USB_GET_SC(ugen, UGENUNIT(dev), sc);
|
||||
|
||||
DPRINTFN(5, ("ugenclose: flag=%d, mode=%d, unit=%"PRId64", endpt=%d\n",
|
||||
DPRINTFN(5, ("ugenclose: flag=%d, mode=%d, unit=%d, endpt=%d\n",
|
||||
flag, mode, UGENUNIT(dev), endpt));
|
||||
|
||||
#ifdef DIAGNOSTIC
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: urio.c,v 1.31 2009/01/11 11:06:08 cegger Exp $ */
|
||||
/* $NetBSD: urio.c,v 1.32 2009/01/20 18:20:48 drochner Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
||||
|
@ -36,7 +36,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: urio.c,v 1.31 2009/01/11 11:06:08 cegger Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: urio.c,v 1.32 2009/01/20 18:20:48 drochner Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -308,7 +308,7 @@ urioopen(dev_t dev, int flag, int mode, struct lwp *l)
|
|||
|
||||
USB_GET_SC_OPEN(urio, URIOUNIT(dev), sc);
|
||||
|
||||
DPRINTFN(5, ("urioopen: flag=%d, mode=%d, unit=%"PRId64"\n",
|
||||
DPRINTFN(5, ("urioopen: flag=%d, mode=%d, unit=%d\n",
|
||||
flag, mode, URIOUNIT(dev)));
|
||||
|
||||
if (sc->sc_dying)
|
||||
|
@ -340,7 +340,7 @@ urioclose(dev_t dev, int flag, int mode,
|
|||
struct urio_softc *sc;
|
||||
USB_GET_SC(urio, URIOUNIT(dev), sc);
|
||||
|
||||
DPRINTFN(5, ("urioclose: flag=%d, mode=%d, unit=%"PRId64"\n",
|
||||
DPRINTFN(5, ("urioclose: flag=%d, mode=%d, unit=%d\n",
|
||||
flag, mode, URIOUNIT(dev)));
|
||||
|
||||
if (sc->sc_in_pipe != NULL) {
|
||||
|
@ -369,7 +369,7 @@ urioread(dev_t dev, struct uio *uio, int flag)
|
|||
|
||||
USB_GET_SC(urio, URIOUNIT(dev), sc);
|
||||
|
||||
DPRINTFN(5, ("urioread: %"PRId64"\n", URIOUNIT(dev)));
|
||||
DPRINTFN(5, ("urioread: %d\n", URIOUNIT(dev)));
|
||||
|
||||
if (sc->sc_dying)
|
||||
return (EIO);
|
||||
|
@ -426,7 +426,7 @@ uriowrite(dev_t dev, struct uio *uio, int flag)
|
|||
|
||||
USB_GET_SC(urio, URIOUNIT(dev), sc);
|
||||
|
||||
DPRINTFN(5, ("uriowrite: unit=%"PRId64", len=%ld\n", URIOUNIT(dev),
|
||||
DPRINTFN(5, ("uriowrite: unit=%d, len=%ld\n", URIOUNIT(dev),
|
||||
(long)uio->uio_resid));
|
||||
|
||||
if (sc->sc_dying)
|
||||
|
@ -469,7 +469,7 @@ uriowrite(dev_t dev, struct uio *uio, int flag)
|
|||
if (--sc->sc_refcnt < 0)
|
||||
usb_detach_wakeup(USBDEV(sc->sc_dev));
|
||||
|
||||
DPRINTFN(5, ("uriowrite: done unit=%"PRId64", error=%d\n", URIOUNIT(dev),
|
||||
DPRINTFN(5, ("uriowrite: done unit=%d, error=%d\n", URIOUNIT(dev),
|
||||
error));
|
||||
|
||||
return (error);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: subr_devsw.c,v 1.23 2008/12/29 17:41:18 pooka Exp $ */
|
||||
/* $NetBSD: subr_devsw.c,v 1.24 2009/01/20 18:20:48 drochner Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2001, 2002, 2007, 2008 The NetBSD Foundation, Inc.
|
||||
|
@ -69,7 +69,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: subr_devsw.c,v 1.23 2008/12/29 17:41:18 pooka Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: subr_devsw.c,v 1.24 2009/01/20 18:20:48 drochner Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/conf.h>
|
||||
|
@ -97,8 +97,8 @@ extern struct devsw_conv *devsw_conv, devsw_conv0[];
|
|||
extern const int sys_bdevsws, sys_cdevsws;
|
||||
extern int max_bdevsws, max_cdevsws, max_devsw_convs;
|
||||
|
||||
static int bdevsw_attach(const struct bdevsw *, int *);
|
||||
static int cdevsw_attach(const struct cdevsw *, int *);
|
||||
static int bdevsw_attach(const struct bdevsw *, devmajor_t *);
|
||||
static int cdevsw_attach(const struct cdevsw *, devmajor_t *);
|
||||
static void devsw_detach_locked(const struct bdevsw *, const struct cdevsw *);
|
||||
|
||||
kmutex_t device_lock;
|
||||
|
@ -113,8 +113,9 @@ devsw_init(void)
|
|||
}
|
||||
|
||||
int
|
||||
devsw_attach(const char *devname, const struct bdevsw *bdev, int *bmajor,
|
||||
const struct cdevsw *cdev, int *cmajor)
|
||||
devsw_attach(const char *devname,
|
||||
const struct bdevsw *bdev, devmajor_t *bmajor,
|
||||
const struct cdevsw *cdev, devmajor_t *cmajor)
|
||||
{
|
||||
struct devsw_conv *conv;
|
||||
char *name;
|
||||
|
@ -214,10 +215,11 @@ devsw_attach(const char *devname, const struct bdevsw *bdev, int *bmajor,
|
|||
}
|
||||
|
||||
static int
|
||||
bdevsw_attach(const struct bdevsw *devsw, int *devmajor)
|
||||
bdevsw_attach(const struct bdevsw *devsw, devmajor_t *devmajor)
|
||||
{
|
||||
const struct bdevsw **newptr;
|
||||
int bmajor, i;
|
||||
devmajor_t bmajor;
|
||||
int i;
|
||||
|
||||
KASSERT(mutex_owned(&device_lock));
|
||||
|
||||
|
@ -263,10 +265,11 @@ bdevsw_attach(const struct bdevsw *devsw, int *devmajor)
|
|||
}
|
||||
|
||||
static int
|
||||
cdevsw_attach(const struct cdevsw *devsw, int *devmajor)
|
||||
cdevsw_attach(const struct cdevsw *devsw, devmajor_t *devmajor)
|
||||
{
|
||||
const struct cdevsw **newptr;
|
||||
int cmajor, i;
|
||||
devmajor_t cmajor;
|
||||
int i;
|
||||
|
||||
KASSERT(mutex_owned(&device_lock));
|
||||
|
||||
|
@ -351,7 +354,7 @@ devsw_detach(const struct bdevsw *bdev, const struct cdevsw *cdev)
|
|||
const struct bdevsw *
|
||||
bdevsw_lookup(dev_t dev)
|
||||
{
|
||||
int bmajor;
|
||||
devmajor_t bmajor;
|
||||
|
||||
if (dev == NODEV)
|
||||
return (NULL);
|
||||
|
@ -370,7 +373,7 @@ bdevsw_lookup(dev_t dev)
|
|||
const struct cdevsw *
|
||||
cdevsw_lookup(dev_t dev)
|
||||
{
|
||||
int cmajor;
|
||||
devmajor_t cmajor;
|
||||
|
||||
if (dev == NODEV)
|
||||
return (NULL);
|
||||
|
@ -387,17 +390,17 @@ cdevsw_lookup(dev_t dev)
|
|||
* => Caller must ensure that the device is not detached, and therefore
|
||||
* that the returned major is still valid when dereferenced.
|
||||
*/
|
||||
int
|
||||
devmajor_t
|
||||
bdevsw_lookup_major(const struct bdevsw *bdev)
|
||||
{
|
||||
int bmajor;
|
||||
devmajor_t bmajor;
|
||||
|
||||
for (bmajor = 0 ; bmajor < max_bdevsws ; bmajor++) {
|
||||
if (bdevsw[bmajor] == bdev)
|
||||
return (bmajor);
|
||||
}
|
||||
|
||||
return (-1);
|
||||
return (NODEVMAJOR);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -406,17 +409,17 @@ bdevsw_lookup_major(const struct bdevsw *bdev)
|
|||
* => Caller must ensure that the device is not detached, and therefore
|
||||
* that the returned major is still valid when dereferenced.
|
||||
*/
|
||||
int
|
||||
devmajor_t
|
||||
cdevsw_lookup_major(const struct cdevsw *cdev)
|
||||
{
|
||||
int cmajor;
|
||||
devmajor_t cmajor;
|
||||
|
||||
for (cmajor = 0 ; cmajor < max_cdevsws ; cmajor++) {
|
||||
if (cdevsw[cmajor] == cdev)
|
||||
return (cmajor);
|
||||
}
|
||||
|
||||
return (-1);
|
||||
return (NODEVMAJOR);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -426,10 +429,11 @@ cdevsw_lookup_major(const struct cdevsw *cdev)
|
|||
* that the name pointer is still valid when dereferenced.
|
||||
*/
|
||||
const char *
|
||||
devsw_blk2name(int bmajor)
|
||||
devsw_blk2name(devmajor_t bmajor)
|
||||
{
|
||||
const char *name;
|
||||
int cmajor, i;
|
||||
devmajor_t cmajor;
|
||||
int i;
|
||||
|
||||
name = NULL;
|
||||
cmajor = -1;
|
||||
|
@ -458,14 +462,15 @@ devsw_blk2name(int bmajor)
|
|||
* => Caller must ensure that the device is not detached, and therefore
|
||||
* that the major number is still valid when dereferenced.
|
||||
*/
|
||||
int
|
||||
devmajor_t
|
||||
devsw_name2blk(const char *name, char *devname, size_t devnamelen)
|
||||
{
|
||||
struct devsw_conv *conv;
|
||||
int bmajor, i;
|
||||
devmajor_t bmajor;
|
||||
int i;
|
||||
|
||||
if (name == NULL)
|
||||
return (-1);
|
||||
return (NODEVMAJOR);
|
||||
|
||||
mutex_enter(&device_lock);
|
||||
for (i = 0 ; i < max_devsw_convs ; i++) {
|
||||
|
@ -496,7 +501,7 @@ devsw_name2blk(const char *name, char *devname, size_t devnamelen)
|
|||
}
|
||||
|
||||
mutex_exit(&device_lock);
|
||||
return (-1);
|
||||
return (NODEVMAJOR);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -505,14 +510,15 @@ devsw_name2blk(const char *name, char *devname, size_t devnamelen)
|
|||
* => Caller must ensure that the device is not detached, and therefore
|
||||
* that the major number is still valid when dereferenced.
|
||||
*/
|
||||
int
|
||||
devmajor_t
|
||||
devsw_name2chr(const char *name, char *devname, size_t devnamelen)
|
||||
{
|
||||
struct devsw_conv *conv;
|
||||
int cmajor, i;
|
||||
devmajor_t cmajor;
|
||||
int i;
|
||||
|
||||
if (name == NULL)
|
||||
return (-1);
|
||||
return (NODEVMAJOR);
|
||||
|
||||
mutex_enter(&device_lock);
|
||||
for (i = 0 ; i < max_devsw_convs ; i++) {
|
||||
|
@ -543,7 +549,7 @@ devsw_name2chr(const char *name, char *devname, size_t devnamelen)
|
|||
}
|
||||
|
||||
mutex_exit(&device_lock);
|
||||
return (-1);
|
||||
return (NODEVMAJOR);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -555,11 +561,12 @@ devsw_name2chr(const char *name, char *devname, size_t devnamelen)
|
|||
dev_t
|
||||
devsw_chr2blk(dev_t cdev)
|
||||
{
|
||||
int bmajor, cmajor, i;
|
||||
devmajor_t bmajor, cmajor;
|
||||
int i;
|
||||
dev_t rv;
|
||||
|
||||
cmajor = major(cdev);
|
||||
bmajor = -1;
|
||||
bmajor = NODEVMAJOR;
|
||||
rv = NODEV;
|
||||
|
||||
mutex_enter(&device_lock);
|
||||
|
@ -589,11 +596,12 @@ devsw_chr2blk(dev_t cdev)
|
|||
dev_t
|
||||
devsw_blk2chr(dev_t bdev)
|
||||
{
|
||||
int bmajor, cmajor, i;
|
||||
devmajor_t bmajor, cmajor;
|
||||
int i;
|
||||
dev_t rv;
|
||||
|
||||
bmajor = major(bdev);
|
||||
cmajor = -1;
|
||||
cmajor = NODEVMAJOR;
|
||||
rv = NODEV;
|
||||
|
||||
mutex_enter(&device_lock);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: conf.h,v 1.132 2008/12/29 17:41:19 pooka Exp $ */
|
||||
/* $NetBSD: conf.h,v 1.133 2009/01/20 18:20:48 drochner Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
|
@ -97,13 +97,13 @@ struct cdevsw {
|
|||
#include <sys/mutex.h>
|
||||
extern kmutex_t device_lock;
|
||||
|
||||
int devsw_attach(const char *, const struct bdevsw *, int *,
|
||||
const struct cdevsw *, int *);
|
||||
int devsw_attach(const char *, const struct bdevsw *, devmajor_t *,
|
||||
const struct cdevsw *, devmajor_t *);
|
||||
int devsw_detach(const struct bdevsw *, const struct cdevsw *);
|
||||
const struct bdevsw *bdevsw_lookup(dev_t);
|
||||
const struct cdevsw *cdevsw_lookup(dev_t);
|
||||
int bdevsw_lookup_major(const struct bdevsw *);
|
||||
int cdevsw_lookup_major(const struct cdevsw *);
|
||||
devmajor_t bdevsw_lookup_major(const struct bdevsw *);
|
||||
devmajor_t cdevsw_lookup_major(const struct cdevsw *);
|
||||
|
||||
#define dev_type_open(n) int n (dev_t, int, int, struct lwp *)
|
||||
#define dev_type_close(n) int n (dev_t, int, int, struct lwp *)
|
||||
|
@ -231,15 +231,15 @@ int seltrue_kqfilter(dev_t, struct knote *);
|
|||
|
||||
struct devsw_conv {
|
||||
const char *d_name;
|
||||
int d_bmajor;
|
||||
int d_cmajor;
|
||||
devmajor_t d_bmajor;
|
||||
devmajor_t d_cmajor;
|
||||
};
|
||||
|
||||
#ifdef _KERNEL
|
||||
void devsw_init(void);
|
||||
const char *devsw_blk2name(int);
|
||||
int devsw_name2blk(const char *, char *, size_t);
|
||||
int devsw_name2chr(const char *, char *, size_t);
|
||||
const char *devsw_blk2name(devmajor_t);
|
||||
devmajor_t devsw_name2blk(const char *, char *, size_t);
|
||||
devmajor_t devsw_name2chr(const char *, char *, size_t);
|
||||
dev_t devsw_chr2blk(dev_t);
|
||||
dev_t devsw_blk2chr(dev_t);
|
||||
#endif /* _KERNEL */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: sysctl.h,v 1.182 2009/01/19 19:39:41 christos Exp $ */
|
||||
/* $NetBSD: sysctl.h,v 1.183 2009/01/20 18:20:48 drochner Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1993
|
||||
|
@ -716,8 +716,8 @@ struct kinfo_lwp {
|
|||
*/
|
||||
|
||||
struct kinfo_drivers {
|
||||
int32_t d_cmajor;
|
||||
int32_t d_bmajor;
|
||||
devmajor_t d_cmajor;
|
||||
devmajor_t d_bmajor;
|
||||
char d_name[24];
|
||||
};
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: types.h,v 1.82 2009/01/11 02:45:56 christos Exp $ */
|
||||
/* $NetBSD: types.h,v 1.83 2009/01/20 18:20:48 drochner Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1982, 1986, 1991, 1993, 1994
|
||||
|
@ -256,12 +256,16 @@ __END_DECLS
|
|||
|
||||
#if defined(_NETBSD_SOURCE)
|
||||
/* Major, minor numbers, dev_t's. */
|
||||
#define major(x) ((dev_t)((((x) & 0x000fff00LL) >> 8)))
|
||||
#define minor(x) ((dev_t)((((x) & 0xfff00000LL) >> 12) | \
|
||||
(((x) & 0x000000ffLL) >> 0)))
|
||||
#define makedev(x,y) ((dev_t)((((x) << 8) & 0x000fff00LL) | \
|
||||
(((y) << 12) & 0xfff00000LL) | \
|
||||
(((y) << 0) & 0x000000ffLL)))
|
||||
typedef int32_t __devmajor_t, __devminor_t;
|
||||
#define devmajor_t __devmajor_t
|
||||
#define devminor_t __devminor_t
|
||||
#define NODEVMAJOR (-1)
|
||||
#define major(x) ((devmajor_t)(((uint32_t)(x) & 0x000fff00) >> 8))
|
||||
#define minor(x) ((devminor_t)((((uint32_t)(x) & 0xfff00000) >> 12) | \
|
||||
(((uint32_t)(x) & 0x000000ff) >> 0)))
|
||||
#define makedev(x,y) ((dev_t)((((x) << 8) & 0x000fff00) | \
|
||||
(((y) << 12) & 0xfff00000) | \
|
||||
(((y) << 0) & 0x000000ff)))
|
||||
#endif
|
||||
|
||||
#ifdef _BSD_CLOCK_T_
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: defs.h,v 1.26 2008/12/28 01:23:46 christos Exp $ */
|
||||
/* $NetBSD: defs.h,v 1.27 2009/01/20 18:20:48 drochner Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -71,14 +71,20 @@
|
|||
|
||||
#ifdef MAKE_BOOTSTRAP
|
||||
#undef dev_t
|
||||
#undef devmajor_t
|
||||
#undef devminor_t
|
||||
#undef NODEV
|
||||
#undef NODEVMAJOR
|
||||
#undef major
|
||||
#undef minor
|
||||
#undef makedev
|
||||
#define dev_t int /* XXX: assumes int is 32 bits */
|
||||
#define dev_t unsigned int /* XXX: assumes int is 32 bits */
|
||||
#define NODEV ((dev_t)-1)
|
||||
#define major(x) ((int)((((x) & 0x000fff00) >> 8)))
|
||||
#define minor(x) ((int)((((x) & 0xfff00000) >> 12) | \
|
||||
#define devmajor_t int
|
||||
#define devminor_t int
|
||||
#define NODEVMAJOR (-1)
|
||||
#define major(x) ((devmajor_t)((((x) & 0x000fff00) >> 8)))
|
||||
#define minor(x) ((devminor_t)((((x) & 0xfff00000) >> 12) | \
|
||||
(((x) & 0x000000ff) >> 0)))
|
||||
#define makedev(x,y) ((dev_t)((((x) << 8) & 0x000fff00) | \
|
||||
(((y) << 12) & 0xfff00000) | \
|
||||
|
@ -200,7 +206,7 @@ struct devbase {
|
|||
TAILQ_ENTRY(devbase) d_next;
|
||||
int d_isdef; /* set once properly defined */
|
||||
int d_ispseudo; /* is a pseudo-device */
|
||||
dev_t d_major; /* used for "root on sd0", e.g. */
|
||||
devmajor_t d_major; /* used for "root on sd0", e.g. */
|
||||
struct nvlist *d_attrs; /* attributes, if any */
|
||||
int d_umax; /* highest unit number + 1 */
|
||||
struct devi *d_ihead; /* first instance, if any */
|
||||
|
@ -361,8 +367,8 @@ struct devm {
|
|||
const char *dm_srcfile; /* the name of the "majors" file */
|
||||
u_short dm_srcline; /* the line number */
|
||||
const char *dm_name; /* [bc]devsw name */
|
||||
int dm_cmajor; /* character major */
|
||||
int dm_bmajor; /* block major */
|
||||
devmajor_t dm_cmajor; /* character major */
|
||||
devmajor_t dm_bmajor; /* block major */
|
||||
struct nvlist *dm_opts; /* options */
|
||||
};
|
||||
|
||||
|
@ -425,8 +431,8 @@ TAILQ_HEAD(, devm) alldevms; /* list of all device-majors */
|
|||
TAILQ_HEAD(, pspec) allpspecs; /* list of all parent specs */
|
||||
int ndevi; /* number of devi's (before packing) */
|
||||
int npspecs; /* number of parent specs */
|
||||
int maxbdevm; /* max number of block major */
|
||||
int maxcdevm; /* max number of character major */
|
||||
devmajor_t maxbdevm; /* max number of block major */
|
||||
devmajor_t maxcdevm; /* max number of character major */
|
||||
int do_devsw; /* 0 if pre-devsw config */
|
||||
int oktopackage; /* 0 before setmachine() */
|
||||
int devilevel; /* used for devi->i_level */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: files.c,v 1.8 2008/12/28 01:23:46 christos Exp $ */
|
||||
/* $NetBSD: files.c,v 1.9 2009/01/20 18:20:48 drochner Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -382,7 +382,7 @@ fixdevsw(void)
|
|||
!expr_eval(dm->dm_opts, fixsel, NULL))
|
||||
continue;
|
||||
|
||||
if (dm->dm_cmajor != -1) {
|
||||
if (dm->dm_cmajor != NODEVMAJOR) {
|
||||
if (ht_lookup(cdevmtab, intern(dm->dm_name)) != NULL) {
|
||||
cfgxerror(dm->dm_srcfile, dm->dm_srcline,
|
||||
"device-major of character device '%s' "
|
||||
|
@ -404,7 +404,7 @@ fixdevsw(void)
|
|||
dm->dm_name, dm->dm_cmajor);
|
||||
}
|
||||
}
|
||||
if (dm->dm_bmajor != -1) {
|
||||
if (dm->dm_bmajor != NODEVMAJOR) {
|
||||
if (ht_lookup(bdevmtab, intern(dm->dm_name)) != NULL) {
|
||||
cfgxerror(dm->dm_srcfile, dm->dm_srcline,
|
||||
"device-major of block device '%s' "
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: mkdevsw.c,v 1.6 2008/04/28 20:24:12 martin Exp $ */
|
||||
/* $NetBSD: mkdevsw.c,v 1.7 2009/01/20 18:20:48 drochner Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2002 The NetBSD Foundation, Inc.
|
||||
|
@ -96,7 +96,7 @@ emitdevm(FILE *fp)
|
|||
{
|
||||
struct devm *dm;
|
||||
char mstr[16];
|
||||
int i;
|
||||
devmajor_t i;
|
||||
|
||||
fputs("\n/* device switch table for block device */\n", fp);
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: mkioconf.c,v 1.12 2009/01/16 09:43:41 uebayasi Exp $ */
|
||||
/* $NetBSD: mkioconf.c,v 1.13 2009/01/20 18:20:48 drochner Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -486,11 +486,11 @@ emitname2blk(FILE *fp)
|
|||
fprintf(fp, "struct devnametobdevmaj dev_name2blk[] = {\n");
|
||||
|
||||
TAILQ_FOREACH(dev, &allbases, d_next) {
|
||||
if (dev->d_major == NODEV)
|
||||
if (dev->d_major == NODEVMAJOR)
|
||||
continue;
|
||||
|
||||
fprintf(fp, "\t{ \"%s\", %lld },\n",
|
||||
dev->d_name, (long long)dev->d_major);
|
||||
fprintf(fp, "\t{ \"%s\", %d },\n",
|
||||
dev->d_name, dev->d_major);
|
||||
}
|
||||
fprintf(fp, "\t{ NULL, 0 }\n};\n");
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: mkswap.c,v 1.6 2008/12/28 01:23:46 christos Exp $ */
|
||||
/* $NetBSD: mkswap.c,v 1.7 2009/01/20 18:20:48 drochner Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -79,8 +79,8 @@ mkdevstr(dev_t d)
|
|||
if (d == NODEV)
|
||||
(void)snprintf(buf, sizeof(buf), "NODEV");
|
||||
else
|
||||
(void)snprintf(buf, sizeof(buf), "makedev(%" PRIi64 ", %"
|
||||
PRIi64 ")", (int64_t)major(d), (int64_t)minor(d));
|
||||
(void)snprintf(buf, sizeof(buf), "makedev(%d, %d)",
|
||||
major(d), minor(d));
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: sem.c,v 1.31 2008/12/28 01:23:46 christos Exp $ */
|
||||
/* $NetBSD: sem.c,v 1.32 2009/01/20 18:20:48 drochner Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -83,9 +83,9 @@ static char *extend(char *, const char *);
|
|||
static int split(const char *, size_t, char *, size_t, int *);
|
||||
static void selectbase(struct devbase *, struct deva *);
|
||||
static const char **fixloc(const char *, struct attr *, struct nvlist *);
|
||||
static const char *makedevstr(dev_t, dev_t);
|
||||
static const char *major2name(int);
|
||||
static dev_t dev2major(struct devbase *);
|
||||
static const char *makedevstr(devmajor_t, devminor_t);
|
||||
static const char *major2name(devmajor_t);
|
||||
static devmajor_t dev2major(struct devbase *);
|
||||
|
||||
extern const char *yyfile;
|
||||
extern int vflag;
|
||||
|
@ -436,7 +436,7 @@ getdevbase(const char *name)
|
|||
dev = ecalloc(1, sizeof *dev);
|
||||
dev->d_name = name;
|
||||
dev->d_isdef = 0;
|
||||
dev->d_major = NODEV;
|
||||
dev->d_major = NODEVMAJOR;
|
||||
dev->d_attrs = NULL;
|
||||
dev->d_ihead = NULL;
|
||||
dev->d_ipp = &dev->d_ihead;
|
||||
|
@ -631,18 +631,18 @@ expandattr(struct attr *a, void (*callback)(struct attr *))
|
|||
* as a root/dumps "on" device in a configuration.
|
||||
*/
|
||||
void
|
||||
setmajor(struct devbase *d, int n)
|
||||
setmajor(struct devbase *d, devmajor_t n)
|
||||
{
|
||||
|
||||
if (d != &errdev && d->d_major != NODEV)
|
||||
cfgerror("device `%s' is already major %lld",
|
||||
d->d_name, (long long)d->d_major);
|
||||
if (d != &errdev && d->d_major != NODEVMAJOR)
|
||||
cfgerror("device `%s' is already major %d",
|
||||
d->d_name, d->d_major);
|
||||
else
|
||||
d->d_major = n;
|
||||
}
|
||||
|
||||
const char *
|
||||
major2name(int maj)
|
||||
major2name(devmajor_t maj)
|
||||
{
|
||||
struct devbase *dev;
|
||||
struct devm *dm;
|
||||
|
@ -661,7 +661,7 @@ major2name(int maj)
|
|||
return (NULL);
|
||||
}
|
||||
|
||||
dev_t
|
||||
devmajor_t
|
||||
dev2major(struct devbase *dev)
|
||||
{
|
||||
struct devm *dm;
|
||||
|
@ -673,26 +673,24 @@ dev2major(struct devbase *dev)
|
|||
if (strcmp(dm->dm_name, dev->d_name) == 0)
|
||||
return (dm->dm_bmajor);
|
||||
}
|
||||
return (NODEV);
|
||||
return (NODEVMAJOR);
|
||||
}
|
||||
|
||||
/*
|
||||
* Make a string description of the device at maj/min.
|
||||
*/
|
||||
static const char *
|
||||
makedevstr(dev_t maj, dev_t min)
|
||||
makedevstr(devmajor_t maj, devminor_t min)
|
||||
{
|
||||
const char *devicename;
|
||||
char buf[32];
|
||||
|
||||
devicename = major2name(maj);
|
||||
if (devicename == NULL)
|
||||
(void)snprintf(buf, sizeof(buf), "<%lld/%lld>",
|
||||
(long long)maj, (long long)min);
|
||||
(void)snprintf(buf, sizeof(buf), "<%d/%d>", maj, min);
|
||||
else
|
||||
(void)snprintf(buf, sizeof(buf), "%s%lld%c", devicename,
|
||||
(long long)min / maxpartitions,
|
||||
(char)(min % maxpartitions) + 'a');
|
||||
(void)snprintf(buf, sizeof(buf), "%s%d%c", devicename,
|
||||
min / maxpartitions, (min % maxpartitions) + 'a');
|
||||
|
||||
return (intern(buf));
|
||||
}
|
||||
|
@ -709,7 +707,8 @@ resolve(struct nvlist **nvp, const char *name, const char *what,
|
|||
struct nvlist *nv;
|
||||
struct devbase *dev;
|
||||
const char *cp;
|
||||
dev_t maj, min;
|
||||
devmajor_t maj;
|
||||
devminor_t min;
|
||||
int i, l;
|
||||
int unit;
|
||||
char buf[NAMESIZE];
|
||||
|
@ -1464,22 +1463,23 @@ delpseudo(const char *name)
|
|||
}
|
||||
|
||||
void
|
||||
adddevm(const char *name, int cmajor, int bmajor, struct nvlist *options)
|
||||
adddevm(const char *name, devmajor_t cmajor, devmajor_t bmajor,
|
||||
struct nvlist *options)
|
||||
{
|
||||
struct devm *dm;
|
||||
|
||||
if (cmajor < -1 || cmajor >= 4096) {
|
||||
if (cmajor != NODEVMAJOR && (cmajor < 0 || cmajor >= 4096)) {
|
||||
cfgerror("character major %d is invalid", cmajor);
|
||||
nvfreel(options);
|
||||
return;
|
||||
}
|
||||
|
||||
if (bmajor < -1 || bmajor >= 4096) {
|
||||
if (bmajor != NODEVMAJOR && (bmajor < 0 || bmajor >= 4096)) {
|
||||
cfgerror("block major %d is invalid", bmajor);
|
||||
nvfreel(options);
|
||||
return;
|
||||
}
|
||||
if (cmajor == -1 && bmajor == -1) {
|
||||
if (cmajor == NODEVMAJOR && bmajor == NODEVMAJOR) {
|
||||
cfgerror("both character/block majors are not specified");
|
||||
nvfreel(options);
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue