Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_fs.c revision 1.53.2.3
      1  1.53.2.3      yamt /*	$NetBSD: netbsd32_fs.c,v 1.53.2.3 2010/08/11 22:53:11 yamt 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.53.2.3      yamt __KERNEL_RCSID(0, "$NetBSD: netbsd32_fs.c,v 1.53.2.3 2010/08/11 22:53:11 yamt 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.53.2.2      yamt #include <fs/cd9660/cd9660_mount.h>
     53  1.53.2.2      yamt #include <ufs/ufs/ufsmount.h>
     54  1.53.2.2      yamt 
     55       1.1       mrg #include <compat/netbsd32/netbsd32.h>
     56       1.1       mrg #include <compat/netbsd32/netbsd32_syscallargs.h>
     57       1.1       mrg #include <compat/netbsd32/netbsd32_conv.h>
     58      1.28    martin #include <compat/sys/mount.h>
     59       1.1       mrg 
     60       1.1       mrg 
     61      1.51        ad static int dofilereadv32(int, struct file *, struct netbsd32_iovec *,
     62      1.47       dsl 			      int, off_t *, int, register_t *);
     63      1.51        ad static int dofilewritev32(int, struct file *, struct netbsd32_iovec *,
     64      1.47       dsl 			       int,  off_t *, int, register_t *);
     65       1.1       mrg 
     66      1.45       dsl struct iovec *
     67      1.45       dsl netbsd32_get_iov(struct netbsd32_iovec *iov32, int iovlen, struct iovec *aiov,
     68      1.45       dsl     int aiov_len)
     69      1.45       dsl {
     70      1.45       dsl #define N_IOV32 8
     71      1.45       dsl 	struct netbsd32_iovec aiov32[N_IOV32];
     72      1.45       dsl 	struct iovec *iov = aiov;
     73      1.45       dsl 	struct iovec *iovp;
     74      1.45       dsl 	int i, n, j;
     75      1.45       dsl 	int error;
     76      1.45       dsl 
     77      1.45       dsl 	if (iovlen < 0 || iovlen > IOV_MAX)
     78      1.45       dsl 		return NULL;
     79      1.45       dsl 
     80      1.45       dsl 	if (iovlen > aiov_len)
     81  1.53.2.3      yamt 		iov = kmem_alloc(iovlen * sizeof(*iov), KM_SLEEP);
     82      1.45       dsl 
     83      1.45       dsl 	iovp = iov;
     84      1.45       dsl 	for (i = 0; i < iovlen; iov32 += N_IOV32, i += N_IOV32) {
     85      1.45       dsl 		n = iovlen - i;
     86      1.45       dsl 		if (n > N_IOV32)
     87      1.45       dsl 			n = N_IOV32;
     88      1.45       dsl 		error = copyin(iov32, aiov32, n * sizeof (*iov32));
     89      1.45       dsl 		if (error != 0) {
     90      1.45       dsl 			if (iov != aiov)
     91  1.53.2.3      yamt 				kmem_free(iov, iovlen * sizeof(*iov));
     92      1.45       dsl 			return NULL;
     93      1.45       dsl 		}
     94      1.45       dsl 		for (j = 0; j < n; iovp++, j++) {
     95      1.45       dsl 			iovp->iov_base = NETBSD32PTR64(aiov32[j].iov_base);
     96      1.45       dsl 			iovp->iov_len = aiov32[j].iov_len;
     97      1.45       dsl 		}
     98      1.45       dsl 	}
     99      1.45       dsl 	return iov;
    100      1.45       dsl #undef N_IOV32
    101      1.45       dsl }
    102      1.45       dsl 
    103       1.1       mrg int
    104      1.49       dsl netbsd32_readv(struct lwp *l, const struct netbsd32_readv_args *uap, register_t *retval)
    105       1.1       mrg {
    106      1.49       dsl 	/* {
    107       1.1       mrg 		syscallarg(int) fd;
    108       1.1       mrg 		syscallarg(const netbsd32_iovecp_t) iovp;
    109       1.1       mrg 		syscallarg(int) iovcnt;
    110      1.49       dsl 	} */
    111       1.1       mrg 	int fd = SCARG(uap, fd);
    112      1.51        ad 	file_t *fp;
    113       1.1       mrg 
    114      1.51        ad 	if ((fp = fd_getfile(fd)) == NULL)
    115       1.6   thorpej 		return (EBADF);
    116       1.6   thorpej 
    117      1.50       dsl 	if ((fp->f_flag & FREAD) == 0) {
    118      1.51        ad 		fd_putfile(fd);
    119       1.1       mrg 		return (EBADF);
    120      1.50       dsl 	}
    121       1.1       mrg 
    122      1.51        ad 	return (dofilereadv32(fd, fp,
    123      1.39       dsl 	    (struct netbsd32_iovec *)SCARG_P32(uap, iovp),
    124      1.10       scw 	    SCARG(uap, iovcnt), &fp->f_offset, FOF_UPDATE_OFFSET, retval));
    125       1.1       mrg }
    126       1.1       mrg 
    127       1.1       mrg /* Damn thing copies in the iovec! */
    128       1.1       mrg int
    129      1.51        ad dofilereadv32(int fd, struct file *fp, struct netbsd32_iovec *iovp, int iovcnt, off_t *offset, int flags, register_t *retval)
    130       1.1       mrg {
    131       1.1       mrg 	struct uio auio;
    132       1.1       mrg 	struct iovec *iov;
    133       1.1       mrg 	struct iovec *needfree;
    134       1.1       mrg 	struct iovec aiov[UIO_SMALLIOV];
    135       1.1       mrg 	long i, cnt, error = 0;
    136       1.1       mrg 	u_int iovlen;
    137       1.1       mrg 	struct iovec *ktriov = NULL;
    138       1.1       mrg 
    139       1.1       mrg 	/* note: can't use iovlen until iovcnt is validated */
    140       1.1       mrg 	iovlen = iovcnt * sizeof(struct iovec);
    141       1.1       mrg 	if ((u_int)iovcnt > UIO_SMALLIOV) {
    142       1.9  jdolecek 		if ((u_int)iovcnt > IOV_MAX) {
    143       1.9  jdolecek 			error = EINVAL;
    144       1.9  jdolecek 			goto out;
    145       1.9  jdolecek 		}
    146  1.53.2.3      yamt 		iov = kmem_alloc(iovlen, KM_SLEEP);
    147       1.1       mrg 		needfree = iov;
    148       1.1       mrg 	} else if ((u_int)iovcnt > 0) {
    149       1.1       mrg 		iov = aiov;
    150       1.1       mrg 		needfree = NULL;
    151       1.9  jdolecek 	} else {
    152       1.9  jdolecek 		error = EINVAL;
    153       1.9  jdolecek 		goto out;
    154       1.9  jdolecek 	}
    155       1.1       mrg 
    156       1.1       mrg 	auio.uio_iov = iov;
    157       1.1       mrg 	auio.uio_iovcnt = iovcnt;
    158       1.1       mrg 	auio.uio_rw = UIO_READ;
    159      1.51        ad 	auio.uio_vmspace = curproc->p_vmspace;
    160       1.1       mrg 	error = netbsd32_to_iovecin(iovp, iov, iovcnt);
    161       1.1       mrg 	if (error)
    162       1.1       mrg 		goto done;
    163       1.1       mrg 	auio.uio_resid = 0;
    164       1.1       mrg 	for (i = 0; i < iovcnt; i++) {
    165       1.1       mrg 		auio.uio_resid += iov->iov_len;
    166       1.1       mrg 		/*
    167       1.1       mrg 		 * Reads return ssize_t because -1 is returned on error.
    168       1.1       mrg 		 * Therefore we must restrict the length to SSIZE_MAX to
    169       1.1       mrg 		 * avoid garbage return values.
    170       1.1       mrg 		 */
    171       1.1       mrg 		if (iov->iov_len > SSIZE_MAX || auio.uio_resid > SSIZE_MAX) {
    172       1.1       mrg 			error = EINVAL;
    173       1.1       mrg 			goto done;
    174       1.1       mrg 		}
    175       1.1       mrg 		iov++;
    176       1.1       mrg 	}
    177      1.46        ad 
    178       1.1       mrg 	/*
    179       1.1       mrg 	 * if tracing, save a copy of iovec
    180       1.1       mrg 	 */
    181      1.46        ad 	if (ktrpoint(KTR_GENIO)) {
    182  1.53.2.3      yamt 		ktriov = kmem_alloc(iovlen, KM_SLEEP);
    183      1.36  christos 		memcpy((void *)ktriov, (void *)auio.uio_iov, iovlen);
    184       1.1       mrg 	}
    185      1.46        ad 
    186       1.1       mrg 	cnt = auio.uio_resid;
    187       1.1       mrg 	error = (*fp->f_ops->fo_read)(fp, offset, &auio, fp->f_cred, flags);
    188       1.1       mrg 	if (error)
    189       1.1       mrg 		if (auio.uio_resid != cnt && (error == ERESTART ||
    190       1.1       mrg 		    error == EINTR || error == EWOULDBLOCK))
    191       1.1       mrg 			error = 0;
    192       1.1       mrg 	cnt -= auio.uio_resid;
    193      1.46        ad 
    194      1.46        ad 	if (ktriov != NULL) {
    195      1.46        ad 		ktrgeniov(fd, UIO_READ, ktriov, cnt, error);
    196  1.53.2.3      yamt 		kmem_free(ktriov, iovlen);
    197       1.1       mrg 	}
    198      1.46        ad 
    199       1.1       mrg 	*retval = cnt;
    200       1.1       mrg done:
    201       1.1       mrg 	if (needfree)
    202  1.53.2.3      yamt 		kmem_free(needfree, iovlen);
    203       1.9  jdolecek out:
    204      1.51        ad 	fd_putfile(fd);
    205       1.1       mrg 	return (error);
    206       1.1       mrg }
    207       1.1       mrg 
    208       1.1       mrg int
    209      1.49       dsl netbsd32_writev(struct lwp *l, const struct netbsd32_writev_args *uap, register_t *retval)
    210       1.1       mrg {
    211      1.49       dsl 	/* {
    212       1.1       mrg 		syscallarg(int) fd;
    213       1.1       mrg 		syscallarg(const netbsd32_iovecp_t) iovp;
    214       1.1       mrg 		syscallarg(int) iovcnt;
    215      1.49       dsl 	} */
    216       1.1       mrg 	int fd = SCARG(uap, fd);
    217      1.51        ad 	file_t *fp;
    218       1.1       mrg 
    219      1.51        ad 	if ((fp = fd_getfile(fd)) == NULL)
    220       1.6   thorpej 		return (EBADF);
    221       1.6   thorpej 
    222      1.50       dsl 	if ((fp->f_flag & FWRITE) == 0) {
    223      1.51        ad 		fd_putfile(fd);
    224       1.1       mrg 		return (EBADF);
    225      1.50       dsl 	}
    226       1.1       mrg 
    227      1.51        ad 	return (dofilewritev32(fd, fp,
    228      1.39       dsl 	    (struct netbsd32_iovec *)SCARG_P32(uap, iovp),
    229      1.10       scw 	    SCARG(uap, iovcnt), &fp->f_offset, FOF_UPDATE_OFFSET, retval));
    230       1.1       mrg }
    231       1.1       mrg 
    232       1.1       mrg int
    233      1.51        ad dofilewritev32(int fd, struct file *fp, struct netbsd32_iovec *iovp, int iovcnt, off_t *offset, int flags, register_t *retval)
    234       1.1       mrg {
    235       1.1       mrg 	struct uio auio;
    236       1.1       mrg 	struct iovec *iov;
    237       1.1       mrg 	struct iovec *needfree;
    238       1.1       mrg 	struct iovec aiov[UIO_SMALLIOV];
    239       1.1       mrg 	long i, cnt, error = 0;
    240       1.1       mrg 	u_int iovlen;
    241       1.1       mrg 	struct iovec *ktriov = NULL;
    242       1.1       mrg 
    243       1.1       mrg 	/* note: can't use iovlen until iovcnt is validated */
    244       1.1       mrg 	iovlen = iovcnt * sizeof(struct iovec);
    245       1.1       mrg 	if ((u_int)iovcnt > UIO_SMALLIOV) {
    246       1.9  jdolecek 		if ((u_int)iovcnt > IOV_MAX) {
    247       1.9  jdolecek 			error = EINVAL;
    248       1.9  jdolecek 			goto out;
    249       1.9  jdolecek 		}
    250  1.53.2.3      yamt 		iov = kmem_alloc(iovlen, KM_SLEEP);
    251       1.1       mrg 		needfree = iov;
    252       1.1       mrg 	} else if ((u_int)iovcnt > 0) {
    253       1.1       mrg 		iov = aiov;
    254       1.1       mrg 		needfree = NULL;
    255       1.9  jdolecek 	} else {
    256       1.9  jdolecek 		error = EINVAL;
    257       1.9  jdolecek 		goto out;
    258       1.9  jdolecek 	}
    259       1.1       mrg 
    260       1.1       mrg 	auio.uio_iov = iov;
    261       1.1       mrg 	auio.uio_iovcnt = iovcnt;
    262       1.1       mrg 	auio.uio_rw = UIO_WRITE;
    263      1.51        ad 	auio.uio_vmspace = curproc->p_vmspace;
    264       1.1       mrg 	error = netbsd32_to_iovecin(iovp, iov, iovcnt);
    265       1.1       mrg 	if (error)
    266       1.1       mrg 		goto done;
    267       1.1       mrg 	auio.uio_resid = 0;
    268       1.1       mrg 	for (i = 0; i < iovcnt; i++) {
    269       1.1       mrg 		auio.uio_resid += iov->iov_len;
    270       1.1       mrg 		/*
    271       1.1       mrg 		 * Writes return ssize_t because -1 is returned on error.
    272       1.1       mrg 		 * Therefore we must restrict the length to SSIZE_MAX to
    273       1.1       mrg 		 * avoid garbage return values.
    274       1.1       mrg 		 */
    275       1.1       mrg 		if (iov->iov_len > SSIZE_MAX || auio.uio_resid > SSIZE_MAX) {
    276       1.1       mrg 			error = EINVAL;
    277       1.1       mrg 			goto done;
    278       1.1       mrg 		}
    279       1.1       mrg 		iov++;
    280       1.1       mrg 	}
    281      1.46        ad 
    282       1.1       mrg 	/*
    283       1.1       mrg 	 * if tracing, save a copy of iovec
    284       1.1       mrg 	 */
    285      1.46        ad 	if (ktrpoint(KTR_GENIO))  {
    286  1.53.2.3      yamt 		ktriov = kmem_alloc(iovlen, KM_SLEEP);
    287      1.36  christos 		memcpy((void *)ktriov, (void *)auio.uio_iov, iovlen);
    288       1.1       mrg 	}
    289      1.46        ad 
    290       1.1       mrg 	cnt = auio.uio_resid;
    291       1.1       mrg 	error = (*fp->f_ops->fo_write)(fp, offset, &auio, fp->f_cred, flags);
    292       1.1       mrg 	if (error) {
    293       1.1       mrg 		if (auio.uio_resid != cnt && (error == ERESTART ||
    294       1.1       mrg 		    error == EINTR || error == EWOULDBLOCK))
    295       1.1       mrg 			error = 0;
    296      1.44        ad 		if (error == EPIPE) {
    297      1.53        ad 			mutex_enter(proc_lock);
    298      1.51        ad 			psignal(curproc, SIGPIPE);
    299      1.53        ad 			mutex_exit(proc_lock);
    300      1.44        ad 		}
    301       1.1       mrg 	}
    302       1.1       mrg 	cnt -= auio.uio_resid;
    303      1.46        ad 	if (ktriov != NULL) {
    304      1.46        ad 		ktrgenio(fd, UIO_WRITE, ktriov, cnt, error);
    305  1.53.2.3      yamt 		kmem_free(ktriov, iovlen);
    306       1.1       mrg 	}
    307       1.1       mrg 	*retval = cnt;
    308       1.1       mrg done:
    309       1.1       mrg 	if (needfree)
    310  1.53.2.3      yamt 		kmem_free(needfree, iovlen);
    311       1.9  jdolecek out:
    312      1.51        ad 	fd_putfile(fd);
    313       1.1       mrg 	return (error);
    314       1.1       mrg }
    315       1.1       mrg 
    316      1.43       dsl /*
    317      1.43       dsl  * Common routine to set access and modification times given a vnode.
    318      1.43       dsl  */
    319      1.43       dsl static int
    320      1.43       dsl get_utimes32(const netbsd32_timevalp_t *tptr, struct timeval *tv,
    321      1.43       dsl     struct timeval **tvp)
    322      1.43       dsl {
    323      1.43       dsl 	int error;
    324      1.43       dsl 	struct netbsd32_timeval tv32[2];
    325      1.43       dsl 
    326      1.43       dsl 	if (tptr == NULL) {
    327      1.43       dsl 		*tvp = NULL;
    328      1.43       dsl 		return 0;
    329      1.43       dsl 	}
    330      1.43       dsl 
    331      1.43       dsl 	error = copyin(tptr, tv32, sizeof(tv32));
    332      1.43       dsl 	if (error)
    333      1.43       dsl 		return error;
    334      1.43       dsl 	netbsd32_to_timeval(&tv32[0], &tv[0]);
    335      1.43       dsl 	netbsd32_to_timeval(&tv32[1], &tv[1]);
    336      1.43       dsl 
    337      1.43       dsl 	*tvp = tv;
    338      1.43       dsl 	return 0;
    339      1.43       dsl }
    340      1.43       dsl 
    341       1.1       mrg int
    342  1.53.2.1      yamt netbsd32___utimes50(struct lwp *l, const struct netbsd32___utimes50_args *uap, register_t *retval)
    343       1.1       mrg {
    344      1.49       dsl 	/* {
    345       1.1       mrg 		syscallarg(const netbsd32_charp) path;
    346       1.1       mrg 		syscallarg(const netbsd32_timevalp_t) tptr;
    347      1.49       dsl 	} */
    348       1.1       mrg 	int error;
    349      1.43       dsl 	struct timeval tv[2], *tvp;
    350       1.1       mrg 
    351      1.43       dsl 	error = get_utimes32(SCARG_P32(uap, tptr), tv, &tvp);
    352      1.43       dsl 	if (error != 0)
    353      1.43       dsl 		return error;
    354       1.1       mrg 
    355      1.43       dsl 	return do_sys_utimes(l, NULL, SCARG_P32(uap, path), FOLLOW,
    356      1.43       dsl 			    tvp, UIO_SYSSPACE);
    357       1.1       mrg }
    358       1.1       mrg 
    359      1.42       dsl static int
    360      1.42       dsl netbds32_copyout_statvfs(const void *kp, void *up, size_t len)
    361      1.42       dsl {
    362      1.42       dsl 	struct netbsd32_statvfs *sbuf_32;
    363      1.42       dsl 	int error;
    364      1.42       dsl 
    365  1.53.2.3      yamt 	sbuf_32 = kmem_alloc(sizeof(*sbuf_32), KM_SLEEP);
    366      1.42       dsl 	netbsd32_from_statvfs(kp, sbuf_32);
    367      1.42       dsl 	error = copyout(sbuf_32, up, sizeof(*sbuf_32));
    368  1.53.2.3      yamt 	kmem_free(sbuf_32, sizeof(*sbuf_32));
    369      1.42       dsl 
    370      1.42       dsl 	return error;
    371      1.42       dsl }
    372      1.42       dsl 
    373       1.1       mrg int
    374      1.49       dsl netbsd32_statvfs1(struct lwp *l, const struct netbsd32_statvfs1_args *uap, register_t *retval)
    375       1.1       mrg {
    376      1.49       dsl 	/* {
    377       1.1       mrg 		syscallarg(const netbsd32_charp) path;
    378      1.18      cube 		syscallarg(netbsd32_statvfsp_t) buf;
    379      1.18      cube 		syscallarg(int) flags;
    380      1.49       dsl 	} */
    381      1.42       dsl 	struct statvfs *sb;
    382       1.1       mrg 	int error;
    383       1.1       mrg 
    384      1.42       dsl 	sb = STATVFSBUF_GET();
    385      1.42       dsl 	error = do_sys_pstatvfs(l, SCARG_P32(uap, path), SCARG(uap, flags), sb);
    386      1.42       dsl 	if (error == 0)
    387      1.42       dsl 		error = netbds32_copyout_statvfs(sb, SCARG_P32(uap, buf), 0);
    388      1.42       dsl 	STATVFSBUF_PUT(sb);
    389      1.42       dsl 	return error;
    390       1.1       mrg }
    391       1.1       mrg 
    392       1.1       mrg int
    393      1.49       dsl netbsd32_fstatvfs1(struct lwp *l, const struct netbsd32_fstatvfs1_args *uap, register_t *retval)
    394       1.1       mrg {
    395      1.49       dsl 	/* {
    396       1.1       mrg 		syscallarg(int) fd;
    397      1.18      cube 		syscallarg(netbsd32_statvfsp_t) buf;
    398      1.18      cube 		syscallarg(int) flags;
    399      1.49       dsl 	} */
    400      1.42       dsl 	struct statvfs *sb;
    401       1.1       mrg 	int error;
    402       1.1       mrg 
    403      1.42       dsl 	sb = STATVFSBUF_GET();
    404      1.42       dsl 	error = do_sys_fstatvfs(l, SCARG(uap, fd), SCARG(uap, flags), sb);
    405      1.42       dsl 	if (error == 0)
    406      1.42       dsl 		error = netbds32_copyout_statvfs(sb, SCARG_P32(uap, buf), 0);
    407      1.42       dsl 	STATVFSBUF_PUT(sb);
    408      1.18      cube 	return error;
    409      1.18      cube }
    410      1.18      cube 
    411      1.18      cube int
    412      1.49       dsl netbsd32_getvfsstat(struct lwp *l, const struct netbsd32_getvfsstat_args *uap, register_t *retval)
    413      1.18      cube {
    414      1.49       dsl 	/* {
    415      1.18      cube 		syscallarg(netbsd32_statvfsp_t) buf;
    416      1.18      cube 		syscallarg(netbsd32_size_t) bufsize;
    417      1.18      cube 		syscallarg(int) flags;
    418      1.49       dsl 	} */
    419      1.18      cube 
    420      1.42       dsl 	return do_sys_getvfsstat(l, SCARG_P32(uap, buf), SCARG(uap, bufsize),
    421      1.42       dsl 	    SCARG(uap, flags), netbds32_copyout_statvfs,
    422      1.42       dsl 	    sizeof (struct netbsd32_statvfs), retval);
    423      1.18      cube }
    424      1.18      cube 
    425      1.18      cube int
    426      1.49       dsl netbsd32___fhstatvfs140(struct lwp *l, const struct netbsd32___fhstatvfs140_args *uap, register_t *retval)
    427      1.18      cube {
    428      1.49       dsl 	/* {
    429      1.32    martin 		syscallarg(const netbsd32_pointer_t) fhp;
    430      1.32    martin 		syscallarg(netbsd32_size_t) fh_size;
    431      1.18      cube 		syscallarg(netbsd32_statvfsp_t) buf;
    432      1.18      cube 		syscallarg(int) flags;
    433      1.49       dsl 	} */
    434      1.42       dsl 	struct statvfs *sb;
    435      1.18      cube 	int error;
    436      1.18      cube 
    437      1.42       dsl 	sb = STATVFSBUF_GET();
    438      1.42       dsl 	error = do_fhstatvfs(l, SCARG_P32(uap, fhp), SCARG(uap, fh_size), sb,
    439      1.42       dsl 	    SCARG(uap, flags));
    440      1.42       dsl 
    441      1.42       dsl 	if (error == 0)
    442      1.42       dsl 		error = netbds32_copyout_statvfs(sb, SCARG_P32(uap, buf), 0);
    443      1.42       dsl 	STATVFSBUF_PUT(sb);
    444      1.18      cube 
    445      1.42       dsl 	return error;
    446       1.1       mrg }
    447       1.1       mrg 
    448       1.1       mrg int
    449  1.53.2.1      yamt netbsd32___futimes50(struct lwp *l, const struct netbsd32___futimes50_args *uap, register_t *retval)
    450       1.1       mrg {
    451      1.49       dsl 	/* {
    452       1.1       mrg 		syscallarg(int) fd;
    453       1.1       mrg 		syscallarg(const netbsd32_timevalp_t) tptr;
    454      1.49       dsl 	} */
    455       1.1       mrg 	int error;
    456      1.51        ad 	file_t *fp;
    457      1.43       dsl 	struct timeval tv[2], *tvp;
    458      1.43       dsl 
    459      1.43       dsl 	error = get_utimes32(SCARG_P32(uap, tptr), tv, &tvp);
    460      1.43       dsl 	if (error != 0)
    461      1.43       dsl 		return error;
    462       1.1       mrg 
    463  1.53.2.1      yamt 	/* fd_getvnode() will use the descriptor for us */
    464      1.51        ad 	if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
    465       1.1       mrg 		return (error);
    466       1.1       mrg 
    467      1.43       dsl 	error = do_sys_utimes(l, fp->f_data, NULL, 0, tvp, UIO_SYSSPACE);
    468      1.43       dsl 
    469      1.51        ad 	fd_putfile(SCARG(uap, fd));
    470       1.1       mrg 	return (error);
    471       1.1       mrg }
    472       1.1       mrg 
    473       1.1       mrg int
    474  1.53.2.1      yamt netbsd32___getdents30(struct lwp *l,
    475  1.53.2.1      yamt     const struct netbsd32___getdents30_args *uap, register_t *retval)
    476       1.1       mrg {
    477      1.49       dsl 	/* {
    478       1.1       mrg 		syscallarg(int) fd;
    479       1.1       mrg 		syscallarg(netbsd32_charp) buf;
    480       1.1       mrg 		syscallarg(netbsd32_size_t) count;
    481      1.49       dsl 	} */
    482      1.51        ad 	file_t *fp;
    483       1.1       mrg 	int error, done;
    484       1.1       mrg 
    485  1.53.2.1      yamt 	/* fd_getvnode() will use the descriptor for us */
    486      1.51        ad 	if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
    487       1.1       mrg 		return (error);
    488       1.1       mrg 	if ((fp->f_flag & FREAD) == 0) {
    489       1.1       mrg 		error = EBADF;
    490       1.1       mrg 		goto out;
    491       1.1       mrg 	}
    492      1.39       dsl 	error = vn_readdir(fp, SCARG_P32(uap, buf),
    493      1.23  christos 	    UIO_USERSPACE, SCARG(uap, count), &done, l, 0, 0);
    494       1.1       mrg 	*retval = done;
    495       1.1       mrg  out:
    496      1.51        ad 	fd_putfile(SCARG(uap, fd));
    497       1.1       mrg 	return (error);
    498       1.1       mrg }
    499       1.1       mrg 
    500       1.1       mrg int
    501  1.53.2.1      yamt netbsd32___lutimes50(struct lwp *l,
    502  1.53.2.1      yamt     const struct netbsd32___lutimes50_args *uap, register_t *retval)
    503       1.1       mrg {
    504      1.49       dsl 	/* {
    505       1.1       mrg 		syscallarg(const netbsd32_charp) path;
    506       1.1       mrg 		syscallarg(const netbsd32_timevalp_t) tptr;
    507      1.49       dsl 	} */
    508       1.1       mrg 	int error;
    509      1.43       dsl 	struct timeval tv[2], *tvp;
    510       1.1       mrg 
    511      1.43       dsl 	error = get_utimes32(SCARG_P32(uap, tptr), tv, &tvp);
    512      1.43       dsl 	if (error != 0)
    513      1.43       dsl 		return error;
    514       1.1       mrg 
    515      1.43       dsl 	return do_sys_utimes(l, NULL, SCARG_P32(uap, path), NOFOLLOW,
    516      1.43       dsl 			    tvp, UIO_SYSSPACE);
    517       1.1       mrg }
    518       1.1       mrg 
    519       1.1       mrg int
    520  1.53.2.1      yamt netbsd32___stat50(struct lwp *l, const struct netbsd32___stat50_args *uap, register_t *retval)
    521       1.1       mrg {
    522      1.49       dsl 	/* {
    523       1.1       mrg 		syscallarg(const netbsd32_charp) path;
    524       1.1       mrg 		syscallarg(netbsd32_statp_t) ub;
    525      1.49       dsl 	} */
    526       1.1       mrg 	struct netbsd32_stat sb32;
    527       1.1       mrg 	struct stat sb;
    528       1.1       mrg 	int error;
    529       1.1       mrg 	const char *path;
    530       1.1       mrg 
    531      1.39       dsl 	path = SCARG_P32(uap, path);
    532       1.1       mrg 
    533      1.51        ad 	error = do_sys_stat(path, FOLLOW, &sb);
    534      1.41       dsl 	if (error)
    535      1.41       dsl 		return (error);
    536  1.53.2.1      yamt 	netbsd32_from_stat(&sb, &sb32);
    537      1.39       dsl 	error = copyout(&sb32, SCARG_P32(uap, ub), sizeof(sb32));
    538       1.1       mrg 	return (error);
    539       1.1       mrg }
    540       1.1       mrg 
    541       1.1       mrg int
    542  1.53.2.1      yamt netbsd32___fstat50(struct lwp *l, const struct netbsd32___fstat50_args *uap, register_t *retval)
    543       1.1       mrg {
    544      1.49       dsl 	/* {
    545       1.1       mrg 		syscallarg(int) fd;
    546       1.1       mrg 		syscallarg(netbsd32_statp_t) sb;
    547      1.49       dsl 	} */
    548       1.1       mrg 	struct netbsd32_stat sb32;
    549       1.1       mrg 	struct stat ub;
    550  1.53.2.1      yamt 	int error;
    551       1.1       mrg 
    552  1.53.2.1      yamt 	error = do_sys_fstat(SCARG(uap, fd), &ub);
    553       1.1       mrg 	if (error == 0) {
    554  1.53.2.1      yamt 		netbsd32_from_stat(&ub, &sb32);
    555      1.39       dsl 		error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb32));
    556       1.1       mrg 	}
    557       1.1       mrg 	return (error);
    558       1.1       mrg }
    559       1.1       mrg 
    560       1.1       mrg int
    561  1.53.2.1      yamt netbsd32___lstat50(struct lwp *l, const struct netbsd32___lstat50_args *uap, register_t *retval)
    562       1.1       mrg {
    563      1.49       dsl 	/* {
    564       1.1       mrg 		syscallarg(const netbsd32_charp) path;
    565       1.1       mrg 		syscallarg(netbsd32_statp_t) ub;
    566      1.49       dsl 	} */
    567       1.1       mrg 	struct netbsd32_stat sb32;
    568       1.1       mrg 	struct stat sb;
    569       1.1       mrg 	int error;
    570       1.1       mrg 	const char *path;
    571       1.1       mrg 
    572      1.39       dsl 	path = SCARG_P32(uap, path);
    573       1.1       mrg 
    574      1.51        ad 	error = do_sys_stat(path, NOFOLLOW, &sb);
    575       1.1       mrg 	if (error)
    576       1.1       mrg 		return (error);
    577  1.53.2.1      yamt 	netbsd32_from_stat(&sb, &sb32);
    578      1.39       dsl 	error = copyout(&sb32, SCARG_P32(uap, ub), sizeof(sb32));
    579       1.1       mrg 	return (error);
    580       1.1       mrg }
    581       1.1       mrg 
    582      1.49       dsl int
    583  1.53.2.1      yamt netbsd32___fhstat50(struct lwp *l, const struct netbsd32___fhstat50_args *uap, register_t *retval)
    584      1.26      cube {
    585      1.49       dsl 	/* {
    586      1.32    martin 		syscallarg(const netbsd32_pointer_t) fhp;
    587      1.32    martin 		syscallarg(netbsd32_size_t) fh_size;
    588      1.26      cube 		syscallarg(netbsd32_statp_t) sb;
    589      1.49       dsl 	} */
    590      1.26      cube 	struct stat sb;
    591      1.26      cube 	struct netbsd32_stat sb32;
    592      1.26      cube 	int error;
    593      1.26      cube 
    594      1.42       dsl 	error = do_fhstat(l, SCARG_P32(uap, fhp), SCARG(uap, fh_size), &sb);
    595      1.42       dsl 	if (error != 0) {
    596  1.53.2.1      yamt 		netbsd32_from_stat(&sb, &sb32);
    597      1.42       dsl 		error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb));
    598      1.42       dsl 	}
    599      1.29    martin 	return error;
    600      1.26      cube }
    601      1.26      cube 
    602       1.1       mrg int
    603      1.49       dsl netbsd32_preadv(struct lwp *l, const struct netbsd32_preadv_args *uap, register_t *retval)
    604       1.1       mrg {
    605      1.49       dsl 	/* {
    606       1.1       mrg 		syscallarg(int) fd;
    607       1.1       mrg 		syscallarg(const netbsd32_iovecp_t) iovp;
    608       1.1       mrg 		syscallarg(int) iovcnt;
    609       1.1       mrg 		syscallarg(int) pad;
    610       1.1       mrg 		syscallarg(off_t) offset;
    611      1.49       dsl 	} */
    612      1.51        ad 	file_t *fp;
    613       1.1       mrg 	struct vnode *vp;
    614       1.1       mrg 	off_t offset;
    615       1.1       mrg 	int error, fd = SCARG(uap, fd);
    616       1.1       mrg 
    617      1.51        ad 	if ((fp = fd_getfile(fd)) == NULL)
    618       1.6   thorpej 		return (EBADF);
    619       1.6   thorpej 
    620      1.50       dsl 	if ((fp->f_flag & FREAD) == 0) {
    621      1.51        ad 		fd_putfile(fd);
    622       1.1       mrg 		return (EBADF);
    623      1.50       dsl 	}
    624       1.1       mrg 
    625      1.51        ad 	vp = fp->f_data;
    626       1.9  jdolecek 	if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO) {
    627       1.9  jdolecek 		error = ESPIPE;
    628       1.9  jdolecek 		goto out;
    629       1.9  jdolecek 	}
    630       1.1       mrg 
    631       1.1       mrg 	offset = SCARG(uap, offset);
    632       1.1       mrg 
    633       1.1       mrg 	/*
    634       1.1       mrg 	 * XXX This works because no file systems actually
    635       1.1       mrg 	 * XXX take any action on the seek operation.
    636       1.1       mrg 	 */
    637       1.1       mrg 	if ((error = VOP_SEEK(vp, fp->f_offset, offset, fp->f_cred)) != 0)
    638       1.9  jdolecek 		goto out;
    639       1.1       mrg 
    640      1.51        ad 	return (dofilereadv32(fd, fp, SCARG_P32(uap, iovp),
    641      1.10       scw 	    SCARG(uap, iovcnt), &offset, 0, retval));
    642       1.9  jdolecek 
    643       1.9  jdolecek out:
    644      1.51        ad 	fd_putfile(fd);
    645       1.9  jdolecek 	return (error);
    646       1.1       mrg }
    647       1.1       mrg 
    648       1.1       mrg int
    649      1.49       dsl netbsd32_pwritev(struct lwp *l, const struct netbsd32_pwritev_args *uap, register_t *retval)
    650       1.1       mrg {
    651      1.49       dsl 	/* {
    652       1.1       mrg 		syscallarg(int) fd;
    653       1.1       mrg 		syscallarg(const netbsd32_iovecp_t) iovp;
    654       1.1       mrg 		syscallarg(int) iovcnt;
    655       1.1       mrg 		syscallarg(int) pad;
    656       1.1       mrg 		syscallarg(off_t) offset;
    657      1.49       dsl 	} */
    658      1.51        ad 	file_t *fp;
    659       1.1       mrg 	struct vnode *vp;
    660       1.1       mrg 	off_t offset;
    661       1.1       mrg 	int error, fd = SCARG(uap, fd);
    662       1.1       mrg 
    663      1.51        ad 	if ((fp = fd_getfile(fd)) == NULL)
    664       1.6   thorpej 		return (EBADF);
    665       1.6   thorpej 
    666      1.50       dsl 	if ((fp->f_flag & FWRITE) == 0) {
    667      1.51        ad 		fd_putfile(fd);
    668       1.1       mrg 		return (EBADF);
    669      1.50       dsl 	}
    670       1.1       mrg 
    671      1.51        ad 	vp = fp->f_data;
    672       1.9  jdolecek 	if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO) {
    673       1.9  jdolecek 		error = ESPIPE;
    674       1.9  jdolecek 		goto out;
    675       1.9  jdolecek 	}
    676       1.1       mrg 
    677       1.1       mrg 	offset = SCARG(uap, offset);
    678       1.1       mrg 
    679       1.1       mrg 	/*
    680       1.1       mrg 	 * XXX This works because no file systems actually
    681       1.1       mrg 	 * XXX take any action on the seek operation.
    682       1.1       mrg 	 */
    683       1.1       mrg 	if ((error = VOP_SEEK(vp, fp->f_offset, offset, fp->f_cred)) != 0)
    684       1.9  jdolecek 		goto out;
    685       1.1       mrg 
    686      1.51        ad 	return (dofilewritev32(fd, fp, SCARG_P32(uap, iovp),
    687      1.10       scw 	    SCARG(uap, iovcnt), &offset, 0, retval));
    688       1.9  jdolecek 
    689       1.9  jdolecek out:
    690      1.51        ad 	fd_putfile(fd);
    691       1.9  jdolecek 	return (error);
    692       1.1       mrg }
    693       1.1       mrg 
    694       1.1       mrg /*
    695       1.1       mrg  * Find pathname of process's current directory.
    696       1.1       mrg  *
    697       1.1       mrg  * Use vfs vnode-to-name reverse cache; if that fails, fall back
    698       1.1       mrg  * to reading directory contents.
    699       1.1       mrg  */
    700      1.23  christos /* XXX NH Why does this exist */
    701      1.14      fvdl int
    702      1.47       dsl getcwd_common(struct vnode *, struct vnode *,
    703      1.47       dsl 		   char **, char *, int, int, struct lwp *);
    704      1.14      fvdl 
    705      1.49       dsl int
    706      1.49       dsl netbsd32___getcwd(struct lwp *l, const struct netbsd32___getcwd_args *uap, register_t *retval)
    707       1.1       mrg {
    708      1.49       dsl 	/* {
    709       1.1       mrg 		syscallarg(char *) bufp;
    710       1.1       mrg 		syscallarg(size_t) length;
    711      1.49       dsl 	} */
    712      1.11   thorpej 	struct proc *p = l->l_proc;
    713       1.1       mrg 	int     error;
    714       1.1       mrg 	char   *path;
    715       1.1       mrg 	char   *bp, *bend;
    716       1.1       mrg 	int     len = (int)SCARG(uap, length);
    717       1.1       mrg 	int	lenused;
    718      1.52        ad 	struct	cwdinfo *cwdi;
    719       1.1       mrg 
    720       1.1       mrg 	if (len > MAXPATHLEN*4)
    721       1.1       mrg 		len = MAXPATHLEN*4;
    722       1.1       mrg 	else if (len < 2)
    723       1.1       mrg 		return ERANGE;
    724       1.1       mrg 
    725  1.53.2.3      yamt 	path = kmem_alloc(len, KM_SLEEP);
    726       1.1       mrg 	if (!path)
    727       1.1       mrg 		return ENOMEM;
    728       1.1       mrg 
    729       1.1       mrg 	bp = &path[len];
    730       1.1       mrg 	bend = bp;
    731       1.1       mrg 	*(--bp) = '\0';
    732       1.1       mrg 
    733       1.1       mrg 	/*
    734       1.1       mrg 	 * 5th argument here is "max number of vnodes to traverse".
    735       1.1       mrg 	 * Since each entry takes up at least 2 bytes in the output buffer,
    736       1.1       mrg 	 * limit it to N/2 vnodes for an N byte buffer.
    737       1.1       mrg 	 */
    738       1.1       mrg #define GETCWD_CHECK_ACCESS 0x0001
    739      1.52        ad 	cwdi = p->p_cwdi;
    740      1.52        ad 	rw_enter(&cwdi->cwdi_lock, RW_READER);
    741      1.52        ad 	error = getcwd_common (cwdi->cwdi_cdir, NULL, &bp, path, len/2,
    742      1.23  christos 			       GETCWD_CHECK_ACCESS, l);
    743      1.52        ad 	rw_exit(&cwdi->cwdi_lock);
    744       1.1       mrg 
    745       1.1       mrg 	if (error)
    746       1.1       mrg 		goto out;
    747       1.1       mrg 	lenused = bend - bp;
    748       1.1       mrg 	*retval = lenused;
    749       1.1       mrg 	/* put the result into user buffer */
    750      1.39       dsl 	error = copyout(bp, SCARG_P32(uap, bufp), lenused);
    751       1.1       mrg 
    752       1.1       mrg out:
    753  1.53.2.3      yamt 	kmem_free(path, len);
    754       1.1       mrg 	return error;
    755       1.1       mrg }
    756  1.53.2.2      yamt 
    757  1.53.2.2      yamt int
    758  1.53.2.2      yamt netbsd32___mount50(struct lwp *l, const struct netbsd32___mount50_args *uap,
    759  1.53.2.2      yamt 	register_t *retval)
    760  1.53.2.2      yamt {
    761  1.53.2.2      yamt 	/* {
    762  1.53.2.2      yamt 		syscallarg(netbsd32_charp) type;
    763  1.53.2.2      yamt 		syscallarg(netbsd32_charp) path;
    764  1.53.2.2      yamt 		syscallarg(int) flags;
    765  1.53.2.2      yamt 		syscallarg(netbsd32_voidp) data;
    766  1.53.2.2      yamt 		syscallarg(netbsd32_size_t) data_len;
    767  1.53.2.2      yamt 	} */
    768  1.53.2.2      yamt 	char mtype[MNAMELEN];
    769  1.53.2.2      yamt 	union {
    770  1.53.2.2      yamt 		struct netbsd32_ufs_args ufs_args;
    771  1.53.2.2      yamt 		struct netbsd32_mfs_args mfs_args;
    772  1.53.2.2      yamt 		struct netbsd32_iso_args iso_args;
    773  1.53.2.2      yamt 	} fs_args32;
    774  1.53.2.2      yamt 	union {
    775  1.53.2.2      yamt 		struct ufs_args ufs_args;
    776  1.53.2.2      yamt 		struct mfs_args mfs_args;
    777  1.53.2.2      yamt 		struct iso_args iso_args;
    778  1.53.2.2      yamt 	} fs_args;
    779  1.53.2.2      yamt 	const char *type = SCARG_P32(uap, type);
    780  1.53.2.2      yamt 	const char *path = SCARG_P32(uap, path);
    781  1.53.2.2      yamt 	int flags = SCARG(uap, flags);
    782  1.53.2.2      yamt 	void *data = SCARG_P32(uap, data);
    783  1.53.2.2      yamt 	size_t data_len = SCARG(uap, data_len);
    784  1.53.2.2      yamt 	enum uio_seg data_seg;
    785  1.53.2.2      yamt 	size_t len;
    786  1.53.2.2      yamt 	int error;
    787  1.53.2.2      yamt 
    788  1.53.2.2      yamt 	error = copyinstr(type, mtype, sizeof(mtype), &len);
    789  1.53.2.2      yamt 	if (error)
    790  1.53.2.2      yamt 		return error;
    791  1.53.2.2      yamt 	if (strcmp(mtype, MOUNT_MFS) == 0) {
    792  1.53.2.2      yamt 		if (data_len != sizeof(fs_args32.mfs_args))
    793  1.53.2.2      yamt 			return EINVAL;
    794  1.53.2.2      yamt 		if ((flags & MNT_GETARGS) == 0) {
    795  1.53.2.2      yamt 			error = copyin(data, &fs_args32.mfs_args,
    796  1.53.2.2      yamt 			    sizeof(fs_args32.mfs_args));
    797  1.53.2.2      yamt 			if (error)
    798  1.53.2.2      yamt 				return error;
    799  1.53.2.2      yamt 			fs_args.mfs_args.fspec =
    800  1.53.2.2      yamt 			    NETBSD32PTR64(fs_args32.mfs_args.fspec);
    801  1.53.2.2      yamt 			memset(&fs_args.mfs_args._pad1, 0,
    802  1.53.2.2      yamt 			    sizeof(fs_args.mfs_args._pad1));
    803  1.53.2.2      yamt 			fs_args.mfs_args.base =
    804  1.53.2.2      yamt 			    NETBSD32PTR64(fs_args32.mfs_args.base);
    805  1.53.2.2      yamt 			fs_args.mfs_args.size = fs_args32.mfs_args.size;
    806  1.53.2.2      yamt 		}
    807  1.53.2.2      yamt 		data_seg = UIO_SYSSPACE;
    808  1.53.2.2      yamt 		data = &fs_args.mfs_args;
    809  1.53.2.2      yamt 		data_len = sizeof(fs_args.mfs_args);
    810  1.53.2.2      yamt 	} else if (strcmp(mtype, MOUNT_UFS) == 0) {
    811  1.53.2.2      yamt 		if (data_len > sizeof(fs_args32.ufs_args))
    812  1.53.2.2      yamt 			return EINVAL;
    813  1.53.2.2      yamt 		if ((flags & MNT_GETARGS) == 0) {
    814  1.53.2.2      yamt 			error = copyin(data, &fs_args32.ufs_args,
    815  1.53.2.2      yamt 			    sizeof(fs_args32.ufs_args));
    816  1.53.2.2      yamt 			if (error)
    817  1.53.2.2      yamt 				return error;
    818  1.53.2.2      yamt 			fs_args.ufs_args.fspec =
    819  1.53.2.2      yamt 			    NETBSD32PTR64(fs_args32.ufs_args.fspec);
    820  1.53.2.2      yamt 		}
    821  1.53.2.2      yamt 		data_seg = UIO_SYSSPACE;
    822  1.53.2.2      yamt 		data = &fs_args.ufs_args;
    823  1.53.2.2      yamt 		data_len = sizeof(fs_args.ufs_args);
    824  1.53.2.2      yamt 	} else if (strcmp(mtype, MOUNT_CD9660) == 0) {
    825  1.53.2.2      yamt 		if (data_len != sizeof(fs_args32.iso_args))
    826  1.53.2.2      yamt 			return EINVAL;
    827  1.53.2.2      yamt 		if ((flags & MNT_GETARGS) == 0) {
    828  1.53.2.2      yamt 			error = copyin(data, &fs_args32.iso_args,
    829  1.53.2.2      yamt 			    sizeof(fs_args32.iso_args));
    830  1.53.2.2      yamt 			if (error)
    831  1.53.2.2      yamt 				return error;
    832  1.53.2.2      yamt 			fs_args.iso_args.fspec =
    833  1.53.2.2      yamt 			    NETBSD32PTR64(fs_args32.iso_args.fspec);
    834  1.53.2.2      yamt 			memset(&fs_args.iso_args._pad1, 0,
    835  1.53.2.2      yamt 			    sizeof(fs_args.iso_args._pad1));
    836  1.53.2.2      yamt 			fs_args.iso_args.flags = fs_args32.iso_args.flags;
    837  1.53.2.2      yamt 		}
    838  1.53.2.2      yamt 		data_seg = UIO_SYSSPACE;
    839  1.53.2.2      yamt 		data = &fs_args.iso_args;
    840  1.53.2.2      yamt 		data_len = sizeof(fs_args.iso_args);
    841  1.53.2.2      yamt 	} else {
    842  1.53.2.2      yamt 		data_seg = UIO_USERSPACE;
    843  1.53.2.2      yamt 	}
    844  1.53.2.2      yamt 	error = do_sys_mount(l, NULL, type, path, flags, data, data_seg,
    845  1.53.2.2      yamt 	    data_len, retval);
    846  1.53.2.2      yamt 	if (error)
    847  1.53.2.2      yamt 		return error;
    848  1.53.2.2      yamt 	if (flags & MNT_GETARGS) {
    849  1.53.2.2      yamt 		data_len = *retval;
    850  1.53.2.2      yamt 		if (strcmp(mtype, MOUNT_MFS) == 0) {
    851  1.53.2.2      yamt 			if (data_len != sizeof(fs_args.mfs_args))
    852  1.53.2.2      yamt 				return EINVAL;
    853  1.53.2.2      yamt 			NETBSD32PTR32(fs_args32.mfs_args.fspec,
    854  1.53.2.2      yamt 			    fs_args.mfs_args.fspec);
    855  1.53.2.2      yamt 			memset(&fs_args32.mfs_args._pad1, 0,
    856  1.53.2.2      yamt 			    sizeof(fs_args32.mfs_args._pad1));
    857  1.53.2.2      yamt 			NETBSD32PTR32(fs_args32.mfs_args.base,
    858  1.53.2.2      yamt 			    fs_args.mfs_args.base);
    859  1.53.2.2      yamt 			fs_args32.mfs_args.size = fs_args.mfs_args.size;
    860  1.53.2.2      yamt 			error = copyout(&fs_args32.mfs_args, data,
    861  1.53.2.2      yamt 				    sizeof(fs_args32.mfs_args));
    862  1.53.2.2      yamt 		} else if (strcmp(mtype, MOUNT_UFS) == 0) {
    863  1.53.2.2      yamt 			if (data_len != sizeof(fs_args.ufs_args))
    864  1.53.2.2      yamt 				return EINVAL;
    865  1.53.2.2      yamt 			NETBSD32PTR32(fs_args32.ufs_args.fspec,
    866  1.53.2.2      yamt 			    fs_args.ufs_args.fspec);
    867  1.53.2.2      yamt 			error = copyout(&fs_args32.ufs_args, data,
    868  1.53.2.2      yamt 			    sizeof(fs_args32.ufs_args));
    869  1.53.2.2      yamt 		} else if (strcmp(mtype, MOUNT_CD9660) == 0) {
    870  1.53.2.2      yamt 			if (data_len != sizeof(fs_args.iso_args))
    871  1.53.2.2      yamt 				return EINVAL;
    872  1.53.2.2      yamt 			NETBSD32PTR32(fs_args32.iso_args.fspec,
    873  1.53.2.2      yamt 			    fs_args.iso_args.fspec);
    874  1.53.2.2      yamt 			memset(&fs_args32.iso_args._pad1, 0,
    875  1.53.2.2      yamt 			    sizeof(fs_args32.iso_args._pad1));
    876  1.53.2.2      yamt 			fs_args32.iso_args.flags = fs_args.iso_args.flags;
    877  1.53.2.2      yamt 			error = copyout(&fs_args32.iso_args, data,
    878  1.53.2.2      yamt 				    sizeof(fs_args32.iso_args));
    879  1.53.2.2      yamt 		}
    880  1.53.2.2      yamt 	}
    881  1.53.2.2      yamt 	return error;
    882  1.53.2.2      yamt }
    883