Lines Matching refs:tty

155 static int tty_copy_to_user(struct tty_struct *tty, void __user *to,  in tty_copy_to_user()  argument
158 struct n_tty_data *ldata = tty->disc_data; in tty_copy_to_user()
164 tty_audit_add_data(tty, from, size); in tty_copy_to_user()
173 tty_audit_add_data(tty, from, n); in tty_copy_to_user()
189 static void n_tty_kick_worker(struct tty_struct *tty) in n_tty_kick_worker() argument
191 struct n_tty_data *ldata = tty->disc_data; in n_tty_kick_worker()
197 WARN_RATELIMIT(tty->port->itty == NULL, in n_tty_kick_worker()
203 WARN_RATELIMIT(test_bit(TTY_LDISC_HALTED, &tty->flags), in n_tty_kick_worker()
205 tty_buffer_restart_work(tty->port); in n_tty_kick_worker()
209 static ssize_t chars_in_buffer(struct tty_struct *tty) in chars_in_buffer() argument
211 struct n_tty_data *ldata = tty->disc_data; in chars_in_buffer()
230 static void n_tty_write_wakeup(struct tty_struct *tty) in n_tty_write_wakeup() argument
232 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in n_tty_write_wakeup()
233 kill_fasync(&tty->fasync, SIGIO, POLL_OUT); in n_tty_write_wakeup()
236 static void n_tty_check_throttle(struct tty_struct *tty) in n_tty_check_throttle() argument
238 struct n_tty_data *ldata = tty->disc_data; in n_tty_check_throttle()
250 tty_set_flow_change(tty, TTY_THROTTLE_SAFE); in n_tty_check_throttle()
253 throttled = tty_throttle_safe(tty); in n_tty_check_throttle()
257 __tty_set_flow_change(tty, 0); in n_tty_check_throttle()
260 static void n_tty_check_unthrottle(struct tty_struct *tty) in n_tty_check_unthrottle() argument
262 if (tty->driver->type == TTY_DRIVER_TYPE_PTY) { in n_tty_check_unthrottle()
263 if (chars_in_buffer(tty) > TTY_THRESHOLD_UNTHROTTLE) in n_tty_check_unthrottle()
265 n_tty_kick_worker(tty); in n_tty_check_unthrottle()
266 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()
283 n_tty_kick_worker(tty); in n_tty_check_unthrottle()
284 unthrottled = tty_unthrottle_safe(tty); in n_tty_check_unthrottle()
288 __tty_set_flow_change(tty, 0); in n_tty_check_unthrottle()
330 static void n_tty_packet_mode_flush(struct tty_struct *tty) in n_tty_packet_mode_flush() argument
334 if (tty->link->packet) { in n_tty_packet_mode_flush()
335 spin_lock_irqsave(&tty->ctrl_lock, flags); in n_tty_packet_mode_flush()
336 tty->ctrl_status |= TIOCPKT_FLUSHREAD; in n_tty_packet_mode_flush()
337 spin_unlock_irqrestore(&tty->ctrl_lock, flags); in n_tty_packet_mode_flush()
338 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()
389 static inline int is_continuation(unsigned char c, struct tty_struct *tty) in is_continuation() argument
391 return I_IUTF8(tty) && is_utf8_continuation(c); in is_continuation()
416 static int do_output_char(unsigned char c, struct tty_struct *tty, int space) in do_output_char() argument
418 struct n_tty_data *ldata = tty->disc_data; in do_output_char()
426 if (O_ONLRET(tty)) in do_output_char()
428 if (O_ONLCR(tty)) { in do_output_char()
432 tty->ops->write(tty, "\r\n", 2); in do_output_char()
438 if (O_ONOCR(tty) && ldata->column == 0) in do_output_char()
440 if (O_OCRNL(tty)) { in do_output_char()
442 if (O_ONLRET(tty)) in do_output_char()
450 if (O_TABDLY(tty) == XTABS) { in do_output_char()
454 tty->ops->write(tty, " ", spaces); in do_output_char()
465 if (O_OLCUC(tty)) in do_output_char()
467 if (!is_continuation(c, tty)) in do_output_char()
473 tty_put_char(tty, c); in do_output_char()
491 static int process_output(unsigned char 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()
527 static ssize_t process_output_block(struct tty_struct *tty, in process_output_block() argument
530 struct n_tty_data *ldata = tty->disc_data; in process_output_block()
537 space = tty_write_room(tty); in process_output_block()
550 if (O_ONLRET(tty)) in process_output_block()
552 if (O_ONLCR(tty)) in process_output_block()
557 if (O_ONOCR(tty) && ldata->column == 0) in process_output_block()
559 if (O_OCRNL(tty)) in process_output_block()
571 if (O_OLCUC(tty)) in process_output_block()
573 if (!is_continuation(c, tty)) in process_output_block()
580 i = tty->ops->write(tty, buf, i); in process_output_block()
611 static size_t __process_echoes(struct tty_struct *tty) in __process_echoes() argument
613 struct n_tty_data *ldata = tty->disc_data; in __process_echoes()
618 old_space = space = tty_write_room(tty); in __process_echoes()
669 tty_put_char(tty, '\b'); in __process_echoes()
693 tty_put_char(tty, ECHO_OP_START); in __process_echoes()
713 tty_put_char(tty, '^'); in __process_echoes()
714 tty_put_char(tty, op ^ 0100); in __process_echoes()
723 if (O_OPOST(tty)) { in __process_echoes()
724 int retval = do_output_char(c, tty, space); in __process_echoes()
731 tty_put_char(tty, c); in __process_echoes()
757 static void commit_echoes(struct tty_struct *tty) in commit_echoes() argument
759 struct n_tty_data *ldata = tty->disc_data; in commit_echoes()
779 echoed = __process_echoes(tty); in commit_echoes()
782 if (echoed && tty->ops->flush_chars) in commit_echoes()
783 tty->ops->flush_chars(tty); in commit_echoes()
786 static void process_echoes(struct tty_struct *tty) in process_echoes() argument
788 struct n_tty_data *ldata = tty->disc_data; in process_echoes()
796 echoed = __process_echoes(tty); in process_echoes()
799 if (echoed && tty->ops->flush_chars) in process_echoes()
800 tty->ops->flush_chars(tty); in process_echoes()
804 static void flush_echoes(struct tty_struct *tty) in flush_echoes() argument
806 struct n_tty_data *ldata = tty->disc_data; in flush_echoes()
808 if ((!L_ECHO(tty) && !L_ECHONL(tty)) || in flush_echoes()
814 __process_echoes(tty); in flush_echoes()
924 static void echo_char(unsigned char c, struct tty_struct *tty) in echo_char() argument
926 struct n_tty_data *ldata = tty->disc_data; in echo_char()
932 if (L_ECHOCTL(tty) && iscntrl(c) && c != '\t') in echo_char()
964 static void eraser(unsigned char c, struct tty_struct *tty) in eraser() argument
966 struct n_tty_data *ldata = tty->disc_data; in eraser()
976 if (c == ERASE_CHAR(tty)) in eraser()
978 else if (c == WERASE_CHAR(tty)) in eraser()
981 if (!L_ECHO(tty)) { in eraser()
985 if (!L_ECHOK(tty) || !L_ECHOKE(tty) || !L_ECHOE(tty)) { in eraser()
988 echo_char(KILL_CHAR(tty), tty); in eraser()
990 if (L_ECHOK(tty)) in eraser()
1005 } while (is_continuation(c, tty) && in eraser()
1009 if (is_continuation(c, tty)) in eraser()
1021 if (L_ECHO(tty)) { in eraser()
1022 if (L_ECHOPRT(tty)) { in eraser()
1028 echo_char(c, tty); in eraser()
1034 } else if (kill_type == ERASE && !L_ECHOE(tty)) { in eraser()
1035 echo_char(ERASE_CHAR(tty), tty); in eraser()
1055 if (L_ECHOCTL(tty)) in eraser()
1057 } else if (!is_continuation(c, tty)) { in eraser()
1063 if (iscntrl(c) && L_ECHOCTL(tty)) { in eraser()
1068 if (!iscntrl(c) || L_ECHOCTL(tty)) { in eraser()
1078 if (ldata->read_head == ldata->canon_head && L_ECHO(tty)) in eraser()
1097 static void __isig(int sig, struct tty_struct *tty) in __isig() argument
1099 struct pid *tty_pgrp = tty_get_pgrp(tty); in __isig()
1106 static void isig(int sig, struct tty_struct *tty) in isig() argument
1108 struct n_tty_data *ldata = tty->disc_data; in isig()
1110 if (L_NOFLSH(tty)) { in isig()
1112 __isig(sig, tty); in isig()
1115 up_read(&tty->termios_rwsem); in isig()
1116 down_write(&tty->termios_rwsem); in isig()
1118 __isig(sig, tty); in isig()
1127 tty_driver_flush_buffer(tty); in isig()
1130 reset_buffer_flags(tty->disc_data); in isig()
1133 if (tty->link) in isig()
1134 n_tty_packet_mode_flush(tty); in isig()
1136 up_write(&tty->termios_rwsem); in isig()
1137 down_read(&tty->termios_rwsem); in isig()
1154 static void n_tty_receive_break(struct tty_struct *tty) in n_tty_receive_break() argument
1156 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_break()
1158 if (I_IGNBRK(tty)) in n_tty_receive_break()
1160 if (I_BRKINT(tty)) { in n_tty_receive_break()
1161 isig(SIGINT, tty); in n_tty_receive_break()
1164 if (I_PARMRK(tty)) { in n_tty_receive_break()
1184 static void n_tty_receive_overrun(struct tty_struct *tty) in n_tty_receive_overrun() argument
1186 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_overrun()
1191 tty_warn(tty, "%d input overrun(s)\n", ldata->num_overrun); in n_tty_receive_overrun()
1208 static void n_tty_receive_parity_error(struct tty_struct *tty, unsigned char c) in n_tty_receive_parity_error() argument
1210 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_parity_error()
1212 if (I_INPCK(tty)) { in n_tty_receive_parity_error()
1213 if (I_IGNPAR(tty)) in n_tty_receive_parity_error()
1215 if (I_PARMRK(tty)) { in n_tty_receive_parity_error()
1226 n_tty_receive_signal_char(struct tty_struct *tty, int signal, unsigned char c) in n_tty_receive_signal_char() argument
1228 isig(signal, tty); in n_tty_receive_signal_char()
1229 if (I_IXON(tty)) in n_tty_receive_signal_char()
1230 start_tty(tty); in n_tty_receive_signal_char()
1231 if (L_ECHO(tty)) { in n_tty_receive_signal_char()
1232 echo_char(c, tty); in n_tty_receive_signal_char()
1233 commit_echoes(tty); in n_tty_receive_signal_char()
1235 process_echoes(tty); in n_tty_receive_signal_char()
1256 n_tty_receive_char_special(struct tty_struct *tty, unsigned char c) in n_tty_receive_char_special() argument
1258 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_char_special()
1260 if (I_IXON(tty)) { in n_tty_receive_char_special()
1261 if (c == START_CHAR(tty)) { in n_tty_receive_char_special()
1262 start_tty(tty); in n_tty_receive_char_special()
1263 process_echoes(tty); in n_tty_receive_char_special()
1266 if (c == STOP_CHAR(tty)) { in n_tty_receive_char_special()
1267 stop_tty(tty); in n_tty_receive_char_special()
1272 if (L_ISIG(tty)) { in n_tty_receive_char_special()
1273 if (c == INTR_CHAR(tty)) { in n_tty_receive_char_special()
1274 n_tty_receive_signal_char(tty, SIGINT, c); in n_tty_receive_char_special()
1276 } else if (c == QUIT_CHAR(tty)) { in n_tty_receive_char_special()
1277 n_tty_receive_signal_char(tty, SIGQUIT, c); in n_tty_receive_char_special()
1279 } else if (c == SUSP_CHAR(tty)) { in n_tty_receive_char_special()
1280 n_tty_receive_signal_char(tty, SIGTSTP, c); in n_tty_receive_char_special()
1285 if (tty->stopped && !tty->flow_stopped && I_IXON(tty) && I_IXANY(tty)) { in n_tty_receive_char_special()
1286 start_tty(tty); in n_tty_receive_char_special()
1287 process_echoes(tty); in n_tty_receive_char_special()
1291 if (I_IGNCR(tty)) in n_tty_receive_char_special()
1293 if (I_ICRNL(tty)) in n_tty_receive_char_special()
1295 } else if (c == '\n' && I_INLCR(tty)) in n_tty_receive_char_special()
1299 if (c == ERASE_CHAR(tty) || c == KILL_CHAR(tty) || in n_tty_receive_char_special()
1300 (c == WERASE_CHAR(tty) && L_IEXTEN(tty))) { in n_tty_receive_char_special()
1301 eraser(c, tty); in n_tty_receive_char_special()
1302 commit_echoes(tty); in n_tty_receive_char_special()
1305 if (c == LNEXT_CHAR(tty) && L_IEXTEN(tty)) { in n_tty_receive_char_special()
1307 if (L_ECHO(tty)) { in n_tty_receive_char_special()
1309 if (L_ECHOCTL(tty)) { in n_tty_receive_char_special()
1312 commit_echoes(tty); in n_tty_receive_char_special()
1317 if (c == REPRINT_CHAR(tty) && L_ECHO(tty) && L_IEXTEN(tty)) { in n_tty_receive_char_special()
1321 echo_char(c, tty); in n_tty_receive_char_special()
1324 echo_char(read_buf(ldata, tail), tty); in n_tty_receive_char_special()
1327 commit_echoes(tty); in n_tty_receive_char_special()
1331 if (L_ECHO(tty) || L_ECHONL(tty)) { in n_tty_receive_char_special()
1333 commit_echoes(tty); in n_tty_receive_char_special()
1337 if (c == EOF_CHAR(tty)) { in n_tty_receive_char_special()
1341 if ((c == EOL_CHAR(tty)) || in n_tty_receive_char_special()
1342 (c == EOL2_CHAR(tty) && L_IEXTEN(tty))) { in n_tty_receive_char_special()
1346 if (L_ECHO(tty)) { in n_tty_receive_char_special()
1350 echo_char(c, tty); in n_tty_receive_char_special()
1351 commit_echoes(tty); in n_tty_receive_char_special()
1357 if (c == (unsigned char) '\377' && I_PARMRK(tty)) in n_tty_receive_char_special()
1364 kill_fasync(&tty->fasync, SIGIO, POLL_IN); in n_tty_receive_char_special()
1365 wake_up_interruptible_poll(&tty->read_wait, EPOLLIN); in n_tty_receive_char_special()
1370 if (L_ECHO(tty)) { in n_tty_receive_char_special()
1378 echo_char(c, tty); in n_tty_receive_char_special()
1380 commit_echoes(tty); in n_tty_receive_char_special()
1384 if (c == (unsigned char) '\377' && I_PARMRK(tty)) in n_tty_receive_char_special()
1392 n_tty_receive_char_inline(struct tty_struct *tty, unsigned char c) in n_tty_receive_char_inline() argument
1394 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_char_inline()
1396 if (tty->stopped && !tty->flow_stopped && I_IXON(tty) && I_IXANY(tty)) { in n_tty_receive_char_inline()
1397 start_tty(tty); in n_tty_receive_char_inline()
1398 process_echoes(tty); in n_tty_receive_char_inline()
1400 if (L_ECHO(tty)) { in n_tty_receive_char_inline()
1405 echo_char(c, tty); in n_tty_receive_char_inline()
1406 commit_echoes(tty); in n_tty_receive_char_inline()
1409 if (c == (unsigned char) '\377' && I_PARMRK(tty)) in n_tty_receive_char_inline()
1414 static void n_tty_receive_char(struct tty_struct *tty, unsigned char c) in n_tty_receive_char() argument
1416 n_tty_receive_char_inline(tty, c); in n_tty_receive_char()
1420 n_tty_receive_char_fast(struct tty_struct *tty, unsigned char c) in n_tty_receive_char_fast() argument
1422 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_char_fast()
1424 if (tty->stopped && !tty->flow_stopped && I_IXON(tty) && I_IXANY(tty)) { in n_tty_receive_char_fast()
1425 start_tty(tty); in n_tty_receive_char_fast()
1426 process_echoes(tty); in n_tty_receive_char_fast()
1428 if (L_ECHO(tty)) { in n_tty_receive_char_fast()
1433 echo_char(c, tty); in n_tty_receive_char_fast()
1434 commit_echoes(tty); in n_tty_receive_char_fast()
1439 static void n_tty_receive_char_closing(struct tty_struct *tty, unsigned char c) in n_tty_receive_char_closing() argument
1441 if (I_ISTRIP(tty)) in n_tty_receive_char_closing()
1443 if (I_IUCLC(tty) && L_IEXTEN(tty)) in n_tty_receive_char_closing()
1446 if (I_IXON(tty)) { in n_tty_receive_char_closing()
1447 if (c == STOP_CHAR(tty)) in n_tty_receive_char_closing()
1448 stop_tty(tty); in n_tty_receive_char_closing()
1449 else if (c == START_CHAR(tty) || in n_tty_receive_char_closing()
1450 (tty->stopped && !tty->flow_stopped && I_IXANY(tty) && in n_tty_receive_char_closing()
1451 c != INTR_CHAR(tty) && c != QUIT_CHAR(tty) && in n_tty_receive_char_closing()
1452 c != SUSP_CHAR(tty))) { in n_tty_receive_char_closing()
1453 start_tty(tty); in n_tty_receive_char_closing()
1454 process_echoes(tty); in n_tty_receive_char_closing()
1460 n_tty_receive_char_flagged(struct tty_struct *tty, unsigned char c, char flag) in n_tty_receive_char_flagged() argument
1464 n_tty_receive_break(tty); in n_tty_receive_char_flagged()
1468 n_tty_receive_parity_error(tty, c); in n_tty_receive_char_flagged()
1471 n_tty_receive_overrun(tty); in n_tty_receive_char_flagged()
1474 tty_err(tty, "unknown flag %d\n", flag); in n_tty_receive_char_flagged()
1480 n_tty_receive_char_lnext(struct tty_struct *tty, unsigned char c, char flag) in n_tty_receive_char_lnext() argument
1482 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_char_lnext()
1486 if (I_ISTRIP(tty)) in n_tty_receive_char_lnext()
1488 if (I_IUCLC(tty) && L_IEXTEN(tty)) in n_tty_receive_char_lnext()
1490 n_tty_receive_char(tty, c); in n_tty_receive_char_lnext()
1492 n_tty_receive_char_flagged(tty, c, flag); in n_tty_receive_char_lnext()
1496 n_tty_receive_buf_real_raw(struct tty_struct *tty, const unsigned char *cp, in n_tty_receive_buf_real_raw() argument
1499 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_real_raw()
1516 n_tty_receive_buf_raw(struct tty_struct *tty, const unsigned char *cp, in n_tty_receive_buf_raw() argument
1519 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_raw()
1528 n_tty_receive_char_flagged(tty, *cp++, flag); in n_tty_receive_buf_raw()
1533 n_tty_receive_buf_closing(struct tty_struct *tty, const unsigned char *cp, in n_tty_receive_buf_closing() argument
1542 n_tty_receive_char_closing(tty, *cp++); in n_tty_receive_buf_closing()
1547 n_tty_receive_buf_standard(struct tty_struct *tty, const unsigned char *cp, in n_tty_receive_buf_standard() argument
1550 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_standard()
1559 if (I_ISTRIP(tty)) in n_tty_receive_buf_standard()
1561 if (I_IUCLC(tty) && L_IEXTEN(tty)) in n_tty_receive_buf_standard()
1563 if (L_EXTPROC(tty)) { in n_tty_receive_buf_standard()
1568 n_tty_receive_char_inline(tty, c); in n_tty_receive_buf_standard()
1569 else if (n_tty_receive_char_special(tty, c) && count) { in n_tty_receive_buf_standard()
1572 n_tty_receive_char_lnext(tty, *cp++, flag); in n_tty_receive_buf_standard()
1576 n_tty_receive_char_flagged(tty, *cp++, flag); in n_tty_receive_buf_standard()
1581 n_tty_receive_buf_fast(struct tty_struct *tty, const unsigned char *cp, in n_tty_receive_buf_fast() argument
1584 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_fast()
1594 n_tty_receive_char_fast(tty, c); in n_tty_receive_buf_fast()
1595 else if (n_tty_receive_char_special(tty, c) && count) { in n_tty_receive_buf_fast()
1598 n_tty_receive_char_lnext(tty, *cp++, flag); in n_tty_receive_buf_fast()
1602 n_tty_receive_char_flagged(tty, *cp++, flag); in n_tty_receive_buf_fast()
1606 static void __receive_buf(struct tty_struct *tty, const unsigned char *cp, in __receive_buf() argument
1609 struct n_tty_data *ldata = tty->disc_data; in __receive_buf()
1610 bool preops = I_ISTRIP(tty) || (I_IUCLC(tty) && L_IEXTEN(tty)); in __receive_buf()
1613 n_tty_receive_buf_real_raw(tty, cp, fp, count); in __receive_buf()
1614 else if (ldata->raw || (L_EXTPROC(tty) && !preops)) in __receive_buf()
1615 n_tty_receive_buf_raw(tty, cp, fp, count); in __receive_buf()
1616 else if (tty->closing && !L_EXTPROC(tty)) in __receive_buf()
1617 n_tty_receive_buf_closing(tty, cp, fp, count); in __receive_buf()
1624 n_tty_receive_char_lnext(tty, *cp++, flag); in __receive_buf()
1628 if (!preops && !I_PARMRK(tty)) in __receive_buf()
1629 n_tty_receive_buf_fast(tty, cp, fp, count); in __receive_buf()
1631 n_tty_receive_buf_standard(tty, cp, fp, count); in __receive_buf()
1633 flush_echoes(tty); in __receive_buf()
1634 if (tty->ops->flush_chars) in __receive_buf()
1635 tty->ops->flush_chars(tty); in __receive_buf()
1638 if (ldata->icanon && !L_EXTPROC(tty)) in __receive_buf()
1645 kill_fasync(&tty->fasync, SIGIO, POLL_IN); in __receive_buf()
1646 wake_up_interruptible_poll(&tty->read_wait, EPOLLIN); in __receive_buf()
1684 n_tty_receive_buf_common(struct tty_struct *tty, const unsigned char *cp, in n_tty_receive_buf_common() argument
1687 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_common()
1690 down_read(&tty->termios_rwsem); in n_tty_receive_buf_common()
1709 if (I_PARMRK(tty)) in n_tty_receive_buf_common()
1727 __receive_buf(tty, cp, fp, n); in n_tty_receive_buf_common()
1736 tty->receive_room = room; in n_tty_receive_buf_common()
1739 if (tty->driver->type == TTY_DRIVER_TYPE_PTY) { in n_tty_receive_buf_common()
1741 tty_set_flow_change(tty, TTY_UNTHROTTLE_SAFE); in n_tty_receive_buf_common()
1742 tty_unthrottle_safe(tty); in n_tty_receive_buf_common()
1743 __tty_set_flow_change(tty, 0); in n_tty_receive_buf_common()
1746 n_tty_check_throttle(tty); in n_tty_receive_buf_common()
1748 up_read(&tty->termios_rwsem); in n_tty_receive_buf_common()
1753 static void n_tty_receive_buf(struct tty_struct *tty, const unsigned char *cp, in n_tty_receive_buf() argument
1756 n_tty_receive_buf_common(tty, cp, fp, count, 0); in n_tty_receive_buf()
1759 static int n_tty_receive_buf2(struct tty_struct *tty, const unsigned char *cp, in n_tty_receive_buf2() argument
1762 return n_tty_receive_buf_common(tty, cp, fp, count, 1); in n_tty_receive_buf2()
1779 static void n_tty_set_termios(struct tty_struct *tty, struct ktermios *old) in n_tty_set_termios() argument
1781 struct n_tty_data *ldata = tty->disc_data; in n_tty_set_termios()
1783 if (!old || (old->c_lflag ^ tty->termios.c_lflag) & (ICANON | EXTPROC)) { in n_tty_set_termios()
1786 if (!L_ICANON(tty) || !read_cnt(ldata)) { in n_tty_set_termios()
1800 ldata->icanon = (L_ICANON(tty) != 0); in n_tty_set_termios()
1802 if (I_ISTRIP(tty) || I_IUCLC(tty) || I_IGNCR(tty) || in n_tty_set_termios()
1803 I_ICRNL(tty) || I_INLCR(tty) || L_ICANON(tty) || in n_tty_set_termios()
1804 I_IXON(tty) || L_ISIG(tty) || L_ECHO(tty) || in n_tty_set_termios()
1805 I_PARMRK(tty)) { in n_tty_set_termios()
1808 if (I_IGNCR(tty) || I_ICRNL(tty)) in n_tty_set_termios()
1810 if (I_INLCR(tty)) in n_tty_set_termios()
1813 if (L_ICANON(tty)) { in n_tty_set_termios()
1814 set_bit(ERASE_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1815 set_bit(KILL_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1816 set_bit(EOF_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1818 set_bit(EOL_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1819 if (L_IEXTEN(tty)) { in n_tty_set_termios()
1820 set_bit(WERASE_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1821 set_bit(LNEXT_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1822 set_bit(EOL2_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1823 if (L_ECHO(tty)) in n_tty_set_termios()
1824 set_bit(REPRINT_CHAR(tty), in n_tty_set_termios()
1828 if (I_IXON(tty)) { in n_tty_set_termios()
1829 set_bit(START_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1830 set_bit(STOP_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1832 if (L_ISIG(tty)) { in n_tty_set_termios()
1833 set_bit(INTR_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1834 set_bit(QUIT_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1835 set_bit(SUSP_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1842 if ((I_IGNBRK(tty) || (!I_BRKINT(tty) && !I_PARMRK(tty))) && in n_tty_set_termios()
1843 (I_IGNPAR(tty) || !I_INPCK(tty)) && in n_tty_set_termios()
1844 (tty->driver->flags & TTY_DRIVER_REAL_RAW)) in n_tty_set_termios()
1853 if (!I_IXON(tty) && old && (old->c_iflag & IXON) && !tty->flow_stopped) { in n_tty_set_termios()
1854 start_tty(tty); in n_tty_set_termios()
1855 process_echoes(tty); in n_tty_set_termios()
1859 wake_up_interruptible(&tty->write_wait); in n_tty_set_termios()
1860 wake_up_interruptible(&tty->read_wait); in n_tty_set_termios()
1873 static void n_tty_close(struct tty_struct *tty) in n_tty_close() argument
1875 struct n_tty_data *ldata = tty->disc_data; in n_tty_close()
1877 if (tty->link) in n_tty_close()
1878 n_tty_packet_mode_flush(tty); in n_tty_close()
1881 tty->disc_data = NULL; in n_tty_close()
1894 static int n_tty_open(struct tty_struct *tty) in n_tty_open() argument
1907 tty->disc_data = ldata; in n_tty_open()
1908 tty->closing = 0; in n_tty_open()
1910 clear_bit(TTY_LDISC_HALTED, &tty->flags); in n_tty_open()
1911 n_tty_set_termios(tty, NULL); in n_tty_open()
1912 tty_unthrottle(tty); in n_tty_open()
1916 static inline int input_available_p(struct tty_struct *tty, int poll) in input_available_p() argument
1918 struct n_tty_data *ldata = tty->disc_data; in input_available_p()
1919 int amt = poll && !TIME_CHAR(tty) && MIN_CHAR(tty) ? MIN_CHAR(tty) : 1; in input_available_p()
1921 if (ldata->icanon && !L_EXTPROC(tty)) in input_available_p()
1947 static int copy_from_read_buf(struct tty_struct *tty, in copy_from_read_buf() argument
1952 struct n_tty_data *ldata = tty->disc_data; in copy_from_read_buf()
1966 is_eof = n == 1 && *from == EOF_CHAR(tty); in copy_from_read_buf()
1967 tty_audit_add_data(tty, from, n); in copy_from_read_buf()
1970 if (L_EXTPROC(tty) && ldata->icanon && is_eof && in copy_from_read_buf()
2002 static int canon_copy_from_read_buf(struct tty_struct *tty, in canon_copy_from_read_buf() argument
2006 struct n_tty_data *ldata = tty->disc_data; in canon_copy_from_read_buf()
2046 ret = tty_copy_to_user(tty, *b, tail, n); in canon_copy_from_read_buf()
2083 static int job_control(struct tty_struct *tty, struct file *file) in job_control() argument
2093 return __tty_check_change(tty, SIGTTIN); in job_control()
2116 static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, in n_tty_read() argument
2119 struct n_tty_data *ldata = tty->disc_data; in n_tty_read()
2129 c = job_control(tty, file); in n_tty_read()
2144 down_read(&tty->termios_rwsem); in n_tty_read()
2149 minimum = MIN_CHAR(tty); in n_tty_read()
2151 time = (HZ / 10) * TIME_CHAR(tty); in n_tty_read()
2153 timeout = (HZ / 10) * TIME_CHAR(tty); in n_tty_read()
2158 packet = tty->packet; in n_tty_read()
2161 add_wait_queue(&tty->read_wait, &wait); in n_tty_read()
2164 if (packet && tty->link->ctrl_status) { in n_tty_read()
2168 spin_lock_irq(&tty->link->ctrl_lock); in n_tty_read()
2169 cs = tty->link->ctrl_status; in n_tty_read()
2170 tty->link->ctrl_status = 0; in n_tty_read()
2171 spin_unlock_irq(&tty->link->ctrl_lock); in n_tty_read()
2181 if (!input_available_p(tty, 0)) { in n_tty_read()
2182 up_read(&tty->termios_rwsem); in n_tty_read()
2183 tty_buffer_flush_work(tty->port); in n_tty_read()
2184 down_read(&tty->termios_rwsem); in n_tty_read()
2185 if (!input_available_p(tty, 0)) { in n_tty_read()
2186 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) { in n_tty_read()
2196 if (test_bit(TTY_HUPPING, &tty->flags)) in n_tty_read()
2208 up_read(&tty->termios_rwsem); in n_tty_read()
2213 down_read(&tty->termios_rwsem); in n_tty_read()
2218 if (ldata->icanon && !L_EXTPROC(tty)) { in n_tty_read()
2219 retval = canon_copy_from_read_buf(tty, &b, &nr); in n_tty_read()
2235 uncopied = copy_from_read_buf(tty, &b, &nr); in n_tty_read()
2236 uncopied += copy_from_read_buf(tty, &b, &nr); in n_tty_read()
2243 n_tty_check_unthrottle(tty); in n_tty_read()
2251 n_tty_kick_worker(tty); in n_tty_read()
2252 up_read(&tty->termios_rwsem); in n_tty_read()
2254 remove_wait_queue(&tty->read_wait, &wait); in n_tty_read()
2285 static ssize_t n_tty_write(struct tty_struct *tty, struct file *file, in n_tty_write() argument
2294 if (L_TOSTOP(tty) && file->f_op->write != redirected_tty_write) { in n_tty_write()
2295 retval = tty_check_change(tty); in n_tty_write()
2300 down_read(&tty->termios_rwsem); in n_tty_write()
2303 process_echoes(tty); in n_tty_write()
2305 add_wait_queue(&tty->write_wait, &wait); in n_tty_write()
2311 if (tty_hung_up_p(file) || (tty->link && !tty->link->count)) { in n_tty_write()
2315 if (O_OPOST(tty)) { in n_tty_write()
2317 ssize_t num = process_output_block(tty, b, nr); in n_tty_write()
2329 if (process_output(c, tty) < 0) in n_tty_write()
2333 if (tty->ops->flush_chars) in n_tty_write()
2334 tty->ops->flush_chars(tty); in n_tty_write()
2336 struct n_tty_data *ldata = tty->disc_data; in n_tty_write()
2340 c = tty->ops->write(tty, b, nr); in n_tty_write()
2358 up_read(&tty->termios_rwsem); in n_tty_write()
2362 down_read(&tty->termios_rwsem); in n_tty_write()
2365 remove_wait_queue(&tty->write_wait, &wait); in n_tty_write()
2366 if (nr && tty->fasync) in n_tty_write()
2367 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in n_tty_write()
2368 up_read(&tty->termios_rwsem); in n_tty_write()
2386 static __poll_t n_tty_poll(struct tty_struct *tty, struct file *file, in n_tty_poll() argument
2391 poll_wait(file, &tty->read_wait, wait); in n_tty_poll()
2392 poll_wait(file, &tty->write_wait, wait); in n_tty_poll()
2393 if (input_available_p(tty, 1)) in n_tty_poll()
2396 tty_buffer_flush_work(tty->port); in n_tty_poll()
2397 if (input_available_p(tty, 1)) in n_tty_poll()
2400 if (tty->packet && tty->link->ctrl_status) in n_tty_poll()
2402 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) in n_tty_poll()
2406 if (tty->ops->write && !tty_is_writelocked(tty) && in n_tty_poll()
2407 tty_chars_in_buffer(tty) < WAKEUP_CHARS && in n_tty_poll()
2408 tty_write_room(tty) > 0) in n_tty_poll()
2432 static int n_tty_ioctl(struct tty_struct *tty, struct file *file, in n_tty_ioctl() argument
2435 struct n_tty_data *ldata = tty->disc_data; in n_tty_ioctl()
2440 return put_user(tty_chars_in_buffer(tty), (int __user *) arg); in n_tty_ioctl()
2442 down_write(&tty->termios_rwsem); in n_tty_ioctl()
2443 if (L_ICANON(tty) && !L_EXTPROC(tty)) in n_tty_ioctl()
2447 up_write(&tty->termios_rwsem); in n_tty_ioctl()
2450 return n_tty_ioctl_helper(tty, file, cmd, arg); in n_tty_ioctl()