Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_fs.c revision 1.90
      1  1.90        ad /*	$NetBSD: netbsd32_fs.c,v 1.90 2020/05/23 23:42:42 ad Exp $	*/
      2   1.1       mrg 
      3   1.1       mrg /*
      4   1.1       mrg  * Copyright (c) 1998, 2001 Matthew R. Green
      5   1.1       mrg  * All rights reserved.
      6   1.1       mrg  *
      7   1.1       mrg  * Redistribution and use in source and binary forms, with or without
      8   1.1       mrg  * modification, are permitted provided that the following conditions
      9   1.1       mrg  * are met:
     10   1.1       mrg  * 1. Redistributions of source code must retain the above copyright
     11   1.1       mrg  *    notice, this list of conditions and the following disclaimer.
     12   1.1       mrg  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1       mrg  *    notice, this list of conditions and the following disclaimer in the
     14   1.1       mrg  *    documentation and/or other materials provided with the distribution.
     15   1.1       mrg  *
     16   1.1       mrg  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17   1.1       mrg  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18   1.1       mrg  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19   1.1       mrg  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20   1.1       mrg  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21   1.1       mrg  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22   1.1       mrg  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23   1.1       mrg  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24   1.1       mrg  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25   1.1       mrg  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26   1.1       mrg  * SUCH DAMAGE.
     27   1.1       mrg  */
     28   1.7     lukem 
     29   1.7     lukem #include <sys/cdefs.h>
     30  1.90        ad __KERNEL_RCSID(0, "$NetBSD: netbsd32_fs.c,v 1.90 2020/05/23 23:42:42 ad Exp $");
     31   1.1       mrg 
     32   1.1       mrg #include <sys/param.h>
     33   1.1       mrg #include <sys/systm.h>
     34   1.1       mrg #include <sys/mount.h>
     35   1.1       mrg #include <sys/socket.h>
     36   1.1       mrg #include <sys/socketvar.h>
     37   1.1       mrg #include <sys/stat.h>
     38   1.1       mrg #include <sys/time.h>
     39   1.1       mrg #include <sys/ktrace.h>
     40   1.1       mrg #include <sys/resourcevar.h>
     41   1.1       mrg #include <sys/vnode.h>
     42   1.1       mrg #include <sys/file.h>
     43   1.1       mrg #include <sys/filedesc.h>
     44   1.1       mrg #include <sys/namei.h>
     45  1.18      cube #include <sys/statvfs.h>
     46   1.1       mrg #include <sys/syscallargs.h>
     47   1.1       mrg #include <sys/proc.h>
     48  1.22  christos #include <sys/dirent.h>
     49  1.27      elad #include <sys/kauth.h>
     50  1.37       dsl #include <sys/vfs_syscalls.h>
     51   1.1       mrg 
     52  1.58      matt #include <fs/cd9660/cd9660_mount.h>
     53  1.72  christos #include <fs/tmpfs/tmpfs_args.h>
     54  1.63  macallan #include <fs/msdosfs/bpb.h>
     55  1.63  macallan #include <fs/msdosfs/msdosfsmount.h>
     56  1.58      matt #include <ufs/ufs/ufsmount.h>
     57  1.81       mrg #include <miscfs/nullfs/null.h>
     58  1.58      matt 
     59  1.60      matt #define NFS_ARGS_ONLY
     60  1.60      matt #include <nfs/nfsmount.h>
     61  1.60      matt 
     62   1.1       mrg #include <compat/netbsd32/netbsd32.h>
     63   1.1       mrg #include <compat/netbsd32/netbsd32_syscallargs.h>
     64   1.1       mrg #include <compat/netbsd32/netbsd32_conv.h>
     65  1.28    martin #include <compat/sys/mount.h>
     66   1.1       mrg 
     67   1.1       mrg 
     68  1.51        ad static int dofilereadv32(int, struct file *, struct netbsd32_iovec *,
     69  1.47       dsl 			      int, off_t *, int, register_t *);
     70  1.51        ad static int dofilewritev32(int, struct file *, struct netbsd32_iovec *,
     71  1.47       dsl 			       int,  off_t *, int, register_t *);
     72   1.1       mrg 
     73  1.45       dsl struct iovec *
     74  1.45       dsl netbsd32_get_iov(struct netbsd32_iovec *iov32, int iovlen, struct iovec *aiov,
     75  1.45       dsl     int aiov_len)
     76  1.45       dsl {
     77  1.45       dsl #define N_IOV32 8
     78  1.45       dsl 	struct netbsd32_iovec aiov32[N_IOV32];
     79  1.45       dsl 	struct iovec *iov = aiov;
     80  1.45       dsl 	struct iovec *iovp;
     81  1.45       dsl 	int i, n, j;
     82  1.45       dsl 	int error;
     83  1.45       dsl 
     84  1.45       dsl 	if (iovlen < 0 || iovlen > IOV_MAX)
     85  1.45       dsl 		return NULL;
     86  1.45       dsl 
     87  1.45       dsl 	if (iovlen > aiov_len)
     88  1.59     rmind 		iov = kmem_alloc(iovlen * sizeof(*iov), KM_SLEEP);
     89  1.45       dsl 
     90  1.45       dsl 	iovp = iov;
     91  1.45       dsl 	for (i = 0; i < iovlen; iov32 += N_IOV32, i += N_IOV32) {
     92  1.45       dsl 		n = iovlen - i;
     93  1.45       dsl 		if (n > N_IOV32)
     94  1.45       dsl 			n = N_IOV32;
     95  1.45       dsl 		error = copyin(iov32, aiov32, n * sizeof (*iov32));
     96  1.45       dsl 		if (error != 0) {
     97  1.45       dsl 			if (iov != aiov)
     98  1.59     rmind 				kmem_free(iov, iovlen * sizeof(*iov));
     99  1.45       dsl 			return NULL;
    100  1.45       dsl 		}
    101  1.45       dsl 		for (j = 0; j < n; iovp++, j++) {
    102  1.45       dsl 			iovp->iov_base = NETBSD32PTR64(aiov32[j].iov_base);
    103  1.45       dsl 			iovp->iov_len = aiov32[j].iov_len;
    104  1.45       dsl 		}
    105  1.45       dsl 	}
    106  1.45       dsl 	return iov;
    107  1.45       dsl #undef N_IOV32
    108  1.45       dsl }
    109  1.45       dsl 
    110   1.1       mrg int
    111  1.49       dsl netbsd32_readv(struct lwp *l, const struct netbsd32_readv_args *uap, register_t *retval)
    112   1.1       mrg {
    113  1.49       dsl 	/* {
    114   1.1       mrg 		syscallarg(int) fd;
    115   1.1       mrg 		syscallarg(const netbsd32_iovecp_t) iovp;
    116   1.1       mrg 		syscallarg(int) iovcnt;
    117  1.49       dsl 	} */
    118   1.1       mrg 	int fd = SCARG(uap, fd);
    119  1.51        ad 	file_t *fp;
    120   1.1       mrg 
    121  1.51        ad 	if ((fp = fd_getfile(fd)) == NULL)
    122   1.6   thorpej 		return (EBADF);
    123   1.6   thorpej 
    124  1.50       dsl 	if ((fp->f_flag & FREAD) == 0) {
    125  1.51        ad 		fd_putfile(fd);
    126   1.1       mrg 		return (EBADF);
    127  1.50       dsl 	}
    128   1.1       mrg 
    129  1.51        ad 	return (dofilereadv32(fd, fp,
    130  1.39       dsl 	    (struct netbsd32_iovec *)SCARG_P32(uap, iovp),
    131  1.10       scw 	    SCARG(uap, iovcnt), &fp->f_offset, FOF_UPDATE_OFFSET, retval));
    132   1.1       mrg }
    133   1.1       mrg 
    134   1.1       mrg /* Damn thing copies in the iovec! */
    135   1.1       mrg int
    136  1.51        ad dofilereadv32(int fd, struct file *fp, struct netbsd32_iovec *iovp, int iovcnt, off_t *offset, int flags, register_t *retval)
    137   1.1       mrg {
    138   1.1       mrg 	struct uio auio;
    139   1.1       mrg 	struct iovec *iov;
    140   1.1       mrg 	struct iovec *needfree;
    141   1.1       mrg 	struct iovec aiov[UIO_SMALLIOV];
    142  1.85  christos 	long i, error = 0;
    143  1.85  christos 	size_t cnt;
    144   1.1       mrg 	u_int iovlen;
    145   1.1       mrg 	struct iovec *ktriov = NULL;
    146   1.1       mrg 
    147   1.1       mrg 	/* note: can't use iovlen until iovcnt is validated */
    148   1.1       mrg 	iovlen = iovcnt * sizeof(struct iovec);
    149   1.1       mrg 	if ((u_int)iovcnt > UIO_SMALLIOV) {
    150   1.9  jdolecek 		if ((u_int)iovcnt > IOV_MAX) {
    151   1.9  jdolecek 			error = EINVAL;
    152   1.9  jdolecek 			goto out;
    153   1.9  jdolecek 		}
    154  1.59     rmind 		iov = kmem_alloc(iovlen, KM_SLEEP);
    155   1.1       mrg 		needfree = iov;
    156   1.1       mrg 	} else if ((u_int)iovcnt > 0) {
    157   1.1       mrg 		iov = aiov;
    158   1.1       mrg 		needfree = NULL;
    159   1.9  jdolecek 	} else {
    160   1.9  jdolecek 		error = EINVAL;
    161   1.9  jdolecek 		goto out;
    162   1.9  jdolecek 	}
    163   1.1       mrg 
    164   1.1       mrg 	auio.uio_iov = iov;
    165   1.1       mrg 	auio.uio_iovcnt = iovcnt;
    166   1.1       mrg 	auio.uio_rw = UIO_READ;
    167  1.51        ad 	auio.uio_vmspace = curproc->p_vmspace;
    168   1.1       mrg 	error = netbsd32_to_iovecin(iovp, iov, iovcnt);
    169   1.1       mrg 	if (error)
    170   1.1       mrg 		goto done;
    171   1.1       mrg 	auio.uio_resid = 0;
    172   1.1       mrg 	for (i = 0; i < iovcnt; i++) {
    173   1.1       mrg 		auio.uio_resid += iov->iov_len;
    174   1.1       mrg 		/*
    175   1.1       mrg 		 * Reads return ssize_t because -1 is returned on error.
    176   1.1       mrg 		 * Therefore we must restrict the length to SSIZE_MAX to
    177   1.1       mrg 		 * avoid garbage return values.
    178   1.1       mrg 		 */
    179   1.1       mrg 		if (iov->iov_len > SSIZE_MAX || auio.uio_resid > SSIZE_MAX) {
    180   1.1       mrg 			error = EINVAL;
    181   1.1       mrg 			goto done;
    182   1.1       mrg 		}
    183   1.1       mrg 		iov++;
    184   1.1       mrg 	}
    185  1.46        ad 
    186   1.1       mrg 	/*
    187   1.1       mrg 	 * if tracing, save a copy of iovec
    188   1.1       mrg 	 */
    189  1.46        ad 	if (ktrpoint(KTR_GENIO)) {
    190  1.59     rmind 		ktriov = kmem_alloc(iovlen, KM_SLEEP);
    191  1.36  christos 		memcpy((void *)ktriov, (void *)auio.uio_iov, iovlen);
    192   1.1       mrg 	}
    193  1.46        ad 
    194   1.1       mrg 	cnt = auio.uio_resid;
    195   1.1       mrg 	error = (*fp->f_ops->fo_read)(fp, offset, &auio, fp->f_cred, flags);
    196   1.1       mrg 	if (error)
    197   1.1       mrg 		if (auio.uio_resid != cnt && (error == ERESTART ||
    198   1.1       mrg 		    error == EINTR || error == EWOULDBLOCK))
    199   1.1       mrg 			error = 0;
    200   1.1       mrg 	cnt -= auio.uio_resid;
    201  1.46        ad 
    202  1.46        ad 	if (ktriov != NULL) {
    203  1.46        ad 		ktrgeniov(fd, UIO_READ, ktriov, cnt, error);
    204  1.59     rmind 		kmem_free(ktriov, iovlen);
    205   1.1       mrg 	}
    206  1.46        ad 
    207   1.1       mrg 	*retval = cnt;
    208   1.1       mrg done:
    209   1.1       mrg 	if (needfree)
    210  1.59     rmind 		kmem_free(needfree, iovlen);
    211   1.9  jdolecek out:
    212  1.51        ad 	fd_putfile(fd);
    213   1.1       mrg 	return (error);
    214   1.1       mrg }
    215   1.1       mrg 
    216   1.1       mrg int
    217  1.49       dsl netbsd32_writev(struct lwp *l, const struct netbsd32_writev_args *uap, register_t *retval)
    218   1.1       mrg {
    219  1.49       dsl 	/* {
    220   1.1       mrg 		syscallarg(int) fd;
    221   1.1       mrg 		syscallarg(const netbsd32_iovecp_t) iovp;
    222   1.1       mrg 		syscallarg(int) iovcnt;
    223  1.49       dsl 	} */
    224   1.1       mrg 	int fd = SCARG(uap, fd);
    225  1.51        ad 	file_t *fp;
    226   1.1       mrg 
    227  1.51        ad 	if ((fp = fd_getfile(fd)) == NULL)
    228   1.6   thorpej 		return (EBADF);
    229   1.6   thorpej 
    230  1.50       dsl 	if ((fp->f_flag & FWRITE) == 0) {
    231  1.51        ad 		fd_putfile(fd);
    232   1.1       mrg 		return (EBADF);
    233  1.50       dsl 	}
    234   1.1       mrg 
    235  1.51        ad 	return (dofilewritev32(fd, fp,
    236  1.39       dsl 	    (struct netbsd32_iovec *)SCARG_P32(uap, iovp),
    237  1.10       scw 	    SCARG(uap, iovcnt), &fp->f_offset, FOF_UPDATE_OFFSET, retval));
    238   1.1       mrg }
    239   1.1       mrg 
    240   1.1       mrg int
    241  1.51        ad dofilewritev32(int fd, struct file *fp, struct netbsd32_iovec *iovp, int iovcnt, off_t *offset, int flags, register_t *retval)
    242   1.1       mrg {
    243   1.1       mrg 	struct uio auio;
    244   1.1       mrg 	struct iovec *iov;
    245   1.1       mrg 	struct iovec *needfree;
    246   1.1       mrg 	struct iovec aiov[UIO_SMALLIOV];
    247  1.85  christos 	long i, error = 0;
    248  1.85  christos 	size_t cnt;
    249   1.1       mrg 	u_int iovlen;
    250   1.1       mrg 	struct iovec *ktriov = NULL;
    251   1.1       mrg 
    252   1.1       mrg 	/* note: can't use iovlen until iovcnt is validated */
    253   1.1       mrg 	iovlen = iovcnt * sizeof(struct iovec);
    254   1.1       mrg 	if ((u_int)iovcnt > UIO_SMALLIOV) {
    255   1.9  jdolecek 		if ((u_int)iovcnt > IOV_MAX) {
    256   1.9  jdolecek 			error = EINVAL;
    257   1.9  jdolecek 			goto out;
    258   1.9  jdolecek 		}
    259  1.59     rmind 		iov = kmem_alloc(iovlen, KM_SLEEP);
    260   1.1       mrg 		needfree = iov;
    261   1.1       mrg 	} else if ((u_int)iovcnt > 0) {
    262   1.1       mrg 		iov = aiov;
    263   1.1       mrg 		needfree = NULL;
    264   1.9  jdolecek 	} else {
    265   1.9  jdolecek 		error = EINVAL;
    266   1.9  jdolecek 		goto out;
    267   1.9  jdolecek 	}
    268   1.1       mrg 
    269   1.1       mrg 	auio.uio_iov = iov;
    270   1.1       mrg 	auio.uio_iovcnt = iovcnt;
    271   1.1       mrg 	auio.uio_rw = UIO_WRITE;
    272  1.51        ad 	auio.uio_vmspace = curproc->p_vmspace;
    273   1.1       mrg 	error = netbsd32_to_iovecin(iovp, iov, iovcnt);
    274   1.1       mrg 	if (error)
    275   1.1       mrg 		goto done;
    276   1.1       mrg 	auio.uio_resid = 0;
    277   1.1       mrg 	for (i = 0; i < iovcnt; i++) {
    278   1.1       mrg 		auio.uio_resid += iov->iov_len;
    279   1.1       mrg 		/*
    280   1.1       mrg 		 * Writes return ssize_t because -1 is returned on error.
    281   1.1       mrg 		 * Therefore we must restrict the length to SSIZE_MAX to
    282   1.1       mrg 		 * avoid garbage return values.
    283   1.1       mrg 		 */
    284   1.1       mrg 		if (iov->iov_len > SSIZE_MAX || auio.uio_resid > SSIZE_MAX) {
    285   1.1       mrg 			error = EINVAL;
    286   1.1       mrg 			goto done;
    287   1.1       mrg 		}
    288   1.1       mrg 		iov++;
    289   1.1       mrg 	}
    290  1.46        ad 
    291   1.1       mrg 	/*
    292   1.1       mrg 	 * if tracing, save a copy of iovec
    293   1.1       mrg 	 */
    294  1.46        ad 	if (ktrpoint(KTR_GENIO))  {
    295  1.59     rmind 		ktriov = kmem_alloc(iovlen, KM_SLEEP);
    296  1.36  christos 		memcpy((void *)ktriov, (void *)auio.uio_iov, iovlen);
    297   1.1       mrg 	}
    298  1.46        ad 
    299   1.1       mrg 	cnt = auio.uio_resid;
    300   1.1       mrg 	error = (*fp->f_ops->fo_write)(fp, offset, &auio, fp->f_cred, flags);
    301   1.1       mrg 	if (error) {
    302   1.1       mrg 		if (auio.uio_resid != cnt && (error == ERESTART ||
    303   1.1       mrg 		    error == EINTR || error == EWOULDBLOCK))
    304   1.1       mrg 			error = 0;
    305  1.62  christos 		if (error == EPIPE && (fp->f_flag & FNOSIGPIPE) == 0) {
    306  1.90        ad 			mutex_enter(&proc_lock);
    307  1.51        ad 			psignal(curproc, SIGPIPE);
    308  1.90        ad 			mutex_exit(&proc_lock);
    309  1.44        ad 		}
    310   1.1       mrg 	}
    311   1.1       mrg 	cnt -= auio.uio_resid;
    312  1.46        ad 	if (ktriov != NULL) {
    313  1.75  dholland 		ktrgeniov(fd, UIO_WRITE, ktriov, cnt, error);
    314  1.59     rmind 		kmem_free(ktriov, iovlen);
    315   1.1       mrg 	}
    316   1.1       mrg 	*retval = cnt;
    317   1.1       mrg done:
    318   1.1       mrg 	if (needfree)
    319  1.59     rmind 		kmem_free(needfree, iovlen);
    320   1.9  jdolecek out:
    321  1.51        ad 	fd_putfile(fd);
    322   1.1       mrg 	return (error);
    323   1.1       mrg }
    324   1.1       mrg 
    325  1.43       dsl /*
    326  1.68     njoly  * Common routines to set access and modification times given a vnode.
    327  1.43       dsl  */
    328  1.43       dsl static int
    329  1.43       dsl get_utimes32(const netbsd32_timevalp_t *tptr, struct timeval *tv,
    330  1.43       dsl     struct timeval **tvp)
    331  1.43       dsl {
    332  1.43       dsl 	int error;
    333  1.43       dsl 	struct netbsd32_timeval tv32[2];
    334  1.43       dsl 
    335  1.43       dsl 	if (tptr == NULL) {
    336  1.43       dsl 		*tvp = NULL;
    337  1.43       dsl 		return 0;
    338  1.43       dsl 	}
    339  1.43       dsl 
    340  1.43       dsl 	error = copyin(tptr, tv32, sizeof(tv32));
    341  1.43       dsl 	if (error)
    342  1.43       dsl 		return error;
    343  1.43       dsl 	netbsd32_to_timeval(&tv32[0], &tv[0]);
    344  1.43       dsl 	netbsd32_to_timeval(&tv32[1], &tv[1]);
    345  1.43       dsl 
    346  1.43       dsl 	*tvp = tv;
    347  1.43       dsl 	return 0;
    348  1.43       dsl }
    349  1.43       dsl 
    350  1.68     njoly static int
    351  1.68     njoly get_utimens32(const netbsd32_timespecp_t *tptr, struct timespec *ts,
    352  1.68     njoly     struct timespec **tsp)
    353  1.68     njoly {
    354  1.68     njoly 	int error;
    355  1.68     njoly 	struct netbsd32_timespec ts32[2];
    356  1.68     njoly 
    357  1.68     njoly 	if (tptr == NULL) {
    358  1.68     njoly 		*tsp = NULL;
    359  1.68     njoly 		return 0;
    360  1.68     njoly 	}
    361  1.68     njoly 
    362  1.68     njoly 	error = copyin(tptr, ts32, sizeof(ts32));
    363  1.68     njoly 	if (error)
    364  1.68     njoly 		return error;
    365  1.68     njoly 	netbsd32_to_timespec(&ts32[0], &ts[0]);
    366  1.68     njoly 	netbsd32_to_timespec(&ts32[1], &ts[1]);
    367  1.68     njoly 
    368  1.68     njoly 	*tsp = ts;
    369  1.68     njoly 	return 0;
    370  1.68     njoly }
    371  1.68     njoly 
    372   1.1       mrg int
    373  1.56  christos netbsd32___utimes50(struct lwp *l, const struct netbsd32___utimes50_args *uap, register_t *retval)
    374   1.1       mrg {
    375  1.49       dsl 	/* {
    376   1.1       mrg 		syscallarg(const netbsd32_charp) path;
    377   1.1       mrg 		syscallarg(const netbsd32_timevalp_t) tptr;
    378  1.49       dsl 	} */
    379   1.1       mrg 	int error;
    380  1.43       dsl 	struct timeval tv[2], *tvp;
    381   1.1       mrg 
    382  1.43       dsl 	error = get_utimes32(SCARG_P32(uap, tptr), tv, &tvp);
    383  1.43       dsl 	if (error != 0)
    384  1.43       dsl 		return error;
    385   1.1       mrg 
    386  1.43       dsl 	return do_sys_utimes(l, NULL, SCARG_P32(uap, path), FOLLOW,
    387  1.43       dsl 			    tvp, UIO_SYSSPACE);
    388   1.1       mrg }
    389   1.1       mrg 
    390  1.42       dsl static int
    391  1.79       mrg netbsd32_copyout_statvfs(const void *kp, void *up, size_t len)
    392  1.42       dsl {
    393  1.42       dsl 	struct netbsd32_statvfs *sbuf_32;
    394  1.42       dsl 	int error;
    395  1.42       dsl 
    396  1.59     rmind 	sbuf_32 = kmem_alloc(sizeof(*sbuf_32), KM_SLEEP);
    397  1.42       dsl 	netbsd32_from_statvfs(kp, sbuf_32);
    398  1.42       dsl 	error = copyout(sbuf_32, up, sizeof(*sbuf_32));
    399  1.59     rmind 	kmem_free(sbuf_32, sizeof(*sbuf_32));
    400  1.42       dsl 
    401  1.42       dsl 	return error;
    402  1.42       dsl }
    403  1.42       dsl 
    404   1.1       mrg int
    405  1.84  christos netbsd32___statvfs190(struct lwp *l,
    406  1.84  christos     const struct netbsd32___statvfs190_args *uap, register_t *retval)
    407   1.1       mrg {
    408  1.49       dsl 	/* {
    409   1.1       mrg 		syscallarg(const netbsd32_charp) path;
    410  1.18      cube 		syscallarg(netbsd32_statvfsp_t) buf;
    411  1.18      cube 		syscallarg(int) flags;
    412  1.49       dsl 	} */
    413  1.42       dsl 	struct statvfs *sb;
    414   1.1       mrg 	int error;
    415   1.1       mrg 
    416  1.42       dsl 	sb = STATVFSBUF_GET();
    417  1.42       dsl 	error = do_sys_pstatvfs(l, SCARG_P32(uap, path), SCARG(uap, flags), sb);
    418  1.42       dsl 	if (error == 0)
    419  1.79       mrg 		error = netbsd32_copyout_statvfs(sb, SCARG_P32(uap, buf), 0);
    420  1.42       dsl 	STATVFSBUF_PUT(sb);
    421  1.42       dsl 	return error;
    422   1.1       mrg }
    423   1.1       mrg 
    424   1.1       mrg int
    425  1.84  christos netbsd32___fstatvfs190(struct lwp *l,
    426  1.84  christos     const struct netbsd32___fstatvfs190_args *uap, register_t *retval)
    427   1.1       mrg {
    428  1.49       dsl 	/* {
    429   1.1       mrg 		syscallarg(int) fd;
    430  1.18      cube 		syscallarg(netbsd32_statvfsp_t) buf;
    431  1.18      cube 		syscallarg(int) flags;
    432  1.49       dsl 	} */
    433  1.42       dsl 	struct statvfs *sb;
    434   1.1       mrg 	int error;
    435   1.1       mrg 
    436  1.42       dsl 	sb = STATVFSBUF_GET();
    437  1.42       dsl 	error = do_sys_fstatvfs(l, SCARG(uap, fd), SCARG(uap, flags), sb);
    438  1.42       dsl 	if (error == 0)
    439  1.79       mrg 		error = netbsd32_copyout_statvfs(sb, SCARG_P32(uap, buf), 0);
    440  1.42       dsl 	STATVFSBUF_PUT(sb);
    441  1.18      cube 	return error;
    442  1.18      cube }
    443  1.18      cube 
    444  1.18      cube int
    445  1.84  christos netbsd32___getvfsstat90(struct lwp *l,
    446  1.84  christos     const struct netbsd32___getvfsstat90_args *uap, register_t *retval)
    447  1.18      cube {
    448  1.49       dsl 	/* {
    449  1.18      cube 		syscallarg(netbsd32_statvfsp_t) buf;
    450  1.18      cube 		syscallarg(netbsd32_size_t) bufsize;
    451  1.18      cube 		syscallarg(int) flags;
    452  1.49       dsl 	} */
    453  1.18      cube 
    454  1.42       dsl 	return do_sys_getvfsstat(l, SCARG_P32(uap, buf), SCARG(uap, bufsize),
    455  1.79       mrg 	    SCARG(uap, flags), netbsd32_copyout_statvfs,
    456  1.42       dsl 	    sizeof (struct netbsd32_statvfs), retval);
    457  1.18      cube }
    458  1.18      cube 
    459  1.18      cube int
    460  1.84  christos netbsd32___fhstatvfs190(struct lwp *l,
    461  1.84  christos     const struct netbsd32___fhstatvfs190_args *uap, register_t *retval)
    462  1.18      cube {
    463  1.49       dsl 	/* {
    464  1.32    martin 		syscallarg(const netbsd32_pointer_t) fhp;
    465  1.32    martin 		syscallarg(netbsd32_size_t) fh_size;
    466  1.18      cube 		syscallarg(netbsd32_statvfsp_t) buf;
    467  1.18      cube 		syscallarg(int) flags;
    468  1.49       dsl 	} */
    469  1.42       dsl 	struct statvfs *sb;
    470  1.18      cube 	int error;
    471  1.18      cube 
    472  1.42       dsl 	sb = STATVFSBUF_GET();
    473  1.42       dsl 	error = do_fhstatvfs(l, SCARG_P32(uap, fhp), SCARG(uap, fh_size), sb,
    474  1.42       dsl 	    SCARG(uap, flags));
    475  1.42       dsl 
    476  1.42       dsl 	if (error == 0)
    477  1.79       mrg 		error = netbsd32_copyout_statvfs(sb, SCARG_P32(uap, buf), 0);
    478  1.42       dsl 	STATVFSBUF_PUT(sb);
    479  1.18      cube 
    480  1.42       dsl 	return error;
    481   1.1       mrg }
    482   1.1       mrg 
    483   1.1       mrg int
    484  1.56  christos netbsd32___futimes50(struct lwp *l, const struct netbsd32___futimes50_args *uap, register_t *retval)
    485   1.1       mrg {
    486  1.49       dsl 	/* {
    487   1.1       mrg 		syscallarg(int) fd;
    488   1.1       mrg 		syscallarg(const netbsd32_timevalp_t) tptr;
    489  1.49       dsl 	} */
    490   1.1       mrg 	int error;
    491  1.51        ad 	file_t *fp;
    492  1.43       dsl 	struct timeval tv[2], *tvp;
    493  1.43       dsl 
    494  1.43       dsl 	error = get_utimes32(SCARG_P32(uap, tptr), tv, &tvp);
    495  1.43       dsl 	if (error != 0)
    496  1.43       dsl 		return error;
    497   1.1       mrg 
    498  1.55        ad 	/* fd_getvnode() will use the descriptor for us */
    499  1.51        ad 	if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
    500   1.1       mrg 		return (error);
    501   1.1       mrg 
    502  1.71      matt 	error = do_sys_utimes(l, fp->f_vnode, NULL, 0, tvp, UIO_SYSSPACE);
    503  1.43       dsl 
    504  1.51        ad 	fd_putfile(SCARG(uap, fd));
    505   1.1       mrg 	return (error);
    506   1.1       mrg }
    507   1.1       mrg 
    508   1.1       mrg int
    509  1.56  christos netbsd32___getdents30(struct lwp *l,
    510  1.56  christos     const struct netbsd32___getdents30_args *uap, register_t *retval)
    511   1.1       mrg {
    512  1.49       dsl 	/* {
    513   1.1       mrg 		syscallarg(int) fd;
    514   1.1       mrg 		syscallarg(netbsd32_charp) buf;
    515   1.1       mrg 		syscallarg(netbsd32_size_t) count;
    516  1.49       dsl 	} */
    517  1.51        ad 	file_t *fp;
    518   1.1       mrg 	int error, done;
    519   1.1       mrg 
    520  1.55        ad 	/* fd_getvnode() will use the descriptor for us */
    521  1.51        ad 	if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
    522   1.1       mrg 		return (error);
    523   1.1       mrg 	if ((fp->f_flag & FREAD) == 0) {
    524   1.1       mrg 		error = EBADF;
    525   1.1       mrg 		goto out;
    526   1.1       mrg 	}
    527  1.39       dsl 	error = vn_readdir(fp, SCARG_P32(uap, buf),
    528  1.23  christos 	    UIO_USERSPACE, SCARG(uap, count), &done, l, 0, 0);
    529  1.78       mrg 	ktrgenio(SCARG(uap, fd), UIO_READ, SCARG_P32(uap, buf), done, error);
    530   1.1       mrg 	*retval = done;
    531   1.1       mrg  out:
    532  1.51        ad 	fd_putfile(SCARG(uap, fd));
    533   1.1       mrg 	return (error);
    534   1.1       mrg }
    535   1.1       mrg 
    536   1.1       mrg int
    537  1.56  christos netbsd32___lutimes50(struct lwp *l,
    538  1.56  christos     const struct netbsd32___lutimes50_args *uap, register_t *retval)
    539   1.1       mrg {
    540  1.49       dsl 	/* {
    541   1.1       mrg 		syscallarg(const netbsd32_charp) path;
    542   1.1       mrg 		syscallarg(const netbsd32_timevalp_t) tptr;
    543  1.49       dsl 	} */
    544   1.1       mrg 	int error;
    545  1.43       dsl 	struct timeval tv[2], *tvp;
    546   1.1       mrg 
    547  1.43       dsl 	error = get_utimes32(SCARG_P32(uap, tptr), tv, &tvp);
    548  1.43       dsl 	if (error != 0)
    549  1.43       dsl 		return error;
    550   1.1       mrg 
    551  1.43       dsl 	return do_sys_utimes(l, NULL, SCARG_P32(uap, path), NOFOLLOW,
    552  1.43       dsl 			    tvp, UIO_SYSSPACE);
    553   1.1       mrg }
    554   1.1       mrg 
    555   1.1       mrg int
    556  1.56  christos netbsd32___stat50(struct lwp *l, const struct netbsd32___stat50_args *uap, register_t *retval)
    557   1.1       mrg {
    558  1.49       dsl 	/* {
    559   1.1       mrg 		syscallarg(const netbsd32_charp) path;
    560   1.1       mrg 		syscallarg(netbsd32_statp_t) ub;
    561  1.49       dsl 	} */
    562   1.1       mrg 	struct netbsd32_stat sb32;
    563   1.1       mrg 	struct stat sb;
    564   1.1       mrg 	int error;
    565   1.1       mrg 	const char *path;
    566   1.1       mrg 
    567  1.39       dsl 	path = SCARG_P32(uap, path);
    568   1.1       mrg 
    569  1.51        ad 	error = do_sys_stat(path, FOLLOW, &sb);
    570  1.41       dsl 	if (error)
    571  1.41       dsl 		return (error);
    572  1.56  christos 	netbsd32_from_stat(&sb, &sb32);
    573  1.39       dsl 	error = copyout(&sb32, SCARG_P32(uap, ub), sizeof(sb32));
    574   1.1       mrg 	return (error);
    575   1.1       mrg }
    576   1.1       mrg 
    577   1.1       mrg int
    578  1.56  christos netbsd32___fstat50(struct lwp *l, const struct netbsd32___fstat50_args *uap, register_t *retval)
    579   1.1       mrg {
    580  1.49       dsl 	/* {
    581   1.1       mrg 		syscallarg(int) fd;
    582   1.1       mrg 		syscallarg(netbsd32_statp_t) sb;
    583  1.49       dsl 	} */
    584   1.1       mrg 	struct netbsd32_stat sb32;
    585   1.1       mrg 	struct stat ub;
    586  1.57     njoly 	int error;
    587   1.1       mrg 
    588  1.57     njoly 	error = do_sys_fstat(SCARG(uap, fd), &ub);
    589   1.1       mrg 	if (error == 0) {
    590  1.56  christos 		netbsd32_from_stat(&ub, &sb32);
    591  1.39       dsl 		error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb32));
    592   1.1       mrg 	}
    593   1.1       mrg 	return (error);
    594   1.1       mrg }
    595   1.1       mrg 
    596   1.1       mrg int
    597  1.56  christos netbsd32___lstat50(struct lwp *l, const struct netbsd32___lstat50_args *uap, register_t *retval)
    598   1.1       mrg {
    599  1.49       dsl 	/* {
    600   1.1       mrg 		syscallarg(const netbsd32_charp) path;
    601   1.1       mrg 		syscallarg(netbsd32_statp_t) ub;
    602  1.49       dsl 	} */
    603   1.1       mrg 	struct netbsd32_stat sb32;
    604   1.1       mrg 	struct stat sb;
    605   1.1       mrg 	int error;
    606   1.1       mrg 	const char *path;
    607   1.1       mrg 
    608  1.39       dsl 	path = SCARG_P32(uap, path);
    609   1.1       mrg 
    610  1.51        ad 	error = do_sys_stat(path, NOFOLLOW, &sb);
    611   1.1       mrg 	if (error)
    612   1.1       mrg 		return (error);
    613  1.56  christos 	netbsd32_from_stat(&sb, &sb32);
    614  1.39       dsl 	error = copyout(&sb32, SCARG_P32(uap, ub), sizeof(sb32));
    615   1.1       mrg 	return (error);
    616   1.1       mrg }
    617   1.1       mrg 
    618  1.49       dsl int
    619  1.56  christos netbsd32___fhstat50(struct lwp *l, const struct netbsd32___fhstat50_args *uap, register_t *retval)
    620  1.26      cube {
    621  1.49       dsl 	/* {
    622  1.32    martin 		syscallarg(const netbsd32_pointer_t) fhp;
    623  1.32    martin 		syscallarg(netbsd32_size_t) fh_size;
    624  1.26      cube 		syscallarg(netbsd32_statp_t) sb;
    625  1.49       dsl 	} */
    626  1.26      cube 	struct stat sb;
    627  1.26      cube 	struct netbsd32_stat sb32;
    628  1.26      cube 	int error;
    629  1.26      cube 
    630  1.42       dsl 	error = do_fhstat(l, SCARG_P32(uap, fhp), SCARG(uap, fh_size), &sb);
    631  1.64      matt 	if (error == 0) {
    632  1.56  christos 		netbsd32_from_stat(&sb, &sb32);
    633  1.86      maxv 		error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb32));
    634  1.42       dsl 	}
    635  1.29    martin 	return error;
    636  1.26      cube }
    637  1.26      cube 
    638   1.1       mrg int
    639  1.49       dsl netbsd32_preadv(struct lwp *l, const struct netbsd32_preadv_args *uap, register_t *retval)
    640   1.1       mrg {
    641  1.49       dsl 	/* {
    642   1.1       mrg 		syscallarg(int) fd;
    643   1.1       mrg 		syscallarg(const netbsd32_iovecp_t) iovp;
    644   1.1       mrg 		syscallarg(int) iovcnt;
    645   1.1       mrg 		syscallarg(int) pad;
    646  1.70     njoly 		syscallarg(netbsd32_off_t) offset;
    647  1.49       dsl 	} */
    648  1.51        ad 	file_t *fp;
    649   1.1       mrg 	struct vnode *vp;
    650   1.1       mrg 	off_t offset;
    651   1.1       mrg 	int error, fd = SCARG(uap, fd);
    652   1.1       mrg 
    653  1.51        ad 	if ((fp = fd_getfile(fd)) == NULL)
    654   1.6   thorpej 		return (EBADF);
    655   1.6   thorpej 
    656  1.50       dsl 	if ((fp->f_flag & FREAD) == 0) {
    657  1.51        ad 		fd_putfile(fd);
    658   1.1       mrg 		return (EBADF);
    659  1.50       dsl 	}
    660   1.1       mrg 
    661  1.71      matt 	vp = fp->f_vnode;
    662   1.9  jdolecek 	if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO) {
    663   1.9  jdolecek 		error = ESPIPE;
    664   1.9  jdolecek 		goto out;
    665   1.9  jdolecek 	}
    666   1.1       mrg 
    667   1.1       mrg 	offset = SCARG(uap, offset);
    668   1.1       mrg 
    669   1.1       mrg 	/*
    670   1.1       mrg 	 * XXX This works because no file systems actually
    671   1.1       mrg 	 * XXX take any action on the seek operation.
    672   1.1       mrg 	 */
    673   1.1       mrg 	if ((error = VOP_SEEK(vp, fp->f_offset, offset, fp->f_cred)) != 0)
    674   1.9  jdolecek 		goto out;
    675   1.1       mrg 
    676  1.51        ad 	return (dofilereadv32(fd, fp, SCARG_P32(uap, iovp),
    677  1.10       scw 	    SCARG(uap, iovcnt), &offset, 0, retval));
    678   1.9  jdolecek 
    679   1.9  jdolecek out:
    680  1.51        ad 	fd_putfile(fd);
    681   1.9  jdolecek 	return (error);
    682   1.1       mrg }
    683   1.1       mrg 
    684   1.1       mrg int
    685  1.49       dsl netbsd32_pwritev(struct lwp *l, const struct netbsd32_pwritev_args *uap, register_t *retval)
    686   1.1       mrg {
    687  1.49       dsl 	/* {
    688   1.1       mrg 		syscallarg(int) fd;
    689   1.1       mrg 		syscallarg(const netbsd32_iovecp_t) iovp;
    690   1.1       mrg 		syscallarg(int) iovcnt;
    691   1.1       mrg 		syscallarg(int) pad;
    692  1.70     njoly 		syscallarg(netbsd32_off_t) offset;
    693  1.49       dsl 	} */
    694  1.51        ad 	file_t *fp;
    695   1.1       mrg 	struct vnode *vp;
    696   1.1       mrg 	off_t offset;
    697   1.1       mrg 	int error, fd = SCARG(uap, fd);
    698   1.1       mrg 
    699  1.51        ad 	if ((fp = fd_getfile(fd)) == NULL)
    700   1.6   thorpej 		return (EBADF);
    701   1.6   thorpej 
    702  1.50       dsl 	if ((fp->f_flag & FWRITE) == 0) {
    703  1.51        ad 		fd_putfile(fd);
    704   1.1       mrg 		return (EBADF);
    705  1.50       dsl 	}
    706   1.1       mrg 
    707  1.71      matt 	vp = fp->f_vnode;
    708   1.9  jdolecek 	if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO) {
    709   1.9  jdolecek 		error = ESPIPE;
    710   1.9  jdolecek 		goto out;
    711   1.9  jdolecek 	}
    712   1.1       mrg 
    713   1.1       mrg 	offset = SCARG(uap, offset);
    714   1.1       mrg 
    715   1.1       mrg 	/*
    716   1.1       mrg 	 * XXX This works because no file systems actually
    717   1.1       mrg 	 * XXX take any action on the seek operation.
    718   1.1       mrg 	 */
    719   1.1       mrg 	if ((error = VOP_SEEK(vp, fp->f_offset, offset, fp->f_cred)) != 0)
    720   1.9  jdolecek 		goto out;
    721   1.1       mrg 
    722  1.51        ad 	return (dofilewritev32(fd, fp, SCARG_P32(uap, iovp),
    723  1.10       scw 	    SCARG(uap, iovcnt), &offset, 0, retval));
    724   1.9  jdolecek 
    725   1.9  jdolecek out:
    726  1.51        ad 	fd_putfile(fd);
    727   1.9  jdolecek 	return (error);
    728   1.1       mrg }
    729   1.1       mrg 
    730   1.1       mrg /*
    731   1.1       mrg  * Find pathname of process's current directory.
    732   1.1       mrg  *
    733   1.1       mrg  * Use vfs vnode-to-name reverse cache; if that fails, fall back
    734   1.1       mrg  * to reading directory contents.
    735   1.1       mrg  */
    736  1.49       dsl int
    737  1.49       dsl netbsd32___getcwd(struct lwp *l, const struct netbsd32___getcwd_args *uap, register_t *retval)
    738   1.1       mrg {
    739  1.49       dsl 	/* {
    740   1.1       mrg 		syscallarg(char *) bufp;
    741   1.1       mrg 		syscallarg(size_t) length;
    742  1.49       dsl 	} */
    743  1.88        ad 	struct proc *p = l->l_proc;
    744   1.1       mrg 	int     error;
    745   1.1       mrg 	char   *path;
    746   1.1       mrg 	char   *bp, *bend;
    747   1.1       mrg 	int     len = (int)SCARG(uap, length);
    748   1.1       mrg 	int	lenused;
    749  1.88        ad 	struct	cwdinfo *cwdi;
    750   1.1       mrg 
    751   1.1       mrg 	if (len > MAXPATHLEN*4)
    752   1.1       mrg 		len = MAXPATHLEN*4;
    753   1.1       mrg 	else if (len < 2)
    754   1.1       mrg 		return ERANGE;
    755   1.1       mrg 
    756  1.59     rmind 	path = kmem_alloc(len, KM_SLEEP);
    757   1.1       mrg 	bp = &path[len];
    758   1.1       mrg 	bend = bp;
    759   1.1       mrg 	*(--bp) = '\0';
    760   1.1       mrg 
    761   1.1       mrg 	/*
    762   1.1       mrg 	 * 5th argument here is "max number of vnodes to traverse".
    763   1.1       mrg 	 * Since each entry takes up at least 2 bytes in the output buffer,
    764   1.1       mrg 	 * limit it to N/2 vnodes for an N byte buffer.
    765   1.1       mrg 	 */
    766   1.1       mrg #define GETCWD_CHECK_ACCESS 0x0001
    767  1.88        ad 	cwdi = p->p_cwdi;
    768  1.88        ad 	rw_enter(&cwdi->cwdi_lock, RW_READER);
    769  1.88        ad 	error = getcwd_common (cwdi->cwdi_cdir, NULL, &bp, path, len/2,
    770  1.23  christos 			       GETCWD_CHECK_ACCESS, l);
    771  1.88        ad 	rw_exit(&cwdi->cwdi_lock);
    772   1.1       mrg 
    773   1.1       mrg 	if (error)
    774   1.1       mrg 		goto out;
    775   1.1       mrg 	lenused = bend - bp;
    776   1.1       mrg 	*retval = lenused;
    777   1.1       mrg 	/* put the result into user buffer */
    778  1.39       dsl 	error = copyout(bp, SCARG_P32(uap, bufp), lenused);
    779   1.1       mrg 
    780   1.1       mrg out:
    781  1.59     rmind 	kmem_free(path, len);
    782   1.1       mrg 	return error;
    783   1.1       mrg }
    784  1.58      matt 
    785  1.58      matt int
    786  1.58      matt netbsd32___mount50(struct lwp *l, const struct netbsd32___mount50_args *uap,
    787  1.61       dsl 	register_t *retval)
    788  1.58      matt {
    789  1.58      matt 	/* {
    790  1.58      matt 		syscallarg(netbsd32_charp) type;
    791  1.58      matt 		syscallarg(netbsd32_charp) path;
    792  1.58      matt 		syscallarg(int) flags;
    793  1.58      matt 		syscallarg(netbsd32_voidp) data;
    794  1.58      matt 		syscallarg(netbsd32_size_t) data_len;
    795  1.58      matt 	} */
    796  1.58      matt 	char mtype[MNAMELEN];
    797  1.58      matt 	union {
    798  1.58      matt 		struct netbsd32_ufs_args ufs_args;
    799  1.58      matt 		struct netbsd32_mfs_args mfs_args;
    800  1.58      matt 		struct netbsd32_iso_args iso_args;
    801  1.60      matt 		struct netbsd32_nfs_args nfs_args;
    802  1.63  macallan 		struct netbsd32_msdosfs_args msdosfs_args;
    803  1.72  christos 		struct netbsd32_tmpfs_args tmpfs_args;
    804  1.81       mrg 		struct netbsd32_null_args null_args;
    805  1.58      matt 	} fs_args32;
    806  1.58      matt 	union {
    807  1.58      matt 		struct ufs_args ufs_args;
    808  1.58      matt 		struct mfs_args mfs_args;
    809  1.58      matt 		struct iso_args iso_args;
    810  1.60      matt 		struct nfs_args nfs_args;
    811  1.63  macallan 		struct msdosfs_args msdosfs_args;
    812  1.72  christos 		struct tmpfs_args tmpfs_args;
    813  1.81       mrg 		struct null_args null_args;
    814  1.58      matt 	} fs_args;
    815  1.58      matt 	const char *type = SCARG_P32(uap, type);
    816  1.58      matt 	const char *path = SCARG_P32(uap, path);
    817  1.58      matt 	int flags = SCARG(uap, flags);
    818  1.83      maxv 	void *data, *udata;
    819  1.58      matt 	size_t data_len = SCARG(uap, data_len);
    820  1.58      matt 	enum uio_seg data_seg;
    821  1.58      matt 	size_t len;
    822  1.58      matt 	int error;
    823  1.58      matt 
    824  1.83      maxv 	udata = data = SCARG_P32(uap, data);
    825  1.83      maxv 	memset(&fs_args32, 0, sizeof(fs_args32));
    826  1.83      maxv 
    827  1.58      matt 	error = copyinstr(type, mtype, sizeof(mtype), &len);
    828  1.58      matt 	if (error)
    829  1.58      matt 		return error;
    830  1.83      maxv 
    831  1.72  christos 	if (strcmp(mtype, MOUNT_TMPFS) == 0) {
    832  1.89  christos 		if (data_len != 0 && data_len < sizeof(fs_args32.tmpfs_args))
    833  1.72  christos 			return EINVAL;
    834  1.72  christos 		if ((flags & MNT_GETARGS) == 0) {
    835  1.72  christos 			error = copyin(data, &fs_args32.tmpfs_args,
    836  1.72  christos 			    sizeof(fs_args32.tmpfs_args));
    837  1.72  christos 			if (error)
    838  1.72  christos 				return error;
    839  1.72  christos 			fs_args.tmpfs_args.ta_version =
    840  1.72  christos 			    fs_args32.tmpfs_args.ta_version;
    841  1.72  christos 			fs_args.tmpfs_args.ta_nodes_max =
    842  1.72  christos 			    fs_args32.tmpfs_args.ta_nodes_max;
    843  1.72  christos 			fs_args.tmpfs_args.ta_size_max =
    844  1.72  christos 			    fs_args32.tmpfs_args.ta_size_max;
    845  1.72  christos 			fs_args.tmpfs_args.ta_root_uid =
    846  1.72  christos 			    fs_args32.tmpfs_args.ta_root_uid;
    847  1.72  christos 			fs_args.tmpfs_args.ta_root_gid =
    848  1.72  christos 			    fs_args32.tmpfs_args.ta_root_gid;
    849  1.72  christos 			fs_args.tmpfs_args.ta_root_mode =
    850  1.72  christos 			    fs_args32.tmpfs_args.ta_root_mode;
    851  1.72  christos 		}
    852  1.72  christos 		data_seg = UIO_SYSSPACE;
    853  1.72  christos 		data = &fs_args.tmpfs_args;
    854  1.72  christos 		data_len = sizeof(fs_args.tmpfs_args);
    855  1.72  christos 	} else if (strcmp(mtype, MOUNT_MFS) == 0) {
    856  1.89  christos 		if (data_len != 0 && data_len < sizeof(fs_args32.mfs_args))
    857  1.58      matt 			return EINVAL;
    858  1.58      matt 		if ((flags & MNT_GETARGS) == 0) {
    859  1.58      matt 			error = copyin(data, &fs_args32.mfs_args,
    860  1.58      matt 			    sizeof(fs_args32.mfs_args));
    861  1.58      matt 			if (error)
    862  1.58      matt 				return error;
    863  1.58      matt 			fs_args.mfs_args.fspec =
    864  1.58      matt 			    NETBSD32PTR64(fs_args32.mfs_args.fspec);
    865  1.58      matt 			memset(&fs_args.mfs_args._pad1, 0,
    866  1.58      matt 			    sizeof(fs_args.mfs_args._pad1));
    867  1.58      matt 			fs_args.mfs_args.base =
    868  1.58      matt 			    NETBSD32PTR64(fs_args32.mfs_args.base);
    869  1.58      matt 			fs_args.mfs_args.size = fs_args32.mfs_args.size;
    870  1.58      matt 		}
    871  1.58      matt 		data_seg = UIO_SYSSPACE;
    872  1.58      matt 		data = &fs_args.mfs_args;
    873  1.58      matt 		data_len = sizeof(fs_args.mfs_args);
    874  1.63  macallan 	} else if ((strcmp(mtype, MOUNT_UFS) == 0) ||
    875  1.63  macallan 		   (strcmp(mtype, MOUNT_EXT2FS) == 0) ||
    876  1.63  macallan 		   (strcmp(mtype, MOUNT_LFS) == 0)) {
    877  1.89  christos 		if (data_len != 0 && data_len < sizeof(fs_args32.ufs_args))
    878  1.58      matt 			return EINVAL;
    879  1.58      matt 		if ((flags & MNT_GETARGS) == 0) {
    880  1.58      matt 			error = copyin(data, &fs_args32.ufs_args,
    881  1.58      matt 			    sizeof(fs_args32.ufs_args));
    882  1.58      matt 			if (error)
    883  1.58      matt 				return error;
    884  1.58      matt 			fs_args.ufs_args.fspec =
    885  1.58      matt 			    NETBSD32PTR64(fs_args32.ufs_args.fspec);
    886  1.58      matt 		}
    887  1.58      matt 		data_seg = UIO_SYSSPACE;
    888  1.58      matt 		data = &fs_args.ufs_args;
    889  1.58      matt 		data_len = sizeof(fs_args.ufs_args);
    890  1.58      matt 	} else if (strcmp(mtype, MOUNT_CD9660) == 0) {
    891  1.89  christos 		if (data_len != 0 && data_len < sizeof(fs_args32.iso_args))
    892  1.58      matt 			return EINVAL;
    893  1.58      matt 		if ((flags & MNT_GETARGS) == 0) {
    894  1.58      matt 			error = copyin(data, &fs_args32.iso_args,
    895  1.58      matt 			    sizeof(fs_args32.iso_args));
    896  1.58      matt 			if (error)
    897  1.58      matt 				return error;
    898  1.58      matt 			fs_args.iso_args.fspec =
    899  1.58      matt 			    NETBSD32PTR64(fs_args32.iso_args.fspec);
    900  1.58      matt 			memset(&fs_args.iso_args._pad1, 0,
    901  1.58      matt 			    sizeof(fs_args.iso_args._pad1));
    902  1.58      matt 			fs_args.iso_args.flags = fs_args32.iso_args.flags;
    903  1.58      matt 		}
    904  1.58      matt 		data_seg = UIO_SYSSPACE;
    905  1.58      matt 		data = &fs_args.iso_args;
    906  1.58      matt 		data_len = sizeof(fs_args.iso_args);
    907  1.63  macallan 	} else if (strcmp(mtype, MOUNT_MSDOS) == 0) {
    908  1.83      maxv 		if (data_len < sizeof(fs_args32.msdosfs_args))
    909  1.63  macallan 			return EINVAL;
    910  1.63  macallan 		if ((flags & MNT_GETARGS) == 0) {
    911  1.63  macallan 			error = copyin(data, &fs_args32.msdosfs_args,
    912  1.63  macallan 			    sizeof(fs_args32.msdosfs_args));
    913  1.63  macallan 			if (error)
    914  1.63  macallan 				return error;
    915  1.63  macallan 			fs_args.msdosfs_args.fspec =
    916  1.63  macallan 			    NETBSD32PTR64(fs_args32.msdosfs_args.fspec);
    917  1.63  macallan 			memset(&fs_args.msdosfs_args._pad1, 0,
    918  1.63  macallan 			    sizeof(fs_args.msdosfs_args._pad1));
    919  1.63  macallan 			fs_args.msdosfs_args.uid =
    920  1.63  macallan 			    fs_args32.msdosfs_args.uid;
    921  1.63  macallan 			fs_args.msdosfs_args.gid =
    922  1.63  macallan 			    fs_args32.msdosfs_args.gid;
    923  1.63  macallan 			fs_args.msdosfs_args.mask =
    924  1.63  macallan 			    fs_args32.msdosfs_args.mask;
    925  1.63  macallan 			fs_args.msdosfs_args.flags =
    926  1.63  macallan 			    fs_args32.msdosfs_args.flags;
    927  1.63  macallan 			fs_args.msdosfs_args.version =
    928  1.63  macallan 			    fs_args32.msdosfs_args.version;
    929  1.63  macallan 			fs_args.msdosfs_args.dirmask =
    930  1.63  macallan 			    fs_args32.msdosfs_args.dirmask;
    931  1.63  macallan 			fs_args.msdosfs_args.gmtoff =
    932  1.63  macallan 			    fs_args32.msdosfs_args.gmtoff;
    933  1.63  macallan 		}
    934  1.63  macallan 		data_seg = UIO_SYSSPACE;
    935  1.63  macallan 		data = &fs_args.msdosfs_args;
    936  1.63  macallan 		data_len = sizeof(fs_args.msdosfs_args);
    937  1.60      matt 	} else if (strcmp(mtype, MOUNT_NFS) == 0) {
    938  1.89  christos 		if (data_len != 0 && data_len < sizeof(fs_args32.nfs_args))
    939  1.60      matt 			return EINVAL;
    940  1.83      maxv 		/* XXX: NFS requires copyin even with MNT_GETARGS */
    941  1.60      matt 		if ((flags & MNT_GETARGS) == 0) {
    942  1.60      matt 			error = copyin(data, &fs_args32.nfs_args,
    943  1.60      matt 			    sizeof(fs_args32.nfs_args));
    944  1.60      matt 			if (error)
    945  1.60      matt 				return error;
    946  1.60      matt 			fs_args.nfs_args.version = fs_args32.nfs_args.version;
    947  1.60      matt 			fs_args.nfs_args.addr =
    948  1.60      matt 			    NETBSD32PTR64(fs_args32.nfs_args.addr);
    949  1.60      matt 			memcpy(&fs_args.nfs_args.addrlen,
    950  1.60      matt 			    &fs_args32.nfs_args.addrlen,
    951  1.60      matt 			    offsetof(struct nfs_args, fh)
    952  1.60      matt 				- offsetof(struct nfs_args, addrlen));
    953  1.60      matt 			fs_args.nfs_args.fh =
    954  1.60      matt 			    NETBSD32PTR64(fs_args32.nfs_args.fh);
    955  1.60      matt 			memcpy(&fs_args.nfs_args.fhsize,
    956  1.60      matt 			    &fs_args32.nfs_args.fhsize,
    957  1.60      matt 			    offsetof(struct nfs_args, hostname)
    958  1.60      matt 				- offsetof(struct nfs_args, fhsize));
    959  1.60      matt 			fs_args.nfs_args.hostname =
    960  1.60      matt 			    NETBSD32PTR64(fs_args32.nfs_args.hostname);
    961  1.60      matt 		}
    962  1.60      matt 		data_seg = UIO_SYSSPACE;
    963  1.60      matt 		data = &fs_args.nfs_args;
    964  1.60      matt 		data_len = sizeof(fs_args.nfs_args);
    965  1.81       mrg 	} else if (strcmp(mtype, MOUNT_NULL) == 0) {
    966  1.89  christos 		if (data_len != 0 && data_len < sizeof(fs_args32.null_args))
    967  1.81       mrg 			return EINVAL;
    968  1.81       mrg 		if ((flags & MNT_GETARGS) == 0) {
    969  1.81       mrg 			error = copyin(data, &fs_args32.null_args,
    970  1.81       mrg 			    sizeof(fs_args32.null_args));
    971  1.81       mrg 			if (error)
    972  1.81       mrg 				return error;
    973  1.81       mrg 			fs_args.null_args.la.target =
    974  1.81       mrg 			    NETBSD32PTR64(fs_args32.null_args.la.target);
    975  1.81       mrg 		}
    976  1.81       mrg 		data_seg = UIO_SYSSPACE;
    977  1.81       mrg 		data = &fs_args.null_args;
    978  1.81       mrg 		data_len = sizeof(fs_args.null_args);
    979  1.58      matt 	} else {
    980  1.58      matt 		data_seg = UIO_USERSPACE;
    981  1.58      matt 	}
    982  1.83      maxv 
    983  1.73      maxv 	error = do_sys_mount(l, mtype, UIO_SYSSPACE, path, flags, data, data_seg,
    984  1.58      matt 	    data_len, retval);
    985  1.58      matt 	if (error)
    986  1.58      matt 		return error;
    987  1.83      maxv 
    988  1.58      matt 	if (flags & MNT_GETARGS) {
    989  1.58      matt 		data_len = *retval;
    990  1.72  christos 		if (strcmp(mtype, MOUNT_TMPFS) == 0) {
    991  1.89  christos 			if (data_len != 0 &&
    992  1.89  christos 			    data_len != sizeof(fs_args.tmpfs_args))
    993  1.72  christos 				return EINVAL;
    994  1.72  christos 			fs_args32.tmpfs_args.ta_version =
    995  1.72  christos 			    fs_args.tmpfs_args.ta_version;
    996  1.72  christos 			fs_args32.tmpfs_args.ta_nodes_max =
    997  1.72  christos 			    fs_args.tmpfs_args.ta_nodes_max;
    998  1.72  christos 			fs_args32.tmpfs_args.ta_size_max =
    999  1.72  christos 			    fs_args.tmpfs_args.ta_size_max;
   1000  1.72  christos 			fs_args32.tmpfs_args.ta_root_uid =
   1001  1.72  christos 			    fs_args.tmpfs_args.ta_root_uid;
   1002  1.72  christos 			fs_args32.tmpfs_args.ta_root_gid =
   1003  1.72  christos 			    fs_args.tmpfs_args.ta_root_gid;
   1004  1.72  christos 			fs_args32.tmpfs_args.ta_root_mode =
   1005  1.72  christos 			    fs_args.tmpfs_args.ta_root_mode;
   1006  1.83      maxv 			error = copyout(&fs_args32.tmpfs_args, udata,
   1007  1.72  christos 				    sizeof(fs_args32.tmpfs_args));
   1008  1.83      maxv 			*retval = sizeof(fs_args32.tmpfs_args);
   1009  1.72  christos 		} else if (strcmp(mtype, MOUNT_MFS) == 0) {
   1010  1.89  christos 			if (data_len != 0 &&
   1011  1.89  christos 			    data_len != sizeof(fs_args.mfs_args))
   1012  1.58      matt 				return EINVAL;
   1013  1.58      matt 			NETBSD32PTR32(fs_args32.mfs_args.fspec,
   1014  1.58      matt 			    fs_args.mfs_args.fspec);
   1015  1.58      matt 			memset(&fs_args32.mfs_args._pad1, 0,
   1016  1.58      matt 			    sizeof(fs_args32.mfs_args._pad1));
   1017  1.58      matt 			NETBSD32PTR32(fs_args32.mfs_args.base,
   1018  1.58      matt 			    fs_args.mfs_args.base);
   1019  1.58      matt 			fs_args32.mfs_args.size = fs_args.mfs_args.size;
   1020  1.83      maxv 			error = copyout(&fs_args32.mfs_args, udata,
   1021  1.58      matt 				    sizeof(fs_args32.mfs_args));
   1022  1.83      maxv 			*retval = sizeof(fs_args32.mfs_args);
   1023  1.58      matt 		} else if (strcmp(mtype, MOUNT_UFS) == 0) {
   1024  1.89  christos 			if (data_len != 0 &&
   1025  1.89  christos 			    data_len != sizeof(fs_args.ufs_args))
   1026  1.58      matt 				return EINVAL;
   1027  1.58      matt 			NETBSD32PTR32(fs_args32.ufs_args.fspec,
   1028  1.58      matt 			    fs_args.ufs_args.fspec);
   1029  1.83      maxv 			error = copyout(&fs_args32.ufs_args, udata,
   1030  1.58      matt 			    sizeof(fs_args32.ufs_args));
   1031  1.83      maxv 			*retval = sizeof(fs_args32.ufs_args);
   1032  1.58      matt 		} else if (strcmp(mtype, MOUNT_CD9660) == 0) {
   1033  1.89  christos 			if (data_len != 0 &&
   1034  1.89  christos 			    data_len != sizeof(fs_args.iso_args))
   1035  1.58      matt 				return EINVAL;
   1036  1.58      matt 			NETBSD32PTR32(fs_args32.iso_args.fspec,
   1037  1.58      matt 			    fs_args.iso_args.fspec);
   1038  1.58      matt 			memset(&fs_args32.iso_args._pad1, 0,
   1039  1.58      matt 			    sizeof(fs_args32.iso_args._pad1));
   1040  1.58      matt 			fs_args32.iso_args.flags = fs_args.iso_args.flags;
   1041  1.83      maxv 			error = copyout(&fs_args32.iso_args, udata,
   1042  1.58      matt 				    sizeof(fs_args32.iso_args));
   1043  1.83      maxv 			*retval = sizeof(fs_args32.iso_args);
   1044  1.60      matt 		} else if (strcmp(mtype, MOUNT_NFS) == 0) {
   1045  1.89  christos 			if (data_len != 0 &&
   1046  1.89  christos 			    data_len != sizeof(fs_args.nfs_args))
   1047  1.60      matt 				return EINVAL;
   1048  1.60      matt 			NETBSD32PTR32(fs_args32.nfs_args.addr,
   1049  1.60      matt 			    fs_args.nfs_args.addr);
   1050  1.60      matt 			memcpy(&fs_args32.nfs_args.addrlen,
   1051  1.60      matt 			    &fs_args.nfs_args.addrlen,
   1052  1.60      matt 			    offsetof(struct nfs_args, fh)
   1053  1.60      matt 				- offsetof(struct nfs_args, addrlen));
   1054  1.60      matt 			NETBSD32PTR32(fs_args32.nfs_args.fh,
   1055  1.60      matt 			    fs_args.nfs_args.fh);
   1056  1.60      matt 			memcpy(&fs_args32.nfs_args.fhsize,
   1057  1.60      matt 			    &fs_args.nfs_args.fhsize,
   1058  1.60      matt 			    offsetof(struct nfs_args, hostname)
   1059  1.60      matt 				- offsetof(struct nfs_args, fhsize));
   1060  1.60      matt 			NETBSD32PTR32(fs_args32.nfs_args.hostname,
   1061  1.60      matt 			    fs_args.nfs_args.hostname);
   1062  1.83      maxv 			error = copyout(&fs_args32.nfs_args, udata,
   1063  1.60      matt 			    sizeof(fs_args32.nfs_args));
   1064  1.83      maxv 			*retval = sizeof(fs_args32.nfs_args);
   1065  1.81       mrg 		} else if (strcmp(mtype, MOUNT_NULL) == 0) {
   1066  1.89  christos 			if (data_len != 0 &&
   1067  1.89  christos 			    data_len != sizeof(fs_args.null_args))
   1068  1.81       mrg 				return EINVAL;
   1069  1.81       mrg 			NETBSD32PTR32(fs_args32.null_args.la.target,
   1070  1.81       mrg 			    fs_args.null_args.la.target);
   1071  1.83      maxv 			error = copyout(&fs_args32.null_args, udata,
   1072  1.81       mrg 			    sizeof(fs_args32.null_args));
   1073  1.83      maxv 			*retval = sizeof(fs_args32.null_args);
   1074  1.58      matt 		}
   1075  1.58      matt 	}
   1076  1.58      matt 	return error;
   1077  1.58      matt }
   1078  1.65      matt 
   1079  1.65      matt int
   1080  1.65      matt netbsd32_linkat(struct lwp *l, const struct netbsd32_linkat_args *uap,
   1081  1.65      matt 		 register_t *retval)
   1082  1.65      matt {
   1083  1.65      matt 	/* {
   1084  1.65      matt 		syscallarg(int) fd1;
   1085  1.65      matt 		syscallarg(const netbsd32_charp) name1;
   1086  1.65      matt 		syscallarg(int) fd2;
   1087  1.65      matt 		syscallarg(const netbsd32_charp) name2;
   1088  1.65      matt 		syscallarg(int) flags;
   1089  1.65      matt 	} */
   1090  1.65      matt 	struct sys_linkat_args ua;
   1091  1.65      matt 
   1092  1.65      matt 	NETBSD32TO64_UAP(fd1);
   1093  1.65      matt 	NETBSD32TOP_UAP(name1, const char);
   1094  1.65      matt 	NETBSD32TO64_UAP(fd2);
   1095  1.65      matt 	NETBSD32TOP_UAP(name2, const char);
   1096  1.65      matt 	NETBSD32TO64_UAP(flags);
   1097  1.65      matt 
   1098  1.65      matt 	return sys_linkat(l, &ua, retval);
   1099  1.65      matt }
   1100  1.65      matt 
   1101  1.65      matt int
   1102  1.65      matt netbsd32_renameat(struct lwp *l, const struct netbsd32_renameat_args *uap,
   1103  1.65      matt 		 register_t *retval)
   1104  1.65      matt {
   1105  1.65      matt 	/* {
   1106  1.65      matt 		syscallarg(int) fromfd;
   1107  1.65      matt 		syscallarg(const netbsd32_charp) from;
   1108  1.65      matt 		syscallarg(int) tofd;
   1109  1.65      matt 		syscallarg(const netbsd32_charp) to;
   1110  1.65      matt 	} */
   1111  1.65      matt 	struct sys_renameat_args ua;
   1112  1.65      matt 
   1113  1.65      matt 	NETBSD32TO64_UAP(fromfd);
   1114  1.65      matt 	NETBSD32TOP_UAP(from, const char);
   1115  1.65      matt 	NETBSD32TO64_UAP(tofd);
   1116  1.65      matt 	NETBSD32TOP_UAP(to, const char);
   1117  1.65      matt 
   1118  1.65      matt 	return sys_renameat(l, &ua, retval);
   1119  1.65      matt }
   1120  1.65      matt 
   1121  1.65      matt int
   1122  1.65      matt netbsd32_mkfifoat(struct lwp *l, const struct netbsd32_mkfifoat_args *uap,
   1123  1.65      matt 		 register_t *retval)
   1124  1.65      matt {
   1125  1.65      matt 	/* {
   1126  1.65      matt 		syscallarg(int) fd;
   1127  1.65      matt 		syscallarg(const netbsd32_charp) path;
   1128  1.65      matt 		syscallarg(mode_t) mode;
   1129  1.65      matt 	} */
   1130  1.65      matt 	struct sys_mkfifoat_args ua;
   1131  1.65      matt 
   1132  1.65      matt 	NETBSD32TO64_UAP(fd);
   1133  1.65      matt 	NETBSD32TOP_UAP(path, const char);
   1134  1.65      matt 	NETBSD32TO64_UAP(mode);
   1135  1.65      matt 
   1136  1.65      matt 	return sys_mkfifoat(l, &ua, retval);
   1137  1.65      matt }
   1138  1.65      matt 
   1139  1.65      matt int
   1140  1.65      matt netbsd32_mknodat(struct lwp *l, const struct netbsd32_mknodat_args *uap,
   1141  1.65      matt 		 register_t *retval)
   1142  1.65      matt {
   1143  1.65      matt 	/* {
   1144  1.65      matt 		syscallarg(int) fd;
   1145  1.65      matt 		syscallarg(netbsd32_charp) path;
   1146  1.65      matt 		syscallarg(mode_t) mode;
   1147  1.69     njoly 		syscallarg(int) pad;
   1148  1.69     njoly 		syscallarg(netbsd32_dev_t) dev;
   1149  1.65      matt 	} */
   1150  1.65      matt 	struct sys_mknodat_args ua;
   1151  1.65      matt 
   1152  1.65      matt 	NETBSD32TO64_UAP(fd);
   1153  1.65      matt 	NETBSD32TOP_UAP(path, const char);
   1154  1.65      matt 	NETBSD32TO64_UAP(mode);
   1155  1.69     njoly 	NETBSD32TO64_UAP(PAD);
   1156  1.65      matt 	NETBSD32TO64_UAP(dev);
   1157  1.65      matt 
   1158  1.65      matt 	return sys_mknodat(l, &ua, retval);
   1159  1.65      matt }
   1160  1.65      matt 
   1161  1.65      matt int
   1162  1.65      matt netbsd32_mkdirat(struct lwp *l, const struct netbsd32_mkdirat_args *uap,
   1163  1.65      matt 		 register_t *retval)
   1164  1.65      matt {
   1165  1.65      matt 	/* {
   1166  1.65      matt 		syscallarg(int) fd;
   1167  1.65      matt 		syscallarg(netbsd32_charp) path;
   1168  1.65      matt 		syscallarg(mode_t) mode;
   1169  1.65      matt 	} */
   1170  1.65      matt 	struct sys_mkdirat_args ua;
   1171  1.65      matt 
   1172  1.65      matt 	NETBSD32TO64_UAP(fd);
   1173  1.65      matt 	NETBSD32TOP_UAP(path, const char);
   1174  1.65      matt 	NETBSD32TO64_UAP(mode);
   1175  1.65      matt 
   1176  1.65      matt 	return sys_mkdirat(l, &ua, retval);
   1177  1.65      matt }
   1178  1.65      matt 
   1179  1.65      matt int
   1180  1.65      matt netbsd32_faccessat(struct lwp *l, const struct netbsd32_faccessat_args *uap,
   1181  1.65      matt 		 register_t *retval)
   1182  1.65      matt {
   1183  1.65      matt 	/* {
   1184  1.65      matt 		syscallarg(int) fd;
   1185  1.65      matt 		syscallarg(netbsd32_charp) path;
   1186  1.65      matt 		syscallarg(int) amode;
   1187  1.65      matt 		syscallarg(int) flag;
   1188  1.65      matt 	} */
   1189  1.65      matt 	struct sys_faccessat_args ua;
   1190  1.65      matt 
   1191  1.65      matt 	NETBSD32TO64_UAP(fd);
   1192  1.65      matt 	NETBSD32TOP_UAP(path, const char);
   1193  1.65      matt 	NETBSD32TO64_UAP(amode);
   1194  1.65      matt 	NETBSD32TO64_UAP(flag);
   1195  1.65      matt 
   1196  1.65      matt 	return sys_faccessat(l, &ua, retval);
   1197  1.65      matt }
   1198  1.65      matt 
   1199  1.65      matt int
   1200  1.65      matt netbsd32_fchmodat(struct lwp *l, const struct netbsd32_fchmodat_args *uap,
   1201  1.65      matt 		 register_t *retval)
   1202  1.65      matt {
   1203  1.65      matt 	/* {
   1204  1.65      matt 		syscallarg(int) fd;
   1205  1.65      matt 		syscallarg(netbsd32_charp) path;
   1206  1.65      matt 		syscallarg(mode_t) mode;
   1207  1.65      matt 		syscallarg(int) flag;
   1208  1.65      matt 	} */
   1209  1.65      matt 	struct sys_fchmodat_args ua;
   1210  1.65      matt 
   1211  1.65      matt 	NETBSD32TO64_UAP(fd);
   1212  1.65      matt 	NETBSD32TOP_UAP(path, const char);
   1213  1.65      matt 	NETBSD32TO64_UAP(mode);
   1214  1.65      matt 	NETBSD32TO64_UAP(flag);
   1215  1.65      matt 
   1216  1.65      matt 	return sys_fchmodat(l, &ua, retval);
   1217  1.65      matt }
   1218  1.65      matt 
   1219  1.65      matt int
   1220  1.65      matt netbsd32_fchownat(struct lwp *l, const struct netbsd32_fchownat_args *uap,
   1221  1.65      matt 		 register_t *retval)
   1222  1.65      matt {
   1223  1.65      matt 	/* {
   1224  1.65      matt 		syscallarg(int) fd;
   1225  1.65      matt 		syscallarg(netbsd32_charp) path;
   1226  1.65      matt 		syscallarg(uid_t) owner;
   1227  1.65      matt 		syscallarg(gid_t) group;
   1228  1.65      matt 		syscallarg(int) flag;
   1229  1.65      matt 	} */
   1230  1.65      matt 	struct sys_fchownat_args ua;
   1231  1.65      matt 
   1232  1.65      matt 	NETBSD32TO64_UAP(fd);
   1233  1.65      matt 	NETBSD32TOP_UAP(path, const char);
   1234  1.65      matt 	NETBSD32TO64_UAP(owner);
   1235  1.65      matt 	NETBSD32TO64_UAP(group);
   1236  1.65      matt 	NETBSD32TO64_UAP(flag);
   1237  1.65      matt 
   1238  1.65      matt 	return sys_fchownat(l, &ua, retval);
   1239  1.65      matt }
   1240  1.65      matt 
   1241  1.65      matt int
   1242  1.65      matt netbsd32_fstatat(struct lwp *l, const struct netbsd32_fstatat_args *uap,
   1243  1.65      matt 		 register_t *retval)
   1244  1.65      matt {
   1245  1.65      matt 	/* {
   1246  1.65      matt 		syscallarg(int) fd;
   1247  1.65      matt 		syscallarg(netbsd32_charp) path;
   1248  1.65      matt 		syscallarg(netbsd32_statp_t) buf;
   1249  1.65      matt 		syscallarg(int) flag;
   1250  1.65      matt 	} */
   1251  1.65      matt 	struct netbsd32_stat sb32;
   1252  1.65      matt 	struct stat sb;
   1253  1.66      matt 	int follow;
   1254  1.65      matt 	int error;
   1255  1.65      matt 
   1256  1.66      matt 	follow = (SCARG(uap, flag) & AT_SYMLINK_NOFOLLOW) ? NOFOLLOW : FOLLOW;
   1257  1.65      matt 
   1258  1.65      matt 	error = do_sys_statat(l, SCARG(uap, fd), SCARG_P32(uap, path),
   1259  1.66      matt 	    follow, &sb);
   1260  1.65      matt 	if (error)
   1261  1.65      matt 		return error;
   1262  1.65      matt 	netbsd32_from_stat(&sb, &sb32);
   1263  1.65      matt 	return copyout(&sb32, SCARG_P32(uap, buf), sizeof(sb32));
   1264  1.65      matt }
   1265  1.65      matt 
   1266  1.65      matt int
   1267  1.65      matt netbsd32_utimensat(struct lwp *l, const struct netbsd32_utimensat_args *uap,
   1268  1.65      matt 		 register_t *retval)
   1269  1.65      matt {
   1270  1.65      matt 	/* {
   1271  1.65      matt 		syscallarg(int) fd;
   1272  1.65      matt 		syscallarg(netbsd32_charp) path;
   1273  1.65      matt 		syscallarg(netbsd32_timespecp_t) tptr;
   1274  1.65      matt 		syscallarg(int) flag;
   1275  1.65      matt 	} */
   1276  1.82       mrg 	struct timespec ts[2], *tsp;
   1277  1.66      matt 	int follow;
   1278  1.66      matt 	int error;
   1279  1.66      matt 
   1280  1.68     njoly 	error = get_utimens32(SCARG_P32(uap, tptr), ts, &tsp);
   1281  1.68     njoly 	if (error != 0)
   1282  1.68     njoly 		return error;
   1283  1.66      matt 
   1284  1.66      matt 	follow = (SCARG(uap, flag) & AT_SYMLINK_NOFOLLOW) ? NOFOLLOW : FOLLOW;
   1285  1.65      matt 
   1286  1.68     njoly 	return do_sys_utimensat(l, SCARG(uap, fd), NULL,
   1287  1.68     njoly 	    SCARG_P32(uap, path), follow, tsp, UIO_SYSSPACE);
   1288  1.65      matt }
   1289  1.65      matt 
   1290  1.65      matt int
   1291  1.65      matt netbsd32_openat(struct lwp *l, const struct netbsd32_openat_args *uap,
   1292  1.65      matt 		 register_t *retval)
   1293  1.65      matt {
   1294  1.65      matt 	/* {
   1295  1.65      matt 		syscallarg(int) fd;
   1296  1.65      matt 		syscallarg(netbsd32_charp) path;
   1297  1.65      matt 		syscallarg(int) oflags;
   1298  1.65      matt 		syscallarg(mode_t) mode;
   1299  1.65      matt 	} */
   1300  1.65      matt 	struct sys_openat_args ua;
   1301  1.65      matt 
   1302  1.65      matt 	NETBSD32TO64_UAP(fd);
   1303  1.65      matt 	NETBSD32TOP_UAP(path, const char);
   1304  1.65      matt 	NETBSD32TO64_UAP(oflags);
   1305  1.65      matt 	NETBSD32TO64_UAP(mode);
   1306  1.65      matt 
   1307  1.65      matt 	return sys_openat(l, &ua, retval);
   1308  1.65      matt }
   1309  1.65      matt 
   1310  1.65      matt int
   1311  1.65      matt netbsd32_readlinkat(struct lwp *l, const struct netbsd32_readlinkat_args *uap,
   1312  1.65      matt 		 register_t *retval)
   1313  1.65      matt {
   1314  1.65      matt 	/* {
   1315  1.65      matt 		syscallarg(int) fd;
   1316  1.65      matt 		syscallarg(netbsd32_charp) path;
   1317  1.65      matt 		syscallarg(netbsd32_charp) buf;
   1318  1.65      matt 		syscallarg(netbsd32_size_t) bufsize;
   1319  1.65      matt 	} */
   1320  1.65      matt 	struct sys_readlinkat_args ua;
   1321  1.65      matt 
   1322  1.65      matt 	NETBSD32TO64_UAP(fd);
   1323  1.65      matt 	NETBSD32TOP_UAP(path, const char *);
   1324  1.65      matt 	NETBSD32TOP_UAP(buf, char *);
   1325  1.65      matt 	NETBSD32TOX_UAP(bufsize, size_t);
   1326  1.65      matt 
   1327  1.65      matt 	return sys_readlinkat(l, &ua, retval);
   1328  1.65      matt }
   1329  1.65      matt 
   1330  1.65      matt int
   1331  1.65      matt netbsd32_symlinkat(struct lwp *l, const struct netbsd32_symlinkat_args *uap,
   1332  1.65      matt 		 register_t *retval)
   1333  1.65      matt {
   1334  1.65      matt 	/* {
   1335  1.65      matt 		syscallarg(netbsd32_charp) path1;
   1336  1.65      matt 		syscallarg(int) fd;
   1337  1.65      matt 		syscallarg(netbsd32_charp) path2;
   1338  1.65      matt 	} */
   1339  1.65      matt 	struct sys_symlinkat_args ua;
   1340  1.65      matt 
   1341  1.65      matt 	NETBSD32TOP_UAP(path1, const char *);
   1342  1.65      matt 	NETBSD32TO64_UAP(fd);
   1343  1.65      matt 	NETBSD32TOP_UAP(path2, const char *);
   1344  1.65      matt 
   1345  1.65      matt 	return sys_symlinkat(l, &ua, retval);
   1346  1.65      matt }
   1347  1.65      matt 
   1348  1.65      matt int
   1349  1.65      matt netbsd32_unlinkat(struct lwp *l, const struct netbsd32_unlinkat_args *uap,
   1350  1.65      matt 		 register_t *retval)
   1351  1.65      matt {
   1352  1.65      matt 	/* {
   1353  1.65      matt 		syscallarg(int) fd;
   1354  1.65      matt 		syscallarg(netbsd32_charp) path;
   1355  1.65      matt 		syscallarg(int) flag;
   1356  1.65      matt 	} */
   1357  1.65      matt 	struct sys_unlinkat_args ua;
   1358  1.65      matt 
   1359  1.65      matt 	NETBSD32TO64_UAP(fd);
   1360  1.65      matt 	NETBSD32TOP_UAP(path, const char *);
   1361  1.65      matt 	NETBSD32TO64_UAP(flag);
   1362  1.65      matt 
   1363  1.65      matt 	return sys_unlinkat(l, &ua, retval);
   1364  1.65      matt }
   1365  1.65      matt 
   1366  1.65      matt int
   1367  1.65      matt netbsd32_futimens(struct lwp *l, const struct netbsd32_futimens_args *uap,
   1368  1.65      matt 		 register_t *retval)
   1369  1.65      matt {
   1370  1.65      matt 	/* {
   1371  1.65      matt 		syscallarg(int) fd;
   1372  1.65      matt 		syscallarg(netbsd32_timespecp_t) tptr;
   1373  1.65      matt 	} */
   1374  1.82       mrg 	struct timespec ts[2], *tsp;
   1375  1.66      matt 	file_t *fp;
   1376  1.66      matt 	int error;
   1377  1.66      matt 
   1378  1.68     njoly 	error = get_utimens32(SCARG_P32(uap, tptr), ts, &tsp);
   1379  1.68     njoly 	if (error != 0)
   1380  1.68     njoly 		return error;
   1381  1.65      matt 
   1382  1.66      matt 	/* fd_getvnode() will use the descriptor for us */
   1383  1.66      matt 	if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
   1384  1.66      matt 		return (error);
   1385  1.71      matt 	error = do_sys_utimensat(l, AT_FDCWD, fp->f_vnode, NULL, 0,
   1386  1.68     njoly 	    tsp, UIO_SYSSPACE);
   1387  1.66      matt 	fd_putfile(SCARG(uap, fd));
   1388  1.66      matt 	return (error);
   1389  1.65      matt }
   1390