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()
253 tty_set_flow_change(tty, TTY_THROTTLE_SAFE); in n_tty_check_throttle()
256 } while (!tty_throttle_safe(tty)); in n_tty_check_throttle()
258 __tty_set_flow_change(tty, 0); in n_tty_check_throttle()
261 static void n_tty_check_unthrottle(struct tty_struct *tty) in n_tty_check_unthrottle() argument
263 if (tty->driver->type == TTY_DRIVER_TYPE_PTY) { in n_tty_check_unthrottle()
264 if (chars_in_buffer(tty) > TTY_THRESHOLD_UNTHROTTLE) in n_tty_check_unthrottle()
266 n_tty_kick_worker(tty); in n_tty_check_unthrottle()
267 tty_wakeup(tty->link); in n_tty_check_unthrottle()
280 tty_set_flow_change(tty, TTY_UNTHROTTLE_SAFE); in n_tty_check_unthrottle()
281 if (chars_in_buffer(tty) > TTY_THRESHOLD_UNTHROTTLE) in n_tty_check_unthrottle()
284 n_tty_kick_worker(tty); in n_tty_check_unthrottle()
285 } while (!tty_unthrottle_safe(tty)); in n_tty_check_unthrottle()
287 __tty_set_flow_change(tty, 0); in n_tty_check_unthrottle()
331 static void n_tty_packet_mode_flush(struct tty_struct *tty) in n_tty_packet_mode_flush() argument
335 if (tty->link->ctrl.packet) { in n_tty_packet_mode_flush()
336 spin_lock_irqsave(&tty->ctrl.lock, flags); in n_tty_packet_mode_flush()
337 tty->ctrl.pktstatus |= TIOCPKT_FLUSHREAD; in n_tty_packet_mode_flush()
338 spin_unlock_irqrestore(&tty->ctrl.lock, flags); in n_tty_packet_mode_flush()
339 wake_up_interruptible(&tty->link->read_wait); in n_tty_packet_mode_flush()
356 static void n_tty_flush_buffer(struct tty_struct *tty) in n_tty_flush_buffer() argument
358 down_write(&tty->termios_rwsem); in n_tty_flush_buffer()
359 reset_buffer_flags(tty->disc_data); in n_tty_flush_buffer()
360 n_tty_kick_worker(tty); in n_tty_flush_buffer()
362 if (tty->link) in n_tty_flush_buffer()
363 n_tty_packet_mode_flush(tty); in n_tty_flush_buffer()
364 up_write(&tty->termios_rwsem); in n_tty_flush_buffer()
388 static inline int is_continuation(u8 c, const struct tty_struct *tty) in is_continuation() argument
390 return I_IUTF8(tty) && is_utf8_continuation(c); in is_continuation()
412 static int do_output_char(u8 c, struct tty_struct *tty, int space) in do_output_char() argument
414 struct n_tty_data *ldata = tty->disc_data; in do_output_char()
422 if (O_ONLRET(tty)) in do_output_char()
424 if (O_ONLCR(tty)) { in do_output_char()
428 tty->ops->write(tty, "\r\n", 2); in do_output_char()
434 if (O_ONOCR(tty) && ldata->column == 0) in do_output_char()
436 if (O_OCRNL(tty)) { in do_output_char()
438 if (O_ONLRET(tty)) in do_output_char()
446 if (O_TABDLY(tty) == XTABS) { in do_output_char()
450 tty->ops->write(tty, " ", spaces); in do_output_char()
461 if (O_OLCUC(tty)) in do_output_char()
463 if (!is_continuation(c, tty)) in do_output_char()
469 tty_put_char(tty, c); in do_output_char()
486 static int process_output(u8 c, struct tty_struct *tty) in process_output() argument
488 struct n_tty_data *ldata = tty->disc_data; in process_output()
493 space = tty_write_room(tty); in process_output()
494 retval = do_output_char(c, tty, space); in process_output()
521 static ssize_t process_output_block(struct tty_struct *tty, in process_output_block() argument
524 struct n_tty_data *ldata = tty->disc_data; in process_output_block()
531 space = tty_write_room(tty); in process_output_block()
544 if (O_ONLRET(tty)) in process_output_block()
546 if (O_ONLCR(tty)) in process_output_block()
551 if (O_ONOCR(tty) && ldata->column == 0) in process_output_block()
553 if (O_OCRNL(tty)) in process_output_block()
565 if (O_OLCUC(tty)) in process_output_block()
567 if (!is_continuation(c, tty)) in process_output_block()
574 i = tty->ops->write(tty, buf, i); in process_output_block()
580 static int n_tty_process_echo_ops(struct tty_struct *tty, size_t *tail, in n_tty_process_echo_ops() argument
583 struct n_tty_data *ldata = tty->disc_data; in n_tty_process_echo_ops()
624 tty_put_char(tty, '\b'); in n_tty_process_echo_ops()
647 tty_put_char(tty, ECHO_OP_START); in n_tty_process_echo_ops()
663 tty_put_char(tty, '^'); in n_tty_process_echo_ops()
664 tty_put_char(tty, op ^ 0100); in n_tty_process_echo_ops()
696 static size_t __process_echoes(struct tty_struct *tty) in __process_echoes() argument
698 struct n_tty_data *ldata = tty->disc_data; in __process_echoes()
703 old_space = space = tty_write_room(tty); in __process_echoes()
709 int ret = n_tty_process_echo_ops(tty, &tail, space); in __process_echoes()
716 if (O_OPOST(tty)) { in __process_echoes()
717 int retval = do_output_char(c, tty, space); in __process_echoes()
724 tty_put_char(tty, c); in __process_echoes()
750 static void commit_echoes(struct tty_struct *tty) in commit_echoes() argument
752 struct n_tty_data *ldata = tty->disc_data; in commit_echoes()
772 echoed = __process_echoes(tty); in commit_echoes()
775 if (echoed && tty->ops->flush_chars) in commit_echoes()
776 tty->ops->flush_chars(tty); in commit_echoes()
779 static void process_echoes(struct tty_struct *tty) in process_echoes() argument
781 struct n_tty_data *ldata = tty->disc_data; in process_echoes()
789 echoed = __process_echoes(tty); in process_echoes()
792 if (echoed && tty->ops->flush_chars) in process_echoes()
793 tty->ops->flush_chars(tty); in process_echoes()
797 static void flush_echoes(struct tty_struct *tty) in flush_echoes() argument
799 struct n_tty_data *ldata = tty->disc_data; in flush_echoes()
801 if ((!L_ECHO(tty) && !L_ECHONL(tty)) || in flush_echoes()
807 __process_echoes(tty); in flush_echoes()
910 static void echo_char(u8 c, const struct tty_struct *tty) in echo_char() argument
912 struct n_tty_data *ldata = tty->disc_data; in echo_char()
918 if (L_ECHOCTL(tty) && iscntrl(c) && c != '\t') in echo_char()
948 static void eraser(u8 c, const struct tty_struct *tty) in eraser() argument
950 struct n_tty_data *ldata = tty->disc_data; in eraser()
960 if (c == ERASE_CHAR(tty)) in eraser()
962 else if (c == WERASE_CHAR(tty)) in eraser()
965 if (!L_ECHO(tty)) { in eraser()
969 if (!L_ECHOK(tty) || !L_ECHOKE(tty) || !L_ECHOE(tty)) { in eraser()
972 echo_char(KILL_CHAR(tty), tty); in eraser()
974 if (L_ECHOK(tty)) in eraser()
989 } while (is_continuation(c, tty) && in eraser()
993 if (is_continuation(c, tty)) in eraser()
1005 if (L_ECHO(tty)) { in eraser()
1006 if (L_ECHOPRT(tty)) { in eraser()
1012 echo_char(c, tty); in eraser()
1018 } else if (kill_type == ERASE && !L_ECHOE(tty)) { in eraser()
1019 echo_char(ERASE_CHAR(tty), tty); in eraser()
1039 if (L_ECHOCTL(tty)) in eraser()
1041 } else if (!is_continuation(c, tty)) { in eraser()
1047 if (iscntrl(c) && L_ECHOCTL(tty)) { in eraser()
1052 if (!iscntrl(c) || L_ECHOCTL(tty)) { in eraser()
1062 if (ldata->read_head == ldata->canon_head && L_ECHO(tty)) in eraser()
1067 static void __isig(int sig, struct tty_struct *tty) in __isig() argument
1069 struct pid *tty_pgrp = tty_get_pgrp(tty); in __isig()
1090 static void isig(int sig, struct tty_struct *tty) in isig() argument
1092 struct n_tty_data *ldata = tty->disc_data; in isig()
1094 if (L_NOFLSH(tty)) { in isig()
1096 __isig(sig, tty); in isig()
1099 up_read(&tty->termios_rwsem); in isig()
1100 down_write(&tty->termios_rwsem); in isig()
1102 __isig(sig, tty); in isig()
1111 tty_driver_flush_buffer(tty); in isig()
1114 reset_buffer_flags(tty->disc_data); in isig()
1117 if (tty->link) in isig()
1118 n_tty_packet_mode_flush(tty); in isig()
1120 up_write(&tty->termios_rwsem); in isig()
1121 down_read(&tty->termios_rwsem); in isig()
1137 static void n_tty_receive_break(struct tty_struct *tty) in n_tty_receive_break() argument
1139 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_break()
1141 if (I_IGNBRK(tty)) in n_tty_receive_break()
1143 if (I_BRKINT(tty)) { in n_tty_receive_break()
1144 isig(SIGINT, tty); in n_tty_receive_break()
1147 if (I_PARMRK(tty)) { in n_tty_receive_break()
1164 static void n_tty_receive_overrun(const struct tty_struct *tty) in n_tty_receive_overrun() argument
1166 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_overrun()
1170 tty_warn(tty, "%u input overrun(s)\n", ldata->num_overrun); in n_tty_receive_overrun()
1187 static void n_tty_receive_parity_error(const struct tty_struct *tty, in n_tty_receive_parity_error() argument
1190 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_parity_error()
1192 if (I_INPCK(tty)) { in n_tty_receive_parity_error()
1193 if (I_IGNPAR(tty)) in n_tty_receive_parity_error()
1195 if (I_PARMRK(tty)) { in n_tty_receive_parity_error()
1206 n_tty_receive_signal_char(struct tty_struct *tty, int signal, u8 c) in n_tty_receive_signal_char() argument
1208 isig(signal, tty); in n_tty_receive_signal_char()
1209 if (I_IXON(tty)) in n_tty_receive_signal_char()
1210 start_tty(tty); in n_tty_receive_signal_char()
1211 if (L_ECHO(tty)) { in n_tty_receive_signal_char()
1212 echo_char(c, tty); in n_tty_receive_signal_char()
1213 commit_echoes(tty); in n_tty_receive_signal_char()
1215 process_echoes(tty); in n_tty_receive_signal_char()
1218 static bool n_tty_is_char_flow_ctrl(struct tty_struct *tty, u8 c) in n_tty_is_char_flow_ctrl() argument
1220 return c == START_CHAR(tty) || c == STOP_CHAR(tty); in n_tty_is_char_flow_ctrl()
1238 static bool n_tty_receive_char_flow_ctrl(struct tty_struct *tty, u8 c, in n_tty_receive_char_flow_ctrl() argument
1241 if (!n_tty_is_char_flow_ctrl(tty, c)) in n_tty_receive_char_flow_ctrl()
1247 if (c == START_CHAR(tty)) { in n_tty_receive_char_flow_ctrl()
1248 start_tty(tty); in n_tty_receive_char_flow_ctrl()
1249 process_echoes(tty); in n_tty_receive_char_flow_ctrl()
1254 stop_tty(tty); in n_tty_receive_char_flow_ctrl()
1258 static void n_tty_receive_handle_newline(struct tty_struct *tty, u8 c) in n_tty_receive_handle_newline() argument
1260 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_handle_newline()
1265 kill_fasync(&tty->fasync, SIGIO, POLL_IN); in n_tty_receive_handle_newline()
1266 wake_up_interruptible_poll(&tty->read_wait, EPOLLIN | EPOLLRDNORM); in n_tty_receive_handle_newline()
1269 static bool n_tty_receive_char_canon(struct tty_struct *tty, u8 c) in n_tty_receive_char_canon() argument
1271 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_char_canon()
1273 if (c == ERASE_CHAR(tty) || c == KILL_CHAR(tty) || in n_tty_receive_char_canon()
1274 (c == WERASE_CHAR(tty) && L_IEXTEN(tty))) { in n_tty_receive_char_canon()
1275 eraser(c, tty); in n_tty_receive_char_canon()
1276 commit_echoes(tty); in n_tty_receive_char_canon()
1281 if (c == LNEXT_CHAR(tty) && L_IEXTEN(tty)) { in n_tty_receive_char_canon()
1283 if (L_ECHO(tty)) { in n_tty_receive_char_canon()
1285 if (L_ECHOCTL(tty)) { in n_tty_receive_char_canon()
1288 commit_echoes(tty); in n_tty_receive_char_canon()
1295 if (c == REPRINT_CHAR(tty) && L_ECHO(tty) && L_IEXTEN(tty)) { in n_tty_receive_char_canon()
1299 echo_char(c, tty); in n_tty_receive_char_canon()
1302 echo_char(read_buf(ldata, tail), tty); in n_tty_receive_char_canon()
1305 commit_echoes(tty); in n_tty_receive_char_canon()
1311 if (L_ECHO(tty) || L_ECHONL(tty)) { in n_tty_receive_char_canon()
1313 commit_echoes(tty); in n_tty_receive_char_canon()
1315 n_tty_receive_handle_newline(tty, c); in n_tty_receive_char_canon()
1320 if (c == EOF_CHAR(tty)) { in n_tty_receive_char_canon()
1322 n_tty_receive_handle_newline(tty, c); in n_tty_receive_char_canon()
1327 if ((c == EOL_CHAR(tty)) || in n_tty_receive_char_canon()
1328 (c == EOL2_CHAR(tty) && L_IEXTEN(tty))) { in n_tty_receive_char_canon()
1332 if (L_ECHO(tty)) { in n_tty_receive_char_canon()
1336 echo_char(c, tty); in n_tty_receive_char_canon()
1337 commit_echoes(tty); in n_tty_receive_char_canon()
1343 if (c == '\377' && I_PARMRK(tty)) in n_tty_receive_char_canon()
1346 n_tty_receive_handle_newline(tty, c); in n_tty_receive_char_canon()
1354 static void n_tty_receive_char_special(struct tty_struct *tty, u8 c, in n_tty_receive_char_special() argument
1357 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_char_special()
1359 if (I_IXON(tty) && n_tty_receive_char_flow_ctrl(tty, c, lookahead_done)) in n_tty_receive_char_special()
1362 if (L_ISIG(tty)) { in n_tty_receive_char_special()
1363 if (c == INTR_CHAR(tty)) { in n_tty_receive_char_special()
1364 n_tty_receive_signal_char(tty, SIGINT, c); in n_tty_receive_char_special()
1366 } else if (c == QUIT_CHAR(tty)) { in n_tty_receive_char_special()
1367 n_tty_receive_signal_char(tty, SIGQUIT, c); in n_tty_receive_char_special()
1369 } else if (c == SUSP_CHAR(tty)) { in n_tty_receive_char_special()
1370 n_tty_receive_signal_char(tty, SIGTSTP, c); in n_tty_receive_char_special()
1375 if (tty->flow.stopped && !tty->flow.tco_stopped && I_IXON(tty) && I_IXANY(tty)) { in n_tty_receive_char_special()
1376 start_tty(tty); in n_tty_receive_char_special()
1377 process_echoes(tty); in n_tty_receive_char_special()
1381 if (I_IGNCR(tty)) in n_tty_receive_char_special()
1383 if (I_ICRNL(tty)) in n_tty_receive_char_special()
1385 } else if (c == '\n' && I_INLCR(tty)) in n_tty_receive_char_special()
1388 if (ldata->icanon && n_tty_receive_char_canon(tty, c)) in n_tty_receive_char_special()
1391 if (L_ECHO(tty)) { in n_tty_receive_char_special()
1399 echo_char(c, tty); in n_tty_receive_char_special()
1401 commit_echoes(tty); in n_tty_receive_char_special()
1405 if (c == '\377' && I_PARMRK(tty)) in n_tty_receive_char_special()
1423 static void n_tty_receive_char(struct tty_struct *tty, u8 c) in n_tty_receive_char() argument
1425 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_char()
1427 if (tty->flow.stopped && !tty->flow.tco_stopped && I_IXON(tty) && I_IXANY(tty)) { in n_tty_receive_char()
1428 start_tty(tty); in n_tty_receive_char()
1429 process_echoes(tty); in n_tty_receive_char()
1431 if (L_ECHO(tty)) { in n_tty_receive_char()
1436 echo_char(c, tty); in n_tty_receive_char()
1437 commit_echoes(tty); in n_tty_receive_char()
1440 if (c == '\377' && I_PARMRK(tty)) in n_tty_receive_char()
1445 static void n_tty_receive_char_closing(struct tty_struct *tty, u8 c, in n_tty_receive_char_closing() argument
1448 if (I_ISTRIP(tty)) in n_tty_receive_char_closing()
1450 if (I_IUCLC(tty) && L_IEXTEN(tty)) in n_tty_receive_char_closing()
1453 if (I_IXON(tty)) { in n_tty_receive_char_closing()
1454 if (!n_tty_receive_char_flow_ctrl(tty, c, lookahead_done) && in n_tty_receive_char_closing()
1455 tty->flow.stopped && !tty->flow.tco_stopped && I_IXANY(tty) && in n_tty_receive_char_closing()
1456 c != INTR_CHAR(tty) && c != QUIT_CHAR(tty) && in n_tty_receive_char_closing()
1457 c != SUSP_CHAR(tty)) { in n_tty_receive_char_closing()
1458 start_tty(tty); in n_tty_receive_char_closing()
1459 process_echoes(tty); in n_tty_receive_char_closing()
1465 n_tty_receive_char_flagged(struct tty_struct *tty, u8 c, u8 flag) in n_tty_receive_char_flagged() argument
1469 n_tty_receive_break(tty); in n_tty_receive_char_flagged()
1473 n_tty_receive_parity_error(tty, c); in n_tty_receive_char_flagged()
1476 n_tty_receive_overrun(tty); in n_tty_receive_char_flagged()
1479 tty_err(tty, "unknown flag %u\n", flag); in n_tty_receive_char_flagged()
1485 n_tty_receive_char_lnext(struct tty_struct *tty, u8 c, u8 flag) in n_tty_receive_char_lnext() argument
1487 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_char_lnext()
1491 if (I_ISTRIP(tty)) in n_tty_receive_char_lnext()
1493 if (I_IUCLC(tty) && L_IEXTEN(tty)) in n_tty_receive_char_lnext()
1495 n_tty_receive_char(tty, c); in n_tty_receive_char_lnext()
1497 n_tty_receive_char_flagged(tty, c, flag); in n_tty_receive_char_lnext()
1501 static void n_tty_lookahead_flow_ctrl(struct tty_struct *tty, const u8 *cp, in n_tty_lookahead_flow_ctrl() argument
1504 struct n_tty_data *ldata = tty->disc_data; in n_tty_lookahead_flow_ctrl()
1509 if (!I_IXON(tty)) in n_tty_lookahead_flow_ctrl()
1516 n_tty_receive_char_flow_ctrl(tty, *cp, false); in n_tty_lookahead_flow_ctrl()
1522 n_tty_receive_buf_real_raw(const struct tty_struct *tty, const u8 *cp, in n_tty_receive_buf_real_raw() argument
1525 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_real_raw()
1541 n_tty_receive_buf_raw(struct tty_struct *tty, const u8 *cp, const u8 *fp, in n_tty_receive_buf_raw() argument
1544 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_raw()
1553 n_tty_receive_char_flagged(tty, *cp++, flag); in n_tty_receive_buf_raw()
1558 n_tty_receive_buf_closing(struct tty_struct *tty, const u8 *cp, const u8 *fp, in n_tty_receive_buf_closing() argument
1567 n_tty_receive_char_closing(tty, *cp++, lookahead_done); in n_tty_receive_buf_closing()
1571 static void n_tty_receive_buf_standard(struct tty_struct *tty, const u8 *cp, in n_tty_receive_buf_standard() argument
1575 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_standard()
1585 n_tty_receive_char_lnext(tty, c, flag); in n_tty_receive_buf_standard()
1590 n_tty_receive_char_flagged(tty, c, flag); in n_tty_receive_buf_standard()
1594 if (I_ISTRIP(tty)) in n_tty_receive_buf_standard()
1596 if (I_IUCLC(tty) && L_IEXTEN(tty)) in n_tty_receive_buf_standard()
1598 if (L_EXTPROC(tty)) { in n_tty_receive_buf_standard()
1604 n_tty_receive_char_special(tty, c, lookahead_done); in n_tty_receive_buf_standard()
1606 n_tty_receive_char(tty, c); in n_tty_receive_buf_standard()
1610 static void __receive_buf(struct tty_struct *tty, const u8 *cp, const u8 *fp, in __receive_buf() argument
1613 struct n_tty_data *ldata = tty->disc_data; in __receive_buf()
1614 bool preops = I_ISTRIP(tty) || (I_IUCLC(tty) && L_IEXTEN(tty)); in __receive_buf()
1618 n_tty_receive_buf_real_raw(tty, cp, count); in __receive_buf()
1619 else if (ldata->raw || (L_EXTPROC(tty) && !preops)) in __receive_buf()
1620 n_tty_receive_buf_raw(tty, cp, fp, count); in __receive_buf()
1621 else if (tty->closing && !L_EXTPROC(tty)) { in __receive_buf()
1623 n_tty_receive_buf_closing(tty, cp, fp, la_count, true); in __receive_buf()
1630 n_tty_receive_buf_closing(tty, cp, fp, count, false); in __receive_buf()
1633 n_tty_receive_buf_standard(tty, cp, fp, la_count, true); in __receive_buf()
1640 n_tty_receive_buf_standard(tty, cp, fp, count, false); in __receive_buf()
1642 flush_echoes(tty); in __receive_buf()
1643 if (tty->ops->flush_chars) in __receive_buf()
1644 tty->ops->flush_chars(tty); in __receive_buf()
1649 if (ldata->icanon && !L_EXTPROC(tty)) in __receive_buf()
1656 kill_fasync(&tty->fasync, SIGIO, POLL_IN); in __receive_buf()
1657 wake_up_interruptible_poll(&tty->read_wait, EPOLLIN | EPOLLRDNORM); in __receive_buf()
1695 n_tty_receive_buf_common(struct tty_struct *tty, const u8 *cp, const u8 *fp, in n_tty_receive_buf_common() argument
1698 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_common()
1702 down_read(&tty->termios_rwsem); in n_tty_receive_buf_common()
1721 if (I_PARMRK(tty)) in n_tty_receive_buf_common()
1739 __receive_buf(tty, cp, fp, n); in n_tty_receive_buf_common()
1746 } while (!test_bit(TTY_LDISC_CHANGING, &tty->flags)); in n_tty_receive_buf_common()
1748 tty->receive_room = room; in n_tty_receive_buf_common()
1751 if (tty->driver->type == TTY_DRIVER_TYPE_PTY) { in n_tty_receive_buf_common()
1753 tty_set_flow_change(tty, TTY_UNTHROTTLE_SAFE); in n_tty_receive_buf_common()
1754 tty_unthrottle_safe(tty); in n_tty_receive_buf_common()
1755 __tty_set_flow_change(tty, 0); in n_tty_receive_buf_common()
1758 n_tty_check_throttle(tty); in n_tty_receive_buf_common()
1767 if (!chars_in_buffer(tty)) in n_tty_receive_buf_common()
1768 n_tty_kick_worker(tty); in n_tty_receive_buf_common()
1771 up_read(&tty->termios_rwsem); in n_tty_receive_buf_common()
1776 static void n_tty_receive_buf(struct tty_struct *tty, const u8 *cp, in n_tty_receive_buf() argument
1779 n_tty_receive_buf_common(tty, cp, fp, count, false); in n_tty_receive_buf()
1782 static size_t n_tty_receive_buf2(struct tty_struct *tty, const u8 *cp, in n_tty_receive_buf2() argument
1785 return n_tty_receive_buf_common(tty, cp, fp, count, true); in n_tty_receive_buf2()
1800 static void n_tty_set_termios(struct tty_struct *tty, const struct ktermios *old) in n_tty_set_termios() argument
1802 struct n_tty_data *ldata = tty->disc_data; in n_tty_set_termios()
1804 if (!old || (old->c_lflag ^ tty->termios.c_lflag) & (ICANON | EXTPROC)) { in n_tty_set_termios()
1807 if (!L_ICANON(tty) || !read_cnt(ldata)) { in n_tty_set_termios()
1820 ldata->icanon = (L_ICANON(tty) != 0); in n_tty_set_termios()
1822 if (I_ISTRIP(tty) || I_IUCLC(tty) || I_IGNCR(tty) || in n_tty_set_termios()
1823 I_ICRNL(tty) || I_INLCR(tty) || L_ICANON(tty) || in n_tty_set_termios()
1824 I_IXON(tty) || L_ISIG(tty) || L_ECHO(tty) || in n_tty_set_termios()
1825 I_PARMRK(tty)) { in n_tty_set_termios()
1828 if (I_IGNCR(tty) || I_ICRNL(tty)) in n_tty_set_termios()
1830 if (I_INLCR(tty)) in n_tty_set_termios()
1833 if (L_ICANON(tty)) { in n_tty_set_termios()
1834 set_bit(ERASE_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1835 set_bit(KILL_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1836 set_bit(EOF_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1838 set_bit(EOL_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1839 if (L_IEXTEN(tty)) { in n_tty_set_termios()
1840 set_bit(WERASE_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1841 set_bit(LNEXT_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1842 set_bit(EOL2_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1843 if (L_ECHO(tty)) in n_tty_set_termios()
1844 set_bit(REPRINT_CHAR(tty), in n_tty_set_termios()
1848 if (I_IXON(tty)) { in n_tty_set_termios()
1849 set_bit(START_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1850 set_bit(STOP_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1852 if (L_ISIG(tty)) { in n_tty_set_termios()
1853 set_bit(INTR_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1854 set_bit(QUIT_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1855 set_bit(SUSP_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1862 if ((I_IGNBRK(tty) || (!I_BRKINT(tty) && !I_PARMRK(tty))) && in n_tty_set_termios()
1863 (I_IGNPAR(tty) || !I_INPCK(tty)) && in n_tty_set_termios()
1864 (tty->driver->flags & TTY_DRIVER_REAL_RAW)) in n_tty_set_termios()
1873 if (!I_IXON(tty) && old && (old->c_iflag & IXON) && !tty->flow.tco_stopped) { in n_tty_set_termios()
1874 start_tty(tty); in n_tty_set_termios()
1875 process_echoes(tty); in n_tty_set_termios()
1879 wake_up_interruptible(&tty->write_wait); in n_tty_set_termios()
1880 wake_up_interruptible(&tty->read_wait); in n_tty_set_termios()
1891 static void n_tty_close(struct tty_struct *tty) in n_tty_close() argument
1893 struct n_tty_data *ldata = tty->disc_data; in n_tty_close()
1895 if (tty->link) in n_tty_close()
1896 n_tty_packet_mode_flush(tty); in n_tty_close()
1898 down_write(&tty->termios_rwsem); in n_tty_close()
1900 tty->disc_data = NULL; in n_tty_close()
1901 up_write(&tty->termios_rwsem); in n_tty_close()
1912 static int n_tty_open(struct tty_struct *tty) in n_tty_open() argument
1925 tty->disc_data = ldata; in n_tty_open()
1926 tty->closing = 0; in n_tty_open()
1928 clear_bit(TTY_LDISC_HALTED, &tty->flags); in n_tty_open()
1929 n_tty_set_termios(tty, NULL); in n_tty_open()
1930 tty_unthrottle(tty); in n_tty_open()
1934 static inline int input_available_p(const struct tty_struct *tty, int poll) in input_available_p() argument
1936 const struct n_tty_data *ldata = tty->disc_data; in input_available_p()
1937 int amt = poll && !TIME_CHAR(tty) && MIN_CHAR(tty) ? MIN_CHAR(tty) : 1; in input_available_p()
1939 if (ldata->icanon && !L_EXTPROC(tty)) in input_available_p()
1963 static bool copy_from_read_buf(const struct tty_struct *tty, u8 **kbp, in copy_from_read_buf() argument
1967 struct n_tty_data *ldata = tty->disc_data; in copy_from_read_buf()
1979 is_eof = n == 1 && *from == EOF_CHAR(tty); in copy_from_read_buf()
1980 tty_audit_add_data(tty, from, n); in copy_from_read_buf()
1981 zero_buffer(tty, from, n); in copy_from_read_buf()
1985 if (L_EXTPROC(tty) && ldata->icanon && is_eof && in copy_from_read_buf()
2018 static bool canon_copy_from_read_buf(const struct tty_struct *tty, u8 **kbp, in canon_copy_from_read_buf() argument
2021 struct n_tty_data *ldata = tty->disc_data; in canon_copy_from_read_buf()
2060 tty_copy(tty, *kbp, tail, n); in canon_copy_from_read_buf()
2123 static int job_control(struct tty_struct *tty, struct file *file) in job_control() argument
2133 return __tty_check_change(tty, SIGTTIN); in job_control()
2157 static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, u8 *kbuf, in n_tty_read() argument
2160 struct n_tty_data *ldata = tty->disc_data; in n_tty_read()
2176 if (ldata->icanon && !L_EXTPROC(tty)) { in n_tty_read()
2184 else if (canon_copy_from_read_buf(tty, &kb, &nr)) in n_tty_read()
2187 if (copy_from_read_buf(tty, &kb, &nr)) in n_tty_read()
2192 n_tty_kick_worker(tty); in n_tty_read()
2193 n_tty_check_unthrottle(tty); in n_tty_read()
2194 up_read(&tty->termios_rwsem); in n_tty_read()
2200 retval = job_control(tty, file); in n_tty_read()
2215 down_read(&tty->termios_rwsem); in n_tty_read()
2220 minimum = MIN_CHAR(tty); in n_tty_read()
2222 time = (HZ / 10) * TIME_CHAR(tty); in n_tty_read()
2224 timeout = (HZ / 10) * TIME_CHAR(tty); in n_tty_read()
2229 packet = tty->ctrl.packet; in n_tty_read()
2232 add_wait_queue(&tty->read_wait, &wait); in n_tty_read()
2235 if (packet && tty->link->ctrl.pktstatus) { in n_tty_read()
2239 spin_lock_irq(&tty->link->ctrl.lock); in n_tty_read()
2240 cs = tty->link->ctrl.pktstatus; in n_tty_read()
2241 tty->link->ctrl.pktstatus = 0; in n_tty_read()
2242 spin_unlock_irq(&tty->link->ctrl.lock); in n_tty_read()
2248 if (!input_available_p(tty, 0)) { in n_tty_read()
2249 up_read(&tty->termios_rwsem); in n_tty_read()
2250 tty_buffer_flush_work(tty->port); in n_tty_read()
2251 down_read(&tty->termios_rwsem); in n_tty_read()
2252 if (!input_available_p(tty, 0)) { in n_tty_read()
2253 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) { in n_tty_read()
2263 if (test_bit(TTY_HUPPING, &tty->flags)) in n_tty_read()
2267 if (tty_io_nonblock(tty, file)) { in n_tty_read()
2275 up_read(&tty->termios_rwsem); in n_tty_read()
2280 down_read(&tty->termios_rwsem); in n_tty_read()
2285 if (ldata->icanon && !L_EXTPROC(tty)) { in n_tty_read()
2286 if (canon_copy_from_read_buf(tty, &kb, &nr)) in n_tty_read()
2304 if (copy_from_read_buf(tty, &kb, &nr) && kb - kbuf >= minimum) { in n_tty_read()
2306 remove_wait_queue(&tty->read_wait, &wait); in n_tty_read()
2312 n_tty_check_unthrottle(tty); in n_tty_read()
2325 n_tty_kick_worker(tty); in n_tty_read()
2327 up_read(&tty->termios_rwsem); in n_tty_read()
2329 remove_wait_queue(&tty->read_wait, &wait); in n_tty_read()
2358 static ssize_t n_tty_write(struct tty_struct *tty, struct file *file, in n_tty_write() argument
2366 if (L_TOSTOP(tty) && file->f_op->write_iter != redirected_tty_write) { in n_tty_write()
2367 retval = tty_check_change(tty); in n_tty_write()
2372 down_read(&tty->termios_rwsem); in n_tty_write()
2375 process_echoes(tty); in n_tty_write()
2377 add_wait_queue(&tty->write_wait, &wait); in n_tty_write()
2383 if (tty_hung_up_p(file) || (tty->link && !tty->link->count)) { in n_tty_write()
2387 if (O_OPOST(tty)) { in n_tty_write()
2389 num = process_output_block(tty, b, nr); in n_tty_write()
2400 if (process_output(*b, tty) < 0) in n_tty_write()
2404 if (tty->ops->flush_chars) in n_tty_write()
2405 tty->ops->flush_chars(tty); in n_tty_write()
2407 struct n_tty_data *ldata = tty->disc_data; in n_tty_write()
2411 num = tty->ops->write(tty, b, nr); in n_tty_write()
2425 if (tty_io_nonblock(tty, file)) { in n_tty_write()
2429 up_read(&tty->termios_rwsem); in n_tty_write()
2433 down_read(&tty->termios_rwsem); in n_tty_write()
2436 remove_wait_queue(&tty->write_wait, &wait); in n_tty_write()
2437 if (nr && tty->fasync) in n_tty_write()
2438 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in n_tty_write()
2439 up_read(&tty->termios_rwsem); in n_tty_write()
2457 static __poll_t n_tty_poll(struct tty_struct *tty, struct file *file, in n_tty_poll() argument
2462 poll_wait(file, &tty->read_wait, wait); in n_tty_poll()
2463 poll_wait(file, &tty->write_wait, wait); in n_tty_poll()
2464 if (input_available_p(tty, 1)) in n_tty_poll()
2467 tty_buffer_flush_work(tty->port); in n_tty_poll()
2468 if (input_available_p(tty, 1)) in n_tty_poll()
2471 if (tty->ctrl.packet && tty->link->ctrl.pktstatus) in n_tty_poll()
2473 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) in n_tty_poll()
2477 if (tty->ops->write && !tty_is_writelocked(tty) && in n_tty_poll()
2478 tty_chars_in_buffer(tty) < WAKEUP_CHARS && in n_tty_poll()
2479 tty_write_room(tty) > 0) in n_tty_poll()
2503 static int n_tty_ioctl(struct tty_struct *tty, unsigned int cmd, in n_tty_ioctl() argument
2506 struct n_tty_data *ldata = tty->disc_data; in n_tty_ioctl()
2511 return put_user(tty_chars_in_buffer(tty), (int __user *) arg); in n_tty_ioctl()
2513 down_write(&tty->termios_rwsem); in n_tty_ioctl()
2514 if (L_ICANON(tty) && !L_EXTPROC(tty)) in n_tty_ioctl()
2518 up_write(&tty->termios_rwsem); in n_tty_ioctl()
2521 return n_tty_ioctl_helper(tty, cmd, arg); in n_tty_ioctl()