Index: sys/fs/devfs/devfs_vnops.c =================================================================== --- sys/fs/devfs/devfs_vnops.c +++ sys/fs/devfs/devfs_vnops.c @@ -113,20 +113,30 @@ } static int +devfs_vn_check(struct vnode *vp, struct cdev **devp, struct cdevsw **dswp, + int *ref) +{ + + *dswp = devvn_refthread(vp, devp, ref); + if (*dswp == NULL) + return (ENXIO); + KASSERT((*devp)->si_refcount > 0, + ("devfs: un-referenced struct cdev *(%s)", devtoname(*devp))); + return (0); +} + +static int devfs_fp_check(struct file *fp, struct cdev **devp, struct cdevsw **dswp, int *ref) { + int error; - *dswp = devvn_refthread(fp->f_vnode, devp, ref); - if (*devp != fp->f_data) { + error = devfs_vn_check(fp->f_vnode, devp, dswp, ref); + if (error == 0 && *devp != fp->f_data) { if (*dswp != NULL) dev_relthread(*devp, *ref); return (ENXIO); } - KASSERT((*devp)->si_refcount > 0, - ("devfs: un-referenced struct cdev *(%s)", devtoname(*devp))); - if (*dswp == NULL) - return (ENXIO); curthread->td_fpop = fp; return (0); } @@ -779,14 +789,10 @@ static int devfs_ioctl_f(struct file *fp, u_long com, void *data, struct ucred *cred, struct thread *td) { - struct cdev *dev; struct cdevsw *dsw; - struct vnode *vp; - struct vnode *vpold; - int error, i, ref; - const char *p; - struct fiodgname_arg *fgn; struct file *fpop; + struct cdev *dev; + int error, ref; fpop = td->td_fpop; error = devfs_fp_check(fp, &dev, &dsw, &ref); @@ -795,31 +801,54 @@ return (error); } + error = VOP_IOCTL(fp->f_vnode, com, data, fp->f_flag, cred, td); + td->td_fpop = fpop; + dev_relthread(dev, ref); + return (error); +} + +static int +devfs_ioctl(struct vop_ioctl_args *ap) +{ + struct fiodgname_arg *fgn; + struct vnode *vpold, *vp; + struct cdevsw *dsw; + struct thread *td; + struct cdev *dev; + int error, ref, i; + const char *p; + u_long com; + + vp = ap->a_vp; + com = ap->a_command; + td = ap->a_td; + + error = devfs_vn_check(vp, &dev, &dsw, &ref); + if (error != 0) + return (error); + if (com == FIODTYPE) { - *(int *)data = dsw->d_flags & D_TYPEMASK; - td->td_fpop = fpop; - dev_relthread(dev, ref); - return (0); + *(int *)ap->a_data = dsw->d_flags & D_TYPEMASK; + goto out; } else if (com == FIODGNAME) { - fgn = data; + fgn = ap->a_data; p = devtoname(dev); i = strlen(p) + 1; if (i > fgn->len) error = EINVAL; else error = copyout(p, fgn->buf, i); - td->td_fpop = fpop; - dev_relthread(dev, ref); - return (error); + goto out; } - error = dsw->d_ioctl(dev, com, data, fp->f_flag, td); - td->td_fpop = NULL; + + error = dsw->d_ioctl(dev, com, ap->a_data, ap->a_fflag, td); + +out: dev_relthread(dev, ref); if (error == ENOIOCTL) error = ENOTTY; - if (error == 0 && com == TIOCSCTTY) { - vp = fp->f_vnode; + if (error == 0 && com == TIOCSCTTY) { /* Do nothing if reassigning same control tty */ sx_slock(&proctree_lock); if (td->td_proc->p_session->s_ttyvp == vp) { @@ -1862,6 +1891,7 @@ .fo_flags = DFLAG_PASSABLE | DFLAG_SEEKABLE }; +/* Just for "/dev" */ static struct vop_vector devfs_vnodeops = { .vop_default = &default_vnodeops, @@ -1894,6 +1924,7 @@ .vop_create = VOP_PANIC, .vop_fsync = devfs_fsync, .vop_getattr = devfs_getattr, + .vop_ioctl = devfs_ioctl, .vop_link = VOP_PANIC, .vop_mkdir = VOP_PANIC, .vop_mknod = VOP_PANIC,