+void
+vnode_list_unlock(void)
+{
+ lck_spin_unlock(vnode_list_spin_lock);
+}
+
+void
+mount_list_lock(void)
+{
+ lck_mtx_lock(mnt_list_mtx_lock);
+}
+
+void
+mount_list_unlock(void)
+{
+ lck_mtx_unlock(mnt_list_mtx_lock);
+}
+
+void
+mount_lock_init(mount_t mp)
+{
+ lck_mtx_init(&mp->mnt_mlock, mnt_lck_grp, mnt_lck_attr);
+ lck_mtx_init(&mp->mnt_renamelock, mnt_lck_grp, mnt_lck_attr);
+ lck_rw_init(&mp->mnt_rwlock, mnt_lck_grp, mnt_lck_attr);
+}
+
+void
+mount_lock_destroy(mount_t mp)
+{
+ lck_mtx_destroy(&mp->mnt_mlock, mnt_lck_grp);
+ lck_mtx_destroy(&mp->mnt_renamelock, mnt_lck_grp);
+ lck_rw_destroy(&mp->mnt_rwlock, mnt_lck_grp);
+}
+
+
+/*
+ * Name: vfstable_add
+ *
+ * Description: Add a filesystem to the vfsconf list at the first
+ * unused slot. If no slots are available, return an
+ * error.
+ *
+ * Parameter: nvfsp vfsconf for VFS to add
+ *
+ * Returns: 0 Success
+ * -1 Failure
+ *
+ * Notes: The vfsconf should be treated as a linked list by
+ * all external references, as the implementation is
+ * expected to change in the future. The linkage is
+ * through ->vfc_next, and the list is NULL terminated.
+ *
+ * Warning: This code assumes that vfsconf[0] is non-empty.
+ */
+struct vfstable *
+vfstable_add(struct vfstable *nvfsp)
+{
+ int slot;
+ struct vfstable *slotp, *allocated = NULL;
+
+ /*
+ * Find the next empty slot; we recognize an empty slot by a
+ * NULL-valued ->vfc_vfsops, so if we delete a VFS, we must
+ * ensure we set the entry back to NULL.
+ */
+findslot:
+ mount_list_lock();
+ for (slot = 0; slot < maxvfsslots; slot++) {
+ if (vfsconf[slot].vfc_vfsops == NULL)
+ break;
+ }
+ if (slot == maxvfsslots) {
+ if (allocated == NULL) {
+ mount_list_unlock();
+ /* out of static slots; allocate one instead */
+ MALLOC(allocated, struct vfstable *, sizeof(struct vfstable),
+ M_TEMP, M_WAITOK);
+ goto findslot;
+ } else {
+ slotp = allocated;
+ allocated = NULL;
+ }
+ } else {
+ slotp = &vfsconf[slot];
+ }
+
+ /*
+ * Replace the contents of the next empty slot with the contents
+ * of the provided nvfsp.
+ *
+ * Note; Takes advantage of the fact that 'slot' was left
+ * with the value of 'maxvfslots' in the allocation case.
+ */
+ bcopy(nvfsp, slotp, sizeof(struct vfstable));
+ if (slot != 0) {
+ slotp->vfc_next = vfsconf[slot - 1].vfc_next;
+ vfsconf[slot - 1].vfc_next = slotp;
+ } else {
+ slotp->vfc_next = NULL;
+ }