Lines Matching refs:tty

162 static void zero_buffer(struct tty_struct *tty, u8 *buffer, int size)  in zero_buffer()  argument
164 bool icanon = !!L_ICANON(tty); in zero_buffer()
165 bool no_echo = !L_ECHO(tty); in zero_buffer()
171 static void tty_copy(struct tty_struct *tty, void *to, size_t tail, size_t n) in tty_copy() argument
173 struct n_tty_data *ldata = tty->disc_data; in tty_copy()
178 tty_audit_add_data(tty, from, size); in tty_copy()
180 zero_buffer(tty, from, size); in tty_copy()
186 tty_audit_add_data(tty, from, n); in tty_copy()
188 zero_buffer(tty, from, n); in tty_copy()
202 static void n_tty_kick_worker(struct tty_struct *tty) in n_tty_kick_worker() argument
204 struct n_tty_data *ldata = tty->disc_data; in n_tty_kick_worker()
210 WARN_RATELIMIT(tty->port->itty == NULL, in n_tty_kick_worker()
216 WARN_RATELIMIT(test_bit(TTY_LDISC_HALTED, &tty->flags), in n_tty_kick_worker()
218 tty_buffer_restart_work(tty->port); in n_tty_kick_worker()
222 static ssize_t chars_in_buffer(struct tty_struct *tty) in chars_in_buffer() argument
224 struct n_tty_data *ldata = tty->disc_data; in chars_in_buffer()
241 static void n_tty_write_wakeup(struct tty_struct *tty) in n_tty_write_wakeup() argument
243 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in n_tty_write_wakeup()
244 kill_fasync(&tty->fasync, SIGIO, POLL_OUT); in n_tty_write_wakeup()
247 static void n_tty_check_throttle(struct tty_struct *tty) in n_tty_check_throttle() argument
249 struct n_tty_data *ldata = tty->disc_data; in n_tty_check_throttle()
261 tty_set_flow_change(tty, TTY_THROTTLE_SAFE); in n_tty_check_throttle()
264 throttled = tty_throttle_safe(tty); in n_tty_check_throttle()
268 __tty_set_flow_change(tty, 0); in n_tty_check_throttle()
271 static void n_tty_check_unthrottle(struct tty_struct *tty) in n_tty_check_unthrottle() argument
273 if (tty->driver->type == TTY_DRIVER_TYPE_PTY) { in n_tty_check_unthrottle()
274 if (chars_in_buffer(tty) > TTY_THRESHOLD_UNTHROTTLE) in n_tty_check_unthrottle()
276 n_tty_kick_worker(tty); in n_tty_check_unthrottle()
277 tty_wakeup(tty->link); in n_tty_check_unthrottle()
291 tty_set_flow_change(tty, TTY_UNTHROTTLE_SAFE); in n_tty_check_unthrottle()
292 if (chars_in_buffer(tty) > TTY_THRESHOLD_UNTHROTTLE) in n_tty_check_unthrottle()
294 n_tty_kick_worker(tty); in n_tty_check_unthrottle()
295 unthrottled = tty_unthrottle_safe(tty); in n_tty_check_unthrottle()
299 __tty_set_flow_change(tty, 0); in n_tty_check_unthrottle()
343 static void n_tty_packet_mode_flush(struct tty_struct *tty) in n_tty_packet_mode_flush() argument
347 if (tty->link->ctrl.packet) { in n_tty_packet_mode_flush()
348 spin_lock_irqsave(&tty->ctrl.lock, flags); in n_tty_packet_mode_flush()
349 tty->ctrl.pktstatus |= TIOCPKT_FLUSHREAD; in n_tty_packet_mode_flush()
350 spin_unlock_irqrestore(&tty->ctrl.lock, flags); in n_tty_packet_mode_flush()
351 wake_up_interruptible(&tty->link->read_wait); in n_tty_packet_mode_flush()
368 static void n_tty_flush_buffer(struct tty_struct *tty) in n_tty_flush_buffer() argument
370 down_write(&tty->termios_rwsem); in n_tty_flush_buffer()
371 reset_buffer_flags(tty->disc_data); in n_tty_flush_buffer()
372 n_tty_kick_worker(tty); in n_tty_flush_buffer()
374 if (tty->link) in n_tty_flush_buffer()
375 n_tty_packet_mode_flush(tty); in n_tty_flush_buffer()
376 up_write(&tty->termios_rwsem); in n_tty_flush_buffer()
400 static inline int is_continuation(unsigned char c, struct tty_struct *tty) in is_continuation() argument
402 return I_IUTF8(tty) && is_utf8_continuation(c); in is_continuation()
424 static int do_output_char(unsigned char c, struct tty_struct *tty, int space) in do_output_char() argument
426 struct n_tty_data *ldata = tty->disc_data; in do_output_char()
434 if (O_ONLRET(tty)) in do_output_char()
436 if (O_ONLCR(tty)) { in do_output_char()
440 tty->ops->write(tty, "\r\n", 2); in do_output_char()
446 if (O_ONOCR(tty) && ldata->column == 0) in do_output_char()
448 if (O_OCRNL(tty)) { in do_output_char()
450 if (O_ONLRET(tty)) in do_output_char()
458 if (O_TABDLY(tty) == XTABS) { in do_output_char()
462 tty->ops->write(tty, " ", spaces); in do_output_char()
473 if (O_OLCUC(tty)) in do_output_char()
475 if (!is_continuation(c, tty)) in do_output_char()
481 tty_put_char(tty, c); in do_output_char()
498 static int process_output(unsigned char c, struct tty_struct *tty) in process_output() argument
500 struct n_tty_data *ldata = tty->disc_data; in process_output()
505 space = tty_write_room(tty); in process_output()
506 retval = do_output_char(c, tty, space); in process_output()
533 static ssize_t process_output_block(struct tty_struct *tty, in process_output_block() argument
536 struct n_tty_data *ldata = tty->disc_data; in process_output_block()
543 space = tty_write_room(tty); in process_output_block()
556 if (O_ONLRET(tty)) in process_output_block()
558 if (O_ONLCR(tty)) in process_output_block()
563 if (O_ONOCR(tty) && ldata->column == 0) in process_output_block()
565 if (O_OCRNL(tty)) in process_output_block()
577 if (O_OLCUC(tty)) in process_output_block()
579 if (!is_continuation(c, tty)) in process_output_block()
586 i = tty->ops->write(tty, buf, i); in process_output_block()
614 static size_t __process_echoes(struct tty_struct *tty) in __process_echoes() argument
616 struct n_tty_data *ldata = tty->disc_data; in __process_echoes()
621 old_space = space = tty_write_room(tty); in __process_echoes()
672 tty_put_char(tty, '\b'); in __process_echoes()
696 tty_put_char(tty, ECHO_OP_START); in __process_echoes()
716 tty_put_char(tty, '^'); in __process_echoes()
717 tty_put_char(tty, op ^ 0100); in __process_echoes()
726 if (O_OPOST(tty)) { in __process_echoes()
727 int retval = do_output_char(c, tty, space); in __process_echoes()
734 tty_put_char(tty, c); in __process_echoes()
760 static void commit_echoes(struct tty_struct *tty) in commit_echoes() argument
762 struct n_tty_data *ldata = tty->disc_data; in commit_echoes()
782 echoed = __process_echoes(tty); in commit_echoes()
785 if (echoed && tty->ops->flush_chars) in commit_echoes()
786 tty->ops->flush_chars(tty); in commit_echoes()
789 static void process_echoes(struct tty_struct *tty) in process_echoes() argument
791 struct n_tty_data *ldata = tty->disc_data; in process_echoes()
799 echoed = __process_echoes(tty); in process_echoes()
802 if (echoed && tty->ops->flush_chars) in process_echoes()
803 tty->ops->flush_chars(tty); in process_echoes()
807 static void flush_echoes(struct tty_struct *tty) in flush_echoes() argument
809 struct n_tty_data *ldata = tty->disc_data; in flush_echoes()
811 if ((!L_ECHO(tty) && !L_ECHONL(tty)) || in flush_echoes()
817 __process_echoes(tty); in flush_echoes()
920 static void echo_char(unsigned char c, struct tty_struct *tty) in echo_char() argument
922 struct n_tty_data *ldata = tty->disc_data; in echo_char()
928 if (L_ECHOCTL(tty) && iscntrl(c) && c != '\t') in echo_char()
958 static void eraser(unsigned char c, struct tty_struct *tty) in eraser() argument
960 struct n_tty_data *ldata = tty->disc_data; in eraser()
970 if (c == ERASE_CHAR(tty)) in eraser()
972 else if (c == WERASE_CHAR(tty)) in eraser()
975 if (!L_ECHO(tty)) { in eraser()
979 if (!L_ECHOK(tty) || !L_ECHOKE(tty) || !L_ECHOE(tty)) { in eraser()
982 echo_char(KILL_CHAR(tty), tty); in eraser()
984 if (L_ECHOK(tty)) in eraser()
999 } while (is_continuation(c, tty) && in eraser()
1003 if (is_continuation(c, tty)) in eraser()
1015 if (L_ECHO(tty)) { in eraser()
1016 if (L_ECHOPRT(tty)) { in eraser()
1022 echo_char(c, tty); in eraser()
1028 } else if (kill_type == ERASE && !L_ECHOE(tty)) { in eraser()
1029 echo_char(ERASE_CHAR(tty), tty); in eraser()
1049 if (L_ECHOCTL(tty)) in eraser()
1051 } else if (!is_continuation(c, tty)) { in eraser()
1057 if (iscntrl(c) && L_ECHOCTL(tty)) { in eraser()
1062 if (!iscntrl(c) || L_ECHOCTL(tty)) { in eraser()
1072 if (ldata->read_head == ldata->canon_head && L_ECHO(tty)) in eraser()
1077 static void __isig(int sig, struct tty_struct *tty) in __isig() argument
1079 struct pid *tty_pgrp = tty_get_pgrp(tty); in __isig()
1100 static void isig(int sig, struct tty_struct *tty) in isig() argument
1102 struct n_tty_data *ldata = tty->disc_data; in isig()
1104 if (L_NOFLSH(tty)) { in isig()
1106 __isig(sig, tty); in isig()
1109 up_read(&tty->termios_rwsem); in isig()
1110 down_write(&tty->termios_rwsem); in isig()
1112 __isig(sig, tty); in isig()
1121 tty_driver_flush_buffer(tty); in isig()
1124 reset_buffer_flags(tty->disc_data); in isig()
1127 if (tty->link) in isig()
1128 n_tty_packet_mode_flush(tty); in isig()
1130 up_write(&tty->termios_rwsem); in isig()
1131 down_read(&tty->termios_rwsem); in isig()
1147 static void n_tty_receive_break(struct tty_struct *tty) in n_tty_receive_break() argument
1149 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_break()
1151 if (I_IGNBRK(tty)) in n_tty_receive_break()
1153 if (I_BRKINT(tty)) { in n_tty_receive_break()
1154 isig(SIGINT, tty); in n_tty_receive_break()
1157 if (I_PARMRK(tty)) { in n_tty_receive_break()
1174 static void n_tty_receive_overrun(struct tty_struct *tty) in n_tty_receive_overrun() argument
1176 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_overrun()
1181 tty_warn(tty, "%d input overrun(s)\n", ldata->num_overrun); in n_tty_receive_overrun()
1198 static void n_tty_receive_parity_error(struct tty_struct *tty, unsigned char c) in n_tty_receive_parity_error() argument
1200 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_parity_error()
1202 if (I_INPCK(tty)) { in n_tty_receive_parity_error()
1203 if (I_IGNPAR(tty)) in n_tty_receive_parity_error()
1205 if (I_PARMRK(tty)) { in n_tty_receive_parity_error()
1216 n_tty_receive_signal_char(struct tty_struct *tty, int signal, unsigned char c) in n_tty_receive_signal_char() argument
1218 isig(signal, tty); in n_tty_receive_signal_char()
1219 if (I_IXON(tty)) in n_tty_receive_signal_char()
1220 start_tty(tty); in n_tty_receive_signal_char()
1221 if (L_ECHO(tty)) { in n_tty_receive_signal_char()
1222 echo_char(c, tty); in n_tty_receive_signal_char()
1223 commit_echoes(tty); in n_tty_receive_signal_char()
1225 process_echoes(tty); in n_tty_receive_signal_char()
1228 static bool n_tty_is_char_flow_ctrl(struct tty_struct *tty, unsigned char c) in n_tty_is_char_flow_ctrl() argument
1230 return c == START_CHAR(tty) || c == STOP_CHAR(tty); in n_tty_is_char_flow_ctrl()
1248 static bool n_tty_receive_char_flow_ctrl(struct tty_struct *tty, unsigned char c, in n_tty_receive_char_flow_ctrl() argument
1251 if (!n_tty_is_char_flow_ctrl(tty, c)) in n_tty_receive_char_flow_ctrl()
1257 if (c == START_CHAR(tty)) { in n_tty_receive_char_flow_ctrl()
1258 start_tty(tty); in n_tty_receive_char_flow_ctrl()
1259 process_echoes(tty); in n_tty_receive_char_flow_ctrl()
1264 stop_tty(tty); in n_tty_receive_char_flow_ctrl()
1268 static void n_tty_receive_char_special(struct tty_struct *tty, unsigned char c, in n_tty_receive_char_special() argument
1271 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_char_special()
1273 if (I_IXON(tty) && n_tty_receive_char_flow_ctrl(tty, c, lookahead_done)) in n_tty_receive_char_special()
1276 if (L_ISIG(tty)) { in n_tty_receive_char_special()
1277 if (c == INTR_CHAR(tty)) { in n_tty_receive_char_special()
1278 n_tty_receive_signal_char(tty, SIGINT, c); in n_tty_receive_char_special()
1280 } else if (c == QUIT_CHAR(tty)) { in n_tty_receive_char_special()
1281 n_tty_receive_signal_char(tty, SIGQUIT, c); in n_tty_receive_char_special()
1283 } else if (c == SUSP_CHAR(tty)) { in n_tty_receive_char_special()
1284 n_tty_receive_signal_char(tty, SIGTSTP, c); in n_tty_receive_char_special()
1289 if (tty->flow.stopped && !tty->flow.tco_stopped && I_IXON(tty) && I_IXANY(tty)) { in n_tty_receive_char_special()
1290 start_tty(tty); in n_tty_receive_char_special()
1291 process_echoes(tty); in n_tty_receive_char_special()
1295 if (I_IGNCR(tty)) in n_tty_receive_char_special()
1297 if (I_ICRNL(tty)) in n_tty_receive_char_special()
1299 } else if (c == '\n' && I_INLCR(tty)) in n_tty_receive_char_special()
1303 if (c == ERASE_CHAR(tty) || c == KILL_CHAR(tty) || in n_tty_receive_char_special()
1304 (c == WERASE_CHAR(tty) && L_IEXTEN(tty))) { in n_tty_receive_char_special()
1305 eraser(c, tty); in n_tty_receive_char_special()
1306 commit_echoes(tty); in n_tty_receive_char_special()
1309 if (c == LNEXT_CHAR(tty) && L_IEXTEN(tty)) { in n_tty_receive_char_special()
1311 if (L_ECHO(tty)) { in n_tty_receive_char_special()
1313 if (L_ECHOCTL(tty)) { in n_tty_receive_char_special()
1316 commit_echoes(tty); in n_tty_receive_char_special()
1321 if (c == REPRINT_CHAR(tty) && L_ECHO(tty) && L_IEXTEN(tty)) { in n_tty_receive_char_special()
1325 echo_char(c, tty); in n_tty_receive_char_special()
1328 echo_char(read_buf(ldata, tail), tty); in n_tty_receive_char_special()
1331 commit_echoes(tty); in n_tty_receive_char_special()
1335 if (L_ECHO(tty) || L_ECHONL(tty)) { in n_tty_receive_char_special()
1337 commit_echoes(tty); in n_tty_receive_char_special()
1341 if (c == EOF_CHAR(tty)) { in n_tty_receive_char_special()
1345 if ((c == EOL_CHAR(tty)) || in n_tty_receive_char_special()
1346 (c == EOL2_CHAR(tty) && L_IEXTEN(tty))) { in n_tty_receive_char_special()
1350 if (L_ECHO(tty)) { in n_tty_receive_char_special()
1354 echo_char(c, tty); in n_tty_receive_char_special()
1355 commit_echoes(tty); in n_tty_receive_char_special()
1361 if (c == (unsigned char) '\377' && I_PARMRK(tty)) in n_tty_receive_char_special()
1368 kill_fasync(&tty->fasync, SIGIO, POLL_IN); in n_tty_receive_char_special()
1369 wake_up_interruptible_poll(&tty->read_wait, EPOLLIN | EPOLLRDNORM); in n_tty_receive_char_special()
1374 if (L_ECHO(tty)) { in n_tty_receive_char_special()
1382 echo_char(c, tty); in n_tty_receive_char_special()
1384 commit_echoes(tty); in n_tty_receive_char_special()
1388 if (c == (unsigned char) '\377' && I_PARMRK(tty)) in n_tty_receive_char_special()
1406 static void n_tty_receive_char(struct tty_struct *tty, unsigned char c) in n_tty_receive_char() argument
1408 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_char()
1410 if (tty->flow.stopped && !tty->flow.tco_stopped && I_IXON(tty) && I_IXANY(tty)) { in n_tty_receive_char()
1411 start_tty(tty); in n_tty_receive_char()
1412 process_echoes(tty); in n_tty_receive_char()
1414 if (L_ECHO(tty)) { in n_tty_receive_char()
1419 echo_char(c, tty); in n_tty_receive_char()
1420 commit_echoes(tty); in n_tty_receive_char()
1423 if (c == (unsigned char) '\377' && I_PARMRK(tty)) in n_tty_receive_char()
1428 static void n_tty_receive_char_closing(struct tty_struct *tty, unsigned char c, in n_tty_receive_char_closing() argument
1431 if (I_ISTRIP(tty)) in n_tty_receive_char_closing()
1433 if (I_IUCLC(tty) && L_IEXTEN(tty)) in n_tty_receive_char_closing()
1436 if (I_IXON(tty)) { in n_tty_receive_char_closing()
1437 if (!n_tty_receive_char_flow_ctrl(tty, c, lookahead_done) && in n_tty_receive_char_closing()
1438 tty->flow.stopped && !tty->flow.tco_stopped && I_IXANY(tty) && in n_tty_receive_char_closing()
1439 c != INTR_CHAR(tty) && c != QUIT_CHAR(tty) && in n_tty_receive_char_closing()
1440 c != SUSP_CHAR(tty)) { in n_tty_receive_char_closing()
1441 start_tty(tty); in n_tty_receive_char_closing()
1442 process_echoes(tty); in n_tty_receive_char_closing()
1448 n_tty_receive_char_flagged(struct tty_struct *tty, unsigned char c, char flag) in n_tty_receive_char_flagged() argument
1452 n_tty_receive_break(tty); in n_tty_receive_char_flagged()
1456 n_tty_receive_parity_error(tty, c); in n_tty_receive_char_flagged()
1459 n_tty_receive_overrun(tty); in n_tty_receive_char_flagged()
1462 tty_err(tty, "unknown flag %d\n", flag); in n_tty_receive_char_flagged()
1468 n_tty_receive_char_lnext(struct tty_struct *tty, unsigned char c, char flag) in n_tty_receive_char_lnext() argument
1470 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_char_lnext()
1474 if (I_ISTRIP(tty)) in n_tty_receive_char_lnext()
1476 if (I_IUCLC(tty) && L_IEXTEN(tty)) in n_tty_receive_char_lnext()
1478 n_tty_receive_char(tty, c); in n_tty_receive_char_lnext()
1480 n_tty_receive_char_flagged(tty, c, flag); in n_tty_receive_char_lnext()
1484 static void n_tty_lookahead_flow_ctrl(struct tty_struct *tty, const unsigned char *cp, in n_tty_lookahead_flow_ctrl() argument
1487 struct n_tty_data *ldata = tty->disc_data; in n_tty_lookahead_flow_ctrl()
1492 if (!I_IXON(tty)) in n_tty_lookahead_flow_ctrl()
1499 n_tty_receive_char_flow_ctrl(tty, *cp, false); in n_tty_lookahead_flow_ctrl()
1505 n_tty_receive_buf_real_raw(struct tty_struct *tty, const unsigned char *cp, in n_tty_receive_buf_real_raw() argument
1508 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_real_raw()
1525 n_tty_receive_buf_raw(struct tty_struct *tty, const unsigned char *cp, in n_tty_receive_buf_raw() argument
1528 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_raw()
1537 n_tty_receive_char_flagged(tty, *cp++, flag); in n_tty_receive_buf_raw()
1542 n_tty_receive_buf_closing(struct tty_struct *tty, const unsigned char *cp, in n_tty_receive_buf_closing() argument
1551 n_tty_receive_char_closing(tty, *cp++, lookahead_done); in n_tty_receive_buf_closing()
1555 static void n_tty_receive_buf_standard(struct tty_struct *tty, in n_tty_receive_buf_standard() argument
1558 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_standard()
1568 n_tty_receive_char_lnext(tty, c, flag); in n_tty_receive_buf_standard()
1573 n_tty_receive_char_flagged(tty, c, flag); in n_tty_receive_buf_standard()
1577 if (I_ISTRIP(tty)) in n_tty_receive_buf_standard()
1579 if (I_IUCLC(tty) && L_IEXTEN(tty)) in n_tty_receive_buf_standard()
1581 if (L_EXTPROC(tty)) { in n_tty_receive_buf_standard()
1587 n_tty_receive_char_special(tty, c, lookahead_done); in n_tty_receive_buf_standard()
1589 n_tty_receive_char(tty, c); in n_tty_receive_buf_standard()
1593 static void __receive_buf(struct tty_struct *tty, const unsigned char *cp, in __receive_buf() argument
1596 struct n_tty_data *ldata = tty->disc_data; in __receive_buf()
1597 bool preops = I_ISTRIP(tty) || (I_IUCLC(tty) && L_IEXTEN(tty)); in __receive_buf()
1601 n_tty_receive_buf_real_raw(tty, cp, fp, count); in __receive_buf()
1602 else if (ldata->raw || (L_EXTPROC(tty) && !preops)) in __receive_buf()
1603 n_tty_receive_buf_raw(tty, cp, fp, count); in __receive_buf()
1604 else if (tty->closing && !L_EXTPROC(tty)) { in __receive_buf()
1606 n_tty_receive_buf_closing(tty, cp, fp, la_count, true); in __receive_buf()
1608 n_tty_receive_buf_closing(tty, cp, fp, count - la_count, false); in __receive_buf()
1611 n_tty_receive_buf_standard(tty, cp, fp, la_count, true); in __receive_buf()
1613 n_tty_receive_buf_standard(tty, cp, fp, count - la_count, false); in __receive_buf()
1615 flush_echoes(tty); in __receive_buf()
1616 if (tty->ops->flush_chars) in __receive_buf()
1617 tty->ops->flush_chars(tty); in __receive_buf()
1622 if (ldata->icanon && !L_EXTPROC(tty)) in __receive_buf()
1629 kill_fasync(&tty->fasync, SIGIO, POLL_IN); in __receive_buf()
1630 wake_up_interruptible_poll(&tty->read_wait, EPOLLIN | EPOLLRDNORM); in __receive_buf()
1668 n_tty_receive_buf_common(struct tty_struct *tty, const unsigned char *cp, in n_tty_receive_buf_common() argument
1671 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_common()
1674 down_read(&tty->termios_rwsem); in n_tty_receive_buf_common()
1693 if (I_PARMRK(tty)) in n_tty_receive_buf_common()
1711 __receive_buf(tty, cp, fp, n); in n_tty_receive_buf_common()
1718 } while (!test_bit(TTY_LDISC_CHANGING, &tty->flags)); in n_tty_receive_buf_common()
1720 tty->receive_room = room; in n_tty_receive_buf_common()
1723 if (tty->driver->type == TTY_DRIVER_TYPE_PTY) { in n_tty_receive_buf_common()
1725 tty_set_flow_change(tty, TTY_UNTHROTTLE_SAFE); in n_tty_receive_buf_common()
1726 tty_unthrottle_safe(tty); in n_tty_receive_buf_common()
1727 __tty_set_flow_change(tty, 0); in n_tty_receive_buf_common()
1730 n_tty_check_throttle(tty); in n_tty_receive_buf_common()
1732 up_read(&tty->termios_rwsem); in n_tty_receive_buf_common()
1737 static void n_tty_receive_buf(struct tty_struct *tty, const unsigned char *cp, in n_tty_receive_buf() argument
1740 n_tty_receive_buf_common(tty, cp, fp, count, 0); in n_tty_receive_buf()
1743 static int n_tty_receive_buf2(struct tty_struct *tty, const unsigned char *cp, in n_tty_receive_buf2() argument
1746 return n_tty_receive_buf_common(tty, cp, fp, count, 1); in n_tty_receive_buf2()
1761 static void n_tty_set_termios(struct tty_struct *tty, const struct ktermios *old) in n_tty_set_termios() argument
1763 struct n_tty_data *ldata = tty->disc_data; in n_tty_set_termios()
1765 if (!old || (old->c_lflag ^ tty->termios.c_lflag) & (ICANON | EXTPROC)) { in n_tty_set_termios()
1768 if (!L_ICANON(tty) || !read_cnt(ldata)) { in n_tty_set_termios()
1782 ldata->icanon = (L_ICANON(tty) != 0); in n_tty_set_termios()
1784 if (I_ISTRIP(tty) || I_IUCLC(tty) || I_IGNCR(tty) || in n_tty_set_termios()
1785 I_ICRNL(tty) || I_INLCR(tty) || L_ICANON(tty) || in n_tty_set_termios()
1786 I_IXON(tty) || L_ISIG(tty) || L_ECHO(tty) || in n_tty_set_termios()
1787 I_PARMRK(tty)) { in n_tty_set_termios()
1790 if (I_IGNCR(tty) || I_ICRNL(tty)) in n_tty_set_termios()
1792 if (I_INLCR(tty)) in n_tty_set_termios()
1795 if (L_ICANON(tty)) { in n_tty_set_termios()
1796 set_bit(ERASE_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1797 set_bit(KILL_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1798 set_bit(EOF_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1800 set_bit(EOL_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1801 if (L_IEXTEN(tty)) { in n_tty_set_termios()
1802 set_bit(WERASE_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1803 set_bit(LNEXT_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1804 set_bit(EOL2_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1805 if (L_ECHO(tty)) in n_tty_set_termios()
1806 set_bit(REPRINT_CHAR(tty), in n_tty_set_termios()
1810 if (I_IXON(tty)) { in n_tty_set_termios()
1811 set_bit(START_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1812 set_bit(STOP_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1814 if (L_ISIG(tty)) { in n_tty_set_termios()
1815 set_bit(INTR_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1816 set_bit(QUIT_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1817 set_bit(SUSP_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1824 if ((I_IGNBRK(tty) || (!I_BRKINT(tty) && !I_PARMRK(tty))) && in n_tty_set_termios()
1825 (I_IGNPAR(tty) || !I_INPCK(tty)) && in n_tty_set_termios()
1826 (tty->driver->flags & TTY_DRIVER_REAL_RAW)) in n_tty_set_termios()
1835 if (!I_IXON(tty) && old && (old->c_iflag & IXON) && !tty->flow.tco_stopped) { in n_tty_set_termios()
1836 start_tty(tty); in n_tty_set_termios()
1837 process_echoes(tty); in n_tty_set_termios()
1841 wake_up_interruptible(&tty->write_wait); in n_tty_set_termios()
1842 wake_up_interruptible(&tty->read_wait); in n_tty_set_termios()
1853 static void n_tty_close(struct tty_struct *tty) in n_tty_close() argument
1855 struct n_tty_data *ldata = tty->disc_data; in n_tty_close()
1857 if (tty->link) in n_tty_close()
1858 n_tty_packet_mode_flush(tty); in n_tty_close()
1860 down_write(&tty->termios_rwsem); in n_tty_close()
1862 tty->disc_data = NULL; in n_tty_close()
1863 up_write(&tty->termios_rwsem); in n_tty_close()
1874 static int n_tty_open(struct tty_struct *tty) in n_tty_open() argument
1887 tty->disc_data = ldata; in n_tty_open()
1888 tty->closing = 0; in n_tty_open()
1890 clear_bit(TTY_LDISC_HALTED, &tty->flags); in n_tty_open()
1891 n_tty_set_termios(tty, NULL); in n_tty_open()
1892 tty_unthrottle(tty); in n_tty_open()
1896 static inline int input_available_p(struct tty_struct *tty, int poll) in input_available_p() argument
1898 struct n_tty_data *ldata = tty->disc_data; in input_available_p()
1899 int amt = poll && !TIME_CHAR(tty) && MIN_CHAR(tty) ? MIN_CHAR(tty) : 1; in input_available_p()
1901 if (ldata->icanon && !L_EXTPROC(tty)) in input_available_p()
1925 static bool copy_from_read_buf(struct tty_struct *tty, in copy_from_read_buf() argument
1930 struct n_tty_data *ldata = tty->disc_data; in copy_from_read_buf()
1941 is_eof = n == 1 && *from == EOF_CHAR(tty); in copy_from_read_buf()
1942 tty_audit_add_data(tty, from, n); in copy_from_read_buf()
1943 zero_buffer(tty, from, n); in copy_from_read_buf()
1946 if (L_EXTPROC(tty) && ldata->icanon && is_eof && in copy_from_read_buf()
1980 static bool canon_copy_from_read_buf(struct tty_struct *tty, in canon_copy_from_read_buf() argument
1984 struct n_tty_data *ldata = tty->disc_data; in canon_copy_from_read_buf()
2023 tty_copy(tty, *kbp, tail, n); in canon_copy_from_read_buf()
2049 static void canon_skip_eof(struct tty_struct *tty) in canon_skip_eof() argument
2051 struct n_tty_data *ldata = tty->disc_data; in canon_skip_eof()
2087 static int job_control(struct tty_struct *tty, struct file *file) in job_control() argument
2097 return __tty_check_change(tty, SIGTTIN); in job_control()
2121 static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, in n_tty_read() argument
2125 struct n_tty_data *ldata = tty->disc_data; in n_tty_read()
2142 if (ldata->icanon && !L_EXTPROC(tty)) { in n_tty_read()
2149 canon_skip_eof(tty); in n_tty_read()
2150 else if (canon_copy_from_read_buf(tty, &kb, &nr)) in n_tty_read()
2153 if (copy_from_read_buf(tty, &kb, &nr)) in n_tty_read()
2158 n_tty_kick_worker(tty); in n_tty_read()
2159 n_tty_check_unthrottle(tty); in n_tty_read()
2160 up_read(&tty->termios_rwsem); in n_tty_read()
2166 c = job_control(tty, file); in n_tty_read()
2181 down_read(&tty->termios_rwsem); in n_tty_read()
2186 minimum = MIN_CHAR(tty); in n_tty_read()
2188 time = (HZ / 10) * TIME_CHAR(tty); in n_tty_read()
2190 timeout = (HZ / 10) * TIME_CHAR(tty); in n_tty_read()
2195 packet = tty->ctrl.packet; in n_tty_read()
2198 add_wait_queue(&tty->read_wait, &wait); in n_tty_read()
2201 if (packet && tty->link->ctrl.pktstatus) { in n_tty_read()
2205 spin_lock_irq(&tty->link->ctrl.lock); in n_tty_read()
2206 cs = tty->link->ctrl.pktstatus; in n_tty_read()
2207 tty->link->ctrl.pktstatus = 0; in n_tty_read()
2208 spin_unlock_irq(&tty->link->ctrl.lock); in n_tty_read()
2214 if (!input_available_p(tty, 0)) { in n_tty_read()
2215 up_read(&tty->termios_rwsem); in n_tty_read()
2216 tty_buffer_flush_work(tty->port); in n_tty_read()
2217 down_read(&tty->termios_rwsem); in n_tty_read()
2218 if (!input_available_p(tty, 0)) { in n_tty_read()
2219 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) { in n_tty_read()
2229 if (test_bit(TTY_HUPPING, &tty->flags)) in n_tty_read()
2233 if (tty_io_nonblock(tty, file)) { in n_tty_read()
2241 up_read(&tty->termios_rwsem); in n_tty_read()
2246 down_read(&tty->termios_rwsem); in n_tty_read()
2251 if (ldata->icanon && !L_EXTPROC(tty)) { in n_tty_read()
2252 if (canon_copy_from_read_buf(tty, &kb, &nr)) in n_tty_read()
2270 if (copy_from_read_buf(tty, &kb, &nr) && kb - kbuf >= minimum) { in n_tty_read()
2272 remove_wait_queue(&tty->read_wait, &wait); in n_tty_read()
2278 n_tty_check_unthrottle(tty); in n_tty_read()
2286 n_tty_kick_worker(tty); in n_tty_read()
2287 up_read(&tty->termios_rwsem); in n_tty_read()
2289 remove_wait_queue(&tty->read_wait, &wait); in n_tty_read()
2318 static ssize_t n_tty_write(struct tty_struct *tty, struct file *file, in n_tty_write() argument
2327 if (L_TOSTOP(tty) && file->f_op->write_iter != redirected_tty_write) { in n_tty_write()
2328 retval = tty_check_change(tty); in n_tty_write()
2333 down_read(&tty->termios_rwsem); in n_tty_write()
2336 process_echoes(tty); in n_tty_write()
2338 add_wait_queue(&tty->write_wait, &wait); in n_tty_write()
2344 if (tty_hung_up_p(file) || (tty->link && !tty->link->count)) { in n_tty_write()
2348 if (O_OPOST(tty)) { in n_tty_write()
2350 ssize_t num = process_output_block(tty, b, nr); in n_tty_write()
2362 if (process_output(c, tty) < 0) in n_tty_write()
2366 if (tty->ops->flush_chars) in n_tty_write()
2367 tty->ops->flush_chars(tty); in n_tty_write()
2369 struct n_tty_data *ldata = tty->disc_data; in n_tty_write()
2373 c = tty->ops->write(tty, b, nr); in n_tty_write()
2387 if (tty_io_nonblock(tty, file)) { in n_tty_write()
2391 up_read(&tty->termios_rwsem); in n_tty_write()
2395 down_read(&tty->termios_rwsem); in n_tty_write()
2398 remove_wait_queue(&tty->write_wait, &wait); in n_tty_write()
2399 if (nr && tty->fasync) in n_tty_write()
2400 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in n_tty_write()
2401 up_read(&tty->termios_rwsem); in n_tty_write()
2419 static __poll_t n_tty_poll(struct tty_struct *tty, struct file *file, in n_tty_poll() argument
2424 poll_wait(file, &tty->read_wait, wait); in n_tty_poll()
2425 poll_wait(file, &tty->write_wait, wait); in n_tty_poll()
2426 if (input_available_p(tty, 1)) in n_tty_poll()
2429 tty_buffer_flush_work(tty->port); in n_tty_poll()
2430 if (input_available_p(tty, 1)) in n_tty_poll()
2433 if (tty->ctrl.packet && tty->link->ctrl.pktstatus) in n_tty_poll()
2435 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) in n_tty_poll()
2439 if (tty->ops->write && !tty_is_writelocked(tty) && in n_tty_poll()
2440 tty_chars_in_buffer(tty) < WAKEUP_CHARS && in n_tty_poll()
2441 tty_write_room(tty) > 0) in n_tty_poll()
2465 static int n_tty_ioctl(struct tty_struct *tty, unsigned int cmd, in n_tty_ioctl() argument
2468 struct n_tty_data *ldata = tty->disc_data; in n_tty_ioctl()
2473 return put_user(tty_chars_in_buffer(tty), (int __user *) arg); in n_tty_ioctl()
2475 down_write(&tty->termios_rwsem); in n_tty_ioctl()
2476 if (L_ICANON(tty) && !L_EXTPROC(tty)) in n_tty_ioctl()
2480 up_write(&tty->termios_rwsem); in n_tty_ioctl()
2483 return n_tty_ioctl_helper(tty, cmd, arg); in n_tty_ioctl()