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