Lines Matching defs:tp

180 ttyopen(dev_t device, struct tty *tp, struct proc *p)
185 tp->t_dev = device;
186 if (!ISSET(tp->t_state, TS_ISOPEN)) {
187 SET(tp->t_state, TS_ISOPEN);
188 memset(&tp->t_winsize, 0, sizeof(tp->t_winsize));
189 tp->t_column = 0;
191 CLR(tp->t_state, TS_WOPEN);
202 ttyclose(struct tty *tp)
204 if (constty == tp)
207 ttyflush(tp, FREAD | FWRITE);
209 tp->t_gen++;
210 tp->t_pgrp = NULL;
211 if (tp->t_session)
212 SESSRELE(tp->t_session);
213 tp->t_session = NULL;
214 tp->t_state = 0;
234 ttyinput(int c, struct tty *tp)
241 enqueue_randomness(tp->t_dev << 8 | c);
245 if (!ISSET(tp->t_cflag, CREAD))
251 lflag = tp->t_lflag;
254 ttypend(tp);
261 ++tp->t_cancc;
264 ++tp->t_rawcc;
269 cc = tp->t_cc;
270 iflag = tp->t_iflag;
276 ttyflush(tp, FREAD | FWRITE);
278 pgsignal(tp->t_pgrp, SIGINT, 1);
288 parmrk: (void)putc(0377 | TTY_QUOTE, &tp->t_rawq);
290 (void)putc(0 | TTY_QUOTE, &tp->t_rawq);
291 (void)putc(c | TTY_QUOTE, &tp->t_rawq);
303 if (ISSET(iflag, IXOFF) || ISSET(tp->t_cflag, CHWFLOW))
304 ttyblock(tp);
305 if (!ISSET(tp->t_state, TS_TYPEN) && ISSET(iflag, ISTRIP))
311 if (ISSET(tp->t_state, TS_LNCH)) {
313 CLR(tp->t_state, TS_LNCH);
331 (void)ttyoutput('^', tp);
332 (void)ttyoutput('\b', tp);
334 ttyecho(c, tp);
336 SET(tp->t_state, TS_LNCH);
341 CLR(tp->t_lflag, FLUSHO);
343 ttyflush(tp, FWRITE);
344 ttyecho(c, tp);
345 if (tp->t_rawq.c_cc + tp->t_canq.c_cc)
346 ret = ttyretype(tp);
347 SET(tp->t_lflag, FLUSHO);
358 ttyflush(tp, FREAD | FWRITE);
359 ttyecho(c, tp);
360 pgsignal(tp->t_pgrp,
366 ttyflush(tp, FREAD);
367 ttyecho(c, tp);
368 pgsignal(tp->t_pgrp, SIGTSTP, 1);
377 if (!ISSET(tp->t_state, TS_TTSTOP)) {
378 SET(tp->t_state, TS_TTSTOP);
379 (*cdevsw[major(tp->t_dev)].d_stop)(tp,
404 if (!ISSET(tp->t_lflag, EXTPROC) && ISSET(lflag, ICANON)) {
413 if (ISSET(tp->t_state, TS_BKSL)) {
414 CLR(tp->t_state, TS_BKSL);
434 SET(tp->t_state, TS_BKSL);
446 if (tp->t_rawq.c_cc)
447 ret = ttyrub(unputc(&tp->t_rawq), tp);
455 tp->t_rawq.c_cc == tp->t_rocount &&
457 while (tp->t_rawq.c_cc)
458 if (ttyrub(unputc(&tp->t_rawq), tp))
461 ttyecho(c, tp);
464 ttyecho('\n', tp);
465 FLUSHQ(&tp->t_rawq);
466 tp->t_rocount = 0;
468 CLR(tp->t_state, TS_LOCAL);
481 while ((c = unputc(&tp->t_rawq)) == ' ' || c == '\t')
482 if (ttyrub(c, tp))
490 if (ttyrub(c, tp))
492 c = unputc(&tp->t_rawq);
496 (void)putc(c, &tp->t_rawq);
504 if (ttyrub(c, tp))
506 c = unputc(&tp->t_rawq);
511 (void)putc(c, &tp->t_rawq);
518 ret = ttyretype(tp);
526 pgsignal(tp->t_pgrp, SIGINFO, 1);
528 ttyinfo(tp);
535 if (tp->t_rawq.c_cc + tp->t_canq.c_cc >= TTYHOG(tp)) {
537 if (tp->t_outq.c_cc < tp->t_hiwat)
538 (void)ttyoutput(CTRL('g'), tp);
540 ttyflush(tp, FREAD | FWRITE);
547 if (putc(c, &tp->t_rawq) >= 0) {
549 ttwakeup(tp);
550 ttyecho(c, tp);
554 tp->t_rocount = 0;
555 catq(&tp->t_rawq, &tp->t_canq);
556 ttwakeup(tp);
557 } else if (tp->t_rocount++ == 0)
558 tp->t_rocol = tp->t_column;
559 if (ISSET(tp->t_state, TS_ERASE)) {
563 CLR(tp->t_state, TS_ERASE);
564 (void)ttyoutput('/', tp);
566 i = tp->t_column;
567 ttyecho(c, tp);
572 i = min(2, tp->t_column - i);
574 (void)ttyoutput('\b', tp);
583 if (ISSET(tp->t_state, TS_TTSTOP) &&
587 CLR(tp->t_lflag, FLUSHO);
588 CLR(tp->t_state, TS_TTSTOP);
590 ttstart(tp);
601 ttyoutput(int c, struct tty *tp)
606 oflag = tp->t_oflag;
609 tp->t_outcc++;
610 if (!ISSET(tp->t_lflag, FLUSHO) && putc(c, &tp->t_outq))
622 ISSET(oflag, OXTABS) && !ISSET(tp->t_lflag, EXTPROC)) {
623 c = 8 - (tp->t_column & 7);
624 if (ISSET(tp->t_lflag, FLUSHO)) {
628 notout = b_to_q(" ", c, &tp->t_outq);
631 tp->t_outcc += c;
634 tp->t_column += c;
645 if (c == '\n' && ISSET(tp->t_oflag, ONLCR)) {
647 tp->t_outcc++;
648 if (!ISSET(tp->t_lflag, FLUSHO) && putc('\r', &tp->t_outq))
650 tp->t_column = 0;
652 else if (c == '\r' && ISSET(tp->t_oflag, OCRNL))
655 if (ISSET(tp->t_oflag, OLCUC) && islower(c))
657 else if (ISSET(tp->t_oflag, OLCUC) && ISSET(tp->t_lflag, XCASE)) {
678 tp->t_outcc++;
679 if (putc('\\', &tp->t_outq))
684 if (ISSET(tp->t_oflag, ONOCR) && c == '\r' && tp->t_column == 0)
688 tp->t_outcc++;
689 if (!ISSET(tp->t_lflag, FLUSHO) && putc(c, &tp->t_outq))
692 col = tp->t_column;
701 if (ISSET(tp->t_oflag, ONLRET) || ISSET(tp->t_oflag, OCRNL))
714 tp->t_column = col;
724 ttioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct proc *p)
744 while (isbackground(pr, tp) &&
750 error = ttysleep(tp, &lbolt, TTOPRI | PCATCH,
762 SET(tp->t_state, TS_ASYNC);
764 CLR(tp->t_state, TS_ASYNC);
769 *(int *)data = ttnread(tp);
774 SET(tp->t_state, TS_XCLUDE);
784 ttyflush(tp, flags);
791 if (constty != NULL && constty != tp &&
810 constty = tp;
811 } else if (tp == constty)
816 if ((error = ttywait(tp)) != 0)
822 memcpy(t, &tp->t_termios, sizeof(struct termios));
826 *(int *)data = tp->t_line;
829 *(struct winsize *)data = tp->t_winsize;
833 *(struct timeval *)data = tp->t_tv;
837 if (!isctty(pr, tp) && suser(p))
839 *(int *)data = tp->t_pgrp ? -tp->t_pgrp->pg_id : 0;
842 if (!isctty(pr, tp) && suser(p))
844 *(int *)data = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PID;
847 if (!isctty(pr, tp))
849 *(int *)data = tp->t_session->s_leader->ps_pid;
853 CLR(tp->t_state, TS_XCLUDE);
857 *(int *)data = tp->t_outq.c_cc;
866 if ((error = ttywait(tp)) != 0) {
871 ttyflush(tp, FREAD);
884 if (tp->t_param && (error = (*tp->t_param)(tp, t))) {
888 if (!ISSET(tp->t_state, TS_CARR_ON) &&
889 ISSET(tp->t_cflag, CLOCAL) &&
891 CLR(tp->t_state, TS_ISOPEN);
892 SET(tp->t_state, TS_WOPEN);
893 ttwakeup(tp);
895 tp->t_cflag = t->c_cflag;
896 tp->t_ispeed = t->c_ispeed;
897 tp->t_ospeed = t->c_ospeed;
898 if (t->c_ospeed == 0 && tp->t_session &&
899 tp->t_session->s_leader)
900 prsignal(tp->t_session->s_leader,
903 ttsetwater(tp);
907 ISSET(tp->t_lflag, ICANON)) {
909 SET(tp->t_lflag, PENDIN);
910 ttwakeup(tp);
914 catq(&tp->t_rawq, &tp->t_canq);
915 tq = tp->t_rawq;
916 tp->t_rawq = tp->t_canq;
917 tp->t_canq = tq;
918 CLR(tp->t_lflag, PENDIN);
922 tp->t_iflag = t->c_iflag;
923 tp->t_oflag = t->c_oflag;
927 if (ISSET(tp->t_lflag, EXTPROC))
931 tp->t_lflag = t->c_lflag | ISSET(tp->t_lflag, PENDIN);
932 memcpy(tp->t_cc, t->c_cc, sizeof(t->c_cc));
938 dev_t device = tp->t_dev;
942 if (t != tp->t_line) {
944 (*linesw[tp->t_line].l_close)(tp, flag, p);
945 error = (*linesw[t].l_open)(device, tp, p);
947 (*linesw[tp->t_line].l_open)(device, tp, p);
951 tp->t_line = t;
958 if (ISSET(tp->t_state, TS_TTSTOP) ||
959 ISSET(tp->t_lflag, FLUSHO)) {
960 CLR(tp->t_lflag, FLUSHO);
961 CLR(tp->t_state, TS_TTSTOP);
962 ttstart(tp);
968 if (!ISSET(tp->t_state, TS_TTSTOP)) {
969 SET(tp->t_state, TS_TTSTOP);
970 (*cdevsw[major(tp->t_dev)].d_stop)(tp, 0);
977 ((pr->ps_session->s_ttyvp || tp->t_session) &&
978 (tp->t_session != pr->ps_session)))
980 if (tp->t_session)
981 SESSRELE(tp->t_session);
983 tp->t_session = pr->ps_session;
984 tp->t_pgrp = pr->ps_pgrp;
985 pr->ps_session->s_ttyp = tp;
993 if (!isctty(pr, tp))
1007 tp->t_pgrp = pgrp;
1013 if (!isctty(pr, tp))
1019 tp->t_pgrp = pgrp;
1023 ttyinfo(tp);
1026 if (bcmp((caddr_t)&tp->t_winsize, data,
1028 tp->t_winsize = *(struct winsize *)data;
1029 pgsignal(tp->t_pgrp, SIGWINCH, 1);
1036 CLR(tp->t_flags, TS_TSTAMPDCDSET);
1037 CLR(tp->t_flags, TS_TSTAMPCTSSET);
1038 CLR(tp->t_flags, TS_TSTAMPDCDCLR);
1039 CLR(tp->t_flags, TS_TSTAMPCTSCLR);
1041 SET(tp->t_flags, TS_TSTAMPDCDSET);
1043 SET(tp->t_flags, TS_TSTAMPCTSSET);
1045 SET(tp->t_flags, TS_TSTAMPDCDCLR);
1047 SET(tp->t_flags, TS_TSTAMPCTSCLR);
1081 struct tty *tp = (*cdevsw[major(dev)].d_tty)(dev);
1087 klist = &tp->t_rsel.si_note;
1091 klist = &tp->t_wsel.si_note;
1103 klist = &tp->t_rsel.si_note;
1110 kn->kn_hook = tp;
1122 struct tty *tp = kn->kn_hook;
1126 klist_remove_locked(&tp->t_rsel.si_note, kn);
1133 struct tty *tp = kn->kn_hook;
1137 kn->kn_data = ttnread(tp);
1139 if (!ISSET(tp->t_cflag, CLOCAL) && !ISSET(tp->t_state, TS_CARR_ON)) {
1154 struct tty *tp = kn->kn_hook;
1158 klist_remove_locked(&tp->t_wsel.si_note, kn);
1165 struct tty *tp = kn->kn_hook;
1169 kn->kn_data = tp->t_outq.c_cn - tp->t_outq.c_cc;
1170 active = (tp->t_outq.c_cc <= tp->t_lowat);
1174 if (!ISSET(tp->t_cflag, CLOCAL) &&
1175 !ISSET(tp->t_state, TS_CARR_ON)) {
1189 struct tty *tp = kn->kn_hook;
1195 if (!ISSET(tp->t_cflag, CLOCAL) &&
1196 !ISSET(tp->t_state, TS_CARR_ON)) {
1208 ttnread(struct tty *tp)
1214 if (ISSET(tp->t_lflag, PENDIN))
1215 ttypend(tp);
1216 nread = tp->t_canq.c_cc;
1217 if (!ISSET(tp->t_lflag, ICANON)) {
1218 nread += tp->t_rawq.c_cc;
1219 if (nread < tp->t_cc[VMIN] && !tp->t_cc[VTIME])
1229 ttywait_nsec(struct tty *tp, uint64_t nsecs)
1235 while ((tp->t_outq.c_cc || ISSET(tp->t_state, TS_BUSY)) &&
1236 (ISSET(tp->t_state, TS_CARR_ON) || ISSET(tp->t_cflag, CLOCAL)) &&
1237 tp->t_oproc) {
1238 (*tp->t_oproc)(tp);
1239 if ((tp->t_outq.c_cc || ISSET(tp->t_state, TS_BUSY)) &&
1240 (ISSET(tp->t_state, TS_CARR_ON) || ISSET(tp->t_cflag, CLOCAL))
1241 && tp->t_oproc) {
1242 SET(tp->t_state, TS_ASLEEP);
1243 error = ttysleep_nsec(tp, &tp->t_outq, TTOPRI | PCATCH,
1246 ttyflush(tp, FWRITE);
1257 ttywait(struct tty *tp)
1259 return (ttywait_nsec(tp, INFSLP));
1266 ttywflush(struct tty *tp)
1270 error = ttywait_nsec(tp, SEC_TO_NSEC(5));
1272 ttyflush(tp, FREAD);
1280 ttyflush(struct tty *tp, int rw)
1286 FLUSHQ(&tp->t_canq);
1287 FLUSHQ(&tp->t_rawq);
1288 tp->t_rocount = 0;
1289 tp->t_rocol = 0;
1290 CLR(tp->t_state, TS_LOCAL);
1291 ttyunblock(tp);
1292 ttwakeup(tp);
1295 CLR(tp->t_state, TS_TTSTOP);
1296 (*cdevsw[major(tp->t_dev)].d_stop)(tp, rw);
1297 FLUSHQ(&tp->t_outq);
1298 wakeup((caddr_t)&tp->t_outq);
1299 selwakeup(&tp->t_wsel);
1308 ttychars(struct tty *tp)
1311 memcpy(tp->t_cc, ttydefchars, sizeof(ttydefchars));
1318 ttyblock(struct tty *tp)
1322 total = tp->t_rawq.c_cc + tp->t_canq.c_cc;
1323 if (tp->t_rawq.c_cc > TTYHOG(tp)) {
1324 ttyflush(tp, FREAD | FWRITE);
1325 CLR(tp->t_state, TS_TBLOCK);
1331 if ((total >= TTYHOG(tp) / 2 &&
1332 !ISSET(tp->t_state, TS_TBLOCK) &&
1333 !ISSET(tp->t_lflag, ICANON)) || tp->t_canq.c_cc > 0) {
1334 if (ISSET(tp->t_iflag, IXOFF) &&
1335 tp->t_cc[VSTOP] != _POSIX_VDISABLE &&
1336 putc(tp->t_cc[VSTOP], &tp->t_outq) == 0) {
1337 SET(tp->t_state, TS_TBLOCK);
1338 ttstart(tp);
1341 if (ISSET(tp->t_cflag, CHWFLOW) && tp->t_hwiflow &&
1342 (*tp->t_hwiflow)(tp, 1) != 0)
1343 SET(tp->t_state, TS_TBLOCK);
1350 struct tty *tp = (struct tty *)arg;
1354 if (tp == NULL)
1358 CLR(tp->t_state, TS_TIMEOUT);
1359 ttstart(tp);
1364 ttstart(struct tty *tp)
1367 if (tp->t_oproc != NULL) /* XXX: Kludge for pty. */
1368 (*tp->t_oproc)(tp);
1376 ttylclose(struct tty *tp, int flag, struct proc *p)
1380 ttyflush(tp, FREAD | FWRITE);
1382 ttywflush(tp);
1392 ttymodem(struct tty *tp, int flag)
1395 if (!ISSET(tp->t_state, TS_WOPEN) && ISSET(tp->t_cflag, MDMBUF)) {
1400 CLR(tp->t_state, TS_TTSTOP);
1401 ttstart(tp);
1402 } else if (!ISSET(tp->t_state, TS_TTSTOP)) {
1403 SET(tp->t_state, TS_TTSTOP);
1404 (*cdevsw[major(tp->t_dev)].d_stop)(tp, 0);
1410 CLR(tp->t_state, TS_CARR_ON);
1411 if (ISSET(tp->t_state, TS_ISOPEN) &&
1412 !ISSET(tp->t_cflag, CLOCAL)) {
1413 if (tp->t_session && tp->t_session->s_leader)
1414 prsignal(tp->t_session->s_leader, SIGHUP);
1415 ttyflush(tp, FREAD | FWRITE);
1422 SET(tp->t_state, TS_CARR_ON);
1423 ttwakeup(tp);
1433 nullmodem(struct tty *tp, int flag)
1437 SET(tp->t_state, TS_CARR_ON);
1439 CLR(tp->t_state, TS_CARR_ON);
1440 if (ISSET(tp->t_state, TS_ISOPEN) &&
1441 !ISSET(tp->t_cflag, CLOCAL)) {
1442 if (tp->t_session && tp->t_session->s_leader)
1443 prsignal(tp->t_session->s_leader, SIGHUP);
1444 ttyflush(tp, FREAD | FWRITE);
1456 ttypend(struct tty *tp)
1463 CLR(tp->t_lflag, PENDIN);
1464 SET(tp->t_state, TS_TYPEN);
1465 tq = tp->t_rawq;
1466 tp->t_rawq.c_cc = 0;
1467 tp->t_rawq.c_cf = tp->t_rawq.c_cl = NULL;
1469 ttyinput(c, tp);
1470 CLR(tp->t_state, TS_TYPEN);
1478 struct tty *tp = (struct tty *)arg;
1480 wakeup(&tp->t_rawq);
1487 ttread(struct tty *tp, struct uio *uio, int flag)
1493 u_char *cc = tp->t_cc;
1499 loop: lflag = tp->t_lflag;
1505 ttypend(tp);
1511 if (isbackground(pr, tp)) {
1518 error = ttysleep(tp, &lbolt, TTIPRI | PCATCH, ttybg);
1529 qp = &tp->t_rawq;
1549 timeout_set(stime, ttvtimeout, tp);
1566 } else if ((qp = &tp->t_canq)->c_cc <= 0) {
1575 carrier = ISSET(tp->t_state, TS_CARR_ON) ||
1576 ISSET(tp->t_cflag, CLOCAL);
1577 if (!carrier && ISSET(tp->t_state, TS_ISOPEN)) {
1587 error = ttysleep(tp, &tp->t_rawq, TTIPRI | PCATCH,
1614 pgsignal(tp->t_pgrp, SIGTSTP, 1);
1616 error = ttysleep(tp, &lbolt, TTIPRI | PCATCH,
1650 if (tp->t_rawq.c_cc < TTYHOG(tp)/5)
1651 ttyunblock(tp);
1664 ttyunblock(struct tty *tp)
1666 u_char *cc = tp->t_cc;
1670 if (ISSET(tp->t_state, TS_TBLOCK)) {
1671 if (ISSET(tp->t_iflag, IXOFF) &&
1673 putc(cc[VSTART], &tp->t_outq) == 0) {
1674 CLR(tp->t_state, TS_TBLOCK);
1675 ttstart(tp);
1678 if (ISSET(tp->t_cflag, CHWFLOW) && tp->t_hwiflow &&
1679 (*tp->t_hwiflow)(tp, 0) != 0)
1680 CLR(tp->t_state, TS_TBLOCK);
1685 * Check the output queue on tp for space for a kernel message (from uprintf
1692 ttycheckoutq(struct tty *tp, int wait)
1696 hiwat = tp->t_hiwat;
1699 if (tp->t_outq.c_cc > hiwat + TTHIWATMINSPACE)
1700 while (tp->t_outq.c_cc > hiwat) {
1701 ttstart(tp);
1706 SET(tp->t_state, TS_ASLEEP);
1707 tsleep_nsec(&tp->t_outq, PZERO - 1, "ttckoutq",
1718 ttwrite(struct tty *tp, struct uio *uio, int flag)
1728 hiwat = tp->t_hiwat;
1734 if (!ISSET(tp->t_state, TS_CARR_ON) &&
1735 !ISSET(tp->t_cflag, CLOCAL)) {
1736 if (ISSET(tp->t_state, TS_ISOPEN)) {
1746 error = ttysleep(tp,
1747 &tp->t_rawq, TTIPRI | PCATCH, ttopen);
1760 if (isbackground(pr, tp) &&
1761 ISSET(tp->t_lflag, TOSTOP) && (pr->ps_flags & PS_PPWAIT) == 0 &&
1768 error = ttysleep(tp, &lbolt, TTIPRI | PCATCH, ttybg);
1779 if (ISSET(tp->t_lflag, FLUSHO)) {
1783 if (tp->t_outq.c_cc > hiwat)
1802 cn_tab->cn_dev == tp->t_dev && tp->t_gen == 0) {
1822 if (!ISSET(tp->t_oflag, OPOST))
1832 tp->t_rocount = 0;
1833 if (ttyoutput(*cp, tp) >= 0) {
1839 if (ISSET(tp->t_lflag, FLUSHO) ||
1840 tp->t_outq.c_cc > hiwat)
1853 tp->t_rocount = 0;
1854 i = b_to_q(cp, ce, &tp->t_outq);
1856 tp->t_column += ce;
1858 tp->t_outcc += ce;
1863 if (ISSET(tp->t_lflag, FLUSHO) ||
1864 tp->t_outq.c_cc > hiwat)
1867 ttstart(tp);
1882 ttstart(tp);
1888 if (tp->t_outq.c_cc <= hiwat) {
1899 SET(tp->t_state, TS_ASLEEP);
1900 error = ttysleep(tp, &tp->t_outq, TTOPRI | PCATCH, ttyout);
1908 * Rubout one character from the rawq of tp
1912 ttyrub(int c, struct tty *tp)
1918 if (!ISSET(tp->t_lflag, ECHO) || ISSET(tp->t_lflag, EXTPROC))
1920 CLR(tp->t_lflag, FLUSHO);
1921 if (ISSET(tp->t_lflag, ECHOE)) {
1922 if (tp->t_rocount == 0) {
1926 return ttyretype(tp);
1929 ttyrubo(tp, 2);
1934 ttyrubo(tp, 1);
1941 if (ISSET(tp->t_lflag, ECHOCTL))
1942 ttyrubo(tp, 2);
1945 if (tp->t_rocount < tp->t_rawq.c_cc)
1946 return ttyretype(tp);
1948 savecol = tp->t_column;
1949 SET(tp->t_state, TS_CNTTB);
1950 SET(tp->t_lflag, FLUSHO);
1951 tp->t_column = tp->t_rocol;
1952 for (cp = firstc(&tp->t_rawq, &tabc, &cc); cp;
1953 cp = nextc(&tp->t_rawq, cp, &tabc, &cc))
1954 ttyecho(tabc, tp);
1955 CLR(tp->t_lflag, FLUSHO);
1956 CLR(tp->t_state, TS_CNTTB);
1960 savecol -= tp->t_column;
1961 tp->t_column += savecol;
1965 (void)ttyoutput('\b', tp);
1975 } else if (ISSET(tp->t_lflag, ECHOPRT)) {
1976 if (!ISSET(tp->t_state, TS_ERASE)) {
1977 SET(tp->t_state, TS_ERASE);
1978 (void)ttyoutput('\\', tp);
1980 ttyecho(c, tp);
1982 ttyecho(tp->t_cc[VERASE], tp);
1983 --tp->t_rocount;
1991 ttyrubo(struct tty *tp, int cnt)
1995 (void)ttyoutput('\b', tp);
1996 (void)ttyoutput(' ', tp);
1997 (void)ttyoutput('\b', tp);
2007 ttyretype(struct tty *tp)
2013 if (tp->t_cc[VREPRINT] != _POSIX_VDISABLE)
2014 ttyecho(tp->t_cc[VREPRINT], tp);
2016 (void)ttyoutput('\n', tp);
2019 for (cp = firstc(&tp->t_canq, &c, &cc); cp;
2020 cp = nextc(&tp->t_canq, cp, &c, &cc))
2021 ttyecho(c, tp);
2022 for (cp = firstc(&tp->t_rawq, &c, &cc); cp;
2023 cp = nextc(&tp->t_rawq, cp, &c, &cc))
2024 ttyecho(c, tp);
2025 CLR(tp->t_state, TS_ERASE);
2028 tp->t_rocount = tp->t_rawq.c_cc;
2029 tp->t_rocol = 0;
2037 ttyecho(int c, struct tty *tp)
2040 if (!ISSET(tp->t_state, TS_CNTTB))
2041 CLR(tp->t_lflag, FLUSHO);
2042 if ((!ISSET(tp->t_lflag, ECHO) &&
2043 (!ISSET(tp->t_lflag, ECHONL) || c != '\n')) ||
2044 ISSET(tp->t_lflag, EXTPROC))
2046 if (((ISSET(tp->t_lflag, ECHOCTL) &&
2049 (void)ttyoutput('^', tp);
2056 (void)ttyoutput(c, tp);
2063 ttwakeupwr(struct tty *tp)
2066 if (tp->t_outq.c_cc <= tp->t_lowat) {
2067 if (ISSET(tp->t_state, TS_ASLEEP)) {
2068 CLR(tp->t_state, TS_ASLEEP);
2069 wakeup(&tp->t_outq);
2071 selwakeup(&tp->t_wsel);
2079 ttwakeup(struct tty *tp)
2082 selwakeup(&tp->t_rsel);
2083 if (ISSET(tp->t_state, TS_ASYNC))
2084 pgsignal(tp->t_pgrp, SIGIO, 1);
2085 wakeup((caddr_t)&tp->t_rawq);
2109 ttsetwater(struct tty *tp)
2115 cps = tp->t_ospeed / 10;
2116 tp->t_lowat = x = CLAMP(cps / 2, TTMAXLOWAT, TTMINLOWAT);
2118 tp->t_hiwat = CLAMP(x, tp->t_outq.c_cn - TTHIWATMINSPACE, TTMINHIWAT);
2149 ttyinfo(struct tty *tp)
2157 if (ttycheckoutq(tp,0) == 0)
2162 ttyprintf(tp, "load: %d.%02d ", tmp / 100, tmp % 100);
2164 if (tp->t_session == NULL)
2165 ttyprintf(tp, "not a controlling terminal\n");
2166 else if (tp->t_pgrp == NULL)
2167 ttyprintf(tp, "no foreground process group\n");
2168 else if ((pr = LIST_FIRST(&tp->t_pgrp->pg_members)) == NULL)
2169 empty: ttyprintf(tp, "empty foreground process group\n");
2273 ttyprintf(tp,
2280 tp->t_rocount = 0; /* so pending input will be retyped if BS */
2287 tputchar(int c, struct tty *tp)
2292 if (ISSET(tp->t_state, TS_ISOPEN) == 0 ||
2293 !(ISSET(tp->t_state, TS_CARR_ON) || ISSET(tp->t_cflag, CLOCAL))) {
2298 (void)ttyoutput('\r', tp);
2299 (void)ttyoutput(c, tp);
2300 ttstart(tp);
2312 ttysleep(struct tty *tp, void *chan, int pri, char *wmesg)
2314 return (ttysleep_nsec(tp, chan, pri, wmesg, INFSLP));
2318 ttysleep_nsec(struct tty *tp, void *chan, int pri, char *wmesg, uint64_t nsecs)
2323 gen = tp->t_gen;
2326 return (tp->t_gen == gen ? 0 : ERESTART);
2347 struct tty *tp;
2349 tp = malloc(sizeof(struct tty), M_TTYS, M_WAITOK|M_ZERO);
2355 tp->t_qlen = 1024;
2357 tp->t_qlen = 4096;
2359 tp->t_qlen = 8192;
2360 clalloc(&tp->t_rawq, tp->t_qlen, 1);
2361 clalloc(&tp->t_canq, tp->t_qlen, 1);
2363 clalloc(&tp->t_outq, tp->t_qlen, 0);
2366 TAILQ_INSERT_TAIL(&ttylist, tp, tty_link);
2370 timeout_set(&tp->t_rstrt_to, ttrstrt, tp);
2372 return(tp);
2380 ttyfree(struct tty *tp)
2390 TAILQ_REMOVE(&ttylist, tp, tty_link);
2394 klist_invalidate(&tp->t_rsel.si_note);
2395 klist_invalidate(&tp->t_wsel.si_note);
2398 clfree(&tp->t_rawq);
2399 clfree(&tp->t_canq);
2400 clfree(&tp->t_outq);
2401 free(tp, M_TTYS, sizeof(*tp));
2409 struct tty *tp;
2417 for (tp = TAILQ_FIRST(&ttylist), itp = *ttystats; tp && ntty++ < ttyc;
2418 tp = TAILQ_NEXT(tp, tty_link), itp++) {
2419 itp->t_dev = tp->t_dev;
2420 itp->t_rawq_c_cc = tp->t_rawq.c_cc;
2421 itp->t_canq_c_cc = tp->t_canq.c_cc;
2422 itp->t_outq_c_cc = tp->t_outq.c_cc;
2423 itp->t_hiwat = tp->t_hiwat;
2424 itp->t_lowat = tp->t_lowat;
2425 if (ISSET(tp->t_oflag, OPOST))
2426 itp->t_column = tp->t_column;
2427 itp->t_state = tp->t_state;
2428 itp->t_session = tp->t_session;
2429 if (tp->t_pgrp)
2430 itp->t_pgrp_pg_id = tp->t_pgrp->pg_id;
2433 itp->t_line = tp->t_line;
2483 ttytstamp(struct tty *tp, int octs, int ncts, int odcd, int ndcd)
2488 doit |= ncts ? ISSET(tp->t_flags, TS_TSTAMPCTSSET) :
2489 ISSET(tp->t_flags, TS_TSTAMPCTSCLR);
2491 doit |= ndcd ? ISSET(tp->t_flags, TS_TSTAMPDCDSET) :
2492 ISSET(tp->t_flags, TS_TSTAMPDCDCLR);
2495 microtime(&tp->t_tv);