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