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