Home | History | Annotate | Line # | Download | only in common
vfs_syscalls_43.c revision 1.47.2.1
      1  1.47.2.1      haad /*	$NetBSD: vfs_syscalls_43.c,v 1.47.2.1 2008/12/13 01:13:47 haad 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.47.2.1      haad __KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_43.c,v 1.47.2.1 2008/12/13 01:13:47 haad Exp $");
     41       1.9   thorpej 
     42      1.18       mrg #if defined(_KERNEL_OPT)
     43       1.9   thorpej #include "fs_union.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.30  christos #include <sys/sysctl.h>
     65       1.1  christos 
     66       1.1  christos #include <sys/mount.h>
     67       1.1  christos #include <sys/syscallargs.h>
     68      1.37       dsl #include <sys/vfs_syscalls.h>
     69       1.1  christos 
     70      1.30  christos #include <compat/sys/stat.h>
     71      1.30  christos #include <compat/sys/mount.h>
     72      1.30  christos 
     73  1.47.2.1      haad #include <compat/common/compat_util.h>
     74  1.47.2.1      haad 
     75      1.42       dsl static void cvtstat(struct stat *, struct stat43 *);
     76       1.4  christos 
     77       1.1  christos /*
     78       1.1  christos  * Convert from an old to a new stat structure.
     79       1.1  christos  */
     80       1.4  christos static void
     81      1.43       dsl cvtstat(struct stat *st, struct stat43 *ost)
     82       1.1  christos {
     83       1.1  christos 
     84       1.1  christos 	ost->st_dev = st->st_dev;
     85       1.1  christos 	ost->st_ino = st->st_ino;
     86      1.11  wrstuden 	ost->st_mode = st->st_mode & 0xffff;
     87       1.1  christos 	ost->st_nlink = st->st_nlink;
     88       1.1  christos 	ost->st_uid = st->st_uid;
     89       1.1  christos 	ost->st_gid = st->st_gid;
     90       1.1  christos 	ost->st_rdev = st->st_rdev;
     91       1.1  christos 	if (st->st_size < (quad_t)1 << 32)
     92       1.1  christos 		ost->st_size = st->st_size;
     93       1.1  christos 	else
     94       1.1  christos 		ost->st_size = -2;
     95       1.1  christos 	ost->st_atime = st->st_atime;
     96       1.1  christos 	ost->st_mtime = st->st_mtime;
     97       1.1  christos 	ost->st_ctime = st->st_ctime;
     98       1.1  christos 	ost->st_blksize = st->st_blksize;
     99       1.1  christos 	ost->st_blocks = st->st_blocks;
    100       1.1  christos 	ost->st_flags = st->st_flags;
    101       1.1  christos 	ost->st_gen = st->st_gen;
    102       1.1  christos }
    103       1.1  christos 
    104       1.1  christos /*
    105       1.1  christos  * Get file status; this version follows links.
    106       1.1  christos  */
    107       1.1  christos /* ARGSUSED */
    108       1.1  christos int
    109      1.45       dsl compat_43_sys_stat(struct lwp *l, const struct compat_43_sys_stat_args *uap, register_t *retval)
    110       1.2   thorpej {
    111      1.45       dsl 	/* {
    112       1.1  christos 		syscallarg(char *) path;
    113       1.8  christos 		syscallarg(struct stat43 *) ub;
    114      1.45       dsl 	} */
    115       1.1  christos 	struct stat sb;
    116       1.8  christos 	struct stat43 osb;
    117       1.1  christos 	int error;
    118       1.1  christos 
    119      1.46        ad 	error = do_sys_stat(SCARG(uap, path), FOLLOW, &sb);
    120       1.1  christos 	if (error)
    121       1.1  christos 		return (error);
    122       1.1  christos 	cvtstat(&sb, &osb);
    123      1.36  christos 	error = copyout((void *)&osb, (void *)SCARG(uap, ub), sizeof (osb));
    124       1.1  christos 	return (error);
    125       1.1  christos }
    126       1.1  christos 
    127       1.1  christos /*
    128       1.1  christos  * Get file status; this version does not follow links.
    129       1.1  christos  */
    130       1.1  christos /* ARGSUSED */
    131       1.1  christos int
    132      1.45       dsl compat_43_sys_lstat(struct lwp *l, const struct compat_43_sys_lstat_args *uap, register_t *retval)
    133       1.2   thorpej {
    134      1.45       dsl 	/* {
    135       1.1  christos 		syscallarg(char *) path;
    136      1.10      fvdl 		syscallarg(struct ostat *) ub;
    137      1.45       dsl 	} */
    138      1.10      fvdl 	struct vnode *vp, *dvp;
    139      1.10      fvdl 	struct stat sb, sb1;
    140       1.8  christos 	struct stat43 osb;
    141       1.1  christos 	int error;
    142       1.1  christos 	struct nameidata nd;
    143      1.14        pk 	int ndflags;
    144       1.1  christos 
    145      1.38       dsl 	ndflags = NOFOLLOW | LOCKLEAF | LOCKPARENT | TRYEMULROOT;
    146      1.14        pk again:
    147      1.44     pooka 	NDINIT(&nd, LOOKUP, ndflags, UIO_USERSPACE, SCARG(uap, path));
    148      1.14        pk 	if ((error = namei(&nd))) {
    149      1.14        pk 		if (error == EISDIR && (ndflags & LOCKPARENT) != 0) {
    150      1.14        pk 			/*
    151      1.14        pk 			 * Should only happen on '/'. Retry without LOCKPARENT;
    152      1.14        pk 			 * this is safe since the vnode won't be a VLNK.
    153      1.14        pk 			 */
    154      1.14        pk 			ndflags &= ~LOCKPARENT;
    155      1.14        pk 			goto again;
    156      1.14        pk 		}
    157       1.5  christos 		return (error);
    158      1.14        pk 	}
    159      1.10      fvdl 	/*
    160      1.10      fvdl 	 * For symbolic links, always return the attributes of its
    161      1.10      fvdl 	 * containing directory, except for mode, size, and links.
    162      1.10      fvdl 	 */
    163      1.10      fvdl 	vp = nd.ni_vp;
    164      1.10      fvdl 	dvp = nd.ni_dvp;
    165      1.10      fvdl 	if (vp->v_type != VLNK) {
    166      1.14        pk 		if ((ndflags & LOCKPARENT) != 0) {
    167      1.14        pk 			if (dvp == vp)
    168      1.14        pk 				vrele(dvp);
    169      1.14        pk 			else
    170      1.14        pk 				vput(dvp);
    171      1.14        pk 		}
    172      1.46        ad 		error = vn_stat(vp, &sb);
    173      1.10      fvdl 		vput(vp);
    174      1.10      fvdl 		if (error)
    175      1.10      fvdl 			return (error);
    176      1.10      fvdl 	} else {
    177      1.46        ad 		error = vn_stat(dvp, &sb);
    178      1.10      fvdl 		vput(dvp);
    179      1.10      fvdl 		if (error) {
    180      1.10      fvdl 			vput(vp);
    181      1.10      fvdl 			return (error);
    182      1.10      fvdl 		}
    183      1.46        ad 		error = vn_stat(vp, &sb1);
    184      1.10      fvdl 		vput(vp);
    185      1.10      fvdl 		if (error)
    186      1.10      fvdl 			return (error);
    187      1.10      fvdl 		sb.st_mode &= ~S_IFDIR;
    188      1.10      fvdl 		sb.st_mode |= S_IFLNK;
    189      1.10      fvdl 		sb.st_nlink = sb1.st_nlink;
    190      1.10      fvdl 		sb.st_size = sb1.st_size;
    191      1.10      fvdl 		sb.st_blocks = sb1.st_blocks;
    192      1.10      fvdl 	}
    193       1.1  christos 	cvtstat(&sb, &osb);
    194      1.36  christos 	error = copyout((void *)&osb, (void *)SCARG(uap, ub), sizeof (osb));
    195       1.1  christos 	return (error);
    196       1.1  christos }
    197       1.1  christos 
    198       1.1  christos /*
    199       1.1  christos  * Return status information about a file descriptor.
    200       1.1  christos  */
    201       1.1  christos /* ARGSUSED */
    202       1.4  christos int
    203      1.45       dsl compat_43_sys_fstat(struct lwp *l, const struct compat_43_sys_fstat_args *uap, register_t *retval)
    204       1.2   thorpej {
    205      1.45       dsl 	/* {
    206       1.1  christos 		syscallarg(int) fd;
    207       1.8  christos 		syscallarg(struct stat43 *) sb;
    208      1.45       dsl 	} */
    209       1.1  christos 	int fd = SCARG(uap, fd);
    210      1.13  augustss 	struct file *fp;
    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.46        ad 	if ((fp = fd_getfile(fd)) == NULL)
    216       1.1  christos 		return (EBADF);
    217      1.46        ad 	error = (*fp->f_ops->fo_stat)(fp, &ub);
    218      1.46        ad 	fd_putfile(fd);
    219      1.16  jdolecek 	if (error == 0) {
    220      1.16  jdolecek 		cvtstat(&ub, &oub);
    221      1.36  christos 		error = copyout((void *)&oub, (void *)SCARG(uap, sb),
    222       1.1  christos 		    sizeof (oub));
    223      1.16  jdolecek 	}
    224      1.16  jdolecek 
    225      1.29     perry 
    226       1.1  christos 	return (error);
    227       1.1  christos }
    228       1.1  christos 
    229       1.1  christos 
    230       1.1  christos /*
    231       1.1  christos  * Truncate a file given a file descriptor.
    232       1.1  christos  */
    233       1.1  christos /* ARGSUSED */
    234       1.1  christos int
    235      1.45       dsl compat_43_sys_ftruncate(struct lwp *l, const struct compat_43_sys_ftruncate_args *uap, register_t *retval)
    236       1.2   thorpej {
    237      1.45       dsl 	/* {
    238       1.1  christos 		syscallarg(int) fd;
    239       1.1  christos 		syscallarg(long) length;
    240      1.45       dsl 	} */
    241       1.3   mycroft 	struct sys_ftruncate_args /* {
    242       1.1  christos 		syscallarg(int) fd;
    243       1.1  christos 		syscallarg(int) pad;
    244       1.1  christos 		syscallarg(off_t) length;
    245       1.1  christos 	} */ nuap;
    246       1.1  christos 
    247       1.1  christos 	SCARG(&nuap, fd) = SCARG(uap, fd);
    248       1.1  christos 	SCARG(&nuap, length) = SCARG(uap, length);
    249      1.22   thorpej 	return (sys_ftruncate(l, &nuap, retval));
    250       1.1  christos }
    251       1.1  christos 
    252       1.1  christos /*
    253       1.1  christos  * Truncate a file given its path name.
    254       1.1  christos  */
    255       1.1  christos /* ARGSUSED */
    256       1.1  christos int
    257      1.45       dsl compat_43_sys_truncate(struct lwp *l, const struct compat_43_sys_truncate_args *uap, register_t *retval)
    258       1.2   thorpej {
    259      1.45       dsl 	/* {
    260       1.1  christos 		syscallarg(char *) path;
    261       1.1  christos 		syscallarg(long) length;
    262      1.45       dsl 	} */
    263       1.3   mycroft 	struct sys_truncate_args /* {
    264       1.1  christos 		syscallarg(char *) path;
    265       1.1  christos 		syscallarg(int) pad;
    266       1.1  christos 		syscallarg(off_t) length;
    267       1.1  christos 	} */ nuap;
    268       1.1  christos 
    269       1.1  christos 	SCARG(&nuap, path) = SCARG(uap, path);
    270       1.1  christos 	SCARG(&nuap, length) = SCARG(uap, length);
    271      1.22   thorpej 	return (sys_truncate(l, &nuap, retval));
    272       1.1  christos }
    273       1.1  christos 
    274       1.1  christos 
    275       1.1  christos /*
    276       1.1  christos  * Reposition read/write file offset.
    277       1.1  christos  */
    278       1.1  christos int
    279      1.45       dsl compat_43_sys_lseek(struct lwp *l, const struct compat_43_sys_lseek_args *uap, register_t *retval)
    280       1.2   thorpej {
    281      1.45       dsl 	/* {
    282       1.1  christos 		syscallarg(int) fd;
    283       1.1  christos 		syscallarg(long) offset;
    284       1.1  christos 		syscallarg(int) whence;
    285      1.45       dsl 	} */
    286       1.3   mycroft 	struct sys_lseek_args /* {
    287       1.1  christos 		syscallarg(int) fd;
    288       1.1  christos 		syscallarg(int) pad;
    289       1.1  christos 		syscallarg(off_t) offset;
    290       1.1  christos 		syscallarg(int) whence;
    291       1.1  christos 	} */ nuap;
    292       1.1  christos 	off_t qret;
    293       1.1  christos 	int error;
    294       1.1  christos 
    295       1.1  christos 	SCARG(&nuap, fd) = SCARG(uap, fd);
    296       1.1  christos 	SCARG(&nuap, offset) = SCARG(uap, offset);
    297       1.1  christos 	SCARG(&nuap, whence) = SCARG(uap, whence);
    298      1.22   thorpej 	error = sys_lseek(l, &nuap, (void *)&qret);
    299       1.1  christos 	*(long *)retval = qret;
    300       1.1  christos 	return (error);
    301       1.1  christos }
    302       1.1  christos 
    303       1.1  christos 
    304       1.1  christos /*
    305       1.1  christos  * Create a file.
    306       1.1  christos  */
    307       1.1  christos int
    308      1.45       dsl compat_43_sys_creat(struct lwp *l, const struct compat_43_sys_creat_args *uap, register_t *retval)
    309       1.2   thorpej {
    310      1.45       dsl 	/* {
    311       1.1  christos 		syscallarg(char *) path;
    312       1.1  christos 		syscallarg(int) mode;
    313      1.45       dsl 	} */
    314       1.3   mycroft 	struct sys_open_args /* {
    315       1.1  christos 		syscallarg(char *) path;
    316       1.1  christos 		syscallarg(int) flags;
    317       1.1  christos 		syscallarg(int) mode;
    318       1.1  christos 	} */ nuap;
    319       1.1  christos 
    320       1.1  christos 	SCARG(&nuap, path) = SCARG(uap, path);
    321       1.1  christos 	SCARG(&nuap, mode) = SCARG(uap, mode);
    322       1.1  christos 	SCARG(&nuap, flags) = O_WRONLY | O_CREAT | O_TRUNC;
    323      1.22   thorpej 	return (sys_open(l, &nuap, retval));
    324       1.1  christos }
    325       1.1  christos 
    326       1.1  christos /*ARGSUSED*/
    327       1.1  christos int
    328      1.45       dsl compat_43_sys_quota(struct lwp *l, const void *v, register_t *retval)
    329       1.1  christos {
    330       1.1  christos 
    331       1.1  christos 	return (ENOSYS);
    332       1.1  christos }
    333       1.1  christos 
    334       1.1  christos 
    335       1.1  christos /*
    336       1.1  christos  * Read a block of directory entries in a file system independent format.
    337       1.1  christos  */
    338       1.1  christos int
    339      1.45       dsl compat_43_sys_getdirentries(struct lwp *l, const struct compat_43_sys_getdirentries_args *uap, register_t *retval)
    340       1.2   thorpej {
    341      1.45       dsl 	/* {
    342       1.1  christos 		syscallarg(int) fd;
    343       1.1  christos 		syscallarg(char *) buf;
    344       1.1  christos 		syscallarg(u_int) count;
    345       1.1  christos 		syscallarg(long *) basep;
    346      1.45       dsl 	} */
    347      1.13  augustss 	struct vnode *vp;
    348       1.1  christos 	struct file *fp;
    349       1.1  christos 	struct uio auio, kuio;
    350       1.1  christos 	struct iovec aiov, kiov;
    351       1.1  christos 	struct dirent *dp, *edp;
    352      1.36  christos 	char *dirbuf;
    353      1.27  christos 	size_t count = min(MAXBSIZE, (size_t)SCARG(uap, count));
    354      1.27  christos 
    355       1.1  christos 	int error, eofflag, readcnt;
    356       1.1  christos 	long loff;
    357       1.1  christos 
    358      1.47        ad 	/* fd_getvnode() will use the descriptor for us */
    359      1.47        ad 	if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
    360       1.1  christos 		return (error);
    361      1.12   thorpej 	if ((fp->f_flag & FREAD) == 0) {
    362      1.12   thorpej 		error = EBADF;
    363      1.12   thorpej 		goto out;
    364      1.12   thorpej 	}
    365       1.1  christos 	vp = (struct vnode *)fp->f_data;
    366       1.1  christos unionread:
    367      1.12   thorpej 	if (vp->v_type != VDIR) {
    368      1.12   thorpej 		error = EINVAL;
    369      1.12   thorpej 		goto out;
    370      1.12   thorpej 	}
    371       1.1  christos 	aiov.iov_base = SCARG(uap, buf);
    372      1.27  christos 	aiov.iov_len = count;
    373       1.1  christos 	auio.uio_iov = &aiov;
    374       1.1  christos 	auio.uio_iovcnt = 1;
    375       1.1  christos 	auio.uio_rw = UIO_READ;
    376      1.27  christos 	auio.uio_resid = count;
    377      1.32      yamt 	KASSERT(l == curlwp);
    378      1.46        ad 	auio.uio_vmspace = curproc->p_vmspace;
    379      1.10      fvdl 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    380       1.1  christos 	loff = auio.uio_offset = fp->f_offset;
    381       1.1  christos #	if (BYTE_ORDER != LITTLE_ENDIAN)
    382      1.28   mycroft 		if ((vp->v_mount->mnt_iflag & IMNT_DTYPE) == 0) {
    383       1.1  christos 			error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag,
    384      1.10      fvdl 			    (off_t **)0, (int *)0);
    385       1.1  christos 			fp->f_offset = auio.uio_offset;
    386       1.1  christos 		} else
    387       1.1  christos #	endif
    388       1.1  christos 	{
    389       1.1  christos 		kuio = auio;
    390       1.1  christos 		kuio.uio_iov = &kiov;
    391      1.27  christos 		kiov.iov_len = count;
    392      1.27  christos 		dirbuf = malloc(count, M_TEMP, M_WAITOK);
    393       1.1  christos 		kiov.iov_base = dirbuf;
    394      1.32      yamt 		UIO_SETUP_SYSSPACE(&kuio);
    395       1.1  christos 		error = VOP_READDIR(vp, &kuio, fp->f_cred, &eofflag,
    396      1.10      fvdl 			    (off_t **)0, (int *)0);
    397       1.1  christos 		fp->f_offset = kuio.uio_offset;
    398       1.1  christos 		if (error == 0) {
    399      1.27  christos 			readcnt = count - kuio.uio_resid;
    400       1.1  christos 			edp = (struct dirent *)&dirbuf[readcnt];
    401       1.1  christos 			for (dp = (struct dirent *)dirbuf; dp < edp; ) {
    402       1.1  christos #				if (BYTE_ORDER == LITTLE_ENDIAN)
    403       1.1  christos 					/*
    404       1.1  christos 					 * The expected low byte of
    405       1.1  christos 					 * dp->d_namlen is our dp->d_type.
    406       1.1  christos 					 * The high MBZ byte of dp->d_namlen
    407       1.1  christos 					 * is our dp->d_namlen.
    408       1.1  christos 					 */
    409       1.1  christos 					dp->d_type = dp->d_namlen;
    410       1.1  christos 					dp->d_namlen = 0;
    411       1.1  christos #				else
    412       1.1  christos 					/*
    413       1.1  christos 					 * The dp->d_type is the high byte
    414       1.1  christos 					 * of the expected dp->d_namlen,
    415       1.1  christos 					 * so must be zero'ed.
    416       1.1  christos 					 */
    417       1.1  christos 					dp->d_type = 0;
    418       1.1  christos #				endif
    419       1.1  christos 				if (dp->d_reclen > 0) {
    420       1.1  christos 					dp = (struct dirent *)
    421       1.1  christos 					    ((char *)dp + dp->d_reclen);
    422       1.1  christos 				} else {
    423       1.1  christos 					error = EIO;
    424       1.1  christos 					break;
    425       1.1  christos 				}
    426       1.1  christos 			}
    427       1.1  christos 			if (dp >= edp)
    428       1.1  christos 				error = uiomove(dirbuf, readcnt, &auio);
    429       1.1  christos 		}
    430      1.27  christos 		free(dirbuf, M_TEMP);
    431       1.1  christos 	}
    432      1.10      fvdl 	VOP_UNLOCK(vp, 0);
    433       1.1  christos 	if (error)
    434      1.12   thorpej 		goto out;
    435       1.1  christos 
    436      1.27  christos 	if ((count == auio.uio_resid) &&
    437      1.40        ad 	    (vp->v_vflag & VV_ROOT) &&
    438       1.1  christos 	    (vp->v_mount->mnt_flag & MNT_UNION)) {
    439       1.1  christos 		struct vnode *tvp = vp;
    440       1.1  christos 		vp = vp->v_mount->mnt_vnodecovered;
    441       1.1  christos 		VREF(vp);
    442      1.36  christos 		fp->f_data = (void *) vp;
    443       1.1  christos 		fp->f_offset = 0;
    444       1.1  christos 		vrele(tvp);
    445       1.1  christos 		goto unionread;
    446       1.1  christos 	}
    447      1.36  christos 	error = copyout((void *)&loff, (void *)SCARG(uap, basep),
    448       1.1  christos 	    sizeof(long));
    449      1.27  christos 	*retval = count - auio.uio_resid;
    450      1.12   thorpej  out:
    451      1.46        ad 	fd_putfile(SCARG(uap, fd));
    452       1.1  christos 	return (error);
    453       1.1  christos }
    454      1.30  christos 
    455      1.30  christos /*
    456      1.30  christos  * sysctl helper routine for vfs.generic.conf lookups.
    457      1.30  christos  */
    458      1.30  christos #if defined(COMPAT_09) || defined(COMPAT_43) || defined(COMPAT_44)
    459  1.47.2.1      haad static struct sysctllog *compat_clog;
    460  1.47.2.1      haad 
    461      1.30  christos static int
    462      1.30  christos sysctl_vfs_generic_conf(SYSCTLFN_ARGS)
    463      1.30  christos {
    464      1.30  christos         struct vfsconf vfc;
    465      1.30  christos         extern const char * const mountcompatnames[];
    466      1.30  christos         extern int nmountcompatnames;
    467      1.30  christos 	struct sysctlnode node;
    468      1.30  christos 	struct vfsops *vfsp;
    469      1.30  christos 	u_int vfsnum;
    470      1.30  christos 
    471      1.30  christos 	if (namelen != 1)
    472      1.30  christos 		return (ENOTDIR);
    473      1.30  christos 	vfsnum = name[0];
    474      1.30  christos 	if (vfsnum >= nmountcompatnames ||
    475      1.30  christos 	    mountcompatnames[vfsnum] == NULL)
    476      1.30  christos 		return (EOPNOTSUPP);
    477      1.30  christos 	vfsp = vfs_getopsbyname(mountcompatnames[vfsnum]);
    478      1.30  christos 	if (vfsp == NULL)
    479      1.30  christos 		return (EOPNOTSUPP);
    480      1.30  christos 
    481      1.30  christos 	vfc.vfc_vfsops = vfsp;
    482      1.39  christos 	strncpy(vfc.vfc_name, vfsp->vfs_name, sizeof(vfc.vfc_name));
    483      1.30  christos 	vfc.vfc_typenum = vfsnum;
    484      1.30  christos 	vfc.vfc_refcount = vfsp->vfs_refcount;
    485      1.30  christos 	vfc.vfc_flags = 0;
    486      1.30  christos 	vfc.vfc_mountroot = vfsp->vfs_mountroot;
    487      1.30  christos 	vfc.vfc_next = NULL;
    488      1.40        ad 	vfs_delref(vfsp);
    489      1.30  christos 
    490      1.30  christos 	node = *rnode;
    491      1.30  christos 	node.sysctl_data = &vfc;
    492      1.30  christos 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
    493      1.30  christos }
    494      1.30  christos 
    495      1.30  christos /*
    496      1.30  christos  * Top level filesystem related information gathering.
    497      1.30  christos  */
    498  1.47.2.1      haad void
    499  1.47.2.1      haad compat_sysctl_init(void)
    500      1.30  christos {
    501      1.30  christos 	extern int nmountcompatnames;
    502      1.30  christos 
    503  1.47.2.1      haad 	sysctl_createv(&compat_clog, 0, NULL, NULL,
    504      1.30  christos 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
    505      1.30  christos 		       CTLTYPE_INT, "maxtypenum",
    506      1.30  christos 		       SYSCTL_DESCR("Highest valid filesystem type number"),
    507      1.30  christos 		       NULL, nmountcompatnames, NULL, 0,
    508      1.30  christos 		       CTL_VFS, VFS_GENERIC, VFS_MAXTYPENUM, CTL_EOL);
    509  1.47.2.1      haad 	sysctl_createv(&compat_clog, 0, NULL, NULL,
    510      1.30  christos 		       CTLFLAG_PERMANENT,
    511      1.30  christos 		       CTLTYPE_STRUCT, "conf",
    512      1.30  christos 		       SYSCTL_DESCR("Filesystem configuration information"),
    513      1.30  christos 		       sysctl_vfs_generic_conf, 0, NULL,
    514      1.30  christos 		       sizeof(struct vfsconf),
    515      1.30  christos 		       CTL_VFS, VFS_GENERIC, VFS_CONF, CTL_EOL);
    516      1.30  christos }
    517  1.47.2.1      haad 
    518  1.47.2.1      haad void
    519  1.47.2.1      haad compat_sysctl_fini(void)
    520  1.47.2.1      haad {
    521  1.47.2.1      haad 
    522  1.47.2.1      haad 	sysctl_teardown(&compat_clog);
    523  1.47.2.1      haad }
    524      1.30  christos #endif
    525