Lines Matching refs:tty

159 static void zero_buffer(struct tty_struct *tty, u8 *buffer, int size)  in zero_buffer()  argument
161 bool icanon = !!L_ICANON(tty); in zero_buffer()
162 bool no_echo = !L_ECHO(tty); in zero_buffer()
168 static void tty_copy(struct tty_struct *tty, void *to, size_t tail, size_t n) 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()
200 static void n_tty_kick_worker(struct tty_struct *tty) in n_tty_kick_worker() argument
202 struct n_tty_data *ldata = tty->disc_data; in n_tty_kick_worker()
208 WARN_RATELIMIT(tty->port->itty == NULL, in n_tty_kick_worker()
214 WARN_RATELIMIT(test_bit(TTY_LDISC_HALTED, &tty->flags), in n_tty_kick_worker()
216 tty_buffer_restart_work(tty->port); in n_tty_kick_worker()
220 static ssize_t chars_in_buffer(struct tty_struct *tty) in chars_in_buffer() argument
222 struct n_tty_data *ldata = tty->disc_data; in chars_in_buffer()
241 static void n_tty_write_wakeup(struct tty_struct *tty) in n_tty_write_wakeup() argument
243 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in n_tty_write_wakeup()
244 kill_fasync(&tty->fasync, SIGIO, POLL_OUT); in n_tty_write_wakeup()
247 static void n_tty_check_throttle(struct tty_struct *tty) in n_tty_check_throttle() argument
249 struct n_tty_data *ldata = tty->disc_data; in n_tty_check_throttle()
261 tty_set_flow_change(tty, TTY_THROTTLE_SAFE); in n_tty_check_throttle()
264 throttled = tty_throttle_safe(tty); in n_tty_check_throttle()
268 __tty_set_flow_change(tty, 0); in n_tty_check_throttle()
271 static void n_tty_check_unthrottle(struct tty_struct *tty) in n_tty_check_unthrottle() argument
273 if (tty->driver->type == TTY_DRIVER_TYPE_PTY) { in n_tty_check_unthrottle()
274 if (chars_in_buffer(tty) > TTY_THRESHOLD_UNTHROTTLE) in n_tty_check_unthrottle()
276 n_tty_kick_worker(tty); in n_tty_check_unthrottle()
277 tty_wakeup(tty->link); in n_tty_check_unthrottle()
291 tty_set_flow_change(tty, TTY_UNTHROTTLE_SAFE); in n_tty_check_unthrottle()
292 if (chars_in_buffer(tty) > TTY_THRESHOLD_UNTHROTTLE) in n_tty_check_unthrottle()
294 n_tty_kick_worker(tty); in n_tty_check_unthrottle()
295 unthrottled = tty_unthrottle_safe(tty); in n_tty_check_unthrottle()
299 __tty_set_flow_change(tty, 0); in n_tty_check_unthrottle()
341 static void n_tty_packet_mode_flush(struct tty_struct *tty) in n_tty_packet_mode_flush() argument
345 if (tty->link->ctrl.packet) { in n_tty_packet_mode_flush()
346 spin_lock_irqsave(&tty->ctrl.lock, flags); in n_tty_packet_mode_flush()
347 tty->ctrl.pktstatus |= TIOCPKT_FLUSHREAD; in n_tty_packet_mode_flush()
348 spin_unlock_irqrestore(&tty->ctrl.lock, flags); in n_tty_packet_mode_flush()
349 wake_up_interruptible(&tty->link->read_wait); in n_tty_packet_mode_flush()
367 static void n_tty_flush_buffer(struct tty_struct *tty) in n_tty_flush_buffer() argument
369 down_write(&tty->termios_rwsem); in n_tty_flush_buffer()
370 reset_buffer_flags(tty->disc_data); in n_tty_flush_buffer()
371 n_tty_kick_worker(tty); in n_tty_flush_buffer()
373 if (tty->link) in n_tty_flush_buffer()
374 n_tty_packet_mode_flush(tty); in n_tty_flush_buffer()
375 up_write(&tty->termios_rwsem); in n_tty_flush_buffer()
401 static inline int is_continuation(unsigned char c, struct tty_struct *tty) in is_continuation() argument
403 return I_IUTF8(tty) && is_utf8_continuation(c); in is_continuation()
428 static int do_output_char(unsigned char c, struct tty_struct *tty, int space) in do_output_char() argument
430 struct n_tty_data *ldata = tty->disc_data; in do_output_char()
438 if (O_ONLRET(tty)) in do_output_char()
440 if (O_ONLCR(tty)) { in do_output_char()
444 tty->ops->write(tty, "\r\n", 2); in do_output_char()
450 if (O_ONOCR(tty) && ldata->column == 0) in do_output_char()
452 if (O_OCRNL(tty)) { in do_output_char()
454 if (O_ONLRET(tty)) in do_output_char()
462 if (O_TABDLY(tty) == XTABS) { in do_output_char()
466 tty->ops->write(tty, " ", spaces); in do_output_char()
477 if (O_OLCUC(tty)) in do_output_char()
479 if (!is_continuation(c, tty)) in do_output_char()
485 tty_put_char(tty, c); in do_output_char()
503 static int process_output(unsigned char c, struct tty_struct *tty) in process_output() argument
505 struct n_tty_data *ldata = tty->disc_data; in process_output()
510 space = tty_write_room(tty); in process_output()
511 retval = do_output_char(c, tty, space); in process_output()
539 static ssize_t process_output_block(struct tty_struct *tty, in process_output_block() argument
542 struct n_tty_data *ldata = tty->disc_data; in process_output_block()
549 space = tty_write_room(tty); in process_output_block()
562 if (O_ONLRET(tty)) in process_output_block()
564 if (O_ONLCR(tty)) in process_output_block()
569 if (O_ONOCR(tty) && ldata->column == 0) in process_output_block()
571 if (O_OCRNL(tty)) in process_output_block()
583 if (O_OLCUC(tty)) in process_output_block()
585 if (!is_continuation(c, tty)) in process_output_block()
592 i = tty->ops->write(tty, buf, i); in process_output_block()
623 static size_t __process_echoes(struct tty_struct *tty) in __process_echoes() argument
625 struct n_tty_data *ldata = tty->disc_data; in __process_echoes()
630 old_space = space = tty_write_room(tty); in __process_echoes()
681 tty_put_char(tty, '\b'); in __process_echoes()
705 tty_put_char(tty, ECHO_OP_START); in __process_echoes()
725 tty_put_char(tty, '^'); in __process_echoes()
726 tty_put_char(tty, op ^ 0100); in __process_echoes()
735 if (O_OPOST(tty)) { in __process_echoes()
736 int retval = do_output_char(c, tty, space); in __process_echoes()
743 tty_put_char(tty, c); in __process_echoes()
769 static void commit_echoes(struct tty_struct *tty) in commit_echoes() argument
771 struct n_tty_data *ldata = tty->disc_data; in commit_echoes()
791 echoed = __process_echoes(tty); in commit_echoes()
794 if (echoed && tty->ops->flush_chars) in commit_echoes()
795 tty->ops->flush_chars(tty); in commit_echoes()
798 static void process_echoes(struct tty_struct *tty) in process_echoes() argument
800 struct n_tty_data *ldata = tty->disc_data; in process_echoes()
808 echoed = __process_echoes(tty); in process_echoes()
811 if (echoed && tty->ops->flush_chars) in process_echoes()
812 tty->ops->flush_chars(tty); in process_echoes()
816 static void flush_echoes(struct tty_struct *tty) in flush_echoes() argument
818 struct n_tty_data *ldata = tty->disc_data; in flush_echoes()
820 if ((!L_ECHO(tty) && !L_ECHONL(tty)) || in flush_echoes()
826 __process_echoes(tty); in flush_echoes()
936 static void echo_char(unsigned char c, struct tty_struct *tty) in echo_char() argument
938 struct n_tty_data *ldata = tty->disc_data; in echo_char()
944 if (L_ECHOCTL(tty) && iscntrl(c) && c != '\t') in echo_char()
976 static void eraser(unsigned char c, struct tty_struct *tty) in eraser() argument
978 struct n_tty_data *ldata = tty->disc_data; in eraser()
988 if (c == ERASE_CHAR(tty)) in eraser()
990 else if (c == WERASE_CHAR(tty)) in eraser()
993 if (!L_ECHO(tty)) { in eraser()
997 if (!L_ECHOK(tty) || !L_ECHOKE(tty) || !L_ECHOE(tty)) { in eraser()
1000 echo_char(KILL_CHAR(tty), tty); in eraser()
1002 if (L_ECHOK(tty)) in eraser()
1017 } while (is_continuation(c, tty) && in eraser()
1021 if (is_continuation(c, tty)) in eraser()
1033 if (L_ECHO(tty)) { in eraser()
1034 if (L_ECHOPRT(tty)) { in eraser()
1040 echo_char(c, tty); in eraser()
1046 } else if (kill_type == ERASE && !L_ECHOE(tty)) { in eraser()
1047 echo_char(ERASE_CHAR(tty), tty); in eraser()
1067 if (L_ECHOCTL(tty)) in eraser()
1069 } else if (!is_continuation(c, tty)) { in eraser()
1075 if (iscntrl(c) && L_ECHOCTL(tty)) { in eraser()
1080 if (!iscntrl(c) || L_ECHOCTL(tty)) { in eraser()
1090 if (ldata->read_head == ldata->canon_head && L_ECHO(tty)) in eraser()
1109 static void __isig(int sig, struct tty_struct *tty) in __isig() argument
1111 struct pid *tty_pgrp = tty_get_pgrp(tty); in __isig()
1118 static void isig(int sig, struct tty_struct *tty) in isig() argument
1120 struct n_tty_data *ldata = tty->disc_data; in isig()
1122 if (L_NOFLSH(tty)) { in isig()
1124 __isig(sig, tty); in isig()
1127 up_read(&tty->termios_rwsem); in isig()
1128 down_write(&tty->termios_rwsem); in isig()
1130 __isig(sig, tty); in isig()
1139 tty_driver_flush_buffer(tty); in isig()
1142 reset_buffer_flags(tty->disc_data); in isig()
1145 if (tty->link) in isig()
1146 n_tty_packet_mode_flush(tty); in isig()
1148 up_write(&tty->termios_rwsem); in isig()
1149 down_read(&tty->termios_rwsem); in isig()
1166 static void n_tty_receive_break(struct tty_struct *tty) in n_tty_receive_break() argument
1168 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_break()
1170 if (I_IGNBRK(tty)) in n_tty_receive_break()
1172 if (I_BRKINT(tty)) { in n_tty_receive_break()
1173 isig(SIGINT, tty); in n_tty_receive_break()
1176 if (I_PARMRK(tty)) { in n_tty_receive_break()
1196 static void n_tty_receive_overrun(struct tty_struct *tty) in n_tty_receive_overrun() argument
1198 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_overrun()
1203 tty_warn(tty, "%d input overrun(s)\n", ldata->num_overrun); in n_tty_receive_overrun()
1220 static void n_tty_receive_parity_error(struct tty_struct *tty, unsigned char c) in n_tty_receive_parity_error() argument
1222 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_parity_error()
1224 if (I_INPCK(tty)) { in n_tty_receive_parity_error()
1225 if (I_IGNPAR(tty)) in n_tty_receive_parity_error()
1227 if (I_PARMRK(tty)) { in n_tty_receive_parity_error()
1238 n_tty_receive_signal_char(struct tty_struct *tty, int signal, unsigned char c) in n_tty_receive_signal_char() argument
1240 isig(signal, tty); in n_tty_receive_signal_char()
1241 if (I_IXON(tty)) in n_tty_receive_signal_char()
1242 start_tty(tty); in n_tty_receive_signal_char()
1243 if (L_ECHO(tty)) { in n_tty_receive_signal_char()
1244 echo_char(c, tty); in n_tty_receive_signal_char()
1245 commit_echoes(tty); in n_tty_receive_signal_char()
1247 process_echoes(tty); in n_tty_receive_signal_char()
1263 static void n_tty_receive_char_special(struct tty_struct *tty, unsigned char c) in n_tty_receive_char_special() argument
1265 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_char_special()
1267 if (I_IXON(tty)) { in n_tty_receive_char_special()
1268 if (c == START_CHAR(tty)) { in n_tty_receive_char_special()
1269 start_tty(tty); in n_tty_receive_char_special()
1270 process_echoes(tty); in n_tty_receive_char_special()
1273 if (c == STOP_CHAR(tty)) { in n_tty_receive_char_special()
1274 stop_tty(tty); in n_tty_receive_char_special()
1279 if (L_ISIG(tty)) { in n_tty_receive_char_special()
1280 if (c == INTR_CHAR(tty)) { in n_tty_receive_char_special()
1281 n_tty_receive_signal_char(tty, SIGINT, c); in n_tty_receive_char_special()
1283 } else if (c == QUIT_CHAR(tty)) { in n_tty_receive_char_special()
1284 n_tty_receive_signal_char(tty, SIGQUIT, c); in n_tty_receive_char_special()
1286 } else if (c == SUSP_CHAR(tty)) { in n_tty_receive_char_special()
1287 n_tty_receive_signal_char(tty, SIGTSTP, c); in n_tty_receive_char_special()
1292 if (tty->flow.stopped && !tty->flow.tco_stopped && I_IXON(tty) && I_IXANY(tty)) { in n_tty_receive_char_special()
1293 start_tty(tty); in n_tty_receive_char_special()
1294 process_echoes(tty); in n_tty_receive_char_special()
1298 if (I_IGNCR(tty)) in n_tty_receive_char_special()
1300 if (I_ICRNL(tty)) in n_tty_receive_char_special()
1302 } else if (c == '\n' && I_INLCR(tty)) in n_tty_receive_char_special()
1306 if (c == ERASE_CHAR(tty) || c == KILL_CHAR(tty) || in n_tty_receive_char_special()
1307 (c == WERASE_CHAR(tty) && L_IEXTEN(tty))) { in n_tty_receive_char_special()
1308 eraser(c, tty); in n_tty_receive_char_special()
1309 commit_echoes(tty); in n_tty_receive_char_special()
1312 if (c == LNEXT_CHAR(tty) && L_IEXTEN(tty)) { in n_tty_receive_char_special()
1314 if (L_ECHO(tty)) { in n_tty_receive_char_special()
1316 if (L_ECHOCTL(tty)) { in n_tty_receive_char_special()
1319 commit_echoes(tty); in n_tty_receive_char_special()
1324 if (c == REPRINT_CHAR(tty) && L_ECHO(tty) && L_IEXTEN(tty)) { in n_tty_receive_char_special()
1328 echo_char(c, tty); in n_tty_receive_char_special()
1331 echo_char(read_buf(ldata, tail), tty); in n_tty_receive_char_special()
1334 commit_echoes(tty); in n_tty_receive_char_special()
1338 if (L_ECHO(tty) || L_ECHONL(tty)) { in n_tty_receive_char_special()
1340 commit_echoes(tty); in n_tty_receive_char_special()
1344 if (c == EOF_CHAR(tty)) { in n_tty_receive_char_special()
1348 if ((c == EOL_CHAR(tty)) || in n_tty_receive_char_special()
1349 (c == EOL2_CHAR(tty) && L_IEXTEN(tty))) { in n_tty_receive_char_special()
1353 if (L_ECHO(tty)) { in n_tty_receive_char_special()
1357 echo_char(c, tty); in n_tty_receive_char_special()
1358 commit_echoes(tty); in n_tty_receive_char_special()
1364 if (c == (unsigned char) '\377' && I_PARMRK(tty)) in n_tty_receive_char_special()
1371 kill_fasync(&tty->fasync, SIGIO, POLL_IN); in n_tty_receive_char_special()
1372 wake_up_interruptible_poll(&tty->read_wait, EPOLLIN); in n_tty_receive_char_special()
1377 if (L_ECHO(tty)) { in n_tty_receive_char_special()
1385 echo_char(c, tty); in n_tty_receive_char_special()
1387 commit_echoes(tty); in n_tty_receive_char_special()
1391 if (c == (unsigned char) '\377' && I_PARMRK(tty)) in n_tty_receive_char_special()
1397 static void n_tty_receive_char(struct tty_struct *tty, unsigned char c) in n_tty_receive_char() argument
1399 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_char()
1401 if (tty->flow.stopped && !tty->flow.tco_stopped && I_IXON(tty) && I_IXANY(tty)) { in n_tty_receive_char()
1402 start_tty(tty); in n_tty_receive_char()
1403 process_echoes(tty); in n_tty_receive_char()
1405 if (L_ECHO(tty)) { in n_tty_receive_char()
1410 echo_char(c, tty); in n_tty_receive_char()
1411 commit_echoes(tty); in n_tty_receive_char()
1414 if (c == (unsigned char) '\377' && I_PARMRK(tty)) in n_tty_receive_char()
1419 static void n_tty_receive_char_closing(struct tty_struct *tty, unsigned char c) in n_tty_receive_char_closing() argument
1421 if (I_ISTRIP(tty)) in n_tty_receive_char_closing()
1423 if (I_IUCLC(tty) && L_IEXTEN(tty)) in n_tty_receive_char_closing()
1426 if (I_IXON(tty)) { in n_tty_receive_char_closing()
1427 if (c == STOP_CHAR(tty)) in n_tty_receive_char_closing()
1428 stop_tty(tty); in n_tty_receive_char_closing()
1429 else if (c == START_CHAR(tty) || in n_tty_receive_char_closing()
1430 (tty->flow.stopped && !tty->flow.tco_stopped && I_IXANY(tty) && in n_tty_receive_char_closing()
1431 c != INTR_CHAR(tty) && c != QUIT_CHAR(tty) && in n_tty_receive_char_closing()
1432 c != SUSP_CHAR(tty))) { in n_tty_receive_char_closing()
1433 start_tty(tty); in n_tty_receive_char_closing()
1434 process_echoes(tty); in n_tty_receive_char_closing()
1440 n_tty_receive_char_flagged(struct tty_struct *tty, unsigned char c, char flag) in n_tty_receive_char_flagged() argument
1444 n_tty_receive_break(tty); in n_tty_receive_char_flagged()
1448 n_tty_receive_parity_error(tty, c); in n_tty_receive_char_flagged()
1451 n_tty_receive_overrun(tty); in n_tty_receive_char_flagged()
1454 tty_err(tty, "unknown flag %d\n", flag); in n_tty_receive_char_flagged()
1460 n_tty_receive_char_lnext(struct tty_struct *tty, unsigned char c, char flag) in n_tty_receive_char_lnext() argument
1462 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_char_lnext()
1466 if (I_ISTRIP(tty)) in n_tty_receive_char_lnext()
1468 if (I_IUCLC(tty) && L_IEXTEN(tty)) in n_tty_receive_char_lnext()
1470 n_tty_receive_char(tty, c); in n_tty_receive_char_lnext()
1472 n_tty_receive_char_flagged(tty, c, flag); in n_tty_receive_char_lnext()
1476 n_tty_receive_buf_real_raw(struct tty_struct *tty, const unsigned char *cp, in n_tty_receive_buf_real_raw() argument
1479 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_real_raw()
1496 n_tty_receive_buf_raw(struct tty_struct *tty, const unsigned char *cp, in n_tty_receive_buf_raw() argument
1499 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_raw()
1508 n_tty_receive_char_flagged(tty, *cp++, flag); in n_tty_receive_buf_raw()
1513 n_tty_receive_buf_closing(struct tty_struct *tty, const unsigned char *cp, in n_tty_receive_buf_closing() argument
1522 n_tty_receive_char_closing(tty, *cp++); in n_tty_receive_buf_closing()
1526 static void n_tty_receive_buf_standard(struct tty_struct *tty, in n_tty_receive_buf_standard() argument
1529 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_standard()
1539 n_tty_receive_char_lnext(tty, c, flag); in n_tty_receive_buf_standard()
1544 n_tty_receive_char_flagged(tty, c, flag); in n_tty_receive_buf_standard()
1548 if (I_ISTRIP(tty)) in n_tty_receive_buf_standard()
1550 if (I_IUCLC(tty) && L_IEXTEN(tty)) in n_tty_receive_buf_standard()
1552 if (L_EXTPROC(tty)) { in n_tty_receive_buf_standard()
1558 n_tty_receive_char_special(tty, c); in n_tty_receive_buf_standard()
1560 n_tty_receive_char(tty, c); in n_tty_receive_buf_standard()
1564 static void __receive_buf(struct tty_struct *tty, const unsigned char *cp, in __receive_buf() argument
1567 struct n_tty_data *ldata = tty->disc_data; in __receive_buf()
1568 bool preops = I_ISTRIP(tty) || (I_IUCLC(tty) && L_IEXTEN(tty)); in __receive_buf()
1571 n_tty_receive_buf_real_raw(tty, cp, fp, count); in __receive_buf()
1572 else if (ldata->raw || (L_EXTPROC(tty) && !preops)) in __receive_buf()
1573 n_tty_receive_buf_raw(tty, cp, fp, count); in __receive_buf()
1574 else if (tty->closing && !L_EXTPROC(tty)) in __receive_buf()
1575 n_tty_receive_buf_closing(tty, cp, fp, count); in __receive_buf()
1577 n_tty_receive_buf_standard(tty, cp, fp, count); in __receive_buf()
1579 flush_echoes(tty); in __receive_buf()
1580 if (tty->ops->flush_chars) in __receive_buf()
1581 tty->ops->flush_chars(tty); in __receive_buf()
1584 if (ldata->icanon && !L_EXTPROC(tty)) in __receive_buf()
1591 kill_fasync(&tty->fasync, SIGIO, POLL_IN); in __receive_buf()
1592 wake_up_interruptible_poll(&tty->read_wait, EPOLLIN); in __receive_buf()
1631 n_tty_receive_buf_common(struct tty_struct *tty, const unsigned char *cp, in n_tty_receive_buf_common() argument
1634 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_common()
1637 down_read(&tty->termios_rwsem); in n_tty_receive_buf_common()
1656 if (I_PARMRK(tty)) in n_tty_receive_buf_common()
1674 __receive_buf(tty, cp, fp, n); in n_tty_receive_buf_common()
1681 } while (!test_bit(TTY_LDISC_CHANGING, &tty->flags)); in n_tty_receive_buf_common()
1683 tty->receive_room = room; in n_tty_receive_buf_common()
1686 if (tty->driver->type == TTY_DRIVER_TYPE_PTY) { in n_tty_receive_buf_common()
1688 tty_set_flow_change(tty, TTY_UNTHROTTLE_SAFE); in n_tty_receive_buf_common()
1689 tty_unthrottle_safe(tty); in n_tty_receive_buf_common()
1690 __tty_set_flow_change(tty, 0); in n_tty_receive_buf_common()
1693 n_tty_check_throttle(tty); in n_tty_receive_buf_common()
1695 up_read(&tty->termios_rwsem); in n_tty_receive_buf_common()
1700 static void n_tty_receive_buf(struct tty_struct *tty, const unsigned char *cp, in n_tty_receive_buf() argument
1703 n_tty_receive_buf_common(tty, cp, fp, count, 0); in n_tty_receive_buf()
1706 static int n_tty_receive_buf2(struct tty_struct *tty, const unsigned char *cp, in n_tty_receive_buf2() argument
1709 return n_tty_receive_buf_common(tty, cp, fp, count, 1); in n_tty_receive_buf2()
1726 static void n_tty_set_termios(struct tty_struct *tty, struct ktermios *old) in n_tty_set_termios() argument
1728 struct n_tty_data *ldata = tty->disc_data; in n_tty_set_termios()
1730 if (!old || (old->c_lflag ^ tty->termios.c_lflag) & (ICANON | EXTPROC)) { in n_tty_set_termios()
1733 if (!L_ICANON(tty) || !read_cnt(ldata)) { in n_tty_set_termios()
1747 ldata->icanon = (L_ICANON(tty) != 0); in n_tty_set_termios()
1749 if (I_ISTRIP(tty) || I_IUCLC(tty) || I_IGNCR(tty) || in n_tty_set_termios()
1750 I_ICRNL(tty) || I_INLCR(tty) || L_ICANON(tty) || in n_tty_set_termios()
1751 I_IXON(tty) || L_ISIG(tty) || L_ECHO(tty) || in n_tty_set_termios()
1752 I_PARMRK(tty)) { in n_tty_set_termios()
1755 if (I_IGNCR(tty) || I_ICRNL(tty)) in n_tty_set_termios()
1757 if (I_INLCR(tty)) in n_tty_set_termios()
1760 if (L_ICANON(tty)) { in n_tty_set_termios()
1761 set_bit(ERASE_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1762 set_bit(KILL_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1763 set_bit(EOF_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1765 set_bit(EOL_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1766 if (L_IEXTEN(tty)) { in n_tty_set_termios()
1767 set_bit(WERASE_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1768 set_bit(LNEXT_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1769 set_bit(EOL2_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1770 if (L_ECHO(tty)) in n_tty_set_termios()
1771 set_bit(REPRINT_CHAR(tty), in n_tty_set_termios()
1775 if (I_IXON(tty)) { in n_tty_set_termios()
1776 set_bit(START_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1777 set_bit(STOP_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1779 if (L_ISIG(tty)) { in n_tty_set_termios()
1780 set_bit(INTR_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1781 set_bit(QUIT_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1782 set_bit(SUSP_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1789 if ((I_IGNBRK(tty) || (!I_BRKINT(tty) && !I_PARMRK(tty))) && in n_tty_set_termios()
1790 (I_IGNPAR(tty) || !I_INPCK(tty)) && in n_tty_set_termios()
1791 (tty->driver->flags & TTY_DRIVER_REAL_RAW)) in n_tty_set_termios()
1800 if (!I_IXON(tty) && old && (old->c_iflag & IXON) && !tty->flow.tco_stopped) { in n_tty_set_termios()
1801 start_tty(tty); in n_tty_set_termios()
1802 process_echoes(tty); in n_tty_set_termios()
1806 wake_up_interruptible(&tty->write_wait); in n_tty_set_termios()
1807 wake_up_interruptible(&tty->read_wait); in n_tty_set_termios()
1820 static void n_tty_close(struct tty_struct *tty) in n_tty_close() argument
1822 struct n_tty_data *ldata = tty->disc_data; in n_tty_close()
1824 if (tty->link) in n_tty_close()
1825 n_tty_packet_mode_flush(tty); in n_tty_close()
1827 down_write(&tty->termios_rwsem); in n_tty_close()
1829 tty->disc_data = NULL; in n_tty_close()
1830 up_write(&tty->termios_rwsem); in n_tty_close()
1843 static int n_tty_open(struct tty_struct *tty) in n_tty_open() argument
1856 tty->disc_data = ldata; in n_tty_open()
1857 tty->closing = 0; in n_tty_open()
1859 clear_bit(TTY_LDISC_HALTED, &tty->flags); in n_tty_open()
1860 n_tty_set_termios(tty, NULL); in n_tty_open()
1861 tty_unthrottle(tty); in n_tty_open()
1865 static inline int input_available_p(struct tty_struct *tty, int poll) in input_available_p() argument
1867 struct n_tty_data *ldata = tty->disc_data; in input_available_p()
1868 int amt = poll && !TIME_CHAR(tty) && MIN_CHAR(tty) ? MIN_CHAR(tty) : 1; in input_available_p()
1870 if (ldata->icanon && !L_EXTPROC(tty)) in input_available_p()
1895 static bool copy_from_read_buf(struct tty_struct *tty, in copy_from_read_buf() argument
1900 struct n_tty_data *ldata = tty->disc_data; in copy_from_read_buf()
1911 is_eof = n == 1 && *from == EOF_CHAR(tty); in copy_from_read_buf()
1912 tty_audit_add_data(tty, from, n); in copy_from_read_buf()
1913 zero_buffer(tty, from, n); in copy_from_read_buf()
1916 if (L_EXTPROC(tty) && ldata->icanon && is_eof && in copy_from_read_buf()
1951 static bool canon_copy_from_read_buf(struct tty_struct *tty, in canon_copy_from_read_buf() argument
1955 struct n_tty_data *ldata = tty->disc_data; in canon_copy_from_read_buf()
1996 tty_copy(tty, *kbp, tail, n); in canon_copy_from_read_buf()
2031 static int job_control(struct tty_struct *tty, struct file *file) in job_control() argument
2041 return __tty_check_change(tty, SIGTTIN); in job_control()
2064 static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, in n_tty_read() argument
2068 struct n_tty_data *ldata = tty->disc_data; in n_tty_read()
2085 if (ldata->icanon && !L_EXTPROC(tty)) { in n_tty_read()
2086 if (canon_copy_from_read_buf(tty, &kb, &nr)) in n_tty_read()
2089 if (copy_from_read_buf(tty, &kb, &nr)) in n_tty_read()
2094 n_tty_kick_worker(tty); in n_tty_read()
2095 n_tty_check_unthrottle(tty); in n_tty_read()
2096 up_read(&tty->termios_rwsem); in n_tty_read()
2102 c = job_control(tty, file); in n_tty_read()
2117 down_read(&tty->termios_rwsem); in n_tty_read()
2122 minimum = MIN_CHAR(tty); in n_tty_read()
2124 time = (HZ / 10) * TIME_CHAR(tty); in n_tty_read()
2126 timeout = (HZ / 10) * TIME_CHAR(tty); in n_tty_read()
2131 packet = tty->ctrl.packet; in n_tty_read()
2134 add_wait_queue(&tty->read_wait, &wait); in n_tty_read()
2137 if (packet && tty->link->ctrl.pktstatus) { in n_tty_read()
2141 spin_lock_irq(&tty->link->ctrl.lock); in n_tty_read()
2142 cs = tty->link->ctrl.pktstatus; in n_tty_read()
2143 tty->link->ctrl.pktstatus = 0; in n_tty_read()
2144 spin_unlock_irq(&tty->link->ctrl.lock); in n_tty_read()
2150 if (!input_available_p(tty, 0)) { in n_tty_read()
2151 up_read(&tty->termios_rwsem); in n_tty_read()
2152 tty_buffer_flush_work(tty->port); in n_tty_read()
2153 down_read(&tty->termios_rwsem); in n_tty_read()
2154 if (!input_available_p(tty, 0)) { in n_tty_read()
2155 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) { in n_tty_read()
2165 if (test_bit(TTY_HUPPING, &tty->flags)) in n_tty_read()
2169 if (tty_io_nonblock(tty, file)) { in n_tty_read()
2177 up_read(&tty->termios_rwsem); in n_tty_read()
2182 down_read(&tty->termios_rwsem); in n_tty_read()
2187 if (ldata->icanon && !L_EXTPROC(tty)) { in n_tty_read()
2188 if (canon_copy_from_read_buf(tty, &kb, &nr)) in n_tty_read()
2206 if (copy_from_read_buf(tty, &kb, &nr) && kb - kbuf >= minimum) { in n_tty_read()
2208 remove_wait_queue(&tty->read_wait, &wait); in n_tty_read()
2214 n_tty_check_unthrottle(tty); in n_tty_read()
2222 n_tty_kick_worker(tty); in n_tty_read()
2223 up_read(&tty->termios_rwsem); in n_tty_read()
2225 remove_wait_queue(&tty->read_wait, &wait); in n_tty_read()
2256 static ssize_t n_tty_write(struct tty_struct *tty, struct file *file, in n_tty_write() argument
2265 if (L_TOSTOP(tty) && file->f_op->write_iter != redirected_tty_write) { in n_tty_write()
2266 retval = tty_check_change(tty); in n_tty_write()
2271 down_read(&tty->termios_rwsem); in n_tty_write()
2274 process_echoes(tty); in n_tty_write()
2276 add_wait_queue(&tty->write_wait, &wait); in n_tty_write()
2282 if (tty_hung_up_p(file) || (tty->link && !tty->link->count)) { in n_tty_write()
2286 if (O_OPOST(tty)) { in n_tty_write()
2288 ssize_t num = process_output_block(tty, b, nr); in n_tty_write()
2300 if (process_output(c, tty) < 0) in n_tty_write()
2304 if (tty->ops->flush_chars) in n_tty_write()
2305 tty->ops->flush_chars(tty); in n_tty_write()
2307 struct n_tty_data *ldata = tty->disc_data; in n_tty_write()
2311 c = tty->ops->write(tty, b, nr); in n_tty_write()
2325 if (tty_io_nonblock(tty, file)) { in n_tty_write()
2329 up_read(&tty->termios_rwsem); in n_tty_write()
2333 down_read(&tty->termios_rwsem); in n_tty_write()
2336 remove_wait_queue(&tty->write_wait, &wait); in n_tty_write()
2337 if (nr && tty->fasync) in n_tty_write()
2338 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in n_tty_write()
2339 up_read(&tty->termios_rwsem); in n_tty_write()
2357 static __poll_t n_tty_poll(struct tty_struct *tty, struct file *file, in n_tty_poll() argument
2362 poll_wait(file, &tty->read_wait, wait); in n_tty_poll()
2363 poll_wait(file, &tty->write_wait, wait); in n_tty_poll()
2364 if (input_available_p(tty, 1)) in n_tty_poll()
2367 tty_buffer_flush_work(tty->port); in n_tty_poll()
2368 if (input_available_p(tty, 1)) in n_tty_poll()
2371 if (tty->ctrl.packet && tty->link->ctrl.pktstatus) in n_tty_poll()
2373 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) in n_tty_poll()
2377 if (tty->ops->write && !tty_is_writelocked(tty) && in n_tty_poll()
2378 tty_chars_in_buffer(tty) < WAKEUP_CHARS && in n_tty_poll()
2379 tty_write_room(tty) > 0) in n_tty_poll()
2403 static int n_tty_ioctl(struct tty_struct *tty, struct file *file, in n_tty_ioctl() argument
2406 struct n_tty_data *ldata = tty->disc_data; in n_tty_ioctl()
2411 return put_user(tty_chars_in_buffer(tty), (int __user *) arg); in n_tty_ioctl()
2413 down_write(&tty->termios_rwsem); in n_tty_ioctl()
2414 if (L_ICANON(tty) && !L_EXTPROC(tty)) in n_tty_ioctl()
2418 up_write(&tty->termios_rwsem); in n_tty_ioctl()
2421 return n_tty_ioctl_helper(tty, cmd, arg); in n_tty_ioctl()