Lines Matching refs:tty

129 static void initialize_tty_struct(struct tty_struct *tty);
177 struct tty_struct *tty; in alloc_tty_struct() local
179 tty = kmalloc(sizeof(struct tty_struct), GFP_KERNEL); in alloc_tty_struct()
180 if (tty) in alloc_tty_struct()
181 memset(tty, 0, sizeof(struct tty_struct)); in alloc_tty_struct()
182 return tty; in alloc_tty_struct()
185 static inline void free_tty_struct(struct tty_struct *tty) in free_tty_struct() argument
187 kfree(tty); in free_tty_struct()
194 _tty_make_name(struct tty_struct *tty, const char *name, char *buf) in _tty_make_name() argument
196 int idx = (tty)?MINOR(tty->device) - tty->driver.minor_start:0; in _tty_make_name()
198 if (!tty) /* Hmm. NULL pointer. That's fun. */ in _tty_make_name()
202 idx + tty->driver.name_base); in _tty_make_name()
207 #define TTY_NUMBER(tty) (MINOR((tty)->device) - (tty)->driver.minor_start + \ argument
208 (tty)->driver.name_base)
210 char *tty_name(struct tty_struct *tty, char *buf) in tty_name() argument
212 return _tty_make_name(tty, (tty)?tty->driver.name:NULL, buf); in tty_name()
215 inline int tty_paranoia_check(struct tty_struct *tty, kdev_t device, in tty_paranoia_check() argument
224 if (!tty) { in tty_paranoia_check()
228 if (tty->magic != TTY_MAGIC) { in tty_paranoia_check()
236 static int check_tty_count(struct tty_struct *tty, const char *routine) in check_tty_count() argument
243 for(p = tty->tty_files.next; p != &tty->tty_files; p = p->next) { in check_tty_count()
244 if(list_entry(p, struct file, f_list)->private_data == tty) in check_tty_count()
248 if (tty->driver.type == TTY_DRIVER_TYPE_PTY && in check_tty_count()
249 tty->driver.subtype == PTY_TYPE_SLAVE && in check_tty_count()
250 tty->link && tty->link->count) in check_tty_count()
252 if (tty->count != count) { in check_tty_count()
255 kdevname(tty->device), tty->count, count, routine); in check_tty_count()
268 static void tty_set_termios_ldisc(struct tty_struct *tty, int num) in tty_set_termios_ldisc() argument
270 down(&tty->termios_sem); in tty_set_termios_ldisc()
271 tty->termios->c_line = num; in tty_set_termios_ldisc()
272 up(&tty->termios_sem); in tty_set_termios_ldisc()
355 void tty_ldisc_assign(struct tty_struct *tty, struct tty_ldisc *ld) in tty_ldisc_assign() argument
357 tty->ldisc = *ld; in tty_ldisc_assign()
358 tty->ldisc.refcount = 0; in tty_ldisc_assign()
371 static int tty_ldisc_try(struct tty_struct *tty) in tty_ldisc_try() argument
378 ld = &tty->ldisc; in tty_ldisc_try()
379 if(test_bit(TTY_LDISC, &tty->flags)) in tty_ldisc_try()
402 struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *tty) in tty_ldisc_ref_wait() argument
405 wait_event(tty_ldisc_wait, tty_ldisc_try(tty)); in tty_ldisc_ref_wait()
406 return &tty->ldisc; in tty_ldisc_ref_wait()
420 struct tty_ldisc *tty_ldisc_ref(struct tty_struct *tty) in tty_ldisc_ref() argument
422 if(tty_ldisc_try(tty)) in tty_ldisc_ref()
423 return &tty->ldisc; in tty_ldisc_ref()
461 static void tty_ldisc_enable(struct tty_struct *tty) in tty_ldisc_enable() argument
463 set_bit(TTY_LDISC, &tty->flags); in tty_ldisc_enable()
476 static int tty_set_ldisc(struct tty_struct *tty, int ldisc) in tty_set_ldisc() argument
489 if (tty->ldisc.num == ldisc) in tty_set_ldisc()
507 o_ldisc = tty->ldisc; in tty_set_ldisc()
508 tty_wait_until_sent(tty, 0); in tty_set_ldisc()
518 if(tty->ldisc.refcount) in tty_set_ldisc()
531 if(wait_event_interruptible(tty_ldisc_wait, tty->ldisc.refcount == 0) < 0) in tty_set_ldisc()
535 clear_bit(TTY_LDISC, &tty->flags); in tty_set_ldisc()
536 clear_bit(TTY_DONT_FLIP, &tty->flags); in tty_set_ldisc()
552 if (tty->ldisc.close) in tty_set_ldisc()
553 (tty->ldisc.close)(tty); in tty_set_ldisc()
556 tty_ldisc_assign(tty, ld); in tty_set_ldisc()
557 tty_set_termios_ldisc(tty, ldisc); in tty_set_ldisc()
558 if (tty->ldisc.open) in tty_set_ldisc()
559 retval = (tty->ldisc.open)(tty); in tty_set_ldisc()
563 tty_ldisc_assign(tty, tty_ldisc_get(o_ldisc.num)); in tty_set_ldisc()
564 tty_set_termios_ldisc(tty, tty->ldisc.num); in tty_set_ldisc()
565 if (tty->ldisc.open && (tty->ldisc.open(tty) < 0)) { in tty_set_ldisc()
568 tty_ldisc_assign(tty, tty_ldisc_get(N_TTY)); in tty_set_ldisc()
569 tty_set_termios_ldisc(tty, N_TTY); in tty_set_ldisc()
570 if (tty->ldisc.open) { in tty_set_ldisc()
571 int r = tty->ldisc.open(tty); in tty_set_ldisc()
576 tty_name(tty, buf), r); in tty_set_ldisc()
584 if (tty->ldisc.num != o_ldisc.num && tty->driver.set_ldisc) in tty_set_ldisc()
585 tty->driver.set_ldisc(tty); in tty_set_ldisc()
593 tty_ldisc_enable(tty); in tty_set_ldisc()
626 int tty_check_change(struct tty_struct * tty) in tty_check_change() argument
628 if (current->tty != tty) in tty_check_change()
630 if (tty->pgrp <= 0) { in tty_check_change()
634 if (current->pgrp == tty->pgrp) in tty_check_change()
706 void tty_wakeup(struct tty_struct *tty) in tty_wakeup() argument
710 if (test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) { in tty_wakeup()
711 ld = tty_ldisc_ref(tty); in tty_wakeup()
714 ld->write_wakeup(tty); in tty_wakeup()
718 wake_up_interruptible(&tty->write_wait); in tty_wakeup()
728 void tty_ldisc_flush(struct tty_struct *tty) in tty_ldisc_flush() argument
730 struct tty_ldisc *ld = tty_ldisc_ref(tty); in tty_ldisc_flush()
733 ld->flush_buffer(tty); in tty_ldisc_flush()
747 struct tty_struct *tty = (struct tty_struct *) data; in do_tty_hangup() local
755 if (!tty) in do_tty_hangup()
762 if (redirect && redirect->private_data == tty) { in do_tty_hangup()
768 check_tty_count(tty, "do_tty_hangup"); in do_tty_hangup()
770 for (l = tty->tty_files.next; l != &tty->tty_files; l = l->next) { in do_tty_hangup()
786 ld = tty_ldisc_ref(tty); in do_tty_hangup()
790 ld->flush_buffer(tty); in do_tty_hangup()
791 if (tty->driver.flush_buffer) in do_tty_hangup()
792 tty->driver.flush_buffer(tty); in do_tty_hangup()
793 if ((test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) && ld->write_wakeup) in do_tty_hangup()
794 ld->write_wakeup(tty); in do_tty_hangup()
796 ld->hangup(tty); in do_tty_hangup()
802 wake_up_interruptible(&tty->write_wait); in do_tty_hangup()
803 wake_up_interruptible(&tty->read_wait); in do_tty_hangup()
810 if (tty->driver.flags & TTY_DRIVER_RESET_TERMIOS) in do_tty_hangup()
812 down(&tty->termios_sem); in do_tty_hangup()
813 *tty->termios = tty->driver.init_termios; in do_tty_hangup()
814 up(&tty->termios_sem); in do_tty_hangup()
824 if ((tty->session > 0) && (p->session == tty->session) && in do_tty_hangup()
828 if (tty->pgrp > 0) in do_tty_hangup()
829 p->tty_old_pgrp = tty->pgrp; in do_tty_hangup()
831 if (p->tty == tty) in do_tty_hangup()
832 p->tty = NULL; in do_tty_hangup()
836 tty->flags = 0; in do_tty_hangup()
837 tty->session = 0; in do_tty_hangup()
838 tty->pgrp = -1; in do_tty_hangup()
839 tty->ctrl_status = 0; in do_tty_hangup()
847 if (tty->driver.close) in do_tty_hangup()
849 tty->driver.close(tty, cons_filp); in do_tty_hangup()
850 } else if (tty->driver.hangup) in do_tty_hangup()
851 (tty->driver.hangup)(tty); in do_tty_hangup()
858 set_bit(TTY_HUPPED, &tty->flags); in do_tty_hangup()
860 tty_ldisc_enable(tty); in do_tty_hangup()
868 void tty_hangup(struct tty_struct * tty) in tty_hangup() argument
873 printk(KERN_DEBUG "%s hangup...\n", tty_name(tty, buf)); in tty_hangup()
875 schedule_task(&tty->tq_hangup); in tty_hangup()
878 void tty_vhangup(struct tty_struct * tty) in tty_vhangup() argument
883 printk(KERN_DEBUG "%s vhangup...\n", tty_name(tty, buf)); in tty_vhangup()
885 do_tty_hangup((void *) tty); in tty_vhangup()
908 struct tty_struct *tty = current->tty; in disassociate_ctty() local
912 if (tty) { in disassociate_ctty()
913 tty_pgrp = tty->pgrp; in disassociate_ctty()
914 if (on_exit && tty->driver.type != TTY_DRIVER_TYPE_PTY) in disassociate_ctty()
915 tty_vhangup(tty); in disassociate_ctty()
930 tty->session = 0; in disassociate_ctty()
931 tty->pgrp = -1; in disassociate_ctty()
936 p->tty = NULL; in disassociate_ctty()
940 void stop_tty(struct tty_struct *tty) in stop_tty() argument
942 if (tty->stopped) in stop_tty()
944 tty->stopped = 1; in stop_tty()
945 if (tty->link && tty->link->packet) { in stop_tty()
946 tty->ctrl_status &= ~TIOCPKT_START; in stop_tty()
947 tty->ctrl_status |= TIOCPKT_STOP; in stop_tty()
948 wake_up_interruptible(&tty->link->read_wait); in stop_tty()
950 if (tty->driver.stop) in stop_tty()
951 (tty->driver.stop)(tty); in stop_tty()
954 void start_tty(struct tty_struct *tty) in start_tty() argument
956 if (!tty->stopped || tty->flow_stopped) in start_tty()
958 tty->stopped = 0; in start_tty()
959 if (tty->link && tty->link->packet) { in start_tty()
960 tty->ctrl_status &= ~TIOCPKT_STOP; in start_tty()
961 tty->ctrl_status |= TIOCPKT_START; in start_tty()
962 wake_up_interruptible(&tty->link->read_wait); in start_tty()
964 if (tty->driver.start) in start_tty()
965 (tty->driver.start)(tty); in start_tty()
967 tty_wakeup(tty); in start_tty()
974 struct tty_struct * tty; in tty_read() local
982 tty = (struct tty_struct *)file->private_data; in tty_read()
984 if (tty_paranoia_check(tty, inode->i_rdev, "tty_read")) in tty_read()
986 if (!tty || (test_bit(TTY_IO_ERROR, &tty->flags))) in tty_read()
995 (tty->pgrp > 0) && in tty_read()
996 (current->tty == tty) && in tty_read()
997 (tty->pgrp != current->pgrp)) in tty_read()
1007 ld = tty_ldisc_ref_wait(tty); in tty_read()
1010 i = (ld->read)(tty,file,buf,count); in tty_read()
1026 struct tty_struct *tty, in do_tty_write() argument
1034 if (down_trylock(&tty->atomic_write)) in do_tty_write()
1038 if (down_interruptible(&tty->atomic_write)) in do_tty_write()
1041 if ( test_bit(TTY_NO_WRITE_SPLIT, &tty->flags) ) { in do_tty_write()
1043 written = write(tty, file, buf, count); in do_tty_write()
1051 ret = write(tty, file, buf, size); in do_tty_write()
1071 up(&tty->atomic_write); in do_tty_write()
1080 struct tty_struct * tty; in tty_write() local
1114 tty = (struct tty_struct *)file->private_data; in tty_write()
1115 if (tty_paranoia_check(tty, inode->i_rdev, "tty_write")) in tty_write()
1117 if (!tty || !tty->driver.write || (test_bit(TTY_IO_ERROR, &tty->flags))) in tty_write()
1120 if (!is_console && L_TOSTOP(tty) && (tty->pgrp > 0) && in tty_write()
1121 (current->tty == tty) && (tty->pgrp != current->pgrp)) { in tty_write()
1131 ld = tty_ldisc_ref_wait(tty); in tty_write()
1135 ret = do_tty_write(ld->write, tty, file, in tty_write()
1155 static void release_mem(struct tty_struct *tty, int idx);
1165 struct tty_struct *tty, *o_tty; in init_dev() local
1185 tty = driver->table[idx]; in init_dev()
1186 if (tty) goto fast_track; in init_dev()
1200 tty = alloc_tty_struct(); in init_dev()
1201 if(!tty) in init_dev()
1203 initialize_tty_struct(tty); in init_dev()
1204 tty->device = device; in init_dev()
1205 tty->driver = *driver; in init_dev()
1267 tty->link = o_tty; in init_dev()
1268 o_tty->link = tty; in init_dev()
1276 driver->table[idx] = tty; in init_dev()
1282 tty->termios = *tp_loc; in init_dev()
1283 tty->termios_locked = *ltp_loc; in init_dev()
1285 tty->count++; in init_dev()
1292 if (tty->ldisc.open) { in init_dev()
1293 retval = (tty->ldisc.open)(tty); in init_dev()
1300 if (tty->ldisc.close) in init_dev()
1301 (tty->ldisc.close)(tty); in init_dev()
1307 tty_ldisc_enable(tty); in init_dev()
1317 if (test_bit(TTY_CLOSING, &tty->flags)) { in init_dev()
1327 if (tty->count) { in init_dev()
1331 tty->link->count++; in init_dev()
1333 tty->count++; in init_dev()
1334 tty->driver = *driver; /* N.B. why do this every time?? */ in init_dev()
1336 if(!test_bit(TTY_LDISC, &tty->flags)) in init_dev()
1339 *ret_tty = tty; in init_dev()
1356 free_tty_struct(tty); in init_dev()
1366 release_mem(tty, idx); in init_dev()
1374 static void release_mem(struct tty_struct *tty, int idx) in release_mem() argument
1379 if ((o_tty = tty->link) != NULL) { in release_mem()
1392 tty->driver.table[idx] = NULL; in release_mem()
1393 if (tty->driver.flags & TTY_DRIVER_RESET_TERMIOS) { in release_mem()
1394 tp = tty->driver.termios[idx]; in release_mem()
1395 tty->driver.termios[idx] = NULL; in release_mem()
1398 tty->magic = 0; in release_mem()
1399 (*tty->driver.refcount)--; in release_mem()
1400 list_del_init(&tty->tty_files); in release_mem()
1401 free_tty_struct(tty); in release_mem()
1414 struct tty_struct *tty, *o_tty; in release_dev() local
1420 tty = (struct tty_struct *)filp->private_data; in release_dev()
1421 if (tty_paranoia_check(tty, filp->f_dentry->d_inode->i_rdev, "release_dev")) in release_dev()
1424 check_tty_count(tty, "release_dev"); in release_dev()
1428 idx = MINOR(tty->device) - tty->driver.minor_start; in release_dev()
1429 pty_master = (tty->driver.type == TTY_DRIVER_TYPE_PTY && in release_dev()
1430 tty->driver.subtype == PTY_TYPE_MASTER); in release_dev()
1431 o_tty = tty->link; in release_dev()
1434 if (idx < 0 || idx >= tty->driver.num) { in release_dev()
1436 "free (%s)\n", kdevname(tty->device)); in release_dev()
1439 if (tty != tty->driver.table[idx]) { in release_dev()
1441 "for (%s)\n", idx, kdevname(tty->device)); in release_dev()
1444 if (tty->termios != tty->driver.termios[idx]) { in release_dev()
1447 idx, kdevname(tty->device)); in release_dev()
1450 if (tty->termios_locked != tty->driver.termios_locked[idx]) { in release_dev()
1453 idx, kdevname(tty->device)); in release_dev()
1460 tty_name(tty, buf), tty->count); in release_dev()
1464 if (tty->driver.other) { in release_dev()
1465 if (o_tty != tty->driver.other->table[idx]) { in release_dev()
1468 idx, kdevname(tty->device)); in release_dev()
1471 if (o_tty->termios != tty->driver.other->termios[idx]) { in release_dev()
1474 idx, kdevname(tty->device)); in release_dev()
1478 tty->driver.other->termios_locked[idx]) { in release_dev()
1481 idx, kdevname(tty->device)); in release_dev()
1484 if (o_tty->link != tty) { in release_dev()
1491 if (tty->driver.close) in release_dev()
1492 tty->driver.close(tty, filp); in release_dev()
1512 tty_closing = tty->count <= 1; in release_dev()
1518 if (waitqueue_active(&tty->read_wait)) { in release_dev()
1519 wake_up(&tty->read_wait); in release_dev()
1522 if (waitqueue_active(&tty->write_wait)) { in release_dev()
1523 wake_up(&tty->write_wait); in release_dev()
1541 "active!\n", tty_name(tty, buf)); in release_dev()
1558 if (--tty->count < 0) { in release_dev()
1560 tty->count, tty_name(tty, buf)); in release_dev()
1561 tty->count = 0; in release_dev()
1582 set_bit(TTY_CLOSING, &tty->flags); in release_dev()
1596 if (p->tty == tty || (o_tty && p->tty == o_tty)) in release_dev()
1597 p->tty = NULL; in release_dev()
1615 clear_bit(TTY_LDISC, &tty->flags); in release_dev()
1616 clear_bit(TTY_DONT_FLIP, &tty->flags); in release_dev()
1632 while(tty->ldisc.refcount) in release_dev()
1635 wait_event(tty_ldisc_wait, tty->ldisc.refcount == 0); in release_dev()
1645 if (tty->ldisc.close) in release_dev()
1646 (tty->ldisc.close)(tty); in release_dev()
1647 tty_ldisc_put(tty->ldisc.num); in release_dev()
1652 tty_ldisc_assign(tty, tty_ldisc_get(N_TTY)); in release_dev()
1653 tty_set_termios_ldisc(tty,N_TTY); in release_dev()
1669 release_mem(tty, idx); in release_dev()
1686 struct tty_struct *tty; in tty_open() local
1697 if (!current->tty) in tty_open()
1699 device = current->tty->device; in tty_open()
1736 if (!init_dev(device, &tty)) goto ptmx_found; /* ok! */ in tty_open()
1741 set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */ in tty_open()
1756 retval = init_dev(device, &tty); in tty_open()
1763 filp->private_data = tty; in tty_open()
1764 file_move(filp, &tty->tty_files); in tty_open()
1765 check_tty_count(tty, "tty_open"); in tty_open()
1766 if (tty->driver.type == TTY_DRIVER_TYPE_PTY && in tty_open()
1767 tty->driver.subtype == PTY_TYPE_MASTER) in tty_open()
1770 printk(KERN_DEBUG "opening %s...", tty_name(tty, buf)); in tty_open()
1772 if (tty->driver.open) in tty_open()
1773 retval = tty->driver.open(tty, filp); in tty_open()
1778 if (!retval && test_bit(TTY_EXCLUSIVE, &tty->flags) && !suser()) in tty_open()
1784 tty_name(tty, buf)); in tty_open()
1801 !current->tty && in tty_open()
1802 tty->session == 0) { in tty_open()
1804 current->tty = tty; in tty_open()
1807 tty->session = current->session; in tty_open()
1808 tty->pgrp = current->pgrp; in tty_open()
1810 if ((tty->driver.type == TTY_DRIVER_TYPE_SERIAL) && in tty_open()
1811 (tty->driver.subtype == SERIAL_TYPE_CALLOUT) && in tty_open()
1812 (tty->count == 1)) { in tty_open()
1819 tty_name(tty, buf), TTY_NUMBER(tty)); in tty_open()
1837 struct tty_struct * tty; in tty_poll() local
1841 tty = (struct tty_struct *)filp->private_data; in tty_poll()
1842 if (tty_paranoia_check(tty, filp->f_dentry->d_inode->i_rdev, "tty_poll")) in tty_poll()
1845 ld = tty_ldisc_ref_wait(tty); in tty_poll()
1847 ret = (ld->poll)(tty, filp, wait); in tty_poll()
1854 struct tty_struct * tty; in tty_fasync() local
1857 tty = (struct tty_struct *)filp->private_data; in tty_fasync()
1858 if (tty_paranoia_check(tty, filp->f_dentry->d_inode->i_rdev, "tty_fasync")) in tty_fasync()
1861 retval = fasync_helper(fd, filp, on, &tty->fasync); in tty_fasync()
1866 if (!waitqueue_active(&tty->read_wait)) in tty_fasync()
1867 tty->minimum_to_wake = 1; in tty_fasync()
1869 filp->f_owner.pid = (-tty->pgrp) ? : current->pid; in tty_fasync()
1874 if (!tty->fasync && !waitqueue_active(&tty->read_wait)) in tty_fasync()
1875 tty->minimum_to_wake = N_TTY_BUF_SIZE; in tty_fasync()
1880 static int tiocsti(struct tty_struct *tty, char * arg) in tiocsti() argument
1885 if ((current->tty != tty) && !suser()) in tiocsti()
1889 ld = tty_ldisc_ref_wait(tty); in tiocsti()
1890 ld->receive_buf(tty, &ch, &mbz, 1); in tiocsti()
1895 static int tiocgwinsz(struct tty_struct *tty, struct winsize * arg) in tiocgwinsz() argument
1897 if (copy_to_user(arg, &tty->winsize, sizeof(*arg))) in tiocgwinsz()
1902 static int tiocswinsz(struct tty_struct *tty, struct tty_struct *real_tty, in tiocswinsz() argument
1909 if (!memcmp(&tmp_ws, &tty->winsize, sizeof(*arg))) in tiocswinsz()
1911 if (tty->pgrp > 0) in tiocswinsz()
1912 kill_pg(tty->pgrp, SIGWINCH, 1); in tiocswinsz()
1913 if ((real_tty->pgrp != tty->pgrp) && (real_tty->pgrp > 0)) in tiocswinsz()
1915 tty->winsize = tmp_ws; in tiocswinsz()
1961 static int tiocsctty(struct tty_struct *tty, int arg) in tiocsctty() argument
1964 (current->session == tty->session)) in tiocsctty()
1970 if (!current->leader || current->tty) in tiocsctty()
1972 if (tty->session > 0) { in tiocsctty()
1985 if (p->tty == tty) in tiocsctty()
1986 p->tty = NULL; in tiocsctty()
1992 current->tty = tty; in tiocsctty()
1995 tty->session = current->session; in tiocsctty()
1996 tty->pgrp = current->pgrp; in tiocsctty()
2000 static int tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t *arg) in tiocgpgrp() argument
2006 if (tty == real_tty && current->tty != real_tty) in tiocgpgrp()
2011 static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t *arg) in tiocspgrp() argument
2020 if (!current->tty || in tiocspgrp()
2021 (current->tty != real_tty) || in tiocspgrp()
2034 static int tiocgsid(struct tty_struct *tty, struct tty_struct *real_tty, pid_t *arg) in tiocgsid() argument
2040 if (tty == real_tty && current->tty != real_tty) in tiocgsid()
2047 static int tiocttygstruct(struct tty_struct *tty, struct tty_struct *arg) in tiocttygstruct() argument
2049 if (copy_to_user(arg, tty, sizeof(*arg))) in tiocttygstruct()
2054 static int tiocsetd(struct tty_struct *tty, int *arg) in tiocsetd() argument
2060 return tty_set_ldisc(tty, ldisc); in tiocsetd()
2063 static int send_break(struct tty_struct *tty, int duration) in send_break() argument
2065 tty->driver.break_ctl(tty, -1); in send_break()
2070 tty->driver.break_ctl(tty, 0); in send_break()
2076 static int tty_generic_brk(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned lo… in tty_generic_brk() argument
2081 int retval = tty_check_change(tty); in tty_generic_brk()
2084 tty_wait_until_sent(tty, 0); in tty_generic_brk()
2097 struct tty_struct *tty, *real_tty; in tty_ioctl() local
2101 tty = (struct tty_struct *)file->private_data; in tty_ioctl()
2102 if (tty_paranoia_check(tty, inode->i_rdev, "tty_ioctl")) in tty_ioctl()
2105 real_tty = tty; in tty_ioctl()
2106 if (tty->driver.type == TTY_DRIVER_TYPE_PTY && in tty_ioctl()
2107 tty->driver.subtype == PTY_TYPE_MASTER) in tty_ioctl()
2108 real_tty = tty->link; in tty_ioctl()
2113 if (!tty->driver.break_ctl) { in tty_ioctl()
2117 if (tty->driver.ioctl) in tty_ioctl()
2118 return tty->driver.ioctl(tty, file, cmd, arg); in tty_ioctl()
2126 if (tty->driver.ioctl) in tty_ioctl()
2127 retval = tty->driver.ioctl(tty, file, cmd, arg); in tty_ioctl()
2130 retval = tty_generic_brk(tty, file, cmd, arg); in tty_ioctl()
2144 retval = tty_check_change(tty); in tty_ioctl()
2148 tty_wait_until_sent(tty, 0); in tty_ioctl()
2157 return tiocsti(tty, (char *)arg); in tty_ioctl()
2159 return tiocgwinsz(tty, (struct winsize *) arg); in tty_ioctl()
2161 return tiocswinsz(tty, real_tty, (struct winsize *) arg); in tty_ioctl()
2163 return real_tty!=tty ? -EINVAL : tioccons(inode, file); in tty_ioctl()
2167 set_bit(TTY_EXCLUSIVE, &tty->flags); in tty_ioctl()
2170 clear_bit(TTY_EXCLUSIVE, &tty->flags); in tty_ioctl()
2173 if (current->tty != tty) in tty_ioctl()
2178 current->tty = NULL; in tty_ioctl()
2182 return tiocsctty(tty, arg); in tty_ioctl()
2184 return tiocgpgrp(tty, real_tty, (pid_t *) arg); in tty_ioctl()
2186 return tiocspgrp(tty, real_tty, (pid_t *) arg); in tty_ioctl()
2188 return tiocgsid(tty, real_tty, (pid_t *) arg); in tty_ioctl()
2191 return put_user(tty->ldisc.num, (int *) arg); in tty_ioctl()
2193 return tiocsetd(tty, (int *) arg); in tty_ioctl()
2196 return tioclinux(tty, arg); in tty_ioctl()
2199 return tiocttygstruct(tty, (struct tty_struct *) arg); in tty_ioctl()
2205 tty->driver.break_ctl(tty, -1); in tty_ioctl()
2209 tty->driver.break_ctl(tty, 0); in tty_ioctl()
2218 return send_break(tty, HZ/4); in tty_ioctl()
2221 return send_break(tty, arg ? arg*(HZ/10) : HZ/4); in tty_ioctl()
2223 if (tty->driver.ioctl) { in tty_ioctl()
2224 retval = (tty->driver.ioctl)(tty, file, cmd, arg); in tty_ioctl()
2228 ld = tty_ldisc_ref_wait(tty); in tty_ioctl()
2231 retval = ld->ioctl(tty, file, cmd, arg); in tty_ioctl()
2262 tty_hangup(tty); in __do_SAK()
2264 struct tty_struct *tty = arg; in __do_SAK()
2271 if (!tty) in __do_SAK()
2273 session = tty->session; in __do_SAK()
2275 disc = tty_ldisc_ref(tty); in __do_SAK()
2277 disc->flush_buffer(tty); in __do_SAK()
2280 if (tty->driver.flush_buffer) in __do_SAK()
2281 tty->driver.flush_buffer(tty); in __do_SAK()
2285 if ((p->tty == tty) || in __do_SAK()
2296 (filp->private_data == tty)) { in __do_SAK()
2316 void do_SAK(struct tty_struct *tty) in do_SAK() argument
2318 if (!tty) in do_SAK()
2320 PREPARE_TQUEUE(&tty->SAK_tq, __do_SAK, tty); in do_SAK()
2321 schedule_task(&tty->SAK_tq); in do_SAK()
2330 struct tty_struct *tty = (struct tty_struct *) private_; in flush_to_ldisc() local
2337 disc = tty_ldisc_ref(tty); in flush_to_ldisc()
2341 if (test_bit(TTY_DONT_FLIP, &tty->flags)) { in flush_to_ldisc()
2342 queue_task(&tty->flip.tqueue, &tq_timer); in flush_to_ldisc()
2345 if (tty->flip.buf_num) { in flush_to_ldisc()
2346 cp = tty->flip.char_buf + TTY_FLIPBUF_SIZE; in flush_to_ldisc()
2347 fp = tty->flip.flag_buf + TTY_FLIPBUF_SIZE; in flush_to_ldisc()
2348 tty->flip.buf_num = 0; in flush_to_ldisc()
2351 tty->flip.char_buf_ptr = tty->flip.char_buf; in flush_to_ldisc()
2352 tty->flip.flag_buf_ptr = tty->flip.flag_buf; in flush_to_ldisc()
2354 cp = tty->flip.char_buf; in flush_to_ldisc()
2355 fp = tty->flip.flag_buf; in flush_to_ldisc()
2356 tty->flip.buf_num = 1; in flush_to_ldisc()
2359 tty->flip.char_buf_ptr = tty->flip.char_buf + TTY_FLIPBUF_SIZE; in flush_to_ldisc()
2360 tty->flip.flag_buf_ptr = tty->flip.flag_buf + TTY_FLIPBUF_SIZE; in flush_to_ldisc()
2362 count = tty->flip.count; in flush_to_ldisc()
2363 tty->flip.count = 0; in flush_to_ldisc()
2366 disc->receive_buf(tty, cp, fp, count); in flush_to_ldisc()
2376 int tty_push_data(struct tty_struct *tty, unsigned char *cp, unsigned char *fp, int count) in tty_push_data() argument
2381 disc = tty_ldisc_ref(tty); in tty_push_data()
2382 if(test_bit(TTY_DONT_FLIP, &tty->flags)) in tty_push_data()
2387 disc->receive_buf(tty, cp, fp, count); in tty_push_data()
2412 int tty_get_baud_rate(struct tty_struct *tty) in tty_get_baud_rate() argument
2416 cflag = tty->termios->c_cflag; in tty_get_baud_rate()
2422 tty->termios->c_cflag &= ~CBAUDEX; in tty_get_baud_rate()
2426 if (i==15 && tty->alt_speed) { in tty_get_baud_rate()
2427 if (!tty->warned) { in tty_get_baud_rate()
2430 tty->warned = 1; in tty_get_baud_rate()
2432 return(tty->alt_speed); in tty_get_baud_rate()
2438 void tty_flip_buffer_push(struct tty_struct *tty) in tty_flip_buffer_push() argument
2440 if (tty->low_latency) in tty_flip_buffer_push()
2441 flush_to_ldisc((void *) tty); in tty_flip_buffer_push()
2443 queue_task(&tty->flip.tqueue, &tq_timer); in tty_flip_buffer_push()
2449 static void initialize_tty_struct(struct tty_struct *tty) in initialize_tty_struct() argument
2451 memset(tty, 0, sizeof(struct tty_struct)); in initialize_tty_struct()
2452 tty->magic = TTY_MAGIC; in initialize_tty_struct()
2453 tty_ldisc_assign(tty, tty_ldisc_get(N_TTY)); in initialize_tty_struct()
2454 tty->pgrp = -1; in initialize_tty_struct()
2455 tty->flip.char_buf_ptr = tty->flip.char_buf; in initialize_tty_struct()
2456 tty->flip.flag_buf_ptr = tty->flip.flag_buf; in initialize_tty_struct()
2457 tty->flip.tqueue.routine = flush_to_ldisc; in initialize_tty_struct()
2458 tty->flip.tqueue.data = tty; in initialize_tty_struct()
2459 init_MUTEX(&tty->flip.pty_sem); in initialize_tty_struct()
2460 init_MUTEX(&tty->termios_sem); in initialize_tty_struct()
2461 init_waitqueue_head(&tty->write_wait); in initialize_tty_struct()
2462 init_waitqueue_head(&tty->read_wait); in initialize_tty_struct()
2463 tty->tq_hangup.routine = do_tty_hangup; in initialize_tty_struct()
2464 tty->tq_hangup.data = tty; in initialize_tty_struct()
2465 sema_init(&tty->atomic_read, 1); in initialize_tty_struct()
2466 sema_init(&tty->atomic_write, 1); in initialize_tty_struct()
2467 spin_lock_init(&tty->read_lock); in initialize_tty_struct()
2468 INIT_LIST_HEAD(&tty->tty_files); in initialize_tty_struct()
2469 INIT_TQUEUE(&tty->SAK_tq, 0, 0); in initialize_tty_struct()
2475 void tty_default_put_char(struct tty_struct *tty, unsigned char ch) in tty_default_put_char() argument
2477 tty->driver.write(tty, 0, &ch, 1); in tty_default_put_char()