Home | History | Annotate | Line # | Download | only in common
vfs_syscalls_43.c revision 1.66
      1  1.66  jdolecek /*	$NetBSD: vfs_syscalls_43.c,v 1.66 2020/06/24 10:28:16 jdolecek Exp $	*/
      2   1.1  christos 
      3   1.1  christos /*
      4   1.1  christos  * Copyright (c) 1989, 1993
      5   1.1  christos  *	The Regents of the University of California.  All rights reserved.
      6   1.1  christos  * (c) UNIX System Laboratories, Inc.
      7   1.1  christos  * All or some portions of this file are derived from material licensed
      8   1.1  christos  * to the University of California by American Telephone and Telegraph
      9   1.1  christos  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
     10   1.1  christos  * the permission of UNIX System Laboratories, Inc.
     11   1.1  christos  *
     12   1.1  christos  * Redistribution and use in source and binary forms, with or without
     13   1.1  christos  * modification, are permitted provided that the following conditions
     14   1.1  christos  * are met:
     15   1.1  christos  * 1. Redistributions of source code must retain the above copyright
     16   1.1  christos  *    notice, this list of conditions and the following disclaimer.
     17   1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     18   1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     19   1.1  christos  *    documentation and/or other materials provided with the distribution.
     20  1.25       agc  * 3. Neither the name of the University nor the names of its contributors
     21   1.1  christos  *    may be used to endorse or promote products derived from this software
     22   1.1  christos  *    without specific prior written permission.
     23   1.1  christos  *
     24   1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25   1.1  christos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26   1.1  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27   1.1  christos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28   1.1  christos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29   1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30   1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31   1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32   1.1  christos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33   1.1  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34   1.1  christos  * SUCH DAMAGE.
     35   1.1  christos  *
     36   1.1  christos  *	@(#)vfs_syscalls.c	8.28 (Berkeley) 12/10/94
     37   1.1  christos  */
     38  1.20     lukem 
     39  1.20     lukem #include <sys/cdefs.h>
     40  1.66  jdolecek __KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_43.c,v 1.66 2020/06/24 10:28:16 jdolecek Exp $");
     41   1.9   thorpej 
     42  1.18       mrg #if defined(_KERNEL_OPT)
     43  1.50    dyoung #include "opt_compat_netbsd.h"
     44  1.15  jdolecek #endif
     45   1.1  christos 
     46   1.1  christos #include <sys/param.h>
     47   1.1  christos #include <sys/systm.h>
     48   1.1  christos #include <sys/filedesc.h>
     49   1.1  christos #include <sys/kernel.h>
     50   1.1  christos #include <sys/proc.h>
     51   1.1  christos #include <sys/file.h>
     52   1.1  christos #include <sys/vnode.h>
     53   1.1  christos #include <sys/namei.h>
     54   1.1  christos #include <sys/dirent.h>
     55   1.1  christos #include <sys/socket.h>
     56   1.1  christos #include <sys/socketvar.h>
     57   1.1  christos #include <sys/stat.h>
     58  1.27  christos #include <sys/malloc.h>
     59   1.1  christos #include <sys/ioctl.h>
     60   1.1  christos #include <sys/fcntl.h>
     61   1.1  christos #include <sys/syslog.h>
     62   1.1  christos #include <sys/unistd.h>
     63   1.1  christos #include <sys/resourcevar.h>
     64   1.1  christos 
     65   1.1  christos #include <sys/mount.h>
     66  1.64  pgoyette #include <sys/syscall.h>
     67  1.64  pgoyette #include <sys/syscallvar.h>
     68   1.1  christos #include <sys/syscallargs.h>
     69  1.37       dsl #include <sys/vfs_syscalls.h>
     70   1.1  christos 
     71  1.30  christos #include <compat/sys/stat.h>
     72  1.30  christos #include <compat/sys/mount.h>
     73  1.56  christos #include <compat/sys/dirent.h>
     74  1.30  christos 
     75  1.48        ad #include <compat/common/compat_util.h>
     76  1.55  pgoyette #include <compat/common/compat_mod.h>
     77  1.48        ad 
     78  1.58       mrg static void cvttimespec(struct timespec *, struct timespec50 *);
     79  1.42       dsl static void cvtstat(struct stat *, struct stat43 *);
     80   1.4  christos 
     81  1.64  pgoyette static struct syscall_package vfs_syscalls_43_syscalls[] = {
     82  1.65  pgoyette 	{ SYS_compat_43_oquota,     0, (sy_call_t *)compat_43_sys_quota },
     83  1.65  pgoyette 	{ SYS_compat_43_stat43,     0, (sy_call_t *)compat_43_sys_stat },
     84  1.65  pgoyette 	{ SYS_compat_43_lstat43,    0, (sy_call_t *)compat_43_sys_lstat },
     85  1.65  pgoyette 	{ SYS_compat_43_fstat43,    0, (sy_call_t *)compat_43_sys_fstat },
     86  1.65  pgoyette 	{ SYS_compat_43_otruncate,  0, (sy_call_t *)compat_43_sys_ftruncate },
     87  1.65  pgoyette 	{ SYS_compat_43_oftruncate, 0, (sy_call_t *)compat_43_sys_ftruncate },
     88  1.65  pgoyette 	{ SYS_compat_43_olseek,     0, (sy_call_t *)compat_43_sys_lseek },
     89  1.65  pgoyette 	{ SYS_compat_43_ocreat,     0, (sy_call_t *)compat_43_sys_creat },
     90  1.65  pgoyette 	{ SYS_compat_43_ogetdirentries, 0,
     91  1.65  pgoyette 	    (sy_call_t *)compat_43_sys_getdirentries },
     92  1.64  pgoyette 	{ 0, 0, NULL }
     93  1.64  pgoyette };
     94  1.64  pgoyette 
     95   1.1  christos /*
     96  1.58       mrg  * Convert from an old to a new timespec structure.
     97  1.58       mrg  */
     98  1.58       mrg static void
     99  1.58       mrg cvttimespec(struct timespec *ts, struct timespec50 *ots)
    100  1.58       mrg {
    101  1.58       mrg 
    102  1.58       mrg 	if (ts->tv_sec > INT_MAX) {
    103  1.58       mrg #if defined(DEBUG) || 1
    104  1.58       mrg 		static bool first = true;
    105  1.58       mrg 
    106  1.58       mrg 		if (first) {
    107  1.58       mrg 			first = false;
    108  1.58       mrg 			printf("%s[%s:%d]: time_t does not fit\n",
    109  1.58       mrg 			    __func__, curlwp->l_proc->p_comm,
    110  1.58       mrg 			    curlwp->l_lid);
    111  1.58       mrg 		}
    112  1.58       mrg #endif
    113  1.58       mrg 		ots->tv_sec = INT_MAX;
    114  1.58       mrg 	} else
    115  1.58       mrg 		ots->tv_sec = ts->tv_sec;
    116  1.58       mrg 	ots->tv_nsec = ts->tv_nsec;
    117  1.58       mrg }
    118  1.58       mrg 
    119  1.58       mrg /*
    120   1.1  christos  * Convert from an old to a new stat structure.
    121   1.1  christos  */
    122   1.4  christos static void
    123  1.43       dsl cvtstat(struct stat *st, struct stat43 *ost)
    124   1.1  christos {
    125   1.1  christos 
    126  1.58       mrg 	/* Handle any padding. */
    127  1.58       mrg 	memset(ost, 0, sizeof *ost);
    128   1.1  christos 	ost->st_dev = st->st_dev;
    129   1.1  christos 	ost->st_ino = st->st_ino;
    130  1.11  wrstuden 	ost->st_mode = st->st_mode & 0xffff;
    131   1.1  christos 	ost->st_nlink = st->st_nlink;
    132   1.1  christos 	ost->st_uid = st->st_uid;
    133   1.1  christos 	ost->st_gid = st->st_gid;
    134   1.1  christos 	ost->st_rdev = st->st_rdev;
    135   1.1  christos 	if (st->st_size < (quad_t)1 << 32)
    136   1.1  christos 		ost->st_size = st->st_size;
    137   1.1  christos 	else
    138   1.1  christos 		ost->st_size = -2;
    139  1.58       mrg 	cvttimespec(&st->st_atimespec, &ost->st_atimespec);
    140  1.58       mrg 	cvttimespec(&st->st_mtimespec, &ost->st_mtimespec);
    141  1.58       mrg 	cvttimespec(&st->st_ctimespec, &ost->st_ctimespec);
    142   1.1  christos 	ost->st_blksize = st->st_blksize;
    143   1.1  christos 	ost->st_blocks = st->st_blocks;
    144   1.1  christos 	ost->st_flags = st->st_flags;
    145   1.1  christos 	ost->st_gen = st->st_gen;
    146   1.1  christos }
    147   1.1  christos 
    148   1.1  christos /*
    149   1.1  christos  * Get file status; this version follows links.
    150   1.1  christos  */
    151   1.1  christos /* ARGSUSED */
    152   1.1  christos int
    153  1.45       dsl compat_43_sys_stat(struct lwp *l, const struct compat_43_sys_stat_args *uap, register_t *retval)
    154   1.2   thorpej {
    155  1.45       dsl 	/* {
    156   1.1  christos 		syscallarg(char *) path;
    157   1.8  christos 		syscallarg(struct stat43 *) ub;
    158  1.45       dsl 	} */
    159   1.1  christos 	struct stat sb;
    160   1.8  christos 	struct stat43 osb;
    161   1.1  christos 	int error;
    162   1.1  christos 
    163  1.46        ad 	error = do_sys_stat(SCARG(uap, path), FOLLOW, &sb);
    164   1.1  christos 	if (error)
    165   1.1  christos 		return (error);
    166   1.1  christos 	cvtstat(&sb, &osb);
    167  1.36  christos 	error = copyout((void *)&osb, (void *)SCARG(uap, ub), sizeof (osb));
    168   1.1  christos 	return (error);
    169   1.1  christos }
    170   1.1  christos 
    171   1.1  christos /*
    172   1.1  christos  * Get file status; this version does not follow links.
    173   1.1  christos  */
    174   1.1  christos /* ARGSUSED */
    175   1.1  christos int
    176  1.45       dsl compat_43_sys_lstat(struct lwp *l, const struct compat_43_sys_lstat_args *uap, register_t *retval)
    177   1.2   thorpej {
    178  1.45       dsl 	/* {
    179   1.1  christos 		syscallarg(char *) path;
    180  1.10      fvdl 		syscallarg(struct ostat *) ub;
    181  1.45       dsl 	} */
    182  1.66  jdolecek 	struct stat sb;
    183   1.8  christos 	struct stat43 osb;
    184   1.1  christos 	int error;
    185   1.1  christos 
    186  1.66  jdolecek 	error = do_sys_stat(SCARG(uap, path), NOFOLLOW, &sb);
    187  1.66  jdolecek 	if (error)
    188  1.54  dholland 		return error;
    189  1.54  dholland 
    190  1.10      fvdl 	/*
    191  1.66  jdolecek 	 * For symbolic links, BSD4.3 returned the attributes of its
    192  1.10      fvdl 	 * containing directory, except for mode, size, and links.
    193  1.66  jdolecek 	 * This is no longer emulated, the parent directory is not consulted.
    194  1.10      fvdl 	 */
    195   1.1  christos 	cvtstat(&sb, &osb);
    196  1.36  christos 	error = copyout((void *)&osb, (void *)SCARG(uap, ub), sizeof (osb));
    197   1.1  christos 	return (error);
    198   1.1  christos }
    199   1.1  christos 
    200   1.1  christos /*
    201   1.1  christos  * Return status information about a file descriptor.
    202   1.1  christos  */
    203   1.1  christos /* ARGSUSED */
    204   1.4  christos int
    205  1.45       dsl compat_43_sys_fstat(struct lwp *l, const struct compat_43_sys_fstat_args *uap, register_t *retval)
    206   1.2   thorpej {
    207  1.45       dsl 	/* {
    208   1.1  christos 		syscallarg(int) fd;
    209   1.8  christos 		syscallarg(struct stat43 *) sb;
    210  1.45       dsl 	} */
    211   1.1  christos 	struct stat ub;
    212   1.8  christos 	struct stat43 oub;
    213   1.1  christos 	int error;
    214   1.1  christos 
    215  1.49     njoly 	error = do_sys_fstat(SCARG(uap, fd), &ub);
    216  1.16  jdolecek 	if (error == 0) {
    217  1.16  jdolecek 		cvtstat(&ub, &oub);
    218  1.36  christos 		error = copyout((void *)&oub, (void *)SCARG(uap, sb),
    219   1.1  christos 		    sizeof (oub));
    220  1.16  jdolecek 	}
    221  1.16  jdolecek 
    222   1.1  christos 	return (error);
    223   1.1  christos }
    224   1.1  christos 
    225   1.1  christos 
    226   1.1  christos /*
    227   1.1  christos  * Truncate a file given a file descriptor.
    228   1.1  christos  */
    229   1.1  christos /* ARGSUSED */
    230   1.1  christos int
    231  1.45       dsl compat_43_sys_ftruncate(struct lwp *l, const struct compat_43_sys_ftruncate_args *uap, register_t *retval)
    232   1.2   thorpej {
    233  1.45       dsl 	/* {
    234   1.1  christos 		syscallarg(int) fd;
    235   1.1  christos 		syscallarg(long) length;
    236  1.45       dsl 	} */
    237   1.3   mycroft 	struct sys_ftruncate_args /* {
    238   1.1  christos 		syscallarg(int) fd;
    239   1.1  christos 		syscallarg(int) pad;
    240   1.1  christos 		syscallarg(off_t) length;
    241   1.1  christos 	} */ nuap;
    242   1.1  christos 
    243   1.1  christos 	SCARG(&nuap, fd) = SCARG(uap, fd);
    244   1.1  christos 	SCARG(&nuap, length) = SCARG(uap, length);
    245  1.22   thorpej 	return (sys_ftruncate(l, &nuap, retval));
    246   1.1  christos }
    247   1.1  christos 
    248   1.1  christos /*
    249   1.1  christos  * Truncate a file given its path name.
    250   1.1  christos  */
    251   1.1  christos /* ARGSUSED */
    252   1.1  christos int
    253  1.45       dsl compat_43_sys_truncate(struct lwp *l, const struct compat_43_sys_truncate_args *uap, register_t *retval)
    254   1.2   thorpej {
    255  1.45       dsl 	/* {
    256   1.1  christos 		syscallarg(char *) path;
    257   1.1  christos 		syscallarg(long) length;
    258  1.45       dsl 	} */
    259   1.3   mycroft 	struct sys_truncate_args /* {
    260   1.1  christos 		syscallarg(char *) path;
    261   1.1  christos 		syscallarg(int) pad;
    262   1.1  christos 		syscallarg(off_t) length;
    263   1.1  christos 	} */ nuap;
    264   1.1  christos 
    265   1.1  christos 	SCARG(&nuap, path) = SCARG(uap, path);
    266   1.1  christos 	SCARG(&nuap, length) = SCARG(uap, length);
    267  1.22   thorpej 	return (sys_truncate(l, &nuap, retval));
    268   1.1  christos }
    269   1.1  christos 
    270   1.1  christos 
    271   1.1  christos /*
    272   1.1  christos  * Reposition read/write file offset.
    273   1.1  christos  */
    274   1.1  christos int
    275  1.45       dsl compat_43_sys_lseek(struct lwp *l, const struct compat_43_sys_lseek_args *uap, register_t *retval)
    276   1.2   thorpej {
    277  1.45       dsl 	/* {
    278   1.1  christos 		syscallarg(int) fd;
    279   1.1  christos 		syscallarg(long) offset;
    280   1.1  christos 		syscallarg(int) whence;
    281  1.45       dsl 	} */
    282   1.3   mycroft 	struct sys_lseek_args /* {
    283   1.1  christos 		syscallarg(int) fd;
    284   1.1  christos 		syscallarg(int) pad;
    285   1.1  christos 		syscallarg(off_t) offset;
    286   1.1  christos 		syscallarg(int) whence;
    287   1.1  christos 	} */ nuap;
    288   1.1  christos 	off_t qret;
    289   1.1  christos 	int error;
    290   1.1  christos 
    291   1.1  christos 	SCARG(&nuap, fd) = SCARG(uap, fd);
    292   1.1  christos 	SCARG(&nuap, offset) = SCARG(uap, offset);
    293   1.1  christos 	SCARG(&nuap, whence) = SCARG(uap, whence);
    294  1.57      matt 	error = sys_lseek(l, &nuap, (register_t *)&qret);
    295   1.1  christos 	*(long *)retval = qret;
    296   1.1  christos 	return (error);
    297   1.1  christos }
    298   1.1  christos 
    299   1.1  christos 
    300   1.1  christos /*
    301   1.1  christos  * Create a file.
    302   1.1  christos  */
    303   1.1  christos int
    304  1.45       dsl compat_43_sys_creat(struct lwp *l, const struct compat_43_sys_creat_args *uap, register_t *retval)
    305   1.2   thorpej {
    306  1.45       dsl 	/* {
    307   1.1  christos 		syscallarg(char *) path;
    308   1.1  christos 		syscallarg(int) mode;
    309  1.45       dsl 	} */
    310   1.3   mycroft 	struct sys_open_args /* {
    311   1.1  christos 		syscallarg(char *) path;
    312   1.1  christos 		syscallarg(int) flags;
    313   1.1  christos 		syscallarg(int) mode;
    314   1.1  christos 	} */ nuap;
    315   1.1  christos 
    316   1.1  christos 	SCARG(&nuap, path) = SCARG(uap, path);
    317   1.1  christos 	SCARG(&nuap, mode) = SCARG(uap, mode);
    318   1.1  christos 	SCARG(&nuap, flags) = O_WRONLY | O_CREAT | O_TRUNC;
    319  1.22   thorpej 	return (sys_open(l, &nuap, retval));
    320   1.1  christos }
    321   1.1  christos 
    322   1.1  christos /*ARGSUSED*/
    323   1.1  christos int
    324  1.45       dsl compat_43_sys_quota(struct lwp *l, const void *v, register_t *retval)
    325   1.1  christos {
    326   1.1  christos 
    327   1.1  christos 	return (ENOSYS);
    328   1.1  christos }
    329   1.1  christos 
    330   1.1  christos 
    331   1.1  christos /*
    332   1.1  christos  * Read a block of directory entries in a file system independent format.
    333   1.1  christos  */
    334   1.1  christos int
    335  1.45       dsl compat_43_sys_getdirentries(struct lwp *l, const struct compat_43_sys_getdirentries_args *uap, register_t *retval)
    336   1.2   thorpej {
    337  1.45       dsl 	/* {
    338   1.1  christos 		syscallarg(int) fd;
    339   1.1  christos 		syscallarg(char *) buf;
    340   1.1  christos 		syscallarg(u_int) count;
    341   1.1  christos 		syscallarg(long *) basep;
    342  1.45       dsl 	} */
    343  1.56  christos 	struct dirent *bdp;
    344  1.13  augustss 	struct vnode *vp;
    345  1.57      matt 	void *tbuf;			/* Current-format */
    346  1.57      matt 	char *inp;			/* Current-format */
    347  1.56  christos 	int len, reclen;		/* Current-format */
    348  1.56  christos 	char *outp;			/* Dirent12-format */
    349  1.56  christos 	int resid, old_reclen = 0;	/* Dirent12-format */
    350   1.1  christos 	struct file *fp;
    351  1.56  christos 	struct uio auio;
    352  1.56  christos 	struct iovec aiov;
    353  1.56  christos 	struct dirent43 idb;
    354  1.56  christos 	off_t off;		/* true file offset */
    355  1.56  christos 	int buflen, error, eofflag, nbytes;
    356  1.56  christos 	struct vattr va;
    357  1.56  christos 	off_t *cookiebuf = NULL, *cookie;
    358  1.56  christos 	int ncookies;
    359   1.1  christos 	long loff;
    360  1.56  christos 
    361  1.47        ad 	/* fd_getvnode() will use the descriptor for us */
    362  1.47        ad 	if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
    363   1.1  christos 		return (error);
    364  1.56  christos 
    365  1.12   thorpej 	if ((fp->f_flag & FREAD) == 0) {
    366  1.12   thorpej 		error = EBADF;
    367  1.56  christos 		goto out1;
    368  1.12   thorpej 	}
    369  1.56  christos 
    370  1.57      matt 	vp = fp->f_vnode;
    371  1.12   thorpej 	if (vp->v_type != VDIR) {
    372  1.56  christos 		error = ENOTDIR;
    373  1.56  christos 		goto out1;
    374  1.12   thorpej 	}
    375  1.56  christos 
    376  1.56  christos 	vn_lock(vp, LK_SHARED | LK_RETRY);
    377  1.56  christos 	error = VOP_GETATTR(vp, &va, l->l_cred);
    378  1.56  christos 	VOP_UNLOCK(vp);
    379  1.56  christos 	if (error)
    380  1.56  christos 		goto out1;
    381  1.56  christos 
    382  1.56  christos 	loff = fp->f_offset;
    383  1.56  christos 	nbytes = SCARG(uap, count);
    384  1.63  riastrad 	buflen = uimin(MAXBSIZE, nbytes);
    385  1.56  christos 	if (buflen < va.va_blocksize)
    386  1.56  christos 		buflen = va.va_blocksize;
    387  1.56  christos 	tbuf = malloc(buflen, M_TEMP, M_WAITOK);
    388  1.56  christos 
    389  1.56  christos 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    390  1.56  christos 	off = fp->f_offset;
    391  1.56  christos again:
    392  1.56  christos 	aiov.iov_base = tbuf;
    393  1.56  christos 	aiov.iov_len = buflen;
    394   1.1  christos 	auio.uio_iov = &aiov;
    395   1.1  christos 	auio.uio_iovcnt = 1;
    396   1.1  christos 	auio.uio_rw = UIO_READ;
    397  1.56  christos 	auio.uio_resid = buflen;
    398  1.56  christos 	auio.uio_offset = off;
    399  1.56  christos 	UIO_SETUP_SYSSPACE(&auio);
    400  1.56  christos 	/*
    401  1.56  christos          * First we read into the malloc'ed buffer, then
    402  1.56  christos          * we massage it into user space, one record at a time.
    403  1.56  christos          */
    404  1.56  christos 	error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &cookiebuf,
    405  1.56  christos 	    &ncookies);
    406  1.56  christos 	if (error)
    407  1.56  christos 		goto out;
    408  1.56  christos 
    409  1.57      matt 	inp = (char *)tbuf;
    410  1.56  christos 	outp = SCARG(uap, buf);
    411  1.56  christos 	resid = nbytes;
    412  1.56  christos 	if ((len = buflen - auio.uio_resid) == 0)
    413  1.56  christos 		goto eof;
    414  1.56  christos 
    415  1.56  christos 	for (cookie = cookiebuf; len > 0; len -= reclen) {
    416  1.56  christos 		bdp = (struct dirent *)inp;
    417  1.56  christos 		reclen = bdp->d_reclen;
    418  1.60  riastrad 		if (reclen & 3) {
    419  1.60  riastrad 			error = EIO;
    420  1.60  riastrad 			goto out;
    421  1.60  riastrad 		}
    422  1.56  christos 		if (bdp->d_fileno == 0) {
    423  1.56  christos 			inp += reclen;	/* it is a hole; squish it out */
    424  1.56  christos 			if (cookie)
    425  1.56  christos 				off = *cookie++;
    426  1.56  christos 			else
    427  1.56  christos 				off += reclen;
    428  1.56  christos 			continue;
    429  1.56  christos 		}
    430  1.62  christos 		if (bdp->d_namlen >= sizeof(idb.d_name))
    431  1.62  christos 			idb.d_namlen = sizeof(idb.d_name) - 1;
    432  1.62  christos 		else
    433  1.62  christos 			idb.d_namlen = bdp->d_namlen;
    434  1.56  christos 		old_reclen = _DIRENT_RECLEN(&idb, bdp->d_namlen);
    435  1.56  christos 		if (reclen > len || resid < old_reclen) {
    436  1.56  christos 			/* entry too big for buffer, so just stop */
    437  1.56  christos 			outp++;
    438  1.56  christos 			break;
    439   1.1  christos 		}
    440  1.56  christos 		/*
    441  1.56  christos 		 * Massage in place to make a Dirent12-shaped dirent (otherwise
    442  1.56  christos 		 * we have to worry about touching user memory outside of
    443  1.56  christos 		 * the copyout() call).
    444  1.56  christos 		 */
    445  1.56  christos 		idb.d_fileno = (uint32_t)bdp->d_fileno;
    446  1.56  christos 		idb.d_reclen = (uint16_t)old_reclen;
    447  1.62  christos 		idb.d_fileno = (uint32_t)bdp->d_fileno;
    448  1.62  christos 		(void)memcpy(idb.d_name, bdp->d_name, idb.d_namlen);
    449  1.62  christos 		memset(idb.d_name + idb.d_namlen, 0,
    450  1.62  christos 		    idb.d_reclen - _DIRENT_NAMEOFF(&idb) - idb.d_namlen);
    451  1.56  christos 		if ((error = copyout(&idb, outp, old_reclen)))
    452  1.56  christos 			goto out;
    453  1.56  christos 		/* advance past this real entry */
    454  1.56  christos 		inp += reclen;
    455  1.56  christos 		if (cookie)
    456  1.56  christos 			off = *cookie++; /* each entry points to itself */
    457  1.56  christos 		else
    458  1.56  christos 			off += reclen;
    459  1.56  christos 		/* advance output past Dirent12-shaped entry */
    460  1.56  christos 		outp += old_reclen;
    461  1.56  christos 		resid -= old_reclen;
    462   1.1  christos 	}
    463   1.1  christos 
    464  1.56  christos 	/* if we squished out the whole block, try again */
    465  1.56  christos 	if (outp == SCARG(uap, buf)) {
    466  1.56  christos 		if (cookiebuf)
    467  1.56  christos 			free(cookiebuf, M_TEMP);
    468  1.56  christos 		cookiebuf = NULL;
    469  1.56  christos 		goto again;
    470   1.1  christos 	}
    471  1.56  christos 	fp->f_offset = off;	/* update the vnode offset */
    472  1.56  christos 
    473  1.56  christos eof:
    474  1.56  christos 	*retval = nbytes - resid;
    475  1.56  christos out:
    476  1.56  christos 	VOP_UNLOCK(vp);
    477  1.56  christos 	if (cookiebuf)
    478  1.56  christos 		free(cookiebuf, M_TEMP);
    479  1.56  christos 	free(tbuf, M_TEMP);
    480  1.56  christos out1:
    481  1.46        ad 	fd_putfile(SCARG(uap, fd));
    482  1.56  christos 	if (error)
    483  1.56  christos 		return error;
    484  1.56  christos 	return copyout(&loff, SCARG(uap, basep), sizeof(long));
    485   1.1  christos }
    486  1.30  christos 
    487  1.64  pgoyette int
    488  1.64  pgoyette vfs_syscalls_43_init(void)
    489  1.64  pgoyette {
    490  1.64  pgoyette 
    491  1.64  pgoyette 	return syscall_establish(NULL, vfs_syscalls_43_syscalls);
    492  1.64  pgoyette }
    493  1.48        ad 
    494  1.64  pgoyette int
    495  1.64  pgoyette vfs_syscalls_43_fini(void)
    496  1.30  christos {
    497  1.30  christos 
    498  1.64  pgoyette 	return syscall_disestablish(NULL, vfs_syscalls_43_syscalls);
    499  1.30  christos }
    500