- if (cmd == TIOCEXT) {
- /*
- * When the EXTPROC bit is being toggled, we need
- * to send an TIOCPKT_IOCTL if the packet driver
- * is turned on.
- */
- if (*(int *)data) {
- if (pti->pt_flags & PF_PKT) {
- pti->pt_send |= TIOCPKT_IOCTL;
- ptmx_wakeup(tp, FREAD);
- }
- tp->t_lflag |= EXTPROC;
- } else {
- if ((tp->t_lflag & EXTPROC) &&
- (pti->pt_flags & PF_PKT)) {
- pti->pt_send |= TIOCPKT_IOCTL;
- ptmx_wakeup(tp, FREAD);
- }
- tp->t_lflag &= ~EXTPROC;
- }
- goto out;
- } else
- if (cdevsw[major(dev)].d_open == ptmx_open)
- switch (cmd) {
-
- case TIOCGPGRP:
- /*
- * We aviod calling ttioctl on the controller since,
- * in that case, tp must be the controlling terminal.
- */
- *(int *)data = tp->t_pgrp ? tp->t_pgrp->pg_id : 0;
- goto out;
-
- case TIOCPKT:
- if (*(int *)data) {
- if (pti->pt_flags & PF_UCNTL) {
- error = EINVAL;
- goto out;
- }
- pti->pt_flags |= PF_PKT;
- } else
- pti->pt_flags &= ~PF_PKT;
- goto out;
-
- case TIOCUCNTL:
- if (*(int *)data) {
- if (pti->pt_flags & PF_PKT) {
- error = EINVAL;
- goto out;
- }
- pti->pt_flags |= PF_UCNTL;
- } else
- pti->pt_flags &= ~PF_UCNTL;
- goto out;
-
- case TIOCREMOTE:
- if (*(int *)data)
- pti->pt_flags |= PF_REMOTE;
- else
- pti->pt_flags &= ~PF_REMOTE;
- ttyflush(tp, FREAD|FWRITE);
- goto out;
-
- case TIOCSETP:
- case TIOCSETN:
- case TIOCSETD:
- case TIOCSETA_32:
- case TIOCSETAW_32:
- case TIOCSETAF_32:
- case TIOCSETA_64:
- case TIOCSETAW_64:
- case TIOCSETAF_64:
- ndflush(&tp->t_outq, tp->t_outq.c_cc);
- break;
-
- case TIOCSIG:
- if (*(unsigned int *)data >= NSIG ||
- *(unsigned int *)data == 0) {
- error = EINVAL;
- goto out;
- }
- if ((tp->t_lflag&NOFLSH) == 0)
- ttyflush(tp, FREAD|FWRITE);
- if ((*(unsigned int *)data == SIGINFO) &&
- ((tp->t_lflag&NOKERNINFO) == 0))
- ttyinfo_locked(tp);
- /*
- * SAFE: All callers drop the lock on return and
- * SAFE: the linesw[] will short circut this call
- * SAFE: if the ioctl() is eaten before the lower
- * SAFE: level code gets to see it.
- */
- tty_unlock(tp);
- tty_pgsignal(tp, *(unsigned int *)data, 1);
- tty_lock(tp);
- goto out;
-
- case TIOCPTYGRANT: /* grantpt(3) */
- /*
- * Change the uid of the slave to that of the calling
- * thread, change the gid of the slave to GID_TTY,
- * change the mode to 0620 (rw--w----).
- */
- {
- error = _devfs_setattr(pti->pt_devhandle, 0620, kauth_getuid(), GID_TTY);
- goto out;
- }
-
- case TIOCPTYGNAME: /* ptsname(3) */
- /*
- * Report the name of the slave device in *data
- * (128 bytes max.). Use the same template string
- * used for calling devfs_make_node() to create it.
- */
- snprintf(data, 128, "/dev/" PTSD_TEMPLATE, minor(dev));
- error = 0;
- goto out;
-
- case TIOCPTYUNLK: /* unlockpt(3) */
- /*
- * Unlock the slave device so that it can be opened.
- */
- pti->pt_flags |= PF_UNLOCKED;
- error = 0;
- goto out;
- }
- error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
- if (error == ENOTTY) {
- error = ttioctl_locked(tp, cmd, data, flag, p);
- if (error == ENOTTY) {
- if (pti->pt_flags & PF_UCNTL && (cmd & ~0xff) == UIOCCMD(0)) {
- /* Process the UIOCMD ioctl group */
- if (cmd & 0xff) {
- pti->pt_ucntl = (u_char)cmd;
- ptmx_wakeup(tp, FREAD);
- }
- error = 0;
- goto out;
- } else if (cmd == TIOCSBRK || cmd == TIOCCBRK) {
- /*
- * POSIX conformance; rdar://3936338
- *
- * Clear ENOTTY in the case of setting or
- * clearing a break failing because pty's
- * don't support break like real serial
- * ports.
- */
- error = 0;
- goto out;
- }
- }