lseek (long form) is used too much to make it COMPAT_43
[unix-history] / usr / src / sys / kern / vfs_syscalls.c
index cd896c1..cf61962 100644 (file)
@@ -4,22 +4,25 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)vfs_syscalls.c      7.83 (Berkeley) %G%
+ *     @(#)vfs_syscalls.c      7.109 (Berkeley) %G%
  */
 
  */
 
-#include "param.h"
-#include "systm.h"
-#include "namei.h"
-#include "filedesc.h"
-#include "kernel.h"
-#include "file.h"
-#include "stat.h"
-#include "vnode.h"
-#include "mount.h"
-#include "proc.h"
-#include "uio.h"
-#include "malloc.h"
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/namei.h>
+#include <sys/filedesc.h>
+#include <sys/kernel.h>
+#include <sys/file.h>
+#include <sys/stat.h>
+#include <sys/vnode.h>
+#include <sys/mount.h>
+#include <sys/proc.h>
+#include <sys/uio.h>
+#include <sys/malloc.h>
+#include <sys/dirent.h>
+
 #include <vm/vm.h>
 #include <vm/vm.h>
+#include <sys/sysctl.h>
 
 #ifdef REF_DIAGNOSTIC
 #define CURCOUNT (curproc ? curproc->p_spare[0] : 0)
 
 #ifdef REF_DIAGNOSTIC
 #define CURCOUNT (curproc ? curproc->p_spare[0] : 0)
 /*
  * Mount system call.
  */
 /*
  * Mount system call.
  */
+struct mount_args {
+       int     type;
+       char    *dir;
+       int     flags;
+       caddr_t data;
+};
 /* ARGSUSED */
 mount(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 mount(p, uap, retval)
        struct proc *p;
-       register struct args {
-               int     type;
-               char    *dir;
-               int     flags;
-               caddr_t data;
-       } *uap;
+       register struct mount_args *uap;
        int *retval;
 {
        int *retval;
 {
-       USES_VOP_UNLOCK;
        register struct vnode *vp;
        register struct mount *mp;
        int error, flag;
        register struct vnode *vp;
        register struct mount *mp;
        int error, flag;
@@ -73,25 +76,27 @@ mount(p, uap, retval)
                        return (EINVAL);
                }
                mp = vp->v_mount;
                        return (EINVAL);
                }
                mp = vp->v_mount;
+               flag = mp->mnt_flag;
                /*
                /*
-                * We allow going from read-only to read-write,
-                * but not from read-write to read-only.
+                * We only allow the filesystem to be reloaded if it
+                * is currently mounted read-only.
                 */
                 */
-               if ((mp->mnt_flag & MNT_RDONLY) == 0 &&
-                   (uap->flags & MNT_RDONLY) != 0) {
+               if ((uap->flags & MNT_RELOAD) &&
+                   ((mp->mnt_flag & MNT_RDONLY) == 0)) {
                        vput(vp);
                        return (EOPNOTSUPP);    /* Needs translation */
                }
                        vput(vp);
                        return (EOPNOTSUPP);    /* Needs translation */
                }
-               flag = mp->mnt_flag;
-               mp->mnt_flag |= MNT_UPDATE;
+               mp->mnt_flag |=
+                   uap->flags & (MNT_RELOAD | MNT_FORCE | MNT_UPDATE);
                VOP_UNLOCK(vp);
                goto update;
        }
                VOP_UNLOCK(vp);
                goto update;
        }
-       vinvalbuf(vp, 1);
-       if (vp->v_usecount != 1) {
+       if (vp->v_usecount != 1 && (uap->flags & MNT_UNION) == 0) {
                vput(vp);
                return (EBUSY);
        }
                vput(vp);
                return (EBUSY);
        }
+       if (error = vinvalbuf(vp, V_SAVE, p->p_ucred, p, 0, 0))
+               return (error);
        if (vp->v_type != VDIR) {
                vput(vp);
                return (ENOTDIR);
        if (vp->v_type != VDIR) {
                vput(vp);
                return (ENOTDIR);
@@ -107,9 +112,8 @@ mount(p, uap, retval)
         */
        mp = (struct mount *)malloc((u_long)sizeof(struct mount),
                M_MOUNT, M_WAITOK);
         */
        mp = (struct mount *)malloc((u_long)sizeof(struct mount),
                M_MOUNT, M_WAITOK);
+       bzero((char *)mp, (u_long)sizeof(struct mount));
        mp->mnt_op = vfssw[uap->type];
        mp->mnt_op = vfssw[uap->type];
-       mp->mnt_flag = 0;
-       mp->mnt_mounth = NULLVP;
        if (error = vfs_lock(mp)) {
                free((caddr_t)mp, M_MOUNT);
                vput(vp);
        if (error = vfs_lock(mp)) {
                free((caddr_t)mp, M_MOUNT);
                vput(vp);
@@ -129,31 +133,22 @@ update:
         */
        if (uap->flags & MNT_RDONLY)
                mp->mnt_flag |= MNT_RDONLY;
         */
        if (uap->flags & MNT_RDONLY)
                mp->mnt_flag |= MNT_RDONLY;
-       else
-               mp->mnt_flag &= ~MNT_RDONLY;
-       if (uap->flags & MNT_NOSUID)
-               mp->mnt_flag |= MNT_NOSUID;
-       else
-               mp->mnt_flag &= ~MNT_NOSUID;
-       if (uap->flags & MNT_NOEXEC)
-               mp->mnt_flag |= MNT_NOEXEC;
-       else
-               mp->mnt_flag &= ~MNT_NOEXEC;
-       if (uap->flags & MNT_NODEV)
-               mp->mnt_flag |= MNT_NODEV;
-       else
-               mp->mnt_flag &= ~MNT_NODEV;
-       if (uap->flags & MNT_SYNCHRONOUS)
-               mp->mnt_flag |= MNT_SYNCHRONOUS;
-       else
-               mp->mnt_flag &= ~MNT_SYNCHRONOUS;
+       else if (mp->mnt_flag & MNT_RDONLY)
+               mp->mnt_flag |= MNT_WANTRDWR;
+       mp->mnt_flag &=~
+           (MNT_NOSUID | MNT_NOEXEC | MNT_NODEV | MNT_SYNCHRONOUS | MNT_UNION);
+       mp->mnt_flag |= uap->flags &
+           (MNT_NOSUID | MNT_NOEXEC | MNT_NODEV | MNT_SYNCHRONOUS | MNT_UNION);
        /*
         * Mount the filesystem.
         */
        error = VFS_MOUNT(mp, uap->dir, uap->data, &nd, p);
        if (mp->mnt_flag & MNT_UPDATE) {
        /*
         * Mount the filesystem.
         */
        error = VFS_MOUNT(mp, uap->dir, uap->data, &nd, p);
        if (mp->mnt_flag & MNT_UPDATE) {
-               mp->mnt_flag &= ~MNT_UPDATE;
                vrele(vp);
                vrele(vp);
+               if (mp->mnt_flag & MNT_WANTRDWR)
+                       mp->mnt_flag &= ~MNT_RDONLY;
+               mp->mnt_flag &=~
+                   (MNT_UPDATE | MNT_RELOAD | MNT_FORCE | MNT_WANTRDWR);
                if (error)
                        mp->mnt_flag = flag;
                return (error);
                if (error)
                        mp->mnt_flag = flag;
                return (error);
@@ -184,13 +179,14 @@ update:
  * Note: unmount takes a path to the vnode mounted on as argument,
  * not special file (as before).
  */
  * Note: unmount takes a path to the vnode mounted on as argument,
  * not special file (as before).
  */
+struct unmount_args {
+       char    *pathp;
+       int     flags;
+};
 /* ARGSUSED */
 unmount(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 unmount(p, uap, retval)
        struct proc *p;
-       register struct args {
-               char    *pathp;
-               int     flags;
-       } *uap;
+       register struct unmount_args *uap;
        int *retval;
 {
        register struct vnode *vp;
        int *retval;
 {
        register struct vnode *vp;
@@ -240,7 +236,8 @@ dounmount(mp, flags, p)
 
        vnode_pager_umount(mp); /* release cached vnodes */
        cache_purgevfs(mp);     /* remove cache entries for this file sys */
 
        vnode_pager_umount(mp); /* release cached vnodes */
        cache_purgevfs(mp);     /* remove cache entries for this file sys */
-       if ((error = VFS_SYNC(mp, MNT_WAIT)) == 0 || (flags & MNT_FORCE))
+       if ((error = VFS_SYNC(mp, MNT_WAIT, p->p_ucred, p)) == 0 ||
+           (flags & MNT_FORCE))
                error = VFS_UNMOUNT(mp, flags, p);
        mp->mnt_flag &= ~MNT_UNMOUNT;
        vfs_unbusy(mp);
                error = VFS_UNMOUNT(mp, flags, p);
        mp->mnt_flag &= ~MNT_UNMOUNT;
        vfs_unbusy(mp);
@@ -260,10 +257,18 @@ dounmount(mp, flags, p)
  * Sync system call.
  * Sync each mounted filesystem.
  */
  * Sync system call.
  * Sync each mounted filesystem.
  */
+#ifdef DIAGNOSTIC
+int syncprt = 0;
+struct ctldebug debug0 = { "syncprt", &syncprt };
+#endif
+
+struct sync_args {
+       int     dummy;
+};
 /* ARGSUSED */
 sync(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 sync(p, uap, retval)
        struct proc *p;
-       void *uap;
+       struct sync_args *uap;
        int *retval;
 {
        register struct mount *mp;
        int *retval;
 {
        register struct mount *mp;
@@ -277,28 +282,33 @@ sync(p, uap, retval)
                 */
                if ((mp->mnt_flag & (MNT_MLOCK|MNT_RDONLY|MNT_MPBUSY)) == 0 &&
                    !vfs_busy(mp)) {
                 */
                if ((mp->mnt_flag & (MNT_MLOCK|MNT_RDONLY|MNT_MPBUSY)) == 0 &&
                    !vfs_busy(mp)) {
-                       VFS_SYNC(mp, MNT_NOWAIT);
+                       VFS_SYNC(mp, MNT_NOWAIT, p->p_ucred, p);
                        omp = mp;
                        mp = mp->mnt_next;
                        vfs_unbusy(omp);
                } else
                        mp = mp->mnt_next;
        } while (mp != rootfs);
                        omp = mp;
                        mp = mp->mnt_next;
                        vfs_unbusy(omp);
                } else
                        mp = mp->mnt_next;
        } while (mp != rootfs);
+#ifdef DIAGNOSTIC
+       if (syncprt)
+               vfs_bufstats();
+#endif /* DIAGNOSTIC */
        return (0);
 }
 
 /*
  * Operate on filesystem quotas.
  */
        return (0);
 }
 
 /*
  * Operate on filesystem quotas.
  */
+struct quotactl_args {
+       char *path;
+       int cmd;
+       int uid;
+       caddr_t arg;
+};
 /* ARGSUSED */
 quotactl(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 quotactl(p, uap, retval)
        struct proc *p;
-       register struct args {
-               char *path;
-               int cmd;
-               int uid;
-               caddr_t arg;
-       } *uap;
+       register struct quotactl_args *uap;
        int *retval;
 {
        register struct mount *mp;
        int *retval;
 {
        register struct mount *mp;
@@ -316,13 +326,14 @@ quotactl(p, uap, retval)
 /*
  * Get filesystem statistics.
  */
 /*
  * Get filesystem statistics.
  */
+struct statfs_args {
+       char *path;
+       struct statfs *buf;
+};
 /* ARGSUSED */
 statfs(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 statfs(p, uap, retval)
        struct proc *p;
-       register struct args {
-               char *path;
-               struct statfs *buf;
-       } *uap;
+       register struct statfs_args *uap;
        int *retval;
 {
        register struct mount *mp;
        int *retval;
 {
        register struct mount *mp;
@@ -345,13 +356,14 @@ statfs(p, uap, retval)
 /*
  * Get filesystem statistics.
  */
 /*
  * Get filesystem statistics.
  */
+struct fstatfs_args {
+       int fd;
+       struct statfs *buf;
+};
 /* ARGSUSED */
 fstatfs(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 fstatfs(p, uap, retval)
        struct proc *p;
-       register struct args {
-               int fd;
-               struct statfs *buf;
-       } *uap;
+       register struct fstatfs_args *uap;
        int *retval;
 {
        struct file *fp;
        int *retval;
 {
        struct file *fp;
@@ -372,13 +384,14 @@ fstatfs(p, uap, retval)
 /*
  * Get statistics on all filesystems.
  */
 /*
  * Get statistics on all filesystems.
  */
+struct getfsstat_args {
+       struct statfs *buf;
+       long bufsize;
+       int flags;
+};
 getfsstat(p, uap, retval)
        struct proc *p;
 getfsstat(p, uap, retval)
        struct proc *p;
-       register struct args {
-               struct statfs *buf;
-               long bufsize;
-               int flags;
-       } *uap;
+       register struct getfsstat_args *uap;
        int *retval;
 {
        register struct mount *mp;
        int *retval;
 {
        register struct mount *mp;
@@ -422,17 +435,15 @@ getfsstat(p, uap, retval)
 /*
  * Change current working directory to a given file descriptor.
  */
 /*
  * Change current working directory to a given file descriptor.
  */
+struct fchdir_args {
+       int     fd;
+};
 /* ARGSUSED */
 fchdir(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 fchdir(p, uap, retval)
        struct proc *p;
-       struct args {
-               int     fd;
-       } *uap;
+       struct fchdir_args *uap;
        int *retval;
 {
        int *retval;
 {
-       USES_VOP_ACCESS;
-       USES_VOP_LOCK;
-       USES_VOP_UNLOCK;
        register struct filedesc *fdp = p->p_fd;
        register struct vnode *vp;
        struct file *fp;
        register struct filedesc *fdp = p->p_fd;
        register struct vnode *vp;
        struct file *fp;
@@ -458,12 +469,13 @@ fchdir(p, uap, retval)
 /*
  * Change current working directory (``.'').
  */
 /*
  * Change current working directory (``.'').
  */
+struct chdir_args {
+       char    *fname;
+};
 /* ARGSUSED */
 chdir(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 chdir(p, uap, retval)
        struct proc *p;
-       struct args {
-               char    *fname;
-       } *uap;
+       struct chdir_args *uap;
        int *retval;
 {
        register struct filedesc *fdp = p->p_fd;
        int *retval;
 {
        register struct filedesc *fdp = p->p_fd;
@@ -481,12 +493,13 @@ chdir(p, uap, retval)
 /*
  * Change notion of root (``/'') directory.
  */
 /*
  * Change notion of root (``/'') directory.
  */
+struct chroot_args {
+       char    *fname;
+};
 /* ARGSUSED */
 chroot(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 chroot(p, uap, retval)
        struct proc *p;
-       struct args {
-               char    *fname;
-       } *uap;
+       struct chroot_args *uap;
        int *retval;
 {
        register struct filedesc *fdp = p->p_fd;
        int *retval;
 {
        register struct filedesc *fdp = p->p_fd;
@@ -511,8 +524,6 @@ chdirec(ndp, p)
        register struct nameidata *ndp;
        struct proc *p;
 {
        register struct nameidata *ndp;
        struct proc *p;
 {
-       USES_VOP_ACCESS;
-       USES_VOP_UNLOCK;
        struct vnode *vp;
        int error;
 
        struct vnode *vp;
        int error;
 
@@ -534,17 +545,16 @@ chdirec(ndp, p)
  * Check permissions, allocate an open file structure,
  * and call the device open routine if any.
  */
  * Check permissions, allocate an open file structure,
  * and call the device open routine if any.
  */
+struct open_args {
+       char    *fname;
+       int     mode;
+       int     crtmode;
+};
 open(p, uap, retval)
        struct proc *p;
 open(p, uap, retval)
        struct proc *p;
-       register struct args {
-               char    *fname;
-               int     mode;
-               int     crtmode;
-       } *uap;
+       register struct open_args *uap;
        int *retval;
 {
        int *retval;
 {
-       USES_VOP_ADVLOCK;
-       USES_VOP_UNLOCK;
        register struct filedesc *fdp = p->p_fd;
        register struct file *fp;
        register struct vnode *vp;
        register struct filedesc *fdp = p->p_fd;
        register struct file *fp;
        register struct vnode *vp;
@@ -564,9 +574,10 @@ open(p, uap, retval)
        p->p_dupfd = -indx - 1;                 /* XXX check for fdopen */
        if (error = vn_open(&nd, fmode, cmode)) {
                ffree(fp);
        p->p_dupfd = -indx - 1;                 /* XXX check for fdopen */
        if (error = vn_open(&nd, fmode, cmode)) {
                ffree(fp);
-               if (error == ENODEV &&          /* XXX from fdopen */
-                   p->p_dupfd >= 0 &&
-                   (error = dupfdopen(fdp, indx, p->p_dupfd, fmode)) == 0) {
+               if ((error == ENODEV || error == ENXIO) &&
+                   p->p_dupfd >= 0 &&                  /* XXX from fdopen */
+                   (error = dupfdopen(fdp, indx, p->p_dupfd,
+                                       fmode, error)) == 0) {
                        *retval = indx;
                        return (0);
                }
                        *retval = indx;
                        return (0);
                }
@@ -575,8 +586,12 @@ open(p, uap, retval)
                fdp->fd_ofiles[indx] = NULL;
                return (error);
        }
                fdp->fd_ofiles[indx] = NULL;
                return (error);
        }
+       p->p_dupfd = 0;
        vp = nd.ni_vp;
        fp->f_flag = fmode & FMASK;
        vp = nd.ni_vp;
        fp->f_flag = fmode & FMASK;
+       fp->f_type = DTYPE_VNODE;
+       fp->f_ops = &vnops;
+       fp->f_data = (caddr_t)vp;
        if (fmode & (O_EXLOCK | O_SHLOCK)) {
                lf.l_whence = SEEK_SET;
                lf.l_start = 0;
        if (fmode & (O_EXLOCK | O_SHLOCK)) {
                lf.l_whence = SEEK_SET;
                lf.l_start = 0;
@@ -598,9 +613,6 @@ open(p, uap, retval)
                fp->f_flag |= FHASLOCK;
        }
        VOP_UNLOCK(vp);
                fp->f_flag |= FHASLOCK;
        }
        VOP_UNLOCK(vp);
-       fp->f_type = DTYPE_VNODE;
-       fp->f_ops = &vnops;
-       fp->f_data = (caddr_t)vp;
        *retval = indx;
        return (0);
 }
        *retval = indx;
        return (0);
 }
@@ -609,19 +621,16 @@ open(p, uap, retval)
 /*
  * Creat system call.
  */
 /*
  * Creat system call.
  */
+struct ocreat_args {
+       char    *fname;
+       int     fmode;
+};
 ocreat(p, uap, retval)
        struct proc *p;
 ocreat(p, uap, retval)
        struct proc *p;
-       register struct args {
-               char    *fname;
-               int     fmode;
-       } *uap;
+       register struct ocreat_args *uap;
        int *retval;
 {
        int *retval;
 {
-       struct args {
-               char    *fname;
-               int     mode;
-               int     crtmode;
-       } openuap;
+       struct open_args openuap;
 
        openuap.fname = uap->fname;
        openuap.crtmode = uap->fmode;
 
        openuap.fname = uap->fname;
        openuap.crtmode = uap->fmode;
@@ -633,18 +642,17 @@ ocreat(p, uap, retval)
 /*
  * Mknod system call.
  */
 /*
  * Mknod system call.
  */
+struct mknod_args {
+       char    *fname;
+       int     fmode;
+       int     dev;
+};
 /* ARGSUSED */
 mknod(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 mknod(p, uap, retval)
        struct proc *p;
-       register struct args {
-               char    *fname;
-               int     fmode;
-               int     dev;
-       } *uap;
+       register struct mknod_args *uap;
        int *retval;
 {
        int *retval;
 {
-       USES_VOP_ABORTOP;
-       USES_VOP_MKNOD;
        register struct vnode *vp;
        struct vattr vattr;
        int error;
        register struct vnode *vp;
        struct vattr vattr;
        int error;
@@ -699,17 +707,16 @@ out:
 /*
  * Mkfifo system call.
  */
 /*
  * Mkfifo system call.
  */
+struct mkfifo_args {
+       char    *fname;
+       int     fmode;
+};
 /* ARGSUSED */
 mkfifo(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 mkfifo(p, uap, retval)
        struct proc *p;
-       register struct args {
-               char    *fname;
-               int     fmode;
-       } *uap;
+       register struct mkfifo_args *uap;
        int *retval;
 {
        int *retval;
 {
-       USES_VOP_ABORTOP;
-       USES_VOP_MKNOD;
        struct vattr vattr;
        int error;
        struct nameidata nd;
        struct vattr vattr;
        int error;
        struct nameidata nd;
@@ -740,17 +747,16 @@ mkfifo(p, uap, retval)
 /*
  * Link system call.
  */
 /*
  * Link system call.
  */
+struct link_args {
+       char    *target;
+       char    *linkname;
+};
 /* ARGSUSED */
 link(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 link(p, uap, retval)
        struct proc *p;
-       register struct args {
-               char    *target;
-               char    *linkname;
-       } *uap;
+       register struct link_args *uap;
        int *retval;
 {
        int *retval;
 {
-       USES_VOP_ABORTOP;
-       USES_VOP_LINK;
        register struct vnode *vp, *xp;
        int error;
        struct nameidata nd;
        register struct vnode *vp, *xp;
        int error;
        struct nameidata nd;
@@ -774,8 +780,6 @@ link(p, uap, retval)
                goto out;
        }
        xp = nd.ni_dvp;
                goto out;
        }
        xp = nd.ni_dvp;
-       if (vp->v_mount != xp->v_mount)
-               error = EXDEV;
 out:
        if (!error) {
                LEASE_CHECK(xp, p, p->p_ucred, LEASE_WRITE);
 out:
        if (!error) {
                LEASE_CHECK(xp, p, p->p_ucred, LEASE_WRITE);
@@ -799,17 +803,16 @@ out1:
 /*
  * Make a symbolic link.
  */
 /*
  * Make a symbolic link.
  */
+struct symlink_args {
+       char    *target;
+       char    *linkname;
+};
 /* ARGSUSED */
 symlink(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 symlink(p, uap, retval)
        struct proc *p;
-       register struct args {
-               char    *target;
-               char    *linkname;
-       } *uap;
+       register struct symlink_args *uap;
        int *retval;
 {
        int *retval;
 {
-       USES_VOP_ABORTOP;
-       USES_VOP_SYMLINK;
        struct vattr vattr;
        char *target;
        int error;
        struct vattr vattr;
        char *target;
        int error;
@@ -845,25 +848,26 @@ out:
 /*
  * Delete a name from the filesystem.
  */
 /*
  * Delete a name from the filesystem.
  */
+struct unlink_args {
+       char    *name;
+};
 /* ARGSUSED */
 unlink(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 unlink(p, uap, retval)
        struct proc *p;
-       struct args {
-               char    *name;
-       } *uap;
+       struct unlink_args *uap;
        int *retval;
 {
        int *retval;
 {
-       USES_VOP_ABORTOP;
-       USES_VOP_REMOVE;
        register struct vnode *vp;
        int error;
        struct nameidata nd;
 
        CHECKPOINTREF;
        register struct vnode *vp;
        int error;
        struct nameidata nd;
 
        CHECKPOINTREF;
-       NDINIT(&nd, DELETE, LOCKPARENT | LOCKLEAF, UIO_USERSPACE, uap->name, p);
+       NDINIT(&nd, DELETE, LOCKPARENT, UIO_USERSPACE, uap->name, p);
        if (error = namei(&nd))
                return (error);
        vp = nd.ni_vp;
        if (error = namei(&nd))
                return (error);
        vp = nd.ni_vp;
+       LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
+       VOP_LOCK(vp);
        if (vp->v_type == VDIR &&
            (error = suser(p->p_ucred, &p->p_acflag)))
                goto out;
        if (vp->v_type == VDIR &&
            (error = suser(p->p_ucred, &p->p_acflag)))
                goto out;
@@ -878,7 +882,6 @@ unlink(p, uap, retval)
 out:
        if (!error) {
                LEASE_CHECK(nd.ni_dvp, p, p->p_ucred, LEASE_WRITE);
 out:
        if (!error) {
                LEASE_CHECK(nd.ni_dvp, p, p->p_ucred, LEASE_WRITE);
-               LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
                error = VOP_REMOVE(nd.ni_dvp, nd.ni_vp, &nd.ni_cnd);
        } else {
                VOP_ABORTOP(nd.ni_dvp, &nd.ni_cnd);
                error = VOP_REMOVE(nd.ni_dvp, nd.ni_vp, &nd.ni_cnd);
        } else {
                VOP_ABORTOP(nd.ni_dvp, &nd.ni_cnd);
@@ -892,49 +895,21 @@ out:
        return (error);
 }
 
        return (error);
 }
 
-#ifdef COMPAT_43
-/*
- * Seek system call.
- */
-lseek(p, uap, retval)
-       struct proc *p;
-       register struct args {
-               int     fdes;
-               long    off;
-               int     sbase;
-       } *uap;
-       long *retval;
-{
-       struct nargs {
-               int     fdes;
-               off_t   off;
-               int     sbase;
-       } nuap;
-       quad_t qret;
-       int error;
-
-       nuap.fdes = uap->fdes;
-       nuap.off = uap->off;
-       nuap.sbase = uap->sbase;
-       error = __lseek(p, &nuap, &qret);
-       *retval = qret;
-       return (error);
-}
-#endif /* COMPAT_43 */
+struct __lseek_args {
+       int     fdes;
+       int     pad;
+       off_t   off;
+       int     sbase;
+};
 
 /*
  * Seek system call.
  */
 __lseek(p, uap, retval)
        struct proc *p;
 
 /*
  * Seek system call.
  */
 __lseek(p, uap, retval)
        struct proc *p;
-       register struct args {
-               int     fdes;
-               off_t   off;
-               int     sbase;
-       } *uap;
-       off_t *retval;
+       register struct __lseek_args *uap;
+       int *retval;
 {
 {
-       USES_VOP_GETATTR;
        struct ucred *cred = p->p_ucred;
        register struct filedesc *fdp = p->p_fd;
        register struct file *fp;
        struct ucred *cred = p->p_ucred;
        register struct filedesc *fdp = p->p_fd;
        register struct file *fp;
@@ -966,23 +941,50 @@ __lseek(p, uap, retval)
        default:
                return (EINVAL);
        }
        default:
                return (EINVAL);
        }
-       *retval = fp->f_offset;
+       *(off_t *)retval = fp->f_offset;
        return (0);
 }
 
        return (0);
 }
 
+/*
+ * Old lseek system call.
+ *
+ * XXX should be COMPAT_43, but too much breaks.
+ */
+struct lseek_args {
+       int     fdes;
+       long    off;
+       int     sbase;
+};
+lseek(p, uap, retval)
+       struct proc *p;
+       register struct lseek_args *uap;
+       int *retval;
+{
+       struct __lseek_args nuap;
+       off_t qret;
+       int error;
+
+       nuap.fdes = uap->fdes;
+       nuap.off = uap->off;
+       nuap.sbase = uap->sbase;
+       error = __lseek(p, &nuap, &qret);
+       *(long *)retval = qret;
+       return (error);
+}
+
 /*
  * Check access permissions.
  */
 /*
  * Check access permissions.
  */
+struct saccess_args {
+       char    *fname;
+       int     fmode;
+};
 /* ARGSUSED */
 saccess(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 saccess(p, uap, retval)
        struct proc *p;
-       register struct args {
-               char    *fname;
-               int     fmode;
-       } *uap;
+       register struct saccess_args *uap;
        int *retval;
 {
        int *retval;
 {
-       USES_VOP_ACCESS;
        register struct ucred *cred = p->p_ucred;
        register struct vnode *vp;
        int error, mode, svuid, svgid;
        register struct ucred *cred = p->p_ucred;
        register struct vnode *vp;
        int error, mode, svuid, svgid;
@@ -1017,18 +1019,19 @@ out1:
        return (error);
 }
 
        return (error);
 }
 
-#ifdef COMPAT_43
+#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
 /*
  * Stat system call.
  * This version follows links.
  */
 /*
  * Stat system call.
  * This version follows links.
  */
+struct ostat_args {
+       char    *fname;
+       struct ostat *ub;
+};
 /* ARGSUSED */
 ostat(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 ostat(p, uap, retval)
        struct proc *p;
-       register struct args {
-               char    *fname;
-               struct ostat *ub;
-       } *uap;
+       register struct ostat_args *uap;
        int *retval;
 {
        struct stat sb;
        int *retval;
 {
        struct stat sb;
@@ -1052,13 +1055,14 @@ ostat(p, uap, retval)
  * Lstat system call.
  * This version does not follow links.
  */
  * Lstat system call.
  * This version does not follow links.
  */
+struct olstat_args {
+       char    *fname;
+       struct ostat *ub;
+};
 /* ARGSUSED */
 olstat(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 olstat(p, uap, retval)
        struct proc *p;
-       register struct args {
-               char    *fname;
-               struct ostat *ub;
-       } *uap;
+       register struct olstat_args *uap;
        int *retval;
 {
        struct stat sb;
        int *retval;
 {
        struct stat sb;
@@ -1105,19 +1109,20 @@ cvtstat(st, ost)
        ost->st_flags = st->st_flags;
        ost->st_gen = st->st_gen;
 }
        ost->st_flags = st->st_flags;
        ost->st_gen = st->st_gen;
 }
-#endif /* COMPAT_43 */
+#endif /* COMPAT_43 || COMPAT_SUNOS */
 
 /*
  * Stat system call.
  * This version follows links.
  */
 
 /*
  * Stat system call.
  * This version follows links.
  */
+struct stat_args {
+       char    *fname;
+       struct stat *ub;
+};
 /* ARGSUSED */
 stat(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 stat(p, uap, retval)
        struct proc *p;
-       register struct args {
-               char    *fname;
-               struct stat *ub;
-       } *uap;
+       register struct stat_args *uap;
        int *retval;
 {
        struct stat sb;
        int *retval;
 {
        struct stat sb;
@@ -1139,26 +1144,57 @@ stat(p, uap, retval)
  * Lstat system call.
  * This version does not follow links.
  */
  * Lstat system call.
  * This version does not follow links.
  */
+struct lstat_args {
+       char    *fname;
+       struct stat *ub;
+};
 /* ARGSUSED */
 lstat(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 lstat(p, uap, retval)
        struct proc *p;
-       register struct args {
-               char    *fname;
-               struct stat *ub;
-       } *uap;
+       register struct lstat_args *uap;
        int *retval;
 {
        int *retval;
 {
-       struct stat sb;
        int error;
        int error;
+       struct vnode *vp, *dvp;
+       struct stat sb, sb1;
        struct nameidata nd;
 
        struct nameidata nd;
 
-       NDINIT(&nd, LOOKUP, NOFOLLOW | LOCKLEAF, UIO_USERSPACE, uap->fname, p);
+       NDINIT(&nd, LOOKUP, NOFOLLOW | LOCKLEAF | LOCKPARENT, UIO_USERSPACE,
+           uap->fname, p);
        if (error = namei(&nd))
                return (error);
        if (error = namei(&nd))
                return (error);
-       error = vn_stat(nd.ni_vp, &sb, p);
-       vput(nd.ni_vp);
-       if (error)
-               return (error);
+       /*
+        * For symbolic links, always return the attributes of its
+        * containing directory, except for mode, size, and links.
+        */
+       vp = nd.ni_vp;
+       dvp = nd.ni_dvp;
+       if (vp->v_type != VLNK) {
+               if (dvp == vp)
+                       vrele(dvp);
+               else
+                       vput(dvp);
+               error = vn_stat(vp, &sb, p);
+               vput(vp);
+               if (error)
+                       return (error);
+       } else {
+               error = vn_stat(dvp, &sb, p);
+               vput(dvp);
+               if (error) {
+                       vput(vp);
+                       return (error);
+               }
+               error = vn_stat(vp, &sb1, p);
+               vput(vp);
+               if (error)
+                       return (error);
+               sb.st_mode &= ~S_IFDIR;
+               sb.st_mode |= S_IFLNK;
+               sb.st_nlink = sb1.st_nlink;
+               sb.st_size = sb1.st_size;
+               sb.st_blocks = sb1.st_blocks;
+       }
        error = copyout((caddr_t)&sb, (caddr_t)uap->ub, sizeof (sb));
        return (error);
 }
        error = copyout((caddr_t)&sb, (caddr_t)uap->ub, sizeof (sb));
        return (error);
 }
@@ -1166,17 +1202,17 @@ lstat(p, uap, retval)
 /*
  * Return target name of a symbolic link.
  */
 /*
  * Return target name of a symbolic link.
  */
+struct readlink_args {
+       char    *name;
+       char    *buf;
+       int     count;
+};
 /* ARGSUSED */
 readlink(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 readlink(p, uap, retval)
        struct proc *p;
-       register struct args {
-               char    *name;
-               char    *buf;
-               int     count;
-       } *uap;
+       register struct readlink_args *uap;
        int *retval;
 {
        int *retval;
 {
-       USES_VOP_READLINK;
        register struct vnode *vp;
        struct iovec aiov;
        struct uio auio;
        register struct vnode *vp;
        struct iovec aiov;
        struct uio auio;
@@ -1212,32 +1248,33 @@ out:
 /*
  * Change flags of a file given path name.
  */
 /*
  * Change flags of a file given path name.
  */
+struct chflags_args {
+       char    *fname;
+       int     flags;
+};
 /* ARGSUSED */
 chflags(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 chflags(p, uap, retval)
        struct proc *p;
-       register struct args {
-               char    *fname;
-               int     flags;
-       } *uap;
+       register struct chflags_args *uap;
        int *retval;
 {
        int *retval;
 {
-       USES_VOP_SETATTR;
        register struct vnode *vp;
        struct vattr vattr;
        int error;
        struct nameidata nd;
 
        register struct vnode *vp;
        struct vattr vattr;
        int error;
        struct nameidata nd;
 
-       NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, uap->fname, p);
+       NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->fname, p);
        if (error = namei(&nd))
                return (error);
        vp = nd.ni_vp;
        if (error = namei(&nd))
                return (error);
        vp = nd.ni_vp;
+       LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
+       VOP_LOCK(vp);
        if (vp->v_mount->mnt_flag & MNT_RDONLY) {
                error = EROFS;
                goto out;
        }
        VATTR_NULL(&vattr);
        vattr.va_flags = uap->flags;
        if (vp->v_mount->mnt_flag & MNT_RDONLY) {
                error = EROFS;
                goto out;
        }
        VATTR_NULL(&vattr);
        vattr.va_flags = uap->flags;
-       LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
        error = VOP_SETATTR(vp, &vattr, p->p_ucred, p);
 out:
        vput(vp);
        error = VOP_SETATTR(vp, &vattr, p->p_ucred, p);
 out:
        vput(vp);
@@ -1247,18 +1284,16 @@ out:
 /*
  * Change flags of a file given a file descriptor.
  */
 /*
  * Change flags of a file given a file descriptor.
  */
+struct fchflags_args {
+       int     fd;
+       int     flags;
+};
 /* ARGSUSED */
 fchflags(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 fchflags(p, uap, retval)
        struct proc *p;
-       register struct args {
-               int     fd;
-               int     flags;
-       } *uap;
+       register struct fchflags_args *uap;
        int *retval;
 {
        int *retval;
 {
-       USES_VOP_LOCK;
-       USES_VOP_SETATTR;
-       USES_VOP_UNLOCK;
        struct vattr vattr;
        struct vnode *vp;
        struct file *fp;
        struct vattr vattr;
        struct vnode *vp;
        struct file *fp;
@@ -1267,6 +1302,7 @@ fchflags(p, uap, retval)
        if (error = getvnode(p->p_fd, uap->fd, &fp))
                return (error);
        vp = (struct vnode *)fp->f_data;
        if (error = getvnode(p->p_fd, uap->fd, &fp))
                return (error);
        vp = (struct vnode *)fp->f_data;
+       LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
        VOP_LOCK(vp);
        if (vp->v_mount->mnt_flag & MNT_RDONLY) {
                error = EROFS;
        VOP_LOCK(vp);
        if (vp->v_mount->mnt_flag & MNT_RDONLY) {
                error = EROFS;
@@ -1274,7 +1310,6 @@ fchflags(p, uap, retval)
        }
        VATTR_NULL(&vattr);
        vattr.va_flags = uap->flags;
        }
        VATTR_NULL(&vattr);
        vattr.va_flags = uap->flags;
-       LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
        error = VOP_SETATTR(vp, &vattr, p->p_ucred, p);
 out:
        VOP_UNLOCK(vp);
        error = VOP_SETATTR(vp, &vattr, p->p_ucred, p);
 out:
        VOP_UNLOCK(vp);
@@ -1284,32 +1319,33 @@ out:
 /*
  * Change mode of a file given path name.
  */
 /*
  * Change mode of a file given path name.
  */
+struct chmod_args {
+       char    *fname;
+       int     fmode;
+};
 /* ARGSUSED */
 chmod(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 chmod(p, uap, retval)
        struct proc *p;
-       register struct args {
-               char    *fname;
-               int     fmode;
-       } *uap;
+       register struct chmod_args *uap;
        int *retval;
 {
        int *retval;
 {
-       USES_VOP_SETATTR;
        register struct vnode *vp;
        struct vattr vattr;
        int error;
        struct nameidata nd;
 
        register struct vnode *vp;
        struct vattr vattr;
        int error;
        struct nameidata nd;
 
-       NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, uap->fname, p);
+       NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->fname, p);
        if (error = namei(&nd))
                return (error);
        vp = nd.ni_vp;
        if (error = namei(&nd))
                return (error);
        vp = nd.ni_vp;
+       LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
+       VOP_LOCK(vp);
        if (vp->v_mount->mnt_flag & MNT_RDONLY) {
                error = EROFS;
                goto out;
        }
        VATTR_NULL(&vattr);
        vattr.va_mode = uap->fmode & 07777;
        if (vp->v_mount->mnt_flag & MNT_RDONLY) {
                error = EROFS;
                goto out;
        }
        VATTR_NULL(&vattr);
        vattr.va_mode = uap->fmode & 07777;
-       LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
        error = VOP_SETATTR(vp, &vattr, p->p_ucred, p);
 out:
        vput(vp);
        error = VOP_SETATTR(vp, &vattr, p->p_ucred, p);
 out:
        vput(vp);
@@ -1319,18 +1355,16 @@ out:
 /*
  * Change mode of a file given a file descriptor.
  */
 /*
  * Change mode of a file given a file descriptor.
  */
+struct fchmod_args {
+       int     fd;
+       int     fmode;
+};
 /* ARGSUSED */
 fchmod(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 fchmod(p, uap, retval)
        struct proc *p;
-       register struct args {
-               int     fd;
-               int     fmode;
-       } *uap;
+       register struct fchmod_args *uap;
        int *retval;
 {
        int *retval;
 {
-       USES_VOP_LOCK;
-       USES_VOP_SETATTR;
-       USES_VOP_UNLOCK;
        struct vattr vattr;
        struct vnode *vp;
        struct file *fp;
        struct vattr vattr;
        struct vnode *vp;
        struct file *fp;
@@ -1339,6 +1373,7 @@ fchmod(p, uap, retval)
        if (error = getvnode(p->p_fd, uap->fd, &fp))
                return (error);
        vp = (struct vnode *)fp->f_data;
        if (error = getvnode(p->p_fd, uap->fd, &fp))
                return (error);
        vp = (struct vnode *)fp->f_data;
+       LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
        VOP_LOCK(vp);
        if (vp->v_mount->mnt_flag & MNT_RDONLY) {
                error = EROFS;
        VOP_LOCK(vp);
        if (vp->v_mount->mnt_flag & MNT_RDONLY) {
                error = EROFS;
@@ -1346,7 +1381,6 @@ fchmod(p, uap, retval)
        }
        VATTR_NULL(&vattr);
        vattr.va_mode = uap->fmode & 07777;
        }
        VATTR_NULL(&vattr);
        vattr.va_mode = uap->fmode & 07777;
-       LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
        error = VOP_SETATTR(vp, &vattr, p->p_ucred, p);
 out:
        VOP_UNLOCK(vp);
        error = VOP_SETATTR(vp, &vattr, p->p_ucred, p);
 out:
        VOP_UNLOCK(vp);
@@ -1356,26 +1390,28 @@ out:
 /*
  * Set ownership given a path name.
  */
 /*
  * Set ownership given a path name.
  */
+struct chown_args {
+       char    *fname;
+       int     uid;
+       int     gid;
+};
 /* ARGSUSED */
 chown(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 chown(p, uap, retval)
        struct proc *p;
-       register struct args {
-               char    *fname;
-               int     uid;
-               int     gid;
-       } *uap;
+       register struct chown_args *uap;
        int *retval;
 {
        int *retval;
 {
-       USES_VOP_SETATTR;
        register struct vnode *vp;
        struct vattr vattr;
        int error;
        struct nameidata nd;
 
        register struct vnode *vp;
        struct vattr vattr;
        int error;
        struct nameidata nd;
 
-       NDINIT(&nd, LOOKUP, NOFOLLOW | LOCKLEAF, UIO_USERSPACE, uap->fname, p);
+       NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->fname, p);
        if (error = namei(&nd))
                return (error);
        vp = nd.ni_vp;
        if (error = namei(&nd))
                return (error);
        vp = nd.ni_vp;
+       LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
+       VOP_LOCK(vp);
        if (vp->v_mount->mnt_flag & MNT_RDONLY) {
                error = EROFS;
                goto out;
        if (vp->v_mount->mnt_flag & MNT_RDONLY) {
                error = EROFS;
                goto out;
@@ -1383,7 +1419,6 @@ chown(p, uap, retval)
        VATTR_NULL(&vattr);
        vattr.va_uid = uap->uid;
        vattr.va_gid = uap->gid;
        VATTR_NULL(&vattr);
        vattr.va_uid = uap->uid;
        vattr.va_gid = uap->gid;
-       LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
        error = VOP_SETATTR(vp, &vattr, p->p_ucred, p);
 out:
        vput(vp);
        error = VOP_SETATTR(vp, &vattr, p->p_ucred, p);
 out:
        vput(vp);
@@ -1393,19 +1428,17 @@ out:
 /*
  * Set ownership given a file descriptor.
  */
 /*
  * Set ownership given a file descriptor.
  */
+struct fchown_args {
+       int     fd;
+       int     uid;
+       int     gid;
+};
 /* ARGSUSED */
 fchown(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 fchown(p, uap, retval)
        struct proc *p;
-       register struct args {
-               int     fd;
-               int     uid;
-               int     gid;
-       } *uap;
+       register struct fchown_args *uap;
        int *retval;
 {
        int *retval;
 {
-       USES_VOP_LOCK;
-       USES_VOP_SETATTR;
-       USES_VOP_UNLOCK;
        struct vattr vattr;
        struct vnode *vp;
        struct file *fp;
        struct vattr vattr;
        struct vnode *vp;
        struct file *fp;
@@ -1414,6 +1447,7 @@ fchown(p, uap, retval)
        if (error = getvnode(p->p_fd, uap->fd, &fp))
                return (error);
        vp = (struct vnode *)fp->f_data;
        if (error = getvnode(p->p_fd, uap->fd, &fp))
                return (error);
        vp = (struct vnode *)fp->f_data;
+       LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
        VOP_LOCK(vp);
        if (vp->v_mount->mnt_flag & MNT_RDONLY) {
                error = EROFS;
        VOP_LOCK(vp);
        if (vp->v_mount->mnt_flag & MNT_RDONLY) {
                error = EROFS;
@@ -1422,7 +1456,6 @@ fchown(p, uap, retval)
        VATTR_NULL(&vattr);
        vattr.va_uid = uap->uid;
        vattr.va_gid = uap->gid;
        VATTR_NULL(&vattr);
        vattr.va_uid = uap->uid;
        vattr.va_gid = uap->gid;
-       LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
        error = VOP_SETATTR(vp, &vattr, p->p_ucred, p);
 out:
        VOP_UNLOCK(vp);
        error = VOP_SETATTR(vp, &vattr, p->p_ucred, p);
 out:
        VOP_UNLOCK(vp);
@@ -1432,87 +1465,54 @@ out:
 /*
  * Set the access and modification times of a file.
  */
 /*
  * Set the access and modification times of a file.
  */
+struct utimes_args {
+       char    *fname;
+       struct  timeval *tptr;
+};
 /* ARGSUSED */
 utimes(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 utimes(p, uap, retval)
        struct proc *p;
-       register struct args {
-               char    *fname;
-               struct  timeval *tptr;
-       } *uap;
+       register struct utimes_args *uap;
        int *retval;
 {
        int *retval;
 {
-       USES_VOP_SETATTR;
        register struct vnode *vp;
        struct timeval tv[2];
        struct vattr vattr;
        int error;
        struct nameidata nd;
 
        register struct vnode *vp;
        struct timeval tv[2];
        struct vattr vattr;
        int error;
        struct nameidata nd;
 
-       if (error = copyin((caddr_t)uap->tptr, (caddr_t)tv, sizeof (tv)))
-               return (error);
-       NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, uap->fname, p);
+       VATTR_NULL(&vattr);
+       if (uap->tptr == NULL) {
+               microtime(&tv[0]);
+               tv[1] = tv[0];
+               vattr.va_vaflags |= VA_UTIMES_NULL;
+       } else if (error = copyin((caddr_t)uap->tptr, (caddr_t)tv, sizeof (tv)))
+               return (error);
+       NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->fname, p);
        if (error = namei(&nd))
                return (error);
        vp = nd.ni_vp;
        if (error = namei(&nd))
                return (error);
        vp = nd.ni_vp;
+       LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
+       VOP_LOCK(vp);
        if (vp->v_mount->mnt_flag & MNT_RDONLY) {
                error = EROFS;
                goto out;
        }
        if (vp->v_mount->mnt_flag & MNT_RDONLY) {
                error = EROFS;
                goto out;
        }
-       VATTR_NULL(&vattr);
-       vattr.va_atime.tv_sec = tv[0].tv_sec;
-       vattr.va_mtime.tv_sec = tv[1].tv_sec;
-       LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
+       vattr.va_atime.ts_sec = tv[0].tv_sec;
+       vattr.va_atime.ts_nsec = tv[0].tv_usec * 1000;
+       vattr.va_mtime.ts_sec = tv[1].tv_sec;
+       vattr.va_mtime.ts_nsec = tv[1].tv_usec * 1000;
        error = VOP_SETATTR(vp, &vattr, p->p_ucred, p);
 out:
        vput(vp);
        return (error);
 }
 
        error = VOP_SETATTR(vp, &vattr, p->p_ucred, p);
 out:
        vput(vp);
        return (error);
 }
 
-#ifdef COMPAT_43
-/*
- * Truncate a file given its path name.
- */
-/* ARGSUSED */
-truncate(p, uap, retval)
-       struct proc *p;
-       register struct args {
-               char    *fname;
-               long    length;
-       } *uap;
-       int *retval;
-{
-       struct nargs {
-               char    *fname;
-               off_t   length;
-       } nuap;
-
-       nuap.fname = uap->fname;
-       nuap.length = uap->length;
-       return (__truncate(p, &nuap, retval));
-}
-
-/*
- * Truncate a file given a file descriptor.
- */
-/* ARGSUSED */
-ftruncate(p, uap, retval)
-       struct proc *p;
-       register struct args {
-               int     fd;
-               long    length;
-       } *uap;
-       int *retval;
-{
-       struct nargs {
-               int     fd;
-               off_t   length;
-       } nuap;
-
-       nuap.fd = uap->fd;
-       nuap.length = uap->length;
-       return (__ftruncate(p, &nuap, retval));
-}
-#endif /* COMPAT_43 */
+struct __truncate_args {
+       char    *fname;
+       int     pad;
+       off_t   length;
+};
 
 /*
  * Truncate a file given its path name.
 
 /*
  * Truncate a file given its path name.
@@ -1520,23 +1520,20 @@ ftruncate(p, uap, retval)
 /* ARGSUSED */
 __truncate(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 __truncate(p, uap, retval)
        struct proc *p;
-       register struct args {
-               char    *fname;
-               off_t   length;
-       } *uap;
+       register struct __truncate_args *uap;
        int *retval;
 {
        int *retval;
 {
-       USES_VOP_ACCESS;
-       USES_VOP_SETATTR;
        register struct vnode *vp;
        struct vattr vattr;
        int error;
        struct nameidata nd;
 
        register struct vnode *vp;
        struct vattr vattr;
        int error;
        struct nameidata nd;
 
-       NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, uap->fname, p);
+       NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->fname, p);
        if (error = namei(&nd))
                return (error);
        vp = nd.ni_vp;
        if (error = namei(&nd))
                return (error);
        vp = nd.ni_vp;
+       LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
+       VOP_LOCK(vp);
        if (vp->v_type == VDIR) {
                error = EISDIR;
                goto out;
        if (vp->v_type == VDIR) {
                error = EISDIR;
                goto out;
@@ -1546,28 +1543,27 @@ __truncate(p, uap, retval)
                goto out;
        VATTR_NULL(&vattr);
        vattr.va_size = uap->length;
                goto out;
        VATTR_NULL(&vattr);
        vattr.va_size = uap->length;
-       LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
        error = VOP_SETATTR(vp, &vattr, p->p_ucred, p);
 out:
        vput(vp);
        return (error);
 }
 
        error = VOP_SETATTR(vp, &vattr, p->p_ucred, p);
 out:
        vput(vp);
        return (error);
 }
 
+struct __ftruncate_args {
+       int     fd;
+       int     pad;
+       off_t   length;
+};
+
 /*
  * Truncate a file given a file descriptor.
  */
 /* ARGSUSED */
 __ftruncate(p, uap, retval)
        struct proc *p;
 /*
  * Truncate a file given a file descriptor.
  */
 /* ARGSUSED */
 __ftruncate(p, uap, retval)
        struct proc *p;
-       register struct args {
-               int     fd;
-               off_t   length;
-       } *uap;
+       register struct __ftruncate_args *uap;
        int *retval;
 {
        int *retval;
 {
-       USES_VOP_LOCK;
-       USES_VOP_SETATTR;
-       USES_VOP_UNLOCK;
        struct vattr vattr;
        struct vnode *vp;
        struct file *fp;
        struct vattr vattr;
        struct vnode *vp;
        struct file *fp;
@@ -1578,6 +1574,7 @@ __ftruncate(p, uap, retval)
        if ((fp->f_flag & FWRITE) == 0)
                return (EINVAL);
        vp = (struct vnode *)fp->f_data;
        if ((fp->f_flag & FWRITE) == 0)
                return (EINVAL);
        vp = (struct vnode *)fp->f_data;
+       LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
        VOP_LOCK(vp);
        if (vp->v_type == VDIR) {
                error = EISDIR;
        VOP_LOCK(vp);
        if (vp->v_type == VDIR) {
                error = EISDIR;
@@ -1587,27 +1584,66 @@ __ftruncate(p, uap, retval)
                goto out;
        VATTR_NULL(&vattr);
        vattr.va_size = uap->length;
                goto out;
        VATTR_NULL(&vattr);
        vattr.va_size = uap->length;
-       LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
        error = VOP_SETATTR(vp, &vattr, fp->f_cred, p);
 out:
        VOP_UNLOCK(vp);
        return (error);
 }
 
        error = VOP_SETATTR(vp, &vattr, fp->f_cred, p);
 out:
        VOP_UNLOCK(vp);
        return (error);
 }
 
+#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
+/*
+ * Truncate a file given its path name.
+ */
+struct truncate_args {
+       char    *fname;
+       long    length;
+};
+/* ARGSUSED */
+truncate(p, uap, retval)
+       struct proc *p;
+       register struct truncate_args *uap;
+       int *retval;
+{
+       struct __truncate_args nuap;
+
+       nuap.fname = uap->fname;
+       nuap.length = uap->length;
+       return (__truncate(p, &nuap, retval));
+}
+
+/*
+ * Truncate a file given a file descriptor.
+ */
+struct ftruncate_args {
+       int     fd;
+       long    length;
+};
+/* ARGSUSED */
+ftruncate(p, uap, retval)
+       struct proc *p;
+       register struct ftruncate_args *uap;
+       int *retval;
+{
+       struct __ftruncate_args nuap;
+
+       nuap.fd = uap->fd;
+       nuap.length = uap->length;
+       return (__ftruncate(p, &nuap, retval));
+}
+#endif /* COMPAT_43 || COMPAT_SUNOS */
+
 /*
  * Synch an open file.
  */
 /*
  * Synch an open file.
  */
+struct fsync_args {
+       int     fd;
+};
 /* ARGSUSED */
 fsync(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 fsync(p, uap, retval)
        struct proc *p;
-       struct args {
-               int     fd;
-       } *uap;
+       struct fsync_args *uap;
        int *retval;
 {
        int *retval;
 {
-       USES_VOP_FSYNC;
-       USES_VOP_LOCK;
-       USES_VOP_UNLOCK;
        register struct vnode *vp;
        struct file *fp;
        int error;
        register struct vnode *vp;
        struct file *fp;
        int error;
@@ -1616,7 +1652,7 @@ fsync(p, uap, retval)
                return (error);
        vp = (struct vnode *)fp->f_data;
        VOP_LOCK(vp);
                return (error);
        vp = (struct vnode *)fp->f_data;
        VOP_LOCK(vp);
-       error = VOP_FSYNC(vp, fp->f_flag, fp->f_cred, MNT_WAIT, p);
+       error = VOP_FSYNC(vp, fp->f_cred, MNT_WAIT, p);
        VOP_UNLOCK(vp);
        return (error);
 }
        VOP_UNLOCK(vp);
        return (error);
 }
@@ -1627,17 +1663,16 @@ fsync(p, uap, retval)
  * Source and destination must either both be directories, or both
  * not be directories.  If target is a directory, it must be empty.
  */
  * Source and destination must either both be directories, or both
  * not be directories.  If target is a directory, it must be empty.
  */
+struct rename_args {
+       char    *from;
+       char    *to;
+};
 /* ARGSUSED */
 rename(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 rename(p, uap, retval)
        struct proc *p;
-       register struct args {
-               char    *from;
-               char    *to;
-       } *uap;
+       register struct rename_args *uap;
        int *retval;
 {
        int *retval;
 {
-       USES_VOP_ABORTOP;
-       USES_VOP_RENAME;
        register struct vnode *tvp, *fvp, *tdvp;
        struct nameidata fromnd, tond;
        int error;
        register struct vnode *tvp, *fvp, *tdvp;
        struct nameidata fromnd, tond;
        int error;
@@ -1666,14 +1701,6 @@ rename(p, uap, retval)
                        error = EISDIR;
                        goto out;
                }
                        error = EISDIR;
                        goto out;
                }
-               if (fvp->v_mount != tvp->v_mount) {
-                       error = EXDEV;
-                       goto out;
-               }
-       }
-       if (fvp->v_mount != tdvp->v_mount) {
-               error = EXDEV;
-               goto out;
        }
        if (fvp == tdvp)
                error = EINVAL;
        }
        if (fvp == tdvp)
                error = EINVAL;
@@ -1724,17 +1751,16 @@ out1:
 /*
  * Mkdir system call.
  */
 /*
  * Mkdir system call.
  */
+struct mkdir_args {
+       char    *name;
+       int     dmode;
+};
 /* ARGSUSED */
 mkdir(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 mkdir(p, uap, retval)
        struct proc *p;
-       register struct args {
-               char    *name;
-               int     dmode;
-       } *uap;
+       register struct mkdir_args *uap;
        int *retval;
 {
        int *retval;
 {
-       USES_VOP_ABORTOP;
-       USES_VOP_MKDIR;
        register struct vnode *vp;
        struct vattr vattr;
        int error;
        register struct vnode *vp;
        struct vattr vattr;
        int error;
@@ -1769,16 +1795,15 @@ mkdir(p, uap, retval)
 /*
  * Rmdir system call.
  */
 /*
  * Rmdir system call.
  */
+struct rmdir_args {
+       char    *name;
+};
 /* ARGSUSED */
 rmdir(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 rmdir(p, uap, retval)
        struct proc *p;
-       struct args {
-               char    *name;
-       } *uap;
+       struct rmdir_args *uap;
        int *retval;
 {
        int *retval;
 {
-       USES_VOP_ABORTOP;
-       USES_VOP_RMDIR;
        register struct vnode *vp;
        int error;
        struct nameidata nd;
        register struct vnode *vp;
        int error;
        struct nameidata nd;
@@ -1821,34 +1846,132 @@ out:
        return (error);
 }
 
        return (error);
 }
 
+#ifdef COMPAT_43
+/*
+ * Read a block of directory entries in a file system independent format.
+ */
+struct ogetdirentries_args {
+       int     fd;
+       char    *buf;
+       unsigned count;
+       long    *basep;
+};
+ogetdirentries(p, uap, retval)
+       struct proc *p;
+       register struct ogetdirentries_args *uap;
+       int *retval;
+{
+       register struct vnode *vp;
+       struct file *fp;
+       struct uio auio, kuio;
+       struct iovec aiov, kiov;
+       struct dirent *dp, *edp;
+       caddr_t dirbuf;
+       int error, readcnt;
+       long loff;
+
+       if (error = getvnode(p->p_fd, uap->fd, &fp))
+               return (error);
+       if ((fp->f_flag & FREAD) == 0)
+               return (EBADF);
+       vp = (struct vnode *)fp->f_data;
+       if (vp->v_type != VDIR)
+               return (EINVAL);
+       aiov.iov_base = uap->buf;
+       aiov.iov_len = uap->count;
+       auio.uio_iov = &aiov;
+       auio.uio_iovcnt = 1;
+       auio.uio_rw = UIO_READ;
+       auio.uio_segflg = UIO_USERSPACE;
+       auio.uio_procp = p;
+       auio.uio_resid = uap->count;
+       VOP_LOCK(vp);
+       loff = auio.uio_offset = fp->f_offset;
+#      if (BYTE_ORDER != LITTLE_ENDIAN)
+               if (vp->v_mount->mnt_maxsymlinklen <= 0) {
+                       error = VOP_READDIR(vp, &auio, fp->f_cred);
+                       fp->f_offset = auio.uio_offset;
+               } else
+#      endif
+       {
+               kuio = auio;
+               kuio.uio_iov = &kiov;
+               kuio.uio_segflg = UIO_SYSSPACE;
+               kiov.iov_len = uap->count;
+               MALLOC(dirbuf, caddr_t, uap->count, M_TEMP, M_WAITOK);
+               kiov.iov_base = dirbuf;
+               error = VOP_READDIR(vp, &kuio, fp->f_cred);
+               fp->f_offset = kuio.uio_offset;
+               if (error == 0) {
+                       readcnt = uap->count - kuio.uio_resid;
+                       edp = (struct dirent *)&dirbuf[readcnt];
+                       for (dp = (struct dirent *)dirbuf; dp < edp; ) {
+#                              if (BYTE_ORDER == LITTLE_ENDIAN)
+                                       /*
+                                        * The expected low byte of
+                                        * dp->d_namlen is our dp->d_type.
+                                        * The high MBZ byte of dp->d_namlen
+                                        * is our dp->d_namlen.
+                                        */
+                                       dp->d_type = dp->d_namlen;
+                                       dp->d_namlen = 0;
+#                              else
+                                       /*
+                                        * The dp->d_type is the high byte
+                                        * of the expected dp->d_namlen,
+                                        * so must be zero'ed.
+                                        */
+                                       dp->d_type = 0;
+#                              endif
+                               if (dp->d_reclen > 0) {
+                                       dp = (struct dirent *)
+                                           ((char *)dp + dp->d_reclen);
+                               } else {
+                                       error = EIO;
+                                       break;
+                               }
+                       }
+                       if (dp >= edp)
+                               error = uiomove(dirbuf, readcnt, &auio);
+               }
+               FREE(dirbuf, M_TEMP);
+       }
+       VOP_UNLOCK(vp);
+       if (error)
+               return (error);
+       error = copyout((caddr_t)&loff, (caddr_t)uap->basep, sizeof(long));
+       *retval = uap->count - auio.uio_resid;
+       return (error);
+}
+#endif
+
 /*
  * Read a block of directory entries in a file system independent format.
  */
 /*
  * Read a block of directory entries in a file system independent format.
  */
+struct getdirentries_args {
+       int     fd;
+       char    *buf;
+       unsigned count;
+       long    *basep;
+};
 getdirentries(p, uap, retval)
        struct proc *p;
 getdirentries(p, uap, retval)
        struct proc *p;
-       register struct args {
-               int     fd;
-               char    *buf;
-               unsigned count;
-               long    *basep;
-       } *uap;
+       register struct getdirentries_args *uap;
        int *retval;
 {
        int *retval;
 {
-       USES_VOP_LOCK;
-       USES_VOP_READDIR;
-       USES_VOP_UNLOCK;
        register struct vnode *vp;
        struct file *fp;
        struct uio auio;
        struct iovec aiov;
        register struct vnode *vp;
        struct file *fp;
        struct uio auio;
        struct iovec aiov;
-       off_t off;
-       int error, eofflag;
+       long loff;
+       int error;
 
        if (error = getvnode(p->p_fd, uap->fd, &fp))
                return (error);
        if ((fp->f_flag & FREAD) == 0)
                return (EBADF);
        vp = (struct vnode *)fp->f_data;
 
        if (error = getvnode(p->p_fd, uap->fd, &fp))
                return (error);
        if ((fp->f_flag & FREAD) == 0)
                return (EBADF);
        vp = (struct vnode *)fp->f_data;
+unionread:
        if (vp->v_type != VDIR)
                return (EINVAL);
        aiov.iov_base = uap->buf;
        if (vp->v_type != VDIR)
                return (EINVAL);
        aiov.iov_base = uap->buf;
@@ -1860,13 +1983,24 @@ getdirentries(p, uap, retval)
        auio.uio_procp = p;
        auio.uio_resid = uap->count;
        VOP_LOCK(vp);
        auio.uio_procp = p;
        auio.uio_resid = uap->count;
        VOP_LOCK(vp);
-       auio.uio_offset = off = fp->f_offset;
-       error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag);
+       loff = auio.uio_offset = fp->f_offset;
+       error = VOP_READDIR(vp, &auio, fp->f_cred);
        fp->f_offset = auio.uio_offset;
        VOP_UNLOCK(vp);
        if (error)
                return (error);
        fp->f_offset = auio.uio_offset;
        VOP_UNLOCK(vp);
        if (error)
                return (error);
-       error = copyout((caddr_t)&off, (caddr_t)uap->basep, sizeof(long));
+       if ((uap->count == auio.uio_resid) &&
+           (vp->v_flag & VROOT) &&
+           (vp->v_mount->mnt_flag & MNT_UNION)) {
+               struct vnode *tvp = vp;
+               vp = vp->v_mount->mnt_vnodecovered;
+               VREF(vp);
+               fp->f_data = (caddr_t) vp;
+               fp->f_offset = 0;
+               vrele(tvp);
+               goto unionread;
+       }
+       error = copyout((caddr_t)&loff, (caddr_t)uap->basep, sizeof(long));
        *retval = uap->count - auio.uio_resid;
        return (error);
 }
        *retval = uap->count - auio.uio_resid;
        return (error);
 }
@@ -1874,12 +2008,13 @@ getdirentries(p, uap, retval)
 /*
  * Set the mode mask for creation of filesystem nodes.
  */
 /*
  * Set the mode mask for creation of filesystem nodes.
  */
-mode_t
+struct umask_args {
+       int     mask;
+};
+mode_t                         /* XXX */
 umask(p, uap, retval)
        struct proc *p;
 umask(p, uap, retval)
        struct proc *p;
-       struct args {
-               int     mask;
-       } *uap;
+       struct umask_args *uap;
        int *retval;
 {
        register struct filedesc *fdp = p->p_fd;
        int *retval;
 {
        register struct filedesc *fdp = p->p_fd;
@@ -1893,15 +2028,15 @@ umask(p, uap, retval)
  * Void all references to file by ripping underlying filesystem
  * away from vnode.
  */
  * Void all references to file by ripping underlying filesystem
  * away from vnode.
  */
+struct revoke_args {
+       char    *fname;
+};
 /* ARGSUSED */
 revoke(p, uap, retval)
        struct proc *p;
 /* ARGSUSED */
 revoke(p, uap, retval)
        struct proc *p;
-       register struct args {
-               char    *fname;
-       } *uap;
+       register struct revoke_args *uap;
        int *retval;
 {
        int *retval;
 {
-       USES_VOP_GETATTR;
        register struct vnode *vp;
        struct vattr vattr;
        int error;
        register struct vnode *vp;
        struct vattr vattr;
        int error;