Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_fs.c revision 1.18.6.1
      1  1.18.6.1      yamt /*	$NetBSD: netbsd32_fs.c,v 1.18.6.1 2005/03/19 08:33:43 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  * 3. The name of the author may not be used to endorse or promote products
     16       1.1       mrg  *    derived from this software without specific prior written permission.
     17       1.1       mrg  *
     18       1.1       mrg  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19       1.1       mrg  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20       1.1       mrg  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21       1.1       mrg  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22       1.1       mrg  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     23       1.1       mrg  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     24       1.1       mrg  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     25       1.1       mrg  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     26       1.1       mrg  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27       1.1       mrg  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28       1.1       mrg  * SUCH DAMAGE.
     29       1.1       mrg  */
     30       1.7     lukem 
     31       1.7     lukem #include <sys/cdefs.h>
     32  1.18.6.1      yamt __KERNEL_RCSID(0, "$NetBSD: netbsd32_fs.c,v 1.18.6.1 2005/03/19 08:33:43 yamt Exp $");
     33       1.1       mrg 
     34       1.5       mrg #if defined(_KERNEL_OPT)
     35       1.1       mrg #include "opt_ktrace.h"
     36       1.1       mrg #endif
     37       1.1       mrg 
     38       1.1       mrg #include <sys/param.h>
     39       1.1       mrg #include <sys/systm.h>
     40       1.1       mrg #include <sys/malloc.h>
     41       1.1       mrg #include <sys/mount.h>
     42       1.1       mrg #include <sys/socket.h>
     43       1.1       mrg #include <sys/socketvar.h>
     44       1.1       mrg #include <sys/stat.h>
     45       1.1       mrg #include <sys/time.h>
     46       1.1       mrg #include <sys/ktrace.h>
     47       1.1       mrg #include <sys/resourcevar.h>
     48       1.1       mrg #include <sys/vnode.h>
     49       1.1       mrg #include <sys/file.h>
     50       1.1       mrg #include <sys/filedesc.h>
     51       1.1       mrg #include <sys/namei.h>
     52      1.11   thorpej #include <sys/sa.h>
     53      1.18      cube #include <sys/statvfs.h>
     54       1.1       mrg #include <sys/syscallargs.h>
     55       1.1       mrg #include <sys/proc.h>
     56       1.1       mrg 
     57       1.1       mrg #include <compat/netbsd32/netbsd32.h>
     58       1.1       mrg #include <compat/netbsd32/netbsd32_syscallargs.h>
     59       1.1       mrg #include <compat/netbsd32/netbsd32_conv.h>
     60       1.1       mrg 
     61       1.1       mrg 
     62  1.18.6.1      yamt static int dofilereadv32 __P((struct proc *, int, struct file *, struct netbsd32_iovec *,
     63       1.1       mrg 			      int, off_t *, int, register_t *));
     64  1.18.6.1      yamt static int dofilewritev32 __P((struct proc *, int, struct file *, struct netbsd32_iovec *,
     65       1.1       mrg 			       int,  off_t *, int, register_t *));
     66      1.14      fvdl static int change_utimes32 __P((struct vnode *, netbsd32_timevalp_t, struct proc *));
     67       1.1       mrg 
     68       1.1       mrg int
     69      1.11   thorpej netbsd32_readv(l, v, retval)
     70      1.11   thorpej 	struct lwp *l;
     71       1.1       mrg 	void *v;
     72       1.1       mrg 	register_t *retval;
     73       1.1       mrg {
     74       1.1       mrg 	struct netbsd32_readv_args /* {
     75       1.1       mrg 		syscallarg(int) fd;
     76       1.1       mrg 		syscallarg(const netbsd32_iovecp_t) iovp;
     77       1.1       mrg 		syscallarg(int) iovcnt;
     78       1.1       mrg 	} */ *uap = v;
     79       1.1       mrg 	int fd = SCARG(uap, fd);
     80      1.11   thorpej 	struct proc *p = l->l_proc;
     81       1.1       mrg 	struct file *fp;
     82       1.1       mrg 	struct filedesc *fdp = p->p_fd;
     83       1.1       mrg 
     84       1.6   thorpej 	if ((fp = fd_getfile(fdp, fd)) == NULL)
     85       1.6   thorpej 		return (EBADF);
     86       1.6   thorpej 
     87       1.6   thorpej 	if ((fp->f_flag & FREAD) == 0)
     88       1.1       mrg 		return (EBADF);
     89       1.1       mrg 
     90       1.9  jdolecek 	FILE_USE(fp);
     91       1.9  jdolecek 
     92      1.14      fvdl 	return (dofilereadv32(p, fd, fp,
     93  1.18.6.1      yamt 	    (struct netbsd32_iovec *)NETBSD32PTR64(SCARG(uap, iovp)),
     94      1.10       scw 	    SCARG(uap, iovcnt), &fp->f_offset, FOF_UPDATE_OFFSET, retval));
     95       1.1       mrg }
     96       1.1       mrg 
     97       1.1       mrg /* Damn thing copies in the iovec! */
     98       1.1       mrg int
     99      1.14      fvdl dofilereadv32(p, fd, fp, iovp, iovcnt, offset, flags, retval)
    100      1.14      fvdl 	struct proc *p;
    101       1.1       mrg 	int fd;
    102       1.1       mrg 	struct file *fp;
    103       1.1       mrg 	struct netbsd32_iovec *iovp;
    104       1.1       mrg 	int iovcnt;
    105       1.1       mrg 	off_t *offset;
    106       1.1       mrg 	int flags;
    107       1.1       mrg 	register_t *retval;
    108       1.1       mrg {
    109       1.1       mrg 	struct uio auio;
    110       1.1       mrg 	struct iovec *iov;
    111       1.1       mrg 	struct iovec *needfree;
    112       1.1       mrg 	struct iovec aiov[UIO_SMALLIOV];
    113       1.1       mrg 	long i, cnt, error = 0;
    114       1.1       mrg 	u_int iovlen;
    115       1.1       mrg #ifdef KTRACE
    116       1.1       mrg 	struct iovec *ktriov = NULL;
    117       1.1       mrg #endif
    118       1.1       mrg 
    119       1.1       mrg 	/* note: can't use iovlen until iovcnt is validated */
    120       1.1       mrg 	iovlen = iovcnt * sizeof(struct iovec);
    121       1.1       mrg 	if ((u_int)iovcnt > UIO_SMALLIOV) {
    122       1.9  jdolecek 		if ((u_int)iovcnt > IOV_MAX) {
    123       1.9  jdolecek 			error = EINVAL;
    124       1.9  jdolecek 			goto out;
    125       1.9  jdolecek 		}
    126       1.9  jdolecek 		iov = malloc(iovlen, M_IOV, M_WAITOK);
    127       1.1       mrg 		needfree = iov;
    128       1.1       mrg 	} else if ((u_int)iovcnt > 0) {
    129       1.1       mrg 		iov = aiov;
    130       1.1       mrg 		needfree = NULL;
    131       1.9  jdolecek 	} else {
    132       1.9  jdolecek 		error = EINVAL;
    133       1.9  jdolecek 		goto out;
    134       1.9  jdolecek 	}
    135       1.1       mrg 
    136       1.1       mrg 	auio.uio_iov = iov;
    137       1.1       mrg 	auio.uio_iovcnt = iovcnt;
    138       1.1       mrg 	auio.uio_rw = UIO_READ;
    139       1.1       mrg 	auio.uio_segflg = UIO_USERSPACE;
    140      1.14      fvdl 	auio.uio_procp = p;
    141       1.1       mrg 	error = netbsd32_to_iovecin(iovp, iov, iovcnt);
    142       1.1       mrg 	if (error)
    143       1.1       mrg 		goto done;
    144       1.1       mrg 	auio.uio_resid = 0;
    145       1.1       mrg 	for (i = 0; i < iovcnt; i++) {
    146       1.1       mrg 		auio.uio_resid += iov->iov_len;
    147       1.1       mrg 		/*
    148       1.1       mrg 		 * Reads return ssize_t because -1 is returned on error.
    149       1.1       mrg 		 * Therefore we must restrict the length to SSIZE_MAX to
    150       1.1       mrg 		 * avoid garbage return values.
    151       1.1       mrg 		 */
    152       1.1       mrg 		if (iov->iov_len > SSIZE_MAX || auio.uio_resid > SSIZE_MAX) {
    153       1.1       mrg 			error = EINVAL;
    154       1.1       mrg 			goto done;
    155       1.1       mrg 		}
    156       1.1       mrg 		iov++;
    157       1.1       mrg 	}
    158       1.1       mrg #ifdef KTRACE
    159       1.1       mrg 	/*
    160       1.1       mrg 	 * if tracing, save a copy of iovec
    161       1.1       mrg 	 */
    162      1.14      fvdl 	if (KTRPOINT(p, KTR_GENIO))  {
    163       1.9  jdolecek 		ktriov = malloc(iovlen, M_TEMP, M_WAITOK);
    164       1.1       mrg 		memcpy((caddr_t)ktriov, (caddr_t)auio.uio_iov, iovlen);
    165       1.1       mrg 	}
    166       1.1       mrg #endif
    167       1.1       mrg 	cnt = auio.uio_resid;
    168       1.1       mrg 	error = (*fp->f_ops->fo_read)(fp, offset, &auio, fp->f_cred, flags);
    169       1.1       mrg 	if (error)
    170       1.1       mrg 		if (auio.uio_resid != cnt && (error == ERESTART ||
    171       1.1       mrg 		    error == EINTR || error == EWOULDBLOCK))
    172       1.1       mrg 			error = 0;
    173       1.1       mrg 	cnt -= auio.uio_resid;
    174       1.1       mrg #ifdef KTRACE
    175      1.14      fvdl 	if (KTRPOINT(p, KTR_GENIO))
    176       1.1       mrg 		if (error == 0) {
    177      1.14      fvdl 			ktrgenio(p, fd, UIO_READ, ktriov, cnt,
    178       1.1       mrg 			    error);
    179       1.9  jdolecek 		free(ktriov, M_TEMP);
    180       1.1       mrg 	}
    181       1.1       mrg #endif
    182       1.1       mrg 	*retval = cnt;
    183       1.1       mrg done:
    184       1.1       mrg 	if (needfree)
    185       1.9  jdolecek 		free(needfree, M_IOV);
    186       1.9  jdolecek out:
    187      1.14      fvdl 	FILE_UNUSE(fp, p);
    188       1.1       mrg 	return (error);
    189       1.1       mrg }
    190       1.1       mrg 
    191       1.1       mrg int
    192      1.11   thorpej netbsd32_writev(l, v, retval)
    193      1.11   thorpej 	struct lwp *l;
    194       1.1       mrg 	void *v;
    195       1.1       mrg 	register_t *retval;
    196       1.1       mrg {
    197       1.1       mrg 	struct netbsd32_writev_args /* {
    198       1.1       mrg 		syscallarg(int) fd;
    199       1.1       mrg 		syscallarg(const netbsd32_iovecp_t) iovp;
    200       1.1       mrg 		syscallarg(int) iovcnt;
    201       1.1       mrg 	} */ *uap = v;
    202       1.1       mrg 	int fd = SCARG(uap, fd);
    203       1.1       mrg 	struct file *fp;
    204      1.11   thorpej 	struct proc *p = l->l_proc;
    205       1.1       mrg 	struct filedesc *fdp = p->p_fd;
    206       1.1       mrg 
    207       1.6   thorpej 	if ((fp = fd_getfile(fdp, fd)) == NULL)
    208       1.6   thorpej 		return (EBADF);
    209       1.6   thorpej 
    210       1.6   thorpej 	if ((fp->f_flag & FWRITE) == 0)
    211       1.1       mrg 		return (EBADF);
    212       1.1       mrg 
    213       1.9  jdolecek 	FILE_USE(fp);
    214       1.9  jdolecek 
    215      1.14      fvdl 	return (dofilewritev32(p, fd, fp,
    216      1.10       scw 	    (struct netbsd32_iovec *)NETBSD32PTR64(SCARG(uap, iovp)),
    217      1.10       scw 	    SCARG(uap, iovcnt), &fp->f_offset, FOF_UPDATE_OFFSET, retval));
    218       1.1       mrg }
    219       1.1       mrg 
    220       1.1       mrg int
    221      1.14      fvdl dofilewritev32(p, fd, fp, iovp, iovcnt, offset, flags, retval)
    222      1.14      fvdl 	struct proc *p;
    223       1.1       mrg 	int fd;
    224       1.1       mrg 	struct file *fp;
    225       1.1       mrg 	struct netbsd32_iovec *iovp;
    226       1.1       mrg 	int iovcnt;
    227       1.1       mrg 	off_t *offset;
    228       1.1       mrg 	int flags;
    229       1.1       mrg 	register_t *retval;
    230       1.1       mrg {
    231       1.1       mrg 	struct uio auio;
    232       1.1       mrg 	struct iovec *iov;
    233       1.1       mrg 	struct iovec *needfree;
    234       1.1       mrg 	struct iovec aiov[UIO_SMALLIOV];
    235       1.1       mrg 	long i, cnt, error = 0;
    236       1.1       mrg 	u_int iovlen;
    237       1.1       mrg #ifdef KTRACE
    238       1.1       mrg 	struct iovec *ktriov = NULL;
    239       1.1       mrg #endif
    240       1.1       mrg 
    241       1.1       mrg 	/* note: can't use iovlen until iovcnt is validated */
    242       1.1       mrg 	iovlen = iovcnt * sizeof(struct iovec);
    243       1.1       mrg 	if ((u_int)iovcnt > UIO_SMALLIOV) {
    244       1.9  jdolecek 		if ((u_int)iovcnt > IOV_MAX) {
    245       1.9  jdolecek 			error = EINVAL;
    246       1.9  jdolecek 			goto out;
    247       1.9  jdolecek 		}
    248       1.9  jdolecek 		iov = malloc(iovlen, M_IOV, M_WAITOK);
    249       1.1       mrg 		needfree = iov;
    250       1.1       mrg 	} else if ((u_int)iovcnt > 0) {
    251       1.1       mrg 		iov = aiov;
    252       1.1       mrg 		needfree = NULL;
    253       1.9  jdolecek 	} else {
    254       1.9  jdolecek 		error = EINVAL;
    255       1.9  jdolecek 		goto out;
    256       1.9  jdolecek 	}
    257       1.1       mrg 
    258       1.1       mrg 	auio.uio_iov = iov;
    259       1.1       mrg 	auio.uio_iovcnt = iovcnt;
    260       1.1       mrg 	auio.uio_rw = UIO_WRITE;
    261       1.1       mrg 	auio.uio_segflg = UIO_USERSPACE;
    262      1.14      fvdl 	auio.uio_procp = p;
    263       1.1       mrg 	error = netbsd32_to_iovecin(iovp, iov, iovcnt);
    264       1.1       mrg 	if (error)
    265       1.1       mrg 		goto done;
    266       1.1       mrg 	auio.uio_resid = 0;
    267       1.1       mrg 	for (i = 0; i < iovcnt; i++) {
    268       1.1       mrg 		auio.uio_resid += iov->iov_len;
    269       1.1       mrg 		/*
    270       1.1       mrg 		 * Writes return ssize_t because -1 is returned on error.
    271       1.1       mrg 		 * Therefore we must restrict the length to SSIZE_MAX to
    272       1.1       mrg 		 * avoid garbage return values.
    273       1.1       mrg 		 */
    274       1.1       mrg 		if (iov->iov_len > SSIZE_MAX || auio.uio_resid > SSIZE_MAX) {
    275       1.1       mrg 			error = EINVAL;
    276       1.1       mrg 			goto done;
    277       1.1       mrg 		}
    278       1.1       mrg 		iov++;
    279       1.1       mrg 	}
    280       1.1       mrg #ifdef KTRACE
    281       1.1       mrg 	/*
    282       1.1       mrg 	 * if tracing, save a copy of iovec
    283       1.1       mrg 	 */
    284      1.14      fvdl 	if (KTRPOINT(p, KTR_GENIO))  {
    285       1.9  jdolecek 		ktriov = malloc(iovlen, M_TEMP, M_WAITOK);
    286       1.1       mrg 		memcpy((caddr_t)ktriov, (caddr_t)auio.uio_iov, iovlen);
    287       1.1       mrg 	}
    288       1.1       mrg #endif
    289       1.1       mrg 	cnt = auio.uio_resid;
    290       1.1       mrg 	error = (*fp->f_ops->fo_write)(fp, offset, &auio, fp->f_cred, flags);
    291       1.1       mrg 	if (error) {
    292       1.1       mrg 		if (auio.uio_resid != cnt && (error == ERESTART ||
    293       1.1       mrg 		    error == EINTR || error == EWOULDBLOCK))
    294       1.1       mrg 			error = 0;
    295       1.1       mrg 		if (error == EPIPE)
    296      1.14      fvdl 			psignal(p, SIGPIPE);
    297       1.1       mrg 	}
    298       1.1       mrg 	cnt -= auio.uio_resid;
    299       1.1       mrg #ifdef KTRACE
    300      1.14      fvdl 	if (KTRPOINT(p, KTR_GENIO))
    301       1.1       mrg 		if (error == 0) {
    302      1.14      fvdl 			ktrgenio(p, fd, UIO_WRITE, ktriov, cnt,
    303       1.1       mrg 			    error);
    304       1.9  jdolecek 		free(ktriov, M_TEMP);
    305       1.1       mrg 	}
    306       1.1       mrg #endif
    307       1.1       mrg 	*retval = cnt;
    308       1.1       mrg done:
    309       1.1       mrg 	if (needfree)
    310       1.9  jdolecek 		free(needfree, M_IOV);
    311       1.9  jdolecek out:
    312      1.14      fvdl 	FILE_UNUSE(fp, p);
    313       1.1       mrg 	return (error);
    314       1.1       mrg }
    315       1.1       mrg 
    316       1.1       mrg int
    317      1.11   thorpej netbsd32_utimes(l, v, retval)
    318      1.11   thorpej 	struct lwp *l;
    319       1.1       mrg 	void *v;
    320       1.1       mrg 	register_t *retval;
    321       1.1       mrg {
    322       1.1       mrg 	struct netbsd32_utimes_args /* {
    323       1.1       mrg 		syscallarg(const netbsd32_charp) path;
    324       1.1       mrg 		syscallarg(const netbsd32_timevalp_t) tptr;
    325       1.1       mrg 	} */ *uap = v;
    326       1.1       mrg 	int error;
    327       1.1       mrg 	struct nameidata nd;
    328      1.14      fvdl 	struct proc *p = l->l_proc;
    329       1.1       mrg 
    330      1.10       scw 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE,
    331      1.14      fvdl 	    (char *)NETBSD32PTR64(SCARG(uap, path)), p);
    332       1.1       mrg 	if ((error = namei(&nd)) != 0)
    333       1.1       mrg 		return (error);
    334       1.1       mrg 
    335      1.14      fvdl 	error = change_utimes32(nd.ni_vp, SCARG(uap, tptr), p);
    336       1.1       mrg 
    337       1.1       mrg 	vrele(nd.ni_vp);
    338       1.1       mrg 	return (error);
    339       1.1       mrg }
    340       1.1       mrg 
    341       1.1       mrg /*
    342       1.1       mrg  * Common routine to set access and modification times given a vnode.
    343       1.1       mrg  */
    344       1.1       mrg static int
    345      1.14      fvdl change_utimes32(vp, tptr, p)
    346       1.1       mrg 	struct vnode *vp;
    347       1.1       mrg 	netbsd32_timevalp_t tptr;
    348      1.14      fvdl 	struct proc *p;
    349       1.1       mrg {
    350       1.1       mrg 	struct netbsd32_timeval tv32[2];
    351       1.1       mrg 	struct timeval tv[2];
    352       1.1       mrg 	struct vattr vattr;
    353       1.1       mrg 	int error;
    354       1.1       mrg 
    355       1.1       mrg 	VATTR_NULL(&vattr);
    356      1.15      fvdl 	if (tptr == 0) {
    357       1.1       mrg 		microtime(&tv[0]);
    358       1.1       mrg 		tv[1] = tv[0];
    359       1.1       mrg 		vattr.va_vaflags |= VA_UTIMES_NULL;
    360       1.1       mrg 	} else {
    361      1.10       scw 		error = copyin((caddr_t)NETBSD32PTR64(tptr), tv32,
    362      1.10       scw 		    sizeof(tv32));
    363       1.1       mrg 		if (error)
    364       1.1       mrg 			return (error);
    365       1.1       mrg 		netbsd32_to_timeval(&tv32[0], &tv[0]);
    366       1.1       mrg 		netbsd32_to_timeval(&tv32[1], &tv[1]);
    367       1.1       mrg 	}
    368      1.14      fvdl 	VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
    369       1.1       mrg 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    370       1.1       mrg 	vattr.va_atime.tv_sec = tv[0].tv_sec;
    371       1.1       mrg 	vattr.va_atime.tv_nsec = tv[0].tv_usec * 1000;
    372       1.1       mrg 	vattr.va_mtime.tv_sec = tv[1].tv_sec;
    373       1.1       mrg 	vattr.va_mtime.tv_nsec = tv[1].tv_usec * 1000;
    374      1.14      fvdl 	error = VOP_SETATTR(vp, &vattr, p->p_ucred, p);
    375       1.1       mrg 	VOP_UNLOCK(vp, 0);
    376       1.1       mrg 	return (error);
    377       1.1       mrg }
    378       1.1       mrg 
    379       1.1       mrg int
    380      1.18      cube netbsd32_statvfs1(l, v, retval)
    381      1.11   thorpej 	struct lwp *l;
    382       1.1       mrg 	void *v;
    383       1.1       mrg 	register_t *retval;
    384       1.1       mrg {
    385      1.18      cube 	struct netbsd32_statvfs1_args /* {
    386       1.1       mrg 		syscallarg(const netbsd32_charp) path;
    387      1.18      cube 		syscallarg(netbsd32_statvfsp_t) buf;
    388      1.18      cube 		syscallarg(int) flags;
    389       1.1       mrg 	} */ *uap = v;
    390      1.18      cube 	struct proc *p = l->l_proc;
    391       1.1       mrg 	struct mount *mp;
    392      1.18      cube 	struct statvfs *sbuf;
    393      1.18      cube 	struct netbsd32_statvfs *s32;
    394      1.18      cube 	struct nameidata nd;
    395       1.1       mrg 	int error;
    396       1.1       mrg 
    397      1.10       scw 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE,
    398      1.14      fvdl 	    (char *)NETBSD32PTR64(SCARG(uap, path)), p);
    399       1.1       mrg 	if ((error = namei(&nd)) != 0)
    400       1.1       mrg 		return (error);
    401      1.18      cube 	/* Allocating on the stack would blow it up */
    402      1.18      cube 	sbuf = (struct statvfs *)malloc(sizeof(struct statvfs), M_TEMP,
    403      1.18      cube 	    M_WAITOK);
    404       1.1       mrg 	mp = nd.ni_vp->v_mount;
    405       1.1       mrg 	vrele(nd.ni_vp);
    406      1.18      cube 	if ((error = dostatvfs(mp, sbuf, p, SCARG(uap, flags), 1)) != 0)
    407      1.18      cube 		goto out;
    408      1.18      cube 	s32 = (struct netbsd32_statvfs *)
    409      1.18      cube 	    malloc(sizeof(struct netbsd32_statvfs), M_TEMP, M_WAITOK);
    410      1.18      cube 	netbsd32_from_statvfs(sbuf, s32);
    411      1.18      cube 	error = copyout(s32, (caddr_t)NETBSD32PTR64(SCARG(uap, buf)),
    412      1.18      cube 	    sizeof(struct netbsd32_statvfs));
    413      1.18      cube 	free(s32, M_TEMP);
    414      1.18      cube out:
    415      1.18      cube 	free(sbuf, M_TEMP);
    416      1.18      cube 	return (error);
    417       1.1       mrg }
    418       1.1       mrg 
    419       1.1       mrg int
    420      1.18      cube netbsd32_fstatvfs1(l, v, retval)
    421      1.11   thorpej 	struct lwp *l;
    422       1.1       mrg 	void *v;
    423       1.1       mrg 	register_t *retval;
    424       1.1       mrg {
    425      1.18      cube 	struct netbsd32_fstatvfs1_args /* {
    426       1.1       mrg 		syscallarg(int) fd;
    427      1.18      cube 		syscallarg(netbsd32_statvfsp_t) buf;
    428      1.18      cube 		syscallarg(int) flags;
    429       1.1       mrg 	} */ *uap = v;
    430      1.18      cube 	struct proc *p = l->l_proc;
    431       1.1       mrg 	struct file *fp;
    432       1.1       mrg 	struct mount *mp;
    433      1.18      cube 	struct statvfs *sbuf;
    434      1.18      cube 	struct netbsd32_statvfs *s32;
    435       1.1       mrg 	int error;
    436       1.1       mrg 
    437       1.1       mrg 	/* getvnode() will use the descriptor for us */
    438      1.14      fvdl 	if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
    439       1.1       mrg 		return (error);
    440       1.1       mrg 	mp = ((struct vnode *)fp->f_data)->v_mount;
    441      1.18      cube 	sbuf = (struct statvfs *)malloc(sizeof(struct statvfs), M_TEMP,
    442      1.18      cube 	    M_WAITOK);
    443      1.18      cube 	if ((error = dostatvfs(mp, sbuf, p, SCARG(uap, flags), 1)) != 0)
    444       1.1       mrg 		goto out;
    445      1.18      cube 	s32 = (struct netbsd32_statvfs *)
    446      1.18      cube 	    malloc(sizeof(struct netbsd32_statvfs), M_TEMP, M_WAITOK);
    447      1.18      cube 	netbsd32_from_statvfs(sbuf, s32);
    448      1.18      cube 	error = copyout(s32, (caddr_t)NETBSD32PTR64(SCARG(uap, buf)),
    449      1.18      cube 	    sizeof(struct netbsd32_statvfs));
    450      1.18      cube 	free(s32, M_TEMP);
    451       1.1       mrg  out:
    452      1.18      cube 	free(sbuf, M_TEMP);
    453      1.14      fvdl 	FILE_UNUSE(fp, p);
    454      1.18      cube 	return error;
    455      1.18      cube }
    456      1.18      cube 
    457      1.18      cube int
    458      1.18      cube netbsd32_getvfsstat(l, v, retval)
    459      1.18      cube 	struct lwp *l;
    460      1.18      cube 	void *v;
    461      1.18      cube 	register_t *retval;
    462      1.18      cube {
    463      1.18      cube 	struct netbsd32_getvfsstat_args /* {
    464      1.18      cube 		syscallarg(netbsd32_statvfsp_t) buf;
    465      1.18      cube 		syscallarg(netbsd32_size_t) bufsize;
    466      1.18      cube 		syscallarg(int) flags;
    467      1.18      cube 	} */ *uap = v;
    468      1.18      cube 	int root = 0;
    469      1.18      cube 	struct proc *p = l->l_proc;
    470      1.18      cube 	struct mount *mp, *nmp;
    471      1.18      cube 	struct statvfs *sbuf;
    472      1.18      cube 	struct netbsd32_statvfs *sfsp;
    473      1.18      cube 	struct netbsd32_statvfs *s32;
    474      1.18      cube 	size_t count, maxcount;
    475      1.18      cube 	int error = 0;
    476      1.18      cube 
    477      1.18      cube 	maxcount = SCARG(uap, bufsize) / sizeof(struct netbsd32_statvfs);
    478      1.18      cube 	sfsp = (struct netbsd32_statvfs *)NETBSD32PTR64(SCARG(uap, buf));
    479      1.18      cube 	simple_lock(&mountlist_slock);
    480      1.18      cube 	count = 0;
    481      1.18      cube 	sbuf = (struct statvfs *)malloc(sizeof(struct statvfs), M_TEMP,
    482      1.18      cube 	    M_WAITOK);
    483      1.18      cube 	s32 = (struct netbsd32_statvfs *)
    484      1.18      cube 	    malloc(sizeof(struct netbsd32_statvfs), M_TEMP, M_WAITOK);
    485      1.18      cube 	for (mp = CIRCLEQ_FIRST(&mountlist); mp != (void *)&mountlist;
    486      1.18      cube 	     mp = nmp) {
    487      1.18      cube 		if (vfs_busy(mp, LK_NOWAIT, &mountlist_slock)) {
    488      1.18      cube 			nmp = CIRCLEQ_NEXT(mp, mnt_list);
    489      1.18      cube 			continue;
    490      1.18      cube 		}
    491      1.18      cube 		if (sfsp && count < maxcount) {
    492      1.18      cube 			error = dostatvfs(mp, sbuf, p, SCARG(uap, flags), 0);
    493      1.18      cube 			if (error) {
    494      1.18      cube 				simple_lock(&mountlist_slock);
    495      1.18      cube 				nmp = CIRCLEQ_NEXT(mp, mnt_list);
    496      1.18      cube 				vfs_unbusy(mp);
    497      1.18      cube 				continue;
    498      1.18      cube 			}
    499      1.18      cube 			netbsd32_from_statvfs(sbuf, s32);
    500      1.18      cube 			error = copyout(s32, sfsp, sizeof(*sfsp));
    501      1.18      cube 			if (error) {
    502      1.18      cube 				vfs_unbusy(mp);
    503      1.18      cube 				goto out;
    504      1.18      cube 			}
    505      1.18      cube 			sfsp++;
    506      1.18      cube 			root |= strcmp(sbuf->f_mntonname, "/") == 0;
    507      1.18      cube 		}
    508      1.18      cube 		count++;
    509      1.18      cube 		simple_lock(&mountlist_slock);
    510      1.18      cube 		nmp = CIRCLEQ_NEXT(mp, mnt_list);
    511      1.18      cube 		vfs_unbusy(mp);
    512      1.18      cube 	}
    513      1.18      cube 	simple_unlock(&mountlist_slock);
    514      1.18      cube 	if (root == 0 && p->p_cwdi->cwdi_rdir) {
    515      1.18      cube 		/*
    516      1.18      cube 		 * fake a root entry
    517      1.18      cube 		 */
    518      1.18      cube 		if ((error = dostatvfs(p->p_cwdi->cwdi_rdir->v_mount, sbuf, p,
    519      1.18      cube 		    SCARG(uap, flags), 1)) != 0)
    520      1.18      cube 			goto out;
    521      1.18      cube 		if (sfsp) {
    522      1.18      cube 			netbsd32_from_statvfs(sbuf, s32);
    523      1.18      cube 			error = copyout(s32, sfsp, sizeof(*sfsp));
    524      1.18      cube 		}
    525      1.18      cube 		count++;
    526      1.18      cube 	}
    527      1.18      cube 	if (sfsp && count > maxcount)
    528      1.18      cube 		*retval = maxcount;
    529      1.18      cube 	else
    530      1.18      cube 		*retval = count;
    531      1.18      cube 
    532      1.18      cube out:
    533      1.18      cube 	free(s32, M_TEMP);
    534      1.18      cube 	free(sbuf, M_TEMP);
    535      1.18      cube 	return (error);
    536      1.18      cube }
    537      1.18      cube 
    538      1.18      cube int
    539      1.18      cube netbsd32_fhstatvfs1(l, v, retval)
    540      1.18      cube 	struct lwp *l;
    541      1.18      cube 	void *v;
    542      1.18      cube 	register_t *retval;
    543      1.18      cube {
    544      1.18      cube 	struct netbsd32_fhstatvfs1_args /* {
    545      1.18      cube 		syscallarg(const netbsd32_fhandlep_t) fhp;
    546      1.18      cube 		syscallarg(netbsd32_statvfsp_t) buf;
    547      1.18      cube 		syscallarg(int) flags;
    548      1.18      cube 	} */ *uap = v;
    549      1.18      cube 	struct proc *p = l->l_proc;
    550      1.18      cube 	struct statvfs *sbuf;
    551      1.18      cube 	struct netbsd32_statvfs *s32;
    552      1.18      cube 	fhandle_t fh;
    553      1.18      cube 	struct mount *mp;
    554      1.18      cube 	struct vnode *vp;
    555      1.18      cube 	int error;
    556      1.18      cube 
    557      1.18      cube 	/*
    558      1.18      cube 	 * Must be super user
    559      1.18      cube 	 */
    560      1.18      cube 	if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
    561      1.18      cube 		return error;
    562      1.18      cube 
    563      1.18      cube 	if ((error = copyin((caddr_t)NETBSD32PTR64(SCARG(uap, fhp)), &fh,
    564      1.18      cube 	    sizeof(fhandle_t))) != 0)
    565      1.18      cube 		return error;
    566      1.18      cube 
    567      1.18      cube 	if ((mp = vfs_getvfs(&fh.fh_fsid)) == NULL)
    568      1.18      cube 		return ESTALE;
    569      1.18      cube 	if ((error = VFS_FHTOVP(mp, &fh.fh_fid, &vp)))
    570      1.18      cube 		return error;
    571      1.18      cube 
    572      1.18      cube 	sbuf = (struct statvfs *)malloc(sizeof(struct statvfs), M_TEMP,
    573      1.18      cube 	    M_WAITOK);
    574      1.18      cube 	mp = vp->v_mount;
    575      1.18      cube 	if ((error = dostatvfs(mp, sbuf, p, SCARG(uap, flags), 1)) != 0) {
    576      1.18      cube 		vput(vp);
    577      1.18      cube 		goto out;
    578      1.18      cube 	}
    579      1.18      cube 	vput(vp);
    580      1.18      cube 
    581      1.18      cube 	s32 = (struct netbsd32_statvfs *)
    582      1.18      cube 	    malloc(sizeof(struct netbsd32_statvfs), M_TEMP, M_WAITOK);
    583      1.18      cube 	netbsd32_from_statvfs(sbuf, s32);
    584      1.18      cube 	error = copyout(s32, (caddr_t)NETBSD32PTR64(SCARG(uap, buf)),
    585      1.18      cube 	    sizeof(struct netbsd32_statvfs));
    586      1.18      cube 	free(s32, M_TEMP);
    587      1.18      cube 
    588      1.18      cube out:
    589      1.18      cube 	free(sbuf, M_TEMP);
    590       1.1       mrg 	return (error);
    591       1.1       mrg }
    592       1.1       mrg 
    593       1.1       mrg int
    594      1.11   thorpej netbsd32_futimes(l, v, retval)
    595      1.11   thorpej 	struct lwp *l;
    596       1.1       mrg 	void *v;
    597       1.1       mrg 	register_t *retval;
    598       1.1       mrg {
    599       1.1       mrg 	struct netbsd32_futimes_args /* {
    600       1.1       mrg 		syscallarg(int) fd;
    601       1.1       mrg 		syscallarg(const netbsd32_timevalp_t) tptr;
    602       1.1       mrg 	} */ *uap = v;
    603       1.1       mrg 	int error;
    604       1.1       mrg 	struct file *fp;
    605      1.14      fvdl 	struct proc *p = l->l_proc;
    606       1.1       mrg 
    607       1.1       mrg 	/* getvnode() will use the descriptor for us */
    608      1.14      fvdl 	if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
    609       1.1       mrg 		return (error);
    610       1.1       mrg 
    611  1.18.6.1      yamt 	error = change_utimes32((struct vnode *)fp->f_data,
    612      1.14      fvdl 				SCARG(uap, tptr), p);
    613      1.14      fvdl 	FILE_UNUSE(fp, p);
    614       1.1       mrg 	return (error);
    615       1.1       mrg }
    616       1.1       mrg 
    617       1.1       mrg int
    618      1.11   thorpej netbsd32_getdents(l, v, retval)
    619      1.11   thorpej 	struct lwp *l;
    620       1.1       mrg 	void *v;
    621       1.1       mrg 	register_t *retval;
    622       1.1       mrg {
    623       1.1       mrg 	struct netbsd32_getdents_args /* {
    624       1.1       mrg 		syscallarg(int) fd;
    625       1.1       mrg 		syscallarg(netbsd32_charp) buf;
    626       1.1       mrg 		syscallarg(netbsd32_size_t) count;
    627       1.1       mrg 	} */ *uap = v;
    628       1.1       mrg 	struct file *fp;
    629       1.1       mrg 	int error, done;
    630      1.11   thorpej 	struct proc *p = l->l_proc;
    631       1.1       mrg 
    632       1.1       mrg 	/* getvnode() will use the descriptor for us */
    633       1.1       mrg 	if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
    634       1.1       mrg 		return (error);
    635       1.1       mrg 	if ((fp->f_flag & FREAD) == 0) {
    636       1.1       mrg 		error = EBADF;
    637       1.1       mrg 		goto out;
    638       1.1       mrg 	}
    639      1.10       scw 	error = vn_readdir(fp, (caddr_t)NETBSD32PTR64(SCARG(uap, buf)),
    640      1.14      fvdl 	    UIO_USERSPACE, SCARG(uap, count), &done, p, 0, 0);
    641       1.1       mrg 	*retval = done;
    642       1.1       mrg  out:
    643      1.14      fvdl 	FILE_UNUSE(fp, p);
    644       1.1       mrg 	return (error);
    645       1.1       mrg }
    646       1.1       mrg 
    647       1.1       mrg int
    648      1.11   thorpej netbsd32_lutimes(l, v, retval)
    649      1.11   thorpej 	struct lwp *l;
    650       1.1       mrg 	void *v;
    651       1.1       mrg 	register_t *retval;
    652       1.1       mrg {
    653       1.1       mrg 	struct netbsd32_lutimes_args /* {
    654       1.1       mrg 		syscallarg(const netbsd32_charp) path;
    655       1.1       mrg 		syscallarg(const netbsd32_timevalp_t) tptr;
    656       1.1       mrg 	} */ *uap = v;
    657       1.1       mrg 	int error;
    658       1.1       mrg 	struct nameidata nd;
    659      1.14      fvdl 	struct proc *p = l->l_proc;
    660       1.1       mrg 
    661      1.10       scw 	NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE,
    662      1.14      fvdl 	    (caddr_t)NETBSD32PTR64(SCARG(uap, path)), p);
    663       1.1       mrg 	if ((error = namei(&nd)) != 0)
    664       1.1       mrg 		return (error);
    665       1.1       mrg 
    666      1.14      fvdl 	error = change_utimes32(nd.ni_vp, SCARG(uap, tptr), p);
    667       1.1       mrg 
    668       1.1       mrg 	vrele(nd.ni_vp);
    669       1.1       mrg 	return (error);
    670       1.1       mrg }
    671       1.1       mrg 
    672       1.1       mrg int
    673      1.11   thorpej netbsd32___stat13(l, v, retval)
    674      1.11   thorpej 	struct lwp *l;
    675       1.1       mrg 	void *v;
    676       1.1       mrg 	register_t *retval;
    677       1.1       mrg {
    678       1.1       mrg 	struct netbsd32___stat13_args /* {
    679       1.1       mrg 		syscallarg(const netbsd32_charp) path;
    680       1.1       mrg 		syscallarg(netbsd32_statp_t) ub;
    681       1.1       mrg 	} */ *uap = v;
    682       1.1       mrg 	struct netbsd32_stat sb32;
    683       1.1       mrg 	struct stat sb;
    684       1.1       mrg 	int error;
    685       1.1       mrg 	struct nameidata nd;
    686       1.1       mrg 	caddr_t sg;
    687       1.1       mrg 	const char *path;
    688      1.14      fvdl 	struct proc *p = l->l_proc;
    689       1.1       mrg 
    690      1.10       scw 	path = (char *)NETBSD32PTR64(SCARG(uap, path));
    691      1.14      fvdl 	sg = stackgap_init(p, 0);
    692      1.14      fvdl 	CHECK_ALT_EXIST(p, &sg, path);
    693       1.1       mrg 
    694      1.14      fvdl 	NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, path, p);
    695       1.1       mrg 	if ((error = namei(&nd)) != 0)
    696       1.1       mrg 		return (error);
    697      1.14      fvdl 	error = vn_stat(nd.ni_vp, &sb, p);
    698       1.1       mrg 	vput(nd.ni_vp);
    699       1.1       mrg 	if (error)
    700       1.1       mrg 		return (error);
    701       1.1       mrg 	netbsd32_from___stat13(&sb, &sb32);
    702      1.10       scw 	error = copyout(&sb32, (caddr_t)NETBSD32PTR64(SCARG(uap, ub)),
    703      1.10       scw 	    sizeof(sb32));
    704       1.1       mrg 	return (error);
    705       1.1       mrg }
    706       1.1       mrg 
    707       1.1       mrg int
    708      1.11   thorpej netbsd32___fstat13(l, v, retval)
    709      1.11   thorpej 	struct lwp *l;
    710       1.1       mrg 	void *v;
    711       1.1       mrg 	register_t *retval;
    712       1.1       mrg {
    713       1.1       mrg 	struct netbsd32___fstat13_args /* {
    714       1.1       mrg 		syscallarg(int) fd;
    715       1.1       mrg 		syscallarg(netbsd32_statp_t) sb;
    716       1.1       mrg 	} */ *uap = v;
    717       1.1       mrg 	int fd = SCARG(uap, fd);
    718      1.14      fvdl 	struct proc *p = l->l_proc;
    719      1.14      fvdl 	struct filedesc *fdp = p->p_fd;
    720       1.1       mrg 	struct file *fp;
    721       1.1       mrg 	struct netbsd32_stat sb32;
    722       1.1       mrg 	struct stat ub;
    723       1.1       mrg 	int error = 0;
    724       1.1       mrg 
    725       1.6   thorpej 	if ((fp = fd_getfile(fdp, fd)) == NULL)
    726       1.1       mrg 		return (EBADF);
    727       1.1       mrg 
    728       1.3  jdolecek 	FILE_USE(fp);
    729      1.14      fvdl 	error = (*fp->f_ops->fo_stat)(fp, &ub, p);
    730      1.14      fvdl 	FILE_UNUSE(fp, p);
    731       1.3  jdolecek 
    732       1.1       mrg 	if (error == 0) {
    733       1.1       mrg 		netbsd32_from___stat13(&ub, &sb32);
    734      1.10       scw 		error = copyout(&sb32, (caddr_t)NETBSD32PTR64(SCARG(uap, sb)),
    735      1.10       scw 		    sizeof(sb32));
    736       1.1       mrg 	}
    737       1.1       mrg 	return (error);
    738       1.1       mrg }
    739       1.1       mrg 
    740       1.1       mrg int
    741      1.11   thorpej netbsd32___lstat13(l, v, retval)
    742      1.11   thorpej 	struct lwp *l;
    743       1.1       mrg 	void *v;
    744       1.1       mrg 	register_t *retval;
    745       1.1       mrg {
    746       1.1       mrg 	struct netbsd32___lstat13_args /* {
    747       1.1       mrg 		syscallarg(const netbsd32_charp) path;
    748       1.1       mrg 		syscallarg(netbsd32_statp_t) ub;
    749       1.1       mrg 	} */ *uap = v;
    750       1.1       mrg 	struct netbsd32_stat sb32;
    751       1.1       mrg 	struct stat sb;
    752       1.1       mrg 	int error;
    753       1.1       mrg 	struct nameidata nd;
    754       1.1       mrg 	caddr_t sg;
    755       1.1       mrg 	const char *path;
    756      1.14      fvdl 	struct proc *p = l->l_proc;
    757       1.1       mrg 
    758      1.10       scw 	path = (char *)NETBSD32PTR64(SCARG(uap, path));
    759      1.14      fvdl 	sg = stackgap_init(p, 0);
    760      1.14      fvdl 	CHECK_ALT_EXIST(p, &sg, path);
    761       1.1       mrg 
    762      1.14      fvdl 	NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, path, p);
    763       1.1       mrg 	if ((error = namei(&nd)) != 0)
    764       1.1       mrg 		return (error);
    765      1.14      fvdl 	error = vn_stat(nd.ni_vp, &sb, p);
    766       1.1       mrg 	vput(nd.ni_vp);
    767       1.1       mrg 	if (error)
    768       1.1       mrg 		return (error);
    769       1.1       mrg 	netbsd32_from___stat13(&sb, &sb32);
    770      1.10       scw 	error = copyout(&sb32, (caddr_t)NETBSD32PTR64(SCARG(uap, ub)),
    771      1.10       scw 	    sizeof(sb32));
    772       1.1       mrg 	return (error);
    773       1.1       mrg }
    774       1.1       mrg 
    775       1.1       mrg int
    776      1.11   thorpej netbsd32_preadv(l, v, retval)
    777      1.11   thorpej 	struct lwp *l;
    778       1.1       mrg 	void *v;
    779       1.1       mrg 	register_t *retval;
    780       1.1       mrg {
    781       1.1       mrg 	struct netbsd32_preadv_args /* {
    782       1.1       mrg 		syscallarg(int) fd;
    783       1.1       mrg 		syscallarg(const netbsd32_iovecp_t) iovp;
    784       1.1       mrg 		syscallarg(int) iovcnt;
    785       1.1       mrg 		syscallarg(int) pad;
    786       1.1       mrg 		syscallarg(off_t) offset;
    787       1.1       mrg 	} */ *uap = v;
    788      1.14      fvdl 	struct proc *p = l->l_proc;
    789      1.14      fvdl 	struct filedesc *fdp = p->p_fd;
    790       1.1       mrg 	struct file *fp;
    791       1.1       mrg 	struct vnode *vp;
    792       1.1       mrg 	off_t offset;
    793       1.1       mrg 	int error, fd = SCARG(uap, fd);
    794       1.1       mrg 
    795       1.6   thorpej 	if ((fp = fd_getfile(fdp, fd)) == NULL)
    796       1.6   thorpej 		return (EBADF);
    797       1.6   thorpej 
    798       1.6   thorpej 	if ((fp->f_flag & FREAD) == 0)
    799       1.1       mrg 		return (EBADF);
    800       1.1       mrg 
    801       1.9  jdolecek 	FILE_USE(fp);
    802       1.9  jdolecek 
    803       1.1       mrg 	vp = (struct vnode *)fp->f_data;
    804       1.9  jdolecek 	if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO) {
    805       1.9  jdolecek 		error = ESPIPE;
    806       1.9  jdolecek 		goto out;
    807       1.9  jdolecek 	}
    808       1.1       mrg 
    809       1.1       mrg 	offset = SCARG(uap, offset);
    810       1.1       mrg 
    811       1.1       mrg 	/*
    812       1.1       mrg 	 * XXX This works because no file systems actually
    813       1.1       mrg 	 * XXX take any action on the seek operation.
    814       1.1       mrg 	 */
    815       1.1       mrg 	if ((error = VOP_SEEK(vp, fp->f_offset, offset, fp->f_cred)) != 0)
    816       1.9  jdolecek 		goto out;
    817       1.1       mrg 
    818      1.14      fvdl 	return (dofilereadv32(p, fd, fp,
    819      1.10       scw 	    (struct netbsd32_iovec *)NETBSD32PTR64(SCARG(uap, iovp)),
    820      1.10       scw 	    SCARG(uap, iovcnt), &offset, 0, retval));
    821       1.9  jdolecek 
    822       1.9  jdolecek out:
    823      1.14      fvdl 	FILE_UNUSE(fp, p);
    824       1.9  jdolecek 	return (error);
    825       1.1       mrg }
    826       1.1       mrg 
    827       1.1       mrg int
    828      1.11   thorpej netbsd32_pwritev(l, v, retval)
    829      1.11   thorpej 	struct lwp *l;
    830       1.1       mrg 	void *v;
    831       1.1       mrg 	register_t *retval;
    832       1.1       mrg {
    833       1.1       mrg 	struct netbsd32_pwritev_args /* {
    834       1.1       mrg 		syscallarg(int) fd;
    835       1.1       mrg 		syscallarg(const netbsd32_iovecp_t) iovp;
    836       1.1       mrg 		syscallarg(int) iovcnt;
    837       1.1       mrg 		syscallarg(int) pad;
    838       1.1       mrg 		syscallarg(off_t) offset;
    839       1.1       mrg 	} */ *uap = v;
    840      1.14      fvdl 	struct proc *p = l->l_proc;
    841      1.14      fvdl 	struct filedesc *fdp = p->p_fd;
    842       1.1       mrg 	struct file *fp;
    843       1.1       mrg 	struct vnode *vp;
    844       1.1       mrg 	off_t offset;
    845       1.1       mrg 	int error, fd = SCARG(uap, fd);
    846       1.1       mrg 
    847       1.6   thorpej 	if ((fp = fd_getfile(fdp, fd)) == NULL)
    848       1.6   thorpej 		return (EBADF);
    849       1.6   thorpej 
    850       1.6   thorpej 	if ((fp->f_flag & FWRITE) == 0)
    851       1.1       mrg 		return (EBADF);
    852       1.1       mrg 
    853       1.9  jdolecek 	FILE_USE(fp);
    854       1.9  jdolecek 
    855       1.1       mrg 	vp = (struct vnode *)fp->f_data;
    856       1.9  jdolecek 	if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO) {
    857       1.9  jdolecek 		error = ESPIPE;
    858       1.9  jdolecek 		goto out;
    859       1.9  jdolecek 	}
    860       1.1       mrg 
    861       1.1       mrg 	offset = SCARG(uap, offset);
    862       1.1       mrg 
    863       1.1       mrg 	/*
    864       1.1       mrg 	 * XXX This works because no file systems actually
    865       1.1       mrg 	 * XXX take any action on the seek operation.
    866       1.1       mrg 	 */
    867       1.1       mrg 	if ((error = VOP_SEEK(vp, fp->f_offset, offset, fp->f_cred)) != 0)
    868       1.9  jdolecek 		goto out;
    869       1.1       mrg 
    870      1.14      fvdl 	return (dofilewritev32(p, fd, fp,
    871      1.10       scw 	    (struct netbsd32_iovec *)NETBSD32PTR64(SCARG(uap, iovp)),
    872      1.10       scw 	    SCARG(uap, iovcnt), &offset, 0, retval));
    873       1.9  jdolecek 
    874       1.9  jdolecek out:
    875      1.14      fvdl 	FILE_UNUSE(fp, p);
    876       1.9  jdolecek 	return (error);
    877       1.1       mrg }
    878       1.1       mrg 
    879       1.1       mrg /*
    880       1.1       mrg  * Find pathname of process's current directory.
    881       1.1       mrg  *
    882       1.1       mrg  * Use vfs vnode-to-name reverse cache; if that fails, fall back
    883       1.1       mrg  * to reading directory contents.
    884       1.1       mrg  */
    885      1.14      fvdl int
    886      1.14      fvdl getcwd_common __P((struct vnode *, struct vnode *,
    887      1.14      fvdl 		   char **, char *, int, int, struct proc *));
    888      1.14      fvdl 
    889  1.18.6.1      yamt int netbsd32___getcwd(l, v, retval)
    890      1.11   thorpej 	struct lwp *l;
    891       1.1       mrg 	void   *v;
    892       1.1       mrg 	register_t *retval;
    893       1.1       mrg {
    894       1.1       mrg 	struct netbsd32___getcwd_args /* {
    895       1.1       mrg 		syscallarg(char *) bufp;
    896       1.1       mrg 		syscallarg(size_t) length;
    897       1.1       mrg 	} */ *uap = v;
    898      1.11   thorpej 	struct proc *p = l->l_proc;
    899       1.1       mrg 	int     error;
    900       1.1       mrg 	char   *path;
    901       1.1       mrg 	char   *bp, *bend;
    902       1.1       mrg 	int     len = (int)SCARG(uap, length);
    903       1.1       mrg 	int	lenused;
    904       1.1       mrg 
    905       1.1       mrg 	if (len > MAXPATHLEN*4)
    906       1.1       mrg 		len = MAXPATHLEN*4;
    907       1.1       mrg 	else if (len < 2)
    908       1.1       mrg 		return ERANGE;
    909       1.1       mrg 
    910       1.1       mrg 	path = (char *)malloc(len, M_TEMP, M_WAITOK);
    911       1.1       mrg 	if (!path)
    912       1.1       mrg 		return ENOMEM;
    913       1.1       mrg 
    914       1.1       mrg 	bp = &path[len];
    915       1.1       mrg 	bend = bp;
    916       1.1       mrg 	*(--bp) = '\0';
    917       1.1       mrg 
    918       1.1       mrg 	/*
    919       1.1       mrg 	 * 5th argument here is "max number of vnodes to traverse".
    920       1.1       mrg 	 * Since each entry takes up at least 2 bytes in the output buffer,
    921       1.1       mrg 	 * limit it to N/2 vnodes for an N byte buffer.
    922       1.1       mrg 	 */
    923       1.1       mrg #define GETCWD_CHECK_ACCESS 0x0001
    924       1.1       mrg 	error = getcwd_common (p->p_cwdi->cwdi_cdir, NULL, &bp, path, len/2,
    925      1.14      fvdl 			       GETCWD_CHECK_ACCESS, p);
    926       1.1       mrg 
    927       1.1       mrg 	if (error)
    928       1.1       mrg 		goto out;
    929       1.1       mrg 	lenused = bend - bp;
    930       1.1       mrg 	*retval = lenused;
    931       1.1       mrg 	/* put the result into user buffer */
    932      1.10       scw 	error = copyout(bp, (caddr_t)NETBSD32PTR64(SCARG(uap, bufp)), lenused);
    933       1.1       mrg 
    934       1.1       mrg out:
    935       1.1       mrg 	free(path, M_TEMP);
    936       1.1       mrg 	return error;
    937       1.1       mrg }
    938