Move uminor() and umajor() to the same place as userspace minor() and major().

The uminor() and umajor() functions have the same use in kernel space as
the minor() and major() functions in userspace. If we ever get rid of
the minor() function in kernel space, we could decide to just expose
minor() and major() to kernel space, making uminor() and umajor()
redundant.

There are two reasons why we want to have uminor() and umajor() in
<sys/types.h>:

- Having them close together prevents them from diverting. Even though
  it's unlikely the definitions will change, it's a good habit to have
  them at the same place.

- They don't really belong in kern_conf.c. kern_conf.c has been
  liberated from dealing with device major and minor number handling.

The device_ids(9) manpage now lists the wrong #include's, because it
should only list <sys/types.h> now. I'm leaving it as it is now, because
I wonder if we should document them anyway. We're probably better off
documenting minor(3) and major(3).
This commit is contained in:
Ed Schouten 2008-09-27 13:19:09 +00:00
parent d83412e791
commit c6ec8c53c5
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=183406
3 changed files with 11 additions and 22 deletions

View File

@ -545,20 +545,6 @@ newdev(struct cdevsw *csw, int y, struct cdev *si)
return (si);
}
#define UMINORMASK 0xffff00ffU
int
uminor(dev_t dev)
{
return (dev & UMINORMASK);
}
int
umajor(dev_t dev)
{
return ((dev & ~UMINORMASK) >> 8);
}
static void
fini_cdevsw(struct cdevsw *devsw)
{

View File

@ -312,8 +312,6 @@ void wakeup_one(void *chan) __nonnull(1);
struct cdev;
dev_t dev2udev(struct cdev *x);
int uminor(dev_t dev);
int umajor(dev_t dev);
const char *devtoname(struct cdev *cdev);
/* XXX: Should be void nanodelay(u_int nsec); */

View File

@ -308,17 +308,22 @@ typedef struct vm_page *vm_page_t;
#include <sys/select.h>
#ifndef _KERNEL
/*
* minor() gives a cookie instead of an index since we don't want to
* change the meanings of bits 0-15 or waste time and space shifting
* bits 16-31 for devices that don't use them.
*
* XXX: In the kernel we must name it umajor() and uminor(), because
* minor() is still in use by <sys/conf.h>.
*/
#define major(x) ((int)(((u_int)(x) >> 8)&0xff)) /* major number */
#define minor(x) ((int)((x)&0xffff00ff)) /* minor number */
#endif /* !_KERNEL */
#define makedev(x,y) ((dev_t)(((x) << 8) | (y))) /* create dev_t */
#ifdef _KERNEL
#define umajor(x) ((int)(((u_int)(x) >> 8)&0xff)) /* major number */
#define uminor(x) ((int)((x)&0xffff00ff)) /* minor number */
#else /* !_KERNEL */
#define major(x) ((int)(((u_int)(x) >> 8)&0xff)) /* major number */
#define minor(x) ((int)((x)&0xffff00ff)) /* minor number */
#endif /* _KERNEL */
#define makedev(x,y) ((dev_t)(((x) << 8) | (y))) /* create dev_t */
/*
* These declarations belong elsewhere, but are repeated here and in