Lines Matching refs:tty
158 static void zero_buffer(struct tty_struct *tty, u8 *buffer, int size) in zero_buffer() argument
160 bool icanon = !!L_ICANON(tty); in zero_buffer()
161 bool no_echo = !L_ECHO(tty); in zero_buffer()
167 static void tty_copy(struct tty_struct *tty, void *to, size_t tail, size_t n) in tty_copy() argument
169 struct n_tty_data *ldata = tty->disc_data; in tty_copy()
174 tty_audit_add_data(tty, from, size); in tty_copy()
176 zero_buffer(tty, from, size); in tty_copy()
182 tty_audit_add_data(tty, from, n); in tty_copy()
184 zero_buffer(tty, from, n); in tty_copy()
199 static void n_tty_kick_worker(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(struct tty_struct *tty) in chars_in_buffer() argument
221 struct n_tty_data *ldata = tty->disc_data; in chars_in_buffer()
240 static void n_tty_write_wakeup(struct tty_struct *tty) in n_tty_write_wakeup() argument
242 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in n_tty_write_wakeup()
243 kill_fasync(&tty->fasync, SIGIO, POLL_OUT); in n_tty_write_wakeup()
246 static void n_tty_check_throttle(struct tty_struct *tty) in n_tty_check_throttle() argument
248 struct n_tty_data *ldata = tty->disc_data; in n_tty_check_throttle()
260 tty_set_flow_change(tty, TTY_THROTTLE_SAFE); in n_tty_check_throttle()
263 throttled = tty_throttle_safe(tty); in n_tty_check_throttle()
267 __tty_set_flow_change(tty, 0); in n_tty_check_throttle()
270 static void n_tty_check_unthrottle(struct tty_struct *tty) in n_tty_check_unthrottle() argument
272 if (tty->driver->type == TTY_DRIVER_TYPE_PTY) { in n_tty_check_unthrottle()
273 if (chars_in_buffer(tty) > TTY_THRESHOLD_UNTHROTTLE) in n_tty_check_unthrottle()
275 n_tty_kick_worker(tty); in n_tty_check_unthrottle()
276 tty_wakeup(tty->link); in n_tty_check_unthrottle()
290 tty_set_flow_change(tty, TTY_UNTHROTTLE_SAFE); in n_tty_check_unthrottle()
291 if (chars_in_buffer(tty) > TTY_THRESHOLD_UNTHROTTLE) in n_tty_check_unthrottle()
293 n_tty_kick_worker(tty); in n_tty_check_unthrottle()
294 unthrottled = tty_unthrottle_safe(tty); in n_tty_check_unthrottle()
298 __tty_set_flow_change(tty, 0); in n_tty_check_unthrottle()
340 static void n_tty_packet_mode_flush(struct tty_struct *tty) in n_tty_packet_mode_flush() argument
344 if (tty->link->packet) { in n_tty_packet_mode_flush()
345 spin_lock_irqsave(&tty->ctrl_lock, flags); in n_tty_packet_mode_flush()
346 tty->ctrl_status |= TIOCPKT_FLUSHREAD; in n_tty_packet_mode_flush()
347 spin_unlock_irqrestore(&tty->ctrl_lock, flags); in n_tty_packet_mode_flush()
348 wake_up_interruptible(&tty->link->read_wait); in n_tty_packet_mode_flush()
366 static void n_tty_flush_buffer(struct tty_struct *tty) in n_tty_flush_buffer() argument
368 down_write(&tty->termios_rwsem); in n_tty_flush_buffer()
369 reset_buffer_flags(tty->disc_data); in n_tty_flush_buffer()
370 n_tty_kick_worker(tty); in n_tty_flush_buffer()
372 if (tty->link) in n_tty_flush_buffer()
373 n_tty_packet_mode_flush(tty); in n_tty_flush_buffer()
374 up_write(&tty->termios_rwsem); in n_tty_flush_buffer()
399 static inline int is_continuation(unsigned char c, struct tty_struct *tty) in is_continuation() argument
401 return I_IUTF8(tty) && is_utf8_continuation(c); in is_continuation()
426 static int do_output_char(unsigned char c, struct tty_struct *tty, int space) in do_output_char() argument
428 struct n_tty_data *ldata = tty->disc_data; in do_output_char()
436 if (O_ONLRET(tty)) in do_output_char()
438 if (O_ONLCR(tty)) { in do_output_char()
442 tty->ops->write(tty, "\r\n", 2); in do_output_char()
448 if (O_ONOCR(tty) && ldata->column == 0) in do_output_char()
450 if (O_OCRNL(tty)) { in do_output_char()
452 if (O_ONLRET(tty)) in do_output_char()
460 if (O_TABDLY(tty) == XTABS) { in do_output_char()
464 tty->ops->write(tty, " ", spaces); in do_output_char()
475 if (O_OLCUC(tty)) in do_output_char()
477 if (!is_continuation(c, tty)) in do_output_char()
483 tty_put_char(tty, c); in do_output_char()
501 static int process_output(unsigned char c, struct tty_struct *tty) in process_output() argument
503 struct n_tty_data *ldata = tty->disc_data; in process_output()
508 space = tty_write_room(tty); in process_output()
509 retval = do_output_char(c, tty, space); in process_output()
537 static ssize_t process_output_block(struct tty_struct *tty, in process_output_block() argument
540 struct n_tty_data *ldata = tty->disc_data; in process_output_block()
547 space = tty_write_room(tty); in process_output_block()
560 if (O_ONLRET(tty)) in process_output_block()
562 if (O_ONLCR(tty)) in process_output_block()
567 if (O_ONOCR(tty) && ldata->column == 0) in process_output_block()
569 if (O_OCRNL(tty)) in process_output_block()
581 if (O_OLCUC(tty)) in process_output_block()
583 if (!is_continuation(c, tty)) in process_output_block()
590 i = tty->ops->write(tty, buf, i); in process_output_block()
621 static size_t __process_echoes(struct tty_struct *tty) in __process_echoes() argument
623 struct n_tty_data *ldata = tty->disc_data; in __process_echoes()
628 old_space = space = tty_write_room(tty); in __process_echoes()
679 tty_put_char(tty, '\b'); in __process_echoes()
703 tty_put_char(tty, ECHO_OP_START); in __process_echoes()
723 tty_put_char(tty, '^'); in __process_echoes()
724 tty_put_char(tty, op ^ 0100); in __process_echoes()
733 if (O_OPOST(tty)) { in __process_echoes()
734 int retval = do_output_char(c, tty, space); in __process_echoes()
741 tty_put_char(tty, c); in __process_echoes()
767 static void commit_echoes(struct tty_struct *tty) in commit_echoes() argument
769 struct n_tty_data *ldata = tty->disc_data; in commit_echoes()
789 echoed = __process_echoes(tty); in commit_echoes()
792 if (echoed && tty->ops->flush_chars) in commit_echoes()
793 tty->ops->flush_chars(tty); in commit_echoes()
796 static void process_echoes(struct tty_struct *tty) in process_echoes() argument
798 struct n_tty_data *ldata = tty->disc_data; in process_echoes()
806 echoed = __process_echoes(tty); in process_echoes()
809 if (echoed && tty->ops->flush_chars) in process_echoes()
810 tty->ops->flush_chars(tty); in process_echoes()
814 static void flush_echoes(struct tty_struct *tty) in flush_echoes() argument
816 struct n_tty_data *ldata = tty->disc_data; in flush_echoes()
818 if ((!L_ECHO(tty) && !L_ECHONL(tty)) || in flush_echoes()
824 __process_echoes(tty); in flush_echoes()
934 static void echo_char(unsigned char c, struct tty_struct *tty) in echo_char() argument
936 struct n_tty_data *ldata = tty->disc_data; in echo_char()
942 if (L_ECHOCTL(tty) && iscntrl(c) && c != '\t') in echo_char()
974 static void eraser(unsigned char c, struct tty_struct *tty) in eraser() argument
976 struct n_tty_data *ldata = tty->disc_data; in eraser()
986 if (c == ERASE_CHAR(tty)) in eraser()
988 else if (c == WERASE_CHAR(tty)) in eraser()
991 if (!L_ECHO(tty)) { in eraser()
995 if (!L_ECHOK(tty) || !L_ECHOKE(tty) || !L_ECHOE(tty)) { in eraser()
998 echo_char(KILL_CHAR(tty), tty); in eraser()
1000 if (L_ECHOK(tty)) in eraser()
1015 } while (is_continuation(c, tty) && in eraser()
1019 if (is_continuation(c, tty)) in eraser()
1031 if (L_ECHO(tty)) { in eraser()
1032 if (L_ECHOPRT(tty)) { in eraser()
1038 echo_char(c, tty); in eraser()
1044 } else if (kill_type == ERASE && !L_ECHOE(tty)) { in eraser()
1045 echo_char(ERASE_CHAR(tty), tty); in eraser()
1065 if (L_ECHOCTL(tty)) in eraser()
1067 } else if (!is_continuation(c, tty)) { in eraser()
1073 if (iscntrl(c) && L_ECHOCTL(tty)) { in eraser()
1078 if (!iscntrl(c) || L_ECHOCTL(tty)) { in eraser()
1088 if (ldata->read_head == ldata->canon_head && L_ECHO(tty)) in eraser()
1107 static void __isig(int sig, struct tty_struct *tty) in __isig() argument
1109 struct pid *tty_pgrp = tty_get_pgrp(tty); in __isig()
1116 static void isig(int sig, struct tty_struct *tty) in isig() argument
1118 struct n_tty_data *ldata = tty->disc_data; in isig()
1120 if (L_NOFLSH(tty)) { in isig()
1122 __isig(sig, tty); in isig()
1125 up_read(&tty->termios_rwsem); in isig()
1126 down_write(&tty->termios_rwsem); in isig()
1128 __isig(sig, tty); in isig()
1137 tty_driver_flush_buffer(tty); in isig()
1140 reset_buffer_flags(tty->disc_data); in isig()
1143 if (tty->link) in isig()
1144 n_tty_packet_mode_flush(tty); in isig()
1146 up_write(&tty->termios_rwsem); in isig()
1147 down_read(&tty->termios_rwsem); in isig()
1164 static void n_tty_receive_break(struct tty_struct *tty) in n_tty_receive_break() argument
1166 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_break()
1168 if (I_IGNBRK(tty)) in n_tty_receive_break()
1170 if (I_BRKINT(tty)) { in n_tty_receive_break()
1171 isig(SIGINT, tty); in n_tty_receive_break()
1174 if (I_PARMRK(tty)) { in n_tty_receive_break()
1194 static void n_tty_receive_overrun(struct tty_struct *tty) in n_tty_receive_overrun() argument
1196 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_overrun()
1201 tty_warn(tty, "%d input overrun(s)\n", ldata->num_overrun); in n_tty_receive_overrun()
1218 static void n_tty_receive_parity_error(struct tty_struct *tty, unsigned char c) in n_tty_receive_parity_error() argument
1220 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_parity_error()
1222 if (I_INPCK(tty)) { in n_tty_receive_parity_error()
1223 if (I_IGNPAR(tty)) in n_tty_receive_parity_error()
1225 if (I_PARMRK(tty)) { in n_tty_receive_parity_error()
1236 n_tty_receive_signal_char(struct tty_struct *tty, int signal, unsigned char c) in n_tty_receive_signal_char() argument
1238 isig(signal, tty); in n_tty_receive_signal_char()
1239 if (I_IXON(tty)) in n_tty_receive_signal_char()
1240 start_tty(tty); in n_tty_receive_signal_char()
1241 if (L_ECHO(tty)) { in n_tty_receive_signal_char()
1242 echo_char(c, tty); in n_tty_receive_signal_char()
1243 commit_echoes(tty); in n_tty_receive_signal_char()
1245 process_echoes(tty); in n_tty_receive_signal_char()
1266 n_tty_receive_char_special(struct tty_struct *tty, unsigned char c) in n_tty_receive_char_special() argument
1268 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_char_special()
1270 if (I_IXON(tty)) { in n_tty_receive_char_special()
1271 if (c == START_CHAR(tty)) { in n_tty_receive_char_special()
1272 start_tty(tty); in n_tty_receive_char_special()
1273 process_echoes(tty); in n_tty_receive_char_special()
1276 if (c == STOP_CHAR(tty)) { in n_tty_receive_char_special()
1277 stop_tty(tty); in n_tty_receive_char_special()
1282 if (L_ISIG(tty)) { in n_tty_receive_char_special()
1283 if (c == INTR_CHAR(tty)) { in n_tty_receive_char_special()
1284 n_tty_receive_signal_char(tty, SIGINT, c); in n_tty_receive_char_special()
1286 } else if (c == QUIT_CHAR(tty)) { in n_tty_receive_char_special()
1287 n_tty_receive_signal_char(tty, SIGQUIT, c); in n_tty_receive_char_special()
1289 } else if (c == SUSP_CHAR(tty)) { in n_tty_receive_char_special()
1290 n_tty_receive_signal_char(tty, SIGTSTP, c); in n_tty_receive_char_special()
1295 if (tty->stopped && !tty->flow_stopped && I_IXON(tty) && I_IXANY(tty)) { in n_tty_receive_char_special()
1296 start_tty(tty); in n_tty_receive_char_special()
1297 process_echoes(tty); in n_tty_receive_char_special()
1301 if (I_IGNCR(tty)) in n_tty_receive_char_special()
1303 if (I_ICRNL(tty)) in n_tty_receive_char_special()
1305 } else if (c == '\n' && I_INLCR(tty)) in n_tty_receive_char_special()
1309 if (c == ERASE_CHAR(tty) || c == KILL_CHAR(tty) || in n_tty_receive_char_special()
1310 (c == WERASE_CHAR(tty) && L_IEXTEN(tty))) { in n_tty_receive_char_special()
1311 eraser(c, tty); in n_tty_receive_char_special()
1312 commit_echoes(tty); in n_tty_receive_char_special()
1315 if (c == LNEXT_CHAR(tty) && L_IEXTEN(tty)) { in n_tty_receive_char_special()
1317 if (L_ECHO(tty)) { in n_tty_receive_char_special()
1319 if (L_ECHOCTL(tty)) { in n_tty_receive_char_special()
1322 commit_echoes(tty); in n_tty_receive_char_special()
1327 if (c == REPRINT_CHAR(tty) && L_ECHO(tty) && L_IEXTEN(tty)) { in n_tty_receive_char_special()
1331 echo_char(c, tty); in n_tty_receive_char_special()
1334 echo_char(read_buf(ldata, tail), tty); in n_tty_receive_char_special()
1337 commit_echoes(tty); in n_tty_receive_char_special()
1341 if (L_ECHO(tty) || L_ECHONL(tty)) { in n_tty_receive_char_special()
1343 commit_echoes(tty); in n_tty_receive_char_special()
1347 if (c == EOF_CHAR(tty)) { in n_tty_receive_char_special()
1351 if ((c == EOL_CHAR(tty)) || in n_tty_receive_char_special()
1352 (c == EOL2_CHAR(tty) && L_IEXTEN(tty))) { in n_tty_receive_char_special()
1356 if (L_ECHO(tty)) { in n_tty_receive_char_special()
1360 echo_char(c, tty); in n_tty_receive_char_special()
1361 commit_echoes(tty); in n_tty_receive_char_special()
1367 if (c == (unsigned char) '\377' && I_PARMRK(tty)) in n_tty_receive_char_special()
1374 kill_fasync(&tty->fasync, SIGIO, POLL_IN); in n_tty_receive_char_special()
1375 wake_up_interruptible_poll(&tty->read_wait, EPOLLIN | EPOLLRDNORM); in n_tty_receive_char_special()
1380 if (L_ECHO(tty)) { in n_tty_receive_char_special()
1388 echo_char(c, tty); in n_tty_receive_char_special()
1390 commit_echoes(tty); in n_tty_receive_char_special()
1394 if (c == (unsigned char) '\377' && I_PARMRK(tty)) in n_tty_receive_char_special()
1402 n_tty_receive_char_inline(struct tty_struct *tty, unsigned char c) in n_tty_receive_char_inline() argument
1404 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_char_inline()
1406 if (tty->stopped && !tty->flow_stopped && I_IXON(tty) && I_IXANY(tty)) { in n_tty_receive_char_inline()
1407 start_tty(tty); in n_tty_receive_char_inline()
1408 process_echoes(tty); in n_tty_receive_char_inline()
1410 if (L_ECHO(tty)) { in n_tty_receive_char_inline()
1415 echo_char(c, tty); in n_tty_receive_char_inline()
1416 commit_echoes(tty); in n_tty_receive_char_inline()
1419 if (c == (unsigned char) '\377' && I_PARMRK(tty)) in n_tty_receive_char_inline()
1424 static void n_tty_receive_char(struct tty_struct *tty, unsigned char c) in n_tty_receive_char() argument
1426 n_tty_receive_char_inline(tty, c); in n_tty_receive_char()
1430 n_tty_receive_char_fast(struct tty_struct *tty, unsigned char c) in n_tty_receive_char_fast() argument
1432 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_char_fast()
1434 if (tty->stopped && !tty->flow_stopped && I_IXON(tty) && I_IXANY(tty)) { in n_tty_receive_char_fast()
1435 start_tty(tty); in n_tty_receive_char_fast()
1436 process_echoes(tty); in n_tty_receive_char_fast()
1438 if (L_ECHO(tty)) { in n_tty_receive_char_fast()
1443 echo_char(c, tty); in n_tty_receive_char_fast()
1444 commit_echoes(tty); in n_tty_receive_char_fast()
1449 static void n_tty_receive_char_closing(struct tty_struct *tty, unsigned char c) in n_tty_receive_char_closing() argument
1451 if (I_ISTRIP(tty)) in n_tty_receive_char_closing()
1453 if (I_IUCLC(tty) && L_IEXTEN(tty)) in n_tty_receive_char_closing()
1456 if (I_IXON(tty)) { in n_tty_receive_char_closing()
1457 if (c == STOP_CHAR(tty)) in n_tty_receive_char_closing()
1458 stop_tty(tty); in n_tty_receive_char_closing()
1459 else if (c == START_CHAR(tty) || in n_tty_receive_char_closing()
1460 (tty->stopped && !tty->flow_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, unsigned char c, char 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 %d\n", flag); in n_tty_receive_char_flagged()
1490 n_tty_receive_char_lnext(struct tty_struct *tty, unsigned char c, char 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 n_tty_receive_buf_real_raw(struct tty_struct *tty, const unsigned char *cp, in n_tty_receive_buf_real_raw() argument
1509 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_real_raw()
1526 n_tty_receive_buf_raw(struct tty_struct *tty, const unsigned char *cp, in n_tty_receive_buf_raw() argument
1529 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_raw()
1538 n_tty_receive_char_flagged(tty, *cp++, flag); in n_tty_receive_buf_raw()
1543 n_tty_receive_buf_closing(struct tty_struct *tty, const unsigned char *cp, in n_tty_receive_buf_closing() argument
1552 n_tty_receive_char_closing(tty, *cp++); in n_tty_receive_buf_closing()
1557 n_tty_receive_buf_standard(struct tty_struct *tty, const unsigned char *cp, in n_tty_receive_buf_standard() argument
1560 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_standard()
1569 if (I_ISTRIP(tty)) in n_tty_receive_buf_standard()
1571 if (I_IUCLC(tty) && L_IEXTEN(tty)) in n_tty_receive_buf_standard()
1573 if (L_EXTPROC(tty)) { in n_tty_receive_buf_standard()
1578 n_tty_receive_char_inline(tty, c); in n_tty_receive_buf_standard()
1579 else if (n_tty_receive_char_special(tty, c) && count) { in n_tty_receive_buf_standard()
1582 n_tty_receive_char_lnext(tty, *cp++, flag); in n_tty_receive_buf_standard()
1586 n_tty_receive_char_flagged(tty, *cp++, flag); in n_tty_receive_buf_standard()
1591 n_tty_receive_buf_fast(struct tty_struct *tty, const unsigned char *cp, in n_tty_receive_buf_fast() argument
1594 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_fast()
1604 n_tty_receive_char_fast(tty, c); in n_tty_receive_buf_fast()
1605 else if (n_tty_receive_char_special(tty, c) && count) { in n_tty_receive_buf_fast()
1608 n_tty_receive_char_lnext(tty, *cp++, flag); in n_tty_receive_buf_fast()
1612 n_tty_receive_char_flagged(tty, *cp++, flag); in n_tty_receive_buf_fast()
1616 static void __receive_buf(struct tty_struct *tty, const unsigned char *cp, in __receive_buf() argument
1619 struct n_tty_data *ldata = tty->disc_data; in __receive_buf()
1620 bool preops = I_ISTRIP(tty) || (I_IUCLC(tty) && L_IEXTEN(tty)); in __receive_buf()
1623 n_tty_receive_buf_real_raw(tty, cp, fp, 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()
1627 n_tty_receive_buf_closing(tty, cp, fp, count); in __receive_buf()
1634 n_tty_receive_char_lnext(tty, *cp++, flag); in __receive_buf()
1638 if (!preops && !I_PARMRK(tty)) in __receive_buf()
1639 n_tty_receive_buf_fast(tty, cp, fp, count); in __receive_buf()
1641 n_tty_receive_buf_standard(tty, cp, fp, count); in __receive_buf()
1643 flush_echoes(tty); in __receive_buf()
1644 if (tty->ops->flush_chars) in __receive_buf()
1645 tty->ops->flush_chars(tty); in __receive_buf()
1648 if (ldata->icanon && !L_EXTPROC(tty)) in __receive_buf()
1655 kill_fasync(&tty->fasync, SIGIO, POLL_IN); in __receive_buf()
1656 wake_up_interruptible_poll(&tty->read_wait, EPOLLIN | EPOLLRDNORM); in __receive_buf()
1694 n_tty_receive_buf_common(struct tty_struct *tty, const unsigned char *cp, in n_tty_receive_buf_common() argument
1697 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_common()
1700 down_read(&tty->termios_rwsem); in n_tty_receive_buf_common()
1719 if (I_PARMRK(tty)) in n_tty_receive_buf_common()
1737 __receive_buf(tty, cp, fp, n); in n_tty_receive_buf_common()
1744 } while (!test_bit(TTY_LDISC_CHANGING, &tty->flags)); in n_tty_receive_buf_common()
1746 tty->receive_room = room; in n_tty_receive_buf_common()
1749 if (tty->driver->type == TTY_DRIVER_TYPE_PTY) { in n_tty_receive_buf_common()
1751 tty_set_flow_change(tty, TTY_UNTHROTTLE_SAFE); in n_tty_receive_buf_common()
1752 tty_unthrottle_safe(tty); in n_tty_receive_buf_common()
1753 __tty_set_flow_change(tty, 0); in n_tty_receive_buf_common()
1756 n_tty_check_throttle(tty); in n_tty_receive_buf_common()
1758 up_read(&tty->termios_rwsem); in n_tty_receive_buf_common()
1763 static void n_tty_receive_buf(struct tty_struct *tty, const unsigned char *cp, in n_tty_receive_buf() argument
1766 n_tty_receive_buf_common(tty, cp, fp, count, 0); in n_tty_receive_buf()
1769 static int n_tty_receive_buf2(struct tty_struct *tty, const unsigned char *cp, in n_tty_receive_buf2() argument
1772 return n_tty_receive_buf_common(tty, cp, fp, count, 1); in n_tty_receive_buf2()
1789 static void n_tty_set_termios(struct tty_struct *tty, struct ktermios *old) in n_tty_set_termios() argument
1791 struct n_tty_data *ldata = tty->disc_data; in n_tty_set_termios()
1793 if (!old || (old->c_lflag ^ tty->termios.c_lflag) & (ICANON | EXTPROC)) { in n_tty_set_termios()
1796 if (!L_ICANON(tty) || !read_cnt(ldata)) { in n_tty_set_termios()
1810 ldata->icanon = (L_ICANON(tty) != 0); in n_tty_set_termios()
1812 if (I_ISTRIP(tty) || I_IUCLC(tty) || I_IGNCR(tty) || in n_tty_set_termios()
1813 I_ICRNL(tty) || I_INLCR(tty) || L_ICANON(tty) || in n_tty_set_termios()
1814 I_IXON(tty) || L_ISIG(tty) || L_ECHO(tty) || in n_tty_set_termios()
1815 I_PARMRK(tty)) { in n_tty_set_termios()
1818 if (I_IGNCR(tty) || I_ICRNL(tty)) in n_tty_set_termios()
1820 if (I_INLCR(tty)) in n_tty_set_termios()
1823 if (L_ICANON(tty)) { in n_tty_set_termios()
1824 set_bit(ERASE_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1825 set_bit(KILL_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1826 set_bit(EOF_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1828 set_bit(EOL_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1829 if (L_IEXTEN(tty)) { in n_tty_set_termios()
1830 set_bit(WERASE_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1831 set_bit(LNEXT_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1832 set_bit(EOL2_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1833 if (L_ECHO(tty)) in n_tty_set_termios()
1834 set_bit(REPRINT_CHAR(tty), in n_tty_set_termios()
1838 if (I_IXON(tty)) { in n_tty_set_termios()
1839 set_bit(START_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1840 set_bit(STOP_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1842 if (L_ISIG(tty)) { in n_tty_set_termios()
1843 set_bit(INTR_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1844 set_bit(QUIT_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1845 set_bit(SUSP_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1852 if ((I_IGNBRK(tty) || (!I_BRKINT(tty) && !I_PARMRK(tty))) && in n_tty_set_termios()
1853 (I_IGNPAR(tty) || !I_INPCK(tty)) && in n_tty_set_termios()
1854 (tty->driver->flags & TTY_DRIVER_REAL_RAW)) in n_tty_set_termios()
1863 if (!I_IXON(tty) && old && (old->c_iflag & IXON) && !tty->flow_stopped) { in n_tty_set_termios()
1864 start_tty(tty); in n_tty_set_termios()
1865 process_echoes(tty); in n_tty_set_termios()
1869 wake_up_interruptible(&tty->write_wait); in n_tty_set_termios()
1870 wake_up_interruptible(&tty->read_wait); in n_tty_set_termios()
1883 static void n_tty_close(struct tty_struct *tty) in n_tty_close() argument
1885 struct n_tty_data *ldata = tty->disc_data; in n_tty_close()
1887 if (tty->link) in n_tty_close()
1888 n_tty_packet_mode_flush(tty); in n_tty_close()
1891 tty->disc_data = NULL; in n_tty_close()
1904 static int n_tty_open(struct tty_struct *tty) in n_tty_open() argument
1917 tty->disc_data = ldata; in n_tty_open()
1918 tty->closing = 0; in n_tty_open()
1920 clear_bit(TTY_LDISC_HALTED, &tty->flags); in n_tty_open()
1921 n_tty_set_termios(tty, NULL); in n_tty_open()
1922 tty_unthrottle(tty); in n_tty_open()
1926 static inline int input_available_p(struct tty_struct *tty, int poll) in input_available_p() argument
1928 struct n_tty_data *ldata = tty->disc_data; in input_available_p()
1929 int amt = poll && !TIME_CHAR(tty) && MIN_CHAR(tty) ? MIN_CHAR(tty) : 1; in input_available_p()
1931 if (ldata->icanon && !L_EXTPROC(tty)) in input_available_p()
1956 static bool copy_from_read_buf(struct tty_struct *tty, in copy_from_read_buf() argument
1961 struct n_tty_data *ldata = tty->disc_data; in copy_from_read_buf()
1972 is_eof = n == 1 && *from == EOF_CHAR(tty); in copy_from_read_buf()
1973 tty_audit_add_data(tty, from, n); in copy_from_read_buf()
1974 zero_buffer(tty, from, n); in copy_from_read_buf()
1977 if (L_EXTPROC(tty) && ldata->icanon && is_eof && in copy_from_read_buf()
2012 static bool canon_copy_from_read_buf(struct tty_struct *tty, in canon_copy_from_read_buf() argument
2016 struct n_tty_data *ldata = tty->disc_data; in canon_copy_from_read_buf()
2055 tty_copy(tty, *kbp, tail, n); in canon_copy_from_read_buf()
2081 static void canon_skip_eof(struct tty_struct *tty) in canon_skip_eof() argument
2083 struct n_tty_data *ldata = tty->disc_data; in canon_skip_eof()
2119 static int job_control(struct tty_struct *tty, struct file *file) in job_control() argument
2129 return __tty_check_change(tty, SIGTTIN); in job_control()
2152 static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, in n_tty_read() argument
2156 struct n_tty_data *ldata = tty->disc_data; in n_tty_read()
2173 if (ldata->icanon && !L_EXTPROC(tty)) { in n_tty_read()
2180 canon_skip_eof(tty); in n_tty_read()
2181 else if (canon_copy_from_read_buf(tty, &kb, &nr)) in n_tty_read()
2184 if (copy_from_read_buf(tty, &kb, &nr)) in n_tty_read()
2189 n_tty_kick_worker(tty); in n_tty_read()
2190 n_tty_check_unthrottle(tty); in n_tty_read()
2191 up_read(&tty->termios_rwsem); in n_tty_read()
2197 c = job_control(tty, file); in n_tty_read()
2212 down_read(&tty->termios_rwsem); in n_tty_read()
2217 minimum = MIN_CHAR(tty); in n_tty_read()
2219 time = (HZ / 10) * TIME_CHAR(tty); in n_tty_read()
2221 timeout = (HZ / 10) * TIME_CHAR(tty); in n_tty_read()
2226 packet = tty->packet; in n_tty_read()
2229 add_wait_queue(&tty->read_wait, &wait); in n_tty_read()
2232 if (packet && tty->link->ctrl_status) { in n_tty_read()
2236 spin_lock_irq(&tty->link->ctrl_lock); in n_tty_read()
2237 cs = tty->link->ctrl_status; in n_tty_read()
2238 tty->link->ctrl_status = 0; in n_tty_read()
2239 spin_unlock_irq(&tty->link->ctrl_lock); in n_tty_read()
2245 if (!input_available_p(tty, 0)) { in n_tty_read()
2246 up_read(&tty->termios_rwsem); in n_tty_read()
2247 tty_buffer_flush_work(tty->port); in n_tty_read()
2248 down_read(&tty->termios_rwsem); in n_tty_read()
2249 if (!input_available_p(tty, 0)) { in n_tty_read()
2250 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) { in n_tty_read()
2260 if (test_bit(TTY_HUPPING, &tty->flags)) in n_tty_read()
2264 if (tty_io_nonblock(tty, file)) { in n_tty_read()
2272 up_read(&tty->termios_rwsem); in n_tty_read()
2277 down_read(&tty->termios_rwsem); in n_tty_read()
2282 if (ldata->icanon && !L_EXTPROC(tty)) { in n_tty_read()
2283 if (canon_copy_from_read_buf(tty, &kb, &nr)) in n_tty_read()
2301 if (copy_from_read_buf(tty, &kb, &nr) && kb - kbuf >= minimum) { in n_tty_read()
2303 remove_wait_queue(&tty->read_wait, &wait); in n_tty_read()
2309 n_tty_check_unthrottle(tty); in n_tty_read()
2317 n_tty_kick_worker(tty); in n_tty_read()
2318 up_read(&tty->termios_rwsem); in n_tty_read()
2320 remove_wait_queue(&tty->read_wait, &wait); in n_tty_read()
2351 static ssize_t n_tty_write(struct tty_struct *tty, struct file *file, in n_tty_write() argument
2360 if (L_TOSTOP(tty) && file->f_op->write_iter != redirected_tty_write) { in n_tty_write()
2361 retval = tty_check_change(tty); in n_tty_write()
2366 down_read(&tty->termios_rwsem); in n_tty_write()
2369 process_echoes(tty); in n_tty_write()
2371 add_wait_queue(&tty->write_wait, &wait); in n_tty_write()
2377 if (tty_hung_up_p(file) || (tty->link && !tty->link->count)) { in n_tty_write()
2381 if (O_OPOST(tty)) { in n_tty_write()
2383 ssize_t num = process_output_block(tty, b, nr); in n_tty_write()
2395 if (process_output(c, 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 c = 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->packet && tty->link->ctrl_status) 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, struct file *file, 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, file, cmd, arg); in n_tty_ioctl()