From bfbb9ce67005673c7b7c8b2267024adef44f7d1d Mon Sep 17 00:00:00 2001 From: Poul-Henning Kamp Date: Tue, 11 May 1999 19:55:07 +0000 Subject: Divorce "dev_t" from the "major|minor" bitmap, which is now called udev_t in the kernel but still called dev_t in userland. Provide functions to manipulate both types: major() umajor() minor() uminor() makedev() umakedev() dev2udev() udev2dev() For now they're functions, they will become in-line functions after one of the next two steps in this process. Return major/minor/makedev to macro-hood for userland. Register a name in cdevsw[] for the "filedescriptor" driver. In the kernel the udev_t appears in places where we have the major/minor number combination, (ie: a potential device: we may not have the driver nor the device), like in inodes, vattr, cdevsw registration and so on, whereas the dev_t appears where we carry around a reference to a actual device. In the future the cdevsw and the aliased-from vnode will be hung directly from the dev_t, along with up to two softc pointers for the device driver and a few houskeeping bits. This will essentially replace the current "alias" check code (same buck, bigger bang). A little stunt has been provided to try to catch places where the wrong type is being used (dev_t vs udev_t), if you see something not working, #undef DEVT_FASCIST in kern/kern_conf.c and see if it makes a difference. If it does, please try to track it down (many hands make light work) or at least try to reproduce it as simply as possible, and describe how to do that. Without DEVT_FASCIST I belive this patch is a no-op. Stylistic/posixoid comments about the userland view of the files welcome now, from userland they now contain the end result. Next planned step: make all dev_t's refer to the same devsw[] which means convert BLK's to CHR's at the perimeter of the vnodes and other places where they enter the game (bootdev, mknod, sysctl). --- sys/kern/kern_conf.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 2 deletions(-) (limited to 'sys/kern/kern_conf.c') diff --git a/sys/kern/kern_conf.c b/sys/kern/kern_conf.c index c20e2aa87214..e6aa7389ca9a 100644 --- a/sys/kern/kern_conf.c +++ b/sys/kern/kern_conf.c @@ -30,7 +30,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: kern_conf.c,v 1.35 1999/05/09 08:18:12 phk Exp $ + * $Id: kern_conf.c,v 1.36 1999/05/09 13:00:46 phk Exp $ */ #include @@ -70,7 +70,15 @@ cdevsw_add(dev_t *descrip, struct cdevsw *newentry, struct cdevsw **oldentry) { - int i ; + int i; + static int setup; + + if (!setup) { + for (i = 0; i < NUMCDEV; i++) + if (!bmaj2cmaj[i]) + bmaj2cmaj[i] = 254; + setup++; + } if ( *descrip == NODEV) { /* auto (0 is valid) */ /* @@ -161,3 +169,66 @@ devsw_module_handler(module_t mod, int what, void* arg) else return 0; } + +/* + * dev_t and u_dev_t primitives + */ + +#define DEVT_FASCIST 1 + +int +major(dev_t x) +{ +#ifdef DEVT_FASCIST + return(253 - ((x >> 8) & 0xff)); +#else + return((x >> 8) & 0xff); +#endif +} + +int +minor(dev_t x) +{ + return(x & 0xffff00ff); +} + +dev_t +makedev(int x, int y) +{ +#ifdef DEVT_FASCIST + return (((253 - x) << 8) | y); +#else + return ((x << 8) | y); +#endif +} + +udev_t +dev2udev(dev_t x) +{ + return umakedev(major(x), minor(x)); +} + +dev_t +udev2dev(udev_t x, int b) +{ + return makedev(umajor(x), uminor(x)); +} + +int +uminor(udev_t dev) +{ + return(dev & 0xffff00ff); +} + +int +umajor(udev_t dev) +{ + return((dev & 0xff00) >> 8); +} + +udev_t +umakedev(int x, int y) +{ + return ((x << 8) | y); +} + -- cgit v1.2.3