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