On Mon, Apr 25, 2005 at 05:23:14PM +0200, Marc Olzheim wrote:
> On Mon, Apr 25, 2005 at 02:50:45PM +0100, Bruce M Simpson wrote:
> > I don't do enough thread-based programming at the moment to make this worth
> > my while, though, but I'm happy to look at a patch.
> 
> Ok, something like this ?
> I'm a bit puzzled by the coding style in the file, but I think I got the
> spirit of it. ;-)

More like this then...

Marc
--- sys/sys/uio.h.orig  Mon Apr 25 18:23:58 2005
+++ sys/sys/uio.h       Mon Apr 25 18:30:54 2005
@@ -101,6 +101,8 @@
 __BEGIN_DECLS
 ssize_t        readv(int, const struct iovec *, int);
 ssize_t        writev(int, const struct iovec *, int);
+ssize_t        preadv(int, const struct iovec *, int, off_t);
+ssize_t        pwritev(int, const struct iovec *, int, off_t);
 __END_DECLS
 
 #endif /* _KERNEL */
--- sys/compat/freebsd32/syscalls.master.orig   Mon Apr 25 16:56:52 2005
+++ sys/compat/freebsd32/syscalls.master        Mon Apr 25 18:45:38 2005
@@ -406,8 +406,13 @@
 286    UNIMPL  nosys
 287    UNIMPL  nosys
 288    UNIMPL  nosys
-289    UNIMPL  nosys
-290    UNIMPL  nosys
+; 289 and 290 from NetBSD (OpenBSD: 267 and 268)
+289    STD { ssize_t freebsd32_preadv(int fd, u_int iovcnt,\
+                   struct uio * auio, off_t offset); }
+; XXX note - bigendian is different
+290    STD { ssize_t freebsd32_pwritev(int fd, u_int iovcnt,\
+                   struct uio * auio, off_t offset); }
+; XXX note - bigendian is different
 291    UNIMPL  nosys
 292    UNIMPL  nosys
 293    UNIMPL  nosys
--- sys/kern/syscalls.master.orig       Mon Apr 25 16:56:40 2005
+++ sys/kern/syscalls.master    Mon Apr 25 18:45:47 2005
@@ -411,8 +411,11 @@
 286    UNIMPL  nosys
 287    UNIMPL  nosys
 288    UNIMPL  nosys
-289    UNIMPL  nosys
-290    UNIMPL  nosys
+; 289 and 290 from NetBSD (OpenBSD: 267 and 268)
+289    MSTD    { ssize_t preadv(int fd, struct iovec *iovp, u_int iovcnt,\
+                   off_t offset); }
+290    MSTD    { ssize_t pwritev(int fd, struct iovec *iovp, u_int iovcnt,\
+                   off_t offset); }
 291    UNIMPL  nosys
 292    UNIMPL  nosys
 293    UNIMPL  nosys
--- sys/kern/sys_generic.c.orig Mon Apr 25 16:12:58 2005
+++ sys/kern/sys_generic.c      Mon Apr 25 18:32:03 2005
@@ -80,6 +80,8 @@
                    size_t, off_t, int);
 static int     dofilewrite(struct thread *, struct file *, int,
                    const void *, size_t, off_t, int);
+static int     dopreadv(struct thread *, int, struct uio *, off_t, int);
+static int     dopwritev(struct thread *, int, struct uio *, off_t, int);
 static void    doselwakeup(struct selinfo *, int);
 
 /*
@@ -233,9 +235,47 @@
        return (error);
 }
 
+/*
+ * Scatter positioned read system call.
+ */
+#ifndef _SYS_SYSPROTO_H_
+struct preadv_args {
+       int     fd;
+       struct  iovec *iovp;
+       u_int   iovcnt;
+       off_t   offset;
+};
+#endif
+/*
+ * MPSAFE
+ */
+int
+preadv(struct thread *td, struct preadv_args *uap)
+{
+       struct uio *auio;
+       int error;
+
+       error = copyinuio(uap->iovp, uap->iovcnt, &auio);
+       if (error)
+               return (error);
+       error = dopreadv(td, uap->fd, auio, uap->offset, FOF_OFFSET);
+       free(auio, M_IOV);
+       return (error);
+}
+
 int
 kern_readv(struct thread *td, int fd, struct uio *auio)
 {
+       return (dopreadv(td, fd, auio, (off_t)-1, 0));
+}
+
+static int
+dopreadv(td, fd, auio, offset, flags)
+       struct thread *td;
+       struct uio *auio;
+       int fd, flags;
+       off_t offset;
+{
        struct file *fp;
        long cnt;
        int error;
@@ -253,13 +293,14 @@
                return(0);
        }
        auio->uio_rw = UIO_READ;
+       auio->uio_offset = offset;
        auio->uio_td = td;
 #ifdef KTRACE
        if (KTRPOINT(td, KTR_GENIO)) 
                ktruio = cloneuio(auio);
 #endif
        cnt = auio->uio_resid;
-       if ((error = fo_read(fp, auio, td->td_ucred, 0, td))) {
+       if ((error = fo_read(fp, auio, td->td_ucred, flags, td))) {
                if (auio->uio_resid != cnt && (error == ERESTART ||
                    error == EINTR || error == EWOULDBLOCK))
                        error = 0;
@@ -430,9 +471,47 @@
        return (error);
 }
 
+/*
+ * Gather posiotioned write system call
+ */
+#ifndef _SYS_SYSPROTO_H_
+struct pwritev_args {
+       int     fd;
+       struct  iovec *iovp;
+       u_int   iovcnt;
+       off_t   offset;
+};
+#endif
+/*
+ * MPSAFE
+ */
+int
+pwritev(struct thread *td, struct pwritev_args *uap)
+{
+       struct uio *auio;
+       int error;
+
+       error = copyinuio(uap->iovp, uap->iovcnt, &auio);
+       if (error)
+               return (error);
+       error = dopwritev(td, uap->fd, auio, uap->offset, FOF_OFFSET);
+       free(auio, M_IOV);
+       return (error);
+}
+
 int
 kern_writev(struct thread *td, int fd, struct uio *auio)
 {
+       return (dopwritev(td, fd, auio, (off_t)-1 , 0));
+}
+
+static int
+dopwritev(td, fd, auio, offset, flags)
+       struct thread *td;
+       struct uio *auio;
+       int fd, flags;
+       off_t offset;
+{
        struct file *fp;
        long cnt;
        int error;
@@ -445,6 +524,7 @@
                return (EBADF);
        auio->uio_rw = UIO_WRITE;
        auio->uio_td = td;
+       auio->uio_offset = offset;
 #ifdef KTRACE
        if (KTRPOINT(td, KTR_GENIO))
                ktruio = cloneuio(auio);
@@ -452,7 +532,7 @@
        cnt = auio->uio_resid;
        if (fp->f_type == DTYPE_VNODE)
                bwillwrite();
-       if ((error = fo_write(fp, auio, td->td_ucred, 0, td))) {
+       if ((error = fo_write(fp, auio, td->td_ucred, flags, td))) {
                if (auio->uio_resid != cnt && (error == ERESTART ||
                    error == EINTR || error == EWOULDBLOCK))
                        error = 0;

Attachment: pgpmhrpZtR6Z0.pgp
Description: PGP signature

Reply via email to