]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
2d21ac55 | 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. |
5d5c5d0d | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
2d21ac55 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ | |
29 | /* | |
30 | * Copyright (c) 1989, 1993 | |
31 | * The Regents of the University of California. All rights reserved. | |
32 | * | |
33 | * This code is derived from software contributed | |
34 | * to Berkeley by John Heidemann of the UCLA Ficus project. | |
35 | * | |
36 | * Source: * @(#)i405_init.c 2.10 92/04/27 UCLA Ficus project | |
37 | * | |
38 | * Redistribution and use in source and binary forms, with or without | |
39 | * modification, are permitted provided that the following conditions | |
40 | * are met: | |
41 | * 1. Redistributions of source code must retain the above copyright | |
42 | * notice, this list of conditions and the following disclaimer. | |
43 | * 2. Redistributions in binary form must reproduce the above copyright | |
44 | * notice, this list of conditions and the following disclaimer in the | |
45 | * documentation and/or other materials provided with the distribution. | |
46 | * 3. All advertising materials mentioning features or use of this software | |
47 | * must display the following acknowledgement: | |
48 | * This product includes software developed by the University of | |
49 | * California, Berkeley and its contributors. | |
50 | * 4. Neither the name of the University nor the names of its contributors | |
51 | * may be used to endorse or promote products derived from this software | |
52 | * without specific prior written permission. | |
53 | * | |
54 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
55 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
56 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
57 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
58 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
59 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
60 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
61 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
62 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
63 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
64 | * SUCH DAMAGE. | |
65 | * | |
66 | * @(#)vfs_init.c 8.5 (Berkeley) 5/11/95 | |
67 | */ | |
2d21ac55 A |
68 | /* |
69 | * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce | |
70 | * support for mandatory and extensible security protections. This notice | |
71 | * is included in support of clause 2.2 (b) of the Apple Public License, | |
72 | * Version 2.0. | |
73 | */ | |
1c79356b A |
74 | |
75 | ||
76 | #include <sys/param.h> | |
91447636 | 77 | #include <sys/mount_internal.h> |
1c79356b A |
78 | #include <sys/time.h> |
79 | #include <sys/vm.h> | |
91447636 | 80 | #include <sys/vnode_internal.h> |
1c79356b A |
81 | #include <sys/stat.h> |
82 | #include <sys/namei.h> | |
83 | #include <sys/ucred.h> | |
1c79356b A |
84 | #include <sys/errno.h> |
85 | #include <sys/malloc.h> | |
86 | ||
2d21ac55 A |
87 | #include <vfs/vfs_journal.h> /* journal_init() */ |
88 | #if CONFIG_MACF | |
89 | #include <security/mac_framework.h> | |
90 | #include <sys/kauth.h> | |
91 | #endif | |
92 | #if QUOTA | |
93 | #include <sys/quota.h> | |
94 | #endif | |
1c79356b A |
95 | |
96 | /* | |
97 | * Sigh, such primitive tools are these... | |
98 | */ | |
99 | #if 0 | |
100 | #define DODEBUG(A) A | |
101 | #else | |
102 | #define DODEBUG(A) | |
103 | #endif | |
104 | ||
2d21ac55 A |
105 | __private_extern__ void vntblinit(void) __attribute__((section("__TEXT, initcode"))); |
106 | ||
1c79356b A |
107 | extern struct vnodeopv_desc *vfs_opv_descs[]; |
108 | /* a list of lists of vnodeops defns */ | |
109 | extern struct vnodeop_desc *vfs_op_descs[]; | |
110 | /* and the operations they perform */ | |
111 | /* | |
112 | * This code doesn't work if the defn is **vnodop_defns with cc. | |
113 | * The problem is because of the compiler sometimes putting in an | |
114 | * extra level of indirection for arrays. It's an interesting | |
115 | * "feature" of C. | |
116 | */ | |
117 | int vfs_opv_numops; | |
118 | ||
2d21ac55 | 119 | typedef int (*PFIvp)(void *); |
1c79356b A |
120 | |
121 | /* | |
122 | * A miscellaneous routine. | |
123 | * A generic "default" routine that just returns an error. | |
124 | */ | |
125 | int | |
2d21ac55 | 126 | vn_default_error(void) |
1c79356b A |
127 | { |
128 | ||
91447636 | 129 | return (ENOTSUP); |
1c79356b A |
130 | } |
131 | ||
132 | /* | |
133 | * vfs_init.c | |
134 | * | |
135 | * Allocate and fill in operations vectors. | |
136 | * | |
137 | * An undocumented feature of this approach to defining operations is that | |
138 | * there can be multiple entries in vfs_opv_descs for the same operations | |
139 | * vector. This allows third parties to extend the set of operations | |
140 | * supported by another layer in a binary compatibile way. For example, | |
141 | * assume that NFS needed to be modified to support Ficus. NFS has an entry | |
142 | * (probably nfs_vnopdeop_decls) declaring all the operations NFS supports by | |
143 | * default. Ficus could add another entry (ficus_nfs_vnodeop_decl_entensions) | |
144 | * listing those new operations Ficus adds to NFS, all without modifying the | |
145 | * NFS code. (Of couse, the OTW NFS protocol still needs to be munged, but | |
146 | * that is a(whole)nother story.) This is a feature. | |
147 | */ | |
148 | void | |
2d21ac55 | 149 | vfs_opv_init(void) |
1c79356b A |
150 | { |
151 | int i, j, k; | |
152 | int (***opv_desc_vector_p)(void *); | |
153 | int (**opv_desc_vector)(void *); | |
154 | struct vnodeopv_entry_desc *opve_descp; | |
155 | ||
156 | /* | |
157 | * Allocate the dynamic vectors and fill them in. | |
158 | */ | |
159 | for (i=0; vfs_opv_descs[i]; i++) { | |
160 | opv_desc_vector_p = vfs_opv_descs[i]->opv_desc_vector_p; | |
161 | /* | |
162 | * Allocate and init the vector, if it needs it. | |
163 | * Also handle backwards compatibility. | |
164 | */ | |
165 | if (*opv_desc_vector_p == NULL) { | |
2d21ac55 A |
166 | MALLOC(*opv_desc_vector_p, PFIvp*, |
167 | vfs_opv_numops*sizeof(PFIvp), M_TEMP, M_WAITOK); | |
168 | bzero (*opv_desc_vector_p, vfs_opv_numops*sizeof(PFIvp)); | |
1c79356b A |
169 | DODEBUG(printf("vector at %x allocated\n", |
170 | opv_desc_vector_p)); | |
171 | } | |
172 | opv_desc_vector = *opv_desc_vector_p; | |
173 | for (j=0; vfs_opv_descs[i]->opv_desc_ops[j].opve_op; j++) { | |
174 | opve_descp = &(vfs_opv_descs[i]->opv_desc_ops[j]); | |
175 | ||
176 | /* | |
177 | * Sanity check: is this operation listed | |
178 | * in the list of operations? We check this | |
179 | * by seeing if its offest is zero. Since | |
180 | * the default routine should always be listed | |
181 | * first, it should be the only one with a zero | |
182 | * offset. Any other operation with a zero | |
183 | * offset is probably not listed in | |
184 | * vfs_op_descs, and so is probably an error. | |
185 | * | |
186 | * A panic here means the layer programmer | |
187 | * has committed the all-too common bug | |
188 | * of adding a new operation to the layer's | |
189 | * list of vnode operations but | |
190 | * not adding the operation to the system-wide | |
191 | * list of supported operations. | |
192 | */ | |
193 | if (opve_descp->opve_op->vdesc_offset == 0 && | |
194 | opve_descp->opve_op->vdesc_offset != | |
91447636 | 195 | VOFFSET(vnop_default)) { |
1c79356b A |
196 | printf("operation %s not listed in %s.\n", |
197 | opve_descp->opve_op->vdesc_name, | |
198 | "vfs_op_descs"); | |
199 | panic ("vfs_opv_init: bad operation"); | |
200 | } | |
201 | /* | |
202 | * Fill in this entry. | |
203 | */ | |
204 | opv_desc_vector[opve_descp->opve_op->vdesc_offset] = | |
205 | opve_descp->opve_impl; | |
206 | } | |
207 | } | |
208 | /* | |
209 | * Finally, go back and replace unfilled routines | |
210 | * with their default. (Sigh, an O(n^3) algorithm. I | |
211 | * could make it better, but that'd be work, and n is small.) | |
212 | */ | |
213 | for (i = 0; vfs_opv_descs[i]; i++) { | |
214 | opv_desc_vector = *(vfs_opv_descs[i]->opv_desc_vector_p); | |
215 | /* | |
216 | * Force every operations vector to have a default routine. | |
217 | */ | |
91447636 | 218 | if (opv_desc_vector[VOFFSET(vnop_default)]==NULL) { |
1c79356b A |
219 | panic("vfs_opv_init: operation vector without default routine."); |
220 | } | |
221 | for (k = 0; k<vfs_opv_numops; k++) | |
222 | if (opv_desc_vector[k] == NULL) | |
223 | opv_desc_vector[k] = | |
91447636 | 224 | opv_desc_vector[VOFFSET(vnop_default)]; |
1c79356b A |
225 | } |
226 | } | |
227 | ||
228 | /* | |
229 | * Initialize known vnode operations vectors. | |
230 | */ | |
231 | void | |
2d21ac55 | 232 | vfs_op_init(void) |
1c79356b A |
233 | { |
234 | int i; | |
235 | ||
236 | DODEBUG(printf("Vnode_interface_init.\n")); | |
237 | /* | |
238 | * Set all vnode vectors to a well known value. | |
239 | */ | |
240 | for (i = 0; vfs_opv_descs[i]; i++) | |
241 | *(vfs_opv_descs[i]->opv_desc_vector_p) = NULL; | |
242 | /* | |
243 | * Figure out how many ops there are by counting the table, | |
244 | * and assign each its offset. | |
245 | */ | |
246 | for (vfs_opv_numops = 0, i = 0; vfs_op_descs[i]; i++) { | |
247 | vfs_op_descs[i]->vdesc_offset = vfs_opv_numops; | |
248 | vfs_opv_numops++; | |
249 | } | |
250 | DODEBUG(printf ("vfs_opv_numops=%d\n", vfs_opv_numops)); | |
251 | } | |
252 | ||
253 | /* | |
254 | * Routines having to do with the management of the vnode table. | |
255 | */ | |
256 | extern struct vnodeops dead_vnodeops; | |
257 | extern struct vnodeops spec_vnodeops; | |
1c79356b | 258 | |
91447636 A |
259 | /* vars for vnode lock */ |
260 | lck_grp_t * vnode_lck_grp; | |
261 | lck_grp_attr_t * vnode_lck_grp_attr; | |
262 | lck_attr_t * vnode_lck_attr; | |
263 | ||
264 | ||
265 | /* vars for vnode list lock */ | |
266 | lck_grp_t * vnode_list_lck_grp; | |
267 | lck_grp_attr_t * vnode_list_lck_grp_attr; | |
268 | lck_attr_t * vnode_list_lck_attr; | |
2d21ac55 | 269 | lck_spin_t * vnode_list_spin_lock; |
91447636 | 270 | lck_mtx_t * spechash_mtx_lock; |
91447636 A |
271 | |
272 | /* vars for vfsconf lock */ | |
273 | lck_grp_t * fsconf_lck_grp; | |
274 | lck_grp_attr_t * fsconf_lck_grp_attr; | |
275 | lck_attr_t * fsconf_lck_attr; | |
276 | ||
277 | ||
278 | /* vars for mount lock */ | |
279 | lck_grp_t * mnt_lck_grp; | |
280 | lck_grp_attr_t * mnt_lck_grp_attr; | |
281 | lck_attr_t * mnt_lck_attr; | |
282 | ||
283 | /* vars for mount list lock */ | |
284 | lck_grp_t * mnt_list_lck_grp; | |
285 | lck_grp_attr_t * mnt_list_lck_grp_attr; | |
286 | lck_attr_t * mnt_list_lck_attr; | |
287 | lck_mtx_t * mnt_list_mtx_lock; | |
288 | ||
91447636 | 289 | struct mount * dead_mountp; |
1c79356b A |
290 | /* |
291 | * Initialize the vnode structures and initialize each file system type. | |
292 | */ | |
91447636 | 293 | void |
2d21ac55 | 294 | vfsinit(void) |
1c79356b | 295 | { |
91447636 | 296 | struct vfstable *vfsp; |
1c79356b | 297 | int i, maxtypenum; |
91447636 A |
298 | struct mount * mp; |
299 | ||
300 | /* Allocate vnode list lock group attribute and group */ | |
0c530ab8 | 301 | vnode_list_lck_grp_attr = lck_grp_attr_alloc_init(); |
91447636 A |
302 | |
303 | vnode_list_lck_grp = lck_grp_alloc_init("vnode list", vnode_list_lck_grp_attr); | |
304 | ||
305 | /* Allocate vnode list lock attribute */ | |
306 | vnode_list_lck_attr = lck_attr_alloc_init(); | |
91447636 A |
307 | |
308 | /* Allocate vnode list lock */ | |
2d21ac55 | 309 | vnode_list_spin_lock = lck_spin_alloc_init(vnode_list_lck_grp, vnode_list_lck_attr); |
91447636 A |
310 | |
311 | /* Allocate spec hash list lock */ | |
312 | spechash_mtx_lock = lck_mtx_alloc_init(vnode_list_lck_grp, vnode_list_lck_attr); | |
313 | ||
314 | /* allocate vnode lock group attribute and group */ | |
315 | vnode_lck_grp_attr= lck_grp_attr_alloc_init(); | |
91447636 A |
316 | |
317 | vnode_lck_grp = lck_grp_alloc_init("vnode", vnode_lck_grp_attr); | |
318 | ||
319 | /* Allocate vnode lock attribute */ | |
320 | vnode_lck_attr = lck_attr_alloc_init(); | |
91447636 A |
321 | |
322 | /* Allocate fs config lock group attribute and group */ | |
323 | fsconf_lck_grp_attr= lck_grp_attr_alloc_init(); | |
91447636 A |
324 | |
325 | fsconf_lck_grp = lck_grp_alloc_init("fs conf", fsconf_lck_grp_attr); | |
326 | ||
327 | /* Allocate fs config lock attribute */ | |
328 | fsconf_lck_attr = lck_attr_alloc_init(); | |
91447636 A |
329 | |
330 | /* Allocate mount point related lock structures */ | |
331 | ||
332 | /* Allocate mount list lock group attribute and group */ | |
333 | mnt_list_lck_grp_attr= lck_grp_attr_alloc_init(); | |
91447636 A |
334 | |
335 | mnt_list_lck_grp = lck_grp_alloc_init("mount list", mnt_list_lck_grp_attr); | |
336 | ||
337 | /* Allocate mount list lock attribute */ | |
338 | mnt_list_lck_attr = lck_attr_alloc_init(); | |
91447636 A |
339 | |
340 | /* Allocate mount list lock */ | |
341 | mnt_list_mtx_lock = lck_mtx_alloc_init(mnt_list_lck_grp, mnt_list_lck_attr); | |
342 | ||
343 | ||
344 | /* allocate mount lock group attribute and group */ | |
345 | mnt_lck_grp_attr= lck_grp_attr_alloc_init(); | |
91447636 A |
346 | |
347 | mnt_lck_grp = lck_grp_alloc_init("mount", mnt_lck_grp_attr); | |
348 | ||
349 | /* Allocate mount lock attribute */ | |
350 | mnt_lck_attr = lck_attr_alloc_init(); | |
1c79356b | 351 | |
1c79356b A |
352 | /* |
353 | * Initialize the vnode table | |
354 | */ | |
355 | vntblinit(); | |
55e303ae A |
356 | /* |
357 | * Initialize the filesystem event mechanism. | |
358 | */ | |
359 | vfs_event_init(); | |
1c79356b A |
360 | /* |
361 | * Initialize the vnode name cache | |
362 | */ | |
363 | nchinit(); | |
2d21ac55 A |
364 | |
365 | #if JOURNALING | |
91447636 A |
366 | /* |
367 | * Initialize the journaling locks | |
368 | */ | |
369 | journal_init(); | |
2d21ac55 A |
370 | #endif |
371 | ||
1c79356b A |
372 | /* |
373 | * Build vnode operation vectors. | |
374 | */ | |
375 | vfs_op_init(); | |
376 | vfs_opv_init(); /* finish the job */ | |
377 | /* | |
55e303ae A |
378 | * Initialize each file system type in the static list, |
379 | * until the first NULL ->vfs_vfsops is encountered. | |
1c79356b | 380 | */ |
1c79356b | 381 | numused_vfsslots = maxtypenum = 0; |
6601e61a | 382 | for (vfsp = vfsconf, i = 0; i < maxvfsslots; i++, vfsp++) { |
1c79356b A |
383 | if (vfsp->vfc_vfsops == (struct vfsops *)0) |
384 | break; | |
385 | if (i) vfsconf[i-1].vfc_next = vfsp; | |
386 | if (maxtypenum <= vfsp->vfc_typenum) | |
387 | maxtypenum = vfsp->vfc_typenum + 1; | |
2d21ac55 A |
388 | /* a vfsconf is a prefix subset of a vfstable... */ |
389 | (*vfsp->vfc_vfsops->vfs_init)((struct vfsconf *)vfsp); | |
91447636 A |
390 | |
391 | lck_mtx_init(&vfsp->vfc_lock, fsconf_lck_grp, fsconf_lck_attr); | |
392 | ||
1c79356b A |
393 | numused_vfsslots++; |
394 | } | |
395 | /* next vfc_typenum to be used */ | |
396 | maxvfsconf = maxtypenum; | |
91447636 A |
397 | |
398 | /* | |
399 | * Initialize the vnop authorization scope. | |
400 | */ | |
401 | vnode_authorize_init(); | |
2d21ac55 A |
402 | |
403 | /* | |
404 | * Initialiize the quota system. | |
405 | */ | |
406 | #if QUOTA | |
407 | dqinit(); | |
408 | #endif | |
91447636 A |
409 | |
410 | /* | |
411 | * create a mount point for dead vnodes | |
412 | */ | |
413 | MALLOC_ZONE(mp, struct mount *, (u_long)sizeof(struct mount), | |
414 | M_MOUNT, M_WAITOK); | |
415 | bzero((char *)mp, (u_long)sizeof(struct mount)); | |
416 | /* Initialize the default IO constraints */ | |
417 | mp->mnt_maxreadcnt = mp->mnt_maxwritecnt = MAXPHYS; | |
418 | mp->mnt_segreadcnt = mp->mnt_segwritecnt = 32; | |
419 | mp->mnt_maxsegreadsize = mp->mnt_maxreadcnt; | |
420 | mp->mnt_maxsegwritesize = mp->mnt_maxwritecnt; | |
421 | mp->mnt_devblocksize = DEV_BSIZE; | |
2d21ac55 A |
422 | mp->mnt_alignmentmask = PAGE_MASK; |
423 | mp->mnt_ioflags = 0; | |
424 | mp->mnt_realrootvp = NULLVP; | |
425 | mp->mnt_authcache_ttl = CACHED_LOOKUP_RIGHT_TTL; | |
91447636 A |
426 | |
427 | TAILQ_INIT(&mp->mnt_vnodelist); | |
428 | TAILQ_INIT(&mp->mnt_workerqueue); | |
429 | TAILQ_INIT(&mp->mnt_newvnodes); | |
430 | mp->mnt_flag = MNT_LOCAL; | |
431 | mp->mnt_lflag = MNT_LDEAD; | |
432 | mount_lock_init(mp); | |
2d21ac55 A |
433 | |
434 | #if CONFIG_MACF | |
435 | mac_mount_label_init(mp); | |
436 | mac_mount_label_associate(vfs_context_kernel(), mp); | |
437 | #endif | |
91447636 A |
438 | dead_mountp = mp; |
439 | } | |
440 | ||
441 | void | |
2d21ac55 | 442 | vnode_list_lock(void) |
91447636 | 443 | { |
2d21ac55 | 444 | lck_spin_lock(vnode_list_spin_lock); |
91447636 A |
445 | } |
446 | ||
447 | void | |
2d21ac55 | 448 | vnode_list_unlock(void) |
91447636 | 449 | { |
2d21ac55 | 450 | lck_spin_unlock(vnode_list_spin_lock); |
91447636 A |
451 | } |
452 | ||
453 | void | |
2d21ac55 | 454 | mount_list_lock(void) |
91447636 A |
455 | { |
456 | lck_mtx_lock(mnt_list_mtx_lock); | |
457 | } | |
458 | ||
459 | void | |
2d21ac55 | 460 | mount_list_unlock(void) |
91447636 A |
461 | { |
462 | lck_mtx_unlock(mnt_list_mtx_lock); | |
463 | } | |
464 | ||
465 | void | |
466 | mount_lock_init(mount_t mp) | |
467 | { | |
468 | lck_mtx_init(&mp->mnt_mlock, mnt_lck_grp, mnt_lck_attr); | |
469 | lck_mtx_init(&mp->mnt_renamelock, mnt_lck_grp, mnt_lck_attr); | |
470 | lck_rw_init(&mp->mnt_rwlock, mnt_lck_grp, mnt_lck_attr); | |
471 | } | |
472 | ||
473 | void | |
474 | mount_lock_destroy(mount_t mp) | |
475 | { | |
476 | lck_mtx_destroy(&mp->mnt_mlock, mnt_lck_grp); | |
477 | lck_mtx_destroy(&mp->mnt_renamelock, mnt_lck_grp); | |
478 | lck_rw_destroy(&mp->mnt_rwlock, mnt_lck_grp); | |
1c79356b A |
479 | } |
480 | ||
91447636 | 481 | |
55e303ae | 482 | /* |
91447636 | 483 | * Name: vfstable_add |
55e303ae A |
484 | * |
485 | * Description: Add a filesystem to the vfsconf list at the first | |
486 | * unused slot. If no slots are available, return an | |
487 | * error. | |
488 | * | |
489 | * Parameter: nvfsp vfsconf for VFS to add | |
490 | * | |
491 | * Returns: 0 Success | |
492 | * -1 Failure | |
493 | * | |
494 | * Notes: The vfsconf should be treated as a linked list by | |
495 | * all external references, as the implementation is | |
496 | * expected to change in the future. The linkage is | |
497 | * through ->vfc_next, and the list is NULL terminated. | |
498 | * | |
499 | * Warning: This code assumes that vfsconf[0] is non-empty. | |
500 | */ | |
91447636 A |
501 | struct vfstable * |
502 | vfstable_add(struct vfstable *nvfsp) | |
1c79356b | 503 | { |
55e303ae | 504 | int slot; |
91447636 | 505 | struct vfstable *slotp; |
1c79356b | 506 | |
55e303ae A |
507 | /* |
508 | * Find the next empty slot; we recognize an empty slot by a | |
509 | * NULL-valued ->vfc_vfsops, so if we delete a VFS, we must | |
510 | * ensure we set the entry back to NULL. | |
511 | */ | |
512 | for (slot = 0; slot < maxvfsslots; slot++) { | |
513 | if (vfsconf[slot].vfc_vfsops == NULL) | |
514 | break; | |
515 | } | |
516 | if (slot == maxvfsslots) { | |
517 | /* out of static slots; allocate one instead */ | |
91447636 | 518 | MALLOC(slotp, struct vfstable *, sizeof(struct vfstable), |
55e303ae A |
519 | M_TEMP, M_WAITOK); |
520 | } else { | |
521 | slotp = &vfsconf[slot]; | |
522 | } | |
523 | ||
524 | /* | |
525 | * Replace the contents of the next empty slot with the contents | |
526 | * of the provided nvfsp. | |
527 | * | |
528 | * Note; Takes advantage of the fact that 'slot' was left | |
529 | * with the value of 'maxvfslots' in the allocation case. | |
530 | */ | |
91447636 A |
531 | bcopy(nvfsp, slotp, sizeof(struct vfstable)); |
532 | lck_mtx_init(&slotp->vfc_lock, fsconf_lck_grp, fsconf_lck_attr); | |
55e303ae A |
533 | if (slot != 0) { |
534 | slotp->vfc_next = vfsconf[slot - 1].vfc_next; | |
535 | vfsconf[slot - 1].vfc_next = slotp; | |
536 | } else { | |
537 | slotp->vfc_next = NULL; | |
538 | } | |
1c79356b | 539 | numused_vfsslots++; |
55e303ae | 540 | |
91447636 | 541 | return(slotp); |
1c79356b A |
542 | } |
543 | ||
55e303ae | 544 | /* |
91447636 | 545 | * Name: vfstable_del |
55e303ae A |
546 | * |
547 | * Description: Remove a filesystem from the vfsconf list by name. | |
548 | * If no such filesystem exists, return an error. | |
549 | * | |
550 | * Parameter: fs_name name of VFS to remove | |
551 | * | |
552 | * Returns: 0 Success | |
553 | * -1 Failure | |
554 | * | |
555 | * Notes: Hopefully all filesystems have unique names. | |
556 | */ | |
1c79356b | 557 | int |
91447636 | 558 | vfstable_del(struct vfstable * vtbl) |
1c79356b | 559 | { |
91447636 A |
560 | struct vfstable **vcpp; |
561 | struct vfstable *vcdelp; | |
1c79356b | 562 | |
55e303ae | 563 | /* |
91447636 | 564 | * Traverse the list looking for vtbl; if found, *vcpp |
55e303ae A |
565 | * will contain the address of the pointer to the entry to |
566 | * be removed. | |
567 | */ | |
568 | for( vcpp = &vfsconf; *vcpp; vcpp = &(*vcpp)->vfc_next) { | |
91447636 | 569 | if (*vcpp == vtbl) |
1c79356b | 570 | break; |
1c79356b | 571 | } |
55e303ae | 572 | |
91447636 A |
573 | if (*vcpp == NULL) |
574 | return(ESRCH); /* vtbl not on vfsconf list */ | |
55e303ae A |
575 | |
576 | /* Unlink entry */ | |
577 | vcdelp = *vcpp; | |
578 | *vcpp = (*vcpp)->vfc_next; | |
579 | ||
91447636 A |
580 | lck_mtx_destroy(&vcdelp->vfc_lock, fsconf_lck_grp); |
581 | ||
55e303ae A |
582 | /* |
583 | * Is this an entry from our static table? We find out by | |
584 | * seeing if the pointer to the object to be deleted places | |
585 | * the object in the address space containing the table (or not). | |
586 | */ | |
587 | if (vcdelp >= vfsconf && vcdelp < (vfsconf + maxvfsslots)) { /* Y */ | |
588 | /* Mark as empty for vfscon_add() */ | |
91447636 | 589 | bzero(vcdelp, sizeof(struct vfstable)); |
55e303ae A |
590 | numused_vfsslots--; |
591 | } else { /* N */ | |
592 | /* | |
593 | * This entry was dynamically allocated; we must free it; | |
594 | * we would prefer to have just linked the caller's | |
595 | * vfsconf onto our list, but it may not be persistent | |
596 | * because of the previous (copying) implementation. | |
597 | */ | |
598 | FREE(vcdelp, M_TEMP); | |
599 | } | |
600 | ||
1c79356b A |
601 | return(0); |
602 | } | |
91447636 A |
603 | |
604 | void | |
605 | SPECHASH_LOCK(void) | |
606 | { | |
607 | lck_mtx_lock(spechash_mtx_lock); | |
608 | } | |
609 | ||
610 | void | |
611 | SPECHASH_UNLOCK(void) | |
612 | { | |
613 | lck_mtx_unlock(spechash_mtx_lock); | |
614 | } | |
615 |