Last step of splitting up minor and unit numbers: remove minor().

Inside the kernel, the minor() function was responsible for obtaining
the device minor number of a character device. Because we made device
numbers dynamically allocated and independent of the unit number passed
to make_dev() a long time ago, it was actually a misnomer. If you really
want to obtain the device number, you should use dev2udev().

We already converted all the drivers to use dev2unit() to obtain the
device unit number, which is still used by a lot of drivers. I've
noticed not a single driver passes NULL to dev2unit(). Even if they
would, its behaviour would make little sense. This is why I've removed
the NULL check.

Ths commit removes minor(), minor2unit() and unit2minor() from the
kernel. Because there was a naming collision with uminor(), we can
rename umajor() and uminor() back to major() and minor(). This means
that the makedev(3) manual page also applies to kernel space code now.

I suspect umajor() and uminor() isn't used that often in external code,
but to make it easier for other parties to port their code, I've
increased __FreeBSD_version to 800062.
This commit is contained in:
Ed Schouten 2009-01-28 17:57:16 +00:00
parent 688ff09fed
commit a4611ab612
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=187830
11 changed files with 18 additions and 29 deletions

View File

@ -494,7 +494,7 @@ zfs_init_fs(zfsvfs_t *zfsvfs, znode_t **zpp)
static uint64_t
zfs_expldev(dev_t dev)
{
return (((uint64_t)umajor(dev) << NBITSMINOR64) | uminor(dev));
return (((uint64_t)major(dev) << NBITSMINOR64) | minor(dev));
}
/*
* Special cmpldev for ZFS private use.

View File

@ -88,7 +88,7 @@ disk_foo(struct somestat *tbuf)
/* XXX this may not be quite right */
/* Map major number to 0 */
tbuf.st_dev = uminor(buf->st_dev) & 0xf;
tbuf.st_dev = minor(buf->st_dev) & 0xf;
tbuf.st_rdev = buf->st_rdev & 0xff;
}
dev_relthread(dev);
@ -156,7 +156,7 @@ newstat_copyout(struct stat *buf, void *ubuf)
struct l_newstat tbuf;
bzero(&tbuf, sizeof(tbuf));
tbuf.st_dev = uminor(buf->st_dev) | (umajor(buf->st_dev) << 8);
tbuf.st_dev = minor(buf->st_dev) | (major(buf->st_dev) << 8);
tbuf.st_ino = buf->st_ino;
tbuf.st_mode = buf->st_mode;
tbuf.st_nlink = buf->st_nlink;
@ -487,7 +487,7 @@ stat64_copyout(struct stat *buf, void *ubuf)
struct l_stat64 lbuf;
bzero(&lbuf, sizeof(lbuf));
lbuf.st_dev = uminor(buf->st_dev) | (umajor(buf->st_dev) << 8);
lbuf.st_dev = minor(buf->st_dev) | (major(buf->st_dev) << 8);
lbuf.st_ino = buf->st_ino;
lbuf.st_mode = buf->st_mode;
lbuf.st_nlink = buf->st_nlink;

View File

@ -69,13 +69,13 @@ typedef struct timespec svr4_timestruc_t;
(((y) << 0) & 0x00ff)))
#define svr4_to_bsd_odev_t(d) makedev(svr4_omajor(d), svr4_ominor(d))
#define bsd_to_svr4_odev_t(d) svr4_omakedev(umajor(d), uminor(d))
#define bsd_to_svr4_odev_t(d) svr4_omakedev(major(d), minor(d))
#define svr4_major(x) ((int32_t)((((x) & 0xfffc0000) >> 18)))
#define svr4_minor(x) ((int32_t)((((x) & 0x0003ffff) >> 0)))
#define svr4_makedev(x,y) ((svr4_dev_t)((((x) << 18) & 0xfffc0000) | \
(((y) << 0) & 0x0003ffff)))
#define svr4_to_bsd_dev_t(d) makedev(svr4_major(d), svr4_minor(d))
#define bsd_to_svr4_dev_t(d) svr4_makedev(umajor(d), uminor(d))
#define bsd_to_svr4_dev_t(d) svr4_makedev(major(d), minor(d))
#endif /* !_SVR4_TYPES_H_ */

View File

@ -1135,8 +1135,8 @@ open_device(blkif_t *blkif)
}
blkif->media_num_sectors = blkif->media_size >> blkif->sector_size_shift;
blkif->major = umajor(vattr.va_rdev);
blkif->minor = uminor(vattr.va_rdev);
blkif->major = major(vattr.va_rdev);
blkif->minor = minor(vattr.va_rdev);
DPRINTF("opened dev=%s major=%d minor=%d sector_size=%u media_size=%lld\n",
blkif->dev_name, blkif->major, blkif->minor, blkif->sector_size, blkif->media_size);

View File

@ -416,9 +416,9 @@ cd9660_rrip_device(p,ana)
low = isonum_733(p->dev_t_low);
if (high == 0)
ana->inop->inode.iso_rdev = makedev(umajor(low), uminor(low));
ana->inop->inode.iso_rdev = makedev(major(low), minor(low));
else
ana->inop->inode.iso_rdev = makedev(high, uminor(low));
ana->inop->inode.iso_rdev = makedev(high, minor(low));
ana->fields &= ~ISO_SUSP_DEVICE;
return ISO_SUSP_DEVICE;
}

View File

@ -668,7 +668,7 @@ nfsm_v4build_create_xx(struct nfs4_compound *cp, struct nfs4_oparg_create *c,
nfsm_buildf_xx(mb, bpos, "s", strlen(c->linktext), c->linktext);
else if (c->type == NFCHR || c->type == NFBLK)
nfsm_buildf_xx(mb, bpos, "uu",
umajor(c->vap->va_rdev), uminor(c->vap->va_rdev));
major(c->vap->va_rdev), minor(c->vap->va_rdev));
/* Name */
nfsm_buildf_xx(mb, bpos, "s", c->namelen, c->name);

View File

@ -1314,8 +1314,8 @@ nfs_mknodrpc(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp,
nfsm_v3attrbuild(vap, FALSE);
if (vap->va_type == VCHR || vap->va_type == VBLK) {
tl = nfsm_build(u_int32_t *, 2 * NFSX_UNSIGNED);
*tl++ = txdr_unsigned(umajor(vap->va_rdev));
*tl = txdr_unsigned(uminor(vap->va_rdev));
*tl++ = txdr_unsigned(major(vap->va_rdev));
*tl = txdr_unsigned(minor(vap->va_rdev));
}
} else {
sp = nfsm_build(struct nfsv2_sattr *, NFSX_V2SATTR);

View File

@ -1057,8 +1057,8 @@ nfsm_srvfattr(struct nfsrv_descript *nfsd, struct vattr *vap,
fp->fa_mode = vtonfsv3_mode(vap->va_mode);
txdr_hyper(vap->va_size, &fp->fa3_size);
txdr_hyper(vap->va_bytes, &fp->fa3_used);
fp->fa3_rdev.specdata1 = txdr_unsigned(umajor(vap->va_rdev));
fp->fa3_rdev.specdata2 = txdr_unsigned(uminor(vap->va_rdev));
fp->fa3_rdev.specdata1 = txdr_unsigned(major(vap->va_rdev));
fp->fa3_rdev.specdata2 = txdr_unsigned(minor(vap->va_rdev));
fp->fa3_fsid.nfsuquad[0] = 0;
fp->fa3_fsid.nfsuquad[1] = txdr_unsigned(vap->va_fsid);
fp->fa3_fileid.nfsuquad[0] = 0;

View File

@ -274,10 +274,7 @@ void dev_lock(void);
void dev_unlock(void);
void setconf(void);
#define dev2unit(d) ((d) ? (d)->si_drv0 : NODEV)
#define minor(d) ((d) ? (d)->si_drv0 : NODEV)
#define unit2minor(u) (u)
#define minor2unit(m) (m)
#define dev2unit(d) ((d)->si_drv0)
typedef void (*cdevpriv_dtr_t)(void *data);
int devfs_get_cdevpriv(void **datap);

View File

@ -57,7 +57,7 @@
* is created, otherwise 1.
*/
#undef __FreeBSD_version
#define __FreeBSD_version 800061 /* Master, propagated to newvers */
#define __FreeBSD_version 800062 /* Master, propagated to newvers */
#ifndef LOCORE
#include <sys/types.h>

View File

@ -317,17 +317,9 @@ typedef struct vm_page *vm_page_t;
* 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>.
*/
#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 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 */
/*