Lines Matching refs:tty
155 static void zero_buffer(const struct tty_struct *tty, u8 *buffer, size_t size) in zero_buffer() argument
157 if (L_ICANON(tty) && !L_ECHO(tty)) in zero_buffer()
161 static void tty_copy(const struct tty_struct *tty, void *to, size_t tail, in tty_copy() argument
164 struct n_tty_data *ldata = tty->disc_data; in tty_copy()
169 tty_audit_add_data(tty, from, size); in tty_copy()
171 zero_buffer(tty, from, size); in tty_copy()
177 tty_audit_add_data(tty, from, n); in tty_copy()
179 zero_buffer(tty, from, n); in tty_copy()
193 static void n_tty_kick_worker(const struct tty_struct *tty) in n_tty_kick_worker() argument
195 struct n_tty_data *ldata = tty->disc_data; in n_tty_kick_worker()
201 WARN_RATELIMIT(tty->port->itty == NULL, in n_tty_kick_worker()
207 WARN_RATELIMIT(test_bit(TTY_LDISC_HALTED, &tty->flags), in n_tty_kick_worker()
209 tty_buffer_restart_work(tty->port); in n_tty_kick_worker()
213 static ssize_t chars_in_buffer(const struct tty_struct *tty) in chars_in_buffer() argument
215 const struct n_tty_data *ldata = tty->disc_data; in chars_in_buffer()
228 static void n_tty_write_wakeup(struct tty_struct *tty) in n_tty_write_wakeup() argument
230 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in n_tty_write_wakeup()
231 kill_fasync(&tty->fasync, SIGIO, POLL_OUT); in n_tty_write_wakeup()
234 static void n_tty_check_throttle(struct tty_struct *tty) in n_tty_check_throttle() argument
236 struct n_tty_data *ldata = tty->disc_data; in n_tty_check_throttle()
247 tty_set_flow_change(tty, TTY_THROTTLE_SAFE); in n_tty_check_throttle()
250 } while (!tty_throttle_safe(tty)); in n_tty_check_throttle()
252 __tty_set_flow_change(tty, 0); in n_tty_check_throttle()
255 static void n_tty_check_unthrottle(struct tty_struct *tty) in n_tty_check_unthrottle() argument
257 if (tty->driver->type == TTY_DRIVER_TYPE_PTY) { in n_tty_check_unthrottle()
258 if (chars_in_buffer(tty) > TTY_THRESHOLD_UNTHROTTLE) in n_tty_check_unthrottle()
260 n_tty_kick_worker(tty); in n_tty_check_unthrottle()
261 tty_wakeup(tty->link); in n_tty_check_unthrottle()
274 tty_set_flow_change(tty, TTY_UNTHROTTLE_SAFE); in n_tty_check_unthrottle()
275 if (chars_in_buffer(tty) > TTY_THRESHOLD_UNTHROTTLE) in n_tty_check_unthrottle()
278 n_tty_kick_worker(tty); in n_tty_check_unthrottle()
279 } while (!tty_unthrottle_safe(tty)); in n_tty_check_unthrottle()
281 __tty_set_flow_change(tty, 0); in n_tty_check_unthrottle()
325 static void n_tty_packet_mode_flush(struct tty_struct *tty) in n_tty_packet_mode_flush() argument
327 if (tty->link->ctrl.packet) { in n_tty_packet_mode_flush()
328 scoped_guard(spinlock_irqsave, &tty->ctrl.lock) in n_tty_packet_mode_flush()
329 tty->ctrl.pktstatus |= TIOCPKT_FLUSHREAD; in n_tty_packet_mode_flush()
330 wake_up_interruptible(&tty->link->read_wait); in n_tty_packet_mode_flush()
347 static void n_tty_flush_buffer(struct tty_struct *tty) in n_tty_flush_buffer() argument
349 guard(rwsem_write)(&tty->termios_rwsem); in n_tty_flush_buffer()
350 reset_buffer_flags(tty->disc_data); in n_tty_flush_buffer()
351 n_tty_kick_worker(tty); in n_tty_flush_buffer()
353 if (tty->link) in n_tty_flush_buffer()
354 n_tty_packet_mode_flush(tty); in n_tty_flush_buffer()
378 static inline int is_continuation(u8 c, const struct tty_struct *tty) in is_continuation() argument
380 return I_IUTF8(tty) && is_utf8_continuation(c); in is_continuation()
402 static int do_output_char(u8 c, struct tty_struct *tty, int space) in do_output_char() argument
404 struct n_tty_data *ldata = tty->disc_data; in do_output_char()
412 if (O_ONLRET(tty)) in do_output_char()
414 if (O_ONLCR(tty)) { in do_output_char()
418 tty->ops->write(tty, "\r\n", 2); in do_output_char()
424 if (O_ONOCR(tty) && ldata->column == 0) in do_output_char()
426 if (O_OCRNL(tty)) { in do_output_char()
428 if (O_ONLRET(tty)) in do_output_char()
436 if (O_TABDLY(tty) == XTABS) { in do_output_char()
440 tty->ops->write(tty, " ", spaces); in do_output_char()
451 if (O_OLCUC(tty)) in do_output_char()
453 if (!is_continuation(c, tty)) in do_output_char()
459 tty_put_char(tty, c); in do_output_char()
476 static int process_output(u8 c, struct tty_struct *tty) in process_output() argument
478 struct n_tty_data *ldata = tty->disc_data; in process_output()
482 if (do_output_char(c, tty, tty_write_room(tty)) < 0) in process_output()
506 static ssize_t process_output_block(struct tty_struct *tty, in process_output_block() argument
509 struct n_tty_data *ldata = tty->disc_data; in process_output_block()
515 space = tty_write_room(tty); in process_output_block()
527 if (O_ONLRET(tty)) in process_output_block()
529 if (O_ONLCR(tty)) in process_output_block()
534 if (O_ONOCR(tty) && ldata->column == 0) in process_output_block()
536 if (O_OCRNL(tty)) in process_output_block()
548 if (O_OLCUC(tty)) in process_output_block()
550 if (!is_continuation(c, tty)) in process_output_block()
557 return tty->ops->write(tty, buf, i); in process_output_block()
560 static int n_tty_process_echo_ops(struct tty_struct *tty, size_t *tail, in n_tty_process_echo_ops() argument
563 struct n_tty_data *ldata = tty->disc_data; in n_tty_process_echo_ops()
604 tty_put_char(tty, '\b'); in n_tty_process_echo_ops()
627 tty_put_char(tty, ECHO_OP_START); in n_tty_process_echo_ops()
643 tty_put_char(tty, '^'); in n_tty_process_echo_ops()
644 tty_put_char(tty, op ^ 0100); in n_tty_process_echo_ops()
676 static size_t __process_echoes(struct tty_struct *tty) in __process_echoes() argument
678 struct n_tty_data *ldata = tty->disc_data; in __process_echoes()
683 old_space = space = tty_write_room(tty); in __process_echoes()
689 int ret = n_tty_process_echo_ops(tty, &tail, space); in __process_echoes()
696 if (O_OPOST(tty)) { in __process_echoes()
697 int retval = do_output_char(c, tty, space); in __process_echoes()
704 tty_put_char(tty, c); in __process_echoes()
730 static void commit_echoes(struct tty_struct *tty) in commit_echoes() argument
732 struct n_tty_data *ldata = tty->disc_data; in commit_echoes()
750 echoed = __process_echoes(tty); in commit_echoes()
753 if (echoed && tty->ops->flush_chars) in commit_echoes()
754 tty->ops->flush_chars(tty); in commit_echoes()
757 static void process_echoes(struct tty_struct *tty) in process_echoes() argument
759 struct n_tty_data *ldata = tty->disc_data; in process_echoes()
767 echoed = __process_echoes(tty); in process_echoes()
770 if (echoed && tty->ops->flush_chars) in process_echoes()
771 tty->ops->flush_chars(tty); in process_echoes()
775 static void flush_echoes(struct tty_struct *tty) in flush_echoes() argument
777 struct n_tty_data *ldata = tty->disc_data; in flush_echoes()
779 if ((!L_ECHO(tty) && !L_ECHONL(tty)) || in flush_echoes()
785 __process_echoes(tty); in flush_echoes()
887 static void echo_char(u8 c, const struct tty_struct *tty) in echo_char() argument
889 struct n_tty_data *ldata = tty->disc_data; in echo_char()
895 if (L_ECHOCTL(tty) && iscntrl(c) && c != '\t') in echo_char()
925 static void eraser(u8 c, const struct tty_struct *tty) in eraser() argument
927 struct n_tty_data *ldata = tty->disc_data; in eraser()
937 if (c == ERASE_CHAR(tty)) in eraser()
939 else if (c == WERASE_CHAR(tty)) in eraser()
942 if (!L_ECHO(tty)) { in eraser()
946 if (!L_ECHOK(tty) || !L_ECHOKE(tty) || !L_ECHOE(tty)) { in eraser()
949 echo_char(KILL_CHAR(tty), tty); in eraser()
951 if (L_ECHOK(tty)) in eraser()
966 } while (is_continuation(c, tty) && in eraser()
970 if (is_continuation(c, tty)) in eraser()
982 if (L_ECHO(tty)) { in eraser()
983 if (L_ECHOPRT(tty)) { in eraser()
989 echo_char(c, tty); in eraser()
995 } else if (kill_type == ERASE && !L_ECHOE(tty)) { in eraser()
996 echo_char(ERASE_CHAR(tty), tty); in eraser()
1016 if (L_ECHOCTL(tty)) in eraser()
1018 } else if (!is_continuation(c, tty)) { in eraser()
1024 if (iscntrl(c) && L_ECHOCTL(tty)) { in eraser()
1029 if (!iscntrl(c) || L_ECHOCTL(tty)) { in eraser()
1039 if (ldata->read_head == ldata->canon_head && L_ECHO(tty)) in eraser()
1044 static void __isig(int sig, struct tty_struct *tty) in __isig() argument
1046 struct pid *tty_pgrp = tty_get_pgrp(tty); in __isig()
1067 static void isig(int sig, struct tty_struct *tty) in isig() argument
1069 struct n_tty_data *ldata = tty->disc_data; in isig()
1071 if (L_NOFLSH(tty)) { in isig()
1073 __isig(sig, tty); in isig()
1078 up_read(&tty->termios_rwsem); in isig()
1079 scoped_guard(rwsem_write, &tty->termios_rwsem) { in isig()
1080 __isig(sig, tty); in isig()
1089 tty_driver_flush_buffer(tty); in isig()
1092 reset_buffer_flags(tty->disc_data); in isig()
1095 if (tty->link) in isig()
1096 n_tty_packet_mode_flush(tty); in isig()
1098 down_read(&tty->termios_rwsem); in isig()
1113 static void n_tty_receive_break(struct tty_struct *tty) in n_tty_receive_break() argument
1115 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_break()
1117 if (I_IGNBRK(tty)) in n_tty_receive_break()
1119 if (I_BRKINT(tty)) { in n_tty_receive_break()
1120 isig(SIGINT, tty); in n_tty_receive_break()
1123 if (I_PARMRK(tty)) { in n_tty_receive_break()
1140 static void n_tty_receive_overrun(const struct tty_struct *tty) in n_tty_receive_overrun() argument
1142 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_overrun()
1146 tty_warn(tty, "%u input overrun(s)\n", ldata->num_overrun); in n_tty_receive_overrun()
1163 static void n_tty_receive_parity_error(const struct tty_struct *tty, in n_tty_receive_parity_error() argument
1166 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_parity_error()
1168 if (I_INPCK(tty)) { in n_tty_receive_parity_error()
1169 if (I_IGNPAR(tty)) in n_tty_receive_parity_error()
1171 if (I_PARMRK(tty)) { in n_tty_receive_parity_error()
1182 n_tty_receive_signal_char(struct tty_struct *tty, int signal, u8 c) in n_tty_receive_signal_char() argument
1184 isig(signal, tty); in n_tty_receive_signal_char()
1185 if (I_IXON(tty)) in n_tty_receive_signal_char()
1186 start_tty(tty); in n_tty_receive_signal_char()
1187 if (L_ECHO(tty)) { in n_tty_receive_signal_char()
1188 echo_char(c, tty); in n_tty_receive_signal_char()
1189 commit_echoes(tty); in n_tty_receive_signal_char()
1191 process_echoes(tty); in n_tty_receive_signal_char()
1194 static bool n_tty_is_char_flow_ctrl(struct tty_struct *tty, u8 c) in n_tty_is_char_flow_ctrl() argument
1196 return c == START_CHAR(tty) || c == STOP_CHAR(tty); in n_tty_is_char_flow_ctrl()
1214 static bool n_tty_receive_char_flow_ctrl(struct tty_struct *tty, u8 c, in n_tty_receive_char_flow_ctrl() argument
1217 if (!n_tty_is_char_flow_ctrl(tty, c)) in n_tty_receive_char_flow_ctrl()
1223 if (c == START_CHAR(tty)) { in n_tty_receive_char_flow_ctrl()
1224 start_tty(tty); in n_tty_receive_char_flow_ctrl()
1225 process_echoes(tty); in n_tty_receive_char_flow_ctrl()
1230 stop_tty(tty); in n_tty_receive_char_flow_ctrl()
1234 static void n_tty_receive_handle_newline(struct tty_struct *tty, u8 c) in n_tty_receive_handle_newline() argument
1236 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_handle_newline()
1241 kill_fasync(&tty->fasync, SIGIO, POLL_IN); in n_tty_receive_handle_newline()
1242 wake_up_interruptible_poll(&tty->read_wait, EPOLLIN | EPOLLRDNORM); in n_tty_receive_handle_newline()
1245 static bool n_tty_receive_char_canon(struct tty_struct *tty, u8 c) in n_tty_receive_char_canon() argument
1247 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_char_canon()
1249 if (c == ERASE_CHAR(tty) || c == KILL_CHAR(tty) || in n_tty_receive_char_canon()
1250 (c == WERASE_CHAR(tty) && L_IEXTEN(tty))) { in n_tty_receive_char_canon()
1251 eraser(c, tty); in n_tty_receive_char_canon()
1252 commit_echoes(tty); in n_tty_receive_char_canon()
1257 if (c == LNEXT_CHAR(tty) && L_IEXTEN(tty)) { in n_tty_receive_char_canon()
1259 if (L_ECHO(tty)) { in n_tty_receive_char_canon()
1261 if (L_ECHOCTL(tty)) { in n_tty_receive_char_canon()
1264 commit_echoes(tty); in n_tty_receive_char_canon()
1271 if (c == REPRINT_CHAR(tty) && L_ECHO(tty) && L_IEXTEN(tty)) { in n_tty_receive_char_canon()
1275 echo_char(c, tty); in n_tty_receive_char_canon()
1278 echo_char(read_buf(ldata, tail), tty); in n_tty_receive_char_canon()
1281 commit_echoes(tty); in n_tty_receive_char_canon()
1287 if (L_ECHO(tty) || L_ECHONL(tty)) { in n_tty_receive_char_canon()
1289 commit_echoes(tty); in n_tty_receive_char_canon()
1291 n_tty_receive_handle_newline(tty, c); in n_tty_receive_char_canon()
1296 if (c == EOF_CHAR(tty)) { in n_tty_receive_char_canon()
1298 n_tty_receive_handle_newline(tty, c); in n_tty_receive_char_canon()
1303 if ((c == EOL_CHAR(tty)) || in n_tty_receive_char_canon()
1304 (c == EOL2_CHAR(tty) && L_IEXTEN(tty))) { in n_tty_receive_char_canon()
1308 if (L_ECHO(tty)) { in n_tty_receive_char_canon()
1312 echo_char(c, tty); in n_tty_receive_char_canon()
1313 commit_echoes(tty); in n_tty_receive_char_canon()
1319 if (c == '\377' && I_PARMRK(tty)) in n_tty_receive_char_canon()
1322 n_tty_receive_handle_newline(tty, c); in n_tty_receive_char_canon()
1330 static void n_tty_receive_char_special(struct tty_struct *tty, u8 c, in n_tty_receive_char_special() argument
1333 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_char_special()
1335 if (I_IXON(tty) && n_tty_receive_char_flow_ctrl(tty, c, lookahead_done)) in n_tty_receive_char_special()
1338 if (L_ISIG(tty)) { in n_tty_receive_char_special()
1339 if (c == INTR_CHAR(tty)) { in n_tty_receive_char_special()
1340 n_tty_receive_signal_char(tty, SIGINT, c); in n_tty_receive_char_special()
1342 } else if (c == QUIT_CHAR(tty)) { in n_tty_receive_char_special()
1343 n_tty_receive_signal_char(tty, SIGQUIT, c); in n_tty_receive_char_special()
1345 } else if (c == SUSP_CHAR(tty)) { in n_tty_receive_char_special()
1346 n_tty_receive_signal_char(tty, SIGTSTP, c); in n_tty_receive_char_special()
1351 if (tty->flow.stopped && !tty->flow.tco_stopped && I_IXON(tty) && I_IXANY(tty)) { in n_tty_receive_char_special()
1352 start_tty(tty); in n_tty_receive_char_special()
1353 process_echoes(tty); in n_tty_receive_char_special()
1357 if (I_IGNCR(tty)) in n_tty_receive_char_special()
1359 if (I_ICRNL(tty)) in n_tty_receive_char_special()
1361 } else if (c == '\n' && I_INLCR(tty)) in n_tty_receive_char_special()
1364 if (ldata->icanon && n_tty_receive_char_canon(tty, c)) in n_tty_receive_char_special()
1367 if (L_ECHO(tty)) { in n_tty_receive_char_special()
1375 echo_char(c, tty); in n_tty_receive_char_special()
1377 commit_echoes(tty); in n_tty_receive_char_special()
1381 if (c == '\377' && I_PARMRK(tty)) in n_tty_receive_char_special()
1399 static void n_tty_receive_char(struct tty_struct *tty, u8 c) in n_tty_receive_char() argument
1401 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_char()
1403 if (tty->flow.stopped && !tty->flow.tco_stopped && I_IXON(tty) && I_IXANY(tty)) { in n_tty_receive_char()
1404 start_tty(tty); in n_tty_receive_char()
1405 process_echoes(tty); in n_tty_receive_char()
1407 if (L_ECHO(tty)) { in n_tty_receive_char()
1412 echo_char(c, tty); in n_tty_receive_char()
1413 commit_echoes(tty); in n_tty_receive_char()
1416 if (c == '\377' && I_PARMRK(tty)) in n_tty_receive_char()
1421 static void n_tty_receive_char_closing(struct tty_struct *tty, u8 c, in n_tty_receive_char_closing() argument
1424 if (I_ISTRIP(tty)) in n_tty_receive_char_closing()
1426 if (I_IUCLC(tty) && L_IEXTEN(tty)) in n_tty_receive_char_closing()
1429 if (I_IXON(tty)) { in n_tty_receive_char_closing()
1430 if (!n_tty_receive_char_flow_ctrl(tty, c, lookahead_done) && in n_tty_receive_char_closing()
1431 tty->flow.stopped && !tty->flow.tco_stopped && I_IXANY(tty) && in n_tty_receive_char_closing()
1432 c != INTR_CHAR(tty) && c != QUIT_CHAR(tty) && in n_tty_receive_char_closing()
1433 c != SUSP_CHAR(tty)) { in n_tty_receive_char_closing()
1434 start_tty(tty); in n_tty_receive_char_closing()
1435 process_echoes(tty); in n_tty_receive_char_closing()
1441 n_tty_receive_char_flagged(struct tty_struct *tty, u8 c, u8 flag) in n_tty_receive_char_flagged() argument
1445 n_tty_receive_break(tty); in n_tty_receive_char_flagged()
1449 n_tty_receive_parity_error(tty, c); in n_tty_receive_char_flagged()
1452 n_tty_receive_overrun(tty); in n_tty_receive_char_flagged()
1455 tty_err(tty, "unknown flag %u\n", flag); in n_tty_receive_char_flagged()
1461 n_tty_receive_char_lnext(struct tty_struct *tty, u8 c, u8 flag) in n_tty_receive_char_lnext() argument
1463 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_char_lnext()
1467 if (I_ISTRIP(tty)) in n_tty_receive_char_lnext()
1469 if (I_IUCLC(tty) && L_IEXTEN(tty)) in n_tty_receive_char_lnext()
1471 n_tty_receive_char(tty, c); in n_tty_receive_char_lnext()
1473 n_tty_receive_char_flagged(tty, c, flag); in n_tty_receive_char_lnext()
1477 static void n_tty_lookahead_flow_ctrl(struct tty_struct *tty, const u8 *cp, in n_tty_lookahead_flow_ctrl() argument
1480 struct n_tty_data *ldata = tty->disc_data; in n_tty_lookahead_flow_ctrl()
1485 if (!I_IXON(tty)) in n_tty_lookahead_flow_ctrl()
1492 n_tty_receive_char_flow_ctrl(tty, *cp, false); in n_tty_lookahead_flow_ctrl()
1498 n_tty_receive_buf_real_raw(const struct tty_struct *tty, const u8 *cp, in n_tty_receive_buf_real_raw() argument
1501 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_real_raw()
1517 n_tty_receive_buf_raw(struct tty_struct *tty, const u8 *cp, const u8 *fp, in n_tty_receive_buf_raw() argument
1520 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_raw()
1529 n_tty_receive_char_flagged(tty, *cp++, flag); in n_tty_receive_buf_raw()
1534 n_tty_receive_buf_closing(struct tty_struct *tty, const u8 *cp, const u8 *fp, in n_tty_receive_buf_closing() argument
1543 n_tty_receive_char_closing(tty, *cp++, lookahead_done); in n_tty_receive_buf_closing()
1547 static void n_tty_receive_buf_standard(struct tty_struct *tty, const u8 *cp, in n_tty_receive_buf_standard() argument
1551 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_standard()
1561 n_tty_receive_char_lnext(tty, c, flag); in n_tty_receive_buf_standard()
1566 n_tty_receive_char_flagged(tty, c, flag); in n_tty_receive_buf_standard()
1570 if (I_ISTRIP(tty)) in n_tty_receive_buf_standard()
1572 if (I_IUCLC(tty) && L_IEXTEN(tty)) in n_tty_receive_buf_standard()
1574 if (L_EXTPROC(tty)) { in n_tty_receive_buf_standard()
1580 n_tty_receive_char_special(tty, c, lookahead_done); in n_tty_receive_buf_standard()
1582 n_tty_receive_char(tty, c); in n_tty_receive_buf_standard()
1586 static void __receive_buf(struct tty_struct *tty, const u8 *cp, const u8 *fp, in __receive_buf() argument
1589 struct n_tty_data *ldata = tty->disc_data; in __receive_buf()
1590 bool preops = I_ISTRIP(tty) || (I_IUCLC(tty) && L_IEXTEN(tty)); in __receive_buf()
1594 n_tty_receive_buf_real_raw(tty, cp, count); in __receive_buf()
1595 else if (ldata->raw || (L_EXTPROC(tty) && !preops)) in __receive_buf()
1596 n_tty_receive_buf_raw(tty, cp, fp, count); in __receive_buf()
1597 else if (tty->closing && !L_EXTPROC(tty)) { in __receive_buf()
1599 n_tty_receive_buf_closing(tty, cp, fp, la_count, true); in __receive_buf()
1606 n_tty_receive_buf_closing(tty, cp, fp, count, false); in __receive_buf()
1609 n_tty_receive_buf_standard(tty, cp, fp, la_count, true); in __receive_buf()
1616 n_tty_receive_buf_standard(tty, cp, fp, count, false); in __receive_buf()
1618 flush_echoes(tty); in __receive_buf()
1619 if (tty->ops->flush_chars) in __receive_buf()
1620 tty->ops->flush_chars(tty); in __receive_buf()
1625 if (ldata->icanon && !L_EXTPROC(tty)) in __receive_buf()
1632 kill_fasync(&tty->fasync, SIGIO, POLL_IN); in __receive_buf()
1633 wake_up_interruptible_poll(&tty->read_wait, EPOLLIN | EPOLLRDNORM); in __receive_buf()
1671 n_tty_receive_buf_common(struct tty_struct *tty, const u8 *cp, const u8 *fp, in n_tty_receive_buf_common() argument
1674 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_common()
1678 guard(rwsem_read)(&tty->termios_rwsem); in n_tty_receive_buf_common()
1697 if (I_PARMRK(tty)) in n_tty_receive_buf_common()
1715 __receive_buf(tty, cp, fp, n); in n_tty_receive_buf_common()
1722 } while (!test_bit(TTY_LDISC_CHANGING, &tty->flags)); in n_tty_receive_buf_common()
1724 tty->receive_room = room; in n_tty_receive_buf_common()
1727 if (tty->driver->type == TTY_DRIVER_TYPE_PTY) { in n_tty_receive_buf_common()
1729 tty_set_flow_change(tty, TTY_UNTHROTTLE_SAFE); in n_tty_receive_buf_common()
1730 tty_unthrottle_safe(tty); in n_tty_receive_buf_common()
1731 __tty_set_flow_change(tty, 0); in n_tty_receive_buf_common()
1734 n_tty_check_throttle(tty); in n_tty_receive_buf_common()
1743 if (!chars_in_buffer(tty)) in n_tty_receive_buf_common()
1744 n_tty_kick_worker(tty); in n_tty_receive_buf_common()
1750 static void n_tty_receive_buf(struct tty_struct *tty, const u8 *cp, in n_tty_receive_buf() argument
1753 n_tty_receive_buf_common(tty, cp, fp, count, false); in n_tty_receive_buf()
1756 static size_t n_tty_receive_buf2(struct tty_struct *tty, const u8 *cp, in n_tty_receive_buf2() argument
1759 return n_tty_receive_buf_common(tty, cp, fp, count, true); in n_tty_receive_buf2()
1774 static void n_tty_set_termios(struct tty_struct *tty, const struct ktermios *old) in n_tty_set_termios() argument
1776 struct n_tty_data *ldata = tty->disc_data; in n_tty_set_termios()
1778 if (!old || (old->c_lflag ^ tty->termios.c_lflag) & (ICANON | EXTPROC)) { in n_tty_set_termios()
1781 if (!L_ICANON(tty) || !read_cnt(ldata)) { in n_tty_set_termios()
1794 ldata->icanon = (L_ICANON(tty) != 0); in n_tty_set_termios()
1796 if (I_ISTRIP(tty) || I_IUCLC(tty) || I_IGNCR(tty) || in n_tty_set_termios()
1797 I_ICRNL(tty) || I_INLCR(tty) || L_ICANON(tty) || in n_tty_set_termios()
1798 I_IXON(tty) || L_ISIG(tty) || L_ECHO(tty) || in n_tty_set_termios()
1799 I_PARMRK(tty)) { in n_tty_set_termios()
1802 if (I_IGNCR(tty) || I_ICRNL(tty)) in n_tty_set_termios()
1804 if (I_INLCR(tty)) in n_tty_set_termios()
1807 if (L_ICANON(tty)) { in n_tty_set_termios()
1808 set_bit(ERASE_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1809 set_bit(KILL_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1810 set_bit(EOF_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1812 set_bit(EOL_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1813 if (L_IEXTEN(tty)) { in n_tty_set_termios()
1814 set_bit(WERASE_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1815 set_bit(LNEXT_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1816 set_bit(EOL2_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1817 if (L_ECHO(tty)) in n_tty_set_termios()
1818 set_bit(REPRINT_CHAR(tty), in n_tty_set_termios()
1822 if (I_IXON(tty)) { in n_tty_set_termios()
1823 set_bit(START_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1824 set_bit(STOP_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1826 if (L_ISIG(tty)) { in n_tty_set_termios()
1827 set_bit(INTR_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1828 set_bit(QUIT_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1829 set_bit(SUSP_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1836 if ((I_IGNBRK(tty) || (!I_BRKINT(tty) && !I_PARMRK(tty))) && in n_tty_set_termios()
1837 (I_IGNPAR(tty) || !I_INPCK(tty)) && in n_tty_set_termios()
1838 (tty->driver->flags & TTY_DRIVER_REAL_RAW)) in n_tty_set_termios()
1847 if (!I_IXON(tty) && old && (old->c_iflag & IXON) && !tty->flow.tco_stopped) { in n_tty_set_termios()
1848 start_tty(tty); in n_tty_set_termios()
1849 process_echoes(tty); in n_tty_set_termios()
1853 wake_up_interruptible(&tty->write_wait); in n_tty_set_termios()
1854 wake_up_interruptible(&tty->read_wait); in n_tty_set_termios()
1865 static void n_tty_close(struct tty_struct *tty) in n_tty_close() argument
1867 struct n_tty_data *ldata = tty->disc_data; in n_tty_close()
1869 if (tty->link) in n_tty_close()
1870 n_tty_packet_mode_flush(tty); in n_tty_close()
1872 guard(rwsem_write)(&tty->termios_rwsem); in n_tty_close()
1874 tty->disc_data = NULL; in n_tty_close()
1885 static int n_tty_open(struct tty_struct *tty) in n_tty_open() argument
1898 tty->disc_data = ldata; in n_tty_open()
1899 tty->closing = 0; in n_tty_open()
1901 clear_bit(TTY_LDISC_HALTED, &tty->flags); in n_tty_open()
1902 n_tty_set_termios(tty, NULL); in n_tty_open()
1903 tty_unthrottle(tty); in n_tty_open()
1907 static inline int input_available_p(const struct tty_struct *tty, int poll) in input_available_p() argument
1909 const struct n_tty_data *ldata = tty->disc_data; in input_available_p()
1910 int amt = poll && !TIME_CHAR(tty) && MIN_CHAR(tty) ? MIN_CHAR(tty) : 1; in input_available_p()
1912 if (ldata->icanon && !L_EXTPROC(tty)) in input_available_p()
1936 static bool copy_from_read_buf(const struct tty_struct *tty, u8 **kbp, in copy_from_read_buf() argument
1940 struct n_tty_data *ldata = tty->disc_data; in copy_from_read_buf()
1952 is_eof = n == 1 && *from == EOF_CHAR(tty); in copy_from_read_buf()
1953 tty_audit_add_data(tty, from, n); in copy_from_read_buf()
1954 zero_buffer(tty, from, n); in copy_from_read_buf()
1958 if (L_EXTPROC(tty) && ldata->icanon && is_eof && in copy_from_read_buf()
1991 static bool canon_copy_from_read_buf(const struct tty_struct *tty, u8 **kbp, in canon_copy_from_read_buf() argument
1994 struct n_tty_data *ldata = tty->disc_data; in canon_copy_from_read_buf()
2027 tty_copy(tty, *kbp, tail, n); in canon_copy_from_read_buf()
2090 static int job_control(struct tty_struct *tty, struct file *file) in job_control() argument
2100 return __tty_check_change(tty, SIGTTIN); in job_control()
2107 static ssize_t n_tty_continue_cookie(struct tty_struct *tty, u8 *kbuf, in n_tty_continue_cookie() argument
2110 struct n_tty_data *ldata = tty->disc_data; in n_tty_continue_cookie()
2113 if (ldata->icanon && !L_EXTPROC(tty)) { in n_tty_continue_cookie()
2120 else if (canon_copy_from_read_buf(tty, &kb, &nr)) in n_tty_continue_cookie()
2123 if (copy_from_read_buf(tty, &kb, &nr)) in n_tty_continue_cookie()
2128 n_tty_kick_worker(tty); in n_tty_continue_cookie()
2129 n_tty_check_unthrottle(tty); in n_tty_continue_cookie()
2130 up_read(&tty->termios_rwsem); in n_tty_continue_cookie()
2137 static int n_tty_wait_for_input(struct tty_struct *tty, struct file *file, in n_tty_wait_for_input() argument
2140 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) in n_tty_wait_for_input()
2148 if (test_bit(TTY_HUPPING, &tty->flags)) in n_tty_wait_for_input()
2152 if (tty_io_nonblock(tty, file)) in n_tty_wait_for_input()
2157 up_read(&tty->termios_rwsem); in n_tty_wait_for_input()
2159 down_read(&tty->termios_rwsem); in n_tty_wait_for_input()
2184 static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, u8 *kbuf, in n_tty_read() argument
2187 struct n_tty_data *ldata = tty->disc_data; in n_tty_read()
2198 return n_tty_continue_cookie(tty, kbuf, nr, cookie); 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 scoped_guard(spinlock_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()
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 int ret = n_tty_wait_for_input(tty, file, &wait, in n_tty_read()
2263 if (ldata->icanon && !L_EXTPROC(tty)) { in n_tty_read()
2264 if (canon_copy_from_read_buf(tty, &kb, &nr)) in n_tty_read()
2273 if (copy_from_read_buf(tty, &kb, &nr) && kb - kbuf >= minimum) in n_tty_read()
2277 n_tty_check_unthrottle(tty); in n_tty_read()
2290 n_tty_kick_worker(tty); in n_tty_read()
2292 up_read(&tty->termios_rwsem); in n_tty_read()
2294 remove_wait_queue(&tty->read_wait, &wait); in n_tty_read()
2309 remove_wait_queue(&tty->read_wait, &wait); in n_tty_read()
2335 static ssize_t n_tty_write(struct tty_struct *tty, struct file *file, in n_tty_write() argument
2343 if (L_TOSTOP(tty) && file->f_op->write_iter != redirected_tty_write) { in n_tty_write()
2344 retval = tty_check_change(tty); in n_tty_write()
2349 guard(rwsem_read)(&tty->termios_rwsem); in n_tty_write()
2352 process_echoes(tty); in n_tty_write()
2354 add_wait_queue(&tty->write_wait, &wait); in n_tty_write()
2360 if (tty_hung_up_p(file) || (tty->link && !tty->link->count)) { in n_tty_write()
2364 if (O_OPOST(tty)) { in n_tty_write()
2366 num = process_output_block(tty, b, nr); in n_tty_write()
2377 if (process_output(*b, tty) < 0) in n_tty_write()
2381 if (tty->ops->flush_chars) in n_tty_write()
2382 tty->ops->flush_chars(tty); in n_tty_write()
2384 struct n_tty_data *ldata = tty->disc_data; in n_tty_write()
2388 num = tty->ops->write(tty, b, nr); in n_tty_write()
2401 if (tty_io_nonblock(tty, file)) { in n_tty_write()
2405 up_read(&tty->termios_rwsem); in n_tty_write()
2409 down_read(&tty->termios_rwsem); in n_tty_write()
2412 remove_wait_queue(&tty->write_wait, &wait); in n_tty_write()
2413 if (nr && tty->fasync) in n_tty_write()
2414 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in n_tty_write()
2433 static __poll_t n_tty_poll(struct tty_struct *tty, struct file *file, in n_tty_poll() argument
2438 poll_wait(file, &tty->read_wait, wait); in n_tty_poll()
2439 poll_wait(file, &tty->write_wait, wait); in n_tty_poll()
2440 if (input_available_p(tty, 1)) in n_tty_poll()
2443 tty_buffer_flush_work(tty->port); in n_tty_poll()
2444 if (input_available_p(tty, 1)) in n_tty_poll()
2447 if (tty->ctrl.packet && tty->link->ctrl.pktstatus) in n_tty_poll()
2449 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) in n_tty_poll()
2453 if (tty->ops->write && !tty_is_writelocked(tty) && in n_tty_poll()
2454 tty_chars_in_buffer(tty) < WAKEUP_CHARS && in n_tty_poll()
2455 tty_write_room(tty) > 0) in n_tty_poll()
2479 static int n_tty_ioctl(struct tty_struct *tty, unsigned int cmd, in n_tty_ioctl() argument
2482 struct n_tty_data *ldata = tty->disc_data; in n_tty_ioctl()
2487 return put_user(tty_chars_in_buffer(tty), (int __user *) arg); in n_tty_ioctl()
2489 scoped_guard(rwsem_write, &tty->termios_rwsem) in n_tty_ioctl()
2490 if (L_ICANON(tty) && !L_EXTPROC(tty)) in n_tty_ioctl()
2496 return n_tty_ioctl_helper(tty, cmd, arg); in n_tty_ioctl()