tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
introducing devmajor_t/devminor_t
Here are patches which make major()/minor() return a
32-bit value again, which avoids 64-bit arithmetics
where major and minor numbers are used as array
indices. This would also make sure that device
unit numbers in drivers are still plain integers,
so no PRI64s are needed to print out device instances.
I've introduced new type names for this. This doesn't
make a difference technically but serves as a kind
of comment. (Some OSes have this too, or major_t/minor_t,
so the idea is not that exotic.)
What do you think?
best regards
Matthias
-------------------------------------------------------------------
-------------------------------------------------------------------
Forschungszentrum Juelich GmbH
52425 Juelich
Sitz der Gesellschaft: Juelich
Eingetragen im Handelsregister des Amtsgerichts Dueren Nr. HR B 3498
Vorsitzende des Aufsichtsrats: MinDir'in Baerbel Brumme-Bothe
Geschaeftsfuehrung: Prof. Dr. Achim Bachem (Vorsitzender),
Dr. Ulrich Krafft (stellv. Vorsitzender), Prof. Dr. Harald Bolt,
Dr. Sebastian M. Schmidt
-------------------------------------------------------------------
-------------------------------------------------------------------
#
# old_revision [635cc6d71ec33a7e5c2bd9fb2c7f00dd713d94d0]
#
# patch "include/stdlib.h"
# from [365fc05de7c61f11df444f4db7eda38f0dc67070]
# to [e44ce25269d7b06494819eb80b0f0a56e6ffdd48]
#
# patch "lib/libc/compat/include/stdlib.h"
# from [204af6b1c0dcd79268b72f6efcabe0b72d902183]
# to [3242faf54f98ca933060fbafebe4e3f54d9e3a51]
#
# patch "lib/libc/gen/devname.c"
# from [bb75cb1087226e4c6ad960a306ab306440508cd6]
# to [5b221cae66b22e50daf2d8b786f7191fdd59ba0d]
#
# patch "lib/libc/gen/getdevmajor.c"
# from [8d741a93bb4ddb0f918f7da5ef4c54b8c9d10141]
# to [0c4e97f74e067d924f7aedd5ec379807c5e8d04f]
#
# patch "sys/dev/drm/drm_drv.c"
# from [ab4a9f3002c65e5f69fa4c8426d4bcd26f09e2d1]
# to [836390e88fd8e0a1a288a20604f04f04a2b255c7]
#
# patch "sys/dev/pud/pud.c"
# from [328c391308b125e7120a8232288d80eb3abad88d]
# to [4d02d5dafa17888f9336fc5a5f32411232c1474f]
#
# patch "sys/dev/putter/putter.c"
# from [640715f2db39c4efe1ccfbeaa7f69db4f0a8d455]
# to [7f230271b7e3ae50d27e888a49993c1e7ad01e82]
#
# patch "sys/dev/usb/ucom.c"
# from [ed2ce8fed1a40f5d068025bcd8a2fe6634bc6f03]
# to [827550bbb899ce84db50806d792097ceb29acdbd]
#
# patch "sys/dev/usb/ucycom.c"
# from [ae758d0fb86610a27f815ac7660824e4be426a61]
# to [118fb4869c9fc701ecc672a87b712fc60d62bfef]
#
# patch "sys/dev/usb/ugen.c"
# from [681c29994b932a3691cb25e0da1ef01189266444]
# to [4e81dead63619fdfad20cf49053c8a95efe6d18b]
#
# patch "sys/dev/usb/urio.c"
# from [6838dc2ecc390226c7201924c43257d8f534cd89]
# to [ced9d9850a06da2f67aa5523fa611d589b7cfc37]
#
# patch "sys/kern/subr_devsw.c"
# from [9677a16d771d101b35ecfd6908e9ffca244237c6]
# to [1e5fd4dbf569637724a95ac43a29fa662f29a4a8]
#
# patch "sys/sys/conf.h"
# from [a23aa1ca44d62ecc4ee2cb12f21e52920ec1f972]
# to [527f2076aff373905d198d383bfb3b0fdc1cfbd9]
#
# patch "sys/sys/sysctl.h"
# from [98610d0ab36fe6b91b62a26b498f7a96fd124648]
# to [1f8a7207c09c415cc82abb27b1bf595cbf3f7a43]
#
# patch "sys/sys/types.h"
# from [05934fc57231506207fdf963ff3e0454625f56c1]
# to [61b69426a8ad5db20e9893acc1ff5be9a1d8e0f3]
#
# patch "usr.bin/config/defs.h"
# from [d65107381fc97d063593690ca9c26bd8cbd42571]
# to [a5a86f38c7ddf537e830d2dff63d130a16e5e8b2]
#
# patch "usr.bin/config/files.c"
# from [7e7a16953cff122315094519f65fd6250195dacf]
# to [7d489dfcd1a581bb494644816c1c50d4c01712a9]
#
# patch "usr.bin/config/mkdevsw.c"
# from [5eda55ccebd2f1ae8bd8e728841d25cd73f54bea]
# to [925b3718076f6bb396f794ba547284377d844d23]
#
# patch "usr.bin/config/mkioconf.c"
# from [51d692f3ce1b93b4cae2910abc1b22cd41e8de50]
# to [226587dfb11cd98940733e3ffc37c38493c16d5f]
#
# patch "usr.bin/config/mkswap.c"
# from [b4d3b66aac72a4de8496ba4a91cc1bb98bcafe15]
# to [7ca81471f557ae193e5728a3bacdc6688a9729cc]
#
# patch "usr.bin/config/sem.c"
# from [bb7e1740efeab2653f8007302d1bc9dd59d7f6ea]
# to [a0c71ff878f6b026aa8d8a90d12b23d58883287b]
#
============================================================
--- include/stdlib.h 365fc05de7c61f11df444f4db7eda38f0dc67070
+++ include/stdlib.h e44ce25269d7b06494819eb80b0f0a56e6ffdd48
@@ -281,7 +281,7 @@ int dehumanize_number(const char *, 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);
============================================================
--- lib/libc/compat/include/stdlib.h 204af6b1c0dcd79268b72f6efcabe0b72d902183
+++ lib/libc/compat/include/stdlib.h 3242faf54f98ca933060fbafebe4e3f54d9e3a51
@@ -41,7 +41,7 @@ int32_t getdevmajor(const char *, mode_
__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
============================================================
--- lib/libc/gen/devname.c bb75cb1087226e4c6ad960a306ab306440508cd6
+++ lib/libc/gen/devname.c 5b221cae66b22e50daf2d8b786f7191fdd59ba0d
@@ -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;
}
}
============================================================
--- lib/libc/gen/getdevmajor.c 8d741a93bb4ddb0f918f7da5ef4c54b8c9d10141
+++ lib/libc/gen/getdevmajor.c 0c4e97f74e067d924f7aedd5ec379807c5e8d04f
@@ -51,13 +51,13 @@ __weak_alias(getdevmajor,_getdevmajor)
__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;
============================================================
--- sys/dev/drm/drm_drv.c ab4a9f3002c65e5f69fa4c8426d4bcd26f09e2d1
+++ sys/dev/drm/drm_drv.c 836390e88fd8e0a1a288a20604f04f04a2b255c7
@@ -816,7 +816,7 @@ drm_modcmd(modcmd_t cmd, void *arg)
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:
============================================================
--- sys/dev/pud/pud.c 328c391308b125e7120a8232288d80eb3abad88d
+++ sys/dev/pud/pud.c 4d02d5dafa17888f9336fc5a5f32411232c1474f
@@ -175,7 +175,8 @@ pudconf_reg(struct pud_dev *pd, struct p
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 p
bmajor = cmajor;
} else {
bsw = NULL;
- bmajor = -1;
+ bmajor = NODEVMAJOR;
}
pcr->pm_devname[PUD_DEVNAME_MAX] = '\0';
============================================================
--- sys/dev/putter/putter.c 640715f2db39c4efe1ccfbeaa7f69db4f0a8d455
+++ sys/dev/putter/putter.c 7f230271b7e3ae50d27e888a49993c1e7ad01e82
@@ -619,7 +619,7 @@ putter_modcmd(modcmd_t cmd, void *arg)
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:
============================================================
--- sys/dev/usb/ucom.c ed2ce8fed1a40f5d068025bcd8a2fe6634bc6f03
+++ sys/dev/usb/ucom.c 827550bbb899ce84db50806d792097ceb29acdbd
@@ -496,7 +496,7 @@ ucomclose(dev_t dev, int flag, int mode,
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);
============================================================
--- sys/dev/usb/ucycom.c ae758d0fb86610a27f815ac7660824e4be426a61
+++ sys/dev/usb/ucycom.c 118fb4869c9fc701ecc672a87b712fc60d62bfef
@@ -306,7 +306,7 @@ ucycomopen(dev_t dev, int flag, int mode
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 mod
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);
============================================================
--- sys/dev/usb/ugen.c 681c29994b932a3691cb25e0da1ef01189266444
+++ sys/dev/usb/ugen.c 4e81dead63619fdfad20cf49053c8a95efe6d18b
@@ -503,7 +503,7 @@ ugenclose(dev_t dev, int flag, int mode,
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
============================================================
--- sys/dev/usb/urio.c 6838dc2ecc390226c7201924c43257d8f534cd89
+++ sys/dev/usb/urio.c ced9d9850a06da2f67aa5523fa611d589b7cfc37
@@ -308,7 +308,7 @@ urioopen(dev_t dev, int flag, int mode,
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
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, in
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, in
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);
============================================================
--- sys/kern/subr_devsw.c 9677a16d771d101b35ecfd6908e9ffca244237c6
+++ sys/kern/subr_devsw.c 1e5fd4dbf569637724a95ac43a29fa662f29a4a8
@@ -97,8 +97,8 @@ extern int max_bdevsws, max_cdevsws, max
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 @@ int
}
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 @@ static int
}
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 @@ static int
}
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 @@ bdevsw_lookup(dev_t dev)
const struct bdevsw *
bdevsw_lookup(dev_t dev)
{
- int bmajor;
+ devmajor_t bmajor;
if (dev == NODEV)
return (NULL);
@@ -370,7 +373,7 @@ cdevsw_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
* => 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 @@ const char *
* 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 *d
}
mutex_exit(&device_lock);
- return (-1);
+ return (NODEVMAJOR);
}
/*
@@ -505,14 +510,15 @@ devsw_name2blk(const char *name, char *d
* => 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 *d
}
mutex_exit(&device_lock);
- return (-1);
+ return (NODEVMAJOR);
}
/*
@@ -555,11 +561,12 @@ devsw_chr2blk(dev_t cdev)
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_blk2chr(dev_t bdev)
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);
============================================================
--- sys/sys/conf.h a23aa1ca44d62ecc4ee2cb12f21e52920ec1f972
+++ sys/sys/conf.h 527f2076aff373905d198d383bfb3b0fdc1cfbd9
@@ -97,13 +97,13 @@ extern kmutex_t device_lock;
#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 @@ struct devsw_conv {
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 */
============================================================
--- sys/sys/sysctl.h 98610d0ab36fe6b91b62a26b498f7a96fd124648
+++ sys/sys/sysctl.h 1f8a7207c09c415cc82abb27b1bf595cbf3f7a43
@@ -713,8 +713,8 @@ struct kinfo_drivers {
*/
struct kinfo_drivers {
- int32_t d_cmajor;
- int32_t d_bmajor;
+ devmajor_t d_cmajor;
+ devmajor_t d_bmajor;
char d_name[24];
};
============================================================
--- sys/sys/types.h 05934fc57231506207fdf963ff3e0454625f56c1
+++ sys/sys/types.h 61b69426a8ad5db20e9893acc1ff5be9a1d8e0f3
@@ -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_
============================================================
--- usr.bin/config/defs.h d65107381fc97d063593690ca9c26bd8cbd42571
+++ usr.bin/config/defs.h a5a86f38c7ddf537e830d2dff63d130a16e5e8b2
@@ -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 @@ int npspecs; /* number of parent
specs
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 */
============================================================
--- usr.bin/config/files.c 7e7a16953cff122315094519f65fd6250195dacf
+++ usr.bin/config/files.c 7d489dfcd1a581bb494644816c1c50d4c01712a9
@@ -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' "
============================================================
--- usr.bin/config/mkdevsw.c 5eda55ccebd2f1ae8bd8e728841d25cd73f54bea
+++ usr.bin/config/mkdevsw.c 925b3718076f6bb396f794ba547284377d844d23
@@ -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);
============================================================
--- usr.bin/config/mkioconf.c 51d692f3ce1b93b4cae2910abc1b22cd41e8de50
+++ usr.bin/config/mkioconf.c 226587dfb11cd98940733e3ffc37c38493c16d5f
@@ -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");
}
============================================================
--- usr.bin/config/mkswap.c b4d3b66aac72a4de8496ba4a91cc1bb98bcafe15
+++ usr.bin/config/mkswap.c 7ca81471f557ae193e5728a3bacdc6688a9729cc
@@ -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;
}
============================================================
--- usr.bin/config/sem.c bb7e1740efeab2653f8007302d1bc9dd59d7f6ea
+++ usr.bin/config/sem.c a0c71ff878f6b026aa8d8a90d12b23d58883287b
@@ -83,9 +83,9 @@ static const char **fixloc(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 @@ void
* 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
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 @@ void
}
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;
Home |
Main Index |
Thread Index |
Old Index