summaryrefslogtreecommitdiff
path: root/sys/compat
diff options
context:
space:
mode:
authorConstantine Sapuntzakis <csapuntz@cvs.openbsd.org>2000-04-19 08:34:58 +0000
committerConstantine Sapuntzakis <csapuntz@cvs.openbsd.org>2000-04-19 08:34:58 +0000
commit1b0d87a1c0c84f70020c31643819aae5aac35415 (patch)
treeb45f915231616b66e02e9674c84a77aad02ce98b /sys/compat
parent83353034a706e18867c607b7c5b2dfb4b868aa84 (diff)
Change struct file interface methods read and write to pass file offset in
and out. Make pread/pwrite in netbsd & linux thread safe - which is the whole point anyway.
Diffstat (limited to 'sys/compat')
-rw-r--r--sys/compat/linux/linux_file.c37
-rw-r--r--sys/compat/netbsd/netbsd_pos_io.c59
2 files changed, 47 insertions, 49 deletions
diff --git a/sys/compat/linux/linux_file.c b/sys/compat/linux/linux_file.c
index ccd5271353a..a25d65763ed 100644
--- a/sys/compat/linux/linux_file.c
+++ b/sys/compat/linux/linux_file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: linux_file.c,v 1.11 2000/04/04 05:31:50 jasoni Exp $ */
+/* $OpenBSD: linux_file.c,v 1.12 2000/04/19 08:34:56 csapuntz Exp $ */
/* $NetBSD: linux_file.c,v 1.15 1996/05/20 01:59:09 fvdl Exp $ */
/*
@@ -65,7 +65,7 @@ static void bsd_to_linux_flock __P((struct flock *, struct linux_flock *));
static void linux_to_bsd_flock __P((struct linux_flock *, struct flock *));
static void bsd_to_linux_stat __P((struct stat *, struct linux_stat *));
static int linux_stat1 __P((struct proc *, void *, register_t *, int));
-static int linux_set_pos __P((struct proc *, int, off_t, off_t *));
+static int linux_set_pos __P((struct proc *, int, off_t));
/*
@@ -858,11 +858,10 @@ linux_sys_fdatasync(p, v, retval)
* sys_lseek trimmed down
*/
static int
-linux_set_pos(p, fd, offset, ooffset)
+linux_set_pos(p, fd, offset)
struct proc *p;
int fd;
off_t offset;
- off_t *ooffset;
{
register struct filedesc *fdp = p->p_fd;
register struct file *fp;
@@ -883,8 +882,6 @@ linux_set_pos(p, fd, offset, ooffset)
special = 0;
if (!special && offset < 0)
return (EINVAL);
- *ooffset = fp->f_offset;
- fp->f_offset = offset;
return (0);
}
@@ -908,14 +905,17 @@ linux_sys_pread(p, v, retval)
struct uio auio;
struct iovec aiov;
long cnt, error = 0;
- off_t save_offset;
+ off_t offset;
/* Don't allow nbyte to be larger than max return val */
if (SCARG(uap, nbyte) > SSIZE_MAX)
return(EINVAL);
- if ((error = linux_set_pos(p, SCARG(uap, fd), SCARG(uap, offset),
- &save_offset)))
+
+ offset = SCARG(uap, offset);
+
+ if ((error = linux_set_pos(p, SCARG(uap, fd), offset)) != 0)
return (error);
+
fp = fdp->fd_ofiles[SCARG(uap, fd)];
aiov.iov_base = (caddr_t)SCARG(uap, buf);
aiov.iov_len = SCARG(uap, nbyte);
@@ -926,13 +926,12 @@ linux_sys_pread(p, v, retval)
auio.uio_segflg = UIO_USERSPACE;
auio.uio_procp = p;
cnt = SCARG(uap, nbyte);
- error = (*fp->f_ops->fo_read)(fp, &auio, fp->f_cred);
+ error = (*fp->f_ops->fo_read)(fp, &offset, &auio, fp->f_cred);
if (error)
if (auio.uio_resid != cnt && (error == ERESTART ||
error == EINTR || error == EWOULDBLOCK))
error = 0;
cnt -= auio.uio_resid;
- fp->f_offset = save_offset;
*retval = cnt;
return (error);
}
@@ -957,19 +956,20 @@ linux_sys_pwrite(p, v, retval)
struct uio auio;
struct iovec aiov;
long cnt, error = 0;
- off_t save_offset;
+ off_t offset;
/* Don't allow nbyte to be larger than max return val */
if (SCARG(uap, nbyte) > SSIZE_MAX)
return(EINVAL);
- if ((error = linux_set_pos(p, SCARG(uap, fd), SCARG(uap, offset),
- &save_offset)))
+
+ offset = SCARG(uap, offset);
+
+ if ((error = linux_set_pos(p, SCARG(uap, fd), offset)) != 0)
return (error);
fp = fdp->fd_ofiles[SCARG(uap, fd)];
- if ((fp->f_flag & FWRITE) == 0) {
- fp->f_offset = save_offset;
+ if ((fp->f_flag & FWRITE) == 0)
return (EBADF);
- }
+
aiov.iov_base = (caddr_t)SCARG(uap, buf);
aiov.iov_len = SCARG(uap, nbyte);
auio.uio_iov = &aiov;
@@ -979,7 +979,7 @@ linux_sys_pwrite(p, v, retval)
auio.uio_segflg = UIO_USERSPACE;
auio.uio_procp = p;
cnt = SCARG(uap, nbyte);
- error = (*fp->f_ops->fo_write)(fp, &auio, fp->f_cred);
+ error = (*fp->f_ops->fo_write)(fp, &offset, &auio, fp->f_cred);
if (error) {
if (auio.uio_resid != cnt && (error == ERESTART ||
error == EINTR || error == EWOULDBLOCK))
@@ -989,6 +989,5 @@ linux_sys_pwrite(p, v, retval)
}
cnt -= auio.uio_resid;
*retval = cnt;
- fp->f_offset = save_offset;
return (error);
}
diff --git a/sys/compat/netbsd/netbsd_pos_io.c b/sys/compat/netbsd/netbsd_pos_io.c
index 1bf02022335..55bea8188ff 100644
--- a/sys/compat/netbsd/netbsd_pos_io.c
+++ b/sys/compat/netbsd/netbsd_pos_io.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: netbsd_pos_io.c,v 1.4 1999/09/17 17:52:13 kstailey Exp $ */
+/* $OpenBSD: netbsd_pos_io.c,v 1.5 2000/04/19 08:34:57 csapuntz Exp $ */
/* $NetBSD: vfs_syscalls.c,v 1.71 1996/04/23 10:29:02 mycroft Exp $ */
@@ -60,16 +60,15 @@
#include <compat/netbsd/netbsd_signal.h>
#include <compat/netbsd/netbsd_syscallargs.h>
-static int netbsd_set_pos __P((struct proc *, int, off_t, off_t *));
+static int netbsd_check_set_pos __P((struct proc *, int, off_t));
/*
* sys_lseek trimmed down
*/
static int
-netbsd_set_pos(p, fd, offset, ooffset)
+netbsd_check_set_pos(p, fd)
struct proc *p;
int fd;
off_t offset;
- off_t *ooffset;
{
register struct filedesc *fdp = p->p_fd;
register struct file *fp;
@@ -90,8 +89,6 @@ netbsd_set_pos(p, fd, offset, ooffset)
special = 0;
if (!special && offset < 0)
return (EINVAL);
- *ooffset = fp->f_offset;
- fp->f_offset = offset;
return (0);
}
@@ -116,7 +113,7 @@ netbsd_sys_pread(p, v, retval)
struct uio auio;
struct iovec aiov;
long cnt, error = 0;
- off_t save_offset;
+ off_t offset;
#ifdef KTRACE
struct iovec ktriov;
#endif
@@ -124,8 +121,10 @@ netbsd_sys_pread(p, v, retval)
/* Don't allow nbyte to be larger than max return val */
if (SCARG(uap, nbyte) > SSIZE_MAX)
return(EINVAL);
- if ((error = netbsd_set_pos(p, SCARG(uap, fd), SCARG(uap, offset),
- &save_offset)))
+
+ offset = SCARG(uap, offset);
+
+ if ((error = netbsd_check_set_pos(p, SCARG(uap, fd), offset) != 0)
return (error);
fp = fdp->fd_ofiles[SCARG(uap, fd)];
aiov.iov_base = (caddr_t)SCARG(uap, buf);
@@ -144,7 +143,7 @@ netbsd_sys_pread(p, v, retval)
ktriov = aiov;
#endif
cnt = SCARG(uap, nbyte);
- error = (*fp->f_ops->fo_read)(fp, &auio, fp->f_cred);
+ error = (*fp->f_ops->fo_read)(fp, &offset, &auio, fp->f_cred);
if (error)
if (auio.uio_resid != cnt && (error == ERESTART ||
error == EINTR || error == EWOULDBLOCK))
@@ -155,7 +154,6 @@ netbsd_sys_pread(p, v, retval)
ktrgenio(p->p_tracep, SCARG(uap, fd), UIO_READ, &ktriov,
cnt, error);
#endif
- fp->f_offset = save_offset;
*retval = cnt;
return (error);
}
@@ -184,22 +182,23 @@ netbsd_sys_preadv(p, v, retval)
struct iovec aiov[UIO_SMALLIOV];
long i, cnt, error = 0;
u_int iovlen;
- off_t save_offset;
+ off_t offset;
#ifdef KTRACE
struct iovec *ktriov = NULL;
#endif
if (SCARG(uap, iovcnt) <= 0)
return (EINVAL);
- if ((error = netbsd_set_pos(p, SCARG(uap, fd), SCARG(uap, offset),
- &save_offset)))
+
+ offset = SCARG(uap, offset);
+
+ if ((error = netbsd_check_set_pos(p, SCARG(uap, fd), offset) != 0)
return (error);
fp = fdp->fd_ofiles[SCARG(uap, fd)];
/* note: can't use iovlen until iovcnt is validated */
iovlen = SCARG(uap, iovcnt) * sizeof (struct iovec);
if (SCARG(uap, iovcnt) > UIO_SMALLIOV) {
if (SCARG(uap, iovcnt) > IOV_MAX) {
- fp->f_offset = save_offset;
return (EINVAL);
}
MALLOC(iov, struct iovec *, iovlen, M_IOV, M_WAITOK);
@@ -235,7 +234,7 @@ netbsd_sys_preadv(p, v, retval)
}
#endif
cnt = auio.uio_resid;
- error = (*fp->f_ops->fo_read)(fp, &auio, fp->f_cred);
+ error = (*fp->f_ops->fo_read)(fp, &offset, &auio, fp->f_cred);
if (error)
if (auio.uio_resid != cnt && (error == ERESTART ||
error == EINTR || error == EWOULDBLOCK))
@@ -253,7 +252,6 @@ netbsd_sys_preadv(p, v, retval)
done:
if (needfree)
FREE(needfree, M_IOV);
- fp->f_offset = save_offset;
return (error);
}
@@ -278,7 +276,7 @@ netbsd_sys_pwrite(p, v, retval)
struct uio auio;
struct iovec aiov;
long cnt, error = 0;
- off_t save_offset;
+ off_t offset;
#ifdef KTRACE
struct iovec ktriov;
#endif
@@ -286,14 +284,15 @@ netbsd_sys_pwrite(p, v, retval)
/* Don't allow nbyte to be larger than max return val */
if (SCARG(uap, nbyte) > SSIZE_MAX)
return(EINVAL);
- if ((error = netbsd_set_pos(p, SCARG(uap, fd), SCARG(uap, offset),
- &save_offset)))
+
+ offset = SCARG(uap, offset);
+
+ if ((error = netbsd_check_set_pos(p, SCARG(uap, fd), offset) != 0)
return (error);
fp = fdp->fd_ofiles[SCARG(uap, fd)];
- if ((fp->f_flag & FWRITE) == 0) {
- fp->f_offset = save_offset;
+ if ((fp->f_flag & FWRITE) == 0)
return (EBADF);
- }
+
aiov.iov_base = (caddr_t)SCARG(uap, buf);
aiov.iov_len = SCARG(uap, nbyte);
auio.uio_iov = &aiov;
@@ -310,7 +309,7 @@ netbsd_sys_pwrite(p, v, retval)
ktriov = aiov;
#endif
cnt = SCARG(uap, nbyte);
- error = (*fp->f_ops->fo_write)(fp, &auio, fp->f_cred);
+ error = (*fp->f_ops->fo_write)(fp, &offset, &auio, fp->f_cred);
if (error) {
if (auio.uio_resid != cnt && (error == ERESTART ||
error == EINTR || error == EWOULDBLOCK))
@@ -325,7 +324,6 @@ netbsd_sys_pwrite(p, v, retval)
&ktriov, cnt, error);
#endif
*retval = cnt;
- fp->f_offset = save_offset;
return (error);
}
@@ -353,15 +351,17 @@ netbsd_sys_pwritev(p, v, retval)
struct iovec aiov[UIO_SMALLIOV];
long i, cnt, error = 0;
u_int iovlen;
- off_t save_offset;
+ off_t offset;
#ifdef KTRACE
struct iovec *ktriov = NULL;
#endif
if (SCARG(uap, iovcnt) <= 0)
return (EINVAL);
- if ((error = netbsd_set_pos(p, SCARG(uap, fd), SCARG(uap, offset),
- &save_offset)))
+
+ offset = SCARG(uap, offset);
+
+ if ((error = netbsd_check_set_pos(p, SCARG(uap, fd), offset) != 0)
return (error);
fp = fdp->fd_ofiles[SCARG(uap, fd)];
if ((fp->f_flag & FWRITE) == 0) {
@@ -408,7 +408,7 @@ netbsd_sys_pwritev(p, v, retval)
}
#endif
cnt = auio.uio_resid;
- error = (*fp->f_ops->fo_write)(fp, &auio, fp->f_cred);
+ error = (*fp->f_ops->fo_write)(fp, &offset, &auio, fp->f_cred);
if (error) {
if (auio.uio_resid != cnt && (error == ERESTART ||
error == EINTR || error == EWOULDBLOCK))
@@ -427,7 +427,6 @@ netbsd_sys_pwritev(p, v, retval)
#endif
*retval = cnt;
done:
- fp->f_offset = save_offset;
if (needfree)
FREE(needfree, M_IOV);
return (error);