• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/linux/linux-2.6.36/drivers/char/

Lines Matching refs:tty

40 #include <linux/tty.h>
77 static inline int tty_put_user(struct tty_struct *tty, unsigned char x,
80 tty_audit_add_data(tty, &x, 1);
86 * @tty: terminal
94 static void n_tty_set_room(struct tty_struct *tty)
96 /* tty->read_cnt is not read locked ? */
97 int left = N_TTY_BUF_SIZE - tty->read_cnt - 1;
106 left = tty->icanon && !tty->canon_data;
107 tty->receive_room = left;
110 static void put_tty_queue_nolock(unsigned char c, struct tty_struct *tty)
112 if (tty->read_cnt < N_TTY_BUF_SIZE) {
113 tty->read_buf[tty->read_head] = c;
114 tty->read_head = (tty->read_head + 1) & (N_TTY_BUF_SIZE-1);
115 tty->read_cnt++;
120 * put_tty_queue - add character to tty
122 * @tty: tty device
124 * Add a character to the tty read_buf queue. This is done under the
129 static void put_tty_queue(unsigned char c, struct tty_struct *tty)
136 spin_lock_irqsave(&tty->read_lock, flags);
137 put_tty_queue_nolock(c, tty);
138 spin_unlock_irqrestore(&tty->read_lock, flags);
143 * @tty; tty device
150 static void check_unthrottle(struct tty_struct *tty)
152 if (tty->count)
153 tty_unthrottle(tty);
158 * @tty: terminal to reset
167 static void reset_buffer_flags(struct tty_struct *tty)
171 spin_lock_irqsave(&tty->read_lock, flags);
172 tty->read_head = tty->read_tail = tty->read_cnt = 0;
173 spin_unlock_irqrestore(&tty->read_lock, flags);
175 mutex_lock(&tty->echo_lock);
176 tty->echo_pos = tty->echo_cnt = tty->echo_overrun = 0;
177 mutex_unlock(&tty->echo_lock);
179 tty->canon_head = tty->canon_data = tty->erasing = 0;
180 memset(&tty->read_flags, 0, sizeof tty->read_flags);
181 n_tty_set_room(tty);
182 check_unthrottle(tty);
187 * @tty: terminal device
190 * being closed, when the tty layer wants the buffer flushed (eg
197 static void n_tty_flush_buffer(struct tty_struct *tty)
201 reset_buffer_flags(tty);
203 if (!tty->link)
206 spin_lock_irqsave(&tty->ctrl_lock, flags);
207 if (tty->link->packet) {
208 tty->ctrl_status |= TIOCPKT_FLUSHREAD;
209 wake_up_interruptible(&tty->link->read_wait);
211 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
216 * @tty: tty device
224 static ssize_t n_tty_chars_in_buffer(struct tty_struct *tty)
229 spin_lock_irqsave(&tty->read_lock, flags);
230 if (!tty->icanon) {
231 n = tty->read_cnt;
232 } else if (tty->canon_data) {
233 n = (tty->canon_head > tty->read_tail) ?
234 tty->canon_head - tty->read_tail :
235 tty->canon_head + (N_TTY_BUF_SIZE - tty->read_tail);
237 spin_unlock_irqrestore(&tty->read_lock, flags);
263 static inline int is_continuation(unsigned char c, struct tty_struct *tty)
265 return I_IUTF8(tty) && is_utf8_continuation(c);
271 * @tty: terminal device
272 * @space: space available in tty driver write buffer
277 * tty driver's write buffer.
290 static int do_output_char(unsigned char c, struct tty_struct *tty, int space)
299 if (O_ONLRET(tty))
300 tty->column = 0;
301 if (O_ONLCR(tty)) {
304 tty->canon_column = tty->column = 0;
305 tty->ops->write(tty, "\r\n", 2);
308 tty->canon_column = tty->column;
311 if (O_ONOCR(tty) && tty->column == 0)
313 if (O_OCRNL(tty)) {
315 if (O_ONLRET(tty))
316 tty->canon_column = tty->column = 0;
319 tty->canon_column = tty->column = 0;
322 spaces = 8 - (tty->column & 7);
323 if (O_TABDLY(tty) == XTABS) {
326 tty->column += spaces;
327 tty->ops->write(tty, " ", spaces);
330 tty->column += spaces;
333 if (tty->column > 0)
334 tty->column--;
338 if (O_OLCUC(tty))
340 if (!is_continuation(c, tty))
341 tty->column++;
346 tty_put_char(tty, c);
353 * @tty: terminal device
361 * tty layer write lock)
364 static int process_output(unsigned char c, struct tty_struct *tty)
368 mutex_lock(&tty->output_lock);
370 space = tty_write_room(tty);
371 retval = do_output_char(c, tty, space);
373 mutex_unlock(&tty->output_lock);
382 * @tty: terminal device
396 * tty layer write lock)
399 static ssize_t process_output_block(struct tty_struct *tty,
406 mutex_lock(&tty->output_lock);
408 space = tty_write_room(tty);
410 mutex_unlock(&tty->output_lock);
421 if (O_ONLRET(tty))
422 tty->column = 0;
423 if (O_ONLCR(tty))
425 tty->canon_column = tty->column;
428 if (O_ONOCR(tty) && tty->column == 0)
430 if (O_OCRNL(tty))
432 tty->canon_column = tty->column = 0;
437 if (tty->column > 0)
438 tty->column--;
442 if (O_OLCUC(tty))
444 if (!is_continuation(c, tty))
445 tty->column++;
451 i = tty->ops->write(tty, buf, i);
453 mutex_unlock(&tty->output_lock);
459 * @tty: terminal device
462 * characters to the tty.
483 static void process_echoes(struct tty_struct *tty)
489 if (!tty->echo_cnt)
492 mutex_lock(&tty->output_lock);
493 mutex_lock(&tty->echo_lock);
495 space = tty_write_room(tty);
497 buf_end = tty->echo_buf + N_TTY_BUF_SIZE;
498 cp = tty->echo_buf + tty->echo_pos;
499 nr = tty->echo_cnt;
536 num_chars += tty->canon_column;
545 tty_put_char(tty, '\b');
546 if (tty->column > 0)
547 tty->column--;
554 tty->canon_column = tty->column;
560 if (tty->column > 0)
561 tty->column--;
572 tty_put_char(tty, ECHO_OP_START);
573 tty->column++;
593 tty_put_char(tty, '^');
594 tty_put_char(tty, op ^ 0100);
595 tty->column += 2;
604 if (O_OPOST(tty) &&
605 !(test_bit(TTY_HW_COOK_OUT, &tty->flags))) {
606 int retval = do_output_char(c, tty, space);
613 tty_put_char(tty, c);
626 tty->echo_pos = 0;
627 tty->echo_cnt = 0;
628 tty->echo_overrun = 0;
630 int num_processed = tty->echo_cnt - nr;
631 tty->echo_pos += num_processed;
632 tty->echo_pos &= N_TTY_BUF_SIZE - 1;
633 tty->echo_cnt = nr;
635 tty->echo_overrun = 0;
638 mutex_unlock(&tty->echo_lock);
639 mutex_unlock(&tty->output_lock);
641 if (tty->ops->flush_chars)
642 tty->ops->flush_chars(tty);
648 * @tty: terminal device
655 static void add_echo_byte(unsigned char c, struct tty_struct *tty)
659 if (tty->echo_cnt == N_TTY_BUF_SIZE) {
661 new_byte_pos = tty->echo_pos;
667 if (tty->echo_buf[tty->echo_pos] == ECHO_OP_START) {
668 if (tty->echo_buf[(tty->echo_pos + 1) &
671 tty->echo_pos += 3;
672 tty->echo_cnt -= 2;
674 tty->echo_pos += 2;
675 tty->echo_cnt -= 1;
678 tty->echo_pos++;
680 tty->echo_pos &= N_TTY_BUF_SIZE - 1;
682 tty->echo_overrun = 1;
684 new_byte_pos = tty->echo_pos + tty->echo_cnt;
686 tty->echo_cnt++;
689 tty->echo_buf[new_byte_pos] = c;
694 * @tty: terminal device
701 static void echo_move_back_col(struct tty_struct *tty)
703 mutex_lock(&tty->echo_lock);
705 add_echo_byte(ECHO_OP_START, tty);
706 add_echo_byte(ECHO_OP_MOVE_BACK_COL, tty);
708 mutex_unlock(&tty->echo_lock);
713 * @tty: terminal device
721 static void echo_set_canon_col(struct tty_struct *tty)
723 mutex_lock(&tty->echo_lock);
725 add_echo_byte(ECHO_OP_START, tty);
726 add_echo_byte(ECHO_OP_SET_CANON_COL, tty);
728 mutex_unlock(&tty->echo_lock);
735 * @tty: terminal device
749 struct tty_struct *tty)
751 mutex_lock(&tty->echo_lock);
753 add_echo_byte(ECHO_OP_START, tty);
754 add_echo_byte(ECHO_OP_ERASE_TAB, tty);
763 add_echo_byte(num_chars, tty);
765 mutex_unlock(&tty->echo_lock);
771 * @tty: terminal device
774 * L_ECHO(tty) is true. Called from the driver receive_buf path.
781 static void echo_char_raw(unsigned char c, struct tty_struct *tty)
783 mutex_lock(&tty->echo_lock);
786 add_echo_byte(ECHO_OP_START, tty);
787 add_echo_byte(ECHO_OP_START, tty);
789 add_echo_byte(c, tty);
792 mutex_unlock(&tty->echo_lock);
798 * @tty: terminal device
801 * L_ECHO(tty) is true. Called from the driver receive_buf path.
809 static void echo_char(unsigned char c, struct tty_struct *tty)
811 mutex_lock(&tty->echo_lock);
814 add_echo_byte(ECHO_OP_START, tty);
815 add_echo_byte(ECHO_OP_START, tty);
817 if (L_ECHOCTL(tty) && iscntrl(c) && c != '\t')
818 add_echo_byte(ECHO_OP_START, tty);
819 add_echo_byte(c, tty);
822 mutex_unlock(&tty->echo_lock);
827 * @tty: tty doing the erase
830 static inline void finish_erasing(struct tty_struct *tty)
832 if (tty->erasing) {
833 echo_char_raw('/', tty);
834 tty->erasing = 0;
841 * @tty: terminal device
847 * Locking: read_lock for tty buffers
850 static void eraser(unsigned char c, struct tty_struct *tty)
856 if (tty->read_head == tty->canon_head) {
857 /* process_output('\a', tty); */ /* what do you think? */
860 if (c == ERASE_CHAR(tty))
862 else if (c == WERASE_CHAR(tty))
865 if (!L_ECHO(tty)) {
866 spin_lock_irqsave(&tty->read_lock, flags);
867 tty->read_cnt -= ((tty->read_head - tty->canon_head) &
869 tty->read_head = tty->canon_head;
870 spin_unlock_irqrestore(&tty->read_lock, flags);
873 if (!L_ECHOK(tty) || !L_ECHOKE(tty) || !L_ECHOE(tty)) {
874 spin_lock_irqsave(&tty->read_lock, flags);
875 tty->read_cnt -= ((tty->read_head - tty->canon_head) &
877 tty->read_head = tty->canon_head;
878 spin_unlock_irqrestore(&tty->read_lock, flags);
879 finish_erasing(tty);
880 echo_char(KILL_CHAR(tty), tty);
882 if (L_ECHOK(tty))
883 echo_char_raw('\n', tty);
890 while (tty->read_head != tty->canon_head) {
891 head = tty->read_head;
896 c = tty->read_buf[head];
897 } while (is_continuation(c, tty) && head != tty->canon_head);
900 if (is_continuation(c, tty))
910 cnt = (tty->read_head - head) & (N_TTY_BUF_SIZE-1);
911 spin_lock_irqsave(&tty->read_lock, flags);
912 tty->read_head = head;
913 tty->read_cnt -= cnt;
914 spin_unlock_irqrestore(&tty->read_lock, flags);
915 if (L_ECHO(tty)) {
916 if (L_ECHOPRT(tty)) {
917 if (!tty->erasing) {
918 echo_char_raw('\\', tty);
919 tty->erasing = 1;
922 echo_char(c, tty);
925 echo_char_raw(tty->read_buf[head], tty);
926 echo_move_back_col(tty);
928 } else if (kill_type == ERASE && !L_ECHOE(tty)) {
929 echo_char(ERASE_CHAR(tty), tty);
933 unsigned long tail = tty->read_head;
942 while (tail != tty->canon_head) {
944 c = tty->read_buf[tail];
949 if (L_ECHOCTL(tty))
951 } else if (!is_continuation(c, tty)) {
955 echo_erase_tab(num_chars, after_tab, tty);
957 if (iscntrl(c) && L_ECHOCTL(tty)) {
958 echo_char_raw('\b', tty);
959 echo_char_raw(' ', tty);
960 echo_char_raw('\b', tty);
962 if (!iscntrl(c) || L_ECHOCTL(tty)) {
963 echo_char_raw('\b', tty);
964 echo_char_raw(' ', tty);
965 echo_char_raw('\b', tty);
972 if (tty->read_head == tty->canon_head && L_ECHO(tty))
973 finish_erasing(tty);
979 * @tty: terminal
990 static inline void isig(int sig, struct tty_struct *tty, int flush)
992 if (tty->pgrp)
993 kill_pgrp(tty->pgrp, sig, 1);
994 if (flush || !L_NOFLSH(tty)) {
995 n_tty_flush_buffer(tty);
996 tty_driver_flush_buffer(tty);
1002 * @tty: terminal
1010 static inline void n_tty_receive_break(struct tty_struct *tty)
1012 if (I_IGNBRK(tty))
1014 if (I_BRKINT(tty)) {
1015 isig(SIGINT, tty, 1);
1018 if (I_PARMRK(tty)) {
1019 put_tty_queue('\377', tty);
1020 put_tty_queue('\0', tty);
1022 put_tty_queue('\0', tty);
1023 wake_up_interruptible(&tty->read_wait);
1028 * @tty: terminal
1030 * Data arrived faster than we could process it. While the tty
1039 static inline void n_tty_receive_overrun(struct tty_struct *tty)
1043 tty->num_overrun++;
1044 if (time_before(tty->overrun_time, jiffies - HZ) ||
1045 time_after(tty->overrun_time, jiffies)) {
1047 tty_name(tty, buf),
1048 tty->num_overrun);
1049 tty->overrun_time = jiffies;
1050 tty->num_overrun = 0;
1056 * @tty: terminal device
1062 static inline void n_tty_receive_parity_error(struct tty_struct *tty,
1065 if (I_IGNPAR(tty))
1067 if (I_PARMRK(tty)) {
1068 put_tty_queue('\377', tty);
1069 put_tty_queue('\0', tty);
1070 put_tty_queue(c, tty);
1071 } else if (I_INPCK(tty))
1072 put_tty_queue('\0', tty);
1074 put_tty_queue(c, tty);
1075 wake_up_interruptible(&tty->read_wait);
1080 * @tty: terminal device
1088 static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
1093 if (tty->raw) {
1094 put_tty_queue(c, tty);
1098 if (I_ISTRIP(tty))
1100 if (I_IUCLC(tty) && L_IEXTEN(tty))
1103 if (L_EXTPROC(tty)) {
1104 put_tty_queue(c, tty);
1108 if (tty->stopped && !tty->flow_stopped && I_IXON(tty) &&
1109 I_IXANY(tty) && c != START_CHAR(tty) && c != STOP_CHAR(tty) &&
1110 c != INTR_CHAR(tty) && c != QUIT_CHAR(tty) && c != SUSP_CHAR(tty)) {
1111 start_tty(tty);
1112 process_echoes(tty);
1115 if (tty->closing) {
1116 if (I_IXON(tty)) {
1117 if (c == START_CHAR(tty)) {
1118 start_tty(tty);
1119 process_echoes(tty);
1120 } else if (c == STOP_CHAR(tty))
1121 stop_tty(tty);
1132 if (!test_bit(c, tty->process_char_map) || tty->lnext) {
1133 tty->lnext = 0;
1134 parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty)) ? 1 : 0;
1135 if (tty->read_cnt >= (N_TTY_BUF_SIZE - parmrk - 1)) {
1137 if (L_ECHO(tty))
1138 process_output('\a', tty);
1141 if (L_ECHO(tty)) {
1142 finish_erasing(tty);
1144 if (tty->canon_head == tty->read_head)
1145 echo_set_canon_col(tty);
1146 echo_char(c, tty);
1147 process_echoes(tty);
1150 put_tty_queue(c, tty);
1151 put_tty_queue(c, tty);
1155 if (I_IXON(tty)) {
1156 if (c == START_CHAR(tty)) {
1157 start_tty(tty);
1158 process_echoes(tty);
1161 if (c == STOP_CHAR(tty)) {
1162 stop_tty(tty);
1167 if (L_ISIG(tty)) {
1170 if (c == INTR_CHAR(tty))
1173 if (c == QUIT_CHAR(tty))
1176 if (c == SUSP_CHAR(tty)) {
1183 if (!L_NOFLSH(tty)) {
1184 n_tty_flush_buffer(tty);
1185 tty_driver_flush_buffer(tty);
1187 if (I_IXON(tty))
1188 start_tty(tty);
1189 if (L_ECHO(tty)) {
1190 echo_char(c, tty);
1191 process_echoes(tty);
1193 if (tty->pgrp)
1194 kill_pgrp(tty->pgrp, signal, 1);
1200 if (I_IGNCR(tty))
1202 if (I_ICRNL(tty))
1204 } else if (c == '\n' && I_INLCR(tty))
1207 if (tty->icanon) {
1208 if (c == ERASE_CHAR(tty) || c == KILL_CHAR(tty) ||
1209 (c == WERASE_CHAR(tty) && L_IEXTEN(tty))) {
1210 eraser(c, tty);
1211 process_echoes(tty);
1214 if (c == LNEXT_CHAR(tty) && L_IEXTEN(tty)) {
1215 tty->lnext = 1;
1216 if (L_ECHO(tty)) {
1217 finish_erasing(tty);
1218 if (L_ECHOCTL(tty)) {
1219 echo_char_raw('^', tty);
1220 echo_char_raw('\b', tty);
1221 process_echoes(tty);
1226 if (c == REPRINT_CHAR(tty) && L_ECHO(tty) &&
1227 L_IEXTEN(tty)) {
1228 unsigned long tail = tty->canon_head;
1230 finish_erasing(tty);
1231 echo_char(c, tty);
1232 echo_char_raw('\n', tty);
1233 while (tail != tty->read_head) {
1234 echo_char(tty->read_buf[tail], tty);
1237 process_echoes(tty);
1241 if (tty->read_cnt >= N_TTY_BUF_SIZE) {
1242 if (L_ECHO(tty))
1243 process_output('\a', tty);
1246 if (L_ECHO(tty) || L_ECHONL(tty)) {
1247 echo_char_raw('\n', tty);
1248 process_echoes(tty);
1252 if (c == EOF_CHAR(tty)) {
1253 if (tty->read_cnt >= N_TTY_BUF_SIZE)
1255 if (tty->canon_head != tty->read_head)
1256 set_bit(TTY_PUSH, &tty->flags);
1260 if ((c == EOL_CHAR(tty)) ||
1261 (c == EOL2_CHAR(tty) && L_IEXTEN(tty))) {
1262 parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty))
1264 if (tty->read_cnt >= (N_TTY_BUF_SIZE - parmrk)) {
1265 if (L_ECHO(tty))
1266 process_output('\a', tty);
1269 if (L_ECHO(tty)) {
1271 if (tty->canon_head == tty->read_head)
1272 echo_set_canon_col(tty);
1273 echo_char(c, tty);
1274 process_echoes(tty);
1277 put_tty_queue(c, tty);
1280 spin_lock_irqsave(&tty->read_lock, flags);
1281 set_bit(tty->read_head, tty->read_flags);
1282 put_tty_queue_nolock(c, tty);
1283 tty->canon_head = tty->read_head;
1284 tty->canon_data++;
1285 spin_unlock_irqrestore(&tty->read_lock, flags);
1286 kill_fasync(&tty->fasync, SIGIO, POLL_IN);
1287 if (waitqueue_active(&tty->read_wait))
1288 wake_up_interruptible(&tty->read_wait);
1293 parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty)) ? 1 : 0;
1294 if (tty->read_cnt >= (N_TTY_BUF_SIZE - parmrk - 1)) {
1296 if (L_ECHO(tty))
1297 process_output('\a', tty);
1300 if (L_ECHO(tty)) {
1301 finish_erasing(tty);
1303 echo_char_raw('\n', tty);
1306 if (tty->canon_head == tty->read_head)
1307 echo_set_canon_col(tty);
1308 echo_char(c, tty);
1310 process_echoes(tty);
1314 put_tty_queue(c, tty);
1316 put_tty_queue(c, tty);
1322 * @tty: tty device
1329 static void n_tty_write_wakeup(struct tty_struct *tty)
1331 if (tty->fasync && test_and_clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags))
1332 kill_fasync(&tty->fasync, SIGIO, POLL_OUT);
1337 * @tty: terminal device
1348 static void n_tty_receive_buf(struct tty_struct *tty, const unsigned char *cp,
1357 if (!tty->read_buf)
1360 if (tty->real_raw) {
1361 spin_lock_irqsave(&tty->read_lock, cpuflags);
1362 i = min(N_TTY_BUF_SIZE - tty->read_cnt,
1363 N_TTY_BUF_SIZE - tty->read_head);
1365 memcpy(tty->read_buf + tty->read_head, cp, i);
1366 tty->read_head = (tty->read_head + i) & (N_TTY_BUF_SIZE-1);
1367 tty->read_cnt += i;
1371 i = min(N_TTY_BUF_SIZE - tty->read_cnt,
1372 N_TTY_BUF_SIZE - tty->read_head);
1374 memcpy(tty->read_buf + tty->read_head, cp, i);
1375 tty->read_head = (tty->read_head + i) & (N_TTY_BUF_SIZE-1);
1376 tty->read_cnt += i;
1377 spin_unlock_irqrestore(&tty->read_lock, cpuflags);
1384 n_tty_receive_char(tty, *p);
1387 n_tty_receive_break(tty);
1391 n_tty_receive_parity_error(tty, *p);
1394 n_tty_receive_overrun(tty);
1398 tty_name(tty, buf), flags);
1402 if (tty->ops->flush_chars)
1403 tty->ops->flush_chars(tty);
1406 n_tty_set_room(tty);
1408 if ((!tty->icanon && (tty->read_cnt >= tty->minimum_to_wake)) ||
1409 L_EXTPROC(tty)) {
1410 kill_fasync(&tty->fasync, SIGIO, POLL_IN);
1411 if (waitqueue_active(&tty->read_wait))
1412 wake_up_interruptible(&tty->read_wait);
1420 if (tty->receive_room < TTY_THRESHOLD_THROTTLE)
1421 tty_throttle(tty);
1432 * @tty: terminal
1435 * Called by the tty layer when the user changes termios flags so
1437 * and is protected from re-entry by the tty layer. The user is
1441 * Locking: Caller holds tty->termios_mutex
1444 static void n_tty_set_termios(struct tty_struct *tty, struct ktermios *old)
1447 BUG_ON(!tty);
1450 canon_change = (old->c_lflag ^ tty->termios->c_lflag) & ICANON;
1452 memset(&tty->read_flags, 0, sizeof tty->read_flags);
1453 tty->canon_head = tty->read_tail;
1454 tty->canon_data = 0;
1455 tty->erasing = 0;
1458 if (canon_change && !L_ICANON(tty) && tty->read_cnt)
1459 wake_up_interruptible(&tty->read_wait);
1461 tty->icanon = (L_ICANON(tty) != 0);
1462 if (test_bit(TTY_HW_COOK_IN, &tty->flags)) {
1463 tty->raw = 1;
1464 tty->real_raw = 1;
1465 n_tty_set_room(tty);
1468 if (I_ISTRIP(tty) || I_IUCLC(tty) || I_IGNCR(tty) ||
1469 I_ICRNL(tty) || I_INLCR(tty) || L_ICANON(tty) ||
1470 I_IXON(tty) || L_ISIG(tty) || L_ECHO(tty) ||
1471 I_PARMRK(tty)) {
1472 memset(tty->process_char_map, 0, 256/8);
1474 if (I_IGNCR(tty) || I_ICRNL(tty))
1475 set_bit('\r', tty->process_char_map);
1476 if (I_INLCR(tty))
1477 set_bit('\n', tty->process_char_map);
1479 if (L_ICANON(tty)) {
1480 set_bit(ERASE_CHAR(tty), tty->process_char_map);
1481 set_bit(KILL_CHAR(tty), tty->process_char_map);
1482 set_bit(EOF_CHAR(tty), tty->process_char_map);
1483 set_bit('\n', tty->process_char_map);
1484 set_bit(EOL_CHAR(tty), tty->process_char_map);
1485 if (L_IEXTEN(tty)) {
1486 set_bit(WERASE_CHAR(tty),
1487 tty->process_char_map);
1488 set_bit(LNEXT_CHAR(tty),
1489 tty->process_char_map);
1490 set_bit(EOL2_CHAR(tty),
1491 tty->process_char_map);
1492 if (L_ECHO(tty))
1493 set_bit(REPRINT_CHAR(tty),
1494 tty->process_char_map);
1497 if (I_IXON(tty)) {
1498 set_bit(START_CHAR(tty), tty->process_char_map);
1499 set_bit(STOP_CHAR(tty), tty->process_char_map);
1501 if (L_ISIG(tty)) {
1502 set_bit(INTR_CHAR(tty), tty->process_char_map);
1503 set_bit(QUIT_CHAR(tty), tty->process_char_map);
1504 set_bit(SUSP_CHAR(tty), tty->process_char_map);
1506 clear_bit(__DISABLED_CHAR, tty->process_char_map);
1507 tty->raw = 0;
1508 tty->real_raw = 0;
1510 tty->raw = 1;
1511 if ((I_IGNBRK(tty) || (!I_BRKINT(tty) && !I_PARMRK(tty))) &&
1512 (I_IGNPAR(tty) || !I_INPCK(tty)) &&
1513 (tty->driver->flags & TTY_DRIVER_REAL_RAW))
1514 tty->real_raw = 1;
1516 tty->real_raw = 0;
1518 n_tty_set_room(tty);
1519 /* The termios change make the tty ready for I/O */
1520 wake_up_interruptible(&tty->write_wait);
1521 wake_up_interruptible(&tty->read_wait);
1525 * n_tty_close - close the ldisc for this tty
1526 * @tty: device
1534 static void n_tty_close(struct tty_struct *tty)
1536 n_tty_flush_buffer(tty);
1537 if (tty->read_buf) {
1538 kfree(tty->read_buf);
1539 tty->read_buf = NULL;
1541 if (tty->echo_buf) {
1542 kfree(tty->echo_buf);
1543 tty->echo_buf = NULL;
1549 * @tty: terminal to open
1557 static int n_tty_open(struct tty_struct *tty)
1559 if (!tty)
1563 if (!tty->read_buf) {
1564 tty->read_buf = kzalloc(N_TTY_BUF_SIZE, GFP_KERNEL);
1565 if (!tty->read_buf)
1568 if (!tty->echo_buf) {
1569 tty->echo_buf = kzalloc(N_TTY_BUF_SIZE, GFP_KERNEL);
1571 if (!tty->echo_buf)
1574 reset_buffer_flags(tty);
1575 tty->column = 0;
1576 n_tty_set_termios(tty, NULL);
1577 tty->minimum_to_wake = 1;
1578 tty->closing = 0;
1582 static inline int input_available_p(struct tty_struct *tty, int amt)
1584 tty_flush_to_ldisc(tty);
1585 if (tty->icanon && !L_EXTPROC(tty)) {
1586 if (tty->canon_data)
1588 } else if (tty->read_cnt >= (amt ? amt : 1))
1596 * @tty: terminal device
1601 * ICANON is off; it copies characters straight from the tty queue to
1607 * Called under the tty->atomic_read_lock sem
1611 static int copy_from_read_buf(struct tty_struct *tty,
1621 spin_lock_irqsave(&tty->read_lock, flags);
1622 n = min(tty->read_cnt, N_TTY_BUF_SIZE - tty->read_tail);
1624 spin_unlock_irqrestore(&tty->read_lock, flags);
1626 retval = copy_to_user(*b, &tty->read_buf[tty->read_tail], n);
1628 tty_audit_add_data(tty, &tty->read_buf[tty->read_tail], n);
1629 spin_lock_irqsave(&tty->read_lock, flags);
1630 tty->read_tail = (tty->read_tail + n) & (N_TTY_BUF_SIZE-1);
1631 tty->read_cnt -= n;
1633 if (L_EXTPROC(tty) && tty->icanon && n == 1) {
1634 if (!tty->read_cnt && (*b)[n-1] == EOF_CHAR(tty))
1637 spin_unlock_irqrestore(&tty->read_lock, flags);
1648 static int job_control(struct tty_struct *tty, struct file *file)
1656 current->signal->tty == tty) {
1657 if (!tty->pgrp)
1658 printk(KERN_ERR "n_tty_read: no tty->pgrp!\n");
1659 else if (task_pgrp(current) != tty->pgrp) {
1673 * n_tty_read - read function for tty
1674 * @tty: tty device
1687 static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
1702 BUG_ON(!tty->read_buf);
1704 c = job_control(tty, file);
1710 if (!tty->icanon) {
1711 time = (HZ / 10) * TIME_CHAR(tty);
1712 minimum = MIN_CHAR(tty);
1715 tty->minimum_to_wake = 1;
1716 else if (!waitqueue_active(&tty->read_wait) ||
1717 (tty->minimum_to_wake > minimum))
1718 tty->minimum_to_wake = minimum;
1725 tty->minimum_to_wake = minimum = 1;
1733 if (!mutex_trylock(&tty->atomic_read_lock))
1736 if (mutex_lock_interruptible(&tty->atomic_read_lock))
1739 packet = tty->packet;
1741 add_wait_queue(&tty->read_wait, &wait);
1744 if (packet && tty->link->ctrl_status) {
1748 spin_lock_irqsave(&tty->link->ctrl_lock, flags);
1749 cs = tty->link->ctrl_status;
1750 tty->link->ctrl_status = 0;
1751 spin_unlock_irqrestore(&tty->link->ctrl_lock, flags);
1752 if (tty_put_user(tty, cs, b++)) {
1761 if (((minimum - (b - buf)) < tty->minimum_to_wake) &&
1763 tty->minimum_to_wake = (minimum - (b - buf));
1765 if (!input_available_p(tty, 0)) {
1766 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) {
1782 n_tty_set_room(tty);
1789 if (tty_put_user(tty, TIOCPKT_DATA, b++)) {
1797 if (tty->icanon && !L_EXTPROC(tty)) {
1799 while (nr && tty->read_cnt) {
1802 eol = test_and_clear_bit(tty->read_tail,
1803 tty->read_flags);
1804 c = tty->read_buf[tty->read_tail];
1805 spin_lock_irqsave(&tty->read_lock, flags);
1806 tty->read_tail = ((tty->read_tail+1) &
1808 tty->read_cnt--;
1814 if (--tty->canon_data < 0)
1815 tty->canon_data = 0;
1817 spin_unlock_irqrestore(&tty->read_lock, flags);
1820 if (tty_put_user(tty, c, b++)) {
1828 tty_audit_push(tty);
1838 uncopied = copy_from_read_buf(tty, &b, &nr);
1839 uncopied += copy_from_read_buf(tty, &b, &nr);
1853 if (n_tty_chars_in_buffer(tty) <= TTY_THRESHOLD_UNTHROTTLE) {
1854 n_tty_set_room(tty);
1855 check_unthrottle(tty);
1863 mutex_unlock(&tty->atomic_read_lock);
1864 remove_wait_queue(&tty->read_wait, &wait);
1866 if (!waitqueue_active(&tty->read_wait))
1867 tty->minimum_to_wake = minimum;
1873 clear_bit(TTY_PUSH, &tty->flags);
1874 } else if (test_and_clear_bit(TTY_PUSH, &tty->flags))
1877 n_tty_set_room(tty);
1882 * n_tty_write - write function for tty
1883 * @tty: tty device
1903 static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
1912 if (L_TOSTOP(tty) && file->f_op->write != redirected_tty_write) {
1913 retval = tty_check_change(tty);
1919 process_echoes(tty);
1921 add_wait_queue(&tty->write_wait, &wait);
1927 if (tty_hung_up_p(file) || (tty->link && !tty->link->count)) {
1931 if (O_OPOST(tty) && !(test_bit(TTY_HW_COOK_OUT, &tty->flags))) {
1933 ssize_t num = process_output_block(tty, b, nr);
1945 if (process_output(c, tty) < 0)
1949 if (tty->ops->flush_chars)
1950 tty->ops->flush_chars(tty);
1953 c = tty->ops->write(tty, b, nr);
1973 remove_wait_queue(&tty->write_wait, &wait);
1974 if (b - buf != nr && tty->fasync)
1975 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
1981 * @tty: terminal device
1993 static unsigned int n_tty_poll(struct tty_struct *tty, struct file *file,
1998 poll_wait(file, &tty->read_wait, wait);
1999 poll_wait(file, &tty->write_wait, wait);
2000 if (input_available_p(tty, TIME_CHAR(tty) ? 0 : MIN_CHAR(tty)))
2002 if (tty->packet && tty->link->ctrl_status)
2004 if (test_bit(TTY_OTHER_CLOSED, &tty->flags))
2009 if (MIN_CHAR(tty) && !TIME_CHAR(tty))
2010 tty->minimum_to_wake = MIN_CHAR(tty);
2012 tty->minimum_to_wake = 1;
2014 if (tty->ops->write && !tty_is_writelocked(tty) &&
2015 tty_chars_in_buffer(tty) < WAKEUP_CHARS &&
2016 tty_write_room(tty) > 0)
2021 static unsigned long inq_canon(struct tty_struct *tty)
2025 if (!tty->canon_data)
2027 head = tty->canon_head;
2028 tail = tty->read_tail;
2032 if (test_bit(tail, tty->read_flags) &&
2033 tty->read_buf[tail] == __DISABLED_CHAR)
2040 static int n_tty_ioctl(struct tty_struct *tty, struct file *file,
2047 return put_user(tty_chars_in_buffer(tty), (int __user *) arg);
2049 retval = tty->read_cnt;
2050 if (L_ICANON(tty))
2051 retval = inq_canon(tty);
2054 return n_tty_ioctl_helper(tty, file, cmd, arg);