- struct vfstable *vfsp;
-
- /* Find our vfstable entry */
- for (vfsp = vfsconf; vfsp; vfsp = vfsp->vfc_next)
- if (!strncmp(vfsp->vfc_name, "devfs", sizeof(vfsp->vfc_name)))
- break;
-
- if (!vfsp) {
- panic("Could not find entry in vfsconf for devfs.\n");
- }
-
- /*
- * Get vnode to be covered
- */
- NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE,
- CAST_USER_ADDR_T(mntname), ctx);
- if ((error = namei(&nd))) {
- printf("devfs_kernel_mount: failed to find directory '%s', %d",
- mntname, error);
- return (error);
- }
- nameidone(&nd);
- vp = nd.ni_vp;
-
- if ((error = VNOP_FSYNC(vp, MNT_WAIT, ctx))) {
- printf("devfs_kernel_mount: vnop_fsync failed: %d\n", error);
- vnode_put(vp);
- return (error);
- }
- if ((error = buf_invalidateblks(vp, BUF_WRITE_DATA, 0, 0))) {
- printf("devfs_kernel_mount: buf_invalidateblks failed: %d\n", error);
- vnode_put(vp);
- return (error);
- }
- if (vnode_isdir(vp) == 0) {
- printf("devfs_kernel_mount: '%s' is not a directory\n", mntname);
- vnode_put(vp);
- return (ENOTDIR);
- }
- if ((vnode_mountedhere(vp))) {
- vnode_put(vp);
- return (EBUSY);
- }
-
- /*
- * Allocate and initialize the filesystem.
- */
- MALLOC_ZONE(mp, struct mount *, sizeof(struct mount),
- M_MOUNT, M_WAITOK);
- bzero((char *)mp, sizeof(struct mount));
-
- /* Initialize the default IO constraints */
- mp->mnt_maxreadcnt = mp->mnt_maxwritecnt = MAXPHYS;
- mp->mnt_segreadcnt = mp->mnt_segwritecnt = 32;
- mp->mnt_ioflags = 0;
- mp->mnt_realrootvp = NULLVP;
- mp->mnt_authcache_ttl = CACHED_LOOKUP_RIGHT_TTL;
-
- mount_lock_init(mp);
- TAILQ_INIT(&mp->mnt_vnodelist);
- TAILQ_INIT(&mp->mnt_workerqueue);
- TAILQ_INIT(&mp->mnt_newvnodes);
-
- (void)vfs_busy(mp, LK_NOWAIT);
- mp->mnt_op = &devfs_vfsops;
- mp->mnt_vtable = vfsp;
- mp->mnt_flag = 0;
- mp->mnt_flag |= vfsp->vfc_flags & MNT_VISFLAGMASK;
- strlcpy(mp->mnt_vfsstat.f_fstypename, vfsp->vfc_name, MFSTYPENAMELEN);
- vp->v_mountedhere = mp;
- mp->mnt_vnodecovered = vp;
- mp->mnt_vfsstat.f_owner = kauth_cred_getuid(kauth_cred_get());
- (void) copystr(mntname, mp->mnt_vfsstat.f_mntonname, MAXPATHLEN - 1, 0);
-#if CONFIG_MACF
- mac_mount_label_init(mp);
- mac_mount_label_associate(ctx, mp);
-#endif
-
- error = devfs_mount(mp, NULL, USER_ADDR_NULL, ctx);