diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2003-05-14 00:20:39 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2003-05-14 00:20:39 +0000 |
commit | cafc243ebae5558778638ed6f6c70c9c9bbd86f4 (patch) | |
tree | 8cbf420519d09c3da1122dfc01777d9d3a734649 /sys/kern | |
parent | b4dd55d103207347b453f69c731250bd549e6b5b (diff) |
add {b,c}devsw_lookup convenience functions.
move chrtoblk and blktochr into MI code.
tested on several archs and ok deraadt@
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/subr_xxx.c | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/sys/kern/subr_xxx.c b/sys/kern/subr_xxx.c index ee6115e5461..1c243610ff0 100644 --- a/sys/kern/subr_xxx.c +++ b/sys/kern/subr_xxx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_xxx.c,v 1.6 1997/11/06 05:58:20 csapuntz Exp $ */ +/* $OpenBSD: subr_xxx.c,v 1.7 2003/05/14 00:20:38 tedu Exp $ */ /* $NetBSD: subr_xxx.c,v 1.10 1996/02/04 02:16:51 christos Exp $ */ /* @@ -42,6 +42,8 @@ */ #include <sys/param.h> #include <sys/systm.h> +#include <sys/device.h> +#include <sys/conf.h> #include <machine/cpu.h> @@ -111,3 +113,50 @@ nullop(v) return (0); } + +struct bdevsw * +bdevsw_lookup(dev_t dev) +{ + return (&bdevsw[major(dev)]); +} + +struct cdevsw * +cdevsw_lookup(dev_t dev) +{ + return (&cdevsw[major(dev)]); +} + +/* + * Convert a character device number to a block device number. + */ +dev_t +chrtoblk(dev) + dev_t dev; +{ + int blkmaj; + + if (major(dev) >= nchrdev || major(dev) >= nchrtoblktbl) + return (NODEV); + blkmaj = chrtoblktbl[major(dev)]; + if (blkmaj == NODEV) + return (NODEV); + return (makedev(blkmaj, minor(dev))); +} + +/* + * Convert a block device number to a character device number. + */ +dev_t +blktochr(dev) + dev_t dev; +{ + int blkmaj = major(dev); + int i; + + if (blkmaj >= nblkdev) + return (NODEV); + for (i = 0; i < nchrtoblktbl; i++) + if (blkmaj == chrtoblktbl[i]) + return (makedev(i, minor(dev))); + return (NODEV); +} |