Home | History | Annotate | Line # | Download | only in kernfs
kernfs_vfsops.c revision 1.57
      1 /*	$NetBSD: kernfs_vfsops.c,v 1.57 2003/12/04 19:38:24 atatat Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1992, 1993, 1995
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * This code is derived from software donated to Berkeley by
      8  * Jan-Simon Pendry.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. Neither the name of the University nor the names of its contributors
     19  *    may be used to endorse or promote products derived from this software
     20  *    without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  * SUCH DAMAGE.
     33  *
     34  *	@(#)kernfs_vfsops.c	8.10 (Berkeley) 5/14/95
     35  */
     36 
     37 /*
     38  * Kernel params Filesystem
     39  */
     40 
     41 #include <sys/cdefs.h>
     42 __KERNEL_RCSID(0, "$NetBSD: kernfs_vfsops.c,v 1.57 2003/12/04 19:38:24 atatat Exp $");
     43 
     44 #ifdef _KERNEL_OPT
     45 #include "opt_compat_netbsd.h"
     46 #endif
     47 
     48 #include <sys/param.h>
     49 #include <sys/systm.h>
     50 #include <sys/sysctl.h>
     51 #include <sys/conf.h>
     52 #include <sys/proc.h>
     53 #include <sys/vnode.h>
     54 #include <sys/mount.h>
     55 #include <sys/namei.h>
     56 #include <sys/malloc.h>
     57 #include <sys/syslog.h>
     58 
     59 #include <miscfs/specfs/specdev.h>
     60 #include <miscfs/kernfs/kernfs.h>
     61 
     62 MALLOC_DEFINE(M_KERNFSMNT, "kernfs mount", "kernfs mount structures");
     63 
     64 dev_t rrootdev = NODEV;
     65 
     66 void	kernfs_init __P((void));
     67 void	kernfs_reinit __P((void));
     68 void	kernfs_done __P((void));
     69 void	kernfs_get_rrootdev __P((void));
     70 int	kernfs_mount __P((struct mount *, const char *, void *,
     71 	    struct nameidata *, struct proc *));
     72 int	kernfs_start __P((struct mount *, int, struct proc *));
     73 int	kernfs_unmount __P((struct mount *, int, struct proc *));
     74 int	kernfs_statfs __P((struct mount *, struct statfs *, struct proc *));
     75 int	kernfs_quotactl __P((struct mount *, int, uid_t, caddr_t,
     76 			     struct proc *));
     77 int	kernfs_sync __P((struct mount *, int, struct ucred *, struct proc *));
     78 int	kernfs_vget __P((struct mount *, ino_t, struct vnode **));
     79 int	kernfs_fhtovp __P((struct mount *, struct fid *, struct vnode **));
     80 int	kernfs_checkexp __P((struct mount *, struct mbuf *, int *,
     81 			   struct ucred **));
     82 int	kernfs_vptofh __P((struct vnode *, struct fid *));
     83 
     84 void
     85 kernfs_init()
     86 {
     87 #ifdef _LKM
     88 	malloc_type_attach(M_KERNFSMNT);
     89 #endif
     90 	kernfs_hashinit();
     91 }
     92 
     93 void
     94 kernfs_reinit()
     95 {
     96 	kernfs_hashreinit();
     97 }
     98 
     99 void
    100 kernfs_done()
    101 {
    102 #ifdef _LKM
    103 	malloc_type_detach(M_KERNFSMNT);
    104 #endif
    105 	kernfs_hashdone();
    106 }
    107 
    108 void
    109 kernfs_get_rrootdev()
    110 {
    111 	static int tried = 0;
    112 
    113 	if (tried) {
    114 		/* Already did it once. */
    115 		return;
    116 	}
    117 	tried = 1;
    118 
    119 	if (rootdev == NODEV)
    120 		return;
    121 	rrootdev = devsw_blk2chr(rootdev);
    122 	if (rrootdev != NODEV)
    123 		return;
    124 	rrootdev = NODEV;
    125 	printf("kernfs_get_rrootdev: no raw root device\n");
    126 }
    127 
    128 /*
    129  * Mount the Kernel params filesystem
    130  */
    131 int
    132 kernfs_mount(mp, path, data, ndp, p)
    133 	struct mount *mp;
    134 	const char *path;
    135 	void *data;
    136 	struct nameidata *ndp;
    137 	struct proc *p;
    138 {
    139 	int error = 0;
    140 	struct kernfs_mount *fmp;
    141 
    142 	if (UIO_MX & (UIO_MX - 1)) {
    143 		log(LOG_ERR, "kernfs: invalid directory entry size");
    144 		return (EINVAL);
    145 	}
    146 
    147 	if (mp->mnt_flag & MNT_GETARGS)
    148 		return 0;
    149 	/*
    150 	 * Update is a no-op
    151 	 */
    152 	if (mp->mnt_flag & MNT_UPDATE)
    153 		return (EOPNOTSUPP);
    154 
    155 	MALLOC(fmp, struct kernfs_mount *, sizeof(struct kernfs_mount),
    156 	    M_KERNFSMNT, M_WAITOK);
    157 	memset(fmp, 0, sizeof(*fmp));
    158 	TAILQ_INIT(&fmp->nodelist);
    159 
    160 	mp->mnt_data = fmp;
    161 	mp->mnt_flag |= MNT_LOCAL;
    162 	vfs_getnewfsid(mp);
    163 
    164 	error = set_statfs_info(path, UIO_USERSPACE, "kernfs", UIO_SYSSPACE,
    165 	    mp, p);
    166 
    167 	kernfs_get_rrootdev();
    168 	return error;
    169 }
    170 
    171 int
    172 kernfs_start(mp, flags, p)
    173 	struct mount *mp;
    174 	int flags;
    175 	struct proc *p;
    176 {
    177 
    178 	return (0);
    179 }
    180 
    181 int
    182 kernfs_unmount(mp, mntflags, p)
    183 	struct mount *mp;
    184 	int mntflags;
    185 	struct proc *p;
    186 {
    187 	int error;
    188 	int flags = 0;
    189 
    190 	if (mntflags & MNT_FORCE)
    191 		flags |= FORCECLOSE;
    192 
    193 	if ((error = vflush(mp, 0, flags)) != 0)
    194 		return (error);
    195 
    196 	/*
    197 	 * Finally, throw away the kernfs_mount structure
    198 	 */
    199 	free(mp->mnt_data, M_KERNFSMNT);
    200 	mp->mnt_data = 0;
    201 	return (0);
    202 }
    203 
    204 int
    205 kernfs_root(mp, vpp)
    206 	struct mount *mp;
    207 	struct vnode **vpp;
    208 {
    209 
    210 	/* setup "." */
    211 	return (kernfs_allocvp(mp, vpp, KFSkern, &kern_targets[0], 0));
    212 }
    213 
    214 int
    215 kernfs_quotactl(mp, cmd, uid, arg, p)
    216 	struct mount *mp;
    217 	int cmd;
    218 	uid_t uid;
    219 	caddr_t arg;
    220 	struct proc *p;
    221 {
    222 
    223 	return (EOPNOTSUPP);
    224 }
    225 
    226 int
    227 kernfs_statfs(mp, sbp, p)
    228 	struct mount *mp;
    229 	struct statfs *sbp;
    230 	struct proc *p;
    231 {
    232 
    233 	sbp->f_bsize = DEV_BSIZE;
    234 	sbp->f_iosize = DEV_BSIZE;
    235 	sbp->f_blocks = 2;		/* 1K to keep df happy */
    236 	sbp->f_bfree = 0;
    237 	sbp->f_bavail = 0;
    238 	sbp->f_files = 1024;	/* XXX lie */
    239 	sbp->f_ffree = 128;	/* XXX lie */
    240 #ifdef COMPAT_09
    241 	sbp->f_type = 7;
    242 #else
    243 	sbp->f_type = 0;
    244 #endif
    245 	copy_statfs_info(sbp, mp);
    246 	return (0);
    247 }
    248 
    249 /*ARGSUSED*/
    250 int
    251 kernfs_sync(mp, waitfor, uc, p)
    252 	struct mount *mp;
    253 	int waitfor;
    254 	struct ucred *uc;
    255 	struct proc *p;
    256 {
    257 
    258 	return (0);
    259 }
    260 
    261 /*
    262  * Kernfs flat namespace lookup.
    263  * Currently unsupported.
    264  */
    265 int
    266 kernfs_vget(mp, ino, vpp)
    267 	struct mount *mp;
    268 	ino_t ino;
    269 	struct vnode **vpp;
    270 {
    271 
    272 	return (EOPNOTSUPP);
    273 }
    274 
    275 /*ARGSUSED*/
    276 int
    277 kernfs_fhtovp(mp, fhp, vpp)
    278 	struct mount *mp;
    279 	struct fid *fhp;
    280 	struct vnode **vpp;
    281 {
    282 
    283 	return (EOPNOTSUPP);
    284 }
    285 
    286 /*ARGSUSED*/
    287 int
    288 kernfs_checkexp(mp, mb, what, anon)
    289 	struct mount *mp;
    290 	struct mbuf *mb;
    291 	int *what;
    292 	struct ucred **anon;
    293 {
    294 
    295 	return (EOPNOTSUPP);
    296 }
    297 
    298 /*ARGSUSED*/
    299 int
    300 kernfs_vptofh(vp, fhp)
    301 	struct vnode *vp;
    302 	struct fid *fhp;
    303 {
    304 
    305 	return (EOPNOTSUPP);
    306 }
    307 
    308 SYSCTL_SETUP(sysctl_vfs_kern_setup, "sysctl vfs.kern subtree setup")
    309 {
    310 
    311 	sysctl_createv(SYSCTL_PERMANENT,
    312 		       CTLTYPE_NODE, "vfs", NULL,
    313 		       NULL, 0, NULL, 0,
    314 		       CTL_VFS, CTL_EOL);
    315 	sysctl_createv(SYSCTL_PERMANENT,
    316 		       CTLTYPE_NODE, "kernfs", NULL,
    317 		       NULL, 0, NULL, 0,
    318 		       CTL_VFS, 11, CTL_EOL);
    319 	/*
    320 	 * XXX the "11" above could be dynamic, thereby eliminating one
    321 	 * more instance of the "number to vfs" mapping problem, but
    322 	 * "11" is the order as taken from sys/mount.h
    323 	 */
    324 }
    325 
    326 extern const struct vnodeopv_desc kernfs_vnodeop_opv_desc;
    327 
    328 const struct vnodeopv_desc * const kernfs_vnodeopv_descs[] = {
    329 	&kernfs_vnodeop_opv_desc,
    330 	NULL,
    331 };
    332 
    333 struct vfsops kernfs_vfsops = {
    334 	MOUNT_KERNFS,
    335 	kernfs_mount,
    336 	kernfs_start,
    337 	kernfs_unmount,
    338 	kernfs_root,
    339 	kernfs_quotactl,
    340 	kernfs_statfs,
    341 	kernfs_sync,
    342 	kernfs_vget,
    343 	kernfs_fhtovp,
    344 	kernfs_vptofh,
    345 	kernfs_init,
    346 	kernfs_reinit,
    347 	kernfs_done,
    348 	NULL,
    349 	NULL,				/* vfs_mountroot */
    350 	kernfs_checkexp,
    351 	kernfs_vnodeopv_descs,
    352 };
    353