Home | History | Annotate | Line # | Download | only in kernfs
kernfs_vfsops.c revision 1.52.2.1
      1  1.52.2.1   darrenr /*	$NetBSD: kernfs_vfsops.c,v 1.52.2.1 2003/07/02 15:26:51 darrenr Exp $	*/
      2      1.18       cgd 
      3       1.1       cgd /*
      4      1.32      fvdl  * Copyright (c) 1992, 1993, 1995
      5      1.15   mycroft  *	The Regents of the University of California.  All rights reserved.
      6       1.1       cgd  *
      7      1.11       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.11       cgd  *	This product includes software developed by the University of
     21      1.11       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.32      fvdl  *	@(#)kernfs_vfsops.c	8.10 (Berkeley) 5/14/95
     39       1.1       cgd  */
     40       1.1       cgd 
     41       1.1       cgd /*
     42       1.1       cgd  * Kernel params Filesystem
     43       1.1       cgd  */
     44      1.42     lukem 
     45      1.42     lukem #include <sys/cdefs.h>
     46  1.52.2.1   darrenr __KERNEL_RCSID(0, "$NetBSD: kernfs_vfsops.c,v 1.52.2.1 2003/07/02 15:26:51 darrenr Exp $");
     47      1.33  jonathan 
     48      1.40       mrg #if defined(_KERNEL_OPT)
     49      1.33  jonathan #include "opt_compat_netbsd.h"
     50      1.33  jonathan #endif
     51       1.1       cgd 
     52       1.9   mycroft #include <sys/param.h>
     53       1.9   mycroft #include <sys/systm.h>
     54      1.15   mycroft #include <sys/conf.h>
     55       1.9   mycroft #include <sys/proc.h>
     56       1.9   mycroft #include <sys/vnode.h>
     57       1.9   mycroft #include <sys/mount.h>
     58       1.9   mycroft #include <sys/namei.h>
     59       1.9   mycroft #include <sys/malloc.h>
     60      1.15   mycroft 
     61      1.15   mycroft #include <miscfs/specfs/specdev.h>
     62       1.9   mycroft #include <miscfs/kernfs/kernfs.h>
     63       1.1       cgd 
     64      1.47   thorpej MALLOC_DEFINE(M_KERNFSMNT, "kernfs mount", "kernfs mount structures");
     65      1.47   thorpej 
     66      1.15   mycroft dev_t rrootdev = NODEV;
     67      1.15   mycroft 
     68      1.25  christos void	kernfs_init __P((void));
     69      1.36  jdolecek void	kernfs_done __P((void));
     70      1.25  christos void	kernfs_get_rrootdev __P((void));
     71      1.29       cgd int	kernfs_mount __P((struct mount *, const char *, void *,
     72  1.52.2.1   darrenr 	    struct nameidata *, struct lwp *));
     73  1.52.2.1   darrenr int	kernfs_start __P((struct mount *, int, struct lwp *));
     74  1.52.2.1   darrenr int	kernfs_unmount __P((struct mount *, int, struct lwp *));
     75  1.52.2.1   darrenr int	kernfs_root __P((struct mount *, struct vnode **, struct lwp *));
     76  1.52.2.1   darrenr int	kernfs_statfs __P((struct mount *, struct statfs *, struct lwp *));
     77      1.25  christos int	kernfs_quotactl __P((struct mount *, int, uid_t, caddr_t,
     78  1.52.2.1   darrenr 			     struct lwp *));
     79  1.52.2.1   darrenr int	kernfs_sync __P((struct mount *, int, struct ucred *, struct lwp *));
     80  1.52.2.1   darrenr int	kernfs_vget __P((struct mount *, ino_t, struct vnode **, struct lwp *));
     81  1.52.2.1   darrenr int	kernfs_fhtovp __P((struct mount *, struct fid *, struct vnode **,
     82  1.52.2.1   darrenr 			   struct lwp *));
     83      1.35  wrstuden int	kernfs_checkexp __P((struct mount *, struct mbuf *, int *,
     84      1.35  wrstuden 			   struct ucred **));
     85      1.25  christos int	kernfs_vptofh __P((struct vnode *, struct fid *));
     86      1.32      fvdl int	kernfs_sysctl __P((int *, u_int, void *, size_t *, void *, size_t,
     87  1.52.2.1   darrenr 			   struct lwp *));
     88      1.25  christos 
     89      1.25  christos void
     90       1.1       cgd kernfs_init()
     91       1.1       cgd {
     92      1.49  christos #ifdef _LKM
     93      1.49  christos 	malloc_type_attach(M_KERNFSMNT);
     94      1.49  christos #endif
     95      1.10       cgd }
     96      1.10       cgd 
     97      1.11       cgd void
     98      1.36  jdolecek kernfs_done()
     99      1.36  jdolecek {
    100      1.49  christos #ifdef _LKM
    101      1.49  christos 	malloc_type_detach(M_KERNFSMNT);
    102      1.49  christos #endif
    103      1.36  jdolecek }
    104      1.36  jdolecek 
    105      1.36  jdolecek void
    106      1.15   mycroft kernfs_get_rrootdev()
    107      1.10       cgd {
    108      1.16   mycroft 	static int tried = 0;
    109      1.10       cgd 
    110      1.16   mycroft 	if (tried) {
    111      1.15   mycroft 		/* Already did it once. */
    112      1.15   mycroft 		return;
    113      1.15   mycroft 	}
    114      1.16   mycroft 	tried = 1;
    115      1.16   mycroft 
    116      1.16   mycroft 	if (rootdev == NODEV)
    117      1.16   mycroft 		return;
    118      1.45   gehenna 	rrootdev = devsw_blk2chr(rootdev);
    119      1.45   gehenna 	if (rrootdev != NODEV) {
    120      1.39       mrg #ifdef KERNFS_DIAGNOSTIC
    121      1.39       mrg 	printf("kernfs_mount: rootdev = %u.%u; rrootdev = %u.%u\n",
    122      1.39       mrg 	    major(rootdev), minor(rootdev), major(rrootdev), minor(rrootdev));
    123      1.39       mrg #endif
    124      1.45   gehenna 		return;
    125      1.10       cgd 	}
    126      1.16   mycroft 	rrootdev = NODEV;
    127      1.28  christos 	printf("kernfs_get_rrootdev: no raw root device\n");
    128       1.1       cgd }
    129       1.1       cgd 
    130       1.1       cgd /*
    131      1.15   mycroft  * Mount the Kernel params filesystem
    132       1.1       cgd  */
    133      1.25  christos int
    134  1.52.2.1   darrenr kernfs_mount(mp, path, data, ndp, l)
    135       1.1       cgd 	struct mount *mp;
    136      1.29       cgd 	const char *path;
    137      1.29       cgd 	void *data;
    138       1.1       cgd 	struct nameidata *ndp;
    139  1.52.2.1   darrenr 	struct lwp *l;
    140       1.1       cgd {
    141       1.1       cgd 	int error = 0;
    142       1.1       cgd 	struct kernfs_mount *fmp;
    143       1.1       cgd 	struct vnode *rvp;
    144       1.1       cgd 
    145       1.1       cgd #ifdef KERNFS_DIAGNOSTIC
    146      1.30  christos 	printf("kernfs_mount(mp = %p)\n", mp);
    147       1.1       cgd #endif
    148       1.1       cgd 
    149      1.46  christos 	if (mp->mnt_flag & MNT_GETARGS)
    150      1.46  christos 		return 0;
    151       1.1       cgd 	/*
    152       1.1       cgd 	 * Update is a no-op
    153       1.1       cgd 	 */
    154       1.1       cgd 	if (mp->mnt_flag & MNT_UPDATE)
    155       1.1       cgd 		return (EOPNOTSUPP);
    156       1.1       cgd 
    157      1.25  christos 	error = getnewvnode(VT_KERNFS, mp, kernfs_vnodeop_p, &rvp);
    158      1.25  christos 	if (error)
    159       1.1       cgd 		return (error);
    160       1.1       cgd 
    161      1.15   mycroft 	MALLOC(fmp, struct kernfs_mount *, sizeof(struct kernfs_mount),
    162      1.47   thorpej 	    M_KERNFSMNT, M_WAITOK);
    163       1.1       cgd 	rvp->v_type = VDIR;
    164       1.1       cgd 	rvp->v_flag |= VROOT;
    165       1.1       cgd #ifdef KERNFS_DIAGNOSTIC
    166      1.30  christos 	printf("kernfs_mount: root vp = %p\n", rvp);
    167       1.1       cgd #endif
    168       1.1       cgd 	fmp->kf_root = rvp;
    169       1.1       cgd 	mp->mnt_flag |= MNT_LOCAL;
    170      1.44     soren 	mp->mnt_data = fmp;
    171      1.37     assar 	vfs_getnewfsid(mp);
    172       1.1       cgd 
    173      1.48  christos 	error = set_statfs_info(path, UIO_USERSPACE, "kernfs", UIO_SYSSPACE,
    174  1.52.2.1   darrenr 	    mp, l);
    175       1.1       cgd #ifdef KERNFS_DIAGNOSTIC
    176      1.28  christos 	printf("kernfs_mount: at %s\n", mp->mnt_stat.f_mntonname);
    177       1.1       cgd #endif
    178      1.10       cgd 
    179      1.15   mycroft 	kernfs_get_rrootdev();
    180      1.48  christos 	return error;
    181       1.1       cgd }
    182       1.1       cgd 
    183      1.25  christos int
    184  1.52.2.1   darrenr kernfs_start(mp, flags, l)
    185       1.1       cgd 	struct mount *mp;
    186       1.1       cgd 	int flags;
    187  1.52.2.1   darrenr 	struct lwp *l;
    188       1.1       cgd {
    189      1.15   mycroft 
    190       1.1       cgd 	return (0);
    191       1.1       cgd }
    192       1.1       cgd 
    193      1.25  christos int
    194  1.52.2.1   darrenr kernfs_unmount(mp, mntflags, l)
    195       1.1       cgd 	struct mount *mp;
    196       1.1       cgd 	int mntflags;
    197  1.52.2.1   darrenr 	struct lwp *l;
    198       1.1       cgd {
    199       1.1       cgd 	int error;
    200       1.1       cgd 	int flags = 0;
    201       1.1       cgd 	struct vnode *rootvp = VFSTOKERNFS(mp)->kf_root;
    202       1.1       cgd 
    203       1.1       cgd #ifdef KERNFS_DIAGNOSTIC
    204      1.30  christos 	printf("kernfs_unmount(mp = %p)\n", mp);
    205       1.1       cgd #endif
    206       1.1       cgd 
    207      1.32      fvdl 	 if (mntflags & MNT_FORCE)
    208       1.1       cgd 		flags |= FORCECLOSE;
    209       1.1       cgd 
    210       1.1       cgd 	/*
    211       1.1       cgd 	 * Clear out buffer cache.  I don't think we
    212       1.1       cgd 	 * ever get anything cached at this level at the
    213       1.1       cgd 	 * moment, but who knows...
    214       1.1       cgd 	 */
    215       1.1       cgd 	if (rootvp->v_usecount > 1)
    216       1.1       cgd 		return (EBUSY);
    217       1.1       cgd #ifdef KERNFS_DIAGNOSTIC
    218      1.28  christos 	printf("kernfs_unmount: calling vflush\n");
    219       1.1       cgd #endif
    220      1.25  christos 	if ((error = vflush(mp, rootvp, flags)) != 0)
    221       1.1       cgd 		return (error);
    222       1.1       cgd 
    223       1.1       cgd #ifdef KERNFS_DIAGNOSTIC
    224       1.1       cgd 	vprint("kernfs root", rootvp);
    225      1.15   mycroft #endif
    226       1.1       cgd 	/*
    227      1.15   mycroft 	 * Clean out the old root vnode for reuse.
    228       1.1       cgd 	 */
    229       1.1       cgd 	vrele(rootvp);
    230       1.1       cgd 	vgone(rootvp);
    231       1.1       cgd 	/*
    232       1.1       cgd 	 * Finally, throw away the kernfs_mount structure
    233       1.1       cgd 	 */
    234      1.47   thorpej 	free(mp->mnt_data, M_KERNFSMNT);
    235       1.1       cgd 	mp->mnt_data = 0;
    236      1.15   mycroft 	return (0);
    237       1.1       cgd }
    238       1.1       cgd 
    239      1.25  christos int
    240  1.52.2.1   darrenr kernfs_root(mp, vpp, l)
    241       1.1       cgd 	struct mount *mp;
    242       1.1       cgd 	struct vnode **vpp;
    243  1.52.2.1   darrenr 	struct lwp *l;
    244       1.1       cgd {
    245       1.1       cgd 	struct vnode *vp;
    246       1.1       cgd 
    247       1.1       cgd #ifdef KERNFS_DIAGNOSTIC
    248      1.30  christos 	printf("kernfs_root(mp = %p)\n", mp);
    249       1.1       cgd #endif
    250       1.1       cgd 
    251       1.1       cgd 	/*
    252       1.1       cgd 	 * Return locked reference to root.
    253       1.1       cgd 	 */
    254       1.1       cgd 	vp = VFSTOKERNFS(mp)->kf_root;
    255       1.1       cgd 	VREF(vp);
    256      1.32      fvdl 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    257       1.1       cgd 	*vpp = vp;
    258       1.1       cgd 	return (0);
    259       1.1       cgd }
    260       1.1       cgd 
    261      1.25  christos int
    262  1.52.2.1   darrenr kernfs_quotactl(mp, cmd, uid, arg, l)
    263       1.1       cgd 	struct mount *mp;
    264       1.1       cgd 	int cmd;
    265       1.1       cgd 	uid_t uid;
    266       1.1       cgd 	caddr_t arg;
    267  1.52.2.1   darrenr 	struct lwp *l;
    268       1.1       cgd {
    269      1.15   mycroft 
    270       1.1       cgd 	return (EOPNOTSUPP);
    271       1.1       cgd }
    272       1.1       cgd 
    273      1.25  christos int
    274  1.52.2.1   darrenr kernfs_statfs(mp, sbp, l)
    275       1.1       cgd 	struct mount *mp;
    276       1.1       cgd 	struct statfs *sbp;
    277  1.52.2.1   darrenr 	struct lwp *l;
    278       1.1       cgd {
    279       1.1       cgd 
    280       1.1       cgd #ifdef KERNFS_DIAGNOSTIC
    281      1.30  christos 	printf("kernfs_statfs(mp = %p)\n", mp);
    282       1.1       cgd #endif
    283       1.1       cgd 
    284       1.1       cgd 	sbp->f_bsize = DEV_BSIZE;
    285      1.13       cgd 	sbp->f_iosize = DEV_BSIZE;
    286       1.1       cgd 	sbp->f_blocks = 2;		/* 1K to keep df happy */
    287       1.1       cgd 	sbp->f_bfree = 0;
    288       1.1       cgd 	sbp->f_bavail = 0;
    289      1.15   mycroft 	sbp->f_files = 0;
    290      1.15   mycroft 	sbp->f_ffree = 0;
    291      1.32      fvdl #ifdef COMPAT_09
    292      1.32      fvdl 	sbp->f_type = 7;
    293      1.32      fvdl #else
    294      1.32      fvdl 	sbp->f_type = 0;
    295      1.32      fvdl #endif
    296      1.48  christos 	copy_statfs_info(sbp, mp);
    297       1.1       cgd 	return (0);
    298       1.1       cgd }
    299       1.1       cgd 
    300      1.25  christos /*ARGSUSED*/
    301      1.25  christos int
    302  1.52.2.1   darrenr kernfs_sync(mp, waitfor, uc, l)
    303       1.1       cgd 	struct mount *mp;
    304       1.1       cgd 	int waitfor;
    305      1.25  christos 	struct ucred *uc;
    306  1.52.2.1   darrenr 	struct lwp *l;
    307       1.1       cgd {
    308      1.15   mycroft 
    309       1.1       cgd 	return (0);
    310       1.1       cgd }
    311       1.1       cgd 
    312      1.15   mycroft /*
    313      1.15   mycroft  * Kernfs flat namespace lookup.
    314      1.15   mycroft  * Currently unsupported.
    315      1.15   mycroft  */
    316      1.25  christos int
    317  1.52.2.1   darrenr kernfs_vget(mp, ino, vpp, l)
    318      1.15   mycroft 	struct mount *mp;
    319      1.15   mycroft 	ino_t ino;
    320      1.15   mycroft 	struct vnode **vpp;
    321  1.52.2.1   darrenr 	struct lwp *l;
    322      1.15   mycroft {
    323      1.15   mycroft 
    324      1.15   mycroft 	return (EOPNOTSUPP);
    325      1.15   mycroft }
    326      1.15   mycroft 
    327      1.25  christos /*ARGSUSED*/
    328      1.25  christos int
    329  1.52.2.1   darrenr kernfs_fhtovp(mp, fhp, vpp, l)
    330       1.1       cgd 	struct mount *mp;
    331       1.1       cgd 	struct fid *fhp;
    332      1.35  wrstuden 	struct vnode **vpp;
    333  1.52.2.1   darrenr 	struct lwp *l;
    334      1.35  wrstuden {
    335      1.35  wrstuden 
    336      1.35  wrstuden 	return (EOPNOTSUPP);
    337      1.35  wrstuden }
    338      1.35  wrstuden 
    339      1.35  wrstuden /*ARGSUSED*/
    340      1.35  wrstuden int
    341      1.35  wrstuden kernfs_checkexp(mp, mb, what, anon)
    342      1.35  wrstuden 	struct mount *mp;
    343      1.25  christos 	struct mbuf *mb;
    344      1.25  christos 	int *what;
    345      1.25  christos 	struct ucred **anon;
    346       1.1       cgd {
    347      1.15   mycroft 
    348       1.1       cgd 	return (EOPNOTSUPP);
    349       1.1       cgd }
    350       1.1       cgd 
    351      1.25  christos /*ARGSUSED*/
    352      1.25  christos int
    353       1.1       cgd kernfs_vptofh(vp, fhp)
    354       1.1       cgd 	struct vnode *vp;
    355       1.1       cgd 	struct fid *fhp;
    356       1.1       cgd {
    357      1.15   mycroft 
    358       1.1       cgd 	return (EOPNOTSUPP);
    359       1.1       cgd }
    360       1.1       cgd 
    361      1.32      fvdl int
    362  1.52.2.1   darrenr kernfs_sysctl(name, namelen, oldp, oldlenp, newp, newlen, l)
    363      1.32      fvdl 	int *name;
    364      1.32      fvdl 	u_int namelen;
    365      1.32      fvdl 	void *oldp;
    366      1.32      fvdl 	size_t *oldlenp;
    367      1.32      fvdl 	void *newp;
    368      1.32      fvdl 	size_t newlen;
    369  1.52.2.1   darrenr 	struct lwp *l;
    370      1.32      fvdl {
    371      1.32      fvdl 	return (EOPNOTSUPP);
    372      1.32      fvdl }
    373      1.32      fvdl 
    374      1.38  jdolecek extern const struct vnodeopv_desc kernfs_vnodeop_opv_desc;
    375      1.31   thorpej 
    376      1.38  jdolecek const struct vnodeopv_desc * const kernfs_vnodeopv_descs[] = {
    377      1.31   thorpej 	&kernfs_vnodeop_opv_desc,
    378      1.31   thorpej 	NULL,
    379      1.31   thorpej };
    380      1.31   thorpej 
    381       1.1       cgd struct vfsops kernfs_vfsops = {
    382      1.12       cgd 	MOUNT_KERNFS,
    383       1.1       cgd 	kernfs_mount,
    384       1.1       cgd 	kernfs_start,
    385       1.1       cgd 	kernfs_unmount,
    386       1.1       cgd 	kernfs_root,
    387       1.1       cgd 	kernfs_quotactl,
    388       1.1       cgd 	kernfs_statfs,
    389       1.1       cgd 	kernfs_sync,
    390      1.15   mycroft 	kernfs_vget,
    391       1.1       cgd 	kernfs_fhtovp,
    392       1.1       cgd 	kernfs_vptofh,
    393       1.1       cgd 	kernfs_init,
    394      1.41       chs 	NULL,
    395      1.36  jdolecek 	kernfs_done,
    396      1.32      fvdl 	kernfs_sysctl,
    397      1.31   thorpej 	NULL,				/* vfs_mountroot */
    398      1.35  wrstuden 	kernfs_checkexp,
    399      1.31   thorpej 	kernfs_vnodeopv_descs,
    400       1.1       cgd };
    401