Home | History | Annotate | Line # | Download | only in fdesc
fdesc_vfsops.c revision 1.41
      1  1.41   thorpej /*	$NetBSD: fdesc_vfsops.c,v 1.41 2003/06/29 02:16:59 thorpej Exp $	*/
      2  1.13       cgd 
      3   1.1       cgd /*
      4  1.24      fvdl  * Copyright (c) 1992, 1993, 1995
      5  1.12   mycroft  *	The Regents of the University of California.  All rights reserved.
      6   1.1       cgd  *
      7   1.6       cgd  * This code is derived from software donated to Berkeley by
      8   1.1       cgd  * Jan-Simon Pendry.
      9   1.1       cgd  *
     10   1.2       cgd  * Redistribution and use in source and binary forms, with or without
     11   1.2       cgd  * modification, are permitted provided that the following conditions
     12   1.2       cgd  * are met:
     13   1.2       cgd  * 1. Redistributions of source code must retain the above copyright
     14   1.2       cgd  *    notice, this list of conditions and the following disclaimer.
     15   1.2       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.2       cgd  *    notice, this list of conditions and the following disclaimer in the
     17   1.2       cgd  *    documentation and/or other materials provided with the distribution.
     18   1.2       cgd  * 3. All advertising materials mentioning features or use of this software
     19   1.2       cgd  *    must display the following acknowledgement:
     20   1.6       cgd  *	This product includes software developed by the University of
     21   1.6       cgd  *	California, Berkeley and its contributors.
     22   1.2       cgd  * 4. Neither the name of the University nor the names of its contributors
     23   1.2       cgd  *    may be used to endorse or promote products derived from this software
     24   1.2       cgd  *    without specific prior written permission.
     25   1.1       cgd  *
     26   1.2       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     27   1.2       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     28   1.2       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     29   1.2       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     30   1.2       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     31   1.2       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     32   1.2       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     33   1.2       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     34   1.2       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     35   1.2       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     36   1.2       cgd  * SUCH DAMAGE.
     37   1.1       cgd  *
     38  1.24      fvdl  *	@(#)fdesc_vfsops.c	8.10 (Berkeley) 5/14/95
     39  1.15   mycroft  *
     40  1.15   mycroft  * #Id: fdesc_vfsops.c,v 1.9 1993/04/06 15:28:33 jsp Exp #
     41   1.1       cgd  */
     42   1.1       cgd 
     43   1.1       cgd /*
     44   1.1       cgd  * /dev/fd Filesystem
     45   1.1       cgd  */
     46  1.35     lukem 
     47  1.35     lukem #include <sys/cdefs.h>
     48  1.41   thorpej __KERNEL_RCSID(0, "$NetBSD: fdesc_vfsops.c,v 1.41 2003/06/29 02:16:59 thorpej Exp $");
     49  1.25  jonathan 
     50  1.33       mrg #if defined(_KERNEL_OPT)
     51  1.25  jonathan #include "opt_compat_netbsd.h"
     52  1.25  jonathan #endif
     53   1.1       cgd 
     54   1.6       cgd #include <sys/param.h>
     55   1.6       cgd #include <sys/systm.h>
     56   1.6       cgd #include <sys/time.h>
     57   1.6       cgd #include <sys/proc.h>
     58   1.6       cgd #include <sys/resourcevar.h>
     59   1.6       cgd #include <sys/filedesc.h>
     60   1.6       cgd #include <sys/vnode.h>
     61   1.6       cgd #include <sys/mount.h>
     62   1.6       cgd #include <sys/namei.h>
     63   1.6       cgd #include <sys/malloc.h>
     64   1.6       cgd #include <miscfs/fdesc/fdesc.h>
     65   1.1       cgd 
     66  1.22       cgd int	fdesc_mount __P((struct mount *, const char *, void *,
     67  1.40   darrenr 			 struct nameidata *, struct lwp *));
     68  1.40   darrenr int	fdesc_start __P((struct mount *, int, struct lwp *));
     69  1.40   darrenr int	fdesc_unmount __P((struct mount *, int, struct lwp *));
     70  1.21  christos int	fdesc_quotactl __P((struct mount *, int, uid_t, caddr_t,
     71  1.40   darrenr 			    struct lwp *));
     72  1.40   darrenr int	fdesc_statfs __P((struct mount *, struct statfs *, struct lwp *));
     73  1.40   darrenr int	fdesc_sync __P((struct mount *, int, struct ucred *, struct lwp *));
     74  1.40   darrenr int	fdesc_vget __P((struct mount *, ino_t, struct vnode **, struct lwp *));
     75  1.40   darrenr int	fdesc_fhtovp __P((struct mount *, struct fid *, struct vnode **,
     76  1.40   darrenr 			    struct lwp *));
     77  1.27  wrstuden int	fdesc_checkexp __P((struct mount *, struct mbuf *, int *,
     78  1.27  wrstuden 			    struct ucred **));
     79  1.21  christos int	fdesc_vptofh __P((struct vnode *, struct fid *));
     80  1.24      fvdl int	fdesc_sysctl __P((int *, u_int, void *, size_t *, void *, size_t,
     81  1.40   darrenr 			  struct lwp *));
     82  1.21  christos 
     83   1.1       cgd /*
     84   1.1       cgd  * Mount the per-process file descriptors (/dev/fd)
     85   1.1       cgd  */
     86  1.12   mycroft int
     87  1.40   darrenr fdesc_mount(mp, path, data, ndp, l)
     88   1.1       cgd 	struct mount *mp;
     89  1.22       cgd 	const char *path;
     90  1.22       cgd 	void *data;
     91   1.1       cgd 	struct nameidata *ndp;
     92  1.40   darrenr 	struct lwp *l;
     93   1.1       cgd {
     94   1.1       cgd 	int error = 0;
     95   1.1       cgd 	struct fdescmount *fmp;
     96   1.1       cgd 	struct vnode *rvp;
     97   1.1       cgd 
     98  1.38  christos 	if (mp->mnt_flag & MNT_GETARGS)
     99  1.38  christos 		return 0;
    100   1.1       cgd 	/*
    101   1.1       cgd 	 * Update is a no-op
    102   1.1       cgd 	 */
    103   1.1       cgd 	if (mp->mnt_flag & MNT_UPDATE)
    104   1.1       cgd 		return (EOPNOTSUPP);
    105   1.1       cgd 
    106   1.6       cgd 	error = fdesc_allocvp(Froot, FD_ROOT, mp, &rvp);
    107   1.1       cgd 	if (error)
    108   1.1       cgd 		return (error);
    109   1.1       cgd 
    110   1.6       cgd 	MALLOC(fmp, struct fdescmount *, sizeof(struct fdescmount),
    111  1.12   mycroft 				M_UFSMNT, M_WAITOK);	/* XXX */
    112   1.1       cgd 	rvp->v_type = VDIR;
    113   1.1       cgd 	rvp->v_flag |= VROOT;
    114   1.1       cgd 	fmp->f_root = rvp;
    115  1.14   mycroft 	mp->mnt_flag |= MNT_LOCAL;
    116  1.37     soren 	mp->mnt_data = fmp;
    117  1.31     assar 	vfs_getnewfsid(mp);
    118   1.1       cgd 
    119  1.39  christos 	error = set_statfs_info(path, UIO_USERSPACE, "fdesc", UIO_SYSSPACE,
    120  1.41   thorpej 	    mp, l);
    121  1.28  wrstuden 	VOP_UNLOCK(rvp, 0);
    122  1.39  christos 	return error;
    123   1.1       cgd }
    124   1.1       cgd 
    125  1.12   mycroft int
    126  1.40   darrenr fdesc_start(mp, flags, l)
    127   1.1       cgd 	struct mount *mp;
    128   1.1       cgd 	int flags;
    129  1.40   darrenr 	struct lwp *l;
    130   1.1       cgd {
    131   1.1       cgd 	return (0);
    132   1.1       cgd }
    133   1.1       cgd 
    134  1.12   mycroft int
    135  1.40   darrenr fdesc_unmount(mp, mntflags, l)
    136   1.1       cgd 	struct mount *mp;
    137   1.1       cgd 	int mntflags;
    138  1.40   darrenr 	struct lwp *l;
    139   1.1       cgd {
    140   1.1       cgd 	int error;
    141   1.1       cgd 	int flags = 0;
    142   1.1       cgd 	struct vnode *rootvp = VFSTOFDESC(mp)->f_root;
    143   1.1       cgd 
    144  1.24      fvdl 	if (mntflags & MNT_FORCE)
    145   1.1       cgd 		flags |= FORCECLOSE;
    146   1.1       cgd 
    147   1.1       cgd 	/*
    148   1.1       cgd 	 * Clear out buffer cache.  I don't think we
    149   1.1       cgd 	 * ever get anything cached at this level at the
    150   1.1       cgd 	 * moment, but who knows...
    151   1.1       cgd 	 */
    152   1.1       cgd 	if (rootvp->v_usecount > 1)
    153   1.1       cgd 		return (EBUSY);
    154  1.21  christos 	if ((error = vflush(mp, rootvp, flags)) != 0)
    155   1.1       cgd 		return (error);
    156   1.1       cgd 
    157   1.1       cgd 	/*
    158   1.1       cgd 	 * Release reference on underlying root vnode
    159   1.1       cgd 	 */
    160   1.1       cgd 	vrele(rootvp);
    161   1.1       cgd 	/*
    162   1.1       cgd 	 * And blow it away for future re-use
    163   1.1       cgd 	 */
    164   1.1       cgd 	vgone(rootvp);
    165   1.1       cgd 	/*
    166   1.1       cgd 	 * Finally, throw away the fdescmount structure
    167   1.1       cgd 	 */
    168  1.12   mycroft 	free(mp->mnt_data, M_UFSMNT);	/* XXX */
    169   1.1       cgd 	mp->mnt_data = 0;
    170  1.12   mycroft 
    171  1.12   mycroft 	return (0);
    172   1.1       cgd }
    173   1.1       cgd 
    174  1.12   mycroft int
    175  1.40   darrenr fdesc_root(mp, vpp, l)
    176   1.1       cgd 	struct mount *mp;
    177   1.1       cgd 	struct vnode **vpp;
    178  1.40   darrenr 	struct lwp *l;
    179   1.1       cgd {
    180   1.1       cgd 	struct vnode *vp;
    181   1.1       cgd 
    182   1.1       cgd 	/*
    183   1.1       cgd 	 * Return locked reference to root.
    184   1.1       cgd 	 */
    185   1.1       cgd 	vp = VFSTOFDESC(mp)->f_root;
    186   1.1       cgd 	VREF(vp);
    187  1.24      fvdl 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    188   1.1       cgd 	*vpp = vp;
    189   1.1       cgd 	return (0);
    190   1.1       cgd }
    191   1.1       cgd 
    192  1.12   mycroft int
    193  1.40   darrenr fdesc_quotactl(mp, cmd, uid, arg, l)
    194   1.1       cgd 	struct mount *mp;
    195   1.1       cgd 	int cmd;
    196   1.1       cgd 	uid_t uid;
    197   1.1       cgd 	caddr_t arg;
    198  1.40   darrenr 	struct lwp *l;
    199   1.1       cgd {
    200  1.12   mycroft 
    201   1.1       cgd 	return (EOPNOTSUPP);
    202   1.1       cgd }
    203   1.1       cgd 
    204  1.12   mycroft int
    205  1.40   darrenr fdesc_statfs(mp, sbp, l)
    206   1.1       cgd 	struct mount *mp;
    207   1.1       cgd 	struct statfs *sbp;
    208  1.40   darrenr 	struct lwp *l;
    209   1.1       cgd {
    210   1.1       cgd 	struct filedesc *fdp;
    211  1.40   darrenr 	struct proc *p;
    212   1.1       cgd 	int lim;
    213   1.1       cgd 	int i;
    214   1.1       cgd 	int last;
    215   1.1       cgd 	int freefd;
    216   1.1       cgd 
    217   1.1       cgd 	/*
    218   1.1       cgd 	 * Compute number of free file descriptors.
    219   1.1       cgd 	 * [ Strange results will ensue if the open file
    220   1.1       cgd 	 * limit is ever reduced below the current number
    221   1.1       cgd 	 * of open files... ]
    222   1.1       cgd 	 */
    223  1.40   darrenr 	p = l->l_proc;
    224   1.5   mycroft 	lim = p->p_rlimit[RLIMIT_NOFILE].rlim_cur;
    225   1.1       cgd 	fdp = p->p_fd;
    226   1.1       cgd 	last = min(fdp->fd_nfiles, lim);
    227   1.1       cgd 	freefd = 0;
    228   1.1       cgd 	for (i = fdp->fd_freefile; i < last; i++)
    229   1.1       cgd 		if (fdp->fd_ofiles[i] == NULL)
    230   1.1       cgd 			freefd++;
    231   1.1       cgd 
    232   1.1       cgd 	/*
    233   1.1       cgd 	 * Adjust for the fact that the fdesc array may not
    234   1.1       cgd 	 * have been fully allocated yet.
    235   1.1       cgd 	 */
    236   1.1       cgd 	if (fdp->fd_nfiles < lim)
    237   1.1       cgd 		freefd += (lim - fdp->fd_nfiles);
    238   1.1       cgd 
    239   1.1       cgd 	sbp->f_bsize = DEV_BSIZE;
    240  1.10       cgd 	sbp->f_iosize = DEV_BSIZE;
    241   1.1       cgd 	sbp->f_blocks = 2;		/* 1K to keep df happy */
    242   1.1       cgd 	sbp->f_bfree = 0;
    243   1.1       cgd 	sbp->f_bavail = 0;
    244   1.1       cgd 	sbp->f_files = lim + 1;		/* Allow for "." */
    245   1.1       cgd 	sbp->f_ffree = freefd;		/* See comments above */
    246  1.24      fvdl #ifdef COMPAT_09
    247  1.24      fvdl 	sbp->f_type = 6;
    248  1.24      fvdl #else
    249  1.24      fvdl 	sbp->f_type = 0;
    250  1.24      fvdl #endif
    251  1.39  christos 	copy_statfs_info(sbp, mp);
    252   1.1       cgd 	return (0);
    253   1.1       cgd }
    254   1.1       cgd 
    255  1.21  christos /*ARGSUSED*/
    256  1.12   mycroft int
    257  1.40   darrenr fdesc_sync(mp, waitfor, uc, l)
    258   1.1       cgd 	struct mount *mp;
    259   1.1       cgd 	int waitfor;
    260  1.21  christos 	struct ucred *uc;
    261  1.40   darrenr 	struct lwp *l;
    262   1.1       cgd {
    263  1.12   mycroft 
    264   1.1       cgd 	return (0);
    265   1.1       cgd }
    266   1.1       cgd 
    267  1.12   mycroft /*
    268  1.12   mycroft  * Fdesc flat namespace lookup.
    269  1.12   mycroft  * Currently unsupported.
    270  1.12   mycroft  */
    271  1.12   mycroft int
    272  1.40   darrenr fdesc_vget(mp, ino, vpp, l)
    273  1.12   mycroft 	struct mount *mp;
    274  1.12   mycroft 	ino_t ino;
    275  1.12   mycroft 	struct vnode **vpp;
    276  1.40   darrenr 	struct lwp *l;
    277  1.12   mycroft {
    278  1.12   mycroft 
    279  1.12   mycroft 	return (EOPNOTSUPP);
    280  1.12   mycroft }
    281  1.12   mycroft 
    282  1.21  christos 
    283  1.21  christos /*ARGSUSED*/
    284  1.12   mycroft int
    285  1.40   darrenr fdesc_fhtovp(mp, fhp, vpp, l)
    286   1.1       cgd 	struct mount *mp;
    287   1.1       cgd 	struct fid *fhp;
    288  1.27  wrstuden 	struct vnode **vpp;
    289  1.40   darrenr 	struct lwp *l;
    290  1.27  wrstuden {
    291  1.27  wrstuden 
    292  1.27  wrstuden 	return (EOPNOTSUPP);
    293  1.27  wrstuden }
    294  1.27  wrstuden 
    295  1.27  wrstuden /*ARGSUSED*/
    296  1.27  wrstuden int
    297  1.27  wrstuden fdesc_checkexp(mp, nam, exflagsp, credanonp)
    298  1.27  wrstuden 	struct mount *mp;
    299  1.21  christos 	struct mbuf *nam;
    300  1.21  christos 	int *exflagsp;
    301  1.21  christos 	struct ucred **credanonp;
    302   1.1       cgd {
    303  1.21  christos 
    304   1.1       cgd 	return (EOPNOTSUPP);
    305   1.1       cgd }
    306   1.1       cgd 
    307  1.21  christos /*ARGSUSED*/
    308  1.12   mycroft int
    309   1.1       cgd fdesc_vptofh(vp, fhp)
    310   1.1       cgd 	struct vnode *vp;
    311   1.1       cgd 	struct fid *fhp;
    312   1.1       cgd {
    313   1.1       cgd 	return (EOPNOTSUPP);
    314   1.1       cgd }
    315   1.1       cgd 
    316  1.24      fvdl int
    317  1.40   darrenr fdesc_sysctl(name, namelen, oldp, oldlenp, newp, newlen, l)
    318  1.24      fvdl 	int *name;
    319  1.24      fvdl 	u_int namelen;
    320  1.24      fvdl 	void *oldp;
    321  1.24      fvdl 	size_t *oldlenp;
    322  1.24      fvdl 	void *newp;
    323  1.24      fvdl 	size_t newlen;
    324  1.40   darrenr 	struct lwp *l;
    325  1.24      fvdl {
    326  1.24      fvdl 	return (EOPNOTSUPP);
    327  1.24      fvdl }
    328  1.24      fvdl 
    329  1.32  jdolecek extern const struct vnodeopv_desc fdesc_vnodeop_opv_desc;
    330  1.23   thorpej 
    331  1.32  jdolecek const struct vnodeopv_desc * const fdesc_vnodeopv_descs[] = {
    332  1.23   thorpej 	&fdesc_vnodeop_opv_desc,
    333  1.23   thorpej 	NULL,
    334  1.23   thorpej };
    335  1.23   thorpej 
    336   1.1       cgd struct vfsops fdesc_vfsops = {
    337   1.9       cgd 	MOUNT_FDESC,
    338   1.1       cgd 	fdesc_mount,
    339   1.1       cgd 	fdesc_start,
    340   1.1       cgd 	fdesc_unmount,
    341   1.1       cgd 	fdesc_root,
    342   1.1       cgd 	fdesc_quotactl,
    343   1.1       cgd 	fdesc_statfs,
    344   1.1       cgd 	fdesc_sync,
    345  1.12   mycroft 	fdesc_vget,
    346   1.1       cgd 	fdesc_fhtovp,
    347   1.1       cgd 	fdesc_vptofh,
    348   1.1       cgd 	fdesc_init,
    349  1.34       chs 	NULL,
    350  1.29  jdolecek 	fdesc_done,
    351  1.24      fvdl 	fdesc_sysctl,
    352  1.23   thorpej 	NULL,				/* vfs_mountroot */
    353  1.27  wrstuden 	fdesc_checkexp,
    354  1.23   thorpej 	fdesc_vnodeopv_descs,
    355   1.1       cgd };
    356