Home | History | Annotate | Line # | Download | only in kern
vfs_init.c revision 1.34.10.2
      1  1.34.10.2  pooka /*	$NetBSD: vfs_init.c,v 1.34.10.2 2007/07/27 14:25:22 pooka Exp $	*/
      2  1.34.10.2  pooka 
      3  1.34.10.2  pooka /*-
      4  1.34.10.2  pooka  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
      5  1.34.10.2  pooka  * All rights reserved.
      6  1.34.10.2  pooka  *
      7  1.34.10.2  pooka  * This code is derived from software contributed to The NetBSD Foundation
      8  1.34.10.2  pooka  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  1.34.10.2  pooka  * NASA Ames Research Center.
     10  1.34.10.2  pooka  *
     11  1.34.10.2  pooka  * Redistribution and use in source and binary forms, with or without
     12  1.34.10.2  pooka  * modification, are permitted provided that the following conditions
     13  1.34.10.2  pooka  * are met:
     14  1.34.10.2  pooka  * 1. Redistributions of source code must retain the above copyright
     15  1.34.10.2  pooka  *    notice, this list of conditions and the following disclaimer.
     16  1.34.10.2  pooka  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.34.10.2  pooka  *    notice, this list of conditions and the following disclaimer in the
     18  1.34.10.2  pooka  *    documentation and/or other materials provided with the distribution.
     19  1.34.10.2  pooka  * 3. All advertising materials mentioning features or use of this software
     20  1.34.10.2  pooka  *    must display the following acknowledgement:
     21  1.34.10.2  pooka  *	This product includes software developed by the NetBSD
     22  1.34.10.2  pooka  *	Foundation, Inc. and its contributors.
     23  1.34.10.2  pooka  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  1.34.10.2  pooka  *    contributors may be used to endorse or promote products derived
     25  1.34.10.2  pooka  *    from this software without specific prior written permission.
     26  1.34.10.2  pooka  *
     27  1.34.10.2  pooka  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  1.34.10.2  pooka  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  1.34.10.2  pooka  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  1.34.10.2  pooka  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  1.34.10.2  pooka  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  1.34.10.2  pooka  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  1.34.10.2  pooka  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  1.34.10.2  pooka  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  1.34.10.2  pooka  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  1.34.10.2  pooka  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  1.34.10.2  pooka  * POSSIBILITY OF SUCH DAMAGE.
     38  1.34.10.2  pooka  */
     39  1.34.10.2  pooka 
     40  1.34.10.2  pooka /*
     41  1.34.10.2  pooka  * Copyright (c) 1989, 1993
     42  1.34.10.2  pooka  *	The Regents of the University of California.  All rights reserved.
     43  1.34.10.2  pooka  *
     44  1.34.10.2  pooka  * This code is derived from software contributed
     45  1.34.10.2  pooka  * to Berkeley by John Heidemann of the UCLA Ficus project.
     46  1.34.10.2  pooka  *
     47  1.34.10.2  pooka  * Source: * @(#)i405_init.c 2.10 92/04/27 UCLA Ficus project
     48  1.34.10.2  pooka  *
     49  1.34.10.2  pooka  * Redistribution and use in source and binary forms, with or without
     50  1.34.10.2  pooka  * modification, are permitted provided that the following conditions
     51  1.34.10.2  pooka  * are met:
     52  1.34.10.2  pooka  * 1. Redistributions of source code must retain the above copyright
     53  1.34.10.2  pooka  *    notice, this list of conditions and the following disclaimer.
     54  1.34.10.2  pooka  * 2. Redistributions in binary form must reproduce the above copyright
     55  1.34.10.2  pooka  *    notice, this list of conditions and the following disclaimer in the
     56  1.34.10.2  pooka  *    documentation and/or other materials provided with the distribution.
     57  1.34.10.2  pooka  * 3. Neither the name of the University nor the names of its contributors
     58  1.34.10.2  pooka  *    may be used to endorse or promote products derived from this software
     59  1.34.10.2  pooka  *    without specific prior written permission.
     60  1.34.10.2  pooka  *
     61  1.34.10.2  pooka  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     62  1.34.10.2  pooka  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     63  1.34.10.2  pooka  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     64  1.34.10.2  pooka  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     65  1.34.10.2  pooka  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     66  1.34.10.2  pooka  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     67  1.34.10.2  pooka  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     68  1.34.10.2  pooka  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     69  1.34.10.2  pooka  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     70  1.34.10.2  pooka  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     71  1.34.10.2  pooka  * SUCH DAMAGE.
     72  1.34.10.2  pooka  *
     73  1.34.10.2  pooka  *	@(#)vfs_init.c	8.5 (Berkeley) 5/11/95
     74  1.34.10.2  pooka  */
     75  1.34.10.2  pooka 
     76  1.34.10.2  pooka #include <sys/cdefs.h>
     77  1.34.10.2  pooka __KERNEL_RCSID(0, "$NetBSD: vfs_init.c,v 1.34.10.2 2007/07/27 14:25:22 pooka Exp $");
     78  1.34.10.2  pooka 
     79  1.34.10.2  pooka #include <sys/param.h>
     80  1.34.10.2  pooka #include <sys/mount.h>
     81  1.34.10.2  pooka #include <sys/time.h>
     82  1.34.10.2  pooka #include <sys/vnode.h>
     83  1.34.10.2  pooka #include <sys/stat.h>
     84  1.34.10.2  pooka #include <sys/namei.h>
     85  1.34.10.2  pooka #include <sys/ucred.h>
     86  1.34.10.2  pooka #include <sys/buf.h>
     87  1.34.10.2  pooka #include <sys/errno.h>
     88  1.34.10.2  pooka #include <sys/malloc.h>
     89  1.34.10.2  pooka #include <sys/systm.h>
     90  1.34.10.2  pooka 
     91  1.34.10.2  pooka /*
     92  1.34.10.2  pooka  * Sigh, such primitive tools are these...
     93  1.34.10.2  pooka  */
     94  1.34.10.2  pooka #if 0
     95  1.34.10.2  pooka #define DODEBUG(A) A
     96  1.34.10.2  pooka #else
     97  1.34.10.2  pooka #define DODEBUG(A)
     98  1.34.10.2  pooka #endif
     99  1.34.10.2  pooka 
    100  1.34.10.2  pooka /*
    101  1.34.10.2  pooka  * The global list of vnode operations.
    102  1.34.10.2  pooka  */
    103  1.34.10.2  pooka extern const struct vnodeop_desc * const vfs_op_descs[];
    104  1.34.10.2  pooka 
    105  1.34.10.2  pooka /*
    106  1.34.10.2  pooka  * These vnodeopv_descs are listed here because they are not
    107  1.34.10.2  pooka  * associated with any particular file system, and thus cannot
    108  1.34.10.2  pooka  * be initialized by vfs_attach().
    109  1.34.10.2  pooka  */
    110  1.34.10.2  pooka extern const struct vnodeopv_desc dead_vnodeop_opv_desc;
    111  1.34.10.2  pooka extern const struct vnodeopv_desc fifo_vnodeop_opv_desc;
    112  1.34.10.2  pooka extern const struct vnodeopv_desc spec_vnodeop_opv_desc;
    113  1.34.10.2  pooka extern const struct vnodeopv_desc sync_vnodeop_opv_desc;
    114  1.34.10.2  pooka 
    115  1.34.10.2  pooka const struct vnodeopv_desc * const vfs_special_vnodeopv_descs[] = {
    116  1.34.10.2  pooka 	&dead_vnodeop_opv_desc,
    117  1.34.10.2  pooka 	&fifo_vnodeop_opv_desc,
    118  1.34.10.2  pooka 	&spec_vnodeop_opv_desc,
    119  1.34.10.2  pooka 	&sync_vnodeop_opv_desc,
    120  1.34.10.2  pooka 	NULL,
    121  1.34.10.2  pooka };
    122  1.34.10.2  pooka 
    123  1.34.10.2  pooka struct vfs_list_head vfs_list =			/* vfs list */
    124  1.34.10.2  pooka     LIST_HEAD_INITIALIZER(vfs_list);
    125  1.34.10.2  pooka 
    126  1.34.10.2  pooka /*
    127  1.34.10.2  pooka  * This code doesn't work if the defn is **vnodop_defns with cc.
    128  1.34.10.2  pooka  * The problem is because of the compiler sometimes putting in an
    129  1.34.10.2  pooka  * extra level of indirection for arrays.  It's an interesting
    130  1.34.10.2  pooka  * "feature" of C.
    131  1.34.10.2  pooka  */
    132  1.34.10.2  pooka typedef int (*PFI)(void *);
    133  1.34.10.2  pooka 
    134  1.34.10.2  pooka /*
    135  1.34.10.2  pooka  * A miscellaneous routine.
    136  1.34.10.2  pooka  * A generic "default" routine that just returns an error.
    137  1.34.10.2  pooka  */
    138  1.34.10.2  pooka /*ARGSUSED*/
    139  1.34.10.2  pooka int
    140  1.34.10.2  pooka vn_default_error(void *v)
    141  1.34.10.2  pooka {
    142  1.34.10.2  pooka 
    143  1.34.10.2  pooka 	return (EOPNOTSUPP);
    144  1.34.10.2  pooka }
    145  1.34.10.2  pooka 
    146  1.34.10.2  pooka /*
    147  1.34.10.2  pooka  * vfs_init.c
    148  1.34.10.2  pooka  *
    149  1.34.10.2  pooka  * Allocate and fill in operations vectors.
    150  1.34.10.2  pooka  *
    151  1.34.10.2  pooka  * An undocumented feature of this approach to defining operations is that
    152  1.34.10.2  pooka  * there can be multiple entries in vfs_opv_descs for the same operations
    153  1.34.10.2  pooka  * vector. This allows third parties to extend the set of operations
    154  1.34.10.2  pooka  * supported by another layer in a binary compatibile way. For example,
    155  1.34.10.2  pooka  * assume that NFS needed to be modified to support Ficus. NFS has an entry
    156  1.34.10.2  pooka  * (probably nfs_vnopdeop_decls) declaring all the operations NFS supports by
    157  1.34.10.2  pooka  * default. Ficus could add another entry (ficus_nfs_vnodeop_decl_entensions)
    158  1.34.10.2  pooka  * listing those new operations Ficus adds to NFS, all without modifying the
    159  1.34.10.2  pooka  * NFS code. (Of couse, the OTW NFS protocol still needs to be munged, but
    160  1.34.10.2  pooka  * that is a(whole)nother story.) This is a feature.
    161  1.34.10.2  pooka  */
    162  1.34.10.2  pooka 
    163  1.34.10.2  pooka /*
    164  1.34.10.2  pooka  * Init the vector, if it needs it.
    165  1.34.10.2  pooka  * Also handle backwards compatibility.
    166  1.34.10.2  pooka  */
    167  1.34.10.2  pooka static void
    168  1.34.10.2  pooka vfs_opv_init_explicit(const struct vnodeopv_desc *vfs_opv_desc)
    169  1.34.10.2  pooka {
    170  1.34.10.2  pooka 	int (**opv_desc_vector)(void *);
    171  1.34.10.2  pooka 	const struct vnodeopv_entry_desc *opve_descp;
    172  1.34.10.2  pooka 
    173  1.34.10.2  pooka 	opv_desc_vector = *(vfs_opv_desc->opv_desc_vector_p);
    174  1.34.10.2  pooka 
    175  1.34.10.2  pooka 	for (opve_descp = vfs_opv_desc->opv_desc_ops;
    176  1.34.10.2  pooka 	     opve_descp->opve_op;
    177  1.34.10.2  pooka 	     opve_descp++) {
    178  1.34.10.2  pooka 		/*
    179  1.34.10.2  pooka 		 * Sanity check:  is this operation listed
    180  1.34.10.2  pooka 		 * in the list of operations?  We check this
    181  1.34.10.2  pooka 		 * by seeing if its offset is zero.  Since
    182  1.34.10.2  pooka 		 * the default routine should always be listed
    183  1.34.10.2  pooka 		 * first, it should be the only one with a zero
    184  1.34.10.2  pooka 		 * offset.  Any other operation with a zero
    185  1.34.10.2  pooka 		 * offset is probably not listed in
    186  1.34.10.2  pooka 		 * vfs_op_descs, and so is probably an error.
    187  1.34.10.2  pooka 		 *
    188  1.34.10.2  pooka 		 * A panic here means the layer programmer
    189  1.34.10.2  pooka 		 * has committed the all-too common bug
    190  1.34.10.2  pooka 		 * of adding a new operation to the layer's
    191  1.34.10.2  pooka 		 * list of vnode operations but
    192  1.34.10.2  pooka 		 * not adding the operation to the system-wide
    193  1.34.10.2  pooka 		 * list of supported operations.
    194  1.34.10.2  pooka 		 */
    195  1.34.10.2  pooka 		if (opve_descp->opve_op->vdesc_offset == 0 &&
    196  1.34.10.2  pooka 		    opve_descp->opve_op->vdesc_offset != VOFFSET(vop_default)) {
    197  1.34.10.2  pooka 			printf("operation %s not listed in %s.\n",
    198  1.34.10.2  pooka 			    opve_descp->opve_op->vdesc_name, "vfs_op_descs");
    199  1.34.10.2  pooka 			panic ("vfs_opv_init: bad operation");
    200  1.34.10.2  pooka 		}
    201  1.34.10.2  pooka 
    202  1.34.10.2  pooka 		/*
    203  1.34.10.2  pooka 		 * Fill in this entry.
    204  1.34.10.2  pooka 		 */
    205  1.34.10.2  pooka 		opv_desc_vector[opve_descp->opve_op->vdesc_offset] =
    206  1.34.10.2  pooka 		    opve_descp->opve_impl;
    207  1.34.10.2  pooka 	}
    208  1.34.10.2  pooka }
    209  1.34.10.2  pooka 
    210  1.34.10.2  pooka static void
    211  1.34.10.2  pooka vfs_opv_init_default(const struct vnodeopv_desc *vfs_opv_desc)
    212  1.34.10.2  pooka {
    213  1.34.10.2  pooka 	int j;
    214  1.34.10.2  pooka 	int (**opv_desc_vector)(void *);
    215  1.34.10.2  pooka 
    216  1.34.10.2  pooka 	opv_desc_vector = *(vfs_opv_desc->opv_desc_vector_p);
    217  1.34.10.2  pooka 
    218  1.34.10.2  pooka 	/*
    219  1.34.10.2  pooka 	 * Force every operations vector to have a default routine.
    220  1.34.10.2  pooka 	 */
    221  1.34.10.2  pooka 	if (opv_desc_vector[VOFFSET(vop_default)] == NULL)
    222  1.34.10.2  pooka 		panic("vfs_opv_init: operation vector without default routine.");
    223  1.34.10.2  pooka 
    224  1.34.10.2  pooka 	for (j = 0; j < VNODE_OPS_COUNT; j++)
    225  1.34.10.2  pooka 		if (opv_desc_vector[j] == NULL)
    226  1.34.10.2  pooka 			opv_desc_vector[j] =
    227  1.34.10.2  pooka 			    opv_desc_vector[VOFFSET(vop_default)];
    228  1.34.10.2  pooka }
    229  1.34.10.2  pooka 
    230  1.34.10.2  pooka void
    231  1.34.10.2  pooka vfs_opv_init(const struct vnodeopv_desc * const *vopvdpp)
    232  1.34.10.2  pooka {
    233  1.34.10.2  pooka 	int (**opv_desc_vector)(void *);
    234  1.34.10.2  pooka 	int i;
    235  1.34.10.2  pooka 
    236  1.34.10.2  pooka 	/*
    237  1.34.10.2  pooka 	 * Allocate the vectors.
    238  1.34.10.2  pooka 	 */
    239  1.34.10.2  pooka 	for (i = 0; vopvdpp[i] != NULL; i++) {
    240  1.34.10.2  pooka 		/* XXX - shouldn't be M_VNODE */
    241  1.34.10.2  pooka 		opv_desc_vector =
    242  1.34.10.2  pooka 		    malloc(VNODE_OPS_COUNT * sizeof(PFI), M_VNODE, M_WAITOK);
    243  1.34.10.2  pooka 		memset(opv_desc_vector, 0, VNODE_OPS_COUNT * sizeof(PFI));
    244  1.34.10.2  pooka 		*(vopvdpp[i]->opv_desc_vector_p) = opv_desc_vector;
    245  1.34.10.2  pooka 		DODEBUG(printf("vector at %p allocated\n",
    246  1.34.10.2  pooka 		    opv_desc_vector_p));
    247  1.34.10.2  pooka 	}
    248  1.34.10.2  pooka 
    249  1.34.10.2  pooka 	/*
    250  1.34.10.2  pooka 	 * ...and fill them in.
    251  1.34.10.2  pooka 	 */
    252  1.34.10.2  pooka 	for (i = 0; vopvdpp[i] != NULL; i++)
    253  1.34.10.2  pooka 		vfs_opv_init_explicit(vopvdpp[i]);
    254  1.34.10.2  pooka 
    255  1.34.10.2  pooka 	/*
    256  1.34.10.2  pooka 	 * Finally, go back and replace unfilled routines
    257  1.34.10.2  pooka 	 * with their default.
    258  1.34.10.2  pooka 	 */
    259  1.34.10.2  pooka 	for (i = 0; vopvdpp[i] != NULL; i++)
    260  1.34.10.2  pooka 		vfs_opv_init_default(vopvdpp[i]);
    261  1.34.10.2  pooka }
    262  1.34.10.2  pooka 
    263  1.34.10.2  pooka void
    264  1.34.10.2  pooka vfs_opv_free(const struct vnodeopv_desc * const *vopvdpp)
    265  1.34.10.2  pooka {
    266  1.34.10.2  pooka 	int i;
    267  1.34.10.2  pooka 
    268  1.34.10.2  pooka 	/*
    269  1.34.10.2  pooka 	 * Free the vectors allocated in vfs_opv_init().
    270  1.34.10.2  pooka 	 */
    271  1.34.10.2  pooka 	for (i = 0; vopvdpp[i] != NULL; i++) {
    272  1.34.10.2  pooka 		/* XXX - shouldn't be M_VNODE */
    273  1.34.10.2  pooka 		free(*(vopvdpp[i]->opv_desc_vector_p), M_VNODE);
    274  1.34.10.2  pooka 		*(vopvdpp[i]->opv_desc_vector_p) = NULL;
    275  1.34.10.2  pooka 	}
    276  1.34.10.2  pooka }
    277  1.34.10.2  pooka 
    278  1.34.10.2  pooka #ifdef DEBUG
    279  1.34.10.2  pooka static void
    280  1.34.10.2  pooka vfs_op_check(void)
    281  1.34.10.2  pooka {
    282  1.34.10.2  pooka 	int i;
    283  1.34.10.2  pooka 
    284  1.34.10.2  pooka 	DODEBUG(printf("Vnode_interface_init.\n"));
    285  1.34.10.2  pooka 
    286  1.34.10.2  pooka 	/*
    287  1.34.10.2  pooka 	 * Check offset of each op.
    288  1.34.10.2  pooka 	 */
    289  1.34.10.2  pooka 	for (i = 0; vfs_op_descs[i]; i++) {
    290  1.34.10.2  pooka 		if (vfs_op_descs[i]->vdesc_offset != i)
    291  1.34.10.2  pooka 			panic("vfs_op_check: vfs_op_desc[] offset mismatch");
    292  1.34.10.2  pooka 	}
    293  1.34.10.2  pooka 
    294  1.34.10.2  pooka 	if (i != VNODE_OPS_COUNT) {
    295  1.34.10.2  pooka 		panic("vfs_op_check: vnode ops count mismatch (%d != %d)",
    296  1.34.10.2  pooka 			i, VNODE_OPS_COUNT);
    297  1.34.10.2  pooka 	}
    298  1.34.10.2  pooka 
    299  1.34.10.2  pooka 	DODEBUG(printf ("vfs_opv_numops=%d\n", VNODE_OPS_COUNT));
    300  1.34.10.2  pooka }
    301  1.34.10.2  pooka #endif /* DEBUG */
    302  1.34.10.2  pooka 
    303  1.34.10.2  pooka /*
    304  1.34.10.2  pooka  * Initialize the vnode structures and initialize each file system type.
    305  1.34.10.2  pooka  */
    306  1.34.10.2  pooka void
    307  1.34.10.2  pooka vfsinit(void)
    308  1.34.10.2  pooka {
    309  1.34.10.2  pooka 	__link_set_decl(vfsops, struct vfsops);
    310  1.34.10.2  pooka 	struct vfsops * const *vfsp;
    311  1.34.10.2  pooka 
    312  1.34.10.2  pooka 	/*
    313  1.34.10.2  pooka 	 * Initialize the namei pathname buffer pool and cache.
    314  1.34.10.2  pooka 	 */
    315  1.34.10.2  pooka 	pool_init(&pnbuf_pool, MAXPATHLEN, 0, 0, 0, "pnbufpl",
    316  1.34.10.2  pooka 	    &pool_allocator_nointr, IPL_NONE);
    317  1.34.10.2  pooka 	pool_cache_init(&pnbuf_cache, &pnbuf_pool, NULL, NULL, NULL);
    318  1.34.10.2  pooka 
    319  1.34.10.2  pooka 	/*
    320  1.34.10.2  pooka 	 * Initialize the vnode table
    321  1.34.10.2  pooka 	 */
    322  1.34.10.2  pooka 	vntblinit();
    323  1.34.10.2  pooka 
    324  1.34.10.2  pooka 	/*
    325  1.34.10.2  pooka 	 * Initialize the vnode name cache
    326  1.34.10.2  pooka 	 */
    327  1.34.10.2  pooka 	nchinit();
    328  1.34.10.2  pooka 
    329  1.34.10.2  pooka #ifdef DEBUG
    330  1.34.10.2  pooka 	/*
    331  1.34.10.2  pooka 	 * Check the list of vnode operations.
    332  1.34.10.2  pooka 	 */
    333  1.34.10.2  pooka 	vfs_op_check();
    334  1.34.10.2  pooka #endif
    335  1.34.10.2  pooka 
    336  1.34.10.2  pooka 	/*
    337  1.34.10.2  pooka 	 * Initialize the special vnode operations.
    338  1.34.10.2  pooka 	 */
    339  1.34.10.2  pooka 	vfs_opv_init(vfs_special_vnodeopv_descs);
    340  1.34.10.2  pooka 
    341  1.34.10.2  pooka 	/*
    342  1.34.10.2  pooka 	 * Establish each file system which was statically
    343  1.34.10.2  pooka 	 * included in the kernel.
    344  1.34.10.2  pooka 	 */
    345  1.34.10.2  pooka 	__link_set_foreach(vfsp, vfsops) {
    346  1.34.10.2  pooka 		if (vfs_attach(*vfsp)) {
    347  1.34.10.2  pooka 			printf("multiple `%s' file systems",
    348  1.34.10.2  pooka 			    (*vfsp)->vfs_name);
    349  1.34.10.2  pooka 			panic("vfsinit");
    350  1.34.10.2  pooka 		}
    351  1.34.10.2  pooka 	}
    352  1.34.10.2  pooka }
    353  1.34.10.2  pooka 
    354  1.34.10.2  pooka /*
    355  1.34.10.2  pooka  * Establish a file system and initialize it.
    356  1.34.10.2  pooka  */
    357  1.34.10.2  pooka int
    358  1.34.10.2  pooka vfs_attach(struct vfsops *vfs)
    359  1.34.10.2  pooka {
    360  1.34.10.2  pooka 	struct vfsops *v;
    361  1.34.10.2  pooka 	int error = 0;
    362  1.34.10.2  pooka 
    363  1.34.10.2  pooka 
    364  1.34.10.2  pooka 	/*
    365  1.34.10.2  pooka 	 * Make sure this file system doesn't already exist.
    366  1.34.10.2  pooka 	 */
    367  1.34.10.2  pooka 	LIST_FOREACH(v, &vfs_list, vfs_list) {
    368  1.34.10.2  pooka 		if (strcmp(vfs->vfs_name, v->vfs_name) == 0) {
    369  1.34.10.2  pooka 			error = EEXIST;
    370  1.34.10.2  pooka 			goto out;
    371  1.34.10.2  pooka 		}
    372  1.34.10.2  pooka 	}
    373  1.34.10.2  pooka 
    374  1.34.10.2  pooka 	/*
    375  1.34.10.2  pooka 	 * Initialize the vnode operations for this file system.
    376  1.34.10.2  pooka 	 */
    377  1.34.10.2  pooka 	vfs_opv_init(vfs->vfs_opv_descs);
    378  1.34.10.2  pooka 
    379  1.34.10.2  pooka 	/*
    380  1.34.10.2  pooka 	 * Now initialize the file system itself.
    381  1.34.10.2  pooka 	 */
    382  1.34.10.2  pooka 	(*vfs->vfs_init)();
    383  1.34.10.2  pooka 
    384  1.34.10.2  pooka 	/*
    385  1.34.10.2  pooka 	 * ...and link it into the kernel's list.
    386  1.34.10.2  pooka 	 */
    387  1.34.10.2  pooka 	LIST_INSERT_HEAD(&vfs_list, vfs, vfs_list);
    388  1.34.10.2  pooka 
    389  1.34.10.2  pooka 	/*
    390  1.34.10.2  pooka 	 * Sanity: make sure the reference count is 0.
    391  1.34.10.2  pooka 	 */
    392  1.34.10.2  pooka 	vfs->vfs_refcount = 0;
    393  1.34.10.2  pooka 
    394  1.34.10.2  pooka  out:
    395  1.34.10.2  pooka 	return (error);
    396  1.34.10.2  pooka }
    397  1.34.10.2  pooka 
    398  1.34.10.2  pooka /*
    399  1.34.10.2  pooka  * Remove a file system from the kernel.
    400  1.34.10.2  pooka  */
    401  1.34.10.2  pooka int
    402  1.34.10.2  pooka vfs_detach(struct vfsops *vfs)
    403  1.34.10.2  pooka {
    404  1.34.10.2  pooka 	struct vfsops *v;
    405  1.34.10.2  pooka 
    406  1.34.10.2  pooka 	/*
    407  1.34.10.2  pooka 	 * Make sure no one is using the filesystem.
    408  1.34.10.2  pooka 	 */
    409  1.34.10.2  pooka 	if (vfs->vfs_refcount != 0)
    410  1.34.10.2  pooka 		return (EBUSY);
    411  1.34.10.2  pooka 
    412  1.34.10.2  pooka 	/*
    413  1.34.10.2  pooka 	 * ...and remove it from the kernel's list.
    414  1.34.10.2  pooka 	 */
    415  1.34.10.2  pooka 	LIST_FOREACH(v, &vfs_list, vfs_list) {
    416  1.34.10.2  pooka 		if (v == vfs) {
    417  1.34.10.2  pooka 			LIST_REMOVE(v, vfs_list);
    418  1.34.10.2  pooka 			break;
    419  1.34.10.2  pooka 		}
    420  1.34.10.2  pooka 	}
    421  1.34.10.2  pooka 
    422  1.34.10.2  pooka 	if (v == NULL)
    423  1.34.10.2  pooka 		return (ESRCH);
    424  1.34.10.2  pooka 
    425  1.34.10.2  pooka 	/*
    426  1.34.10.2  pooka 	 * Now run the file system-specific cleanups.
    427  1.34.10.2  pooka 	 */
    428  1.34.10.2  pooka 	(*vfs->vfs_done)();
    429  1.34.10.2  pooka 
    430  1.34.10.2  pooka 	/*
    431  1.34.10.2  pooka 	 * Free the vnode operations vector.
    432  1.34.10.2  pooka 	 */
    433  1.34.10.2  pooka 	vfs_opv_free(vfs->vfs_opv_descs);
    434  1.34.10.2  pooka 	return (0);
    435  1.34.10.2  pooka }
    436  1.34.10.2  pooka 
    437  1.34.10.2  pooka void
    438  1.34.10.2  pooka vfs_reinit(void)
    439  1.34.10.2  pooka {
    440  1.34.10.2  pooka 	struct vfsops *vfs;
    441  1.34.10.2  pooka 
    442  1.34.10.2  pooka 	LIST_FOREACH(vfs, &vfs_list, vfs_list) {
    443  1.34.10.2  pooka 		if (vfs->vfs_reinit) {
    444  1.34.10.2  pooka 			(*vfs->vfs_reinit)();
    445  1.34.10.2  pooka 		}
    446  1.34.10.2  pooka 	}
    447  1.34.10.2  pooka }
    448