]> git.saurik.com Git - apple/xnu.git/blame - bsd/vfs/vfs_init.c
xnu-7195.101.1.tar.gz
[apple/xnu.git] / bsd / vfs / vfs_init.c
CommitLineData
1c79356b 1/*
6d2010ae 2 * Copyright (c) 2000-2010 Apple Inc. All rights reserved.
5d5c5d0d 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 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.
0a7de745 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.
0a7de745 17 *
2d21ac55
A
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.
0a7de745 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 84#include <sys/errno.h>
f427ee49 85#include <kern/kalloc.h>
39037602 86#include <sys/decmpfs.h>
1c79356b 87
2d21ac55
A
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
f427ee49
A
105ZONE_DECLARE(mount_zone, "mount", sizeof(struct mount), ZC_ZFREE_CLEARMEM);
106
39236c6e 107__private_extern__ void vntblinit(void);
2d21ac55 108
cb323159 109extern const struct vnodeopv_desc *vfs_opv_descs[];
0a7de745 110/* a list of lists of vnodeops defns */
1c79356b 111extern struct vnodeop_desc *vfs_op_descs[];
0a7de745 112/* and the operations they perform */
1c79356b
A
113/*
114 * This code doesn't work if the defn is **vnodop_defns with cc.
115 * The problem is because of the compiler sometimes putting in an
116 * extra level of indirection for arrays. It's an interesting
117 * "feature" of C.
118 */
119int vfs_opv_numops;
120
0a7de745 121typedef int (*PFIvp)(void *);
1c79356b
A
122
123/*
124 * A miscellaneous routine.
125 * A generic "default" routine that just returns an error.
126 */
127int
2d21ac55 128vn_default_error(void)
1c79356b 129{
0a7de745 130 return ENOTSUP;
1c79356b
A
131}
132
133/*
134 * vfs_init.c
135 *
136 * Allocate and fill in operations vectors.
137 *
138 * An undocumented feature of this approach to defining operations is that
139 * there can be multiple entries in vfs_opv_descs for the same operations
140 * vector. This allows third parties to extend the set of operations
141 * supported by another layer in a binary compatibile way. For example,
142 * assume that NFS needed to be modified to support Ficus. NFS has an entry
143 * (probably nfs_vnopdeop_decls) declaring all the operations NFS supports by
144 * default. Ficus could add another entry (ficus_nfs_vnodeop_decl_entensions)
145 * listing those new operations Ficus adds to NFS, all without modifying the
146 * NFS code. (Of couse, the OTW NFS protocol still needs to be munged, but
147 * that is a(whole)nother story.) This is a feature.
148 */
149void
2d21ac55 150vfs_opv_init(void)
1c79356b
A
151{
152 int i, j, k;
0a7de745
A
153 int(***opv_desc_vector_p)(void *);
154 int(**opv_desc_vector)(void *);
cb323159 155 const struct vnodeopv_entry_desc *opve_descp;
1c79356b
A
156
157 /*
158 * Allocate the dynamic vectors and fill them in.
159 */
0a7de745 160 for (i = 0; vfs_opv_descs[i]; i++) {
1c79356b
A
161 opv_desc_vector_p = vfs_opv_descs[i]->opv_desc_vector_p;
162 /*
163 * Allocate and init the vector, if it needs it.
164 * Also handle backwards compatibility.
165 */
166 if (*opv_desc_vector_p == NULL) {
f427ee49
A
167 *opv_desc_vector_p = kheap_alloc(KHEAP_DEFAULT,
168 vfs_opv_numops * sizeof(PFIvp), Z_WAITOK | Z_ZERO);
1c79356b
A
169 DODEBUG(printf("vector at %x allocated\n",
170 opv_desc_vector_p));
171 }
172 opv_desc_vector = *opv_desc_vector_p;
0a7de745 173 for (j = 0; vfs_opv_descs[i]->opv_desc_ops[j].opve_op; j++) {
1c79356b
A
174 opve_descp = &(vfs_opv_descs[i]->opv_desc_ops[j]);
175
813fb2f6
A
176 /* Silently skip known-disabled operations */
177 if (opve_descp->opve_op->vdesc_flags & VDESC_DISABLED) {
178 printf("vfs_fsadd: Ignoring reference in %p to disabled operation %s.\n",
0a7de745 179 vfs_opv_descs[i], opve_descp->opve_op->vdesc_name);
813fb2f6
A
180 continue;
181 }
182
1c79356b
A
183 /*
184 * Sanity check: is this operation listed
185 * in the list of operations? We check this
186 * by seeing if its offest is zero. Since
187 * the default routine should always be listed
188 * first, it should be the only one with a zero
189 * offset. Any other operation with a zero
190 * offset is probably not listed in
191 * vfs_op_descs, and so is probably an error.
192 *
193 * A panic here means the layer programmer
194 * has committed the all-too common bug
195 * of adding a new operation to the layer's
196 * list of vnode operations but
197 * not adding the operation to the system-wide
198 * list of supported operations.
199 */
200 if (opve_descp->opve_op->vdesc_offset == 0 &&
0a7de745
A
201 opve_descp->opve_op !=
202 VDESC(vnop_default)) {
1c79356b
A
203 printf("operation %s not listed in %s.\n",
204 opve_descp->opve_op->vdesc_name,
205 "vfs_op_descs");
0a7de745 206 panic("vfs_opv_init: bad operation");
1c79356b
A
207 }
208 /*
209 * Fill in this entry.
210 */
211 opv_desc_vector[opve_descp->opve_op->vdesc_offset] =
0a7de745 212 opve_descp->opve_impl;
1c79356b
A
213 }
214 }
215 /*
216 * Finally, go back and replace unfilled routines
217 * with their default. (Sigh, an O(n^3) algorithm. I
218 * could make it better, but that'd be work, and n is small.)
219 */
220 for (i = 0; vfs_opv_descs[i]; i++) {
221 opv_desc_vector = *(vfs_opv_descs[i]->opv_desc_vector_p);
222 /*
223 * Force every operations vector to have a default routine.
224 */
0a7de745 225 if (opv_desc_vector[VOFFSET(vnop_default)] == NULL) {
1c79356b
A
226 panic("vfs_opv_init: operation vector without default routine.");
227 }
0a7de745
A
228 for (k = 0; k < vfs_opv_numops; k++) {
229 if (opv_desc_vector[k] == NULL) {
230 opv_desc_vector[k] =
231 opv_desc_vector[VOFFSET(vnop_default)];
232 }
233 }
1c79356b
A
234 }
235}
236
237/*
238 * Initialize known vnode operations vectors.
239 */
240void
2d21ac55 241vfs_op_init(void)
1c79356b
A
242{
243 int i;
244
245 DODEBUG(printf("Vnode_interface_init.\n"));
246 /*
247 * Set all vnode vectors to a well known value.
248 */
0a7de745 249 for (i = 0; vfs_opv_descs[i]; i++) {
1c79356b 250 *(vfs_opv_descs[i]->opv_desc_vector_p) = NULL;
0a7de745 251 }
1c79356b
A
252 /*
253 * Figure out how many ops there are by counting the table,
254 * and assign each its offset.
255 */
256 for (vfs_opv_numops = 0, i = 0; vfs_op_descs[i]; i++) {
813fb2f6
A
257 /* Silently skip known-disabled operations */
258 if (vfs_op_descs[i]->vdesc_flags & VDESC_DISABLED) {
259 continue;
260 }
1c79356b
A
261 vfs_op_descs[i]->vdesc_offset = vfs_opv_numops;
262 vfs_opv_numops++;
263 }
0a7de745 264 DODEBUG(printf("vfs_opv_numops=%d\n", vfs_opv_numops));
1c79356b
A
265}
266
267/*
268 * Routines having to do with the management of the vnode table.
269 */
270extern struct vnodeops dead_vnodeops;
271extern struct vnodeops spec_vnodeops;
1c79356b 272
91447636 273/* vars for vnode list lock */
c3c9b80d
A
274static LCK_GRP_DECLARE(vnode_list_lck_grp, "vnode list");
275static LCK_ATTR_DECLARE(vnode_list_lck_attr, 0, 0);
276static LCK_SPIN_DECLARE_ATTR(vnode_list_spin_lock,
277 &vnode_list_lck_grp, &vnode_list_lck_attr);
278static LCK_MTX_DECLARE_ATTR(spechash_mtx_lock,
279 &vnode_list_lck_grp, &vnode_list_lck_attr);
280LCK_MTX_DECLARE_ATTR(pkg_extensions_lck,
281 &vnode_list_lck_grp, &vnode_list_lck_attr);
91447636
A
282
283/* vars for mount lock */
c3c9b80d
A
284static LCK_GRP_DECLARE(mnt_lck_grp, "mount");
285static LCK_ATTR_DECLARE(mnt_lck_attr, 0, 0);
91447636
A
286
287/* vars for mount list lock */
c3c9b80d
A
288static LCK_GRP_DECLARE(mnt_list_lck_grp, "mount list");
289LCK_MTX_DECLARE(mnt_list_mtx_lock, &mnt_list_lck_grp);
b0d623f7 290
91447636 291struct mount * dead_mountp;
6d2010ae 292
1c79356b
A
293/*
294 * Initialize the vnode structures and initialize each file system type.
295 */
91447636 296void
2d21ac55 297vfsinit(void)
1c79356b 298{
91447636 299 struct vfstable *vfsp;
1c79356b 300 int i, maxtypenum;
91447636 301 struct mount * mp;
0a7de745 302
1c79356b
A
303 /*
304 * Initialize the vnode table
305 */
306 vntblinit();
55e303ae
A
307 /*
308 * Initialize the filesystem event mechanism.
309 */
310 vfs_event_init();
1c79356b
A
311 /*
312 * Initialize the vnode name cache
313 */
314 nchinit();
2d21ac55 315
1c79356b
A
316 /*
317 * Build vnode operation vectors.
318 */
319 vfs_op_init();
320 vfs_opv_init(); /* finish the job */
321 /*
55e303ae
A
322 * Initialize each file system type in the static list,
323 * until the first NULL ->vfs_vfsops is encountered.
1c79356b 324 */
fe8ab488 325 maxtypenum = VT_NON;
6601e61a 326 for (vfsp = vfsconf, i = 0; i < maxvfsslots; i++, vfsp++) {
b0d623f7 327 struct vfsconf vfsc;
0a7de745 328 if (vfsp->vfc_vfsops == (struct vfsops *)0) {
1c79356b 329 break;
0a7de745
A
330 }
331 if (i) {
332 vfsconf[i - 1].vfc_next = vfsp;
333 }
334 if (maxtypenum <= vfsp->vfc_typenum) {
1c79356b 335 maxtypenum = vfsp->vfc_typenum + 1;
0a7de745
A
336 }
337
b0d623f7
A
338 bzero(&vfsc, sizeof(struct vfsconf));
339 vfsc.vfc_reserved1 = 0;
340 bcopy(vfsp->vfc_name, vfsc.vfc_name, sizeof(vfsc.vfc_name));
341 vfsc.vfc_typenum = vfsp->vfc_typenum;
342 vfsc.vfc_refcount = vfsp->vfc_refcount;
343 vfsc.vfc_flags = vfsp->vfc_flags;
344 vfsc.vfc_reserved2 = 0;
345 vfsc.vfc_reserved3 = 0;
346
fe8ab488
A
347 if (vfsp->vfc_vfsops->vfs_sysctl) {
348 struct sysctl_oid *oidp = NULL;
349 struct sysctl_oid oid = SYSCTL_STRUCT_INIT(_vfs, vfsp->vfc_typenum, , CTLTYPE_NODE | CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED, NULL, 0, vfs_sysctl_node, "-", "");
0a7de745 350
f427ee49 351 oidp = kheap_alloc(KHEAP_DEFAULT, sizeof(struct sysctl_oid), Z_WAITOK);
fe8ab488 352 *oidp = oid;
0a7de745 353
fe8ab488
A
354 /* Memory for VFS oid held by vfsentry forever */
355 vfsp->vfc_sysctl = oidp;
356 oidp->oid_name = vfsp->vfc_name;
357 sysctl_register_oid(vfsp->vfc_sysctl);
358 }
0a7de745 359
b0d623f7
A
360 (*vfsp->vfc_vfsops->vfs_init)(&vfsc);
361
1c79356b 362 numused_vfsslots++;
fe8ab488 363 numregistered_fses++;
1c79356b
A
364 }
365 /* next vfc_typenum to be used */
fe8ab488 366 maxvfstypenum = maxtypenum;
91447636
A
367
368 /*
369 * Initialize the vnop authorization scope.
370 */
371 vnode_authorize_init();
2d21ac55 372
0a7de745 373 /*
91447636
A
374 * create a mount point for dead vnodes
375 */
f427ee49 376 mp = zalloc_flags(mount_zone, Z_WAITOK | Z_ZERO);
91447636
A
377 /* Initialize the default IO constraints */
378 mp->mnt_maxreadcnt = mp->mnt_maxwritecnt = MAXPHYS;
379 mp->mnt_segreadcnt = mp->mnt_segwritecnt = 32;
380 mp->mnt_maxsegreadsize = mp->mnt_maxreadcnt;
381 mp->mnt_maxsegwritesize = mp->mnt_maxwritecnt;
382 mp->mnt_devblocksize = DEV_BSIZE;
2d21ac55 383 mp->mnt_alignmentmask = PAGE_MASK;
b0d623f7
A
384 mp->mnt_ioqueue_depth = MNT_DEFAULT_IOQUEUE_DEPTH;
385 mp->mnt_ioscale = 1;
2d21ac55
A
386 mp->mnt_ioflags = 0;
387 mp->mnt_realrootvp = NULLVP;
388 mp->mnt_authcache_ttl = CACHED_LOOKUP_RIGHT_TTL;
0a7de745 389
91447636
A
390 TAILQ_INIT(&mp->mnt_vnodelist);
391 TAILQ_INIT(&mp->mnt_workerqueue);
392 TAILQ_INIT(&mp->mnt_newvnodes);
393 mp->mnt_flag = MNT_LOCAL;
394 mp->mnt_lflag = MNT_LDEAD;
395 mount_lock_init(mp);
2d21ac55
A
396
397#if CONFIG_MACF
398 mac_mount_label_init(mp);
399 mac_mount_label_associate(vfs_context_kernel(), mp);
400#endif
91447636 401 dead_mountp = mp;
39037602
A
402
403#if FS_COMPRESSION
404 decmpfs_init();
405#endif
cb323159
A
406
407 nspace_resolver_init();
91447636
A
408}
409
410void
2d21ac55 411vnode_list_lock(void)
91447636 412{
c3c9b80d 413 lck_spin_lock_grp(&vnode_list_spin_lock, &vnode_list_lck_grp);
91447636
A
414}
415
416void
2d21ac55 417vnode_list_unlock(void)
91447636 418{
c3c9b80d 419 lck_spin_unlock(&vnode_list_spin_lock);
91447636
A
420}
421
422void
2d21ac55 423mount_list_lock(void)
91447636 424{
c3c9b80d 425 lck_mtx_lock(&mnt_list_mtx_lock);
91447636
A
426}
427
428void
2d21ac55 429mount_list_unlock(void)
91447636 430{
c3c9b80d 431 lck_mtx_unlock(&mnt_list_mtx_lock);
91447636
A
432}
433
434void
435mount_lock_init(mount_t mp)
436{
c3c9b80d
A
437 lck_mtx_init(&mp->mnt_mlock, &mnt_lck_grp, &mnt_lck_attr);
438 lck_mtx_init(&mp->mnt_iter_lock, &mnt_lck_grp, &mnt_lck_attr);
439 lck_mtx_init(&mp->mnt_renamelock, &mnt_lck_grp, &mnt_lck_attr);
440 lck_rw_init(&mp->mnt_rwlock, &mnt_lck_grp, &mnt_lck_attr);
91447636
A
441}
442
443void
444mount_lock_destroy(mount_t mp)
445{
c3c9b80d
A
446 lck_mtx_destroy(&mp->mnt_mlock, &mnt_lck_grp);
447 lck_mtx_destroy(&mp->mnt_iter_lock, &mnt_lck_grp);
448 lck_mtx_destroy(&mp->mnt_renamelock, &mnt_lck_grp);
449 lck_rw_destroy(&mp->mnt_rwlock, &mnt_lck_grp);
1c79356b
A
450}
451
91447636 452
55e303ae 453/*
91447636 454 * Name: vfstable_add
55e303ae
A
455 *
456 * Description: Add a filesystem to the vfsconf list at the first
457 * unused slot. If no slots are available, return an
458 * error.
459 *
460 * Parameter: nvfsp vfsconf for VFS to add
461 *
462 * Returns: 0 Success
463 * -1 Failure
464 *
465 * Notes: The vfsconf should be treated as a linked list by
466 * all external references, as the implementation is
467 * expected to change in the future. The linkage is
468 * through ->vfc_next, and the list is NULL terminated.
469 *
470 * Warning: This code assumes that vfsconf[0] is non-empty.
471 */
91447636
A
472struct vfstable *
473vfstable_add(struct vfstable *nvfsp)
1c79356b 474{
55e303ae 475 int slot;
b0d623f7 476 struct vfstable *slotp, *allocated = NULL;
fe8ab488 477 struct sysctl_oid *oidp = NULL;
1c79356b 478
0a7de745 479
fe8ab488
A
480 if (nvfsp->vfc_vfsops->vfs_sysctl) {
481 struct sysctl_oid oid = SYSCTL_STRUCT_INIT(_vfs, nvfsp->vfc_typenum, , CTLTYPE_NODE | CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED, NULL, 0, vfs_sysctl_node, "-", "");
0a7de745 482
f427ee49 483 oidp = kheap_alloc(KHEAP_DEFAULT, sizeof(struct sysctl_oid), Z_WAITOK);
fe8ab488
A
484 *oidp = oid;
485 }
0a7de745 486
55e303ae
A
487 /*
488 * Find the next empty slot; we recognize an empty slot by a
489 * NULL-valued ->vfc_vfsops, so if we delete a VFS, we must
490 * ensure we set the entry back to NULL.
491 */
b0d623f7
A
492findslot:
493 mount_list_lock();
55e303ae 494 for (slot = 0; slot < maxvfsslots; slot++) {
0a7de745 495 if (vfsconf[slot].vfc_vfsops == NULL) {
55e303ae 496 break;
0a7de745 497 }
55e303ae
A
498 }
499 if (slot == maxvfsslots) {
b0d623f7
A
500 if (allocated == NULL) {
501 mount_list_unlock();
502 /* out of static slots; allocate one instead */
f427ee49
A
503 allocated = kheap_alloc(KHEAP_DEFAULT, sizeof(struct vfstable),
504 Z_WAITOK);
b0d623f7
A
505 goto findslot;
506 } else {
507 slotp = allocated;
b0d623f7 508 }
55e303ae
A
509 } else {
510 slotp = &vfsconf[slot];
511 }
512
513 /*
514 * Replace the contents of the next empty slot with the contents
515 * of the provided nvfsp.
516 *
517 * Note; Takes advantage of the fact that 'slot' was left
518 * with the value of 'maxvfslots' in the allocation case.
519 */
91447636 520 bcopy(nvfsp, slotp, sizeof(struct vfstable));
55e303ae
A
521 if (slot != 0) {
522 slotp->vfc_next = vfsconf[slot - 1].vfc_next;
523 vfsconf[slot - 1].vfc_next = slotp;
524 } else {
525 slotp->vfc_next = NULL;
526 }
55e303ae 527
fe8ab488
A
528 if (slotp != allocated) {
529 /* used a statically allocated slot */
530 numused_vfsslots++;
531 }
532 numregistered_fses++;
b0d623f7 533
fe8ab488
A
534 if (oidp) {
535 /* Memory freed in vfstable_del after unregistration */
536 slotp->vfc_sysctl = oidp;
537 oidp->oid_name = slotp->vfc_name;
538 sysctl_register_oid(slotp->vfc_sysctl);
539 }
540
541 mount_list_unlock();
0a7de745 542
fe8ab488
A
543 if (allocated && allocated != slotp) {
544 /* did allocation, but ended up using static slot */
f427ee49 545 kheap_free(KHEAP_DEFAULT, allocated, sizeof(struct vfstable));
b0d623f7
A
546 }
547
0a7de745 548 return slotp;
1c79356b
A
549}
550
55e303ae 551/*
91447636 552 * Name: vfstable_del
55e303ae
A
553 *
554 * Description: Remove a filesystem from the vfsconf list by name.
555 * If no such filesystem exists, return an error.
556 *
557 * Parameter: fs_name name of VFS to remove
558 *
559 * Returns: 0 Success
560 * -1 Failure
561 *
562 * Notes: Hopefully all filesystems have unique names.
563 */
1c79356b 564int
91447636 565vfstable_del(struct vfstable * vtbl)
1c79356b 566{
91447636
A
567 struct vfstable **vcpp;
568 struct vfstable *vcdelp;
1c79356b 569
b0d623f7 570#if DEBUG
c3c9b80d 571 lck_mtx_assert(&mnt_list_mtx_lock, LCK_MTX_ASSERT_OWNED);
b0d623f7
A
572#endif /* DEBUG */
573
55e303ae 574 /*
91447636 575 * Traverse the list looking for vtbl; if found, *vcpp
55e303ae
A
576 * will contain the address of the pointer to the entry to
577 * be removed.
578 */
0a7de745
A
579 for (vcpp = &vfsconf; *vcpp; vcpp = &(*vcpp)->vfc_next) {
580 if (*vcpp == vtbl) {
fe8ab488 581 break;
0a7de745 582 }
fe8ab488 583 }
55e303ae 584
0a7de745
A
585 if (*vcpp == NULL) {
586 return ESRCH; /* vtbl not on vfsconf list */
587 }
fe8ab488
A
588 if ((*vcpp)->vfc_sysctl) {
589 sysctl_unregister_oid((*vcpp)->vfc_sysctl);
590 (*vcpp)->vfc_sysctl->oid_name = NULL;
f427ee49 591 kheap_free(KHEAP_DEFAULT, (*vcpp)->vfc_sysctl, sizeof(struct sysctl_oid));
fe8ab488
A
592 }
593
55e303ae
A
594 /* Unlink entry */
595 vcdelp = *vcpp;
596 *vcpp = (*vcpp)->vfc_next;
597
598 /*
599 * Is this an entry from our static table? We find out by
600 * seeing if the pointer to the object to be deleted places
601 * the object in the address space containing the table (or not).
602 */
0a7de745 603 if (vcdelp >= vfsconf && vcdelp < (vfsconf + maxvfsslots)) { /* Y */
55e303ae 604 /* Mark as empty for vfscon_add() */
91447636 605 bzero(vcdelp, sizeof(struct vfstable));
fe8ab488 606 numregistered_fses--;
55e303ae 607 numused_vfsslots--;
0a7de745 608 } else { /* N */
55e303ae
A
609 /*
610 * This entry was dynamically allocated; we must free it;
611 * we would prefer to have just linked the caller's
612 * vfsconf onto our list, but it may not be persistent
613 * because of the previous (copying) implementation.
614 */
fe8ab488 615 numregistered_fses--;
b0d623f7 616 mount_list_unlock();
f427ee49 617 kheap_free(KHEAP_DEFAULT, vcdelp, sizeof(struct vfstable));
b0d623f7 618 mount_list_lock();
55e303ae
A
619 }
620
b0d623f7 621#if DEBUG
c3c9b80d 622 lck_mtx_assert(&mnt_list_mtx_lock, LCK_MTX_ASSERT_OWNED);
b0d623f7
A
623#endif /* DEBUG */
624
0a7de745 625 return 0;
1c79356b 626}
91447636
A
627
628void
629SPECHASH_LOCK(void)
630{
c3c9b80d 631 lck_mtx_lock(&spechash_mtx_lock);
91447636
A
632}
633
634void
635SPECHASH_UNLOCK(void)
636{
c3c9b80d 637 lck_mtx_unlock(&spechash_mtx_lock);
91447636 638}