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
329 if (tty->link->ctrl.packet) { in n_tty_packet_mode_flush()
330 spin_lock_irqsave(&tty->ctrl.lock, flags); in n_tty_packet_mode_flush()
331 tty->ctrl.pktstatus |= TIOCPKT_FLUSHREAD; in n_tty_packet_mode_flush()
332 spin_unlock_irqrestore(&tty->ctrl.lock, flags); in n_tty_packet_mode_flush()
333 wake_up_interruptible(&tty->link->read_wait); in n_tty_packet_mode_flush()
350 static void n_tty_flush_buffer(struct tty_struct *tty) in n_tty_flush_buffer() argument
352 down_write(&tty->termios_rwsem); in n_tty_flush_buffer()
353 reset_buffer_flags(tty->disc_data); in n_tty_flush_buffer()
354 n_tty_kick_worker(tty); in n_tty_flush_buffer()
356 if (tty->link) in n_tty_flush_buffer()
357 n_tty_packet_mode_flush(tty); in n_tty_flush_buffer()
358 up_write(&tty->termios_rwsem); in n_tty_flush_buffer()
382 static inline int is_continuation(u8 c, const struct tty_struct *tty) in is_continuation() argument
384 return I_IUTF8(tty) && is_utf8_continuation(c); in is_continuation()
406 static int do_output_char(u8 c, struct tty_struct *tty, int space) in do_output_char() argument
408 struct n_tty_data *ldata = tty->disc_data; in do_output_char()
416 if (O_ONLRET(tty)) in do_output_char()
418 if (O_ONLCR(tty)) { in do_output_char()
422 tty->ops->write(tty, "\r\n", 2); in do_output_char()
428 if (O_ONOCR(tty) && ldata->column == 0) in do_output_char()
430 if (O_OCRNL(tty)) { in do_output_char()
432 if (O_ONLRET(tty)) in do_output_char()
440 if (O_TABDLY(tty) == XTABS) { in do_output_char()
444 tty->ops->write(tty, " ", spaces); in do_output_char()
455 if (O_OLCUC(tty)) in do_output_char()
457 if (!is_continuation(c, tty)) in do_output_char()
463 tty_put_char(tty, c); in do_output_char()
480 static int process_output(u8 c, struct tty_struct *tty) in process_output() argument
482 struct n_tty_data *ldata = tty->disc_data; in process_output()
486 if (do_output_char(c, tty, tty_write_room(tty)) < 0) in process_output()
510 static ssize_t process_output_block(struct tty_struct *tty, in process_output_block() argument
513 struct n_tty_data *ldata = tty->disc_data; in process_output_block()
519 space = tty_write_room(tty); in process_output_block()
531 if (O_ONLRET(tty)) in process_output_block()
533 if (O_ONLCR(tty)) in process_output_block()
538 if (O_ONOCR(tty) && ldata->column == 0) in process_output_block()
540 if (O_OCRNL(tty)) in process_output_block()
552 if (O_OLCUC(tty)) in process_output_block()
554 if (!is_continuation(c, tty)) in process_output_block()
561 return tty->ops->write(tty, buf, i); in process_output_block()
564 static int n_tty_process_echo_ops(struct tty_struct *tty, size_t *tail, in n_tty_process_echo_ops() argument
567 struct n_tty_data *ldata = tty->disc_data; in n_tty_process_echo_ops()
608 tty_put_char(tty, '\b'); in n_tty_process_echo_ops()
631 tty_put_char(tty, ECHO_OP_START); in n_tty_process_echo_ops()
647 tty_put_char(tty, '^'); in n_tty_process_echo_ops()
648 tty_put_char(tty, op ^ 0100); in n_tty_process_echo_ops()
680 static size_t __process_echoes(struct tty_struct *tty) in __process_echoes() argument
682 struct n_tty_data *ldata = tty->disc_data; in __process_echoes()
687 old_space = space = tty_write_room(tty); in __process_echoes()
693 int ret = n_tty_process_echo_ops(tty, &tail, space); in __process_echoes()
700 if (O_OPOST(tty)) { in __process_echoes()
701 int retval = do_output_char(c, tty, space); in __process_echoes()
708 tty_put_char(tty, c); in __process_echoes()
734 static void commit_echoes(struct tty_struct *tty) in commit_echoes() argument
736 struct n_tty_data *ldata = tty->disc_data; in commit_echoes()
756 echoed = __process_echoes(tty); in commit_echoes()
759 if (echoed && tty->ops->flush_chars) in commit_echoes()
760 tty->ops->flush_chars(tty); in commit_echoes()
763 static void process_echoes(struct tty_struct *tty) in process_echoes() argument
765 struct n_tty_data *ldata = tty->disc_data; in process_echoes()
773 echoed = __process_echoes(tty); in process_echoes()
776 if (echoed && tty->ops->flush_chars) in process_echoes()
777 tty->ops->flush_chars(tty); in process_echoes()
781 static void flush_echoes(struct tty_struct *tty) in flush_echoes() argument
783 struct n_tty_data *ldata = tty->disc_data; in flush_echoes()
785 if ((!L_ECHO(tty) && !L_ECHONL(tty)) || in flush_echoes()
791 __process_echoes(tty); in flush_echoes()
894 static void echo_char(u8 c, const struct tty_struct *tty) in echo_char() argument
896 struct n_tty_data *ldata = tty->disc_data; in echo_char()
902 if (L_ECHOCTL(tty) && iscntrl(c) && c != '\t') in echo_char()
932 static void eraser(u8 c, const struct tty_struct *tty) in eraser() argument
934 struct n_tty_data *ldata = tty->disc_data; in eraser()
944 if (c == ERASE_CHAR(tty)) in eraser()
946 else if (c == WERASE_CHAR(tty)) in eraser()
949 if (!L_ECHO(tty)) { in eraser()
953 if (!L_ECHOK(tty) || !L_ECHOKE(tty) || !L_ECHOE(tty)) { in eraser()
956 echo_char(KILL_CHAR(tty), tty); in eraser()
958 if (L_ECHOK(tty)) in eraser()
973 } while (is_continuation(c, tty) && in eraser()
977 if (is_continuation(c, tty)) in eraser()
989 if (L_ECHO(tty)) { in eraser()
990 if (L_ECHOPRT(tty)) { in eraser()
996 echo_char(c, tty); in eraser()
1002 } else if (kill_type == ERASE && !L_ECHOE(tty)) { in eraser()
1003 echo_char(ERASE_CHAR(tty), tty); in eraser()
1023 if (L_ECHOCTL(tty)) in eraser()
1025 } else if (!is_continuation(c, tty)) { in eraser()
1031 if (iscntrl(c) && L_ECHOCTL(tty)) { in eraser()
1036 if (!iscntrl(c) || L_ECHOCTL(tty)) { in eraser()
1046 if (ldata->read_head == ldata->canon_head && L_ECHO(tty)) in eraser()
1051 static void __isig(int sig, struct tty_struct *tty) in __isig() argument
1053 struct pid *tty_pgrp = tty_get_pgrp(tty); in __isig()
1074 static void isig(int sig, struct tty_struct *tty) in isig() argument
1076 struct n_tty_data *ldata = tty->disc_data; in isig()
1078 if (L_NOFLSH(tty)) { in isig()
1080 __isig(sig, tty); in isig()
1083 up_read(&tty->termios_rwsem); in isig()
1084 down_write(&tty->termios_rwsem); in isig()
1086 __isig(sig, tty); in isig()
1095 tty_driver_flush_buffer(tty); in isig()
1098 reset_buffer_flags(tty->disc_data); in isig()
1101 if (tty->link) in isig()
1102 n_tty_packet_mode_flush(tty); in isig()
1104 up_write(&tty->termios_rwsem); in isig()
1105 down_read(&tty->termios_rwsem); in isig()
1121 static void n_tty_receive_break(struct tty_struct *tty) in n_tty_receive_break() argument
1123 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_break()
1125 if (I_IGNBRK(tty)) in n_tty_receive_break()
1127 if (I_BRKINT(tty)) { in n_tty_receive_break()
1128 isig(SIGINT, tty); in n_tty_receive_break()
1131 if (I_PARMRK(tty)) { in n_tty_receive_break()
1148 static void n_tty_receive_overrun(const struct tty_struct *tty) in n_tty_receive_overrun() argument
1150 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_overrun()
1154 tty_warn(tty, "%u input overrun(s)\n", ldata->num_overrun); in n_tty_receive_overrun()
1171 static void n_tty_receive_parity_error(const struct tty_struct *tty, in n_tty_receive_parity_error() argument
1174 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_parity_error()
1176 if (I_INPCK(tty)) { in n_tty_receive_parity_error()
1177 if (I_IGNPAR(tty)) in n_tty_receive_parity_error()
1179 if (I_PARMRK(tty)) { in n_tty_receive_parity_error()
1190 n_tty_receive_signal_char(struct tty_struct *tty, int signal, u8 c) in n_tty_receive_signal_char() argument
1192 isig(signal, tty); in n_tty_receive_signal_char()
1193 if (I_IXON(tty)) in n_tty_receive_signal_char()
1194 start_tty(tty); in n_tty_receive_signal_char()
1195 if (L_ECHO(tty)) { in n_tty_receive_signal_char()
1196 echo_char(c, tty); in n_tty_receive_signal_char()
1197 commit_echoes(tty); in n_tty_receive_signal_char()
1199 process_echoes(tty); in n_tty_receive_signal_char()
1202 static bool n_tty_is_char_flow_ctrl(struct tty_struct *tty, u8 c) in n_tty_is_char_flow_ctrl() argument
1204 return c == START_CHAR(tty) || c == STOP_CHAR(tty); in n_tty_is_char_flow_ctrl()
1222 static bool n_tty_receive_char_flow_ctrl(struct tty_struct *tty, u8 c, in n_tty_receive_char_flow_ctrl() argument
1225 if (!n_tty_is_char_flow_ctrl(tty, c)) in n_tty_receive_char_flow_ctrl()
1231 if (c == START_CHAR(tty)) { in n_tty_receive_char_flow_ctrl()
1232 start_tty(tty); in n_tty_receive_char_flow_ctrl()
1233 process_echoes(tty); in n_tty_receive_char_flow_ctrl()
1238 stop_tty(tty); in n_tty_receive_char_flow_ctrl()
1242 static void n_tty_receive_handle_newline(struct tty_struct *tty, u8 c) in n_tty_receive_handle_newline() argument
1244 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_handle_newline()
1249 kill_fasync(&tty->fasync, SIGIO, POLL_IN); in n_tty_receive_handle_newline()
1250 wake_up_interruptible_poll(&tty->read_wait, EPOLLIN | EPOLLRDNORM); in n_tty_receive_handle_newline()
1253 static bool n_tty_receive_char_canon(struct tty_struct *tty, u8 c) in n_tty_receive_char_canon() argument
1255 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_char_canon()
1257 if (c == ERASE_CHAR(tty) || c == KILL_CHAR(tty) || in n_tty_receive_char_canon()
1258 (c == WERASE_CHAR(tty) && L_IEXTEN(tty))) { in n_tty_receive_char_canon()
1259 eraser(c, tty); in n_tty_receive_char_canon()
1260 commit_echoes(tty); in n_tty_receive_char_canon()
1265 if (c == LNEXT_CHAR(tty) && L_IEXTEN(tty)) { in n_tty_receive_char_canon()
1267 if (L_ECHO(tty)) { in n_tty_receive_char_canon()
1269 if (L_ECHOCTL(tty)) { in n_tty_receive_char_canon()
1272 commit_echoes(tty); in n_tty_receive_char_canon()
1279 if (c == REPRINT_CHAR(tty) && L_ECHO(tty) && L_IEXTEN(tty)) { in n_tty_receive_char_canon()
1283 echo_char(c, tty); in n_tty_receive_char_canon()
1286 echo_char(read_buf(ldata, tail), tty); in n_tty_receive_char_canon()
1289 commit_echoes(tty); in n_tty_receive_char_canon()
1295 if (L_ECHO(tty) || L_ECHONL(tty)) { in n_tty_receive_char_canon()
1297 commit_echoes(tty); in n_tty_receive_char_canon()
1299 n_tty_receive_handle_newline(tty, c); in n_tty_receive_char_canon()
1304 if (c == EOF_CHAR(tty)) { in n_tty_receive_char_canon()
1306 n_tty_receive_handle_newline(tty, c); in n_tty_receive_char_canon()
1311 if ((c == EOL_CHAR(tty)) || in n_tty_receive_char_canon()
1312 (c == EOL2_CHAR(tty) && L_IEXTEN(tty))) { in n_tty_receive_char_canon()
1316 if (L_ECHO(tty)) { in n_tty_receive_char_canon()
1320 echo_char(c, tty); in n_tty_receive_char_canon()
1321 commit_echoes(tty); in n_tty_receive_char_canon()
1327 if (c == '\377' && I_PARMRK(tty)) in n_tty_receive_char_canon()
1330 n_tty_receive_handle_newline(tty, c); in n_tty_receive_char_canon()
1338 static void n_tty_receive_char_special(struct tty_struct *tty, u8 c, in n_tty_receive_char_special() argument
1341 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_char_special()
1343 if (I_IXON(tty) && n_tty_receive_char_flow_ctrl(tty, c, lookahead_done)) in n_tty_receive_char_special()
1346 if (L_ISIG(tty)) { in n_tty_receive_char_special()
1347 if (c == INTR_CHAR(tty)) { in n_tty_receive_char_special()
1348 n_tty_receive_signal_char(tty, SIGINT, c); in n_tty_receive_char_special()
1350 } else if (c == QUIT_CHAR(tty)) { in n_tty_receive_char_special()
1351 n_tty_receive_signal_char(tty, SIGQUIT, c); in n_tty_receive_char_special()
1353 } else if (c == SUSP_CHAR(tty)) { in n_tty_receive_char_special()
1354 n_tty_receive_signal_char(tty, SIGTSTP, c); in n_tty_receive_char_special()
1359 if (tty->flow.stopped && !tty->flow.tco_stopped && I_IXON(tty) && I_IXANY(tty)) { in n_tty_receive_char_special()
1360 start_tty(tty); in n_tty_receive_char_special()
1361 process_echoes(tty); in n_tty_receive_char_special()
1365 if (I_IGNCR(tty)) in n_tty_receive_char_special()
1367 if (I_ICRNL(tty)) in n_tty_receive_char_special()
1369 } else if (c == '\n' && I_INLCR(tty)) in n_tty_receive_char_special()
1372 if (ldata->icanon && n_tty_receive_char_canon(tty, c)) in n_tty_receive_char_special()
1375 if (L_ECHO(tty)) { in n_tty_receive_char_special()
1383 echo_char(c, tty); in n_tty_receive_char_special()
1385 commit_echoes(tty); in n_tty_receive_char_special()
1389 if (c == '\377' && I_PARMRK(tty)) in n_tty_receive_char_special()
1407 static void n_tty_receive_char(struct tty_struct *tty, u8 c) in n_tty_receive_char() argument
1409 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_char()
1411 if (tty->flow.stopped && !tty->flow.tco_stopped && I_IXON(tty) && I_IXANY(tty)) { in n_tty_receive_char()
1412 start_tty(tty); in n_tty_receive_char()
1413 process_echoes(tty); in n_tty_receive_char()
1415 if (L_ECHO(tty)) { in n_tty_receive_char()
1420 echo_char(c, tty); in n_tty_receive_char()
1421 commit_echoes(tty); in n_tty_receive_char()
1424 if (c == '\377' && I_PARMRK(tty)) in n_tty_receive_char()
1429 static void n_tty_receive_char_closing(struct tty_struct *tty, u8 c, in n_tty_receive_char_closing() argument
1432 if (I_ISTRIP(tty)) in n_tty_receive_char_closing()
1434 if (I_IUCLC(tty) && L_IEXTEN(tty)) in n_tty_receive_char_closing()
1437 if (I_IXON(tty)) { in n_tty_receive_char_closing()
1438 if (!n_tty_receive_char_flow_ctrl(tty, c, lookahead_done) && in n_tty_receive_char_closing()
1439 tty->flow.stopped && !tty->flow.tco_stopped && I_IXANY(tty) && in n_tty_receive_char_closing()
1440 c != INTR_CHAR(tty) && c != QUIT_CHAR(tty) && in n_tty_receive_char_closing()
1441 c != SUSP_CHAR(tty)) { in n_tty_receive_char_closing()
1442 start_tty(tty); in n_tty_receive_char_closing()
1443 process_echoes(tty); in n_tty_receive_char_closing()
1449 n_tty_receive_char_flagged(struct tty_struct *tty, u8 c, u8 flag) in n_tty_receive_char_flagged() argument
1453 n_tty_receive_break(tty); in n_tty_receive_char_flagged()
1457 n_tty_receive_parity_error(tty, c); in n_tty_receive_char_flagged()
1460 n_tty_receive_overrun(tty); in n_tty_receive_char_flagged()
1463 tty_err(tty, "unknown flag %u\n", flag); in n_tty_receive_char_flagged()
1469 n_tty_receive_char_lnext(struct tty_struct *tty, u8 c, u8 flag) in n_tty_receive_char_lnext() argument
1471 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_char_lnext()
1475 if (I_ISTRIP(tty)) in n_tty_receive_char_lnext()
1477 if (I_IUCLC(tty) && L_IEXTEN(tty)) in n_tty_receive_char_lnext()
1479 n_tty_receive_char(tty, c); in n_tty_receive_char_lnext()
1481 n_tty_receive_char_flagged(tty, c, flag); in n_tty_receive_char_lnext()
1485 static void n_tty_lookahead_flow_ctrl(struct tty_struct *tty, const u8 *cp, in n_tty_lookahead_flow_ctrl() argument
1488 struct n_tty_data *ldata = tty->disc_data; in n_tty_lookahead_flow_ctrl()
1493 if (!I_IXON(tty)) in n_tty_lookahead_flow_ctrl()
1500 n_tty_receive_char_flow_ctrl(tty, *cp, false); in n_tty_lookahead_flow_ctrl()
1506 n_tty_receive_buf_real_raw(const struct tty_struct *tty, const u8 *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()
1525 n_tty_receive_buf_raw(struct tty_struct *tty, const u8 *cp, const u8 *fp, in n_tty_receive_buf_raw() argument
1528 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_raw()
1537 n_tty_receive_char_flagged(tty, *cp++, flag); in n_tty_receive_buf_raw()
1542 n_tty_receive_buf_closing(struct tty_struct *tty, const u8 *cp, const u8 *fp, in n_tty_receive_buf_closing() argument
1551 n_tty_receive_char_closing(tty, *cp++, lookahead_done); in n_tty_receive_buf_closing()
1555 static void n_tty_receive_buf_standard(struct tty_struct *tty, const u8 *cp, in n_tty_receive_buf_standard() argument
1559 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_standard()
1569 n_tty_receive_char_lnext(tty, c, flag); in n_tty_receive_buf_standard()
1574 n_tty_receive_char_flagged(tty, c, flag); in n_tty_receive_buf_standard()
1578 if (I_ISTRIP(tty)) in n_tty_receive_buf_standard()
1580 if (I_IUCLC(tty) && L_IEXTEN(tty)) in n_tty_receive_buf_standard()
1582 if (L_EXTPROC(tty)) { in n_tty_receive_buf_standard()
1588 n_tty_receive_char_special(tty, c, lookahead_done); in n_tty_receive_buf_standard()
1590 n_tty_receive_char(tty, c); in n_tty_receive_buf_standard()
1594 static void __receive_buf(struct tty_struct *tty, const u8 *cp, const u8 *fp, in __receive_buf() argument
1597 struct n_tty_data *ldata = tty->disc_data; in __receive_buf()
1598 bool preops = I_ISTRIP(tty) || (I_IUCLC(tty) && L_IEXTEN(tty)); in __receive_buf()
1602 n_tty_receive_buf_real_raw(tty, cp, count); in __receive_buf()
1603 else if (ldata->raw || (L_EXTPROC(tty) && !preops)) in __receive_buf()
1604 n_tty_receive_buf_raw(tty, cp, fp, count); in __receive_buf()
1605 else if (tty->closing && !L_EXTPROC(tty)) { in __receive_buf()
1607 n_tty_receive_buf_closing(tty, cp, fp, la_count, true); in __receive_buf()
1614 n_tty_receive_buf_closing(tty, cp, fp, count, false); in __receive_buf()
1617 n_tty_receive_buf_standard(tty, cp, fp, la_count, true); in __receive_buf()
1624 n_tty_receive_buf_standard(tty, cp, fp, count, false); in __receive_buf()
1626 flush_echoes(tty); in __receive_buf()
1627 if (tty->ops->flush_chars) in __receive_buf()
1628 tty->ops->flush_chars(tty); in __receive_buf()
1633 if (ldata->icanon && !L_EXTPROC(tty)) in __receive_buf()
1640 kill_fasync(&tty->fasync, SIGIO, POLL_IN); in __receive_buf()
1641 wake_up_interruptible_poll(&tty->read_wait, EPOLLIN | EPOLLRDNORM); in __receive_buf()
1679 n_tty_receive_buf_common(struct tty_struct *tty, const u8 *cp, const u8 *fp, in n_tty_receive_buf_common() argument
1682 struct n_tty_data *ldata = tty->disc_data; in n_tty_receive_buf_common()
1686 down_read(&tty->termios_rwsem); in n_tty_receive_buf_common()
1705 if (I_PARMRK(tty)) in n_tty_receive_buf_common()
1723 __receive_buf(tty, cp, fp, n); in n_tty_receive_buf_common()
1730 } while (!test_bit(TTY_LDISC_CHANGING, &tty->flags)); in n_tty_receive_buf_common()
1732 tty->receive_room = room; in n_tty_receive_buf_common()
1735 if (tty->driver->type == TTY_DRIVER_TYPE_PTY) { in n_tty_receive_buf_common()
1737 tty_set_flow_change(tty, TTY_UNTHROTTLE_SAFE); in n_tty_receive_buf_common()
1738 tty_unthrottle_safe(tty); in n_tty_receive_buf_common()
1739 __tty_set_flow_change(tty, 0); in n_tty_receive_buf_common()
1742 n_tty_check_throttle(tty); in n_tty_receive_buf_common()
1751 if (!chars_in_buffer(tty)) in n_tty_receive_buf_common()
1752 n_tty_kick_worker(tty); in n_tty_receive_buf_common()
1755 up_read(&tty->termios_rwsem); in n_tty_receive_buf_common()
1760 static void n_tty_receive_buf(struct tty_struct *tty, const u8 *cp, in n_tty_receive_buf() argument
1763 n_tty_receive_buf_common(tty, cp, fp, count, false); in n_tty_receive_buf()
1766 static size_t n_tty_receive_buf2(struct tty_struct *tty, const u8 *cp, in n_tty_receive_buf2() argument
1769 return n_tty_receive_buf_common(tty, cp, fp, count, true); in n_tty_receive_buf2()
1784 static void n_tty_set_termios(struct tty_struct *tty, const struct ktermios *old) in n_tty_set_termios() argument
1786 struct n_tty_data *ldata = tty->disc_data; in n_tty_set_termios()
1788 if (!old || (old->c_lflag ^ tty->termios.c_lflag) & (ICANON | EXTPROC)) { in n_tty_set_termios()
1791 if (!L_ICANON(tty) || !read_cnt(ldata)) { in n_tty_set_termios()
1804 ldata->icanon = (L_ICANON(tty) != 0); in n_tty_set_termios()
1806 if (I_ISTRIP(tty) || I_IUCLC(tty) || I_IGNCR(tty) || in n_tty_set_termios()
1807 I_ICRNL(tty) || I_INLCR(tty) || L_ICANON(tty) || in n_tty_set_termios()
1808 I_IXON(tty) || L_ISIG(tty) || L_ECHO(tty) || in n_tty_set_termios()
1809 I_PARMRK(tty)) { in n_tty_set_termios()
1812 if (I_IGNCR(tty) || I_ICRNL(tty)) in n_tty_set_termios()
1814 if (I_INLCR(tty)) in n_tty_set_termios()
1817 if (L_ICANON(tty)) { in n_tty_set_termios()
1818 set_bit(ERASE_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1819 set_bit(KILL_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1820 set_bit(EOF_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1822 set_bit(EOL_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1823 if (L_IEXTEN(tty)) { in n_tty_set_termios()
1824 set_bit(WERASE_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1825 set_bit(LNEXT_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1826 set_bit(EOL2_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1827 if (L_ECHO(tty)) in n_tty_set_termios()
1828 set_bit(REPRINT_CHAR(tty), in n_tty_set_termios()
1832 if (I_IXON(tty)) { in n_tty_set_termios()
1833 set_bit(START_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1834 set_bit(STOP_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1836 if (L_ISIG(tty)) { in n_tty_set_termios()
1837 set_bit(INTR_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1838 set_bit(QUIT_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1839 set_bit(SUSP_CHAR(tty), ldata->char_map); in n_tty_set_termios()
1846 if ((I_IGNBRK(tty) || (!I_BRKINT(tty) && !I_PARMRK(tty))) && in n_tty_set_termios()
1847 (I_IGNPAR(tty) || !I_INPCK(tty)) && in n_tty_set_termios()
1848 (tty->driver->flags & TTY_DRIVER_REAL_RAW)) in n_tty_set_termios()
1857 if (!I_IXON(tty) && old && (old->c_iflag & IXON) && !tty->flow.tco_stopped) { in n_tty_set_termios()
1858 start_tty(tty); in n_tty_set_termios()
1859 process_echoes(tty); in n_tty_set_termios()
1863 wake_up_interruptible(&tty->write_wait); in n_tty_set_termios()
1864 wake_up_interruptible(&tty->read_wait); in n_tty_set_termios()
1875 static void n_tty_close(struct tty_struct *tty) in n_tty_close() argument
1877 struct n_tty_data *ldata = tty->disc_data; in n_tty_close()
1879 if (tty->link) in n_tty_close()
1880 n_tty_packet_mode_flush(tty); in n_tty_close()
1882 down_write(&tty->termios_rwsem); in n_tty_close()
1884 tty->disc_data = NULL; in n_tty_close()
1885 up_write(&tty->termios_rwsem); in n_tty_close()
1896 static int n_tty_open(struct tty_struct *tty) in n_tty_open() argument
1909 tty->disc_data = ldata; in n_tty_open()
1910 tty->closing = 0; in n_tty_open()
1912 clear_bit(TTY_LDISC_HALTED, &tty->flags); in n_tty_open()
1913 n_tty_set_termios(tty, NULL); in n_tty_open()
1914 tty_unthrottle(tty); in n_tty_open()
1918 static inline int input_available_p(const struct tty_struct *tty, int poll) in input_available_p() argument
1920 const struct n_tty_data *ldata = tty->disc_data; in input_available_p()
1921 int amt = poll && !TIME_CHAR(tty) && MIN_CHAR(tty) ? MIN_CHAR(tty) : 1; in input_available_p()
1923 if (ldata->icanon && !L_EXTPROC(tty)) in input_available_p()
1947 static bool copy_from_read_buf(const struct tty_struct *tty, u8 **kbp, in copy_from_read_buf() argument
1951 struct n_tty_data *ldata = tty->disc_data; in copy_from_read_buf()
1963 is_eof = n == 1 && *from == EOF_CHAR(tty); in copy_from_read_buf()
1964 tty_audit_add_data(tty, from, n); in copy_from_read_buf()
1965 zero_buffer(tty, from, n); in copy_from_read_buf()
1969 if (L_EXTPROC(tty) && ldata->icanon && is_eof && in copy_from_read_buf()
2002 static bool canon_copy_from_read_buf(const struct tty_struct *tty, u8 **kbp, in canon_copy_from_read_buf() argument
2005 struct n_tty_data *ldata = tty->disc_data; in canon_copy_from_read_buf()
2038 tty_copy(tty, *kbp, tail, n); in canon_copy_from_read_buf()
2101 static int job_control(struct tty_struct *tty, struct file *file) in job_control() argument
2111 return __tty_check_change(tty, SIGTTIN); in job_control()
2118 static ssize_t n_tty_continue_cookie(struct tty_struct *tty, u8 *kbuf, in n_tty_continue_cookie() argument
2121 struct n_tty_data *ldata = tty->disc_data; in n_tty_continue_cookie()
2124 if (ldata->icanon && !L_EXTPROC(tty)) { in n_tty_continue_cookie()
2131 else if (canon_copy_from_read_buf(tty, &kb, &nr)) in n_tty_continue_cookie()
2134 if (copy_from_read_buf(tty, &kb, &nr)) in n_tty_continue_cookie()
2139 n_tty_kick_worker(tty); in n_tty_continue_cookie()
2140 n_tty_check_unthrottle(tty); in n_tty_continue_cookie()
2141 up_read(&tty->termios_rwsem); in n_tty_continue_cookie()
2148 static int n_tty_wait_for_input(struct tty_struct *tty, struct file *file, in n_tty_wait_for_input() argument
2151 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) in n_tty_wait_for_input()
2159 if (test_bit(TTY_HUPPING, &tty->flags)) in n_tty_wait_for_input()
2163 if (tty_io_nonblock(tty, file)) in n_tty_wait_for_input()
2168 up_read(&tty->termios_rwsem); in n_tty_wait_for_input()
2170 down_read(&tty->termios_rwsem); in n_tty_wait_for_input()
2195 static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, u8 *kbuf, in n_tty_read() argument
2198 struct n_tty_data *ldata = tty->disc_data; in n_tty_read()
2209 return n_tty_continue_cookie(tty, kbuf, nr, cookie); in n_tty_read()
2211 retval = job_control(tty, file); in n_tty_read()
2226 down_read(&tty->termios_rwsem); in n_tty_read()
2231 minimum = MIN_CHAR(tty); in n_tty_read()
2233 time = (HZ / 10) * TIME_CHAR(tty); in n_tty_read()
2235 timeout = (HZ / 10) * TIME_CHAR(tty); in n_tty_read()
2240 packet = tty->ctrl.packet; in n_tty_read()
2243 add_wait_queue(&tty->read_wait, &wait); in n_tty_read()
2246 if (packet && tty->link->ctrl.pktstatus) { in n_tty_read()
2250 spin_lock_irq(&tty->link->ctrl.lock); in n_tty_read()
2251 cs = tty->link->ctrl.pktstatus; in n_tty_read()
2252 tty->link->ctrl.pktstatus = 0; in n_tty_read()
2253 spin_unlock_irq(&tty->link->ctrl.lock); in n_tty_read()
2259 if (!input_available_p(tty, 0)) { in n_tty_read()
2260 up_read(&tty->termios_rwsem); in n_tty_read()
2261 tty_buffer_flush_work(tty->port); in n_tty_read()
2262 down_read(&tty->termios_rwsem); in n_tty_read()
2263 if (!input_available_p(tty, 0)) { in n_tty_read()
2264 int ret = n_tty_wait_for_input(tty, file, &wait, in n_tty_read()
2274 if (ldata->icanon && !L_EXTPROC(tty)) { in n_tty_read()
2275 if (canon_copy_from_read_buf(tty, &kb, &nr)) in n_tty_read()
2284 if (copy_from_read_buf(tty, &kb, &nr) && kb - kbuf >= minimum) in n_tty_read()
2288 n_tty_check_unthrottle(tty); in n_tty_read()
2301 n_tty_kick_worker(tty); in n_tty_read()
2303 up_read(&tty->termios_rwsem); in n_tty_read()
2305 remove_wait_queue(&tty->read_wait, &wait); in n_tty_read()
2320 remove_wait_queue(&tty->read_wait, &wait); in n_tty_read()
2346 static ssize_t n_tty_write(struct tty_struct *tty, struct file *file, in n_tty_write() argument
2354 if (L_TOSTOP(tty) && file->f_op->write_iter != redirected_tty_write) { in n_tty_write()
2355 retval = tty_check_change(tty); in n_tty_write()
2360 down_read(&tty->termios_rwsem); in n_tty_write()
2363 process_echoes(tty); in n_tty_write()
2365 add_wait_queue(&tty->write_wait, &wait); in n_tty_write()
2371 if (tty_hung_up_p(file) || (tty->link && !tty->link->count)) { in n_tty_write()
2375 if (O_OPOST(tty)) { in n_tty_write()
2377 num = process_output_block(tty, b, nr); in n_tty_write()
2388 if (process_output(*b, tty) < 0) in n_tty_write()
2392 if (tty->ops->flush_chars) in n_tty_write()
2393 tty->ops->flush_chars(tty); in n_tty_write()
2395 struct n_tty_data *ldata = tty->disc_data; in n_tty_write()
2399 num = tty->ops->write(tty, b, nr); in n_tty_write()
2413 if (tty_io_nonblock(tty, file)) { in n_tty_write()
2417 up_read(&tty->termios_rwsem); in n_tty_write()
2421 down_read(&tty->termios_rwsem); in n_tty_write()
2424 remove_wait_queue(&tty->write_wait, &wait); in n_tty_write()
2425 if (nr && tty->fasync) in n_tty_write()
2426 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in n_tty_write()
2427 up_read(&tty->termios_rwsem); in n_tty_write()
2445 static __poll_t n_tty_poll(struct tty_struct *tty, struct file *file, in n_tty_poll() argument
2450 poll_wait(file, &tty->read_wait, wait); in n_tty_poll()
2451 poll_wait(file, &tty->write_wait, wait); in n_tty_poll()
2452 if (input_available_p(tty, 1)) in n_tty_poll()
2455 tty_buffer_flush_work(tty->port); in n_tty_poll()
2456 if (input_available_p(tty, 1)) in n_tty_poll()
2459 if (tty->ctrl.packet && tty->link->ctrl.pktstatus) in n_tty_poll()
2461 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) in n_tty_poll()
2465 if (tty->ops->write && !tty_is_writelocked(tty) && in n_tty_poll()
2466 tty_chars_in_buffer(tty) < WAKEUP_CHARS && in n_tty_poll()
2467 tty_write_room(tty) > 0) in n_tty_poll()
2491 static int n_tty_ioctl(struct tty_struct *tty, unsigned int cmd, in n_tty_ioctl() argument
2494 struct n_tty_data *ldata = tty->disc_data; in n_tty_ioctl()
2499 return put_user(tty_chars_in_buffer(tty), (int __user *) arg); in n_tty_ioctl()
2501 down_write(&tty->termios_rwsem); in n_tty_ioctl()
2502 if (L_ICANON(tty) && !L_EXTPROC(tty)) in n_tty_ioctl()
2506 up_write(&tty->termios_rwsem); in n_tty_ioctl()
2509 return n_tty_ioctl_helper(tty, cmd, arg); in n_tty_ioctl()