static int vnclone(struct dev_clone_args *ap) { int unit; unit = devfs_clone_bitmap_get(&DEVFS_CLONE_BITMAP(vn), 0); ap->a_dev = vn_create(unit, &DEVFS_CLONE_BITMAP(vn), 1); return 0; }
static int snpclone(struct dev_clone_args *ap) { int unit; lwkt_gettoken(&tty_token); unit = devfs_clone_bitmap_get(&DEVFS_CLONE_BITMAP(snp), 0); ap->a_dev = make_only_dev(&snp_ops, unit, UID_ROOT, GID_WHEEL, 0600, "snp%d", unit); lwkt_reltoken(&tty_token); return 0; }
static int ptyclone(struct dev_clone_args *ap) { int unit; struct pt_ioctl *pt; /* * Limit the number of unix98 pty (slave) devices to 1000, as * the utmp(5) format only allows for 8 bytes for the tty, * "pts/XXX". * If this limit is reached, we don't clone and return error * to devfs. */ unit = devfs_clone_bitmap_get(&DEVFS_CLONE_BITMAP(pty), 1000); if (unit < 0) { ap->a_dev = NULL; return 1; } pt = kmalloc(sizeof(*pt), M_PTY, M_WAITOK | M_ZERO); pt->devc = make_only_dev(&ptc98_ops, unit, ap->a_cred->cr_ruid, 0, 0600, "ptm/%d", unit); pt->devs = make_dev(&pts98_ops, unit, ap->a_cred->cr_ruid, GID_TTY, 0620, "pts/%d", unit); ap->a_dev = pt->devc; pt->devs->si_flags |= SI_OVERRIDE; /* uid, gid, perms from dev */ pt->devc->si_flags |= SI_OVERRIDE; /* uid, gid, perms from dev */ pt->pt_tty.t_dev = pt->devs; pt->pt_flags |= PF_UNIX98; pt->pt_uminor = unit; pt->devs->si_drv1 = pt->devc->si_drv1 = pt; pt->devs->si_tty = pt->devc->si_tty = &pt->pt_tty; ttyregister(&pt->pt_tty); return 0; }
static void ue_attach_post_task(struct usb_proc_msg *_task) { struct usb_ether_cfg_task *task = (struct usb_ether_cfg_task *)_task; struct usb_ether *ue = task->ue; struct ifnet *ifp = uether_getifp(ue); int error; char num[14]; /* sufficient for 32 bits */ /* first call driver's post attach routine */ ue->ue_methods->ue_attach_post(ue); UE_UNLOCK(ue); KKASSERT(!lockowned(ue->ue_lock)); ue->ue_unit = devfs_clone_bitmap_get(&DEVFS_CLONE_BITMAP(ue), 0); usb_callout_init_mtx(&ue->ue_watchdog, ue->ue_lock, 0); sysctl_ctx_init(&ue->ue_sysctl_ctx); KKASSERT(!lockowned(ue->ue_lock)); error = 0; ifp->if_softc = ue; if_initname(ifp, "ue", ue->ue_unit); if (ue->ue_methods->ue_attach_post_sub != NULL) { error = ue->ue_methods->ue_attach_post_sub(ue); KKASSERT(!lockowned(ue->ue_lock)); } else { ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; if (ue->ue_methods->ue_ioctl != NULL) ifp->if_ioctl = ue->ue_methods->ue_ioctl; else ifp->if_ioctl = uether_ioctl; ifp->if_start = ue_start; ifp->if_init = ue_init; ifq_set_maxlen(&ifp->if_snd, ifqmaxlen); ifq_set_ready(&ifp->if_snd); if (ue->ue_methods->ue_mii_upd != NULL && ue->ue_methods->ue_mii_sts != NULL) { error = mii_phy_probe(ue->ue_dev, &ue->ue_miibus, ue_ifmedia_upd, ue->ue_methods->ue_mii_sts); } } if (error) { device_printf(ue->ue_dev, "attaching PHYs failed\n"); goto fail; } if_printf(ifp, "<USB Ethernet> on %s\n", device_get_nameunit(ue->ue_dev)); ether_ifattach(ifp, ue->ue_eaddr, NULL); /* Tell upper layer we support VLAN oversized frames. */ if (ifp->if_capabilities & IFCAP_VLAN_MTU) ifp->if_hdrlen = sizeof(struct ether_vlan_header); ksnprintf(num, sizeof(num), "%u", ue->ue_unit); ue->ue_sysctl_oid = SYSCTL_ADD_NODE(&ue->ue_sysctl_ctx, &SYSCTL_NODE_CHILDREN(_net, ue), OID_AUTO, num, CTLFLAG_RD, NULL, ""); SYSCTL_ADD_PROC(&ue->ue_sysctl_ctx, SYSCTL_CHILDREN(ue->ue_sysctl_oid), OID_AUTO, "%parent", CTLTYPE_STRING | CTLFLAG_RD, ue, 0, ue_sysctl_parent, "A", "parent device"); KKASSERT(!lockowned(ue->ue_lock)); UE_LOCK(ue); return; fail: devfs_clone_bitmap_put(&DEVFS_CLONE_BITMAP(ue), ue->ue_unit); UE_LOCK(ue); return; }