Home | History | Annotate | Line # | Download | only in kern
vfs_init.c revision 1.2.2.1
      1  1.2.2.1      cgd /*	$NetBSD: vfs_init.c,v 1.2.2.1 1994/07/24 07:20:21 cgd Exp $	*/
      2      1.2      cgd 
      3      1.1  mycroft /*
      4      1.1  mycroft  * Copyright (c) 1989, 1993
      5      1.1  mycroft  *	The Regents of the University of California.  All rights reserved.
      6      1.1  mycroft  *
      7      1.1  mycroft  * This code is derived from software contributed
      8      1.1  mycroft  * to Berkeley by John Heidemann of the UCLA Ficus project.
      9      1.1  mycroft  *
     10      1.1  mycroft  * Source: * @(#)i405_init.c 2.10 92/04/27 UCLA Ficus project
     11      1.1  mycroft  *
     12      1.1  mycroft  * Redistribution and use in source and binary forms, with or without
     13      1.1  mycroft  * modification, are permitted provided that the following conditions
     14      1.1  mycroft  * are met:
     15      1.1  mycroft  * 1. Redistributions of source code must retain the above copyright
     16      1.1  mycroft  *    notice, this list of conditions and the following disclaimer.
     17      1.1  mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     18      1.1  mycroft  *    notice, this list of conditions and the following disclaimer in the
     19      1.1  mycroft  *    documentation and/or other materials provided with the distribution.
     20      1.1  mycroft  * 3. All advertising materials mentioning features or use of this software
     21      1.1  mycroft  *    must display the following acknowledgement:
     22      1.1  mycroft  *	This product includes software developed by the University of
     23      1.1  mycroft  *	California, Berkeley and its contributors.
     24      1.1  mycroft  * 4. Neither the name of the University nor the names of its contributors
     25      1.1  mycroft  *    may be used to endorse or promote products derived from this software
     26      1.1  mycroft  *    without specific prior written permission.
     27      1.1  mycroft  *
     28      1.1  mycroft  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     29      1.1  mycroft  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     30      1.1  mycroft  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     31      1.1  mycroft  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     32      1.1  mycroft  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     33      1.1  mycroft  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     34      1.1  mycroft  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     35      1.1  mycroft  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     36      1.1  mycroft  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     37      1.1  mycroft  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     38      1.1  mycroft  * SUCH DAMAGE.
     39      1.1  mycroft  *
     40      1.2      cgd  *	@(#)vfs_init.c	8.3 (Berkeley) 1/4/94
     41      1.1  mycroft  */
     42      1.1  mycroft 
     43      1.1  mycroft 
     44      1.1  mycroft #include <sys/param.h>
     45      1.1  mycroft #include <sys/mount.h>
     46      1.1  mycroft #include <sys/time.h>
     47      1.1  mycroft #include <sys/vnode.h>
     48      1.1  mycroft #include <sys/stat.h>
     49      1.1  mycroft #include <sys/namei.h>
     50      1.1  mycroft #include <sys/ucred.h>
     51      1.1  mycroft #include <sys/buf.h>
     52      1.1  mycroft #include <sys/errno.h>
     53      1.1  mycroft #include <sys/malloc.h>
     54      1.1  mycroft 
     55      1.1  mycroft /*
     56      1.1  mycroft  * Sigh, such primitive tools are these...
     57      1.1  mycroft  */
     58      1.1  mycroft #if 0
     59      1.1  mycroft #define DODEBUG(A) A
     60      1.1  mycroft #else
     61      1.1  mycroft #define DODEBUG(A)
     62      1.1  mycroft #endif
     63      1.1  mycroft 
     64      1.1  mycroft extern struct vnodeopv_desc *vfs_opv_descs[];
     65      1.1  mycroft 				/* a list of lists of vnodeops defns */
     66      1.1  mycroft extern struct vnodeop_desc *vfs_op_descs[];
     67      1.1  mycroft 				/* and the operations they perform */
     68      1.1  mycroft /*
     69      1.1  mycroft  * This code doesn't work if the defn is **vnodop_defns with cc.
     70      1.1  mycroft  * The problem is because of the compiler sometimes putting in an
     71      1.1  mycroft  * extra level of indirection for arrays.  It's an interesting
     72      1.1  mycroft  * "feature" of C.
     73      1.1  mycroft  */
     74      1.1  mycroft int vfs_opv_numops;
     75      1.1  mycroft 
     76      1.1  mycroft typedef (*PFI)();   /* the standard Pointer to a Function returning an Int */
     77      1.1  mycroft 
     78      1.1  mycroft /*
     79      1.1  mycroft  * A miscellaneous routine.
     80      1.1  mycroft  * A generic "default" routine that just returns an error.
     81      1.1  mycroft  */
     82      1.1  mycroft int
     83      1.1  mycroft vn_default_error()
     84      1.1  mycroft {
     85      1.1  mycroft 
     86      1.1  mycroft 	return (EOPNOTSUPP);
     87      1.1  mycroft }
     88      1.1  mycroft 
     89      1.1  mycroft /*
     90      1.1  mycroft  * vfs_init.c
     91      1.1  mycroft  *
     92      1.1  mycroft  * Allocate and fill in operations vectors.
     93      1.1  mycroft  *
     94      1.1  mycroft  * An undocumented feature of this approach to defining operations is that
     95      1.1  mycroft  * there can be multiple entries in vfs_opv_descs for the same operations
     96      1.1  mycroft  * vector. This allows third parties to extend the set of operations
     97      1.1  mycroft  * supported by another layer in a binary compatibile way. For example,
     98      1.1  mycroft  * assume that NFS needed to be modified to support Ficus. NFS has an entry
     99      1.1  mycroft  * (probably nfs_vnopdeop_decls) declaring all the operations NFS supports by
    100      1.1  mycroft  * default. Ficus could add another entry (ficus_nfs_vnodeop_decl_entensions)
    101      1.1  mycroft  * listing those new operations Ficus adds to NFS, all without modifying the
    102      1.1  mycroft  * NFS code. (Of couse, the OTW NFS protocol still needs to be munged, but
    103      1.1  mycroft  * that is a(whole)nother story.) This is a feature.
    104      1.1  mycroft  */
    105  1.2.2.1      cgd 
    106  1.2.2.1      cgd /*
    107  1.2.2.1      cgd  * Allocate and init the vector, if it needs it.
    108  1.2.2.1      cgd  * Also handle backwards compatibility.
    109  1.2.2.1      cgd  */
    110      1.1  mycroft void
    111  1.2.2.1      cgd vfs_opv_init_explicit(vfs_opv_desc)
    112  1.2.2.1      cgd 	struct vnodeopv_desc *vfs_opv_desc;
    113      1.1  mycroft {
    114      1.1  mycroft 	int (**opv_desc_vector)();
    115      1.1  mycroft 	struct vnodeopv_entry_desc *opve_descp;
    116      1.1  mycroft 
    117  1.2.2.1      cgd 	opv_desc_vector = *(vfs_opv_desc->opv_desc_vector_p);
    118  1.2.2.1      cgd 
    119  1.2.2.1      cgd 	if (opv_desc_vector == NULL) {
    120  1.2.2.1      cgd 		/* XXX - shouldn't be M_VNODE */
    121  1.2.2.1      cgd 		MALLOC(opv_desc_vector, PFI *,
    122  1.2.2.1      cgd 		    vfs_opv_numops * sizeof(PFI), M_VNODE, M_WAITOK);
    123  1.2.2.1      cgd 		bzero(opv_desc_vector, vfs_opv_numops * sizeof(PFI));
    124  1.2.2.1      cgd 		*(vfs_opv_desc->opv_desc_vector_p) = opv_desc_vector;
    125  1.2.2.1      cgd 		DODEBUG(printf("vector at %x allocated\n",
    126  1.2.2.1      cgd 		    opv_desc_vector_p));
    127  1.2.2.1      cgd 	}
    128  1.2.2.1      cgd 
    129  1.2.2.1      cgd 	for (opve_descp = vfs_opv_desc->opv_desc_ops;
    130  1.2.2.1      cgd 	     opve_descp->opve_op;
    131  1.2.2.1      cgd 	     opve_descp++) {
    132      1.1  mycroft 		/*
    133  1.2.2.1      cgd 		 * Sanity check:  is this operation listed
    134  1.2.2.1      cgd 		 * in the list of operations?  We check this
    135  1.2.2.1      cgd 		 * by seeing if its offest is zero.  Since
    136  1.2.2.1      cgd 		 * the default routine should always be listed
    137  1.2.2.1      cgd 		 * first, it should be the only one with a zero
    138  1.2.2.1      cgd 		 * offset.  Any other operation with a zero
    139  1.2.2.1      cgd 		 * offset is probably not listed in
    140  1.2.2.1      cgd 		 * vfs_op_descs, and so is probably an error.
    141  1.2.2.1      cgd 		 *
    142  1.2.2.1      cgd 		 * A panic here means the layer programmer
    143  1.2.2.1      cgd 		 * has committed the all-too common bug
    144  1.2.2.1      cgd 		 * of adding a new operation to the layer's
    145  1.2.2.1      cgd 		 * list of vnode operations but
    146  1.2.2.1      cgd 		 * not adding the operation to the system-wide
    147  1.2.2.1      cgd 		 * list of supported operations.
    148      1.1  mycroft 		 */
    149  1.2.2.1      cgd 		if (opve_descp->opve_op->vdesc_offset == 0 &&
    150  1.2.2.1      cgd 		    opve_descp->opve_op->vdesc_offset != VOFFSET(vop_default)) {
    151  1.2.2.1      cgd 			printf("operation %s not listed in %s.\n",
    152  1.2.2.1      cgd 			    opve_descp->opve_op->vdesc_name, "vfs_op_descs");
    153  1.2.2.1      cgd 			panic ("vfs_opv_init: bad operation");
    154      1.1  mycroft 		}
    155  1.2.2.1      cgd 
    156  1.2.2.1      cgd 		/*
    157  1.2.2.1      cgd 		 * Fill in this entry.
    158  1.2.2.1      cgd 		 */
    159  1.2.2.1      cgd 		opv_desc_vector[opve_descp->opve_op->vdesc_offset] =
    160  1.2.2.1      cgd 		    opve_descp->opve_impl;
    161      1.1  mycroft 	}
    162  1.2.2.1      cgd }
    163  1.2.2.1      cgd 
    164  1.2.2.1      cgd void
    165  1.2.2.1      cgd vfs_opv_init_default(vfs_opv_desc)
    166  1.2.2.1      cgd 	struct vnodeopv_desc *vfs_opv_desc;
    167  1.2.2.1      cgd {
    168  1.2.2.1      cgd 	int j;
    169  1.2.2.1      cgd 	int (**opv_desc_vector)();
    170  1.2.2.1      cgd 	struct vnodeopv_entry_desc *opve_descp;
    171  1.2.2.1      cgd 
    172  1.2.2.1      cgd 	opv_desc_vector = *(vfs_opv_desc->opv_desc_vector_p);
    173  1.2.2.1      cgd 
    174  1.2.2.1      cgd 	/*
    175  1.2.2.1      cgd 	 * Force every operations vector to have a default routine.
    176  1.2.2.1      cgd 	 */
    177  1.2.2.1      cgd 	if (opv_desc_vector[VOFFSET(vop_default)] == NULL)
    178  1.2.2.1      cgd 		panic("vfs_opv_init: operation vector without default routine.");
    179  1.2.2.1      cgd 
    180  1.2.2.1      cgd 	for (j = 0; j < vfs_opv_numops; j++)
    181  1.2.2.1      cgd 		if (opv_desc_vector[j] == NULL)
    182  1.2.2.1      cgd 			opv_desc_vector[j] =
    183  1.2.2.1      cgd 			    opv_desc_vector[VOFFSET(vop_default)];
    184  1.2.2.1      cgd }
    185  1.2.2.1      cgd 
    186  1.2.2.1      cgd void
    187  1.2.2.1      cgd vfs_opv_init()
    188  1.2.2.1      cgd {
    189  1.2.2.1      cgd 	int i;
    190  1.2.2.1      cgd 
    191  1.2.2.1      cgd 	/*
    192  1.2.2.1      cgd 	 * Allocate the dynamic vectors and fill them in.
    193  1.2.2.1      cgd 	 */
    194  1.2.2.1      cgd 	for (i = 0; vfs_opv_descs[i]; i++)
    195  1.2.2.1      cgd 		vfs_opv_init_explicit(vfs_opv_descs[i]);
    196  1.2.2.1      cgd 
    197      1.1  mycroft 	/*
    198      1.1  mycroft 	 * Finally, go back and replace unfilled routines
    199  1.2.2.1      cgd 	 * with their default.
    200      1.1  mycroft 	 */
    201  1.2.2.1      cgd 	for (i = 0; vfs_opv_descs[i]; i++)
    202  1.2.2.1      cgd 		vfs_opv_init_default(vfs_opv_descs[i]);
    203      1.1  mycroft }
    204      1.1  mycroft 
    205      1.1  mycroft /*
    206      1.1  mycroft  * Initialize known vnode operations vectors.
    207      1.1  mycroft  */
    208      1.1  mycroft void
    209      1.1  mycroft vfs_op_init()
    210      1.1  mycroft {
    211      1.1  mycroft 	int i;
    212      1.1  mycroft 
    213      1.1  mycroft 	DODEBUG(printf("Vnode_interface_init.\n"));
    214      1.1  mycroft 	/*
    215      1.1  mycroft 	 * Set all vnode vectors to a well known value.
    216      1.1  mycroft 	 */
    217      1.1  mycroft 	for (i = 0; vfs_opv_descs[i]; i++)
    218      1.1  mycroft 		*(vfs_opv_descs[i]->opv_desc_vector_p) = NULL;
    219      1.1  mycroft 	/*
    220      1.1  mycroft 	 * Figure out how many ops there are by counting the table,
    221      1.1  mycroft 	 * and assign each its offset.
    222      1.1  mycroft 	 */
    223      1.1  mycroft 	for (vfs_opv_numops = 0, i = 0; vfs_op_descs[i]; i++) {
    224      1.1  mycroft 		vfs_op_descs[i]->vdesc_offset = vfs_opv_numops;
    225      1.1  mycroft 		vfs_opv_numops++;
    226      1.1  mycroft 	}
    227      1.1  mycroft 	DODEBUG(printf ("vfs_opv_numops=%d\n", vfs_opv_numops));
    228      1.1  mycroft }
    229      1.1  mycroft 
    230      1.1  mycroft /*
    231      1.1  mycroft  * Routines having to do with the management of the vnode table.
    232      1.1  mycroft  */
    233      1.1  mycroft extern struct vnodeops dead_vnodeops;
    234      1.1  mycroft extern struct vnodeops spec_vnodeops;
    235      1.1  mycroft extern void vclean();
    236      1.1  mycroft struct vattr va_null;
    237      1.1  mycroft 
    238      1.1  mycroft /*
    239      1.1  mycroft  * Initialize the vnode structures and initialize each file system type.
    240      1.1  mycroft  */
    241      1.1  mycroft vfsinit()
    242      1.1  mycroft {
    243      1.1  mycroft 	struct vfsops **vfsp;
    244      1.1  mycroft 
    245      1.1  mycroft 	/*
    246      1.1  mycroft 	 * Initialize the vnode table
    247      1.1  mycroft 	 */
    248      1.1  mycroft 	vntblinit();
    249      1.1  mycroft 	/*
    250      1.1  mycroft 	 * Initialize the vnode name cache
    251      1.1  mycroft 	 */
    252      1.1  mycroft 	nchinit();
    253      1.1  mycroft 	/*
    254      1.1  mycroft 	 * Build vnode operation vectors.
    255      1.1  mycroft 	 */
    256      1.1  mycroft 	vfs_op_init();
    257      1.1  mycroft 	vfs_opv_init();   /* finish the job */
    258      1.1  mycroft 	/*
    259      1.1  mycroft 	 * Initialize each file system type.
    260      1.1  mycroft 	 */
    261      1.1  mycroft 	vattr_null(&va_null);
    262      1.1  mycroft 	for (vfsp = &vfssw[0]; vfsp < &vfssw[nvfssw]; vfsp++) {
    263      1.1  mycroft 		if (*vfsp == NULL)
    264      1.1  mycroft 			continue;
    265      1.1  mycroft 		(*(*vfsp)->vfs_init)();
    266      1.1  mycroft 	}
    267      1.1  mycroft }
    268