Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_fs.c revision 1.55.10.2
      1  1.55.10.2  christos /*	$NetBSD: netbsd32_fs.c,v 1.55.10.2 2009/01/04 01:56:02 christos Exp $	*/
      2  1.55.10.2  christos 
      3  1.55.10.2  christos /*
      4  1.55.10.2  christos  * Copyright (c) 1998, 2001 Matthew R. Green
      5  1.55.10.2  christos  * All rights reserved.
      6  1.55.10.2  christos  *
      7  1.55.10.2  christos  * Redistribution and use in source and binary forms, with or without
      8  1.55.10.2  christos  * modification, are permitted provided that the following conditions
      9  1.55.10.2  christos  * are met:
     10  1.55.10.2  christos  * 1. Redistributions of source code must retain the above copyright
     11  1.55.10.2  christos  *    notice, this list of conditions and the following disclaimer.
     12  1.55.10.2  christos  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.55.10.2  christos  *    notice, this list of conditions and the following disclaimer in the
     14  1.55.10.2  christos  *    documentation and/or other materials provided with the distribution.
     15  1.55.10.2  christos  *
     16  1.55.10.2  christos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  1.55.10.2  christos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  1.55.10.2  christos  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  1.55.10.2  christos  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  1.55.10.2  christos  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21  1.55.10.2  christos  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22  1.55.10.2  christos  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23  1.55.10.2  christos  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24  1.55.10.2  christos  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  1.55.10.2  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  1.55.10.2  christos  * SUCH DAMAGE.
     27  1.55.10.2  christos  */
     28  1.55.10.2  christos 
     29  1.55.10.2  christos #include <sys/cdefs.h>
     30  1.55.10.2  christos __KERNEL_RCSID(0, "$NetBSD: netbsd32_fs.c,v 1.55.10.2 2009/01/04 01:56:02 christos Exp $");
     31  1.55.10.2  christos 
     32  1.55.10.2  christos #include <sys/param.h>
     33  1.55.10.2  christos #include <sys/systm.h>
     34  1.55.10.2  christos #include <sys/malloc.h>
     35  1.55.10.2  christos #include <sys/mount.h>
     36  1.55.10.2  christos #include <sys/socket.h>
     37  1.55.10.2  christos #include <sys/socketvar.h>
     38  1.55.10.2  christos #include <sys/stat.h>
     39  1.55.10.2  christos #include <sys/time.h>
     40  1.55.10.2  christos #include <sys/ktrace.h>
     41  1.55.10.2  christos #include <sys/resourcevar.h>
     42  1.55.10.2  christos #include <sys/vnode.h>
     43  1.55.10.2  christos #include <sys/file.h>
     44  1.55.10.2  christos #include <sys/filedesc.h>
     45  1.55.10.2  christos #include <sys/namei.h>
     46  1.55.10.2  christos #include <sys/statvfs.h>
     47  1.55.10.2  christos #include <sys/syscallargs.h>
     48  1.55.10.2  christos #include <sys/proc.h>
     49  1.55.10.2  christos #include <sys/dirent.h>
     50  1.55.10.2  christos #include <sys/kauth.h>
     51  1.55.10.2  christos #include <sys/vfs_syscalls.h>
     52  1.55.10.2  christos 
     53  1.55.10.2  christos #include <compat/netbsd32/netbsd32.h>
     54  1.55.10.2  christos #include <compat/netbsd32/netbsd32_syscallargs.h>
     55  1.55.10.2  christos #include <compat/netbsd32/netbsd32_conv.h>
     56  1.55.10.2  christos #include <compat/sys/mount.h>
     57  1.55.10.2  christos 
     58  1.55.10.2  christos 
     59  1.55.10.2  christos static int dofilereadv32(int, struct file *, struct netbsd32_iovec *,
     60  1.55.10.2  christos 			      int, off_t *, int, register_t *);
     61  1.55.10.2  christos static int dofilewritev32(int, struct file *, struct netbsd32_iovec *,
     62  1.55.10.2  christos 			       int,  off_t *, int, register_t *);
     63  1.55.10.2  christos 
     64  1.55.10.2  christos struct iovec *
     65  1.55.10.2  christos netbsd32_get_iov(struct netbsd32_iovec *iov32, int iovlen, struct iovec *aiov,
     66  1.55.10.2  christos     int aiov_len)
     67  1.55.10.2  christos {
     68  1.55.10.2  christos #define N_IOV32 8
     69  1.55.10.2  christos 	struct netbsd32_iovec aiov32[N_IOV32];
     70  1.55.10.2  christos 	struct iovec *iov = aiov;
     71  1.55.10.2  christos 	struct iovec *iovp;
     72  1.55.10.2  christos 	int i, n, j;
     73  1.55.10.2  christos 	int error;
     74  1.55.10.2  christos 
     75  1.55.10.2  christos 	if (iovlen < 0 || iovlen > IOV_MAX)
     76  1.55.10.2  christos 		return NULL;
     77  1.55.10.2  christos 
     78  1.55.10.2  christos 	if (iovlen > aiov_len)
     79  1.55.10.2  christos 		iov = malloc(iovlen * sizeof (*iov), M_TEMP, M_WAITOK);
     80  1.55.10.2  christos 
     81  1.55.10.2  christos 	iovp = iov;
     82  1.55.10.2  christos 	for (i = 0; i < iovlen; iov32 += N_IOV32, i += N_IOV32) {
     83  1.55.10.2  christos 		n = iovlen - i;
     84  1.55.10.2  christos 		if (n > N_IOV32)
     85  1.55.10.2  christos 			n = N_IOV32;
     86  1.55.10.2  christos 		error = copyin(iov32, aiov32, n * sizeof (*iov32));
     87  1.55.10.2  christos 		if (error != 0) {
     88  1.55.10.2  christos 			if (iov != aiov)
     89  1.55.10.2  christos 				free(iov, M_TEMP);
     90  1.55.10.2  christos 			return NULL;
     91  1.55.10.2  christos 		}
     92  1.55.10.2  christos 		for (j = 0; j < n; iovp++, j++) {
     93  1.55.10.2  christos 			iovp->iov_base = NETBSD32PTR64(aiov32[j].iov_base);
     94  1.55.10.2  christos 			iovp->iov_len = aiov32[j].iov_len;
     95  1.55.10.2  christos 		}
     96  1.55.10.2  christos 	}
     97  1.55.10.2  christos 	return iov;
     98  1.55.10.2  christos #undef N_IOV32
     99  1.55.10.2  christos }
    100  1.55.10.2  christos 
    101  1.55.10.2  christos int
    102  1.55.10.2  christos netbsd32_readv(struct lwp *l, const struct netbsd32_readv_args *uap, register_t *retval)
    103  1.55.10.2  christos {
    104  1.55.10.2  christos 	/* {
    105  1.55.10.2  christos 		syscallarg(int) fd;
    106  1.55.10.2  christos 		syscallarg(const netbsd32_iovecp_t) iovp;
    107  1.55.10.2  christos 		syscallarg(int) iovcnt;
    108  1.55.10.2  christos 	} */
    109  1.55.10.2  christos 	int fd = SCARG(uap, fd);
    110  1.55.10.2  christos 	file_t *fp;
    111  1.55.10.2  christos 
    112  1.55.10.2  christos 	if ((fp = fd_getfile(fd)) == NULL)
    113  1.55.10.2  christos 		return (EBADF);
    114  1.55.10.2  christos 
    115  1.55.10.2  christos 	if ((fp->f_flag & FREAD) == 0) {
    116  1.55.10.2  christos 		fd_putfile(fd);
    117  1.55.10.2  christos 		return (EBADF);
    118  1.55.10.2  christos 	}
    119  1.55.10.2  christos 
    120  1.55.10.2  christos 	return (dofilereadv32(fd, fp,
    121  1.55.10.2  christos 	    (struct netbsd32_iovec *)SCARG_P32(uap, iovp),
    122  1.55.10.2  christos 	    SCARG(uap, iovcnt), &fp->f_offset, FOF_UPDATE_OFFSET, retval));
    123  1.55.10.2  christos }
    124  1.55.10.2  christos 
    125  1.55.10.2  christos /* Damn thing copies in the iovec! */
    126  1.55.10.2  christos int
    127  1.55.10.2  christos dofilereadv32(int fd, struct file *fp, struct netbsd32_iovec *iovp, int iovcnt, off_t *offset, int flags, register_t *retval)
    128  1.55.10.2  christos {
    129  1.55.10.2  christos 	struct uio auio;
    130  1.55.10.2  christos 	struct iovec *iov;
    131  1.55.10.2  christos 	struct iovec *needfree;
    132  1.55.10.2  christos 	struct iovec aiov[UIO_SMALLIOV];
    133  1.55.10.2  christos 	long i, cnt, error = 0;
    134  1.55.10.2  christos 	u_int iovlen;
    135  1.55.10.2  christos 	struct iovec *ktriov = NULL;
    136  1.55.10.2  christos 
    137  1.55.10.2  christos 	/* note: can't use iovlen until iovcnt is validated */
    138  1.55.10.2  christos 	iovlen = iovcnt * sizeof(struct iovec);
    139  1.55.10.2  christos 	if ((u_int)iovcnt > UIO_SMALLIOV) {
    140  1.55.10.2  christos 		if ((u_int)iovcnt > IOV_MAX) {
    141  1.55.10.2  christos 			error = EINVAL;
    142  1.55.10.2  christos 			goto out;
    143  1.55.10.2  christos 		}
    144  1.55.10.2  christos 		iov = malloc(iovlen, M_IOV, M_WAITOK);
    145  1.55.10.2  christos 		needfree = iov;
    146  1.55.10.2  christos 	} else if ((u_int)iovcnt > 0) {
    147  1.55.10.2  christos 		iov = aiov;
    148  1.55.10.2  christos 		needfree = NULL;
    149  1.55.10.2  christos 	} else {
    150  1.55.10.2  christos 		error = EINVAL;
    151  1.55.10.2  christos 		goto out;
    152  1.55.10.2  christos 	}
    153  1.55.10.2  christos 
    154  1.55.10.2  christos 	auio.uio_iov = iov;
    155  1.55.10.2  christos 	auio.uio_iovcnt = iovcnt;
    156  1.55.10.2  christos 	auio.uio_rw = UIO_READ;
    157  1.55.10.2  christos 	auio.uio_vmspace = curproc->p_vmspace;
    158  1.55.10.2  christos 	error = netbsd32_to_iovecin(iovp, iov, iovcnt);
    159  1.55.10.2  christos 	if (error)
    160  1.55.10.2  christos 		goto done;
    161  1.55.10.2  christos 	auio.uio_resid = 0;
    162  1.55.10.2  christos 	for (i = 0; i < iovcnt; i++) {
    163  1.55.10.2  christos 		auio.uio_resid += iov->iov_len;
    164  1.55.10.2  christos 		/*
    165  1.55.10.2  christos 		 * Reads return ssize_t because -1 is returned on error.
    166  1.55.10.2  christos 		 * Therefore we must restrict the length to SSIZE_MAX to
    167  1.55.10.2  christos 		 * avoid garbage return values.
    168  1.55.10.2  christos 		 */
    169  1.55.10.2  christos 		if (iov->iov_len > SSIZE_MAX || auio.uio_resid > SSIZE_MAX) {
    170  1.55.10.2  christos 			error = EINVAL;
    171  1.55.10.2  christos 			goto done;
    172  1.55.10.2  christos 		}
    173  1.55.10.2  christos 		iov++;
    174  1.55.10.2  christos 	}
    175  1.55.10.2  christos 
    176  1.55.10.2  christos 	/*
    177  1.55.10.2  christos 	 * if tracing, save a copy of iovec
    178  1.55.10.2  christos 	 */
    179  1.55.10.2  christos 	if (ktrpoint(KTR_GENIO)) {
    180  1.55.10.2  christos 		ktriov = malloc(iovlen, M_TEMP, M_WAITOK);
    181  1.55.10.2  christos 		memcpy((void *)ktriov, (void *)auio.uio_iov, iovlen);
    182  1.55.10.2  christos 	}
    183  1.55.10.2  christos 
    184  1.55.10.2  christos 	cnt = auio.uio_resid;
    185  1.55.10.2  christos 	error = (*fp->f_ops->fo_read)(fp, offset, &auio, fp->f_cred, flags);
    186  1.55.10.2  christos 	if (error)
    187  1.55.10.2  christos 		if (auio.uio_resid != cnt && (error == ERESTART ||
    188  1.55.10.2  christos 		    error == EINTR || error == EWOULDBLOCK))
    189  1.55.10.2  christos 			error = 0;
    190  1.55.10.2  christos 	cnt -= auio.uio_resid;
    191  1.55.10.2  christos 
    192  1.55.10.2  christos 	if (ktriov != NULL) {
    193  1.55.10.2  christos 		ktrgeniov(fd, UIO_READ, ktriov, cnt, error);
    194  1.55.10.2  christos 		free(ktriov, M_TEMP);
    195  1.55.10.2  christos 	}
    196  1.55.10.2  christos 
    197  1.55.10.2  christos 	*retval = cnt;
    198  1.55.10.2  christos done:
    199  1.55.10.2  christos 	if (needfree)
    200  1.55.10.2  christos 		free(needfree, M_IOV);
    201  1.55.10.2  christos out:
    202  1.55.10.2  christos 	fd_putfile(fd);
    203  1.55.10.2  christos 	return (error);
    204  1.55.10.2  christos }
    205  1.55.10.2  christos 
    206  1.55.10.2  christos int
    207  1.55.10.2  christos netbsd32_writev(struct lwp *l, const struct netbsd32_writev_args *uap, register_t *retval)
    208  1.55.10.2  christos {
    209  1.55.10.2  christos 	/* {
    210  1.55.10.2  christos 		syscallarg(int) fd;
    211  1.55.10.2  christos 		syscallarg(const netbsd32_iovecp_t) iovp;
    212  1.55.10.2  christos 		syscallarg(int) iovcnt;
    213  1.55.10.2  christos 	} */
    214  1.55.10.2  christos 	int fd = SCARG(uap, fd);
    215  1.55.10.2  christos 	file_t *fp;
    216  1.55.10.2  christos 
    217  1.55.10.2  christos 	if ((fp = fd_getfile(fd)) == NULL)
    218  1.55.10.2  christos 		return (EBADF);
    219  1.55.10.2  christos 
    220  1.55.10.2  christos 	if ((fp->f_flag & FWRITE) == 0) {
    221  1.55.10.2  christos 		fd_putfile(fd);
    222  1.55.10.2  christos 		return (EBADF);
    223  1.55.10.2  christos 	}
    224  1.55.10.2  christos 
    225  1.55.10.2  christos 	return (dofilewritev32(fd, fp,
    226  1.55.10.2  christos 	    (struct netbsd32_iovec *)SCARG_P32(uap, iovp),
    227  1.55.10.2  christos 	    SCARG(uap, iovcnt), &fp->f_offset, FOF_UPDATE_OFFSET, retval));
    228  1.55.10.2  christos }
    229  1.55.10.2  christos 
    230  1.55.10.2  christos int
    231  1.55.10.2  christos dofilewritev32(int fd, struct file *fp, struct netbsd32_iovec *iovp, int iovcnt, off_t *offset, int flags, register_t *retval)
    232  1.55.10.2  christos {
    233  1.55.10.2  christos 	struct uio auio;
    234  1.55.10.2  christos 	struct iovec *iov;
    235  1.55.10.2  christos 	struct iovec *needfree;
    236  1.55.10.2  christos 	struct iovec aiov[UIO_SMALLIOV];
    237  1.55.10.2  christos 	long i, cnt, error = 0;
    238  1.55.10.2  christos 	u_int iovlen;
    239  1.55.10.2  christos 	struct iovec *ktriov = NULL;
    240  1.55.10.2  christos 
    241  1.55.10.2  christos 	/* note: can't use iovlen until iovcnt is validated */
    242  1.55.10.2  christos 	iovlen = iovcnt * sizeof(struct iovec);
    243  1.55.10.2  christos 	if ((u_int)iovcnt > UIO_SMALLIOV) {
    244  1.55.10.2  christos 		if ((u_int)iovcnt > IOV_MAX) {
    245  1.55.10.2  christos 			error = EINVAL;
    246  1.55.10.2  christos 			goto out;
    247  1.55.10.2  christos 		}
    248  1.55.10.2  christos 		iov = malloc(iovlen, M_IOV, M_WAITOK);
    249  1.55.10.2  christos 		needfree = iov;
    250  1.55.10.2  christos 	} else if ((u_int)iovcnt > 0) {
    251  1.55.10.2  christos 		iov = aiov;
    252  1.55.10.2  christos 		needfree = NULL;
    253  1.55.10.2  christos 	} else {
    254  1.55.10.2  christos 		error = EINVAL;
    255  1.55.10.2  christos 		goto out;
    256  1.55.10.2  christos 	}
    257  1.55.10.2  christos 
    258  1.55.10.2  christos 	auio.uio_iov = iov;
    259  1.55.10.2  christos 	auio.uio_iovcnt = iovcnt;
    260  1.55.10.2  christos 	auio.uio_rw = UIO_WRITE;
    261  1.55.10.2  christos 	auio.uio_vmspace = curproc->p_vmspace;
    262  1.55.10.2  christos 	error = netbsd32_to_iovecin(iovp, iov, iovcnt);
    263  1.55.10.2  christos 	if (error)
    264  1.55.10.2  christos 		goto done;
    265  1.55.10.2  christos 	auio.uio_resid = 0;
    266  1.55.10.2  christos 	for (i = 0; i < iovcnt; i++) {
    267  1.55.10.2  christos 		auio.uio_resid += iov->iov_len;
    268  1.55.10.2  christos 		/*
    269  1.55.10.2  christos 		 * Writes return ssize_t because -1 is returned on error.
    270  1.55.10.2  christos 		 * Therefore we must restrict the length to SSIZE_MAX to
    271  1.55.10.2  christos 		 * avoid garbage return values.
    272  1.55.10.2  christos 		 */
    273  1.55.10.2  christos 		if (iov->iov_len > SSIZE_MAX || auio.uio_resid > SSIZE_MAX) {
    274  1.55.10.2  christos 			error = EINVAL;
    275  1.55.10.2  christos 			goto done;
    276  1.55.10.2  christos 		}
    277  1.55.10.2  christos 		iov++;
    278  1.55.10.2  christos 	}
    279  1.55.10.2  christos 
    280  1.55.10.2  christos 	/*
    281  1.55.10.2  christos 	 * if tracing, save a copy of iovec
    282  1.55.10.2  christos 	 */
    283  1.55.10.2  christos 	if (ktrpoint(KTR_GENIO))  {
    284  1.55.10.2  christos 		ktriov = malloc(iovlen, M_TEMP, M_WAITOK);
    285  1.55.10.2  christos 		memcpy((void *)ktriov, (void *)auio.uio_iov, iovlen);
    286  1.55.10.2  christos 	}
    287  1.55.10.2  christos 
    288  1.55.10.2  christos 	cnt = auio.uio_resid;
    289  1.55.10.2  christos 	error = (*fp->f_ops->fo_write)(fp, offset, &auio, fp->f_cred, flags);
    290  1.55.10.2  christos 	if (error) {
    291  1.55.10.2  christos 		if (auio.uio_resid != cnt && (error == ERESTART ||
    292  1.55.10.2  christos 		    error == EINTR || error == EWOULDBLOCK))
    293  1.55.10.2  christos 			error = 0;
    294  1.55.10.2  christos 		if (error == EPIPE) {
    295  1.55.10.2  christos 			mutex_enter(proc_lock);
    296  1.55.10.2  christos 			psignal(curproc, SIGPIPE);
    297  1.55.10.2  christos 			mutex_exit(proc_lock);
    298  1.55.10.2  christos 		}
    299  1.55.10.2  christos 	}
    300  1.55.10.2  christos 	cnt -= auio.uio_resid;
    301  1.55.10.2  christos 	if (ktriov != NULL) {
    302  1.55.10.2  christos 		ktrgenio(fd, UIO_WRITE, ktriov, cnt, error);
    303  1.55.10.2  christos 		free(ktriov, M_TEMP);
    304  1.55.10.2  christos 	}
    305  1.55.10.2  christos 	*retval = cnt;
    306  1.55.10.2  christos done:
    307  1.55.10.2  christos 	if (needfree)
    308  1.55.10.2  christos 		free(needfree, M_IOV);
    309  1.55.10.2  christos out:
    310  1.55.10.2  christos 	fd_putfile(fd);
    311  1.55.10.2  christos 	return (error);
    312  1.55.10.2  christos }
    313  1.55.10.2  christos 
    314  1.55.10.2  christos /*
    315  1.55.10.2  christos  * Common routine to set access and modification times given a vnode.
    316  1.55.10.2  christos  */
    317  1.55.10.2  christos static int
    318  1.55.10.2  christos get_utimes32(const netbsd32_timevalp_t *tptr, struct timeval *tv,
    319  1.55.10.2  christos     struct timeval **tvp)
    320  1.55.10.2  christos {
    321  1.55.10.2  christos 	int error;
    322  1.55.10.2  christos 	struct netbsd32_timeval tv32[2];
    323  1.55.10.2  christos 
    324  1.55.10.2  christos 	if (tptr == NULL) {
    325  1.55.10.2  christos 		*tvp = NULL;
    326  1.55.10.2  christos 		return 0;
    327  1.55.10.2  christos 	}
    328  1.55.10.2  christos 
    329  1.55.10.2  christos 	error = copyin(tptr, tv32, sizeof(tv32));
    330  1.55.10.2  christos 	if (error)
    331  1.55.10.2  christos 		return error;
    332  1.55.10.2  christos 	netbsd32_to_timeval(&tv32[0], &tv[0]);
    333  1.55.10.2  christos 	netbsd32_to_timeval(&tv32[1], &tv[1]);
    334  1.55.10.2  christos 
    335  1.55.10.2  christos 	*tvp = tv;
    336  1.55.10.2  christos 	return 0;
    337  1.55.10.2  christos }
    338  1.55.10.2  christos 
    339  1.55.10.2  christos int
    340  1.55.10.2  christos netbsd32___utimes50(struct lwp *l, const struct netbsd32___utimes50_args *uap, register_t *retval)
    341  1.55.10.2  christos {
    342  1.55.10.2  christos 	/* {
    343  1.55.10.2  christos 		syscallarg(const netbsd32_charp) path;
    344  1.55.10.2  christos 		syscallarg(const netbsd32_timevalp_t) tptr;
    345  1.55.10.2  christos 	} */
    346  1.55.10.2  christos 	int error;
    347  1.55.10.2  christos 	struct timeval tv[2], *tvp;
    348  1.55.10.2  christos 
    349  1.55.10.2  christos 	error = get_utimes32(SCARG_P32(uap, tptr), tv, &tvp);
    350  1.55.10.2  christos 	if (error != 0)
    351  1.55.10.2  christos 		return error;
    352  1.55.10.2  christos 
    353  1.55.10.2  christos 	return do_sys_utimes(l, NULL, SCARG_P32(uap, path), FOLLOW,
    354  1.55.10.2  christos 			    tvp, UIO_SYSSPACE);
    355  1.55.10.2  christos }
    356  1.55.10.2  christos 
    357  1.55.10.2  christos static int
    358  1.55.10.2  christos netbds32_copyout_statvfs(const void *kp, void *up, size_t len)
    359  1.55.10.2  christos {
    360  1.55.10.2  christos 	struct netbsd32_statvfs *sbuf_32;
    361  1.55.10.2  christos 	int error;
    362  1.55.10.2  christos 
    363  1.55.10.2  christos 	sbuf_32 = malloc(sizeof *sbuf_32, M_TEMP, M_WAITOK);
    364  1.55.10.2  christos 	netbsd32_from_statvfs(kp, sbuf_32);
    365  1.55.10.2  christos 	error = copyout(sbuf_32, up, sizeof(*sbuf_32));
    366  1.55.10.2  christos 	free(sbuf_32, M_TEMP);
    367  1.55.10.2  christos 
    368  1.55.10.2  christos 	return error;
    369  1.55.10.2  christos }
    370  1.55.10.2  christos 
    371  1.55.10.2  christos int
    372  1.55.10.2  christos netbsd32_statvfs1(struct lwp *l, const struct netbsd32_statvfs1_args *uap, register_t *retval)
    373  1.55.10.2  christos {
    374  1.55.10.2  christos 	/* {
    375  1.55.10.2  christos 		syscallarg(const netbsd32_charp) path;
    376  1.55.10.2  christos 		syscallarg(netbsd32_statvfsp_t) buf;
    377  1.55.10.2  christos 		syscallarg(int) flags;
    378  1.55.10.2  christos 	} */
    379  1.55.10.2  christos 	struct statvfs *sb;
    380  1.55.10.2  christos 	int error;
    381  1.55.10.2  christos 
    382  1.55.10.2  christos 	sb = STATVFSBUF_GET();
    383  1.55.10.2  christos 	error = do_sys_pstatvfs(l, SCARG_P32(uap, path), SCARG(uap, flags), sb);
    384  1.55.10.2  christos 	if (error == 0)
    385  1.55.10.2  christos 		error = netbds32_copyout_statvfs(sb, SCARG_P32(uap, buf), 0);
    386  1.55.10.2  christos 	STATVFSBUF_PUT(sb);
    387  1.55.10.2  christos 	return error;
    388  1.55.10.2  christos }
    389  1.55.10.2  christos 
    390  1.55.10.2  christos int
    391  1.55.10.2  christos netbsd32_fstatvfs1(struct lwp *l, const struct netbsd32_fstatvfs1_args *uap, register_t *retval)
    392  1.55.10.2  christos {
    393  1.55.10.2  christos 	/* {
    394  1.55.10.2  christos 		syscallarg(int) fd;
    395  1.55.10.2  christos 		syscallarg(netbsd32_statvfsp_t) buf;
    396  1.55.10.2  christos 		syscallarg(int) flags;
    397  1.55.10.2  christos 	} */
    398  1.55.10.2  christos 	struct statvfs *sb;
    399  1.55.10.2  christos 	int error;
    400  1.55.10.2  christos 
    401  1.55.10.2  christos 	sb = STATVFSBUF_GET();
    402  1.55.10.2  christos 	error = do_sys_fstatvfs(l, SCARG(uap, fd), SCARG(uap, flags), sb);
    403  1.55.10.2  christos 	if (error == 0)
    404  1.55.10.2  christos 		error = netbds32_copyout_statvfs(sb, SCARG_P32(uap, buf), 0);
    405  1.55.10.2  christos 	STATVFSBUF_PUT(sb);
    406  1.55.10.2  christos 	return error;
    407  1.55.10.2  christos }
    408  1.55.10.2  christos 
    409  1.55.10.2  christos int
    410  1.55.10.2  christos netbsd32_getvfsstat(struct lwp *l, const struct netbsd32_getvfsstat_args *uap, register_t *retval)
    411  1.55.10.2  christos {
    412  1.55.10.2  christos 	/* {
    413  1.55.10.2  christos 		syscallarg(netbsd32_statvfsp_t) buf;
    414  1.55.10.2  christos 		syscallarg(netbsd32_size_t) bufsize;
    415  1.55.10.2  christos 		syscallarg(int) flags;
    416  1.55.10.2  christos 	} */
    417  1.55.10.2  christos 
    418  1.55.10.2  christos 	return do_sys_getvfsstat(l, SCARG_P32(uap, buf), SCARG(uap, bufsize),
    419  1.55.10.2  christos 	    SCARG(uap, flags), netbds32_copyout_statvfs,
    420  1.55.10.2  christos 	    sizeof (struct netbsd32_statvfs), retval);
    421  1.55.10.2  christos }
    422  1.55.10.2  christos 
    423  1.55.10.2  christos int
    424  1.55.10.2  christos netbsd32___fhstatvfs140(struct lwp *l, const struct netbsd32___fhstatvfs140_args *uap, register_t *retval)
    425  1.55.10.2  christos {
    426  1.55.10.2  christos 	/* {
    427  1.55.10.2  christos 		syscallarg(const netbsd32_pointer_t) fhp;
    428  1.55.10.2  christos 		syscallarg(netbsd32_size_t) fh_size;
    429  1.55.10.2  christos 		syscallarg(netbsd32_statvfsp_t) buf;
    430  1.55.10.2  christos 		syscallarg(int) flags;
    431  1.55.10.2  christos 	} */
    432  1.55.10.2  christos 	struct statvfs *sb;
    433  1.55.10.2  christos 	int error;
    434  1.55.10.2  christos 
    435  1.55.10.2  christos 	sb = STATVFSBUF_GET();
    436  1.55.10.2  christos 	error = do_fhstatvfs(l, SCARG_P32(uap, fhp), SCARG(uap, fh_size), sb,
    437  1.55.10.2  christos 	    SCARG(uap, flags));
    438  1.55.10.2  christos 
    439  1.55.10.2  christos 	if (error == 0)
    440  1.55.10.2  christos 		error = netbds32_copyout_statvfs(sb, SCARG_P32(uap, buf), 0);
    441  1.55.10.2  christos 	STATVFSBUF_PUT(sb);
    442  1.55.10.2  christos 
    443  1.55.10.2  christos 	return error;
    444  1.55.10.2  christos }
    445  1.55.10.2  christos 
    446  1.55.10.2  christos int
    447  1.55.10.2  christos netbsd32___futimes50(struct lwp *l, const struct netbsd32___futimes50_args *uap, register_t *retval)
    448  1.55.10.2  christos {
    449  1.55.10.2  christos 	/* {
    450  1.55.10.2  christos 		syscallarg(int) fd;
    451  1.55.10.2  christos 		syscallarg(const netbsd32_timevalp_t) tptr;
    452  1.55.10.2  christos 	} */
    453  1.55.10.2  christos 	int error;
    454  1.55.10.2  christos 	file_t *fp;
    455  1.55.10.2  christos 	struct timeval tv[2], *tvp;
    456  1.55.10.2  christos 
    457  1.55.10.2  christos 	error = get_utimes32(SCARG_P32(uap, tptr), tv, &tvp);
    458  1.55.10.2  christos 	if (error != 0)
    459  1.55.10.2  christos 		return error;
    460  1.55.10.2  christos 
    461  1.55.10.2  christos 	/* fd_getvnode() will use the descriptor for us */
    462  1.55.10.2  christos 	if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
    463  1.55.10.2  christos 		return (error);
    464  1.55.10.2  christos 
    465  1.55.10.2  christos 	error = do_sys_utimes(l, fp->f_data, NULL, 0, tvp, UIO_SYSSPACE);
    466  1.55.10.2  christos 
    467  1.55.10.2  christos 	fd_putfile(SCARG(uap, fd));
    468  1.55.10.2  christos 	return (error);
    469  1.55.10.2  christos }
    470  1.55.10.2  christos 
    471  1.55.10.2  christos int
    472  1.55.10.2  christos netbsd32___getdents30(struct lwp *l,
    473  1.55.10.2  christos     const struct netbsd32___getdents30_args *uap, register_t *retval)
    474  1.55.10.2  christos {
    475  1.55.10.2  christos 	/* {
    476  1.55.10.2  christos 		syscallarg(int) fd;
    477  1.55.10.2  christos 		syscallarg(netbsd32_charp) buf;
    478  1.55.10.2  christos 		syscallarg(netbsd32_size_t) count;
    479  1.55.10.2  christos 	} */
    480  1.55.10.2  christos 	file_t *fp;
    481  1.55.10.2  christos 	int error, done;
    482  1.55.10.2  christos 
    483  1.55.10.2  christos 	/* fd_getvnode() will use the descriptor for us */
    484  1.55.10.2  christos 	if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
    485  1.55.10.2  christos 		return (error);
    486  1.55.10.2  christos 	if ((fp->f_flag & FREAD) == 0) {
    487  1.55.10.2  christos 		error = EBADF;
    488  1.55.10.2  christos 		goto out;
    489  1.55.10.2  christos 	}
    490  1.55.10.2  christos 	error = vn_readdir(fp, SCARG_P32(uap, buf),
    491  1.55.10.2  christos 	    UIO_USERSPACE, SCARG(uap, count), &done, l, 0, 0);
    492  1.55.10.2  christos 	*retval = done;
    493  1.55.10.2  christos  out:
    494  1.55.10.2  christos 	fd_putfile(SCARG(uap, fd));
    495  1.55.10.2  christos 	return (error);
    496  1.55.10.2  christos }
    497  1.55.10.2  christos 
    498  1.55.10.2  christos int
    499  1.55.10.2  christos netbsd32___lutimes50(struct lwp *l,
    500  1.55.10.2  christos     const struct netbsd32___lutimes50_args *uap, register_t *retval)
    501  1.55.10.2  christos {
    502  1.55.10.2  christos 	/* {
    503  1.55.10.2  christos 		syscallarg(const netbsd32_charp) path;
    504  1.55.10.2  christos 		syscallarg(const netbsd32_timevalp_t) tptr;
    505  1.55.10.2  christos 	} */
    506  1.55.10.2  christos 	int error;
    507  1.55.10.2  christos 	struct timeval tv[2], *tvp;
    508  1.55.10.2  christos 
    509  1.55.10.2  christos 	error = get_utimes32(SCARG_P32(uap, tptr), tv, &tvp);
    510  1.55.10.2  christos 	if (error != 0)
    511  1.55.10.2  christos 		return error;
    512  1.55.10.2  christos 
    513  1.55.10.2  christos 	return do_sys_utimes(l, NULL, SCARG_P32(uap, path), NOFOLLOW,
    514  1.55.10.2  christos 			    tvp, UIO_SYSSPACE);
    515  1.55.10.2  christos }
    516  1.55.10.2  christos 
    517  1.55.10.2  christos int
    518  1.55.10.2  christos netbsd32___stat50(struct lwp *l, const struct netbsd32___stat50_args *uap, register_t *retval)
    519  1.55.10.2  christos {
    520  1.55.10.2  christos 	/* {
    521  1.55.10.2  christos 		syscallarg(const netbsd32_charp) path;
    522  1.55.10.2  christos 		syscallarg(netbsd32_statp_t) ub;
    523  1.55.10.2  christos 	} */
    524  1.55.10.2  christos 	struct netbsd32_stat sb32;
    525  1.55.10.2  christos 	struct stat sb;
    526  1.55.10.2  christos 	int error;
    527  1.55.10.2  christos 	const char *path;
    528  1.55.10.2  christos 
    529  1.55.10.2  christos 	path = SCARG_P32(uap, path);
    530  1.55.10.2  christos 
    531  1.55.10.2  christos 	error = do_sys_stat(path, FOLLOW, &sb);
    532  1.55.10.2  christos 	if (error)
    533  1.55.10.2  christos 		return (error);
    534  1.55.10.2  christos 	netbsd32_from_stat(&sb, &sb32);
    535  1.55.10.2  christos 	error = copyout(&sb32, SCARG_P32(uap, ub), sizeof(sb32));
    536  1.55.10.2  christos 	return (error);
    537  1.55.10.2  christos }
    538  1.55.10.2  christos 
    539  1.55.10.2  christos int
    540  1.55.10.2  christos netbsd32___fstat50(struct lwp *l, const struct netbsd32___fstat50_args *uap, register_t *retval)
    541  1.55.10.2  christos {
    542  1.55.10.2  christos 	/* {
    543  1.55.10.2  christos 		syscallarg(int) fd;
    544  1.55.10.2  christos 		syscallarg(netbsd32_statp_t) sb;
    545  1.55.10.2  christos 	} */
    546  1.55.10.2  christos 	int fd = SCARG(uap, fd);
    547  1.55.10.2  christos 	file_t *fp;
    548  1.55.10.2  christos 	struct netbsd32_stat sb32;
    549  1.55.10.2  christos 	struct stat ub;
    550  1.55.10.2  christos 	int error = 0;
    551  1.55.10.2  christos 
    552  1.55.10.2  christos 	if ((fp = fd_getfile(fd)) == NULL)
    553  1.55.10.2  christos 		return (EBADF);
    554  1.55.10.2  christos 	error = (*fp->f_ops->fo_stat)(fp, &ub);
    555  1.55.10.2  christos 	fd_putfile(fd);
    556  1.55.10.2  christos 	if (error == 0) {
    557  1.55.10.2  christos 		netbsd32_from_stat(&ub, &sb32);
    558  1.55.10.2  christos 		error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb32));
    559  1.55.10.2  christos 	}
    560  1.55.10.2  christos 	return (error);
    561  1.55.10.2  christos }
    562  1.55.10.2  christos 
    563  1.55.10.2  christos int
    564  1.55.10.2  christos netbsd32___lstat50(struct lwp *l, const struct netbsd32___lstat50_args *uap, register_t *retval)
    565  1.55.10.2  christos {
    566  1.55.10.2  christos 	/* {
    567  1.55.10.2  christos 		syscallarg(const netbsd32_charp) path;
    568  1.55.10.2  christos 		syscallarg(netbsd32_statp_t) ub;
    569  1.55.10.2  christos 	} */
    570  1.55.10.2  christos 	struct netbsd32_stat sb32;
    571  1.55.10.2  christos 	struct stat sb;
    572  1.55.10.2  christos 	int error;
    573  1.55.10.2  christos 	const char *path;
    574  1.55.10.2  christos 
    575  1.55.10.2  christos 	path = SCARG_P32(uap, path);
    576  1.55.10.2  christos 
    577  1.55.10.2  christos 	error = do_sys_stat(path, NOFOLLOW, &sb);
    578  1.55.10.2  christos 	if (error)
    579  1.55.10.2  christos 		return (error);
    580  1.55.10.2  christos 	netbsd32_from_stat(&sb, &sb32);
    581  1.55.10.2  christos 	error = copyout(&sb32, SCARG_P32(uap, ub), sizeof(sb32));
    582  1.55.10.2  christos 	return (error);
    583  1.55.10.2  christos }
    584  1.55.10.2  christos 
    585  1.55.10.2  christos int
    586  1.55.10.2  christos netbsd32___fhstat50(struct lwp *l, const struct netbsd32___fhstat50_args *uap, register_t *retval)
    587  1.55.10.2  christos {
    588  1.55.10.2  christos 	/* {
    589  1.55.10.2  christos 		syscallarg(const netbsd32_pointer_t) fhp;
    590  1.55.10.2  christos 		syscallarg(netbsd32_size_t) fh_size;
    591  1.55.10.2  christos 		syscallarg(netbsd32_statp_t) sb;
    592  1.55.10.2  christos 	} */
    593  1.55.10.2  christos 	struct stat sb;
    594  1.55.10.2  christos 	struct netbsd32_stat sb32;
    595  1.55.10.2  christos 	int error;
    596  1.55.10.2  christos 
    597  1.55.10.2  christos 	error = do_fhstat(l, SCARG_P32(uap, fhp), SCARG(uap, fh_size), &sb);
    598  1.55.10.2  christos 	if (error != 0) {
    599  1.55.10.2  christos 		netbsd32_from_stat(&sb, &sb32);
    600  1.55.10.2  christos 		error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb));
    601  1.55.10.2  christos 	}
    602  1.55.10.2  christos 	return error;
    603  1.55.10.2  christos }
    604  1.55.10.2  christos 
    605  1.55.10.2  christos int
    606  1.55.10.2  christos netbsd32_preadv(struct lwp *l, const struct netbsd32_preadv_args *uap, register_t *retval)
    607  1.55.10.2  christos {
    608  1.55.10.2  christos 	/* {
    609  1.55.10.2  christos 		syscallarg(int) fd;
    610  1.55.10.2  christos 		syscallarg(const netbsd32_iovecp_t) iovp;
    611  1.55.10.2  christos 		syscallarg(int) iovcnt;
    612  1.55.10.2  christos 		syscallarg(int) pad;
    613  1.55.10.2  christos 		syscallarg(off_t) offset;
    614  1.55.10.2  christos 	} */
    615  1.55.10.2  christos 	file_t *fp;
    616  1.55.10.2  christos 	struct vnode *vp;
    617  1.55.10.2  christos 	off_t offset;
    618  1.55.10.2  christos 	int error, fd = SCARG(uap, fd);
    619  1.55.10.2  christos 
    620  1.55.10.2  christos 	if ((fp = fd_getfile(fd)) == NULL)
    621  1.55.10.2  christos 		return (EBADF);
    622  1.55.10.2  christos 
    623  1.55.10.2  christos 	if ((fp->f_flag & FREAD) == 0) {
    624  1.55.10.2  christos 		fd_putfile(fd);
    625  1.55.10.2  christos 		return (EBADF);
    626  1.55.10.2  christos 	}
    627  1.55.10.2  christos 
    628  1.55.10.2  christos 	vp = fp->f_data;
    629  1.55.10.2  christos 	if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO) {
    630  1.55.10.2  christos 		error = ESPIPE;
    631  1.55.10.2  christos 		goto out;
    632  1.55.10.2  christos 	}
    633  1.55.10.2  christos 
    634  1.55.10.2  christos 	offset = SCARG(uap, offset);
    635  1.55.10.2  christos 
    636  1.55.10.2  christos 	/*
    637  1.55.10.2  christos 	 * XXX This works because no file systems actually
    638  1.55.10.2  christos 	 * XXX take any action on the seek operation.
    639  1.55.10.2  christos 	 */
    640  1.55.10.2  christos 	if ((error = VOP_SEEK(vp, fp->f_offset, offset, fp->f_cred)) != 0)
    641  1.55.10.2  christos 		goto out;
    642  1.55.10.2  christos 
    643  1.55.10.2  christos 	return (dofilereadv32(fd, fp, SCARG_P32(uap, iovp),
    644  1.55.10.2  christos 	    SCARG(uap, iovcnt), &offset, 0, retval));
    645  1.55.10.2  christos 
    646  1.55.10.2  christos out:
    647  1.55.10.2  christos 	fd_putfile(fd);
    648  1.55.10.2  christos 	return (error);
    649  1.55.10.2  christos }
    650  1.55.10.2  christos 
    651  1.55.10.2  christos int
    652  1.55.10.2  christos netbsd32_pwritev(struct lwp *l, const struct netbsd32_pwritev_args *uap, register_t *retval)
    653  1.55.10.2  christos {
    654  1.55.10.2  christos 	/* {
    655  1.55.10.2  christos 		syscallarg(int) fd;
    656  1.55.10.2  christos 		syscallarg(const netbsd32_iovecp_t) iovp;
    657  1.55.10.2  christos 		syscallarg(int) iovcnt;
    658  1.55.10.2  christos 		syscallarg(int) pad;
    659  1.55.10.2  christos 		syscallarg(off_t) offset;
    660  1.55.10.2  christos 	} */
    661  1.55.10.2  christos 	file_t *fp;
    662  1.55.10.2  christos 	struct vnode *vp;
    663  1.55.10.2  christos 	off_t offset;
    664  1.55.10.2  christos 	int error, fd = SCARG(uap, fd);
    665  1.55.10.2  christos 
    666  1.55.10.2  christos 	if ((fp = fd_getfile(fd)) == NULL)
    667  1.55.10.2  christos 		return (EBADF);
    668  1.55.10.2  christos 
    669  1.55.10.2  christos 	if ((fp->f_flag & FWRITE) == 0) {
    670  1.55.10.2  christos 		fd_putfile(fd);
    671  1.55.10.2  christos 		return (EBADF);
    672  1.55.10.2  christos 	}
    673  1.55.10.2  christos 
    674  1.55.10.2  christos 	vp = fp->f_data;
    675  1.55.10.2  christos 	if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO) {
    676  1.55.10.2  christos 		error = ESPIPE;
    677  1.55.10.2  christos 		goto out;
    678  1.55.10.2  christos 	}
    679  1.55.10.2  christos 
    680  1.55.10.2  christos 	offset = SCARG(uap, offset);
    681  1.55.10.2  christos 
    682  1.55.10.2  christos 	/*
    683  1.55.10.2  christos 	 * XXX This works because no file systems actually
    684  1.55.10.2  christos 	 * XXX take any action on the seek operation.
    685  1.55.10.2  christos 	 */
    686  1.55.10.2  christos 	if ((error = VOP_SEEK(vp, fp->f_offset, offset, fp->f_cred)) != 0)
    687  1.55.10.2  christos 		goto out;
    688  1.55.10.2  christos 
    689  1.55.10.2  christos 	return (dofilewritev32(fd, fp, SCARG_P32(uap, iovp),
    690  1.55.10.2  christos 	    SCARG(uap, iovcnt), &offset, 0, retval));
    691  1.55.10.2  christos 
    692  1.55.10.2  christos out:
    693  1.55.10.2  christos 	fd_putfile(fd);
    694  1.55.10.2  christos 	return (error);
    695  1.55.10.2  christos }
    696  1.55.10.2  christos 
    697  1.55.10.2  christos /*
    698  1.55.10.2  christos  * Find pathname of process's current directory.
    699  1.55.10.2  christos  *
    700  1.55.10.2  christos  * Use vfs vnode-to-name reverse cache; if that fails, fall back
    701  1.55.10.2  christos  * to reading directory contents.
    702  1.55.10.2  christos  */
    703  1.55.10.2  christos /* XXX NH Why does this exist */
    704  1.55.10.2  christos int
    705  1.55.10.2  christos getcwd_common(struct vnode *, struct vnode *,
    706  1.55.10.2  christos 		   char **, char *, int, int, struct lwp *);
    707  1.55.10.2  christos 
    708  1.55.10.2  christos int
    709  1.55.10.2  christos netbsd32___getcwd(struct lwp *l, const struct netbsd32___getcwd_args *uap, register_t *retval)
    710  1.55.10.2  christos {
    711  1.55.10.2  christos 	/* {
    712  1.55.10.2  christos 		syscallarg(char *) bufp;
    713  1.55.10.2  christos 		syscallarg(size_t) length;
    714  1.55.10.2  christos 	} */
    715  1.55.10.2  christos 	struct proc *p = l->l_proc;
    716  1.55.10.2  christos 	int     error;
    717  1.55.10.2  christos 	char   *path;
    718  1.55.10.2  christos 	char   *bp, *bend;
    719  1.55.10.2  christos 	int     len = (int)SCARG(uap, length);
    720  1.55.10.2  christos 	int	lenused;
    721  1.55.10.2  christos 	struct	cwdinfo *cwdi;
    722  1.55.10.2  christos 
    723  1.55.10.2  christos 	if (len > MAXPATHLEN*4)
    724  1.55.10.2  christos 		len = MAXPATHLEN*4;
    725  1.55.10.2  christos 	else if (len < 2)
    726  1.55.10.2  christos 		return ERANGE;
    727  1.55.10.2  christos 
    728  1.55.10.2  christos 	path = (char *)malloc(len, M_TEMP, M_WAITOK);
    729  1.55.10.2  christos 	if (!path)
    730  1.55.10.2  christos 		return ENOMEM;
    731  1.55.10.2  christos 
    732  1.55.10.2  christos 	bp = &path[len];
    733  1.55.10.2  christos 	bend = bp;
    734  1.55.10.2  christos 	*(--bp) = '\0';
    735  1.55.10.2  christos 
    736  1.55.10.2  christos 	/*
    737  1.55.10.2  christos 	 * 5th argument here is "max number of vnodes to traverse".
    738  1.55.10.2  christos 	 * Since each entry takes up at least 2 bytes in the output buffer,
    739  1.55.10.2  christos 	 * limit it to N/2 vnodes for an N byte buffer.
    740  1.55.10.2  christos 	 */
    741  1.55.10.2  christos #define GETCWD_CHECK_ACCESS 0x0001
    742  1.55.10.2  christos 	cwdi = p->p_cwdi;
    743  1.55.10.2  christos 	rw_enter(&cwdi->cwdi_lock, RW_READER);
    744  1.55.10.2  christos 	error = getcwd_common (cwdi->cwdi_cdir, NULL, &bp, path, len/2,
    745  1.55.10.2  christos 			       GETCWD_CHECK_ACCESS, l);
    746  1.55.10.2  christos 	rw_exit(&cwdi->cwdi_lock);
    747  1.55.10.2  christos 
    748  1.55.10.2  christos 	if (error)
    749  1.55.10.2  christos 		goto out;
    750  1.55.10.2  christos 	lenused = bend - bp;
    751  1.55.10.2  christos 	*retval = lenused;
    752  1.55.10.2  christos 	/* put the result into user buffer */
    753  1.55.10.2  christos 	error = copyout(bp, SCARG_P32(uap, bufp), lenused);
    754  1.55.10.2  christos 
    755  1.55.10.2  christos out:
    756  1.55.10.2  christos 	free(path, M_TEMP);
    757  1.55.10.2  christos 	return error;
    758  1.55.10.2  christos }
    759