diff options
author | kstailey <kstailey@cvs.openbsd.org> | 1999-09-17 17:52:14 +0000 |
---|---|---|
committer | kstailey <kstailey@cvs.openbsd.org> | 1999-09-17 17:52:14 +0000 |
commit | 49e1ec736d24dfc9311de1cd6f573483fcb05f00 (patch) | |
tree | a3cc57ba4026931e64ad6ad907568f8727ce49cb | |
parent | 83a5efcde20357c8fe0a60297557f47a951e2ed3 (diff) |
leave the filepointer where you found it - XPG4
-rw-r--r-- | sys/compat/netbsd/netbsd_pos_io.c | 66 |
1 files changed, 44 insertions, 22 deletions
diff --git a/sys/compat/netbsd/netbsd_pos_io.c b/sys/compat/netbsd/netbsd_pos_io.c index 9cb98f9bff0..1bf02022335 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.3 1999/09/17 13:41:29 kstailey Exp $ */ +/* $OpenBSD: netbsd_pos_io.c,v 1.4 1999/09/17 17:52:13 kstailey Exp $ */ /* $NetBSD: vfs_syscalls.c,v 1.71 1996/04/23 10:29:02 mycroft Exp $ */ @@ -60,15 +60,16 @@ #include <compat/netbsd/netbsd_signal.h> #include <compat/netbsd/netbsd_syscallargs.h> -static int netbsd_set_pos __P((struct proc *, int fd, off_t offset)); +static int netbsd_set_pos __P((struct proc *, int, off_t, off_t *)); /* * sys_lseek trimmed down */ static int -netbsd_set_pos(p, fd, offset) +netbsd_set_pos(p, fd, offset, ooffset) struct proc *p; int fd; off_t offset; + off_t *ooffset; { register struct filedesc *fdp = p->p_fd; register struct file *fp; @@ -89,6 +90,7 @@ netbsd_set_pos(p, fd, offset) special = 0; if (!special && offset < 0) return (EINVAL); + *ooffset = fp->f_offset; fp->f_offset = offset; return (0); } @@ -114,16 +116,18 @@ netbsd_sys_pread(p, v, retval) struct uio auio; struct iovec aiov; long cnt, error = 0; + off_t save_offset; #ifdef KTRACE struct iovec ktriov; #endif - if ((error = netbsd_set_pos(p, SCARG(uap, fd), SCARG(uap, offset)))) - return (error); - fp = fdp->fd_ofiles[SCARG(uap, fd)]; /* 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))) + return (error); + fp = fdp->fd_ofiles[SCARG(uap, fd)]; aiov.iov_base = (caddr_t)SCARG(uap, buf); aiov.iov_len = SCARG(uap, nbyte); auio.uio_iov = &aiov; @@ -151,6 +155,7 @@ 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); } @@ -179,20 +184,24 @@ netbsd_sys_preadv(p, v, retval) struct iovec aiov[UIO_SMALLIOV]; long i, cnt, error = 0; u_int iovlen; + off_t save_offset; #ifdef KTRACE struct iovec *ktriov = NULL; #endif - if ((error = netbsd_set_pos(p, SCARG(uap, fd), SCARG(uap, offset)))) - return (error); - fp = fdp->fd_ofiles[SCARG(uap, fd)]; if (SCARG(uap, iovcnt) <= 0) return (EINVAL); + if ((error = netbsd_set_pos(p, SCARG(uap, fd), SCARG(uap, offset), + &save_offset))) + 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) + if (SCARG(uap, iovcnt) > IOV_MAX) { + fp->f_offset = save_offset; return (EINVAL); + } MALLOC(iov, struct iovec *, iovlen, M_IOV, M_WAITOK); needfree = iov; } else { @@ -244,6 +253,7 @@ netbsd_sys_preadv(p, v, retval) done: if (needfree) FREE(needfree, M_IOV); + fp->f_offset = save_offset; return (error); } @@ -268,18 +278,22 @@ netbsd_sys_pwrite(p, v, retval) struct uio auio; struct iovec aiov; long cnt, error = 0; + off_t save_offset; #ifdef KTRACE struct iovec ktriov; #endif - if ((error = netbsd_set_pos(p, SCARG(uap, fd), SCARG(uap, offset)))) - return (error); - fp = fdp->fd_ofiles[SCARG(uap, fd)]; - if ((fp->f_flag & FWRITE) == 0) - return (EBADF); /* 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))) + return (error); + fp = fdp->fd_ofiles[SCARG(uap, fd)]; + if ((fp->f_flag & FWRITE) == 0) { + fp->f_offset = save_offset; + return (EBADF); + } aiov.iov_base = (caddr_t)SCARG(uap, buf); aiov.iov_len = SCARG(uap, nbyte); auio.uio_iov = &aiov; @@ -311,6 +325,7 @@ netbsd_sys_pwrite(p, v, retval) &ktriov, cnt, error); #endif *retval = cnt; + fp->f_offset = save_offset; return (error); } @@ -338,22 +353,28 @@ netbsd_sys_pwritev(p, v, retval) struct iovec aiov[UIO_SMALLIOV]; long i, cnt, error = 0; u_int iovlen; + off_t save_offset; #ifdef KTRACE struct iovec *ktriov = NULL; #endif - if ((error = netbsd_set_pos(p, SCARG(uap, fd), SCARG(uap, offset)))) - return (error); - fp = fdp->fd_ofiles[SCARG(uap, fd)]; - if ((fp->f_flag & FWRITE) == 0) - return (EBADF); if (SCARG(uap, iovcnt) <= 0) return (EINVAL); + if ((error = netbsd_set_pos(p, SCARG(uap, fd), SCARG(uap, offset), + &save_offset))) + return (error); + fp = fdp->fd_ofiles[SCARG(uap, fd)]; + if ((fp->f_flag & FWRITE) == 0) { + error = EBADF; + goto done; + } /* 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) - return (EINVAL); + if (SCARG(uap, iovcnt) > IOV_MAX) { + error = EINVAL; + goto done; + } MALLOC(iov, struct iovec *, iovlen, M_IOV, M_WAITOK); needfree = iov; } else { @@ -406,6 +427,7 @@ netbsd_sys_pwritev(p, v, retval) #endif *retval = cnt; done: + fp->f_offset = save_offset; if (needfree) FREE(needfree, M_IOV); return (error); |