summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>2002-08-23 15:39:32 +0000
committerArtur Grabowski <art@cvs.openbsd.org>2002-08-23 15:39:32 +0000
commit0037f572cfa2fac5d4856ab2774b5d879e46d2c0 (patch)
treebc73652b01ced4a34b60e13f5c0fcebf6c03654d /sys
parent557b435e5b58e8c4514957fceb7d44dc55877d99 (diff)
Cleanup change. Since almost all callers (except one) of getvnode did a FREF
on the returned file, do the FREF inside getvnode so that people can't get away with avoiding FREF and FRELE. Eyeballed by various people.
Diffstat (limited to 'sys')
-rw-r--r--sys/compat/common/vfs_syscalls_25.c3
-rw-r--r--sys/compat/common/vfs_syscalls_43.c9
-rw-r--r--sys/compat/freebsd/freebsd_file.c3
-rw-r--r--sys/compat/ibcs2/ibcs2_misc.c15
-rw-r--r--sys/compat/ibcs2/ibcs2_stat.c3
-rw-r--r--sys/compat/linux/linux_misc.c3
-rw-r--r--sys/compat/netbsd/netbsd_file.c3
-rw-r--r--sys/compat/netbsd/netbsd_getdents.c10
-rw-r--r--sys/compat/osf1/osf1_mount.c3
-rw-r--r--sys/compat/sunos/sunos_misc.c12
-rw-r--r--sys/compat/svr4/svr4_misc.c6
-rw-r--r--sys/compat/ultrix/ultrix_pathname.c4
-rw-r--r--sys/kern/vfs_syscalls.c32
-rw-r--r--sys/miscfs/fdesc/fdesc_vnops.c3
14 files changed, 52 insertions, 57 deletions
diff --git a/sys/compat/common/vfs_syscalls_25.c b/sys/compat/common/vfs_syscalls_25.c
index 73178f3e59d..e197407dbc4 100644
--- a/sys/compat/common/vfs_syscalls_25.c
+++ b/sys/compat/common/vfs_syscalls_25.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfs_syscalls_25.c,v 1.3 2002/03/14 01:26:49 millert Exp $ */
+/* $OpenBSD: vfs_syscalls_25.c,v 1.4 2002/08/23 15:39:31 art Exp $ */
/*
* Copyright (c) 1989, 1993
@@ -147,7 +147,6 @@ compat_25_sys_fstatfs(p, v, retval)
if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
return (error);
- FREF(fp);
mp = ((struct vnode *)fp->f_data)->v_mount;
sp = &mp->mnt_stat;
error = VFS_STATFS(mp, sp, p);
diff --git a/sys/compat/common/vfs_syscalls_43.c b/sys/compat/common/vfs_syscalls_43.c
index cf9a4b229a3..1e6d437229b 100644
--- a/sys/compat/common/vfs_syscalls_43.c
+++ b/sys/compat/common/vfs_syscalls_43.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfs_syscalls_43.c,v 1.19 2002/03/14 01:26:49 millert Exp $ */
+/* $OpenBSD: vfs_syscalls_43.c,v 1.20 2002/08/23 15:39:31 art Exp $ */
/* $NetBSD: vfs_syscalls_43.c,v 1.4 1996/03/14 19:31:52 christos Exp $ */
/*
@@ -355,9 +355,10 @@ compat_43_sys_getdirentries(p, v, retval)
if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
return (error);
- if ((fp->f_flag & FREAD) == 0)
- return (EBADF);
- FREF(fp);
+ if ((fp->f_flag & FREAD) == 0) {
+ error = EBADF;
+ goto bad;
+ }
vp = (struct vnode *)fp->f_data;
unionread:
if (vp->v_type != VDIR) {
diff --git a/sys/compat/freebsd/freebsd_file.c b/sys/compat/freebsd/freebsd_file.c
index 058a9e3785f..50284f65de6 100644
--- a/sys/compat/freebsd/freebsd_file.c
+++ b/sys/compat/freebsd/freebsd_file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: freebsd_file.c,v 1.15 2002/03/14 01:26:49 millert Exp $ */
+/* $OpenBSD: freebsd_file.c,v 1.16 2002/08/23 15:39:31 art Exp $ */
/* $NetBSD: freebsd_file.c,v 1.3 1996/05/03 17:03:09 christos Exp $ */
/*
@@ -623,7 +623,6 @@ freebsd_sys_fstatfs(p, v, retval)
return (error);
mp = ((struct vnode *)fp->f_data)->v_mount;
sp = &mp->mnt_stat;
- FREF(fp);
error = VFS_STATFS(mp, sp, p);
FRELE(fp);
if (error)
diff --git a/sys/compat/ibcs2/ibcs2_misc.c b/sys/compat/ibcs2/ibcs2_misc.c
index b8c82282267..2f1de1686c8 100644
--- a/sys/compat/ibcs2/ibcs2_misc.c
+++ b/sys/compat/ibcs2/ibcs2_misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ibcs2_misc.c,v 1.24 2002/04/25 21:01:41 espie Exp $ */
+/* $OpenBSD: ibcs2_misc.c,v 1.25 2002/08/23 15:39:31 art Exp $ */
/* $NetBSD: ibcs2_misc.c,v 1.23 1997/01/15 01:37:49 perry Exp $ */
/*
@@ -434,7 +434,6 @@ ibcs2_sys_getdents(p, v, retval)
if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
return (error);
- FREF(fp);
args.resid = SCARG(uap, nbytes);
args.outp = (caddr_t)SCARG(uap, buf);
error = readdir_with_callback(fp, &fp->f_offset, args.resid,
@@ -469,18 +468,22 @@ ibcs2_sys_read(p, v, retval)
else
return error;
}
- if ((fp->f_flag & FREAD) == 0)
- return (EBADF);
+ if ((fp->f_flag & FREAD) == 0) {
+ error = EBADF;
+ goto bad;
+ }
vp = (struct vnode *)fp->f_data;
- if (vp->v_type != VDIR)
+ if (vp->v_type != VDIR) {
+ FRELE(fp);
return sys_read(p, uap, retval);
+ }
- FREF(fp);
args.resid = SCARG(uap, nbytes);
args.outp = (caddr_t)SCARG(uap, buf);
error = readdir_with_callback(fp, &fp->f_offset, args.resid,
ibcs2_classicread_callback, &args);
+bad:
FRELE(fp);
if (error)
return (error);
diff --git a/sys/compat/ibcs2/ibcs2_stat.c b/sys/compat/ibcs2/ibcs2_stat.c
index 366f49f7a10..b4285a31b73 100644
--- a/sys/compat/ibcs2/ibcs2_stat.c
+++ b/sys/compat/ibcs2/ibcs2_stat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ibcs2_stat.c,v 1.10 2002/08/02 18:06:25 millert Exp $ */
+/* $OpenBSD: ibcs2_stat.c,v 1.11 2002/08/23 15:39:31 art Exp $ */
/* $NetBSD: ibcs2_stat.c,v 1.5 1996/05/03 17:05:32 christos Exp $ */
/*
@@ -154,7 +154,6 @@ ibcs2_sys_fstatfs(p, v, retval)
return (error);
mp = ((struct vnode *)fp->f_data)->v_mount;
sp = &mp->mnt_stat;
- FREF(fp);
error = VFS_STATFS(mp, sp, p);
FRELE(fp);
if (error)
diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c
index 31fe8cc71fd..d392fc85dda 100644
--- a/sys/compat/linux/linux_misc.c
+++ b/sys/compat/linux/linux_misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: linux_misc.c,v 1.44 2002/07/25 22:18:27 nordin Exp $ */
+/* $OpenBSD: linux_misc.c,v 1.45 2002/08/23 15:39:31 art Exp $ */
/* $NetBSD: linux_misc.c,v 1.27 1996/05/20 01:59:21 fvdl Exp $ */
/*
@@ -1021,7 +1021,6 @@ linux_sys_getdents(p, v, retval)
args.resid = nbytes;
args.outp = (caddr_t)SCARG(uap, dirent);
- FREF(fp);
if ((error = readdir_with_callback(fp, &fp->f_offset, nbytes,
linux_readdir_callback, &args)) != 0)
goto exit;
diff --git a/sys/compat/netbsd/netbsd_file.c b/sys/compat/netbsd/netbsd_file.c
index 65f6f7c77bf..fc1268bbc87 100644
--- a/sys/compat/netbsd/netbsd_file.c
+++ b/sys/compat/netbsd/netbsd_file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: netbsd_file.c,v 1.3 2002/03/14 01:26:50 millert Exp $ */
+/* $OpenBSD: netbsd_file.c,v 1.4 2002/08/23 15:39:31 art Exp $ */
/* $NetBSD: freebsd_file.c,v 1.3 1996/05/03 17:03:09 christos Exp $ */
/*
@@ -597,7 +597,6 @@ netbsd_sys_fstatfs(p, v, retval)
return (error);
mp = ((struct vnode *)fp->f_data)->v_mount;
sp = &mp->mnt_stat;
- FREF(fp);
error = VFS_STATFS(mp, sp, p);
FRELE(fp);
if (error)
diff --git a/sys/compat/netbsd/netbsd_getdents.c b/sys/compat/netbsd/netbsd_getdents.c
index 50d89dfd5ff..9b735ca5aee 100644
--- a/sys/compat/netbsd/netbsd_getdents.c
+++ b/sys/compat/netbsd/netbsd_getdents.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: netbsd_getdents.c,v 1.6 2002/03/14 01:26:50 millert Exp $ */
+/* $OpenBSD: netbsd_getdents.c,v 1.7 2002/08/23 15:39:31 art Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1993
@@ -165,12 +165,14 @@ netbsd_sys_getdents(p, v, retval)
if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
return (error);
- if ((fp->f_flag & FREAD) == 0)
- return (EBADF);
- FREF(fp);
+ if ((fp->f_flag & FREAD) == 0) {
+ error = EBADF;
+ goto bad;
+ }
error = netbsd_vn_readdir(fp, SCARG(uap, buf), UIO_USERSPACE,
SCARG(uap, count), &done, p, 0, 0);
*retval = done;
+bad:
FRELE(fp);
return (error);
}
diff --git a/sys/compat/osf1/osf1_mount.c b/sys/compat/osf1/osf1_mount.c
index c3a4e3ca43a..e30736e0b33 100644
--- a/sys/compat/osf1/osf1_mount.c
+++ b/sys/compat/osf1/osf1_mount.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: osf1_mount.c,v 1.8 2002/03/14 01:26:50 millert Exp $ */
+/* $OpenBSD: osf1_mount.c,v 1.9 2002/08/23 15:39:31 art Exp $ */
/* $NetBSD: osf1_mount.c,v 1.14 1999/05/05 01:51:34 cgd Exp $ */
/*
@@ -122,7 +122,6 @@ osf1_sys_fstatfs(p, v, retval)
return (error);
mp = ((struct vnode *)fp->f_data)->v_mount;
sp = &mp->mnt_stat;
- FREF(fp);
error = VFS_STATFS(mp, sp, p);
FRELE(fp);
if (error)
diff --git a/sys/compat/sunos/sunos_misc.c b/sys/compat/sunos/sunos_misc.c
index 330f38a1a18..a1d582100ce 100644
--- a/sys/compat/sunos/sunos_misc.c
+++ b/sys/compat/sunos/sunos_misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sunos_misc.c,v 1.39 2002/08/23 01:13:09 pvalchev Exp $ */
+/* $OpenBSD: sunos_misc.c,v 1.40 2002/08/23 15:39:31 art Exp $ */
/* $NetBSD: sunos_misc.c,v 1.65 1996/04/22 01:44:31 christos Exp $ */
/*
@@ -436,15 +436,17 @@ sunos_sys_getdents(p, v, retval)
vp = (struct vnode *)fp->f_data;
/* SunOS returns ENOTDIR here, BSD would use EINVAL */
- if (vp->v_type != VDIR)
- return (ENOTDIR);
+ if (vp->v_type != VDIR) {
+ error = ENOTDIR;
+ goto bad;
+ }
args.resid = SCARG(uap, nbytes);
args.outp = (caddr_t)SCARG(uap, buf);
- FREF(fp);
error = readdir_with_callback(fp, &fp->f_offset, args.resid,
sunos_readdir_callback, &args);
+bad:
FRELE(fp);
if (error)
return (error);
@@ -596,7 +598,6 @@ sunos_sys_fchroot(p, v, retval)
if ((error = getvnode(fdp, SCARG(uap, fd), &fp)) != 0)
return (error);
vp = (struct vnode *)fp->f_data;
- FREF(fp);
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
if (vp->v_type != VDIR)
error = ENOTDIR;
@@ -864,7 +865,6 @@ sunos_sys_fstatfs(p, v, retval)
return (error);
mp = ((struct vnode *)fp->f_data)->v_mount;
sp = &mp->mnt_stat;
- FREF(fp);
error = VFS_STATFS(mp, sp, p);
FRELE(fp);
if (error)
diff --git a/sys/compat/svr4/svr4_misc.c b/sys/compat/svr4/svr4_misc.c
index bbe3f4264ea..ece88dfe61a 100644
--- a/sys/compat/svr4/svr4_misc.c
+++ b/sys/compat/svr4/svr4_misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: svr4_misc.c,v 1.41 2002/03/14 01:26:51 millert Exp $ */
+/* $OpenBSD: svr4_misc.c,v 1.42 2002/08/23 15:39:31 art Exp $ */
/* $NetBSD: svr4_misc.c,v 1.42 1996/12/06 03:22:34 christos Exp $ */
/*
@@ -305,7 +305,6 @@ svr4_sys_getdents(p, v, retval)
args.resid = SCARG(uap, nbytes);
args.outp = (caddr_t)SCARG(uap, buf);
- FREF(fp);
error = readdir_with_callback(fp, &fp->f_offset, SCARG(uap, nbytes),
svr4_readdir_callback, &args);
FRELE(fp);
@@ -334,7 +333,6 @@ svr4_sys_getdents64(p, v, retval)
args.resid = SCARG(uap, nbytes);
args.outp = (caddr_t)SCARG(uap, dp);
- FREF(fp);
error = readdir_with_callback(fp, &fp->f_offset, SCARG(uap, nbytes),
svr4_readdir64_callback, &args);
FRELE(fp);
@@ -430,7 +428,7 @@ svr4_sys_fchroot(p, v, retval)
return error;
if ((error = getvnode(fdp, SCARG(uap, fd), &fp)) != 0)
return error;
- FREF(fp);
+
vp = (struct vnode *) fp->f_data;
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
if (vp->v_type != VDIR)
diff --git a/sys/compat/ultrix/ultrix_pathname.c b/sys/compat/ultrix/ultrix_pathname.c
index ce2a88ea869..ac2260c702c 100644
--- a/sys/compat/ultrix/ultrix_pathname.c
+++ b/sys/compat/ultrix/ultrix_pathname.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ultrix_pathname.c,v 1.7 2002/02/13 19:08:06 art Exp $ */
+/* $OpenBSD: ultrix_pathname.c,v 1.8 2002/08/23 15:39:31 art Exp $ */
/* $NetBSD: ultrix_pathname.c,v 1.2 1996/04/07 17:23:07 jonathan Exp $ */
/*
@@ -284,7 +284,7 @@ ultrix_sys_fstatfs(p, v, retval)
if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
return (error);
- FREF(fp);
+
mp = ((struct vnode *)fp->f_data)->v_mount;
sp = &mp->mnt_stat;
error = VFS_STATFS(mp, sp, p);
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index 68f91738ade..b0998985e7c 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfs_syscalls.c,v 1.96 2002/07/12 14:02:22 art Exp $ */
+/* $OpenBSD: vfs_syscalls.c,v 1.97 2002/08/23 15:39:31 art Exp $ */
/* $NetBSD: vfs_syscalls.c,v 1.71 1996/04/23 10:29:02 mycroft Exp $ */
/*
@@ -612,7 +612,6 @@ sys_fstatfs(p, v, retval)
return (error);
mp = ((struct vnode *)fp->f_data)->v_mount;
sp = &mp->mnt_stat;
- FREF(fp);
error = VFS_STATFS(mp, sp, p);
FRELE(fp);
if (error)
@@ -728,9 +727,9 @@ sys_fchdir(p, v, retval)
if ((error = getvnode(fdp, SCARG(uap, fd), &fp)) != 0)
return (error);
- /* No need to FREF/FRELE since we VREF the vnode here. */
vp = (struct vnode *)fp->f_data;
VREF(vp);
+ FRELE(fp);
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
if (vp->v_type != VDIR)
error = ENOTDIR;
@@ -1809,7 +1808,6 @@ sys_fchflags(p, v, retval)
if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
return (error);
- FREF(fp);
vp = (struct vnode *)fp->f_data;
VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
@@ -1900,7 +1898,6 @@ sys_fchmod(p, v, retval)
if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
return (error);
- FREF(fp);
vp = (struct vnode *)fp->f_data;
VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
@@ -2043,7 +2040,6 @@ sys_fchown(p, v, retval)
if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
return (error);
- FREF(fp);
vp = (struct vnode *)fp->f_data;
VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
@@ -2166,7 +2162,6 @@ sys_futimes(p, v, retval)
}
if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
return (error);
- FREF(fp);
vp = (struct vnode *)fp->f_data;
VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
@@ -2244,9 +2239,10 @@ sys_ftruncate(p, v, retval)
if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
return (error);
- if ((fp->f_flag & FWRITE) == 0)
- return (EINVAL);
- FREF(fp);
+ if ((fp->f_flag & FWRITE) == 0) {
+ error = EINVAL;
+ goto bad;
+ }
vp = (struct vnode *)fp->f_data;
VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
@@ -2258,6 +2254,7 @@ sys_ftruncate(p, v, retval)
error = VOP_SETATTR(vp, &vattr, fp->f_cred, p);
}
VOP_UNLOCK(vp, 0, p);
+bad:
FRELE(fp);
return (error);
}
@@ -2281,7 +2278,6 @@ sys_fsync(p, v, retval)
if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
return (error);
- FREF(fp);
vp = (struct vnode *)fp->f_data;
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
error = VOP_FSYNC(vp, fp->f_cred, MNT_WAIT, p);
@@ -2510,9 +2506,10 @@ sys_getdirentries(p, v, retval)
if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
return (error);
- if ((fp->f_flag & FREAD) == 0)
- return (EBADF);
- FREF(fp);
+ if ((fp->f_flag & FREAD) == 0) {
+ error = EBADF;
+ goto bad;
+ }
vp = (struct vnode *)fp->f_data;
unionread:
if (vp->v_type != VDIR) {
@@ -2617,6 +2614,8 @@ out:
/*
* Convert a user file descriptor to a kernel file entry.
+ *
+ * On return *fpp is FREF:ed.
*/
int
getvnode(fdp, fd, fpp)
@@ -2630,7 +2629,9 @@ getvnode(fdp, fd, fpp)
return (EBADF);
if (fp->f_type != DTYPE_VNODE)
return (EINVAL);
+ FREF(fp);
*fpp = fp;
+
return (0);
}
@@ -2983,7 +2984,6 @@ sys_extattr_set_fd(struct proc *p, void *v, register_t *retval)
if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
return (error);
- FREF(fp);
error = extattr_set_vp((struct vnode *)fp->f_data,
SCARG(uap, attrnamespace), attrname, SCARG(uap, data),
SCARG(uap, nbytes), p, retval);
@@ -3106,7 +3106,6 @@ sys_extattr_get_fd(p, v, retval)
if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
return (error);
- FREF(fp);
error = extattr_get_vp((struct vnode *)fp->f_data,
SCARG(uap, attrnamespace), attrname, SCARG(uap, data),
SCARG(uap, nbytes), p, retval);
@@ -3195,7 +3194,6 @@ sys_extattr_delete_fd(p, v, retval)
if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
return (error);
- FREF(fp);
error = extattr_delete_vp((struct vnode *)fp->f_data,
SCARG(uap, attrnamespace), attrname, p);
FRELE(fp);
diff --git a/sys/miscfs/fdesc/fdesc_vnops.c b/sys/miscfs/fdesc/fdesc_vnops.c
index ebec8a22cac..c54cbe0a4e3 100644
--- a/sys/miscfs/fdesc/fdesc_vnops.c
+++ b/sys/miscfs/fdesc/fdesc_vnops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fdesc_vnops.c,v 1.31 2002/03/14 01:27:07 millert Exp $ */
+/* $OpenBSD: fdesc_vnops.c,v 1.32 2002/08/23 15:39:31 art Exp $ */
/* $NetBSD: fdesc_vnops.c,v 1.32 1996/04/11 11:24:29 mrg Exp $ */
/*
@@ -570,7 +570,6 @@ fdesc_setattr(v)
}
return (error);
}
- FREF(fp);
vp = (struct vnode *)fp->f_data;
if (vp->v_mount->mnt_flag & MNT_RDONLY) {
error = EROFS;