Home | History | Annotate | Line # | Download | only in kernfs
kernfs_vfsops.c revision 1.56
      1  1.56     darcy /*	$NetBSD: kernfs_vfsops.c,v 1.56 2003/09/27 13:29:02 darcy 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.56     darcy __KERNEL_RCSID(0, "$NetBSD: kernfs_vfsops.c,v 1.56 2003/09/27 13:29:02 darcy 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.15   mycroft #include <sys/conf.h>
     51   1.9   mycroft #include <sys/proc.h>
     52   1.9   mycroft #include <sys/vnode.h>
     53   1.9   mycroft #include <sys/mount.h>
     54   1.9   mycroft #include <sys/namei.h>
     55   1.9   mycroft #include <sys/malloc.h>
     56  1.54    itojun #include <sys/syslog.h>
     57  1.15   mycroft 
     58  1.15   mycroft #include <miscfs/specfs/specdev.h>
     59   1.9   mycroft #include <miscfs/kernfs/kernfs.h>
     60   1.1       cgd 
     61  1.47   thorpej MALLOC_DEFINE(M_KERNFSMNT, "kernfs mount", "kernfs mount structures");
     62  1.47   thorpej 
     63  1.15   mycroft dev_t rrootdev = NODEV;
     64  1.15   mycroft 
     65  1.25  christos void	kernfs_init __P((void));
     66  1.54    itojun void	kernfs_reinit __P((void));
     67  1.36  jdolecek void	kernfs_done __P((void));
     68  1.25  christos void	kernfs_get_rrootdev __P((void));
     69  1.29       cgd int	kernfs_mount __P((struct mount *, const char *, void *,
     70  1.52      fvdl 	    struct nameidata *, struct proc *));
     71  1.52      fvdl int	kernfs_start __P((struct mount *, int, struct proc *));
     72  1.52      fvdl int	kernfs_unmount __P((struct mount *, int, struct proc *));
     73  1.52      fvdl int	kernfs_statfs __P((struct mount *, struct statfs *, struct proc *));
     74  1.25  christos int	kernfs_quotactl __P((struct mount *, int, uid_t, caddr_t,
     75  1.52      fvdl 			     struct proc *));
     76  1.52      fvdl int	kernfs_sync __P((struct mount *, int, struct ucred *, struct proc *));
     77  1.51   thorpej int	kernfs_vget __P((struct mount *, ino_t, struct vnode **));
     78  1.51   thorpej int	kernfs_fhtovp __P((struct mount *, struct fid *, struct vnode **));
     79  1.35  wrstuden int	kernfs_checkexp __P((struct mount *, struct mbuf *, int *,
     80  1.35  wrstuden 			   struct ucred **));
     81  1.25  christos int	kernfs_vptofh __P((struct vnode *, struct fid *));
     82  1.32      fvdl int	kernfs_sysctl __P((int *, u_int, void *, size_t *, void *, size_t,
     83  1.52      fvdl 			   struct proc *));
     84  1.25  christos 
     85  1.25  christos void
     86   1.1       cgd kernfs_init()
     87   1.1       cgd {
     88  1.49  christos #ifdef _LKM
     89  1.49  christos 	malloc_type_attach(M_KERNFSMNT);
     90  1.49  christos #endif
     91  1.54    itojun 	kernfs_hashinit();
     92  1.54    itojun }
     93  1.54    itojun 
     94  1.54    itojun void
     95  1.54    itojun kernfs_reinit()
     96  1.54    itojun {
     97  1.54    itojun 	kernfs_hashreinit();
     98  1.10       cgd }
     99  1.10       cgd 
    100  1.11       cgd void
    101  1.36  jdolecek kernfs_done()
    102  1.36  jdolecek {
    103  1.49  christos #ifdef _LKM
    104  1.49  christos 	malloc_type_detach(M_KERNFSMNT);
    105  1.49  christos #endif
    106  1.54    itojun 	kernfs_hashdone();
    107  1.36  jdolecek }
    108  1.36  jdolecek 
    109  1.36  jdolecek void
    110  1.15   mycroft kernfs_get_rrootdev()
    111  1.10       cgd {
    112  1.16   mycroft 	static int tried = 0;
    113  1.10       cgd 
    114  1.16   mycroft 	if (tried) {
    115  1.15   mycroft 		/* Already did it once. */
    116  1.15   mycroft 		return;
    117  1.15   mycroft 	}
    118  1.16   mycroft 	tried = 1;
    119  1.16   mycroft 
    120  1.16   mycroft 	if (rootdev == NODEV)
    121  1.16   mycroft 		return;
    122  1.45   gehenna 	rrootdev = devsw_blk2chr(rootdev);
    123  1.54    itojun 	if (rrootdev != NODEV)
    124  1.45   gehenna 		return;
    125  1.16   mycroft 	rrootdev = NODEV;
    126  1.28  christos 	printf("kernfs_get_rrootdev: no raw root device\n");
    127   1.1       cgd }
    128   1.1       cgd 
    129   1.1       cgd /*
    130  1.15   mycroft  * Mount the Kernel params filesystem
    131   1.1       cgd  */
    132  1.25  christos int
    133  1.52      fvdl kernfs_mount(mp, path, data, ndp, p)
    134   1.1       cgd 	struct mount *mp;
    135  1.29       cgd 	const char *path;
    136  1.29       cgd 	void *data;
    137   1.1       cgd 	struct nameidata *ndp;
    138  1.52      fvdl 	struct proc *p;
    139   1.1       cgd {
    140   1.1       cgd 	int error = 0;
    141   1.1       cgd 	struct kernfs_mount *fmp;
    142   1.1       cgd 
    143  1.54    itojun 	if (UIO_MX & (UIO_MX - 1)) {
    144  1.54    itojun 		log(LOG_ERR, "kernfs: invalid directory entry size");
    145  1.54    itojun 		return (EINVAL);
    146  1.54    itojun 	}
    147   1.1       cgd 
    148  1.46  christos 	if (mp->mnt_flag & MNT_GETARGS)
    149  1.46  christos 		return 0;
    150   1.1       cgd 	/*
    151   1.1       cgd 	 * Update is a no-op
    152   1.1       cgd 	 */
    153   1.1       cgd 	if (mp->mnt_flag & MNT_UPDATE)
    154   1.1       cgd 		return (EOPNOTSUPP);
    155   1.1       cgd 
    156  1.15   mycroft 	MALLOC(fmp, struct kernfs_mount *, sizeof(struct kernfs_mount),
    157  1.47   thorpej 	    M_KERNFSMNT, M_WAITOK);
    158  1.54    itojun 	memset(fmp, 0, sizeof(*fmp));
    159  1.54    itojun 	TAILQ_INIT(&fmp->nodelist);
    160  1.54    itojun 
    161  1.54    itojun 	mp->mnt_data = fmp;
    162   1.1       cgd 	mp->mnt_flag |= MNT_LOCAL;
    163  1.37     assar 	vfs_getnewfsid(mp);
    164   1.1       cgd 
    165  1.48  christos 	error = set_statfs_info(path, UIO_USERSPACE, "kernfs", UIO_SYSSPACE,
    166  1.52      fvdl 	    mp, p);
    167  1.10       cgd 
    168  1.15   mycroft 	kernfs_get_rrootdev();
    169  1.48  christos 	return error;
    170   1.1       cgd }
    171   1.1       cgd 
    172  1.25  christos int
    173  1.52      fvdl kernfs_start(mp, flags, p)
    174   1.1       cgd 	struct mount *mp;
    175   1.1       cgd 	int flags;
    176  1.52      fvdl 	struct proc *p;
    177   1.1       cgd {
    178  1.15   mycroft 
    179   1.1       cgd 	return (0);
    180   1.1       cgd }
    181   1.1       cgd 
    182  1.25  christos int
    183  1.52      fvdl kernfs_unmount(mp, mntflags, p)
    184   1.1       cgd 	struct mount *mp;
    185   1.1       cgd 	int mntflags;
    186  1.52      fvdl 	struct proc *p;
    187   1.1       cgd {
    188   1.1       cgd 	int error;
    189   1.1       cgd 	int flags = 0;
    190   1.1       cgd 
    191  1.54    itojun 	if (mntflags & MNT_FORCE)
    192   1.1       cgd 		flags |= FORCECLOSE;
    193   1.1       cgd 
    194  1.54    itojun 	if ((error = vflush(mp, 0, flags)) != 0)
    195   1.1       cgd 		return (error);
    196   1.1       cgd 
    197   1.1       cgd 	/*
    198   1.1       cgd 	 * Finally, throw away the kernfs_mount structure
    199   1.1       cgd 	 */
    200  1.47   thorpej 	free(mp->mnt_data, M_KERNFSMNT);
    201   1.1       cgd 	mp->mnt_data = 0;
    202  1.15   mycroft 	return (0);
    203   1.1       cgd }
    204   1.1       cgd 
    205  1.25  christos int
    206  1.51   thorpej kernfs_root(mp, vpp)
    207   1.1       cgd 	struct mount *mp;
    208   1.1       cgd 	struct vnode **vpp;
    209   1.1       cgd {
    210   1.1       cgd 
    211  1.54    itojun 	/* setup "." */
    212  1.56     darcy 	return (kernfs_allocvp(mp, vpp, KFSkern, &kern_targets[0], 0));
    213   1.1       cgd }
    214   1.1       cgd 
    215  1.25  christos int
    216  1.52      fvdl kernfs_quotactl(mp, cmd, uid, arg, p)
    217   1.1       cgd 	struct mount *mp;
    218   1.1       cgd 	int cmd;
    219   1.1       cgd 	uid_t uid;
    220   1.1       cgd 	caddr_t arg;
    221  1.52      fvdl 	struct proc *p;
    222   1.1       cgd {
    223  1.15   mycroft 
    224   1.1       cgd 	return (EOPNOTSUPP);
    225   1.1       cgd }
    226   1.1       cgd 
    227  1.25  christos int
    228  1.52      fvdl kernfs_statfs(mp, sbp, p)
    229   1.1       cgd 	struct mount *mp;
    230   1.1       cgd 	struct statfs *sbp;
    231  1.52      fvdl 	struct proc *p;
    232   1.1       cgd {
    233   1.1       cgd 
    234   1.1       cgd 	sbp->f_bsize = DEV_BSIZE;
    235  1.13       cgd 	sbp->f_iosize = DEV_BSIZE;
    236   1.1       cgd 	sbp->f_blocks = 2;		/* 1K to keep df happy */
    237   1.1       cgd 	sbp->f_bfree = 0;
    238   1.1       cgd 	sbp->f_bavail = 0;
    239  1.54    itojun 	sbp->f_files = 1024;	/* XXX lie */
    240  1.54    itojun 	sbp->f_ffree = 128;	/* XXX lie */
    241  1.32      fvdl #ifdef COMPAT_09
    242  1.32      fvdl 	sbp->f_type = 7;
    243  1.32      fvdl #else
    244  1.32      fvdl 	sbp->f_type = 0;
    245  1.32      fvdl #endif
    246  1.48  christos 	copy_statfs_info(sbp, mp);
    247   1.1       cgd 	return (0);
    248   1.1       cgd }
    249   1.1       cgd 
    250  1.25  christos /*ARGSUSED*/
    251  1.25  christos int
    252  1.52      fvdl kernfs_sync(mp, waitfor, uc, p)
    253   1.1       cgd 	struct mount *mp;
    254   1.1       cgd 	int waitfor;
    255  1.25  christos 	struct ucred *uc;
    256  1.52      fvdl 	struct proc *p;
    257   1.1       cgd {
    258  1.15   mycroft 
    259   1.1       cgd 	return (0);
    260   1.1       cgd }
    261   1.1       cgd 
    262  1.15   mycroft /*
    263  1.15   mycroft  * Kernfs flat namespace lookup.
    264  1.15   mycroft  * Currently unsupported.
    265  1.15   mycroft  */
    266  1.25  christos int
    267  1.51   thorpej kernfs_vget(mp, ino, vpp)
    268  1.15   mycroft 	struct mount *mp;
    269  1.15   mycroft 	ino_t ino;
    270  1.15   mycroft 	struct vnode **vpp;
    271  1.15   mycroft {
    272  1.15   mycroft 
    273  1.15   mycroft 	return (EOPNOTSUPP);
    274  1.15   mycroft }
    275  1.15   mycroft 
    276  1.25  christos /*ARGSUSED*/
    277  1.25  christos int
    278  1.51   thorpej kernfs_fhtovp(mp, fhp, vpp)
    279   1.1       cgd 	struct mount *mp;
    280   1.1       cgd 	struct fid *fhp;
    281  1.35  wrstuden 	struct vnode **vpp;
    282  1.35  wrstuden {
    283  1.35  wrstuden 
    284  1.35  wrstuden 	return (EOPNOTSUPP);
    285  1.35  wrstuden }
    286  1.35  wrstuden 
    287  1.35  wrstuden /*ARGSUSED*/
    288  1.35  wrstuden int
    289  1.35  wrstuden kernfs_checkexp(mp, mb, what, anon)
    290  1.35  wrstuden 	struct mount *mp;
    291  1.25  christos 	struct mbuf *mb;
    292  1.25  christos 	int *what;
    293  1.25  christos 	struct ucred **anon;
    294   1.1       cgd {
    295  1.15   mycroft 
    296   1.1       cgd 	return (EOPNOTSUPP);
    297   1.1       cgd }
    298   1.1       cgd 
    299  1.25  christos /*ARGSUSED*/
    300  1.25  christos int
    301   1.1       cgd kernfs_vptofh(vp, fhp)
    302   1.1       cgd 	struct vnode *vp;
    303   1.1       cgd 	struct fid *fhp;
    304   1.1       cgd {
    305  1.15   mycroft 
    306   1.1       cgd 	return (EOPNOTSUPP);
    307   1.1       cgd }
    308   1.1       cgd 
    309  1.32      fvdl int
    310  1.52      fvdl kernfs_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
    311  1.32      fvdl 	int *name;
    312  1.32      fvdl 	u_int namelen;
    313  1.32      fvdl 	void *oldp;
    314  1.32      fvdl 	size_t *oldlenp;
    315  1.32      fvdl 	void *newp;
    316  1.32      fvdl 	size_t newlen;
    317  1.52      fvdl 	struct proc *p;
    318  1.32      fvdl {
    319  1.32      fvdl 	return (EOPNOTSUPP);
    320  1.32      fvdl }
    321  1.32      fvdl 
    322  1.38  jdolecek extern const struct vnodeopv_desc kernfs_vnodeop_opv_desc;
    323  1.31   thorpej 
    324  1.38  jdolecek const struct vnodeopv_desc * const kernfs_vnodeopv_descs[] = {
    325  1.31   thorpej 	&kernfs_vnodeop_opv_desc,
    326  1.31   thorpej 	NULL,
    327  1.31   thorpej };
    328  1.31   thorpej 
    329   1.1       cgd struct vfsops kernfs_vfsops = {
    330  1.12       cgd 	MOUNT_KERNFS,
    331   1.1       cgd 	kernfs_mount,
    332   1.1       cgd 	kernfs_start,
    333   1.1       cgd 	kernfs_unmount,
    334   1.1       cgd 	kernfs_root,
    335   1.1       cgd 	kernfs_quotactl,
    336   1.1       cgd 	kernfs_statfs,
    337   1.1       cgd 	kernfs_sync,
    338  1.15   mycroft 	kernfs_vget,
    339   1.1       cgd 	kernfs_fhtovp,
    340   1.1       cgd 	kernfs_vptofh,
    341   1.1       cgd 	kernfs_init,
    342  1.54    itojun 	kernfs_reinit,
    343  1.36  jdolecek 	kernfs_done,
    344  1.32      fvdl 	kernfs_sysctl,
    345  1.31   thorpej 	NULL,				/* vfs_mountroot */
    346  1.35  wrstuden 	kernfs_checkexp,
    347  1.31   thorpej 	kernfs_vnodeopv_descs,
    348   1.1       cgd };
    349