]>
git.saurik.com Git - apple/xnu.git/blob - bsd/vfs/vfs_init.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
27 * Copyright (c) 1989, 1993
28 * The Regents of the University of California. All rights reserved.
30 * This code is derived from software contributed
31 * to Berkeley by John Heidemann of the UCLA Ficus project.
33 * Source: * @(#)i405_init.c 2.10 92/04/27 UCLA Ficus project
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 * 3. All advertising materials mentioning features or use of this software
44 * must display the following acknowledgement:
45 * This product includes software developed by the University of
46 * California, Berkeley and its contributors.
47 * 4. Neither the name of the University nor the names of its contributors
48 * may be used to endorse or promote products derived from this software
49 * without specific prior written permission.
51 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * @(#)vfs_init.c 8.5 (Berkeley) 5/11/95
67 #include <sys/param.h>
68 #include <sys/mount.h>
71 #include <sys/vnode.h>
73 #include <sys/namei.h>
74 #include <sys/ucred.h>
76 #include <sys/errno.h>
77 #include <sys/malloc.h>
81 * Sigh, such primitive tools are these...
89 extern uid_t console_user
;
90 extern struct vnodeopv_desc
*vfs_opv_descs
[];
91 /* a list of lists of vnodeops defns */
92 extern struct vnodeop_desc
*vfs_op_descs
[];
93 /* and the operations they perform */
95 * This code doesn't work if the defn is **vnodop_defns with cc.
96 * The problem is because of the compiler sometimes putting in an
97 * extra level of indirection for arrays. It's an interesting
102 typedef (*PFI
)(); /* the standard Pointer to a Function returning an Int */
105 * A miscellaneous routine.
106 * A generic "default" routine that just returns an error.
118 * Allocate and fill in operations vectors.
120 * An undocumented feature of this approach to defining operations is that
121 * there can be multiple entries in vfs_opv_descs for the same operations
122 * vector. This allows third parties to extend the set of operations
123 * supported by another layer in a binary compatibile way. For example,
124 * assume that NFS needed to be modified to support Ficus. NFS has an entry
125 * (probably nfs_vnopdeop_decls) declaring all the operations NFS supports by
126 * default. Ficus could add another entry (ficus_nfs_vnodeop_decl_entensions)
127 * listing those new operations Ficus adds to NFS, all without modifying the
128 * NFS code. (Of couse, the OTW NFS protocol still needs to be munged, but
129 * that is a(whole)nother story.) This is a feature.
135 int (***opv_desc_vector_p
)(void *);
136 int (**opv_desc_vector
)(void *);
137 struct vnodeopv_entry_desc
*opve_descp
;
140 * Allocate the dynamic vectors and fill them in.
142 for (i
=0; vfs_opv_descs
[i
]; i
++) {
143 opv_desc_vector_p
= vfs_opv_descs
[i
]->opv_desc_vector_p
;
145 * Allocate and init the vector, if it needs it.
146 * Also handle backwards compatibility.
148 if (*opv_desc_vector_p
== NULL
) {
149 /* XXX - shouldn't be M_VNODE */
150 MALLOC(*opv_desc_vector_p
, PFI
*,
151 vfs_opv_numops
*sizeof(PFI
), M_VNODE
, M_WAITOK
);
152 bzero (*opv_desc_vector_p
, vfs_opv_numops
*sizeof(PFI
));
153 DODEBUG(printf("vector at %x allocated\n",
156 opv_desc_vector
= *opv_desc_vector_p
;
157 for (j
=0; vfs_opv_descs
[i
]->opv_desc_ops
[j
].opve_op
; j
++) {
158 opve_descp
= &(vfs_opv_descs
[i
]->opv_desc_ops
[j
]);
161 * Sanity check: is this operation listed
162 * in the list of operations? We check this
163 * by seeing if its offest is zero. Since
164 * the default routine should always be listed
165 * first, it should be the only one with a zero
166 * offset. Any other operation with a zero
167 * offset is probably not listed in
168 * vfs_op_descs, and so is probably an error.
170 * A panic here means the layer programmer
171 * has committed the all-too common bug
172 * of adding a new operation to the layer's
173 * list of vnode operations but
174 * not adding the operation to the system-wide
175 * list of supported operations.
177 if (opve_descp
->opve_op
->vdesc_offset
== 0 &&
178 opve_descp
->opve_op
->vdesc_offset
!=
179 VOFFSET(vop_default
)) {
180 printf("operation %s not listed in %s.\n",
181 opve_descp
->opve_op
->vdesc_name
,
183 panic ("vfs_opv_init: bad operation");
186 * Fill in this entry.
188 opv_desc_vector
[opve_descp
->opve_op
->vdesc_offset
] =
189 opve_descp
->opve_impl
;
193 * Finally, go back and replace unfilled routines
194 * with their default. (Sigh, an O(n^3) algorithm. I
195 * could make it better, but that'd be work, and n is small.)
197 for (i
= 0; vfs_opv_descs
[i
]; i
++) {
198 opv_desc_vector
= *(vfs_opv_descs
[i
]->opv_desc_vector_p
);
200 * Force every operations vector to have a default routine.
202 if (opv_desc_vector
[VOFFSET(vop_default
)]==NULL
) {
203 panic("vfs_opv_init: operation vector without default routine.");
205 for (k
= 0; k
<vfs_opv_numops
; k
++)
206 if (opv_desc_vector
[k
] == NULL
)
208 opv_desc_vector
[VOFFSET(vop_default
)];
213 * Initialize known vnode operations vectors.
220 DODEBUG(printf("Vnode_interface_init.\n"));
222 * Set all vnode vectors to a well known value.
224 for (i
= 0; vfs_opv_descs
[i
]; i
++)
225 *(vfs_opv_descs
[i
]->opv_desc_vector_p
) = NULL
;
227 * Figure out how many ops there are by counting the table,
228 * and assign each its offset.
230 for (vfs_opv_numops
= 0, i
= 0; vfs_op_descs
[i
]; i
++) {
231 vfs_op_descs
[i
]->vdesc_offset
= vfs_opv_numops
;
234 DODEBUG(printf ("vfs_opv_numops=%d\n", vfs_opv_numops
));
238 * Routines having to do with the management of the vnode table.
240 extern struct vnodeops dead_vnodeops
;
241 extern struct vnodeops spec_vnodeops
;
242 struct vattr va_null
;
245 * Initialize the vnode structures and initialize each file system type.
249 struct vfsconf
*vfsp
;
253 * Initialize the "console user" for access purposes:
255 console_user
= (uid_t
)0;
258 * Initialize the vnode table
262 * Initialize the vnode name cache
266 * Build vnode operation vectors.
269 vfs_opv_init(); /* finish the job */
271 * Initialize each file system type.
273 vattr_null(&va_null
);
274 numused_vfsslots
= maxtypenum
= 0;
275 for (vfsp
= vfsconf
, i
= 0; i
< maxvfsconf
; i
++, vfsp
++) {
276 if (vfsp
->vfc_vfsops
== (struct vfsops
*)0)
278 if (i
) vfsconf
[i
-1].vfc_next
= vfsp
;
279 if (maxtypenum
<= vfsp
->vfc_typenum
)
280 maxtypenum
= vfsp
->vfc_typenum
+ 1;
281 (*vfsp
->vfc_vfsops
->vfs_init
)(vfsp
);
284 /* next vfc_typenum to be used */
285 maxvfsconf
= maxtypenum
;
289 vfsconf_add(struct vfsconf
*nvfsp
)
291 struct vfsconf
*vfsp
;
293 if ((numused_vfsslots
>= maxvfsslots
) || (nvfsp
== (struct vfsconf
*)0))
295 bcopy(nvfsp
, &vfsconf
[numused_vfsslots
], sizeof(struct vfsconf
));
296 vfsconf
[numused_vfsslots
-1].vfc_next
= &vfsconf
[numused_vfsslots
];
298 if (nvfsp
->vfc_typenum
<= maxvfsconf
)
299 maxvfsconf
= nvfsp
->vfc_typenum
+ 1;
301 if (nvfsp
->vfc_vfsops
->vfs_init
)
302 (*nvfsp
->vfc_vfsops
->vfs_init
)(nvfsp
);
307 vfsconf_del(char * fs_name
)
309 int entriesRemaining
;
310 struct vfsconf
*vfsconflistentry
;
311 struct vfsconf
*prevconf
= NULL
;
312 struct vfsconf
*targetconf
= NULL
;
314 prevconf
= vfsconflistentry
= vfsconf
;
315 for (entriesRemaining
= maxvfsslots
;
316 (entriesRemaining
> 0) && (vfsconflistentry
!= NULL
);
317 --entriesRemaining
) {
318 if ((vfsconflistentry
->vfc_vfsops
!= NULL
) && (strcmp(vfsconflistentry
->vfc_name
, fs_name
) == 0)) {
319 targetconf
= vfsconflistentry
;
322 prevconf
= vfsconflistentry
;
323 vfsconflistentry
= vfsconflistentry
->vfc_next
;
326 if (targetconf
!= NULL
) {
327 if (prevconf
!= NULL
) {
328 /* Unlink the target entry from the list:
329 and decrement our count */
330 prevconf
->vfc_next
= targetconf
->vfc_next
;
333 /* XXX need real error code for no previous entry in list */
337 /* XXX need real error code for entry not found */