From c81c59299bd255eb5ab7510c9e84e9c54b8003d0 Mon Sep 17 00:00:00 2001 From: phk Date: Sun, 22 Jun 2003 08:41:43 +0000 Subject: Add a f_vnode field to struct file. Several of the subtypes have an associated vnode which is used for stuff like the f*() functions. By giving the vnode a speparate field, a number of checks for the specific subtype can be replaced simply with a check for f_vnode != NULL, and we can later free f_data up to subtype specific use. At this point in time, f_data still points to the vnode, so any code I might have overlooked will still work. --- sys/alpha/osf1/osf1_mount.c | 2 +- sys/compat/linux/linux_file.c | 2 +- sys/compat/linux/linux_stats.c | 2 +- sys/compat/svr4/svr4_fcntl.c | 2 +- sys/compat/svr4/svr4_misc.c | 6 +++--- sys/fs/fdescfs/fdesc_vnops.c | 2 +- sys/fs/unionfs/union_subr.c | 1 + sys/i386/ibcs2/ibcs2_misc.c | 4 ++-- sys/i386/ibcs2/ibcs2_stat.c | 2 +- sys/kern/kern_acl.c | 8 ++++---- sys/kern/kern_descrip.c | 21 +++++++++++---------- sys/kern/kern_mac.c | 4 ++-- sys/kern/subr_acl_posix1e.c | 8 ++++---- sys/kern/vfs_acl.c | 8 ++++---- sys/kern/vfs_aio.c | 4 ++-- sys/kern/vfs_extattr.c | 36 ++++++++++++++++++++---------------- sys/kern/vfs_syscalls.c | 36 ++++++++++++++++++++---------------- sys/kern/vfs_vnops.c | 14 +++++++------- sys/netsmb/smb_dev.c | 2 +- sys/security/mac/mac_framework.c | 4 ++-- sys/security/mac/mac_internal.h | 4 ++-- sys/security/mac/mac_net.c | 4 ++-- sys/security/mac/mac_pipe.c | 4 ++-- sys/security/mac/mac_process.c | 4 ++-- sys/security/mac/mac_syscalls.c | 4 ++-- sys/security/mac/mac_system.c | 4 ++-- sys/security/mac/mac_vfs.c | 4 ++-- sys/sys/file.h | 1 + sys/vm/vm_mmap.c | 2 +- 29 files changed, 105 insertions(+), 94 deletions(-) diff --git a/sys/alpha/osf1/osf1_mount.c b/sys/alpha/osf1/osf1_mount.c index aa0e787..8b2882f 100644 --- a/sys/alpha/osf1/osf1_mount.c +++ b/sys/alpha/osf1/osf1_mount.c @@ -159,7 +159,7 @@ osf1_fstatfs(td, uap) if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp))) return (error); - mp = ((struct vnode *)fp->f_data)->v_mount; + mp = fp->f_vnode->v_mount; #ifdef MAC error = mac_check_mount_stat(td->td_ucred, mp); if (error) { diff --git a/sys/compat/linux/linux_file.c b/sys/compat/linux/linux_file.c index d61483a..96af89c 100644 --- a/sys/compat/linux/linux_file.c +++ b/sys/compat/linux/linux_file.c @@ -271,7 +271,7 @@ getdents_common(struct thread *td, struct linux_getdents64_args *args, return (EBADF); } - vp = fp->f_data; + vp = fp->f_vnode; if (vp->v_type != VDIR) { fdrop(fp, td); return (EINVAL); diff --git a/sys/compat/linux/linux_stats.c b/sys/compat/linux/linux_stats.c index 3b873f8..8d90b1f 100644 --- a/sys/compat/linux/linux_stats.c +++ b/sys/compat/linux/linux_stats.c @@ -290,7 +290,7 @@ linux_fstatfs(struct thread *td, struct linux_fstatfs_args *args) error = getvnode(td->td_proc->p_fd, args->fd, &fp); if (error) return error; - mp = ((struct vnode *)fp->f_data)->v_mount; + mp = fp->f_vnode->v_mount; #ifdef MAC error = mac_check_mount_stat(td->td_ucred, mp); if (error) { diff --git a/sys/compat/svr4/svr4_fcntl.c b/sys/compat/svr4/svr4_fcntl.c index c21afa7..7a01b15 100644 --- a/sys/compat/svr4/svr4_fcntl.c +++ b/sys/compat/svr4/svr4_fcntl.c @@ -312,7 +312,7 @@ fd_truncate(td, fd, flp) if ((error = fget(td, fd, &fp)) != 0) return (error); - vp = fp->f_data; + vp = fp->f_vnode; if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO) { fdrop(fp, td); diff --git a/sys/compat/svr4/svr4_misc.c b/sys/compat/svr4/svr4_misc.c index 7cdb576..1766e88 100644 --- a/sys/compat/svr4/svr4_misc.c +++ b/sys/compat/svr4/svr4_misc.c @@ -272,7 +272,7 @@ svr4_sys_getdents64(td, uap) return (EBADF); } - vp = fp->f_data; + vp = fp->f_vnode; if (vp->v_type != VDIR) { fdrop(fp, td); @@ -452,7 +452,7 @@ svr4_sys_getdents(td, uap) return (EBADF); } - vp = fp->f_data; + vp = fp->f_vnode; if (vp->v_type != VDIR) { fdrop(fp, td); return (EINVAL); @@ -628,7 +628,7 @@ svr4_sys_fchroot(td, uap) return error; if ((error = getvnode(fdp, uap->fd, &fp)) != 0) return error; - vp = fp->f_data; + vp = fp->f_vnode; vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td); if (vp->v_type != VDIR) error = ENOTDIR; diff --git a/sys/fs/fdescfs/fdesc_vnops.c b/sys/fs/fdescfs/fdesc_vnops.c index 3dfd9dd..dbdb012 100644 --- a/sys/fs/fdescfs/fdesc_vnops.c +++ b/sys/fs/fdescfs/fdesc_vnops.c @@ -395,7 +395,7 @@ fdesc_setattr(ap) } return (error); } - vp = fp->f_data; + vp = fp->f_vnode; if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0) { fdrop(fp, ap->a_td); return (error); diff --git a/sys/fs/unionfs/union_subr.c b/sys/fs/unionfs/union_subr.c index c2e048a..94460cf 100644 --- a/sys/fs/unionfs/union_subr.c +++ b/sys/fs/unionfs/union_subr.c @@ -1349,6 +1349,7 @@ union_dircheck(struct thread *td, struct vnode **vp, struct file *fp) } VOP_UNLOCK(lvp, 0, td); FILE_LOCK(fp); + fp->f_vnode = lvp; fp->f_data = lvp; fp->f_offset = 0; FILE_UNLOCK(fp); diff --git a/sys/i386/ibcs2/ibcs2_misc.c b/sys/i386/ibcs2/ibcs2_misc.c index 013b757..8cd3488 100644 --- a/sys/i386/ibcs2/ibcs2_misc.c +++ b/sys/i386/ibcs2/ibcs2_misc.c @@ -324,7 +324,7 @@ ibcs2_getdents(td, uap) fdrop(fp, td); return (EBADF); } - vp = fp->f_data; + vp = fp->f_vnode; if (vp->v_type != VDIR) { /* XXX vnode readdir op should do this */ fdrop(fp, td); return (EINVAL); @@ -481,7 +481,7 @@ ibcs2_read(td, uap) fdrop(fp, td); return (EBADF); } - vp = fp->f_data; + vp = fp->f_vnode; if (vp->v_type != VDIR) { fdrop(fp, td); return read(td, (struct read_args *)uap); diff --git a/sys/i386/ibcs2/ibcs2_stat.c b/sys/i386/ibcs2/ibcs2_stat.c index 572b77b..74f8f7c 100644 --- a/sys/i386/ibcs2/ibcs2_stat.c +++ b/sys/i386/ibcs2/ibcs2_stat.c @@ -133,7 +133,7 @@ ibcs2_fstatfs(td, uap) if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0) return (error); - mp = ((struct vnode *)fp->f_data)->v_mount; + mp = fp->f_vnode->v_mount; sp = &mp->mnt_stat; error = VFS_STATFS(mp, sp, td); fdrop(fp, td); diff --git a/sys/kern/kern_acl.c b/sys/kern/kern_acl.c index d1bce92..5a60f78 100644 --- a/sys/kern/kern_acl.c +++ b/sys/kern/kern_acl.c @@ -781,7 +781,7 @@ __acl_get_fd(struct thread *td, struct __acl_get_fd_args *uap) mtx_lock(&Giant); error = getvnode(td->td_proc->p_fd, uap->filedes, &fp); if (error == 0) { - error = vacl_get_acl(td, fp->f_data, uap->type, uap->aclp); + error = vacl_get_acl(td, fp->f_vnode, uap->type, uap->aclp); fdrop(fp, td); } mtx_unlock(&Giant); @@ -802,7 +802,7 @@ __acl_set_fd(struct thread *td, struct __acl_set_fd_args *uap) mtx_lock(&Giant); error = getvnode(td->td_proc->p_fd, uap->filedes, &fp); if (error == 0) { - error = vacl_set_acl(td, fp->f_data, uap->type, uap->aclp); + error = vacl_set_acl(td, fp->f_vnode, uap->type, uap->aclp); fdrop(fp, td); } mtx_unlock(&Giant); @@ -867,7 +867,7 @@ __acl_delete_fd(struct thread *td, struct __acl_delete_fd_args *uap) mtx_lock(&Giant); error = getvnode(td->td_proc->p_fd, uap->filedes, &fp); if (error == 0) { - error = vacl_delete(td, fp->f_data, uap->type); + error = vacl_delete(td, fp->f_vnode, uap->type); fdrop(fp, td); } mtx_unlock(&Giant); @@ -932,7 +932,7 @@ __acl_aclcheck_fd(struct thread *td, struct __acl_aclcheck_fd_args *uap) mtx_lock(&Giant); error = getvnode(td->td_proc->p_fd, uap->filedes, &fp); if (error == 0) { - error = vacl_aclcheck(td, fp->f_data, uap->type, uap->aclp); + error = vacl_aclcheck(td, fp->f_vnode, uap->type, uap->aclp); fdrop(fp, td); } mtx_unlock(&Giant); diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 6699e32..c61d08a 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -352,7 +352,7 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg) */ fhold(fp); FILEDESC_UNLOCK(fdp); - vp = fp->f_data; + vp = fp->f_vnode; switch (flp->l_type) { case F_RDLCK: @@ -430,7 +430,7 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg) */ fhold(fp); FILEDESC_UNLOCK(fdp); - vp = fp->f_data; + vp = fp->f_vnode; error = VOP_ADVLOCK(vp, (caddr_t)p->p_leader, F_GETLK, flp, F_POSIX); fdrop(fp, td); @@ -1028,7 +1028,7 @@ fpathconf(td, uap) break; case DTYPE_FIFO: case DTYPE_VNODE: - vp = fp->f_data; + vp = fp->f_vnode; mtx_lock(&Giant); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td); error = VOP_PATHCONF(vp, uap->name, td->td_retval); @@ -1465,7 +1465,7 @@ fdfree(td) lf.l_start = 0; lf.l_len = 0; lf.l_type = F_UNLCK; - vp = fp->f_data; + vp = fp->f_vnode; (void) VOP_ADVLOCK(vp, (caddr_t)td->td_proc-> p_leader, @@ -1564,7 +1564,7 @@ static int is_unsafe(struct file *fp) { if (fp->f_type == DTYPE_VNODE) { - struct vnode *vp = fp->f_data; + struct vnode *vp = fp->f_vnode; if ((vp->v_vflag & VV_PROCDEP) != 0) return (1); @@ -1722,6 +1722,7 @@ fdcheckstd(td) break; } NDFREE(&nd, NDF_ONLY_PNBUF); + fp->f_vnode = nd.ni_vp; fp->f_data = nd.ni_vp; fp->f_flag = flags; fp->f_ops = &vnops; @@ -1770,7 +1771,7 @@ closef(fp, td) lf.l_start = 0; lf.l_len = 0; lf.l_type = F_UNLCK; - vp = fp->f_data; + vp = fp->f_vnode; (void) VOP_ADVLOCK(vp, (caddr_t)td->td_proc->p_leader, F_UNLCK, &lf, F_POSIX); } @@ -1794,7 +1795,7 @@ closef(fp, td) lf.l_start = 0; lf.l_len = 0; lf.l_type = F_UNLCK; - vp = fp->f_data; + vp = fp->f_vnode; (void) VOP_ADVLOCK(vp, (caddr_t)fdtol->fdl_leader, F_UNLCK, &lf, F_POSIX); @@ -1919,7 +1920,7 @@ _fgetvp(struct thread *td, int fd, struct vnode **vpp, int flags) if (fp->f_type != DTYPE_VNODE && fp->f_type != DTYPE_FIFO) { error = EINVAL; } else { - *vpp = fp->f_data; + *vpp = fp->f_vnode; vref(*vpp); } FILEDESC_UNLOCK(td->td_proc->p_fd); @@ -2018,7 +2019,7 @@ fdrop_locked(fp, td) lf.l_start = 0; lf.l_len = 0; lf.l_type = F_UNLCK; - vp = fp->f_data; + vp = fp->f_vnode; (void) VOP_ADVLOCK(vp, (caddr_t)fp, F_UNLCK, &lf, F_FLOCK); } if (fp->f_ops != &badfileops) @@ -2064,7 +2065,7 @@ flock(td, uap) } mtx_lock(&Giant); - vp = fp->f_data; + vp = fp->f_vnode; lf.l_whence = SEEK_SET; lf.l_start = 0; lf.l_len = 0; diff --git a/sys/kern/kern_mac.c b/sys/kern/kern_mac.c index e5e25dc..79a12ec 100644 --- a/sys/kern/kern_mac.c +++ b/sys/kern/kern_mac.c @@ -3496,7 +3496,7 @@ __mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap) switch (fp->f_type) { case DTYPE_FIFO: case DTYPE_VNODE: - vp = fp->f_data; + vp = fp->f_vnode; mac_init_vnode_label(&intlabel); @@ -3704,7 +3704,7 @@ __mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap) break; } - vp = fp->f_data; + vp = fp->f_vnode; error = vn_start_write(vp, &mp, V_WAIT | PCATCH); if (error != 0) { mac_destroy_vnode_label(&intlabel); diff --git a/sys/kern/subr_acl_posix1e.c b/sys/kern/subr_acl_posix1e.c index d1bce92..5a60f78 100644 --- a/sys/kern/subr_acl_posix1e.c +++ b/sys/kern/subr_acl_posix1e.c @@ -781,7 +781,7 @@ __acl_get_fd(struct thread *td, struct __acl_get_fd_args *uap) mtx_lock(&Giant); error = getvnode(td->td_proc->p_fd, uap->filedes, &fp); if (error == 0) { - error = vacl_get_acl(td, fp->f_data, uap->type, uap->aclp); + error = vacl_get_acl(td, fp->f_vnode, uap->type, uap->aclp); fdrop(fp, td); } mtx_unlock(&Giant); @@ -802,7 +802,7 @@ __acl_set_fd(struct thread *td, struct __acl_set_fd_args *uap) mtx_lock(&Giant); error = getvnode(td->td_proc->p_fd, uap->filedes, &fp); if (error == 0) { - error = vacl_set_acl(td, fp->f_data, uap->type, uap->aclp); + error = vacl_set_acl(td, fp->f_vnode, uap->type, uap->aclp); fdrop(fp, td); } mtx_unlock(&Giant); @@ -867,7 +867,7 @@ __acl_delete_fd(struct thread *td, struct __acl_delete_fd_args *uap) mtx_lock(&Giant); error = getvnode(td->td_proc->p_fd, uap->filedes, &fp); if (error == 0) { - error = vacl_delete(td, fp->f_data, uap->type); + error = vacl_delete(td, fp->f_vnode, uap->type); fdrop(fp, td); } mtx_unlock(&Giant); @@ -932,7 +932,7 @@ __acl_aclcheck_fd(struct thread *td, struct __acl_aclcheck_fd_args *uap) mtx_lock(&Giant); error = getvnode(td->td_proc->p_fd, uap->filedes, &fp); if (error == 0) { - error = vacl_aclcheck(td, fp->f_data, uap->type, uap->aclp); + error = vacl_aclcheck(td, fp->f_vnode, uap->type, uap->aclp); fdrop(fp, td); } mtx_unlock(&Giant); diff --git a/sys/kern/vfs_acl.c b/sys/kern/vfs_acl.c index d1bce92..5a60f78 100644 --- a/sys/kern/vfs_acl.c +++ b/sys/kern/vfs_acl.c @@ -781,7 +781,7 @@ __acl_get_fd(struct thread *td, struct __acl_get_fd_args *uap) mtx_lock(&Giant); error = getvnode(td->td_proc->p_fd, uap->filedes, &fp); if (error == 0) { - error = vacl_get_acl(td, fp->f_data, uap->type, uap->aclp); + error = vacl_get_acl(td, fp->f_vnode, uap->type, uap->aclp); fdrop(fp, td); } mtx_unlock(&Giant); @@ -802,7 +802,7 @@ __acl_set_fd(struct thread *td, struct __acl_set_fd_args *uap) mtx_lock(&Giant); error = getvnode(td->td_proc->p_fd, uap->filedes, &fp); if (error == 0) { - error = vacl_set_acl(td, fp->f_data, uap->type, uap->aclp); + error = vacl_set_acl(td, fp->f_vnode, uap->type, uap->aclp); fdrop(fp, td); } mtx_unlock(&Giant); @@ -867,7 +867,7 @@ __acl_delete_fd(struct thread *td, struct __acl_delete_fd_args *uap) mtx_lock(&Giant); error = getvnode(td->td_proc->p_fd, uap->filedes, &fp); if (error == 0) { - error = vacl_delete(td, fp->f_data, uap->type); + error = vacl_delete(td, fp->f_vnode, uap->type); fdrop(fp, td); } mtx_unlock(&Giant); @@ -932,7 +932,7 @@ __acl_aclcheck_fd(struct thread *td, struct __acl_aclcheck_fd_args *uap) mtx_lock(&Giant); error = getvnode(td->td_proc->p_fd, uap->filedes, &fp); if (error == 0) { - error = vacl_aclcheck(td, fp->f_data, uap->type, uap->aclp); + error = vacl_aclcheck(td, fp->f_vnode, uap->type, uap->aclp); fdrop(fp, td); } mtx_unlock(&Giant); diff --git a/sys/kern/vfs_aio.c b/sys/kern/vfs_aio.c index ef6e305..fc52073 100644 --- a/sys/kern/vfs_aio.c +++ b/sys/kern/vfs_aio.c @@ -1059,7 +1059,7 @@ aio_qphysio(struct proc *p, struct aiocblist *aiocbe) if (fp->f_type != DTYPE_VNODE) return (-1); - vp = fp->f_data; + vp = fp->f_vnode; /* * If its not a disk, we don't want to return a positive error. @@ -1723,7 +1723,7 @@ aio_cancel(struct thread *td, struct aio_cancel_args *uap) return (EBADF); if (fp->f_type == DTYPE_VNODE) { - vp = fp->f_data; + vp = fp->f_vnode; if (vn_isdisk(vp,&error)) { td->td_retval[0] = AIO_NOTCANCELED; diff --git a/sys/kern/vfs_extattr.c b/sys/kern/vfs_extattr.c index 30e16fc..3b45d43 100644 --- a/sys/kern/vfs_extattr.c +++ b/sys/kern/vfs_extattr.c @@ -282,7 +282,7 @@ fstatfs(td, uap) if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0) return (error); - mp = ((struct vnode *)fp->f_data)->v_mount; + mp = fp->f_vnode->v_mount; fdrop(fp, td); if (mp == NULL) return (EBADF); @@ -403,7 +403,7 @@ fchdir(td, uap) if ((error = getvnode(fdp, uap->fd, &fp)) != 0) return (error); - vp = fp->f_data; + vp = fp->f_vnode; VREF(vp); fdrop(fp, td); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td); @@ -502,7 +502,7 @@ chroot_refuse_vdir_fds(fdp) if (fp == NULL) continue; if (fp->f_type == DTYPE_VNODE) { - vp = fp->f_data; + vp = fp->f_vnode; if (vp->v_type == VDIR) return (EPERM); } @@ -745,6 +745,7 @@ kern_open(struct thread *td, char *path, enum uio_seg pathseg, int flags, td->td_retval[0] = indx; return 0; } + fp->f_vnode = vp; fp->f_data = vp; fp->f_flag = flags & FMASK; fp->f_ops = &vnops; @@ -1346,7 +1347,7 @@ lseek(td, uap) fdrop(fp, td); return (ESPIPE); } - vp = fp->f_data; + vp = fp->f_vnode; noneg = (vp->v_type != VCHR); offset = uap->offset; switch (uap->whence) { @@ -2056,7 +2057,7 @@ fchflags(td, uap) if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0) return (error); - error = setfflags(td, fp->f_data, uap->flags); + error = setfflags(td, fp->f_vnode, uap->flags); fdrop(fp, td); return (error); } @@ -2180,7 +2181,7 @@ fchmod(td, uap) if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0) return (error); - error = setfmode(td, fp->f_data, uap->mode); + error = setfmode(td, fp->f_vnode, uap->mode); fdrop(fp, td); return (error); } @@ -2322,7 +2323,7 @@ fchown(td, uap) if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0) return (error); - error = setfown(td, fp->f_data, uap->uid, uap->gid); + error = setfown(td, fp->f_vnode, uap->uid, uap->gid); fdrop(fp, td); return (error); } @@ -2520,7 +2521,7 @@ kern_futimes(struct thread *td, int fd, struct timeval *tptr, return (error); if ((error = getvnode(td->td_proc->p_fd, fd, &fp)) != 0) return (error); - error = setutimes(td, fp->f_data, ts, 2, tptr == NULL); + error = setutimes(td, fp->f_vnode, ts, 2, tptr == NULL); fdrop(fp, td); return (error); } @@ -2622,7 +2623,7 @@ ftruncate(td, uap) fdrop(fp, td); return (EINVAL); } - vp = fp->f_data; + vp = fp->f_vnode; if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0) { fdrop(fp, td); return (error); @@ -2733,7 +2734,7 @@ fsync(td, uap) if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0) return (error); - vp = fp->f_data; + vp = fp->f_vnode; if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0) { fdrop(fp, td); return (error); @@ -3096,7 +3097,7 @@ ogetdirentries(td, uap) fdrop(fp, td); return (EBADF); } - vp = fp->f_data; + vp = fp->f_vnode; unionread: if (vp->v_type != VDIR) { fdrop(fp, td); @@ -3196,6 +3197,7 @@ unionread: struct vnode *tvp = vp; vp = vp->v_mount->mnt_vnodecovered; VREF(vp); + fp->f_vnode = vp; fp->f_data = vp; fp->f_offset = 0; vput(tvp); @@ -3244,7 +3246,7 @@ getdirentries(td, uap) fdrop(fp, td); return (EBADF); } - vp = fp->f_data; + vp = fp->f_vnode; unionread: if (vp->v_type != VDIR) { fdrop(fp, td); @@ -3293,6 +3295,7 @@ unionread: struct vnode *tvp = vp; vp = vp->v_mount->mnt_vnodecovered; VREF(vp); + fp->f_vnode = vp; fp->f_data = vp; fp->f_offset = 0; vput(tvp); @@ -3646,6 +3649,7 @@ fhopen(td, uap) * from under us while we block in the lock op */ fhold(fp); + nfp->f_vnode = vp; nfp->f_data = vp; nfp->f_flag = fmode & FMASK; nfp->f_ops = &vnops; @@ -3967,7 +3971,7 @@ extattr_set_fd(td, uap) if (error) return (error); - error = extattr_set_vp(fp->f_data, uap->attrnamespace, + error = extattr_set_vp(fp->f_vnode, uap->attrnamespace, attrname, uap->data, uap->nbytes, td); fdrop(fp, td); @@ -4140,7 +4144,7 @@ extattr_get_fd(td, uap) if (error) return (error); - error = extattr_get_vp(fp->f_data, uap->attrnamespace, + error = extattr_get_vp(fp->f_vnode, uap->attrnamespace, attrname, uap->data, uap->nbytes, td); fdrop(fp, td); @@ -4272,7 +4276,7 @@ extattr_delete_fd(td, uap) error = getvnode(td->td_proc->p_fd, uap->fd, &fp); if (error) return (error); - vp = fp->f_data; + vp = fp->f_vnode; error = extattr_delete_vp(vp, uap->attrnamespace, attrname, td); fdrop(fp, td); @@ -4418,7 +4422,7 @@ extattr_list_fd(td, uap) if (error) return (error); - error = extattr_list_vp(fp->f_data, uap->attrnamespace, uap->data, + error = extattr_list_vp(fp->f_vnode, uap->attrnamespace, uap->data, uap->nbytes, td); fdrop(fp, td); diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index 30e16fc..3b45d43 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -282,7 +282,7 @@ fstatfs(td, uap) if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0) return (error); - mp = ((struct vnode *)fp->f_data)->v_mount; + mp = fp->f_vnode->v_mount; fdrop(fp, td); if (mp == NULL) return (EBADF); @@ -403,7 +403,7 @@ fchdir(td, uap) if ((error = getvnode(fdp, uap->fd, &fp)) != 0) return (error); - vp = fp->f_data; + vp = fp->f_vnode; VREF(vp); fdrop(fp, td); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td); @@ -502,7 +502,7 @@ chroot_refuse_vdir_fds(fdp) if (fp == NULL) continue; if (fp->f_type == DTYPE_VNODE) { - vp = fp->f_data; + vp = fp->f_vnode; if (vp->v_type == VDIR) return (EPERM); } @@ -745,6 +745,7 @@ kern_open(struct thread *td, char *path, enum uio_seg pathseg, int flags, td->td_retval[0] = indx; return 0; } + fp->f_vnode = vp; fp->f_data = vp; fp->f_flag = flags & FMASK; fp->f_ops = &vnops; @@ -1346,7 +1347,7 @@ lseek(td, uap) fdrop(fp, td); return (ESPIPE); } - vp = fp->f_data; + vp = fp->f_vnode; noneg = (vp->v_type != VCHR); offset = uap->offset; switch (uap->whence) { @@ -2056,7 +2057,7 @@ fchflags(td, uap) if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0) return (error); - error = setfflags(td, fp->f_data, uap->flags); + error = setfflags(td, fp->f_vnode, uap->flags); fdrop(fp, td); return (error); } @@ -2180,7 +2181,7 @@ fchmod(td, uap) if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0) return (error); - error = setfmode(td, fp->f_data, uap->mode); + error = setfmode(td, fp->f_vnode, uap->mode); fdrop(fp, td); return (error); } @@ -2322,7 +2323,7 @@ fchown(td, uap) if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0) return (error); - error = setfown(td, fp->f_data, uap->uid, uap->gid); + error = setfown(td, fp->f_vnode, uap->uid, uap->gid); fdrop(fp, td); return (error); } @@ -2520,7 +2521,7 @@ kern_futimes(struct thread *td, int fd, struct timeval *tptr, return (error); if ((error = getvnode(td->td_proc->p_fd, fd, &fp)) != 0) return (error); - error = setutimes(td, fp->f_data, ts, 2, tptr == NULL); + error = setutimes(td, fp->f_vnode, ts, 2, tptr == NULL); fdrop(fp, td); return (error); } @@ -2622,7 +2623,7 @@ ftruncate(td, uap) fdrop(fp, td); return (EINVAL); } - vp = fp->f_data; + vp = fp->f_vnode; if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0) { fdrop(fp, td); return (error); @@ -2733,7 +2734,7 @@ fsync(td, uap) if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0) return (error); - vp = fp->f_data; + vp = fp->f_vnode; if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0) { fdrop(fp, td); return (error); @@ -3096,7 +3097,7 @@ ogetdirentries(td, uap) fdrop(fp, td); return (EBADF); } - vp = fp->f_data; + vp = fp->f_vnode; unionread: if (vp->v_type != VDIR) { fdrop(fp, td); @@ -3196,6 +3197,7 @@ unionread: struct vnode *tvp = vp; vp = vp->v_mount->mnt_vnodecovered; VREF(vp); + fp->f_vnode = vp; fp->f_data = vp; fp->f_offset = 0; vput(tvp); @@ -3244,7 +3246,7 @@ getdirentries(td, uap) fdrop(fp, td); return (EBADF); } - vp = fp->f_data; + vp = fp->f_vnode; unionread: if (vp->v_type != VDIR) { fdrop(fp, td); @@ -3293,6 +3295,7 @@ unionread: struct vnode *tvp = vp; vp = vp->v_mount->mnt_vnodecovered; VREF(vp); + fp->f_vnode = vp; fp->f_data = vp; fp->f_offset = 0; vput(tvp); @@ -3646,6 +3649,7 @@ fhopen(td, uap) * from under us while we block in the lock op */ fhold(fp); + nfp->f_vnode = vp; nfp->f_data = vp; nfp->f_flag = fmode & FMASK; nfp->f_ops = &vnops; @@ -3967,7 +3971,7 @@ extattr_set_fd(td, uap) if (error) return (error); - error = extattr_set_vp(fp->f_data, uap->attrnamespace, + error = extattr_set_vp(fp->f_vnode, uap->attrnamespace, attrname, uap->data, uap->nbytes, td); fdrop(fp, td); @@ -4140,7 +4144,7 @@ extattr_get_fd(td, uap) if (error) return (error); - error = extattr_get_vp(fp->f_data, uap->attrnamespace, + error = extattr_get_vp(fp->f_vnode, uap->attrnamespace, attrname, uap->data, uap->nbytes, td); fdrop(fp, td); @@ -4272,7 +4276,7 @@ extattr_delete_fd(td, uap) error = getvnode(td->td_proc->p_fd, uap->fd, &fp); if (error) return (error); - vp = fp->f_data; + vp = fp->f_vnode; error = extattr_delete_vp(vp, uap->attrnamespace, attrname, td); fdrop(fp, td); @@ -4418,7 +4422,7 @@ extattr_list_fd(td, uap) if (error) return (error); - error = extattr_list_vp(fp->f_data, uap->attrnamespace, uap->data, + error = extattr_list_vp(fp->f_vnode, uap->attrnamespace, uap->data, uap->nbytes, td); fdrop(fp, td); diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index 786fad1..8d8f13d 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -510,7 +510,7 @@ vn_read(fp, uio, active_cred, flags, td) mtx_lock(&Giant); KASSERT(uio->uio_td == td, ("uio_td %p is not td %p", uio->uio_td, td)); - vp = fp->f_data; + vp = fp->f_vnode; ioflag = 0; if (fp->f_flag & FNONBLOCK) ioflag |= IO_NDELAY; @@ -560,7 +560,7 @@ vn_write(fp, uio, active_cred, flags, td) mtx_lock(&Giant); KASSERT(uio->uio_td == td, ("uio_td %p is not td %p", uio->uio_td, td)); - vp = fp->f_data; + vp = fp->f_vnode; if (vp->v_type == VREG) bwillwrite(); ioflag = IO_UNIT; @@ -608,7 +608,7 @@ vn_statfile(fp, sb, active_cred, td) struct ucred *active_cred; struct thread *td; { - struct vnode *vp = fp->f_data; + struct vnode *vp = fp->f_vnode; int error; vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td); @@ -751,7 +751,7 @@ vn_ioctl(fp, com, data, active_cred, td) struct ucred *active_cred; struct thread *td; { - struct vnode *vp = fp->f_data; + struct vnode *vp = fp->f_vnode; struct vnode *vpold; struct vattr vattr; int error; @@ -833,7 +833,7 @@ vn_poll(fp, events, active_cred, td) int error; #endif - vp = fp->f_data; + vp = fp->f_vnode; #ifdef MAC vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td); error = mac_check_vnode_poll(active_cred, fp->f_cred, vp); @@ -901,7 +901,7 @@ vn_closefile(fp, td) { fp->f_ops = &badfileops; - return (vn_close(fp->f_data, fp->f_flag, fp->f_cred, td)); + return (vn_close(fp->f_vnode, fp->f_flag, fp->f_cred, td)); } /* @@ -1052,7 +1052,7 @@ static int vn_kqfilter(struct file *fp, struct knote *kn) { - return (VOP_KQFILTER(fp->f_data, kn)); + return (VOP_KQFILTER(fp->f_vnode, kn)); } /* diff --git a/sys/netsmb/smb_dev.c b/sys/netsmb/smb_dev.c index 7afff66..12cf996 100644 --- a/sys/netsmb/smb_dev.c +++ b/sys/netsmb/smb_dev.c @@ -389,7 +389,7 @@ smb_dev2share(int fd, int mode, struct smb_cred *scred, fp = nsmb_getfp(scred->scr_td->td_proc->p_fd, fd, FREAD | FWRITE); if (fp == NULL) return EBADF; - vp = fp->f_data; + vp = fp->f_vnode; if (vp == NULL) { fdrop(fp, curthread); return EBADF; diff --git a/sys/security/mac/mac_framework.c b/sys/security/mac/mac_framework.c index e5e25dc..79a12ec 100644 --- a/sys/security/mac/mac_framework.c +++ b/sys/security/mac/mac_framework.c @@ -3496,7 +3496,7 @@ __mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap) switch (fp->f_type) { case DTYPE_FIFO: case DTYPE_VNODE: - vp = fp->f_data; + vp = fp->f_vnode; mac_init_vnode_label(&intlabel); @@ -3704,7 +3704,7 @@ __mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap) break; } - vp = fp->f_data; + vp = fp->f_vnode; error = vn_start_write(vp, &mp, V_WAIT | PCATCH); if (error != 0) { mac_destroy_vnode_label(&intlabel); diff --git a/sys/security/mac/mac_internal.h b/sys/security/mac/mac_internal.h index e5e25dc..79a12ec 100644 --- a/sys/security/mac/mac_internal.h +++ b/sys/security/mac/mac_internal.h @@ -3496,7 +3496,7 @@ __mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap) switch (fp->f_type) { case DTYPE_FIFO: case DTYPE_VNODE: - vp = fp->f_data; + vp = fp->f_vnode; mac_init_vnode_label(&intlabel); @@ -3704,7 +3704,7 @@ __mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap) break; } - vp = fp->f_data; + vp = fp->f_vnode; error = vn_start_write(vp, &mp, V_WAIT | PCATCH); if (error != 0) { mac_destroy_vnode_label(&intlabel); diff --git a/sys/security/mac/mac_net.c b/sys/security/mac/mac_net.c index e5e25dc..79a12ec 100644 --- a/sys/security/mac/mac_net.c +++ b/sys/security/mac/mac_net.c @@ -3496,7 +3496,7 @@ __mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap) switch (fp->f_type) { case DTYPE_FIFO: case DTYPE_VNODE: - vp = fp->f_data; + vp = fp->f_vnode; mac_init_vnode_label(&intlabel); @@ -3704,7 +3704,7 @@ __mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap) break; } - vp = fp->f_data; + vp = fp->f_vnode; error = vn_start_write(vp, &mp, V_WAIT | PCATCH); if (error != 0) { mac_destroy_vnode_label(&intlabel); diff --git a/sys/security/mac/mac_pipe.c b/sys/security/mac/mac_pipe.c index e5e25dc..79a12ec 100644 --- a/sys/security/mac/mac_pipe.c +++ b/sys/security/mac/mac_pipe.c @@ -3496,7 +3496,7 @@ __mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap) switch (fp->f_type) { case DTYPE_FIFO: case DTYPE_VNODE: - vp = fp->f_data; + vp = fp->f_vnode; mac_init_vnode_label(&intlabel); @@ -3704,7 +3704,7 @@ __mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap) break; } - vp = fp->f_data; + vp = fp->f_vnode; error = vn_start_write(vp, &mp, V_WAIT | PCATCH); if (error != 0) { mac_destroy_vnode_label(&intlabel); diff --git a/sys/security/mac/mac_process.c b/sys/security/mac/mac_process.c index e5e25dc..79a12ec 100644 --- a/sys/security/mac/mac_process.c +++ b/sys/security/mac/mac_process.c @@ -3496,7 +3496,7 @@ __mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap) switch (fp->f_type) { case DTYPE_FIFO: case DTYPE_VNODE: - vp = fp->f_data; + vp = fp->f_vnode; mac_init_vnode_label(&intlabel); @@ -3704,7 +3704,7 @@ __mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap) break; } - vp = fp->f_data; + vp = fp->f_vnode; error = vn_start_write(vp, &mp, V_WAIT | PCATCH); if (error != 0) { mac_destroy_vnode_label(&intlabel); diff --git a/sys/security/mac/mac_syscalls.c b/sys/security/mac/mac_syscalls.c index e5e25dc..79a12ec 100644 --- a/sys/security/mac/mac_syscalls.c +++ b/sys/security/mac/mac_syscalls.c @@ -3496,7 +3496,7 @@ __mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap) switch (fp->f_type) { case DTYPE_FIFO: case DTYPE_VNODE: - vp = fp->f_data; + vp = fp->f_vnode; mac_init_vnode_label(&intlabel); @@ -3704,7 +3704,7 @@ __mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap) break; } - vp = fp->f_data; + vp = fp->f_vnode; error = vn_start_write(vp, &mp, V_WAIT | PCATCH); if (error != 0) { mac_destroy_vnode_label(&intlabel); diff --git a/sys/security/mac/mac_system.c b/sys/security/mac/mac_system.c index e5e25dc..79a12ec 100644 --- a/sys/security/mac/mac_system.c +++ b/sys/security/mac/mac_system.c @@ -3496,7 +3496,7 @@ __mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap) switch (fp->f_type) { case DTYPE_FIFO: case DTYPE_VNODE: - vp = fp->f_data; + vp = fp->f_vnode; mac_init_vnode_label(&intlabel); @@ -3704,7 +3704,7 @@ __mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap) break; } - vp = fp->f_data; + vp = fp->f_vnode; error = vn_start_write(vp, &mp, V_WAIT | PCATCH); if (error != 0) { mac_destroy_vnode_label(&intlabel); diff --git a/sys/security/mac/mac_vfs.c b/sys/security/mac/mac_vfs.c index e5e25dc..79a12ec 100644 --- a/sys/security/mac/mac_vfs.c +++ b/sys/security/mac/mac_vfs.c @@ -3496,7 +3496,7 @@ __mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap) switch (fp->f_type) { case DTYPE_FIFO: case DTYPE_VNODE: - vp = fp->f_data; + vp = fp->f_vnode; mac_init_vnode_label(&intlabel); @@ -3704,7 +3704,7 @@ __mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap) break; } - vp = fp->f_data; + vp = fp->f_vnode; error = vn_start_write(vp, &mp, V_WAIT | PCATCH); if (error != 0) { mac_destroy_vnode_label(&intlabel); diff --git a/sys/sys/file.h b/sys/sys/file.h index 71170bd..0b71ab6 100644 --- a/sys/sys/file.h +++ b/sys/sys/file.h @@ -116,6 +116,7 @@ struct file { struct fileops *f_ops; /* File operations */ struct ucred *f_cred; /* credentials associated with descriptor */ int f_count; /* (f) reference count */ + struct vnode *f_vnode; /* NULL or applicable vnode */ /* DFLAG_SEEKABLE specific fields */ off_t f_offset; diff --git a/sys/vm/vm_mmap.c b/sys/vm/vm_mmap.c index 7e446d1..af0d0ab 100644 --- a/sys/vm/vm_mmap.c +++ b/sys/vm/vm_mmap.c @@ -313,7 +313,7 @@ mmap(td, uap) */ if (fp->f_flag & FPOSIXSHM) flags |= MAP_NOSYNC; - vp = fp->f_data; + vp = fp->f_vnode; error = vget(vp, LK_EXCLUSIVE, td); if (error) goto done; -- cgit v1.1