Add a vnode** argument to getvnode(), prototype it, and make it return
EBADF if the file descriptor has been revoked.
This commit is contained in:
parent
bd587f836f
commit
99686e0059
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: svr4_misc.c,v 1.29 1995/10/14 20:24:35 christos Exp $ */
|
/* $NetBSD: svr4_misc.c,v 1.30 1996/01/30 20:05:33 mycroft Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1994 Christos Zoulas
|
* Copyright (c) 1994 Christos Zoulas
|
||||||
@ -210,14 +210,12 @@ svr4_sys_getdents(p, v, retval)
|
|||||||
u_long *cookiebuf, *cookie;
|
u_long *cookiebuf, *cookie;
|
||||||
int ncookies;
|
int ncookies;
|
||||||
|
|
||||||
if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
|
if (error = getvnode(p->p_fd, SCARG(uap, fd), &vp, &fp))
|
||||||
return (error);
|
return (error);
|
||||||
|
|
||||||
if ((fp->f_flag & FREAD) == 0)
|
if ((fp->f_flag & FREAD) == 0)
|
||||||
return (EBADF);
|
return (EBADF);
|
||||||
|
|
||||||
vp = (struct vnode *)fp->f_data;
|
|
||||||
|
|
||||||
if (vp->v_type != VDIR) /* XXX vnode readdir op should do this */
|
if (vp->v_type != VDIR) /* XXX vnode readdir op should do this */
|
||||||
return (EINVAL);
|
return (EINVAL);
|
||||||
|
|
||||||
@ -343,11 +341,10 @@ svr4_sys_fchroot(p, v, retval)
|
|||||||
struct file *fp;
|
struct file *fp;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
|
if (error = suser(p->p_ucred, &p->p_acflag))
|
||||||
return error;
|
return error;
|
||||||
if ((error = getvnode(fdp, SCARG(uap, fd), &fp)) != 0)
|
if (error = getvnode(fdp, SCARG(uap, fd), &vp, &fp))
|
||||||
return error;
|
return error;
|
||||||
vp = (struct vnode *) fp->f_data;
|
|
||||||
VOP_LOCK(vp);
|
VOP_LOCK(vp);
|
||||||
if (vp->v_type != VDIR)
|
if (vp->v_type != VDIR)
|
||||||
error = ENOTDIR;
|
error = ENOTDIR;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: vfs_syscalls.c,v 1.59 1995/11/11 22:00:18 mycroft Exp $ */
|
/* $NetBSD: vfs_syscalls.c,v 1.60 1996/01/30 20:05:38 mycroft Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1989, 1993
|
* Copyright (c) 1989, 1993
|
||||||
@ -523,14 +523,15 @@ sys_fstatfs(p, v, retval)
|
|||||||
syscallarg(int) fd;
|
syscallarg(int) fd;
|
||||||
syscallarg(struct statfs *) buf;
|
syscallarg(struct statfs *) buf;
|
||||||
} */ *uap = v;
|
} */ *uap = v;
|
||||||
|
struct vnode *vp;
|
||||||
struct file *fp;
|
struct file *fp;
|
||||||
struct mount *mp;
|
struct mount *mp;
|
||||||
register struct statfs *sp;
|
register struct statfs *sp;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
if (error = getvnode(p->p_fd, SCARG(uap, fd), &fp))
|
if (error = getvnode(p->p_fd, SCARG(uap, fd), &vp, &fp))
|
||||||
return (error);
|
return (error);
|
||||||
mp = ((struct vnode *)fp->f_data)->v_mount;
|
mp = vp->v_mount;
|
||||||
sp = &mp->mnt_stat;
|
sp = &mp->mnt_stat;
|
||||||
if (error = VFS_STATFS(mp, sp, p))
|
if (error = VFS_STATFS(mp, sp, p))
|
||||||
return (error);
|
return (error);
|
||||||
@ -604,9 +605,8 @@ sys_fchdir(p, v, retval)
|
|||||||
struct file *fp;
|
struct file *fp;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
if (error = getvnode(fdp, SCARG(uap, fd), &fp))
|
if (error = getvnode(fdp, SCARG(uap, fd), &vp, &fp))
|
||||||
return (error);
|
return (error);
|
||||||
vp = (struct vnode *)fp->f_data;
|
|
||||||
VREF(vp);
|
VREF(vp);
|
||||||
VOP_LOCK(vp);
|
VOP_LOCK(vp);
|
||||||
if (vp->v_type != VDIR)
|
if (vp->v_type != VDIR)
|
||||||
@ -1383,9 +1383,8 @@ sys_fchflags(p, v, retval)
|
|||||||
struct file *fp;
|
struct file *fp;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
if (error = getvnode(p->p_fd, SCARG(uap, fd), &fp))
|
if (error = getvnode(p->p_fd, SCARG(uap, fd), &vp, &fp))
|
||||||
return (error);
|
return (error);
|
||||||
vp = (struct vnode *)fp->f_data;
|
|
||||||
VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
|
VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
|
||||||
VOP_LOCK(vp);
|
VOP_LOCK(vp);
|
||||||
if (vp->v_mount->mnt_flag & MNT_RDONLY)
|
if (vp->v_mount->mnt_flag & MNT_RDONLY)
|
||||||
@ -1452,9 +1451,8 @@ sys_fchmod(p, v, retval)
|
|||||||
struct file *fp;
|
struct file *fp;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
if (error = getvnode(p->p_fd, SCARG(uap, fd), &fp))
|
if (error = getvnode(p->p_fd, SCARG(uap, fd), &vp, &fp))
|
||||||
return (error);
|
return (error);
|
||||||
vp = (struct vnode *)fp->f_data;
|
|
||||||
VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
|
VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
|
||||||
VOP_LOCK(vp);
|
VOP_LOCK(vp);
|
||||||
if (vp->v_mount->mnt_flag & MNT_RDONLY)
|
if (vp->v_mount->mnt_flag & MNT_RDONLY)
|
||||||
@ -1524,9 +1522,8 @@ sys_fchown(p, v, retval)
|
|||||||
struct file *fp;
|
struct file *fp;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
if (error = getvnode(p->p_fd, SCARG(uap, fd), &fp))
|
if (error = getvnode(p->p_fd, SCARG(uap, fd), &vp, &fp))
|
||||||
return (error);
|
return (error);
|
||||||
vp = (struct vnode *)fp->f_data;
|
|
||||||
VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
|
VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
|
||||||
VOP_LOCK(vp);
|
VOP_LOCK(vp);
|
||||||
if (vp->v_mount->mnt_flag & MNT_RDONLY)
|
if (vp->v_mount->mnt_flag & MNT_RDONLY)
|
||||||
@ -1643,11 +1640,10 @@ sys_ftruncate(p, v, retval)
|
|||||||
struct file *fp;
|
struct file *fp;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
if (error = getvnode(p->p_fd, SCARG(uap, fd), &fp))
|
if (error = getvnode(p->p_fd, SCARG(uap, fd), &vp, &fp))
|
||||||
return (error);
|
return (error);
|
||||||
if ((fp->f_flag & FWRITE) == 0)
|
if ((fp->f_flag & FWRITE) == 0)
|
||||||
return (EINVAL);
|
return (EINVAL);
|
||||||
vp = (struct vnode *)fp->f_data;
|
|
||||||
VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
|
VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
|
||||||
VOP_LOCK(vp);
|
VOP_LOCK(vp);
|
||||||
if (vp->v_type == VDIR)
|
if (vp->v_type == VDIR)
|
||||||
@ -1673,13 +1669,12 @@ sys_fsync(p, v, retval)
|
|||||||
struct sys_fsync_args /* {
|
struct sys_fsync_args /* {
|
||||||
syscallarg(int) fd;
|
syscallarg(int) fd;
|
||||||
} */ *uap = v;
|
} */ *uap = v;
|
||||||
register struct vnode *vp;
|
struct vnode *vp;
|
||||||
struct file *fp;
|
struct file *fp;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
if (error = getvnode(p->p_fd, SCARG(uap, fd), &fp))
|
if (error = getvnode(p->p_fd, SCARG(uap, fd), &vp, &fp))
|
||||||
return (error);
|
return (error);
|
||||||
vp = (struct vnode *)fp->f_data;
|
|
||||||
VOP_LOCK(vp);
|
VOP_LOCK(vp);
|
||||||
error = VOP_FSYNC(vp, fp->f_cred, MNT_WAIT, p);
|
error = VOP_FSYNC(vp, fp->f_cred, MNT_WAIT, p);
|
||||||
VOP_UNLOCK(vp);
|
VOP_UNLOCK(vp);
|
||||||
@ -1880,18 +1875,17 @@ sys_getdirentries(p, v, retval)
|
|||||||
syscallarg(u_int) count;
|
syscallarg(u_int) count;
|
||||||
syscallarg(long *) basep;
|
syscallarg(long *) basep;
|
||||||
} */ *uap = v;
|
} */ *uap = v;
|
||||||
register struct vnode *vp;
|
struct vnode *vp;
|
||||||
struct file *fp;
|
struct file *fp;
|
||||||
struct uio auio;
|
struct uio auio;
|
||||||
struct iovec aiov;
|
struct iovec aiov;
|
||||||
long loff;
|
long loff;
|
||||||
int error, eofflag;
|
int error, eofflag;
|
||||||
|
|
||||||
if (error = getvnode(p->p_fd, SCARG(uap, fd), &fp))
|
if (error = getvnode(p->p_fd, SCARG(uap, fd), &vp, &fp))
|
||||||
return (error);
|
return (error);
|
||||||
if ((fp->f_flag & FREAD) == 0)
|
if ((fp->f_flag & FREAD) == 0)
|
||||||
return (EBADF);
|
return (EBADF);
|
||||||
vp = (struct vnode *)fp->f_data;
|
|
||||||
unionread:
|
unionread:
|
||||||
if (vp->v_type != VDIR)
|
if (vp->v_type != VDIR)
|
||||||
return (EINVAL);
|
return (EINVAL);
|
||||||
@ -2033,11 +2027,14 @@ out:
|
|||||||
/*
|
/*
|
||||||
* Convert a user file descriptor to a kernel file entry.
|
* Convert a user file descriptor to a kernel file entry.
|
||||||
*/
|
*/
|
||||||
getvnode(fdp, fd, fpp)
|
int
|
||||||
|
getvnode(fdp, fd, vpp, fpp)
|
||||||
struct filedesc *fdp;
|
struct filedesc *fdp;
|
||||||
struct file **fpp;
|
|
||||||
int fd;
|
int fd;
|
||||||
|
struct vnode **vpp;
|
||||||
|
struct file **fpp;
|
||||||
{
|
{
|
||||||
|
struct vnode *vp;
|
||||||
struct file *fp;
|
struct file *fp;
|
||||||
|
|
||||||
if ((u_int)fd >= fdp->fd_nfiles ||
|
if ((u_int)fd >= fdp->fd_nfiles ||
|
||||||
@ -2045,6 +2042,10 @@ getvnode(fdp, fd, fpp)
|
|||||||
return (EBADF);
|
return (EBADF);
|
||||||
if (fp->f_type != DTYPE_VNODE)
|
if (fp->f_type != DTYPE_VNODE)
|
||||||
return (EINVAL);
|
return (EINVAL);
|
||||||
|
vp = (struct vnode *)fp->f_data;
|
||||||
|
if (vp->v_type == VBAD)
|
||||||
|
return (EBADF);
|
||||||
|
*vpp = vp;
|
||||||
*fpp = fp;
|
*fpp = fp;
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: vnode.h,v 1.32 1995/03/26 20:25:05 jtc Exp $ */
|
/* $NetBSD: vnode.h,v 1.33 1996/01/30 20:05:43 mycroft Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1989, 1993
|
* Copyright (c) 1989, 1993
|
||||||
@ -349,6 +349,7 @@ struct vop_generic_args {
|
|||||||
* Public vnode manipulation functions.
|
* Public vnode manipulation functions.
|
||||||
*/
|
*/
|
||||||
struct file;
|
struct file;
|
||||||
|
struct filedesc;
|
||||||
struct mount;
|
struct mount;
|
||||||
struct nameidata;
|
struct nameidata;
|
||||||
struct proc;
|
struct proc;
|
||||||
@ -363,6 +364,8 @@ int bdevvp __P((dev_t dev, struct vnode **vpp));
|
|||||||
int cdevvp __P((dev_t dev, struct vnode **vpp));
|
int cdevvp __P((dev_t dev, struct vnode **vpp));
|
||||||
int getnewvnode __P((enum vtagtype tag,
|
int getnewvnode __P((enum vtagtype tag,
|
||||||
struct mount *mp, int (**vops)(), struct vnode **vpp));
|
struct mount *mp, int (**vops)(), struct vnode **vpp));
|
||||||
|
int getvnode __P((struct filedesc *fdp,
|
||||||
|
int fd, struct vnode **vpp, struct file **fpp));
|
||||||
void vattr_null __P((struct vattr *vap));
|
void vattr_null __P((struct vattr *vap));
|
||||||
int vcount __P((struct vnode *vp));
|
int vcount __P((struct vnode *vp));
|
||||||
void vflushbuf __P((struct vnode *vp, int sync));
|
void vflushbuf __P((struct vnode *vp, int sync));
|
||||||
|
Loading…
Reference in New Issue
Block a user