diff --git a/sys/fs/devfs/devfs_devs.c b/sys/fs/devfs/devfs_devs.c index 1d5e3c90f50a..45f8d58f5b43 100644 --- a/sys/fs/devfs/devfs_devs.c +++ b/sys/fs/devfs/devfs_devs.c @@ -125,7 +125,6 @@ devfs_alloc(void) cdp->cdp_maxdirent = 0; cdev = &cdp->cdp_c; - cdev->si_priv = cdp; cdev->si_name = cdev->__si_namebuf; LIST_INIT(&cdev->si_children); @@ -137,7 +136,7 @@ devfs_free(struct cdev *cdev) { struct cdev_priv *cdp; - cdp = cdev->si_priv; + cdp = cdev2priv(cdev); if (cdev->si_cred != NULL) crfree(cdev->si_cred); if (cdp->cdp_inode > 0) @@ -510,7 +509,7 @@ devfs_create(struct cdev *dev) struct cdev_priv *cdp; mtx_assert(&devmtx, MA_OWNED); - cdp = dev->si_priv; + cdp = cdev2priv(dev); cdp->cdp_flags |= CDP_ACTIVE; cdp->cdp_inode = alloc_unrl(devfs_inos); dev_refl(dev); @@ -524,7 +523,7 @@ devfs_destroy(struct cdev *dev) struct cdev_priv *cdp; mtx_assert(&devmtx, MA_OWNED); - cdp = dev->si_priv; + cdp = cdev2priv(dev); cdp->cdp_flags &= ~CDP_ACTIVE; devfs_generation++; } diff --git a/sys/fs/devfs/devfs_int.h b/sys/fs/devfs/devfs_int.h index df0ad56069d9..5a61dd4a79b0 100644 --- a/sys/fs/devfs/devfs_int.h +++ b/sys/fs/devfs/devfs_int.h @@ -68,6 +68,8 @@ struct cdev_priv { LIST_HEAD(, cdev_privdata) cdp_fdpriv; }; +#define cdev2priv(c) member2struct(cdev_priv, cdp_c, c) + struct cdev *devfs_alloc(void); void devfs_free(struct cdev *); void devfs_create(struct cdev *dev); diff --git a/sys/fs/devfs/devfs_vnops.c b/sys/fs/devfs/devfs_vnops.c index 649f492dc61e..8130642f1154 100644 --- a/sys/fs/devfs/devfs_vnops.c +++ b/sys/fs/devfs/devfs_vnops.c @@ -132,7 +132,7 @@ devfs_set_cdevpriv(void *priv, cdevpriv_dtr_t priv_dtr) fp = curthread->td_fpop; if (fp == NULL) return (ENOENT); - cdp = ((struct cdev *)fp->f_data)->si_priv; + cdp = cdev2priv((struct cdev *)fp->f_data); p = malloc(sizeof(struct cdev_privdata), M_CDEVPDATA, M_WAITOK); p->cdpd_data = priv; p->cdpd_dtr = priv_dtr; @@ -541,7 +541,7 @@ devfs_getattr(struct vop_getattr_args *ap) fix(dev->si_ctime); vap->va_ctime = dev->si_ctime; - vap->va_rdev = dev->si_priv->cdp_inode; + vap->va_rdev = cdev2priv(dev)->cdp_inode; } vap->va_gen = 0; vap->va_flags = 0; @@ -742,7 +742,7 @@ devfs_lookupx(struct vop_lookup_args *ap, int *dm_unlock) } dev_lock(); - dde = &cdev->si_priv->cdp_dirents[dmp->dm_idx]; + dde = &cdev2priv(cdev)->cdp_dirents[dmp->dm_idx]; if (dde != NULL && *dde != NULL) de = *dde; dev_unlock(); @@ -1141,7 +1141,7 @@ devfs_revoke(struct vop_revoke_args *ap) KASSERT((ap->a_flags & REVOKEALL) != 0, ("devfs_revoke !REVOKEALL")); dev = vp->v_rdev; - cdp = dev->si_priv; + cdp = cdev2priv(dev); dev_lock(); cdp->cdp_inuse++; @@ -1419,7 +1419,7 @@ dev2udev(struct cdev *x) { if (x == NULL) return (NODEV); - return (x->si_priv->cdp_inode); + return (cdev2priv(x)->cdp_inode); } static struct fileops devfs_ops_f = { diff --git a/sys/kern/kern_conf.c b/sys/kern/kern_conf.c index c9eac628796a..e328ca97b38e 100644 --- a/sys/kern/kern_conf.c +++ b/sys/kern/kern_conf.c @@ -115,7 +115,7 @@ dev_free_devlocked(struct cdev *cdev) struct cdev_priv *cdp; mtx_assert(&devmtx, MA_OWNED); - cdp = cdev->si_priv; + cdp = cdev2priv(cdev); TAILQ_INSERT_HEAD(&cdevp_free_list, cdp, cdp_list); } @@ -187,7 +187,7 @@ dev_refthread(struct cdev *dev) dev_lock(); csw = dev->si_devsw; if (csw != NULL) { - cdp = dev->si_priv; + cdp = cdev2priv(dev); if ((cdp->cdp_flags & CDP_SCHED_DTR) == 0) dev->si_threadcount++; else @@ -208,7 +208,7 @@ devvn_refthread(struct vnode *vp, struct cdev **devp) dev_lock(); *devp = vp->v_rdev; if (*devp != NULL) { - cdp = (*devp)->si_priv; + cdp = cdev2priv(*devp); if ((cdp->cdp_flags & CDP_SCHED_DTR) == 0) { csw = (*devp)->si_devsw; if (csw != NULL) @@ -851,7 +851,7 @@ destroy_devl(struct cdev *dev) dev_unlock(); notify_destroy(dev); mtx_lock(&cdevpriv_mtx); - LIST_FOREACH_SAFE(p, &dev->si_priv->cdp_fdpriv, cdpd_list, p1) { + LIST_FOREACH_SAFE(p, &cdev2priv(dev)->cdp_fdpriv, cdpd_list, p1) { devfs_destroy_cdevpriv(p); mtx_lock(&cdevpriv_mtx); } @@ -1071,7 +1071,7 @@ clone_cleanup(struct clonedevs **cdp) KASSERT(dev->si_flags & SI_CLONELIST, ("Dev %p(%s) should be on clonelist", dev, dev->si_name)); dev->si_flags &= ~SI_CLONELIST; - cp = dev->si_priv; + cp = cdev2priv(dev); if (!(cp->cdp_flags & CDP_SCHED_DTR)) { cp->cdp_flags |= CDP_SCHED_DTR; KASSERT(dev->si_flags & SI_NAMED, @@ -1125,7 +1125,7 @@ destroy_dev_sched_cbl(struct cdev *dev, void (*cb)(void *), void *arg) struct cdev_priv *cp; mtx_assert(&devmtx, MA_OWNED); - cp = dev->si_priv; + cp = cdev2priv(dev); if (cp->cdp_flags & CDP_SCHED_DTR) { dev_unlock(); return (0); diff --git a/sys/sys/conf.h b/sys/sys/conf.h index cd2bb8d1dcfa..739c3fe9cebd 100644 --- a/sys/sys/conf.h +++ b/sys/sys/conf.h @@ -53,7 +53,7 @@ struct cdevsw; struct file; struct cdev { - struct cdev_priv *si_priv; + void *__si_reserved; u_int si_flags; #define SI_ALIAS 0x0002 /* carrier of alias name */ #define SI_NAMED 0x0004 /* make_dev{_alias} has been called */ diff --git a/usr.bin/fstat/fstat.c b/usr.bin/fstat/fstat.c index 90ffba8207a6..886c3bb4746c 100644 --- a/usr.bin/fstat/fstat.c +++ b/usr.bin/fstat/fstat.c @@ -97,6 +97,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -895,10 +896,8 @@ dev_t dev2udev(struct cdev *dev) { struct cdev_priv priv; - struct cdev si; - if (KVM_READ(dev, &si, sizeof si) && - KVM_READ(si.si_priv, &priv, sizeof priv)) { + if (KVM_READ(cdev2priv(dev), &priv, sizeof priv)) { return ((dev_t)priv.cdp_inode); } else { dprintf(stderr, "can't convert cdev *%p to a dev_t\n", dev);