Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_fs.c revision 1.39
      1  1.39       dsl /*	$NetBSD: netbsd32_fs.c,v 1.39 2007/03/18 21:38:33 dsl 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.39       dsl __KERNEL_RCSID(0, "$NetBSD: netbsd32_fs.c,v 1.39 2007/03/18 21:38:33 dsl 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.18      cube #include <sys/statvfs.h>
     53   1.1       mrg #include <sys/syscallargs.h>
     54   1.1       mrg #include <sys/proc.h>
     55  1.22  christos #include <sys/dirent.h>
     56  1.27      elad #include <sys/kauth.h>
     57  1.37       dsl #include <sys/vfs_syscalls.h>
     58   1.1       mrg 
     59   1.1       mrg #include <compat/netbsd32/netbsd32.h>
     60   1.1       mrg #include <compat/netbsd32/netbsd32_syscallargs.h>
     61   1.1       mrg #include <compat/netbsd32/netbsd32_conv.h>
     62  1.28    martin #include <compat/sys/mount.h>
     63   1.1       mrg 
     64   1.1       mrg 
     65  1.23  christos static int dofilereadv32 __P((struct lwp *, int, struct file *, struct netbsd32_iovec *,
     66   1.1       mrg 			      int, off_t *, int, register_t *));
     67  1.23  christos static int dofilewritev32 __P((struct lwp *, int, struct file *, struct netbsd32_iovec *,
     68   1.1       mrg 			       int,  off_t *, int, register_t *));
     69  1.23  christos static int change_utimes32 __P((struct vnode *, netbsd32_timevalp_t, struct lwp *));
     70   1.1       mrg 
     71   1.1       mrg int
     72  1.11   thorpej netbsd32_readv(l, v, retval)
     73  1.11   thorpej 	struct lwp *l;
     74   1.1       mrg 	void *v;
     75   1.1       mrg 	register_t *retval;
     76   1.1       mrg {
     77   1.1       mrg 	struct netbsd32_readv_args /* {
     78   1.1       mrg 		syscallarg(int) fd;
     79   1.1       mrg 		syscallarg(const netbsd32_iovecp_t) iovp;
     80   1.1       mrg 		syscallarg(int) iovcnt;
     81   1.1       mrg 	} */ *uap = v;
     82   1.1       mrg 	int fd = SCARG(uap, fd);
     83  1.11   thorpej 	struct proc *p = l->l_proc;
     84   1.1       mrg 	struct file *fp;
     85   1.1       mrg 	struct filedesc *fdp = p->p_fd;
     86   1.1       mrg 
     87   1.6   thorpej 	if ((fp = fd_getfile(fdp, fd)) == NULL)
     88   1.6   thorpej 		return (EBADF);
     89   1.6   thorpej 
     90   1.6   thorpej 	if ((fp->f_flag & FREAD) == 0)
     91   1.1       mrg 		return (EBADF);
     92   1.1       mrg 
     93   1.9  jdolecek 	FILE_USE(fp);
     94   1.9  jdolecek 
     95  1.23  christos 	return (dofilereadv32(l, fd, fp,
     96  1.39       dsl 	    (struct netbsd32_iovec *)SCARG_P32(uap, iovp),
     97  1.10       scw 	    SCARG(uap, iovcnt), &fp->f_offset, FOF_UPDATE_OFFSET, retval));
     98   1.1       mrg }
     99   1.1       mrg 
    100   1.1       mrg /* Damn thing copies in the iovec! */
    101   1.1       mrg int
    102  1.23  christos dofilereadv32(l, fd, fp, iovp, iovcnt, offset, flags, retval)
    103  1.23  christos 	struct lwp *l;
    104   1.1       mrg 	int fd;
    105   1.1       mrg 	struct file *fp;
    106   1.1       mrg 	struct netbsd32_iovec *iovp;
    107   1.1       mrg 	int iovcnt;
    108   1.1       mrg 	off_t *offset;
    109   1.1       mrg 	int flags;
    110   1.1       mrg 	register_t *retval;
    111   1.1       mrg {
    112   1.1       mrg 	struct uio auio;
    113   1.1       mrg 	struct iovec *iov;
    114   1.1       mrg 	struct iovec *needfree;
    115   1.1       mrg 	struct iovec aiov[UIO_SMALLIOV];
    116   1.1       mrg 	long i, cnt, error = 0;
    117   1.1       mrg 	u_int iovlen;
    118   1.1       mrg #ifdef KTRACE
    119   1.1       mrg 	struct iovec *ktriov = NULL;
    120   1.1       mrg #endif
    121   1.1       mrg 
    122   1.1       mrg 	/* note: can't use iovlen until iovcnt is validated */
    123   1.1       mrg 	iovlen = iovcnt * sizeof(struct iovec);
    124   1.1       mrg 	if ((u_int)iovcnt > UIO_SMALLIOV) {
    125   1.9  jdolecek 		if ((u_int)iovcnt > IOV_MAX) {
    126   1.9  jdolecek 			error = EINVAL;
    127   1.9  jdolecek 			goto out;
    128   1.9  jdolecek 		}
    129   1.9  jdolecek 		iov = malloc(iovlen, M_IOV, M_WAITOK);
    130   1.1       mrg 		needfree = iov;
    131   1.1       mrg 	} else if ((u_int)iovcnt > 0) {
    132   1.1       mrg 		iov = aiov;
    133   1.1       mrg 		needfree = NULL;
    134   1.9  jdolecek 	} else {
    135   1.9  jdolecek 		error = EINVAL;
    136   1.9  jdolecek 		goto out;
    137   1.9  jdolecek 	}
    138   1.1       mrg 
    139   1.1       mrg 	auio.uio_iov = iov;
    140   1.1       mrg 	auio.uio_iovcnt = iovcnt;
    141   1.1       mrg 	auio.uio_rw = UIO_READ;
    142  1.24      yamt 	auio.uio_vmspace = l->l_proc->p_vmspace;
    143   1.1       mrg 	error = netbsd32_to_iovecin(iovp, iov, iovcnt);
    144   1.1       mrg 	if (error)
    145   1.1       mrg 		goto done;
    146   1.1       mrg 	auio.uio_resid = 0;
    147   1.1       mrg 	for (i = 0; i < iovcnt; i++) {
    148   1.1       mrg 		auio.uio_resid += iov->iov_len;
    149   1.1       mrg 		/*
    150   1.1       mrg 		 * Reads return ssize_t because -1 is returned on error.
    151   1.1       mrg 		 * Therefore we must restrict the length to SSIZE_MAX to
    152   1.1       mrg 		 * avoid garbage return values.
    153   1.1       mrg 		 */
    154   1.1       mrg 		if (iov->iov_len > SSIZE_MAX || auio.uio_resid > SSIZE_MAX) {
    155   1.1       mrg 			error = EINVAL;
    156   1.1       mrg 			goto done;
    157   1.1       mrg 		}
    158   1.1       mrg 		iov++;
    159   1.1       mrg 	}
    160   1.1       mrg #ifdef KTRACE
    161   1.1       mrg 	/*
    162   1.1       mrg 	 * if tracing, save a copy of iovec
    163   1.1       mrg 	 */
    164  1.23  christos 	if (KTRPOINT(l->l_proc, KTR_GENIO))  {
    165   1.9  jdolecek 		ktriov = malloc(iovlen, M_TEMP, M_WAITOK);
    166  1.36  christos 		memcpy((void *)ktriov, (void *)auio.uio_iov, iovlen);
    167   1.1       mrg 	}
    168   1.1       mrg #endif
    169   1.1       mrg 	cnt = auio.uio_resid;
    170   1.1       mrg 	error = (*fp->f_ops->fo_read)(fp, offset, &auio, fp->f_cred, flags);
    171   1.1       mrg 	if (error)
    172   1.1       mrg 		if (auio.uio_resid != cnt && (error == ERESTART ||
    173   1.1       mrg 		    error == EINTR || error == EWOULDBLOCK))
    174   1.1       mrg 			error = 0;
    175   1.1       mrg 	cnt -= auio.uio_resid;
    176   1.1       mrg #ifdef KTRACE
    177  1.23  christos 	if (KTRPOINT(l->l_proc, KTR_GENIO))
    178   1.1       mrg 		if (error == 0) {
    179  1.23  christos 			ktrgenio(l, fd, UIO_READ, ktriov, cnt,
    180   1.1       mrg 			    error);
    181   1.9  jdolecek 		free(ktriov, M_TEMP);
    182   1.1       mrg 	}
    183   1.1       mrg #endif
    184   1.1       mrg 	*retval = cnt;
    185   1.1       mrg done:
    186   1.1       mrg 	if (needfree)
    187   1.9  jdolecek 		free(needfree, M_IOV);
    188   1.9  jdolecek out:
    189  1.23  christos 	FILE_UNUSE(fp, l);
    190   1.1       mrg 	return (error);
    191   1.1       mrg }
    192   1.1       mrg 
    193   1.1       mrg int
    194  1.11   thorpej netbsd32_writev(l, v, retval)
    195  1.11   thorpej 	struct lwp *l;
    196   1.1       mrg 	void *v;
    197   1.1       mrg 	register_t *retval;
    198   1.1       mrg {
    199   1.1       mrg 	struct netbsd32_writev_args /* {
    200   1.1       mrg 		syscallarg(int) fd;
    201   1.1       mrg 		syscallarg(const netbsd32_iovecp_t) iovp;
    202   1.1       mrg 		syscallarg(int) iovcnt;
    203   1.1       mrg 	} */ *uap = v;
    204   1.1       mrg 	int fd = SCARG(uap, fd);
    205   1.1       mrg 	struct file *fp;
    206  1.11   thorpej 	struct proc *p = l->l_proc;
    207   1.1       mrg 	struct filedesc *fdp = p->p_fd;
    208   1.1       mrg 
    209   1.6   thorpej 	if ((fp = fd_getfile(fdp, fd)) == NULL)
    210   1.6   thorpej 		return (EBADF);
    211   1.6   thorpej 
    212   1.6   thorpej 	if ((fp->f_flag & FWRITE) == 0)
    213   1.1       mrg 		return (EBADF);
    214   1.1       mrg 
    215   1.9  jdolecek 	FILE_USE(fp);
    216   1.9  jdolecek 
    217  1.23  christos 	return (dofilewritev32(l, fd, fp,
    218  1.39       dsl 	    (struct netbsd32_iovec *)SCARG_P32(uap, iovp),
    219  1.10       scw 	    SCARG(uap, iovcnt), &fp->f_offset, FOF_UPDATE_OFFSET, retval));
    220   1.1       mrg }
    221   1.1       mrg 
    222   1.1       mrg int
    223  1.23  christos dofilewritev32(l, fd, fp, iovp, iovcnt, offset, flags, retval)
    224  1.23  christos 	struct lwp *l;
    225   1.1       mrg 	int fd;
    226   1.1       mrg 	struct file *fp;
    227   1.1       mrg 	struct netbsd32_iovec *iovp;
    228   1.1       mrg 	int iovcnt;
    229   1.1       mrg 	off_t *offset;
    230   1.1       mrg 	int flags;
    231   1.1       mrg 	register_t *retval;
    232   1.1       mrg {
    233   1.1       mrg 	struct uio auio;
    234   1.1       mrg 	struct iovec *iov;
    235   1.1       mrg 	struct iovec *needfree;
    236   1.1       mrg 	struct iovec aiov[UIO_SMALLIOV];
    237  1.23  christos 	struct proc *p = l->l_proc;
    238   1.1       mrg 	long i, cnt, error = 0;
    239   1.1       mrg 	u_int iovlen;
    240   1.1       mrg #ifdef KTRACE
    241   1.1       mrg 	struct iovec *ktriov = NULL;
    242   1.1       mrg #endif
    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.24      yamt 	auio.uio_vmspace = l->l_proc->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.1       mrg #ifdef KTRACE
    283   1.1       mrg 	/*
    284   1.1       mrg 	 * if tracing, save a copy of iovec
    285   1.1       mrg 	 */
    286  1.14      fvdl 	if (KTRPOINT(p, 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.1       mrg #endif
    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.1       mrg 		if (error == EPIPE)
    298  1.14      fvdl 			psignal(p, SIGPIPE);
    299   1.1       mrg 	}
    300   1.1       mrg 	cnt -= auio.uio_resid;
    301   1.1       mrg #ifdef KTRACE
    302  1.14      fvdl 	if (KTRPOINT(p, KTR_GENIO))
    303   1.1       mrg 		if (error == 0) {
    304  1.23  christos 			ktrgenio(l, fd, UIO_WRITE, ktriov, cnt,
    305   1.1       mrg 			    error);
    306   1.9  jdolecek 		free(ktriov, M_TEMP);
    307   1.1       mrg 	}
    308   1.1       mrg #endif
    309   1.1       mrg 	*retval = cnt;
    310   1.1       mrg done:
    311   1.1       mrg 	if (needfree)
    312   1.9  jdolecek 		free(needfree, M_IOV);
    313   1.9  jdolecek out:
    314  1.23  christos 	FILE_UNUSE(fp, l);
    315   1.1       mrg 	return (error);
    316   1.1       mrg }
    317   1.1       mrg 
    318   1.1       mrg int
    319  1.11   thorpej netbsd32_utimes(l, v, retval)
    320  1.11   thorpej 	struct lwp *l;
    321   1.1       mrg 	void *v;
    322   1.1       mrg 	register_t *retval;
    323   1.1       mrg {
    324   1.1       mrg 	struct netbsd32_utimes_args /* {
    325   1.1       mrg 		syscallarg(const netbsd32_charp) path;
    326   1.1       mrg 		syscallarg(const netbsd32_timevalp_t) tptr;
    327   1.1       mrg 	} */ *uap = v;
    328   1.1       mrg 	int error;
    329   1.1       mrg 	struct nameidata nd;
    330   1.1       mrg 
    331  1.39       dsl 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG_P32(uap, path), l);
    332   1.1       mrg 	if ((error = namei(&nd)) != 0)
    333   1.1       mrg 		return (error);
    334   1.1       mrg 
    335  1.23  christos 	error = change_utimes32(nd.ni_vp, SCARG(uap, tptr), l);
    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.23  christos change_utimes32(vp, tptr, l)
    346   1.1       mrg 	struct vnode *vp;
    347   1.1       mrg 	netbsd32_timevalp_t tptr;
    348  1.23  christos 	struct lwp *l;
    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.38       dsl 	if (NETBSD32PTR64(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.38       dsl 		error = copyin(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.31        ad 	VOP_LEASE(vp, l, l->l_cred, 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.31        ad 	error = VOP_SETATTR(vp, &vattr, l->l_cred, l);
    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.1       mrg 	struct mount *mp;
    391  1.18      cube 	struct statvfs *sbuf;
    392  1.18      cube 	struct netbsd32_statvfs *s32;
    393  1.18      cube 	struct nameidata nd;
    394   1.1       mrg 	int error;
    395   1.1       mrg 
    396  1.39       dsl 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG_P32(uap, path), l);
    397   1.1       mrg 	if ((error = namei(&nd)) != 0)
    398   1.1       mrg 		return (error);
    399  1.18      cube 	/* Allocating on the stack would blow it up */
    400  1.18      cube 	sbuf = (struct statvfs *)malloc(sizeof(struct statvfs), M_TEMP,
    401  1.18      cube 	    M_WAITOK);
    402   1.1       mrg 	mp = nd.ni_vp->v_mount;
    403   1.1       mrg 	vrele(nd.ni_vp);
    404  1.23  christos 	if ((error = dostatvfs(mp, sbuf, l, SCARG(uap, flags), 1)) != 0)
    405  1.18      cube 		goto out;
    406  1.18      cube 	s32 = (struct netbsd32_statvfs *)
    407  1.18      cube 	    malloc(sizeof(struct netbsd32_statvfs), M_TEMP, M_WAITOK);
    408  1.18      cube 	netbsd32_from_statvfs(sbuf, s32);
    409  1.39       dsl 	error = copyout(s32, SCARG_P32(uap, buf),
    410  1.18      cube 	    sizeof(struct netbsd32_statvfs));
    411  1.18      cube 	free(s32, M_TEMP);
    412  1.18      cube out:
    413  1.18      cube 	free(sbuf, M_TEMP);
    414  1.18      cube 	return (error);
    415   1.1       mrg }
    416   1.1       mrg 
    417   1.1       mrg int
    418  1.18      cube netbsd32_fstatvfs1(l, v, retval)
    419  1.11   thorpej 	struct lwp *l;
    420   1.1       mrg 	void *v;
    421   1.1       mrg 	register_t *retval;
    422   1.1       mrg {
    423  1.18      cube 	struct netbsd32_fstatvfs1_args /* {
    424   1.1       mrg 		syscallarg(int) fd;
    425  1.18      cube 		syscallarg(netbsd32_statvfsp_t) buf;
    426  1.18      cube 		syscallarg(int) flags;
    427   1.1       mrg 	} */ *uap = v;
    428  1.18      cube 	struct proc *p = l->l_proc;
    429   1.1       mrg 	struct file *fp;
    430   1.1       mrg 	struct mount *mp;
    431  1.18      cube 	struct statvfs *sbuf;
    432  1.18      cube 	struct netbsd32_statvfs *s32;
    433   1.1       mrg 	int error;
    434   1.1       mrg 
    435   1.1       mrg 	/* getvnode() will use the descriptor for us */
    436  1.14      fvdl 	if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
    437   1.1       mrg 		return (error);
    438   1.1       mrg 	mp = ((struct vnode *)fp->f_data)->v_mount;
    439  1.18      cube 	sbuf = (struct statvfs *)malloc(sizeof(struct statvfs), M_TEMP,
    440  1.18      cube 	    M_WAITOK);
    441  1.23  christos 	if ((error = dostatvfs(mp, sbuf, l, SCARG(uap, flags), 1)) != 0)
    442   1.1       mrg 		goto out;
    443  1.18      cube 	s32 = (struct netbsd32_statvfs *)
    444  1.18      cube 	    malloc(sizeof(struct netbsd32_statvfs), M_TEMP, M_WAITOK);
    445  1.18      cube 	netbsd32_from_statvfs(sbuf, s32);
    446  1.39       dsl 	error = copyout(s32, SCARG_P32(uap, buf),
    447  1.18      cube 	    sizeof(struct netbsd32_statvfs));
    448  1.18      cube 	free(s32, M_TEMP);
    449   1.1       mrg  out:
    450  1.18      cube 	free(sbuf, M_TEMP);
    451  1.23  christos 	FILE_UNUSE(fp, l);
    452  1.18      cube 	return error;
    453  1.18      cube }
    454  1.18      cube 
    455  1.18      cube int
    456  1.18      cube netbsd32_getvfsstat(l, v, retval)
    457  1.18      cube 	struct lwp *l;
    458  1.18      cube 	void *v;
    459  1.18      cube 	register_t *retval;
    460  1.18      cube {
    461  1.18      cube 	struct netbsd32_getvfsstat_args /* {
    462  1.18      cube 		syscallarg(netbsd32_statvfsp_t) buf;
    463  1.18      cube 		syscallarg(netbsd32_size_t) bufsize;
    464  1.18      cube 		syscallarg(int) flags;
    465  1.18      cube 	} */ *uap = v;
    466  1.18      cube 	int root = 0;
    467  1.18      cube 	struct proc *p = l->l_proc;
    468  1.18      cube 	struct mount *mp, *nmp;
    469  1.18      cube 	struct statvfs *sbuf;
    470  1.18      cube 	struct netbsd32_statvfs *sfsp;
    471  1.18      cube 	struct netbsd32_statvfs *s32;
    472  1.18      cube 	size_t count, maxcount;
    473  1.18      cube 	int error = 0;
    474  1.18      cube 
    475  1.18      cube 	maxcount = SCARG(uap, bufsize) / sizeof(struct netbsd32_statvfs);
    476  1.39       dsl 	sfsp = SCARG_P32(uap, buf);
    477  1.18      cube 	sbuf = (struct statvfs *)malloc(sizeof(struct statvfs), M_TEMP,
    478  1.18      cube 	    M_WAITOK);
    479  1.18      cube 	s32 = (struct netbsd32_statvfs *)
    480  1.18      cube 	    malloc(sizeof(struct netbsd32_statvfs), M_TEMP, M_WAITOK);
    481  1.25      cube 	simple_lock(&mountlist_slock);
    482  1.25      cube 	count = 0;
    483  1.18      cube 	for (mp = CIRCLEQ_FIRST(&mountlist); mp != (void *)&mountlist;
    484  1.18      cube 	     mp = nmp) {
    485  1.18      cube 		if (vfs_busy(mp, LK_NOWAIT, &mountlist_slock)) {
    486  1.18      cube 			nmp = CIRCLEQ_NEXT(mp, mnt_list);
    487  1.18      cube 			continue;
    488  1.18      cube 		}
    489  1.18      cube 		if (sfsp && count < maxcount) {
    490  1.23  christos 			error = dostatvfs(mp, sbuf, l, SCARG(uap, flags), 0);
    491  1.18      cube 			if (error) {
    492  1.18      cube 				simple_lock(&mountlist_slock);
    493  1.18      cube 				nmp = CIRCLEQ_NEXT(mp, mnt_list);
    494  1.18      cube 				vfs_unbusy(mp);
    495  1.18      cube 				continue;
    496  1.18      cube 			}
    497  1.18      cube 			netbsd32_from_statvfs(sbuf, s32);
    498  1.18      cube 			error = copyout(s32, sfsp, sizeof(*sfsp));
    499  1.18      cube 			if (error) {
    500  1.18      cube 				vfs_unbusy(mp);
    501  1.18      cube 				goto out;
    502  1.18      cube 			}
    503  1.18      cube 			sfsp++;
    504  1.18      cube 			root |= strcmp(sbuf->f_mntonname, "/") == 0;
    505  1.18      cube 		}
    506  1.18      cube 		count++;
    507  1.18      cube 		simple_lock(&mountlist_slock);
    508  1.18      cube 		nmp = CIRCLEQ_NEXT(mp, mnt_list);
    509  1.18      cube 		vfs_unbusy(mp);
    510  1.18      cube 	}
    511  1.18      cube 	simple_unlock(&mountlist_slock);
    512  1.18      cube 	if (root == 0 && p->p_cwdi->cwdi_rdir) {
    513  1.18      cube 		/*
    514  1.18      cube 		 * fake a root entry
    515  1.18      cube 		 */
    516  1.23  christos 		if ((error = dostatvfs(p->p_cwdi->cwdi_rdir->v_mount, sbuf, l,
    517  1.18      cube 		    SCARG(uap, flags), 1)) != 0)
    518  1.18      cube 			goto out;
    519  1.18      cube 		if (sfsp) {
    520  1.18      cube 			netbsd32_from_statvfs(sbuf, s32);
    521  1.18      cube 			error = copyout(s32, sfsp, sizeof(*sfsp));
    522  1.18      cube 		}
    523  1.18      cube 		count++;
    524  1.18      cube 	}
    525  1.18      cube 	if (sfsp && count > maxcount)
    526  1.18      cube 		*retval = maxcount;
    527  1.18      cube 	else
    528  1.18      cube 		*retval = count;
    529  1.18      cube 
    530  1.18      cube out:
    531  1.18      cube 	free(s32, M_TEMP);
    532  1.18      cube 	free(sbuf, M_TEMP);
    533  1.18      cube 	return (error);
    534  1.18      cube }
    535  1.18      cube 
    536  1.18      cube int
    537  1.32    martin netbsd32___fhstatvfs140(l, v, retval)
    538  1.18      cube 	struct lwp *l;
    539  1.18      cube 	void *v;
    540  1.18      cube 	register_t *retval;
    541  1.18      cube {
    542  1.32    martin 	struct netbsd32___fhstatvfs140_args /* {
    543  1.32    martin 		syscallarg(const netbsd32_pointer_t) fhp;
    544  1.32    martin 		syscallarg(netbsd32_size_t) fh_size;
    545  1.18      cube 		syscallarg(netbsd32_statvfsp_t) buf;
    546  1.18      cube 		syscallarg(int) flags;
    547  1.18      cube 	} */ *uap = v;
    548  1.18      cube 	struct statvfs *sbuf;
    549  1.18      cube 	struct netbsd32_statvfs *s32;
    550  1.29    martin 	fhandle_t *fh;
    551  1.18      cube 	struct vnode *vp;
    552  1.18      cube 	int error;
    553  1.18      cube 
    554  1.18      cube 	/*
    555  1.18      cube 	 * Must be super user
    556  1.18      cube 	 */
    557  1.34      elad 	if ((error = kauth_authorize_system(l->l_cred,
    558  1.34      elad 	    KAUTH_SYSTEM_FILEHANDLE, 0, NULL, NULL, NULL)) != 0)
    559  1.18      cube 		return error;
    560  1.18      cube 
    561  1.39       dsl 	if ((error = vfs_copyinfh_alloc(SCARG_P32(uap, fhp),
    562  1.32    martin 	    SCARG(uap, fh_size), &fh)) != 0)
    563  1.29    martin 		goto bad;
    564  1.29    martin 	if ((error = vfs_fhtovp(fh, &vp)) != 0)
    565  1.29    martin 		goto bad;
    566  1.18      cube 
    567  1.18      cube 	sbuf = (struct statvfs *)malloc(sizeof(struct statvfs), M_TEMP,
    568  1.18      cube 	    M_WAITOK);
    569  1.29    martin 	error = dostatvfs(vp->v_mount, sbuf, l, SCARG(uap, flags), 1);
    570  1.29    martin 	vput(vp);
    571  1.29    martin 	if (error != 0)
    572  1.18      cube 		goto out;
    573  1.18      cube 
    574  1.18      cube 	s32 = (struct netbsd32_statvfs *)
    575  1.18      cube 	    malloc(sizeof(struct netbsd32_statvfs), M_TEMP, M_WAITOK);
    576  1.18      cube 	netbsd32_from_statvfs(sbuf, s32);
    577  1.39       dsl 	error = copyout(s32, SCARG_P32(uap, buf),
    578  1.18      cube 	    sizeof(struct netbsd32_statvfs));
    579  1.18      cube 	free(s32, M_TEMP);
    580  1.18      cube 
    581  1.18      cube out:
    582  1.18      cube 	free(sbuf, M_TEMP);
    583  1.29    martin bad:
    584  1.29    martin 	vfs_copyinfh_free(fh);
    585   1.1       mrg 	return (error);
    586   1.1       mrg }
    587   1.1       mrg 
    588   1.1       mrg int
    589  1.11   thorpej netbsd32_futimes(l, v, retval)
    590  1.11   thorpej 	struct lwp *l;
    591   1.1       mrg 	void *v;
    592   1.1       mrg 	register_t *retval;
    593   1.1       mrg {
    594   1.1       mrg 	struct netbsd32_futimes_args /* {
    595   1.1       mrg 		syscallarg(int) fd;
    596   1.1       mrg 		syscallarg(const netbsd32_timevalp_t) tptr;
    597   1.1       mrg 	} */ *uap = v;
    598   1.1       mrg 	int error;
    599   1.1       mrg 	struct file *fp;
    600  1.14      fvdl 	struct proc *p = l->l_proc;
    601   1.1       mrg 
    602   1.1       mrg 	/* getvnode() will use the descriptor for us */
    603  1.14      fvdl 	if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
    604   1.1       mrg 		return (error);
    605   1.1       mrg 
    606  1.19     perry 	error = change_utimes32((struct vnode *)fp->f_data,
    607  1.23  christos 				SCARG(uap, tptr), l);
    608  1.23  christos 	FILE_UNUSE(fp, l);
    609   1.1       mrg 	return (error);
    610   1.1       mrg }
    611   1.1       mrg 
    612   1.1       mrg int
    613  1.22  christos netbsd32_sys___getdents30(l, v, retval)
    614  1.11   thorpej 	struct lwp *l;
    615   1.1       mrg 	void *v;
    616   1.1       mrg 	register_t *retval;
    617   1.1       mrg {
    618  1.22  christos 	struct netbsd32_sys___getdents30_args /* {
    619   1.1       mrg 		syscallarg(int) fd;
    620   1.1       mrg 		syscallarg(netbsd32_charp) buf;
    621   1.1       mrg 		syscallarg(netbsd32_size_t) count;
    622   1.1       mrg 	} */ *uap = v;
    623   1.1       mrg 	struct file *fp;
    624   1.1       mrg 	int error, done;
    625  1.11   thorpej 	struct proc *p = l->l_proc;
    626   1.1       mrg 
    627   1.1       mrg 	/* getvnode() will use the descriptor for us */
    628   1.1       mrg 	if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
    629   1.1       mrg 		return (error);
    630   1.1       mrg 	if ((fp->f_flag & FREAD) == 0) {
    631   1.1       mrg 		error = EBADF;
    632   1.1       mrg 		goto out;
    633   1.1       mrg 	}
    634  1.39       dsl 	error = vn_readdir(fp, SCARG_P32(uap, buf),
    635  1.23  christos 	    UIO_USERSPACE, SCARG(uap, count), &done, l, 0, 0);
    636   1.1       mrg 	*retval = done;
    637   1.1       mrg  out:
    638  1.23  christos 	FILE_UNUSE(fp, l);
    639   1.1       mrg 	return (error);
    640   1.1       mrg }
    641   1.1       mrg 
    642   1.1       mrg int
    643  1.11   thorpej netbsd32_lutimes(l, v, retval)
    644  1.11   thorpej 	struct lwp *l;
    645   1.1       mrg 	void *v;
    646   1.1       mrg 	register_t *retval;
    647   1.1       mrg {
    648   1.1       mrg 	struct netbsd32_lutimes_args /* {
    649   1.1       mrg 		syscallarg(const netbsd32_charp) path;
    650   1.1       mrg 		syscallarg(const netbsd32_timevalp_t) tptr;
    651   1.1       mrg 	} */ *uap = v;
    652   1.1       mrg 	int error;
    653   1.1       mrg 	struct nameidata nd;
    654   1.1       mrg 
    655  1.39       dsl 	NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG_P32(uap, path), l);
    656   1.1       mrg 	if ((error = namei(&nd)) != 0)
    657   1.1       mrg 		return (error);
    658   1.1       mrg 
    659  1.23  christos 	error = change_utimes32(nd.ni_vp, SCARG(uap, tptr), l);
    660   1.1       mrg 
    661   1.1       mrg 	vrele(nd.ni_vp);
    662   1.1       mrg 	return (error);
    663   1.1       mrg }
    664   1.1       mrg 
    665   1.1       mrg int
    666  1.22  christos netbsd32_sys___stat30(l, v, retval)
    667  1.11   thorpej 	struct lwp *l;
    668   1.1       mrg 	void *v;
    669   1.1       mrg 	register_t *retval;
    670   1.1       mrg {
    671  1.22  christos 	struct netbsd32_sys___stat30_args /* {
    672   1.1       mrg 		syscallarg(const netbsd32_charp) path;
    673   1.1       mrg 		syscallarg(netbsd32_statp_t) ub;
    674   1.1       mrg 	} */ *uap = v;
    675   1.1       mrg 	struct netbsd32_stat sb32;
    676   1.1       mrg 	struct stat sb;
    677   1.1       mrg 	int error;
    678  1.36  christos 	void *sg;
    679   1.1       mrg 	const char *path;
    680  1.14      fvdl 	struct proc *p = l->l_proc;
    681   1.1       mrg 
    682  1.39       dsl 	path = SCARG_P32(uap, path);
    683  1.14      fvdl 	sg = stackgap_init(p, 0);
    684  1.23  christos 	CHECK_ALT_EXIST(l, &sg, path);
    685   1.1       mrg 
    686  1.37       dsl 	error = do_sys_stat(l, path, FOLLOW, &sb);
    687  1.22  christos 	netbsd32_from___stat30(&sb, &sb32);
    688  1.39       dsl 	error = copyout(&sb32, SCARG_P32(uap, ub), sizeof(sb32));
    689   1.1       mrg 	return (error);
    690   1.1       mrg }
    691   1.1       mrg 
    692   1.1       mrg int
    693  1.22  christos netbsd32_sys___fstat30(l, v, retval)
    694  1.11   thorpej 	struct lwp *l;
    695   1.1       mrg 	void *v;
    696   1.1       mrg 	register_t *retval;
    697   1.1       mrg {
    698  1.22  christos 	struct netbsd32_sys___fstat30_args /* {
    699   1.1       mrg 		syscallarg(int) fd;
    700   1.1       mrg 		syscallarg(netbsd32_statp_t) sb;
    701   1.1       mrg 	} */ *uap = v;
    702   1.1       mrg 	int fd = SCARG(uap, fd);
    703  1.14      fvdl 	struct proc *p = l->l_proc;
    704  1.14      fvdl 	struct filedesc *fdp = p->p_fd;
    705   1.1       mrg 	struct file *fp;
    706   1.1       mrg 	struct netbsd32_stat sb32;
    707   1.1       mrg 	struct stat ub;
    708   1.1       mrg 	int error = 0;
    709   1.1       mrg 
    710   1.6   thorpej 	if ((fp = fd_getfile(fdp, fd)) == NULL)
    711   1.1       mrg 		return (EBADF);
    712   1.1       mrg 
    713   1.3  jdolecek 	FILE_USE(fp);
    714  1.23  christos 	error = (*fp->f_ops->fo_stat)(fp, &ub, l);
    715  1.23  christos 	FILE_UNUSE(fp, l);
    716   1.3  jdolecek 
    717   1.1       mrg 	if (error == 0) {
    718  1.22  christos 		netbsd32_from___stat30(&ub, &sb32);
    719  1.39       dsl 		error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb32));
    720   1.1       mrg 	}
    721   1.1       mrg 	return (error);
    722   1.1       mrg }
    723   1.1       mrg 
    724   1.1       mrg int
    725  1.22  christos netbsd32_sys___lstat30(l, v, retval)
    726  1.11   thorpej 	struct lwp *l;
    727   1.1       mrg 	void *v;
    728   1.1       mrg 	register_t *retval;
    729   1.1       mrg {
    730  1.22  christos 	struct netbsd32_sys___lstat30_args /* {
    731   1.1       mrg 		syscallarg(const netbsd32_charp) path;
    732   1.1       mrg 		syscallarg(netbsd32_statp_t) ub;
    733   1.1       mrg 	} */ *uap = v;
    734   1.1       mrg 	struct netbsd32_stat sb32;
    735   1.1       mrg 	struct stat sb;
    736   1.1       mrg 	int error;
    737  1.36  christos 	void *sg;
    738   1.1       mrg 	const char *path;
    739  1.14      fvdl 	struct proc *p = l->l_proc;
    740   1.1       mrg 
    741  1.39       dsl 	path = SCARG_P32(uap, path);
    742  1.14      fvdl 	sg = stackgap_init(p, 0);
    743  1.23  christos 	CHECK_ALT_EXIST(l, &sg, path);
    744   1.1       mrg 
    745  1.37       dsl 	error = do_sys_stat(l, path, NOFOLLOW, &sb);
    746   1.1       mrg 	if (error)
    747   1.1       mrg 		return (error);
    748  1.22  christos 	netbsd32_from___stat30(&sb, &sb32);
    749  1.39       dsl 	error = copyout(&sb32, SCARG_P32(uap, ub), sizeof(sb32));
    750   1.1       mrg 	return (error);
    751   1.1       mrg }
    752   1.1       mrg 
    753  1.32    martin int netbsd32___fhstat40(l, v, retval)
    754  1.26      cube 	struct lwp *l;
    755  1.26      cube 	void *v;
    756  1.26      cube 	register_t *retval;
    757  1.26      cube {
    758  1.32    martin 	struct netbsd32___fhstat40_args /* {
    759  1.32    martin 		syscallarg(const netbsd32_pointer_t) fhp;
    760  1.32    martin 		syscallarg(netbsd32_size_t) fh_size;
    761  1.26      cube 		syscallarg(netbsd32_statp_t) sb;
    762  1.26      cube 	} */ *uap = v;
    763  1.26      cube 	struct stat sb;
    764  1.26      cube 	struct netbsd32_stat sb32;
    765  1.26      cube 	int error;
    766  1.29    martin 	fhandle_t *fh;
    767  1.26      cube 	struct vnode *vp;
    768  1.26      cube 
    769  1.26      cube 	/*
    770  1.26      cube 	 * Must be super user
    771  1.26      cube 	 */
    772  1.34      elad 	if ((error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_FILEHANDLE,
    773  1.34      elad 	    0, NULL, NULL, NULL)))
    774  1.29    martin 		return error;
    775  1.29    martin 
    776  1.39       dsl 	if ((error = vfs_copyinfh_alloc(SCARG_P32(uap, fhp),
    777  1.33      yamt 	    SCARG(uap, fh_size), &fh)) != 0)
    778  1.29    martin 		goto bad;
    779  1.26      cube 
    780  1.29    martin 	if ((error = vfs_fhtovp(fh, &vp)) != 0)
    781  1.29    martin 		goto bad;
    782  1.26      cube 
    783  1.26      cube 	error = vn_stat(vp, &sb, l);
    784  1.26      cube 	vput(vp);
    785  1.26      cube 	if (error)
    786  1.29    martin 		goto bad;
    787  1.26      cube 	netbsd32_from___stat30(&sb, &sb32);
    788  1.39       dsl 	error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb));
    789  1.29    martin bad:
    790  1.29    martin 	vfs_copyinfh_free(fh);
    791  1.29    martin 	return error;
    792  1.26      cube }
    793  1.26      cube 
    794   1.1       mrg int
    795  1.11   thorpej netbsd32_preadv(l, v, retval)
    796  1.11   thorpej 	struct lwp *l;
    797   1.1       mrg 	void *v;
    798   1.1       mrg 	register_t *retval;
    799   1.1       mrg {
    800   1.1       mrg 	struct netbsd32_preadv_args /* {
    801   1.1       mrg 		syscallarg(int) fd;
    802   1.1       mrg 		syscallarg(const netbsd32_iovecp_t) iovp;
    803   1.1       mrg 		syscallarg(int) iovcnt;
    804   1.1       mrg 		syscallarg(int) pad;
    805   1.1       mrg 		syscallarg(off_t) offset;
    806   1.1       mrg 	} */ *uap = v;
    807  1.14      fvdl 	struct proc *p = l->l_proc;
    808  1.14      fvdl 	struct filedesc *fdp = p->p_fd;
    809   1.1       mrg 	struct file *fp;
    810   1.1       mrg 	struct vnode *vp;
    811   1.1       mrg 	off_t offset;
    812   1.1       mrg 	int error, fd = SCARG(uap, fd);
    813   1.1       mrg 
    814   1.6   thorpej 	if ((fp = fd_getfile(fdp, fd)) == NULL)
    815   1.6   thorpej 		return (EBADF);
    816   1.6   thorpej 
    817   1.6   thorpej 	if ((fp->f_flag & FREAD) == 0)
    818   1.1       mrg 		return (EBADF);
    819   1.1       mrg 
    820   1.9  jdolecek 	FILE_USE(fp);
    821   1.9  jdolecek 
    822   1.1       mrg 	vp = (struct vnode *)fp->f_data;
    823   1.9  jdolecek 	if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO) {
    824   1.9  jdolecek 		error = ESPIPE;
    825   1.9  jdolecek 		goto out;
    826   1.9  jdolecek 	}
    827   1.1       mrg 
    828   1.1       mrg 	offset = SCARG(uap, offset);
    829   1.1       mrg 
    830   1.1       mrg 	/*
    831   1.1       mrg 	 * XXX This works because no file systems actually
    832   1.1       mrg 	 * XXX take any action on the seek operation.
    833   1.1       mrg 	 */
    834   1.1       mrg 	if ((error = VOP_SEEK(vp, fp->f_offset, offset, fp->f_cred)) != 0)
    835   1.9  jdolecek 		goto out;
    836   1.1       mrg 
    837  1.39       dsl 	return (dofilereadv32(l, fd, fp, SCARG_P32(uap, iovp),
    838  1.10       scw 	    SCARG(uap, iovcnt), &offset, 0, retval));
    839   1.9  jdolecek 
    840   1.9  jdolecek out:
    841  1.23  christos 	FILE_UNUSE(fp, l);
    842   1.9  jdolecek 	return (error);
    843   1.1       mrg }
    844   1.1       mrg 
    845   1.1       mrg int
    846  1.11   thorpej netbsd32_pwritev(l, v, retval)
    847  1.11   thorpej 	struct lwp *l;
    848   1.1       mrg 	void *v;
    849   1.1       mrg 	register_t *retval;
    850   1.1       mrg {
    851   1.1       mrg 	struct netbsd32_pwritev_args /* {
    852   1.1       mrg 		syscallarg(int) fd;
    853   1.1       mrg 		syscallarg(const netbsd32_iovecp_t) iovp;
    854   1.1       mrg 		syscallarg(int) iovcnt;
    855   1.1       mrg 		syscallarg(int) pad;
    856   1.1       mrg 		syscallarg(off_t) offset;
    857   1.1       mrg 	} */ *uap = v;
    858  1.14      fvdl 	struct proc *p = l->l_proc;
    859  1.14      fvdl 	struct filedesc *fdp = p->p_fd;
    860   1.1       mrg 	struct file *fp;
    861   1.1       mrg 	struct vnode *vp;
    862   1.1       mrg 	off_t offset;
    863   1.1       mrg 	int error, fd = SCARG(uap, fd);
    864   1.1       mrg 
    865   1.6   thorpej 	if ((fp = fd_getfile(fdp, fd)) == NULL)
    866   1.6   thorpej 		return (EBADF);
    867   1.6   thorpej 
    868   1.6   thorpej 	if ((fp->f_flag & FWRITE) == 0)
    869   1.1       mrg 		return (EBADF);
    870   1.1       mrg 
    871   1.9  jdolecek 	FILE_USE(fp);
    872   1.9  jdolecek 
    873   1.1       mrg 	vp = (struct vnode *)fp->f_data;
    874   1.9  jdolecek 	if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO) {
    875   1.9  jdolecek 		error = ESPIPE;
    876   1.9  jdolecek 		goto out;
    877   1.9  jdolecek 	}
    878   1.1       mrg 
    879   1.1       mrg 	offset = SCARG(uap, offset);
    880   1.1       mrg 
    881   1.1       mrg 	/*
    882   1.1       mrg 	 * XXX This works because no file systems actually
    883   1.1       mrg 	 * XXX take any action on the seek operation.
    884   1.1       mrg 	 */
    885   1.1       mrg 	if ((error = VOP_SEEK(vp, fp->f_offset, offset, fp->f_cred)) != 0)
    886   1.9  jdolecek 		goto out;
    887   1.1       mrg 
    888  1.39       dsl 	return (dofilewritev32(l, fd, fp, SCARG_P32(uap, iovp),
    889  1.10       scw 	    SCARG(uap, iovcnt), &offset, 0, retval));
    890   1.9  jdolecek 
    891   1.9  jdolecek out:
    892  1.23  christos 	FILE_UNUSE(fp, l);
    893   1.9  jdolecek 	return (error);
    894   1.1       mrg }
    895   1.1       mrg 
    896   1.1       mrg /*
    897   1.1       mrg  * Find pathname of process's current directory.
    898   1.1       mrg  *
    899   1.1       mrg  * Use vfs vnode-to-name reverse cache; if that fails, fall back
    900   1.1       mrg  * to reading directory contents.
    901   1.1       mrg  */
    902  1.23  christos /* XXX NH Why does this exist */
    903  1.14      fvdl int
    904  1.14      fvdl getcwd_common __P((struct vnode *, struct vnode *,
    905  1.23  christos 		   char **, char *, int, int, struct lwp *));
    906  1.14      fvdl 
    907  1.19     perry int netbsd32___getcwd(l, v, retval)
    908  1.11   thorpej 	struct lwp *l;
    909   1.1       mrg 	void   *v;
    910   1.1       mrg 	register_t *retval;
    911   1.1       mrg {
    912   1.1       mrg 	struct netbsd32___getcwd_args /* {
    913   1.1       mrg 		syscallarg(char *) bufp;
    914   1.1       mrg 		syscallarg(size_t) length;
    915   1.1       mrg 	} */ *uap = v;
    916  1.11   thorpej 	struct proc *p = l->l_proc;
    917   1.1       mrg 	int     error;
    918   1.1       mrg 	char   *path;
    919   1.1       mrg 	char   *bp, *bend;
    920   1.1       mrg 	int     len = (int)SCARG(uap, length);
    921   1.1       mrg 	int	lenused;
    922   1.1       mrg 
    923   1.1       mrg 	if (len > MAXPATHLEN*4)
    924   1.1       mrg 		len = MAXPATHLEN*4;
    925   1.1       mrg 	else if (len < 2)
    926   1.1       mrg 		return ERANGE;
    927   1.1       mrg 
    928   1.1       mrg 	path = (char *)malloc(len, M_TEMP, M_WAITOK);
    929   1.1       mrg 	if (!path)
    930   1.1       mrg 		return ENOMEM;
    931   1.1       mrg 
    932   1.1       mrg 	bp = &path[len];
    933   1.1       mrg 	bend = bp;
    934   1.1       mrg 	*(--bp) = '\0';
    935   1.1       mrg 
    936   1.1       mrg 	/*
    937   1.1       mrg 	 * 5th argument here is "max number of vnodes to traverse".
    938   1.1       mrg 	 * Since each entry takes up at least 2 bytes in the output buffer,
    939   1.1       mrg 	 * limit it to N/2 vnodes for an N byte buffer.
    940   1.1       mrg 	 */
    941   1.1       mrg #define GETCWD_CHECK_ACCESS 0x0001
    942   1.1       mrg 	error = getcwd_common (p->p_cwdi->cwdi_cdir, NULL, &bp, path, len/2,
    943  1.23  christos 			       GETCWD_CHECK_ACCESS, l);
    944   1.1       mrg 
    945   1.1       mrg 	if (error)
    946   1.1       mrg 		goto out;
    947   1.1       mrg 	lenused = bend - bp;
    948   1.1       mrg 	*retval = lenused;
    949   1.1       mrg 	/* put the result into user buffer */
    950  1.39       dsl 	error = copyout(bp, SCARG_P32(uap, bufp), lenused);
    951   1.1       mrg 
    952   1.1       mrg out:
    953   1.1       mrg 	free(path, M_TEMP);
    954   1.1       mrg 	return error;
    955   1.1       mrg }
    956