summaryrefslogtreecommitdiff
path: root/sys/compat/ibcs2/ibcs2_misc.c
diff options
context:
space:
mode:
authorConstantine Sapuntzakis <csapuntz@cvs.openbsd.org>1997-10-06 14:57:25 +0000
committerConstantine Sapuntzakis <csapuntz@cvs.openbsd.org>1997-10-06 14:57:25 +0000
commit9edf2581c6553b9af6c80d28f1027b44776020d3 (patch)
treee1a7b2c7b8994d846aff3afe7d6210b1524fda6d /sys/compat/ibcs2/ibcs2_misc.c
parentda9d52f5837a5d21230fdb6406204160a6eee497 (diff)
VFS Lite 2 Changes
Diffstat (limited to 'sys/compat/ibcs2/ibcs2_misc.c')
-rw-r--r--sys/compat/ibcs2/ibcs2_misc.c46
1 files changed, 28 insertions, 18 deletions
diff --git a/sys/compat/ibcs2/ibcs2_misc.c b/sys/compat/ibcs2/ibcs2_misc.c
index 5a670f21125..97f3ab14835 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.10 1997/09/11 10:48:14 deraadt Exp $ */
+/* $OpenBSD: ibcs2_misc.c,v 1.11 1997/10/06 14:57:24 csapuntz Exp $ */
/* $NetBSD: ibcs2_misc.c,v 1.23 1997/01/15 01:37:49 perry Exp $ */
/*
@@ -358,8 +358,8 @@ ibcs2_sys_getdents(p, v, retval)
struct ibcs2_dirent idb;
off_t off; /* true file offset */
int buflen, error, eofflag;
- u_long *cookiebuf, *cookie;
- int ncookies;
+ u_long *cookiebuf = NULL, *cookie;
+ int ncookies = 0;
if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
return (error);
@@ -374,9 +374,7 @@ ibcs2_sys_getdents(p, v, retval)
buflen = min(MAXBSIZE, SCARG(uap, nbytes));
buf = malloc(buflen, M_TEMP, M_WAITOK);
- ncookies = buflen / 16;
- cookiebuf = malloc(ncookies * sizeof(*cookiebuf), M_TEMP, M_WAITOK);
- VOP_LOCK(vp);
+ vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
off = fp->f_offset;
again:
aiov.iov_base = buf;
@@ -392,11 +390,16 @@ again:
* First we read into the malloc'ed buffer, then
* we massage it into user space, one record at a time.
*/
- error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, cookiebuf,
- ncookies);
+ error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies,
+ &cookiebuf);
if (error)
goto out;
+ if (!error && !cookiebuf) {
+ error = EPERM;
+ goto out;
+ }
+
inp = buf;
outp = SCARG(uap, buf);
resid = SCARG(uap, nbytes);
@@ -446,8 +449,9 @@ again:
eof:
*retval = SCARG(uap, nbytes) - resid;
out:
- VOP_UNLOCK(vp);
- free(cookiebuf, M_TEMP);
+ VOP_UNLOCK(vp, 0, p);
+ if (cookiebuf)
+ free(cookiebuf, M_TEMP);
free(buf, M_TEMP);
return (error);
}
@@ -478,8 +482,8 @@ ibcs2_sys_read(p, v, retval)
} idb;
off_t off; /* true file offset */
int buflen, error, eofflag, size;
- u_long *cookiebuf, *cookie;
- int ncookies;
+ u_long *cookiebuf = NULL, *cookie;
+ int ncookies = 0;
if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0) {
if (error == EINVAL)
@@ -495,9 +499,7 @@ ibcs2_sys_read(p, v, retval)
DPRINTF(("ibcs2_read: read directory\n"));
buflen = max(MAXBSIZE, SCARG(uap, nbytes));
buf = malloc(buflen, M_TEMP, M_WAITOK);
- ncookies = buflen / 16;
- cookiebuf = malloc(ncookies * sizeof(*cookiebuf), M_TEMP, M_WAITOK);
- VOP_LOCK(vp);
+ vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
off = fp->f_offset;
again:
aiov.iov_base = buf;
@@ -513,10 +515,16 @@ again:
* First we read into the malloc'ed buffer, then
* we massage it into user space, one record at a time.
*/
- error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, cookiebuf,
- ncookies);
+ error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies,
+ &cookiebuf);
if (error)
goto out;
+
+ if (!error && !cookiebuf) {
+ error = EPERM;
+ goto out;
+ }
+
inp = buf;
outp = SCARG(uap, buf);
resid = SCARG(uap, nbytes);
@@ -565,7 +573,9 @@ again:
eof:
*retval = SCARG(uap, nbytes) - resid;
out:
- VOP_UNLOCK(vp);
+ VOP_UNLOCK(vp, 0, p);
+ if (cookiebuf)
+ free(cookiebuf, M_TEMP);
free(buf, M_TEMP);
return (error);
}