Author: trasz
Date: Mon Jan 30 12:24:47 2017
New Revision: 312987
URL: https://svnweb.freebsd.org/changeset/base/312987

Log:
  Add kern_lseek() and use it instead of sys_lseek() in various compats.
  I didn't touch svr4/, there's no point.
  
  Reviewed by:  ed@, kib@
  MFC after:    2 weeks
  Sponsored by: DARPA, AFRL
  Differential Revision:        https://reviews.freebsd.org/D9366

Modified:
  head/sys/compat/cloudabi/cloudabi_fd.c
  head/sys/compat/freebsd32/freebsd32_misc.c
  head/sys/compat/linux/linux_file.c
  head/sys/kern/vfs_syscalls.c
  head/sys/sys/syscallsubr.h

Modified: head/sys/compat/cloudabi/cloudabi_fd.c
==============================================================================
--- head/sys/compat/cloudabi/cloudabi_fd.c      Mon Jan 30 11:50:54 2017        
(r312986)
+++ head/sys/compat/cloudabi/cloudabi_fd.c      Mon Jan 30 12:24:47 2017        
(r312987)
@@ -209,26 +209,23 @@ cloudabi_sys_fd_replace(struct thread *t
 int
 cloudabi_sys_fd_seek(struct thread *td, struct cloudabi_sys_fd_seek_args *uap)
 {
-       struct lseek_args lseek_args = {
-               .fd     = uap->fd,
-               .offset = uap->offset
-       };
+       int whence;
 
        switch (uap->whence) {
        case CLOUDABI_WHENCE_CUR:
-               lseek_args.whence = SEEK_CUR;
+               whence = SEEK_CUR;
                break;
        case CLOUDABI_WHENCE_END:
-               lseek_args.whence = SEEK_END;
+               whence = SEEK_END;
                break;
        case CLOUDABI_WHENCE_SET:
-               lseek_args.whence = SEEK_SET;
+               whence = SEEK_SET;
                break;
        default:
                return (EINVAL);
        }
 
-       return (sys_lseek(td, &lseek_args));
+       return (kern_lseek(td, uap->fd, uap->offset, whence));
 }
 
 /* Converts a file descriptor to a CloudABI file descriptor type. */

Modified: head/sys/compat/freebsd32/freebsd32_misc.c
==============================================================================
--- head/sys/compat/freebsd32/freebsd32_misc.c  Mon Jan 30 11:50:54 2017        
(r312986)
+++ head/sys/compat/freebsd32/freebsd32_misc.c  Mon Jan 30 12:24:47 2017        
(r312987)
@@ -1477,12 +1477,8 @@ freebsd32_pwrite(struct thread *td, stru
 int
 ofreebsd32_lseek(struct thread *td, struct ofreebsd32_lseek_args *uap)
 {
-       struct lseek_args nuap;
 
-       nuap.fd = uap->fd;
-       nuap.offset = uap->offset;
-       nuap.whence = uap->whence;
-       return (sys_lseek(td, &nuap));
+       return (kern_lseek(td, uap->fd, uap->offset, uap->whence));
 }
 #endif
 
@@ -1490,13 +1486,10 @@ int
 freebsd32_lseek(struct thread *td, struct freebsd32_lseek_args *uap)
 {
        int error;
-       struct lseek_args ap;
        off_t pos;
 
-       ap.fd = uap->fd;
-       ap.offset = PAIR32TO64(off_t,uap->offset);
-       ap.whence = uap->whence;
-       error = sys_lseek(td, &ap);
+       error = kern_lseek(td, uap->fd, PAIR32TO64(off_t, uap->offset),
+           uap->whence);
        /* Expand the quad return into two parts for eax and edx */
        pos = td->td_uretoff.tdu_off;
        td->td_retval[RETVAL_LO] = pos & 0xffffffff;    /* %eax */
@@ -1593,13 +1586,10 @@ int
 freebsd6_freebsd32_lseek(struct thread *td, struct 
freebsd6_freebsd32_lseek_args *uap)
 {
        int error;
-       struct lseek_args ap;
        off_t pos;
 
-       ap.fd = uap->fd;
-       ap.offset = PAIR32TO64(off_t,uap->offset);
-       ap.whence = uap->whence;
-       error = sys_lseek(td, &ap);
+       error = kern_lseek(td, uap->fd, PAIR32TO64(off_t, uap->offset),
+           uap->whence);
        /* Expand the quad return into two parts for eax and edx */
        pos = *(off_t *)(td->td_retval);
        td->td_retval[RETVAL_LO] = pos & 0xffffffff;    /* %eax */

Modified: head/sys/compat/linux/linux_file.c
==============================================================================
--- head/sys/compat/linux/linux_file.c  Mon Jan 30 11:50:54 2017        
(r312986)
+++ head/sys/compat/linux/linux_file.c  Mon Jan 30 12:24:47 2017        
(r312987)
@@ -210,31 +210,19 @@ linux_open(struct thread *td, struct lin
 int
 linux_lseek(struct thread *td, struct linux_lseek_args *args)
 {
-       struct lseek_args /* {
-               int fd;
-               int pad;
-               off_t offset;
-               int whence;
-       } */ tmp_args;
-       int error;
 
 #ifdef DEBUG
        if (ldebug(lseek))
                printf(ARGS(lseek, "%d, %ld, %d"),
                    args->fdes, (long)args->off, args->whence);
 #endif
-       tmp_args.fd = args->fdes;
-       tmp_args.offset = (off_t)args->off;
-       tmp_args.whence = args->whence;
-       error = sys_lseek(td, &tmp_args);
-       return (error);
+       return (kern_lseek(td, args->fdes, args->off, args->whence));
 }
 
 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
 int
 linux_llseek(struct thread *td, struct linux_llseek_args *args)
 {
-       struct lseek_args bsd_args;
        int error;
        off_t off;
 
@@ -245,14 +233,12 @@ linux_llseek(struct thread *td, struct l
 #endif
        off = (args->olow) | (((off_t) args->ohigh) << 32);
 
-       bsd_args.fd = args->fd;
-       bsd_args.offset = off;
-       bsd_args.whence = args->whence;
-
-       if ((error = sys_lseek(td, &bsd_args)))
+       error = kern_lseek(td, args->fd, off, args->whence);
+       if (error != 0)
                return (error);
 
-       if ((error = copyout(td->td_retval, args->res, sizeof (off_t))))
+       error = copyout(td->td_retval, args->res, sizeof(off_t));
+       if (error != 0)
                return (error);
 
        td->td_retval[0] = 0;

Modified: head/sys/kern/vfs_syscalls.c
==============================================================================
--- head/sys/kern/vfs_syscalls.c        Mon Jan 30 11:50:54 2017        
(r312986)
+++ head/sys/kern/vfs_syscalls.c        Mon Jan 30 12:24:47 2017        
(r312987)
@@ -1806,25 +1806,25 @@ struct lseek_args {
 };
 #endif
 int
-sys_lseek(td, uap)
-       struct thread *td;
-       register struct lseek_args /* {
-               int fd;
-               int pad;
-               off_t offset;
-               int whence;
-       } */ *uap;
+sys_lseek(struct thread *td, struct lseek_args *uap)
+{
+
+       return (kern_lseek(td, uap->fd, uap->offset, uap->whence));
+}
+
+int
+kern_lseek(struct thread *td, int fd, off_t offset, int whence)
 {
        struct file *fp;
        cap_rights_t rights;
        int error;
 
-       AUDIT_ARG_FD(uap->fd);
-       error = fget(td, uap->fd, cap_rights_init(&rights, CAP_SEEK), &fp);
+       AUDIT_ARG_FD(fd);
+       error = fget(td, fd, cap_rights_init(&rights, CAP_SEEK), &fp);
        if (error != 0)
                return (error);
        error = (fp->f_ops->fo_flags & DFLAG_SEEKABLE) != 0 ?
-           fo_seek(fp, uap->offset, uap->whence, td) : ESPIPE;
+           fo_seek(fp, offset, whence, td) : ESPIPE;
        fdrop(fp, td);
        return (error);
 }
@@ -1841,41 +1841,20 @@ struct olseek_args {
 };
 #endif
 int
-olseek(td, uap)
-       struct thread *td;
-       register struct olseek_args /* {
-               int fd;
-               long offset;
-               int whence;
-       } */ *uap;
+olseek(struct thread *td, struct olseek_args *uap)
 {
-       struct lseek_args /* {
-               int fd;
-               int pad;
-               off_t offset;
-               int whence;
-       } */ nuap;
 
-       nuap.fd = uap->fd;
-       nuap.offset = uap->offset;
-       nuap.whence = uap->whence;
-       return (sys_lseek(td, &nuap));
+       return (kern_lseek(td, uap->fd, uap->offset, uap->whence));
 }
 #endif /* COMPAT_43 */
 
 #if defined(COMPAT_FREEBSD6)
 /* Version with the 'pad' argument */
 int
-freebsd6_lseek(td, uap)
-       struct thread *td;
-       register struct freebsd6_lseek_args *uap;
+freebsd6_lseek(struct thread *td, struct freebsd6_lseek_args *uap)
 {
-       struct lseek_args ouap;
 
-       ouap.fd = uap->fd;
-       ouap.offset = uap->offset;
-       ouap.whence = uap->whence;
-       return (sys_lseek(td, &ouap));
+       return (kern_lseek(td, uap->fd, uap->offset, uap->whence));
 }
 #endif
 

Modified: head/sys/sys/syscallsubr.h
==============================================================================
--- head/sys/sys/syscallsubr.h  Mon Jan 30 11:50:54 2017        (r312986)
+++ head/sys/sys/syscallsubr.h  Mon Jan 30 12:24:47 2017        (r312987)
@@ -135,6 +135,7 @@ int kern_kldstat(struct thread *td, int 
 int    kern_kldunload(struct thread *td, int fileid, int flags);
 int    kern_linkat(struct thread *td, int fd1, int fd2, char *path1,
            char *path2, enum uio_seg segflg, int follow);
+int    kern_lseek(struct thread *td, int fd, off_t offset, int whence);
 int    kern_lutimes(struct thread *td, char *path, enum uio_seg pathseg,
            struct timeval *tptr, enum uio_seg tptrseg);
 int    kern_mkdirat(struct thread *td, int fd, char *path,
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to