+ devsw_lock_t newlock, tmplock;
+ int res;
+
+ assert(0 <= major(dev) && major(dev) < nchrdev);
+ assert(mode == S_IFCHR || mode == S_IFBLK);
+
+ MALLOC(newlock, devsw_lock_t, sizeof(struct devsw_lock), M_TEMP, M_WAITOK | M_ZERO);
+ newlock->dl_dev = dev;
+ newlock->dl_thread = current_thread();
+ newlock->dl_mode = mode;
+
+ lck_mtx_lock_spin(&devsw_lock_list_mtx);
+retry:
+ TAILQ_FOREACH(tmplock, &devsw_locks, dl_list)
+ {
+ if (tmplock->dl_dev == dev && tmplock->dl_mode == mode) {
+ res = msleep(tmplock, &devsw_lock_list_mtx, PVFS, "devsw_lock", NULL);
+ assert(res == 0);
+ goto retry;
+ }
+ }
+
+ TAILQ_INSERT_TAIL(&devsw_locks, newlock, dl_list);
+ lck_mtx_unlock(&devsw_lock_list_mtx);
+}
+void
+devsw_unlock(dev_t dev, int mode)
+{
+ devsw_lock_t tmplock;
+
+ assert(0 <= major(dev) && major(dev) < nchrdev);
+
+ lck_mtx_lock_spin(&devsw_lock_list_mtx);