Home | History | Annotate | Line # | Download | only in kernfs
kernfs_vfsops.c revision 1.81.10.1
      1  1.81.10.1       mjf /*	$NetBSD: kernfs_vfsops.c,v 1.81.10.1 2007/12/08 18:21:01 mjf 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.53       agc  * 3. Neither the name of the University nor the names of its contributors
     19        1.2       cgd  *    may be used to endorse or promote products derived from this software
     20        1.2       cgd  *    without specific prior written permission.
     21        1.1       cgd  *
     22        1.2       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23        1.2       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24        1.2       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25        1.2       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26        1.2       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27        1.2       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28        1.2       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29        1.2       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30        1.2       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31        1.2       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32        1.2       cgd  * SUCH DAMAGE.
     33        1.1       cgd  *
     34       1.32      fvdl  *	@(#)kernfs_vfsops.c	8.10 (Berkeley) 5/14/95
     35        1.1       cgd  */
     36        1.1       cgd 
     37        1.1       cgd /*
     38        1.1       cgd  * Kernel params Filesystem
     39        1.1       cgd  */
     40       1.42     lukem 
     41       1.42     lukem #include <sys/cdefs.h>
     42  1.81.10.1       mjf __KERNEL_RCSID(0, "$NetBSD: kernfs_vfsops.c,v 1.81.10.1 2007/12/08 18:21:01 mjf Exp $");
     43       1.33  jonathan 
     44       1.54    itojun #ifdef _KERNEL_OPT
     45       1.33  jonathan #include "opt_compat_netbsd.h"
     46       1.33  jonathan #endif
     47        1.1       cgd 
     48        1.9   mycroft #include <sys/param.h>
     49        1.9   mycroft #include <sys/systm.h>
     50       1.57    atatat #include <sys/sysctl.h>
     51       1.15   mycroft #include <sys/conf.h>
     52        1.9   mycroft #include <sys/proc.h>
     53        1.9   mycroft #include <sys/vnode.h>
     54        1.9   mycroft #include <sys/mount.h>
     55        1.9   mycroft #include <sys/namei.h>
     56       1.60  christos #include <sys/dirent.h>
     57        1.9   mycroft #include <sys/malloc.h>
     58       1.54    itojun #include <sys/syslog.h>
     59       1.71      elad #include <sys/kauth.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.77     pooka MALLOC_JUSTDEFINE(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.81     pooka VFS_PROTOS(kernfs);
     69       1.81     pooka 
     70       1.68   xtraeme void	kernfs_get_rrootdev(void);
     71       1.25  christos 
     72       1.25  christos void
     73        1.1       cgd kernfs_init()
     74        1.1       cgd {
     75       1.77     pooka 
     76       1.49  christos 	malloc_type_attach(M_KERNFSMNT);
     77       1.54    itojun 	kernfs_hashinit();
     78       1.54    itojun }
     79       1.54    itojun 
     80       1.54    itojun void
     81       1.54    itojun kernfs_reinit()
     82       1.54    itojun {
     83       1.54    itojun 	kernfs_hashreinit();
     84       1.10       cgd }
     85       1.10       cgd 
     86       1.11       cgd void
     87       1.36  jdolecek kernfs_done()
     88       1.36  jdolecek {
     89       1.77     pooka 
     90       1.77     pooka 	kernfs_hashdone();
     91       1.49  christos 	malloc_type_detach(M_KERNFSMNT);
     92       1.36  jdolecek }
     93       1.36  jdolecek 
     94       1.36  jdolecek void
     95       1.15   mycroft kernfs_get_rrootdev()
     96       1.10       cgd {
     97       1.16   mycroft 	static int tried = 0;
     98       1.10       cgd 
     99       1.16   mycroft 	if (tried) {
    100       1.15   mycroft 		/* Already did it once. */
    101       1.15   mycroft 		return;
    102       1.15   mycroft 	}
    103       1.16   mycroft 	tried = 1;
    104       1.16   mycroft 
    105       1.16   mycroft 	if (rootdev == NODEV)
    106       1.16   mycroft 		return;
    107       1.45   gehenna 	rrootdev = devsw_blk2chr(rootdev);
    108       1.54    itojun 	if (rrootdev != NODEV)
    109       1.45   gehenna 		return;
    110       1.16   mycroft 	rrootdev = NODEV;
    111       1.28  christos 	printf("kernfs_get_rrootdev: no raw root device\n");
    112        1.1       cgd }
    113        1.1       cgd 
    114        1.1       cgd /*
    115       1.15   mycroft  * Mount the Kernel params filesystem
    116        1.1       cgd  */
    117       1.25  christos int
    118  1.81.10.1       mjf kernfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
    119        1.1       cgd {
    120  1.81.10.1       mjf 	struct lwp *l = curlwp;
    121        1.1       cgd 	int error = 0;
    122        1.1       cgd 	struct kernfs_mount *fmp;
    123        1.1       cgd 
    124       1.54    itojun 	if (UIO_MX & (UIO_MX - 1)) {
    125       1.54    itojun 		log(LOG_ERR, "kernfs: invalid directory entry size");
    126       1.54    itojun 		return (EINVAL);
    127       1.54    itojun 	}
    128        1.1       cgd 
    129       1.78       dsl 	if (mp->mnt_flag & MNT_GETARGS) {
    130       1.78       dsl 		*data_len = 0;
    131       1.46  christos 		return 0;
    132       1.78       dsl 	}
    133        1.1       cgd 	/*
    134        1.1       cgd 	 * Update is a no-op
    135        1.1       cgd 	 */
    136        1.1       cgd 	if (mp->mnt_flag & MNT_UPDATE)
    137        1.1       cgd 		return (EOPNOTSUPP);
    138        1.1       cgd 
    139       1.15   mycroft 	MALLOC(fmp, struct kernfs_mount *, sizeof(struct kernfs_mount),
    140       1.47   thorpej 	    M_KERNFSMNT, M_WAITOK);
    141       1.54    itojun 	memset(fmp, 0, sizeof(*fmp));
    142       1.54    itojun 	TAILQ_INIT(&fmp->nodelist);
    143       1.54    itojun 
    144       1.65  jdolecek 	mp->mnt_stat.f_namemax = MAXNAMLEN;
    145       1.65  jdolecek 	mp->mnt_flag |= MNT_LOCAL;
    146       1.54    itojun 	mp->mnt_data = fmp;
    147       1.37     assar 	vfs_getnewfsid(mp);
    148        1.1       cgd 
    149       1.64      tron 	if ((error = set_statvfs_info(path, UIO_USERSPACE, "kernfs",
    150       1.79     pooka 	    UIO_SYSSPACE, mp->mnt_op->vfs_name, mp, l)) != 0) {
    151       1.64      tron 		free(fmp, M_KERNFSMNT);
    152       1.64      tron 		return error;
    153       1.64      tron 	}
    154       1.10       cgd 
    155       1.15   mycroft 	kernfs_get_rrootdev();
    156       1.64      tron 	return 0;
    157        1.1       cgd }
    158        1.1       cgd 
    159       1.25  christos int
    160  1.81.10.1       mjf kernfs_start(struct mount *mp, int flags)
    161        1.1       cgd {
    162       1.15   mycroft 
    163        1.1       cgd 	return (0);
    164        1.1       cgd }
    165        1.1       cgd 
    166       1.25  christos int
    167  1.81.10.1       mjf kernfs_unmount(struct mount *mp, int mntflags)
    168        1.1       cgd {
    169        1.1       cgd 	int error;
    170        1.1       cgd 	int flags = 0;
    171        1.1       cgd 
    172       1.54    itojun 	if (mntflags & MNT_FORCE)
    173        1.1       cgd 		flags |= FORCECLOSE;
    174        1.1       cgd 
    175       1.54    itojun 	if ((error = vflush(mp, 0, flags)) != 0)
    176        1.1       cgd 		return (error);
    177        1.1       cgd 
    178        1.1       cgd 	/*
    179        1.1       cgd 	 * Finally, throw away the kernfs_mount structure
    180        1.1       cgd 	 */
    181       1.47   thorpej 	free(mp->mnt_data, M_KERNFSMNT);
    182       1.64      tron 	mp->mnt_data = NULL;
    183       1.15   mycroft 	return (0);
    184        1.1       cgd }
    185        1.1       cgd 
    186       1.25  christos int
    187       1.51   thorpej kernfs_root(mp, vpp)
    188        1.1       cgd 	struct mount *mp;
    189        1.1       cgd 	struct vnode **vpp;
    190        1.1       cgd {
    191        1.1       cgd 
    192       1.54    itojun 	/* setup "." */
    193       1.56     darcy 	return (kernfs_allocvp(mp, vpp, KFSkern, &kern_targets[0], 0));
    194        1.1       cgd }
    195        1.1       cgd 
    196       1.25  christos int
    197  1.81.10.1       mjf kernfs_statvfs(struct mount *mp, struct statvfs *sbp)
    198        1.1       cgd {
    199        1.1       cgd 
    200        1.1       cgd 	sbp->f_bsize = DEV_BSIZE;
    201       1.59  christos 	sbp->f_frsize = DEV_BSIZE;
    202       1.13       cgd 	sbp->f_iosize = DEV_BSIZE;
    203        1.1       cgd 	sbp->f_blocks = 2;		/* 1K to keep df happy */
    204        1.1       cgd 	sbp->f_bfree = 0;
    205        1.1       cgd 	sbp->f_bavail = 0;
    206       1.59  christos 	sbp->f_bresvd = 0;
    207       1.54    itojun 	sbp->f_files = 1024;	/* XXX lie */
    208       1.54    itojun 	sbp->f_ffree = 128;	/* XXX lie */
    209       1.59  christos 	sbp->f_favail = 128;	/* XXX lie */
    210       1.59  christos 	sbp->f_fresvd = 0;
    211       1.59  christos 	copy_statvfs_info(sbp, mp);
    212        1.1       cgd 	return (0);
    213        1.1       cgd }
    214        1.1       cgd 
    215       1.25  christos /*ARGSUSED*/
    216       1.25  christos int
    217       1.74  christos kernfs_sync(struct mount *mp, int waitfor,
    218  1.81.10.1       mjf     kauth_cred_t uc)
    219        1.1       cgd {
    220       1.15   mycroft 
    221        1.1       cgd 	return (0);
    222        1.1       cgd }
    223        1.1       cgd 
    224       1.15   mycroft /*
    225       1.15   mycroft  * Kernfs flat namespace lookup.
    226       1.15   mycroft  * Currently unsupported.
    227       1.15   mycroft  */
    228       1.25  christos int
    229       1.74  christos kernfs_vget(struct mount *mp, ino_t ino,
    230       1.74  christos     struct vnode **vpp)
    231       1.15   mycroft {
    232       1.15   mycroft 
    233       1.15   mycroft 	return (EOPNOTSUPP);
    234       1.15   mycroft }
    235       1.15   mycroft 
    236       1.58    atatat SYSCTL_SETUP(sysctl_vfs_kernfs_setup, "sysctl vfs.kern subtree setup")
    237       1.32      fvdl {
    238       1.57    atatat 
    239       1.58    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    240       1.58    atatat 		       CTLFLAG_PERMANENT,
    241       1.57    atatat 		       CTLTYPE_NODE, "vfs", NULL,
    242       1.57    atatat 		       NULL, 0, NULL, 0,
    243       1.57    atatat 		       CTL_VFS, CTL_EOL);
    244       1.58    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    245       1.58    atatat 		       CTLFLAG_PERMANENT,
    246       1.62    atatat 		       CTLTYPE_NODE, "kernfs",
    247       1.62    atatat 		       SYSCTL_DESCR("/kern file system"),
    248       1.57    atatat 		       NULL, 0, NULL, 0,
    249       1.57    atatat 		       CTL_VFS, 11, CTL_EOL);
    250       1.57    atatat 	/*
    251       1.57    atatat 	 * XXX the "11" above could be dynamic, thereby eliminating one
    252       1.57    atatat 	 * more instance of the "number to vfs" mapping problem, but
    253       1.57    atatat 	 * "11" is the order as taken from sys/mount.h
    254       1.57    atatat 	 */
    255       1.32      fvdl }
    256       1.32      fvdl 
    257       1.38  jdolecek extern const struct vnodeopv_desc kernfs_vnodeop_opv_desc;
    258       1.31   thorpej 
    259       1.38  jdolecek const struct vnodeopv_desc * const kernfs_vnodeopv_descs[] = {
    260       1.31   thorpej 	&kernfs_vnodeop_opv_desc,
    261       1.31   thorpej 	NULL,
    262       1.31   thorpej };
    263       1.31   thorpej 
    264        1.1       cgd struct vfsops kernfs_vfsops = {
    265       1.12       cgd 	MOUNT_KERNFS,
    266       1.78       dsl 	0,
    267        1.1       cgd 	kernfs_mount,
    268        1.1       cgd 	kernfs_start,
    269        1.1       cgd 	kernfs_unmount,
    270        1.1       cgd 	kernfs_root,
    271  1.81.10.1       mjf 	(void *)eopnotsupp,		/* vfs_quotactl */
    272       1.59  christos 	kernfs_statvfs,
    273        1.1       cgd 	kernfs_sync,
    274       1.15   mycroft 	kernfs_vget,
    275       1.75       chs 	(void *)eopnotsupp,		/* vfs_fhtovp */
    276       1.75       chs 	(void *)eopnotsupp,		/* vfs_vptofh */
    277        1.1       cgd 	kernfs_init,
    278       1.54    itojun 	kernfs_reinit,
    279       1.36  jdolecek 	kernfs_done,
    280       1.31   thorpej 	NULL,				/* vfs_mountroot */
    281       1.63   hannken 	(int (*)(struct mount *, struct vnode *, struct timespec *)) eopnotsupp,
    282       1.66   thorpej 	vfs_stdextattrctl,
    283       1.80     pooka 	(void *)eopnotsupp,		/* vfs_suspendctl */
    284       1.31   thorpej 	kernfs_vnodeopv_descs,
    285       1.72  christos 	0,
    286       1.72  christos 	{ NULL, NULL },
    287        1.1       cgd };
    288       1.67   thorpej VFS_ATTACH(kernfs_vfsops);
    289