Lines Matching refs:tty

161 static void zero_buffer(const struct tty_struct *tty, u8 *buffer, size_t size)  in zero_buffer()  argument
163 if (L_ICANON(tty) && !L_ECHO(tty)) in zero_buffer()
167 static void tty_copy(const struct tty_struct *tty, void *to, size_t tail, in tty_copy() argument
170 struct n_tty_data *ldata = tty->disc_data; in tty_copy()
175 tty_audit_add_data(tty, from, size); in tty_copy()
177 zero_buffer(tty, from, size); in tty_copy()
183 tty_audit_add_data(tty, from, n); in tty_copy()
185 zero_buffer(tty, from, n); in tty_copy()
199 static void n_tty_kick_worker(const struct tty_struct *tty) in n_tty_kick_worker() argument
201 struct n_tty_data *ldata = tty->disc_data; in n_tty_kick_worker()
207 WARN_RATELIMIT(tty->port->itty == NULL, in n_tty_kick_worker()
213 WARN_RATELIMIT(test_bit(TTY_LDISC_HALTED, &tty->flags), in n_tty_kick_worker()
215 tty_buffer_restart_work(tty->port); in n_tty_kick_worker()
219 static ssize_t chars_in_buffer(const struct tty_struct *tty) in chars_in_buffer() argument
221 const struct n_tty_data *ldata = tty->disc_data; in chars_in_buffer()
234 static void n_tty_write_wakeup(struct tty_struct *tty) in n_tty_write_wakeup() argument
236 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in n_tty_write_wakeup()
237 kill_fasync(&tty->fasync, SIGIO, POLL_OUT); in n_tty_write_wakeup()
240 static void n_tty_check_throttle(struct tty_struct *tty) in n_tty_check_throttle() argument
242 struct n_tty_data *ldata = tty->disc_data; in n_tty_check_throttle()
254 tty_set_flow_change(tty, TTY_THROTTLE_SAFE); in n_tty_check_throttle()
257 throttled = tty_throttle_safe(tty); in n_tty_check_throttle()
261 __tty_set_flow_change(tty, 0); in n_tty_check_throttle()
264 static void n_tty_check_unthrottle(struct tty_struct *tty) in n_tty_check_unthrottle() argument
266 if (tty->driver->type == TTY_DRIVER_TYPE_PTY) { in n_tty_check_unthrottle()
267 if (chars_in_buffer(tty) > TTY_THRESHOLD_UNTHROTTLE) in n_tty_check_unthrottle()
269 n_tty_kick_worker(tty); in n_tty_check_unthrottle()
270 tty_wakeup(tty->link); in n_tty_check_unthrottle()
284 tty_set_flow_change(tty, TTY_UNTHROTTLE_SAFE); in n_tty_check_unthrottle()
285 if (chars_in_buffer(tty) > TTY_THRESHOLD_UNTHROTTLE) in n_tty_check_unthrottle()
287 n_tty_kick_worker(tty); in n_tty_check_unthrottle()
288 unthrottled = tty_unthrottle_safe(tty); in n_tty_check_unthrottle()
292 __tty_set_flow_change(tty, 0); in n_tty_check_unthrottle()
336 static void n_tty_packet_mode_flush(struct tty_struct *tty) in n_tty_packet_mode_flush() argument
340 if (tty->link->ctrl.packet) { in n_tty_packet_mode_flush()
341 spin_lock_irqsave(&tty->ctrl.lock, flags); in n_tty_packet_mode_flush()
342 tty->ctrl.pktstatus |= TIOCPKT_FLUSHREAD; in n_tty_packet_mode_flush()
343 spin_unlock_irqrestore(&tty->ctrl.lock, flags); in n_tty_packet_mode_flush()
344 wake_up_interruptible(&tty->link->read_wait); in n_tty_packet_mode_flush()
361 static void n_tty_flush_buffer(struct tty_struct *tty) in n_tty_flush_buffer() argument
363 down_write(&tty->termios_rwsem); in n_tty_flush_buffer()
364 reset_buffer_flags(tty->disc_data); in n_tty_flush_buffer()
365 n_tty_kick_worker(tty); in n_tty_flush_buffer()
367 if (tty->link) in n_tty_flush_buffer()
368 n_tty_packet_mode_flush(tty); in n_tty_flush_buffer()
369 up_write(&tty->termios_rwsem); in n_tty_flush_buffer()
393 static inline int is_continuation(u8 c, const struct tty_struct *tty) in is_continuation() argument
395 return I_IUTF8(tty) && is_utf8_continuation(c); in is_continuation()
417 static int do_output_char(u8 c, struct tty_struct *tty, int space) in do_output_char() argument
419 struct n_tty_data *ldata = tty->disc_data; in do_output_char()
427 if (O_ONLRET(tty)) in do_output_char()
429 if (O_ONLCR(tty)) { in do_output_char()
433 tty->ops->write(tty, "\r\n", 2); in do_output_char()
439 if (O_ONOCR(tty) && ldata->column == 0) in do_output_char()
441 if (O_OCRNL(tty)) { in do_output_char()
443 if (O_ONLRET(tty)) in do_output_char()
451 if (O_TABDLY(tty) == XTABS) { in do_output_char()
455 tty->ops->write(tty, " ", spaces); in do_output_char()
466 if (O_OLCUC(tty)) in do_output_char()
468 if (!is_continuation(c, tty)) in do_output_char()
474 tty_put_char(tty, c); in do_output_char()
491 static int process_output(u8 c, struct tty_struct *tty) in process_output() argument
493 struct n_tty_data *ldata = tty->disc_data; in process_output()
498 space = tty_write_room(tty); in process_output()
499 retval = do_output_char(c, tty, space); in process_output()
526 static ssize_t process_output_block(struct tty_struct *tty, in process_output_block() argument
529 struct n_tty_data *ldata = tty->disc_data; in process_output_block()
536 space = tty_write_room(tty); in process_output_block()
549 if (O_ONLRET(tty)) in process_output_block()
551 if (O_ONLCR(tty)) in process_output_block()
556 if (O_ONOCR(tty) && ldata->column == 0) in process_output_block()
558 if (O_OCRNL(tty)) in process_output_block()
570 if (O_OLCUC(tty)) in process_output_block()
572 if (!is_continuation(c, tty)) in process_output_block()
579 i = tty->ops->write(tty, buf, i); in process_output_block()
585 static int n_tty_process_echo_ops(struct tty_struct *tty, size_t *tail, in n_tty_process_echo_ops() argument
588 struct n_tty_data *ldata = tty->disc_data; in n_tty_process_echo_ops()
629 tty_put_char(tty, '\b'); in n_tty_process_echo_ops()
652 tty_put_char(tty, ECHO_OP_START); in n_tty_process_echo_ops()
668 tty_put_char(tty, '^'); in n_tty_process_echo_ops()
669 tty_put_char(tty, op ^ 0100); in n_tty_process_echo_ops()
701 static size_t __process_echoes(struct tty_struct *tty) in __process_echoes() argument
703 struct n_tty_data *ldata = tty->disc_data; in __process_echoes()
708 old_space = space = tty_write_room(tty); in __process_echoes()
714 int ret = n_tty_process_echo_ops(tty, &tail, space); in __process_echoes()
721 if (O_OPOST(tty)) { in __process_echoes()
722 int retval = do_output_char(c, tty, space); in __process_echoes()
729 tty_put_char(tty, c); in __process_echoes()
755 static void commit_echoes(struct tty_struct *tty) in commit_echoes() argument
757 struct n_tty_data *ldata = tty->disc_data; in commit_echoes()
777 echoed = __process_echoes(tty); in commit_echoes()
780 if (echoed && tty->ops->flush_chars) in commit_echoes()
781 tty->ops->flush_chars(tty); in commit_echoes()
784 static void process_echoes(struct tty_struct *tty) in process_echoes() argument
786 struct n_tty_data *ldata = tty->disc_data; in process_echoes()
794 echoed = __process_echoes(tty); in process_echoes()
797 if (echoed && tty->ops->flush_chars) in process_echoes()
798 tty->ops->flush_chars(tty); in process_echoes()
802 static void flush_echoes(struct tty_struct *tty) in flush_echoes() argument
804 struct n_tty_data *ldata = tty->disc_data; in flush_echoes()
806 if ((!L_ECHO(tty) && !L_ECHONL(tty)) || in flush_echoes()
812 __process_echoes(tty); in flush_echoes()
915 static void echo_char(u8 c, const struct tty_struct *tty) in echo_char() argument
917 struct n_tty_data *ldata = tty->disc_data; in echo_char()
923 if (L_ECHOCTL(tty) && iscntrl(c) && c != '\t') in echo_char()
953 static void eraser(u8 c, const struct tty_struct *tty) in eraser() argument
955 struct n_tty_data *ldata = tty->disc_data; in eraser()
965 if (c == ERASE_CHAR(tty)) in eraser()
967 else if (c == WERASE_CHAR(tty)) in eraser()
970 if (!L_ECHO(tty)) { in eraser()
974 if (!L_ECHOK(tty) || !L_ECHOKE(tty) || !L_ECHOE(tty)) { in eraser()
977 echo_char(KILL_CHAR(tty), tty); in eraser()
979 if (L_ECHOK(tty)) in eraser()
994 } while (is_continuation(c, tty) && in eraser()
998 if (is_continuation(c, tty)) in eraser()
1010 if (L_ECHO(tty)) { in eraser()
1011 if (L_ECHOPRT(tty)) { in eraser()
1017 echo_char(c, tty); in eraser()
1023 } else if (kill_type == ERASE && !L_ECHOE(tty)) { in eraser()
1024 echo_char(ERASE_CHAR(tty), tty); in eraser()
1044 if (L_ECHOCTL(tty)) in eraser()
1046 } else if (!is_continuation(c, tty)) { in eraser()
1052 if (iscntrl(c) && L_ECHOCTL(tty)) { in eraser()
1057 if (!iscntrl(c) || L_ECHOCTL(tty)) { in eraser()
1067 if (ldata->read_head == ldata->canon_head && L_ECHO(tty)) in eraser()
1072 static void __isig(int sig, struct tty_struct *tty) in __isig() argument
1074 struct pid *tty_pgrp = tty_get_pgrp(tty); in __isig()
1095 static void isig(int sig, struct tty_struct *tty) in isig() argument
1097 struct n_tty_data *ldata = tty->disc_data; in isig()
1099 if (L_NOFLSH(tty)) { in isig()
1101 __isig(sig, tty); in isig()
1104 up_read(&tty->termios_rwsem); in isig()
1105 down_write(&tty->termios_rwsem); in isig()
1107 __isig(sig, tty); in isig()
1116 tty_driver_flush_buffer(tty); in isig()
1119 reset_buffer_flags(tty->disc_data); in isig()
1122 if (tty->link) in isig()
1123 n_tty_packet_mode_flush(tty); in isig()
1125 up_write(&tty->termios_rwsem); in isig()
1126 down_read(&tty->termios_rwsem); in isig()
1142 static void n_tty_receive_break(struct tty_struct *tty) in n_tty_receive_break() argument
1144 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_break()
1146 if (I_IGNBRK(tty)) in n_tty_receive_break()
1148 if (I_BRKINT(tty)) { in n_tty_receive_break()
1149 isig(SIGINT, tty); in n_tty_receive_break()
1152 if (I_PARMRK(tty)) { in n_tty_receive_break()
1169 static void n_tty_receive_overrun(const struct tty_struct *tty) in n_tty_receive_overrun() argument
1171 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_overrun()
1175 tty_warn(tty, "%u input overrun(s)\n", ldata->num_overrun); in n_tty_receive_overrun()
1192 static void n_tty_receive_parity_error(const struct tty_struct *tty, in n_tty_receive_parity_error() argument
1195 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_parity_error()
1197 if (I_INPCK(tty)) { in n_tty_receive_parity_error()
1198 if (I_IGNPAR(tty)) in n_tty_receive_parity_error()
1200 if (I_PARMRK(tty)) { in n_tty_receive_parity_error()
1211 n_tty_receive_signal_char(struct tty_struct *tty, int signal, u8 c) in n_tty_receive_signal_char() argument
1213 isig(signal, tty); in n_tty_receive_signal_char()
1214 if (I_IXON(tty)) in n_tty_receive_signal_char()
1215 start_tty(tty); in n_tty_receive_signal_char()
1216 if (L_ECHO(tty)) { in n_tty_receive_signal_char()
1217 echo_char(c, tty); in n_tty_receive_signal_char()
1218 commit_echoes(tty); in n_tty_receive_signal_char()
1220 process_echoes(tty); in n_tty_receive_signal_char()
1223 static bool n_tty_is_char_flow_ctrl(struct tty_struct *tty, u8 c) in n_tty_is_char_flow_ctrl() argument
1225 return c == START_CHAR(tty) || c == STOP_CHAR(tty); in n_tty_is_char_flow_ctrl()
1243 static bool n_tty_receive_char_flow_ctrl(struct tty_struct *tty, u8 c, in n_tty_receive_char_flow_ctrl() argument
1246 if (!n_tty_is_char_flow_ctrl(tty, c)) in n_tty_receive_char_flow_ctrl()
1252 if (c == START_CHAR(tty)) { in n_tty_receive_char_flow_ctrl()
1253 start_tty(tty); in n_tty_receive_char_flow_ctrl()
1254 process_echoes(tty); in n_tty_receive_char_flow_ctrl()
1259 stop_tty(tty); in n_tty_receive_char_flow_ctrl()
1263 static void n_tty_receive_handle_newline(struct tty_struct *tty, u8 c) in n_tty_receive_handle_newline() argument
1265 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_handle_newline()
1270 kill_fasync(&tty->fasync, SIGIO, POLL_IN); in n_tty_receive_handle_newline()
1271 wake_up_interruptible_poll(&tty->read_wait, EPOLLIN | EPOLLRDNORM); in n_tty_receive_handle_newline()
1274 static bool n_tty_receive_char_canon(struct tty_struct *tty, u8 c) in n_tty_receive_char_canon() argument
1276 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_char_canon()
1278 if (c == ERASE_CHAR(tty) || c == KILL_CHAR(tty) || in n_tty_receive_char_canon()
1279 (c == WERASE_CHAR(tty) && L_IEXTEN(tty))) { in n_tty_receive_char_canon()
1280 eraser(c, tty); in n_tty_receive_char_canon()
1281 commit_echoes(tty); in n_tty_receive_char_canon()
1286 if (c == LNEXT_CHAR(tty) && L_IEXTEN(tty)) { in n_tty_receive_char_canon()
1288 if (L_ECHO(tty)) { in n_tty_receive_char_canon()
1290 if (L_ECHOCTL(tty)) { in n_tty_receive_char_canon()
1293 commit_echoes(tty); in n_tty_receive_char_canon()
1300 if (c == REPRINT_CHAR(tty) && L_ECHO(tty) && L_IEXTEN(tty)) { in n_tty_receive_char_canon()
1304 echo_char(c, tty); in n_tty_receive_char_canon()
1307 echo_char(read_buf(ldata, tail), tty); in n_tty_receive_char_canon()
1310 commit_echoes(tty); in n_tty_receive_char_canon()
1316 if (L_ECHO(tty) || L_ECHONL(tty)) { in n_tty_receive_char_canon()
1318 commit_echoes(tty); in n_tty_receive_char_canon()
1320 n_tty_receive_handle_newline(tty, c); in n_tty_receive_char_canon()
1325 if (c == EOF_CHAR(tty)) { in n_tty_receive_char_canon()
1327 n_tty_receive_handle_newline(tty, c); in n_tty_receive_char_canon()
1332 if ((c == EOL_CHAR(tty)) || in n_tty_receive_char_canon()
1333 (c == EOL2_CHAR(tty) && L_IEXTEN(tty))) { in n_tty_receive_char_canon()
1337 if (L_ECHO(tty)) { in n_tty_receive_char_canon()
1341 echo_char(c, tty); in n_tty_receive_char_canon()
1342 commit_echoes(tty); in n_tty_receive_char_canon()
1348 if (c == '\377' && I_PARMRK(tty)) in n_tty_receive_char_canon()
1351 n_tty_receive_handle_newline(tty, c); in n_tty_receive_char_canon()
1359 static void n_tty_receive_char_special(struct tty_struct *tty, u8 c, in n_tty_receive_char_special() argument
1362 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_char_special()
1364 if (I_IXON(tty) && n_tty_receive_char_flow_ctrl(tty, c, lookahead_done)) in n_tty_receive_char_special()
1367 if (L_ISIG(tty)) { in n_tty_receive_char_special()
1368 if (c == INTR_CHAR(tty)) { in n_tty_receive_char_special()
1369 n_tty_receive_signal_char(tty, SIGINT, c); in n_tty_receive_char_special()
1371 } else if (c == QUIT_CHAR(tty)) { in n_tty_receive_char_special()
1372 n_tty_receive_signal_char(tty, SIGQUIT, c); in n_tty_receive_char_special()
1374 } else if (c == SUSP_CHAR(tty)) { in n_tty_receive_char_special()
1375 n_tty_receive_signal_char(tty, SIGTSTP, c); in n_tty_receive_char_special()
1380 if (tty->flow.stopped && !tty->flow.tco_stopped && I_IXON(tty) && I_IXANY(tty)) { in n_tty_receive_char_special()
1381 start_tty(tty); in n_tty_receive_char_special()
1382 process_echoes(tty); in n_tty_receive_char_special()
1386 if (I_IGNCR(tty)) in n_tty_receive_char_special()
1388 if (I_ICRNL(tty)) in n_tty_receive_char_special()
1390 } else if (c == '\n' && I_INLCR(tty)) in n_tty_receive_char_special()
1393 if (ldata->icanon && n_tty_receive_char_canon(tty, c)) in n_tty_receive_char_special()
1396 if (L_ECHO(tty)) { in n_tty_receive_char_special()
1404 echo_char(c, tty); in n_tty_receive_char_special()
1406 commit_echoes(tty); in n_tty_receive_char_special()
1410 if (c == '\377' && I_PARMRK(tty)) in n_tty_receive_char_special()
1428 static void n_tty_receive_char(struct tty_struct *tty, u8 c) in n_tty_receive_char() argument
1430 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_char()
1432 if (tty->flow.stopped && !tty->flow.tco_stopped && I_IXON(tty) && I_IXANY(tty)) { in n_tty_receive_char()
1433 start_tty(tty); in n_tty_receive_char()
1434 process_echoes(tty); in n_tty_receive_char()
1436 if (L_ECHO(tty)) { in n_tty_receive_char()
1441 echo_char(c, tty); in n_tty_receive_char()
1442 commit_echoes(tty); in n_tty_receive_char()
1445 if (c == '\377' && I_PARMRK(tty)) in n_tty_receive_char()
1450 static void n_tty_receive_char_closing(struct tty_struct *tty, u8 c, in n_tty_receive_char_closing() argument
1453 if (I_ISTRIP(tty)) in n_tty_receive_char_closing()
1455 if (I_IUCLC(tty) && L_IEXTEN(tty)) in n_tty_receive_char_closing()
1458 if (I_IXON(tty)) { in n_tty_receive_char_closing()
1459 if (!n_tty_receive_char_flow_ctrl(tty, c, lookahead_done) && in n_tty_receive_char_closing()
1460 tty->flow.stopped && !tty->flow.tco_stopped && I_IXANY(tty) && in n_tty_receive_char_closing()
1461 c != INTR_CHAR(tty) && c != QUIT_CHAR(tty) && in n_tty_receive_char_closing()
1462 c != SUSP_CHAR(tty)) { in n_tty_receive_char_closing()
1463 start_tty(tty); in n_tty_receive_char_closing()
1464 process_echoes(tty); in n_tty_receive_char_closing()
1470 n_tty_receive_char_flagged(struct tty_struct *tty, u8 c, u8 flag) in n_tty_receive_char_flagged() argument
1474 n_tty_receive_break(tty); in n_tty_receive_char_flagged()
1478 n_tty_receive_parity_error(tty, c); in n_tty_receive_char_flagged()
1481 n_tty_receive_overrun(tty); in n_tty_receive_char_flagged()
1484 tty_err(tty, "unknown flag %u\n", flag); in n_tty_receive_char_flagged()
1490 n_tty_receive_char_lnext(struct tty_struct *tty, u8 c, u8 flag) in n_tty_receive_char_lnext() argument
1492 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_char_lnext()
1496 if (I_ISTRIP(tty)) in n_tty_receive_char_lnext()
1498 if (I_IUCLC(tty) && L_IEXTEN(tty)) in n_tty_receive_char_lnext()
1500 n_tty_receive_char(tty, c); in n_tty_receive_char_lnext()
1502 n_tty_receive_char_flagged(tty, c, flag); in n_tty_receive_char_lnext()
1506 static void n_tty_lookahead_flow_ctrl(struct tty_struct *tty, const u8 *cp, in n_tty_lookahead_flow_ctrl() argument
1509 struct n_tty_data *ldata = tty->disc_data; in n_tty_lookahead_flow_ctrl()
1514 if (!I_IXON(tty)) in n_tty_lookahead_flow_ctrl()
1521 n_tty_receive_char_flow_ctrl(tty, *cp, false); in n_tty_lookahead_flow_ctrl()
1527 n_tty_receive_buf_real_raw(const struct tty_struct *tty, const u8 *cp, in n_tty_receive_buf_real_raw() argument
1530 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_real_raw()
1546 n_tty_receive_buf_raw(struct tty_struct *tty, const u8 *cp, const u8 *fp, in n_tty_receive_buf_raw() argument
1549 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_raw()
1558 n_tty_receive_char_flagged(tty, *cp++, flag); in n_tty_receive_buf_raw()
1563 n_tty_receive_buf_closing(struct tty_struct *tty, const u8 *cp, const u8 *fp, in n_tty_receive_buf_closing() argument
1572 n_tty_receive_char_closing(tty, *cp++, lookahead_done); in n_tty_receive_buf_closing()
1576 static void n_tty_receive_buf_standard(struct tty_struct *tty, const u8 *cp, in n_tty_receive_buf_standard() argument
1580 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_standard()
1590 n_tty_receive_char_lnext(tty, c, flag); in n_tty_receive_buf_standard()
1595 n_tty_receive_char_flagged(tty, c, flag); in n_tty_receive_buf_standard()
1599 if (I_ISTRIP(tty)) in n_tty_receive_buf_standard()
1601 if (I_IUCLC(tty) && L_IEXTEN(tty)) in n_tty_receive_buf_standard()
1603 if (L_EXTPROC(tty)) { in n_tty_receive_buf_standard()
1609 n_tty_receive_char_special(tty, c, lookahead_done); in n_tty_receive_buf_standard()
1611 n_tty_receive_char(tty, c); in n_tty_receive_buf_standard()
1615 static void __receive_buf(struct tty_struct *tty, const u8 *cp, const u8 *fp, in __receive_buf() argument
1618 struct n_tty_data *ldata = tty->disc_data; in __receive_buf()
1619 bool preops = I_ISTRIP(tty) || (I_IUCLC(tty) && L_IEXTEN(tty)); in __receive_buf()
1623 n_tty_receive_buf_real_raw(tty, cp, count); in __receive_buf()
1624 else if (ldata->raw || (L_EXTPROC(tty) && !preops)) in __receive_buf()
1625 n_tty_receive_buf_raw(tty, cp, fp, count); in __receive_buf()
1626 else if (tty->closing && !L_EXTPROC(tty)) { in __receive_buf()
1628 n_tty_receive_buf_closing(tty, cp, fp, la_count, true); in __receive_buf()
1630 n_tty_receive_buf_closing(tty, cp, fp, count - la_count, false); in __receive_buf()
1633 n_tty_receive_buf_standard(tty, cp, fp, la_count, true); in __receive_buf()
1635 n_tty_receive_buf_standard(tty, cp, fp, count - la_count, false); in __receive_buf()
1637 flush_echoes(tty); in __receive_buf()
1638 if (tty->ops->flush_chars) in __receive_buf()
1639 tty->ops->flush_chars(tty); in __receive_buf()
1644 if (ldata->icanon && !L_EXTPROC(tty)) in __receive_buf()
1651 kill_fasync(&tty->fasync, SIGIO, POLL_IN); in __receive_buf()
1652 wake_up_interruptible_poll(&tty->read_wait, EPOLLIN | EPOLLRDNORM); in __receive_buf()
1690 n_tty_receive_buf_common(struct tty_struct *tty, const u8 *cp, const u8 *fp, in n_tty_receive_buf_common() argument
1693 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_common()
1697 down_read(&tty->termios_rwsem); in n_tty_receive_buf_common()
1716 if (I_PARMRK(tty)) in n_tty_receive_buf_common()
1734 __receive_buf(tty, cp, fp, n); in n_tty_receive_buf_common()
1741 } while (!test_bit(TTY_LDISC_CHANGING, &tty->flags)); in n_tty_receive_buf_common()
1743 tty->receive_room = room; in n_tty_receive_buf_common()
1746 if (tty->driver->type == TTY_DRIVER_TYPE_PTY) { in n_tty_receive_buf_common()
1748 tty_set_flow_change(tty, TTY_UNTHROTTLE_SAFE); in n_tty_receive_buf_common()
1749 tty_unthrottle_safe(tty); in n_tty_receive_buf_common()
1750 __tty_set_flow_change(tty, 0); in n_tty_receive_buf_common()
1753 n_tty_check_throttle(tty); in n_tty_receive_buf_common()
1762 if (!chars_in_buffer(tty)) in n_tty_receive_buf_common()
1763 n_tty_kick_worker(tty); in n_tty_receive_buf_common()
1766 up_read(&tty->termios_rwsem); in n_tty_receive_buf_common()
1771 static void n_tty_receive_buf(struct tty_struct *tty, const u8 *cp, in n_tty_receive_buf() argument
1774 n_tty_receive_buf_common(tty, cp, fp, count, false); in n_tty_receive_buf()
1777 static size_t n_tty_receive_buf2(struct tty_struct *tty, const u8 *cp, in n_tty_receive_buf2() argument
1780 return n_tty_receive_buf_common(tty, cp, fp, count, true); in n_tty_receive_buf2()
1795 static void n_tty_set_termios(struct tty_struct *tty, const struct ktermios *old) in n_tty_set_termios() argument
1797 struct n_tty_data *ldata = tty->disc_data; in n_tty_set_termios()
1799 if (!old || (old->c_lflag ^ tty->termios.c_lflag) & (ICANON | EXTPROC)) { in n_tty_set_termios()
1802 if (!L_ICANON(tty) || !read_cnt(ldata)) { in n_tty_set_termios()
1815 ldata->icanon = (L_ICANON(tty) != 0); in n_tty_set_termios()
1817 if (I_ISTRIP(tty) || I_IUCLC(tty) || I_IGNCR(tty) || in n_tty_set_termios()
1818 I_ICRNL(tty) || I_INLCR(tty) || L_ICANON(tty) || in n_tty_set_termios()
1819 I_IXON(tty) || L_ISIG(tty) || L_ECHO(tty) || in n_tty_set_termios()
1820 I_PARMRK(tty)) { in n_tty_set_termios()
1823 if (I_IGNCR(tty) || I_ICRNL(tty)) in n_tty_set_termios()
1825 if (I_INLCR(tty)) in n_tty_set_termios()
1828 if (L_ICANON(tty)) { in n_tty_set_termios()
1829 set_bit(ERASE_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1830 set_bit(KILL_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1831 set_bit(EOF_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1833 set_bit(EOL_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1834 if (L_IEXTEN(tty)) { in n_tty_set_termios()
1835 set_bit(WERASE_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1836 set_bit(LNEXT_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1837 set_bit(EOL2_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1838 if (L_ECHO(tty)) in n_tty_set_termios()
1839 set_bit(REPRINT_CHAR(tty), in n_tty_set_termios()
1843 if (I_IXON(tty)) { in n_tty_set_termios()
1844 set_bit(START_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1845 set_bit(STOP_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1847 if (L_ISIG(tty)) { in n_tty_set_termios()
1848 set_bit(INTR_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1849 set_bit(QUIT_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1850 set_bit(SUSP_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1857 if ((I_IGNBRK(tty) || (!I_BRKINT(tty) && !I_PARMRK(tty))) && in n_tty_set_termios()
1858 (I_IGNPAR(tty) || !I_INPCK(tty)) && in n_tty_set_termios()
1859 (tty->driver->flags & TTY_DRIVER_REAL_RAW)) in n_tty_set_termios()
1868 if (!I_IXON(tty) && old && (old->c_iflag & IXON) && !tty->flow.tco_stopped) { in n_tty_set_termios()
1869 start_tty(tty); in n_tty_set_termios()
1870 process_echoes(tty); in n_tty_set_termios()
1874 wake_up_interruptible(&tty->write_wait); in n_tty_set_termios()
1875 wake_up_interruptible(&tty->read_wait); in n_tty_set_termios()
1886 static void n_tty_close(struct tty_struct *tty) in n_tty_close() argument
1888 struct n_tty_data *ldata = tty->disc_data; in n_tty_close()
1890 if (tty->link) in n_tty_close()
1891 n_tty_packet_mode_flush(tty); in n_tty_close()
1893 down_write(&tty->termios_rwsem); in n_tty_close()
1895 tty->disc_data = NULL; in n_tty_close()
1896 up_write(&tty->termios_rwsem); in n_tty_close()
1907 static int n_tty_open(struct tty_struct *tty) in n_tty_open() argument
1920 tty->disc_data = ldata; in n_tty_open()
1921 tty->closing = 0; in n_tty_open()
1923 clear_bit(TTY_LDISC_HALTED, &tty->flags); in n_tty_open()
1924 n_tty_set_termios(tty, NULL); in n_tty_open()
1925 tty_unthrottle(tty); in n_tty_open()
1929 static inline int input_available_p(const struct tty_struct *tty, int poll) in input_available_p() argument
1931 const struct n_tty_data *ldata = tty->disc_data; in input_available_p()
1932 int amt = poll && !TIME_CHAR(tty) && MIN_CHAR(tty) ? MIN_CHAR(tty) : 1; in input_available_p()
1934 if (ldata->icanon && !L_EXTPROC(tty)) in input_available_p()
1958 static bool copy_from_read_buf(const struct tty_struct *tty, u8 **kbp, in copy_from_read_buf() argument
1962 struct n_tty_data *ldata = tty->disc_data; in copy_from_read_buf()
1973 is_eof = n == 1 && *from == EOF_CHAR(tty); in copy_from_read_buf()
1974 tty_audit_add_data(tty, from, n); in copy_from_read_buf()
1975 zero_buffer(tty, from, n); in copy_from_read_buf()
1978 if (L_EXTPROC(tty) && ldata->icanon && is_eof && in copy_from_read_buf()
2012 static bool canon_copy_from_read_buf(const struct tty_struct *tty, u8 **kbp, in canon_copy_from_read_buf() argument
2015 struct n_tty_data *ldata = tty->disc_data; in canon_copy_from_read_buf()
2054 tty_copy(tty, *kbp, tail, n); in canon_copy_from_read_buf()
2117 static int job_control(struct tty_struct *tty, struct file *file) in job_control() argument
2127 return __tty_check_change(tty, SIGTTIN); in job_control()
2151 static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, u8 *kbuf, in n_tty_read() argument
2154 struct n_tty_data *ldata = tty->disc_data; in n_tty_read()
2171 if (ldata->icanon && !L_EXTPROC(tty)) { in n_tty_read()
2179 else if (canon_copy_from_read_buf(tty, &kb, &nr)) in n_tty_read()
2182 if (copy_from_read_buf(tty, &kb, &nr)) in n_tty_read()
2187 n_tty_kick_worker(tty); in n_tty_read()
2188 n_tty_check_unthrottle(tty); in n_tty_read()
2189 up_read(&tty->termios_rwsem); in n_tty_read()
2195 c = job_control(tty, file); in n_tty_read()
2210 down_read(&tty->termios_rwsem); in n_tty_read()
2215 minimum = MIN_CHAR(tty); in n_tty_read()
2217 time = (HZ / 10) * TIME_CHAR(tty); in n_tty_read()
2219 timeout = (HZ / 10) * TIME_CHAR(tty); in n_tty_read()
2224 packet = tty->ctrl.packet; in n_tty_read()
2227 add_wait_queue(&tty->read_wait, &wait); in n_tty_read()
2230 if (packet && tty->link->ctrl.pktstatus) { in n_tty_read()
2234 spin_lock_irq(&tty->link->ctrl.lock); in n_tty_read()
2235 cs = tty->link->ctrl.pktstatus; in n_tty_read()
2236 tty->link->ctrl.pktstatus = 0; in n_tty_read()
2237 spin_unlock_irq(&tty->link->ctrl.lock); in n_tty_read()
2243 if (!input_available_p(tty, 0)) { in n_tty_read()
2244 up_read(&tty->termios_rwsem); in n_tty_read()
2245 tty_buffer_flush_work(tty->port); in n_tty_read()
2246 down_read(&tty->termios_rwsem); in n_tty_read()
2247 if (!input_available_p(tty, 0)) { in n_tty_read()
2248 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) { in n_tty_read()
2258 if (test_bit(TTY_HUPPING, &tty->flags)) in n_tty_read()
2262 if (tty_io_nonblock(tty, file)) { in n_tty_read()
2270 up_read(&tty->termios_rwsem); in n_tty_read()
2275 down_read(&tty->termios_rwsem); in n_tty_read()
2280 if (ldata->icanon && !L_EXTPROC(tty)) { in n_tty_read()
2281 if (canon_copy_from_read_buf(tty, &kb, &nr)) in n_tty_read()
2299 if (copy_from_read_buf(tty, &kb, &nr) && kb - kbuf >= minimum) { in n_tty_read()
2301 remove_wait_queue(&tty->read_wait, &wait); in n_tty_read()
2307 n_tty_check_unthrottle(tty); in n_tty_read()
2320 n_tty_kick_worker(tty); in n_tty_read()
2322 up_read(&tty->termios_rwsem); in n_tty_read()
2324 remove_wait_queue(&tty->read_wait, &wait); in n_tty_read()
2353 static ssize_t n_tty_write(struct tty_struct *tty, struct file *file, in n_tty_write() argument
2361 if (L_TOSTOP(tty) && file->f_op->write_iter != redirected_tty_write) { in n_tty_write()
2362 retval = tty_check_change(tty); in n_tty_write()
2367 down_read(&tty->termios_rwsem); in n_tty_write()
2370 process_echoes(tty); in n_tty_write()
2372 add_wait_queue(&tty->write_wait, &wait); in n_tty_write()
2378 if (tty_hung_up_p(file) || (tty->link && !tty->link->count)) { in n_tty_write()
2382 if (O_OPOST(tty)) { in n_tty_write()
2384 num = process_output_block(tty, b, nr); in n_tty_write()
2395 if (process_output(*b, tty) < 0) in n_tty_write()
2399 if (tty->ops->flush_chars) in n_tty_write()
2400 tty->ops->flush_chars(tty); in n_tty_write()
2402 struct n_tty_data *ldata = tty->disc_data; in n_tty_write()
2406 num = tty->ops->write(tty, b, nr); in n_tty_write()
2420 if (tty_io_nonblock(tty, file)) { in n_tty_write()
2424 up_read(&tty->termios_rwsem); in n_tty_write()
2428 down_read(&tty->termios_rwsem); in n_tty_write()
2431 remove_wait_queue(&tty->write_wait, &wait); in n_tty_write()
2432 if (nr && tty->fasync) in n_tty_write()
2433 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in n_tty_write()
2434 up_read(&tty->termios_rwsem); in n_tty_write()
2452 static __poll_t n_tty_poll(struct tty_struct *tty, struct file *file, in n_tty_poll() argument
2457 poll_wait(file, &tty->read_wait, wait); in n_tty_poll()
2458 poll_wait(file, &tty->write_wait, wait); in n_tty_poll()
2459 if (input_available_p(tty, 1)) in n_tty_poll()
2462 tty_buffer_flush_work(tty->port); in n_tty_poll()
2463 if (input_available_p(tty, 1)) in n_tty_poll()
2466 if (tty->ctrl.packet && tty->link->ctrl.pktstatus) in n_tty_poll()
2468 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) in n_tty_poll()
2472 if (tty->ops->write && !tty_is_writelocked(tty) && in n_tty_poll()
2473 tty_chars_in_buffer(tty) < WAKEUP_CHARS && in n_tty_poll()
2474 tty_write_room(tty) > 0) in n_tty_poll()
2498 static int n_tty_ioctl(struct tty_struct *tty, unsigned int cmd, in n_tty_ioctl() argument
2501 struct n_tty_data *ldata = tty->disc_data; in n_tty_ioctl()
2506 return put_user(tty_chars_in_buffer(tty), (int __user *) arg); in n_tty_ioctl()
2508 down_write(&tty->termios_rwsem); in n_tty_ioctl()
2509 if (L_ICANON(tty) && !L_EXTPROC(tty)) in n_tty_ioctl()
2513 up_write(&tty->termios_rwsem); in n_tty_ioctl()
2516 return n_tty_ioctl_helper(tty, cmd, arg); in n_tty_ioctl()