From 3a85fd262cf759135879a7dae35426b1ac5e13f5 Mon Sep 17 00:00:00 2001 From: Poul-Henning Kamp Date: Sat, 29 Jan 2005 15:07:13 +0000 Subject: [PATCH] Add MAXMINOR #define, we should have had this long time ago. Add minor2unit() in addition to dev2unit() and unit2minor(). If it wasn't such a hazzle we should redefine minor numbers in the kernel without the gap for the major number, but it's not worth the bother (yet). --- sys/kern/kern_conf.c | 12 +++++++++--- sys/sys/conf.h | 3 +++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/sys/kern/kern_conf.c b/sys/kern/kern_conf.c index d8083816a843..07ddc91ca44e 100644 --- a/sys/kern/kern_conf.c +++ b/sys/kern/kern_conf.c @@ -258,12 +258,18 @@ minor(struct cdev *x) int dev2unit(struct cdev *x) { - int i; if (x == NULL) return NODEV; - i = minor(x); - return ((i & 0xff) | (i >> 8)); + return (minor2unit(minor(x)); +} + +int +minor2unit(int _minor) +{ + + KASSERT((_minor & 0xff00) == 0, ("Illegal minor %x", _minor)); + return ((_minor & 0xff) | (_minor >> 8)); } int diff --git a/sys/sys/conf.h b/sys/sys/conf.h index d7ecddc3b84b..143faf5ef556 100644 --- a/sys/sys/conf.h +++ b/sys/sys/conf.h @@ -219,6 +219,8 @@ struct cdevsw { #define NUMCDEVSW 256 +#define MAXMINOR 0xffff00ff + /* * XXX: do not use MAJOR_AUTO unless you have no choice. In general drivers * should just not initialize .d_maj and that will DTRT. @@ -266,6 +268,7 @@ int dev2unit(struct cdev *_dev); void dev_lock(void); void dev_unlock(void); int unit2minor(int _unit); +int minor2unit(int _minor); void setconf(void); void devfs_create(struct cdev *dev);