Lines Matching refs:tty
36 # define tty_debug_hangup(tty, f, args...) tty_debug(tty, f, ##args) argument
38 # define tty_debug_hangup(tty, f, args...) do {} while (0) argument
47 static void pty_close(struct tty_struct *tty, struct file *filp) in pty_close() argument
49 if (tty->driver->subtype == PTY_TYPE_MASTER) in pty_close()
50 WARN_ON(tty->count > 1); in pty_close()
52 if (tty_io_error(tty)) in pty_close()
54 if (tty->count > 2) in pty_close()
57 set_bit(TTY_IO_ERROR, &tty->flags); in pty_close()
58 wake_up_interruptible(&tty->read_wait); in pty_close()
59 wake_up_interruptible(&tty->write_wait); in pty_close()
60 spin_lock_irq(&tty->ctrl.lock); in pty_close()
61 tty->ctrl.packet = false; in pty_close()
62 spin_unlock_irq(&tty->ctrl.lock); in pty_close()
64 if (!tty->link) in pty_close()
66 set_bit(TTY_OTHER_CLOSED, &tty->link->flags); in pty_close()
67 wake_up_interruptible(&tty->link->read_wait); in pty_close()
68 wake_up_interruptible(&tty->link->write_wait); in pty_close()
69 if (tty->driver->subtype == PTY_TYPE_MASTER) { in pty_close()
70 set_bit(TTY_OTHER_CLOSED, &tty->flags); in pty_close()
72 if (tty->driver == ptm_driver) { in pty_close()
74 if (tty->link->driver_data) in pty_close()
75 devpts_pty_kill(tty->link->driver_data); in pty_close()
79 tty_vhangup(tty->link); in pty_close()
93 static void pty_unthrottle(struct tty_struct *tty) in pty_unthrottle() argument
95 tty_wakeup(tty->link); in pty_unthrottle()
96 set_bit(TTY_THROTTLED, &tty->flags); in pty_unthrottle()
111 static int pty_write(struct tty_struct *tty, const unsigned char *buf, int c) in pty_write() argument
113 struct tty_struct *to = tty->link; in pty_write()
116 if (tty->flow.stopped) in pty_write()
139 static unsigned int pty_write_room(struct tty_struct *tty) in pty_write_room() argument
141 if (tty->flow.stopped) in pty_write_room()
143 return tty_buffer_space_avail(tty->link->port); in pty_write_room()
147 static int pty_set_lock(struct tty_struct *tty, int __user *arg) in pty_set_lock() argument
154 set_bit(TTY_PTY_LOCK, &tty->flags); in pty_set_lock()
156 clear_bit(TTY_PTY_LOCK, &tty->flags); in pty_set_lock()
160 static int pty_get_lock(struct tty_struct *tty, int __user *arg) in pty_get_lock() argument
162 int locked = test_bit(TTY_PTY_LOCK, &tty->flags); in pty_get_lock()
168 static int pty_set_pktmode(struct tty_struct *tty, int __user *arg) in pty_set_pktmode() argument
175 spin_lock_irq(&tty->ctrl.lock); in pty_set_pktmode()
177 if (!tty->ctrl.packet) { in pty_set_pktmode()
178 tty->link->ctrl.pktstatus = 0; in pty_set_pktmode()
180 tty->ctrl.packet = true; in pty_set_pktmode()
183 tty->ctrl.packet = false; in pty_set_pktmode()
184 spin_unlock_irq(&tty->ctrl.lock); in pty_set_pktmode()
190 static int pty_get_pktmode(struct tty_struct *tty, int __user *arg) in pty_get_pktmode() argument
192 int pktmode = tty->ctrl.packet; in pty_get_pktmode()
198 static int pty_signal(struct tty_struct *tty, int sig) in pty_signal() argument
205 if (tty->link) { in pty_signal()
206 pgrp = tty_get_pgrp(tty->link); in pty_signal()
214 static void pty_flush_buffer(struct tty_struct *tty) in pty_flush_buffer() argument
216 struct tty_struct *to = tty->link; in pty_flush_buffer()
223 spin_lock_irq(&tty->ctrl.lock); in pty_flush_buffer()
224 tty->ctrl.pktstatus |= TIOCPKT_FLUSHWRITE; in pty_flush_buffer()
226 spin_unlock_irq(&tty->ctrl.lock); in pty_flush_buffer()
230 static int pty_open(struct tty_struct *tty, struct file *filp) in pty_open() argument
232 if (!tty || !tty->link) in pty_open()
235 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) in pty_open()
237 if (test_bit(TTY_PTY_LOCK, &tty->link->flags)) in pty_open()
239 if (tty->driver->subtype == PTY_TYPE_SLAVE && tty->link->count != 1) in pty_open()
242 clear_bit(TTY_IO_ERROR, &tty->flags); in pty_open()
243 clear_bit(TTY_OTHER_CLOSED, &tty->link->flags); in pty_open()
244 set_bit(TTY_THROTTLED, &tty->flags); in pty_open()
248 set_bit(TTY_IO_ERROR, &tty->flags); in pty_open()
252 static void pty_set_termios(struct tty_struct *tty, in pty_set_termios() argument
256 if (tty->link && tty->link->ctrl.packet) { in pty_set_termios()
257 int extproc = (old_termios->c_lflag & EXTPROC) | L_EXTPROC(tty); in pty_set_termios()
261 int new_flow = (I_IXON(tty) && in pty_set_termios()
262 STOP_CHAR(tty) == '\023' && in pty_set_termios()
263 START_CHAR(tty) == '\021'); in pty_set_termios()
265 spin_lock_irq(&tty->ctrl.lock); in pty_set_termios()
267 tty->ctrl.pktstatus &= ~(TIOCPKT_DOSTOP | TIOCPKT_NOSTOP); in pty_set_termios()
269 tty->ctrl.pktstatus |= TIOCPKT_DOSTOP; in pty_set_termios()
271 tty->ctrl.pktstatus |= TIOCPKT_NOSTOP; in pty_set_termios()
274 tty->ctrl.pktstatus |= TIOCPKT_IOCTL; in pty_set_termios()
275 spin_unlock_irq(&tty->ctrl.lock); in pty_set_termios()
276 wake_up_interruptible(&tty->link->read_wait); in pty_set_termios()
280 tty->termios.c_cflag &= ~(CSIZE | PARENB); in pty_set_termios()
281 tty->termios.c_cflag |= (CS8 | CREAD); in pty_set_termios()
293 static int pty_resize(struct tty_struct *tty, struct winsize *ws) in pty_resize() argument
296 struct tty_struct *pty = tty->link; in pty_resize()
299 mutex_lock(&tty->winsize_mutex); in pty_resize()
300 if (!memcmp(ws, &tty->winsize, sizeof(*ws))) in pty_resize()
304 pgrp = tty_get_pgrp(tty); in pty_resize()
315 tty->winsize = *ws; in pty_resize()
318 mutex_unlock(&tty->winsize_mutex); in pty_resize()
332 static void pty_start(struct tty_struct *tty) in pty_start() argument
336 if (tty->link && tty->link->ctrl.packet) { in pty_start()
337 spin_lock_irqsave(&tty->ctrl.lock, flags); in pty_start()
338 tty->ctrl.pktstatus &= ~TIOCPKT_STOP; in pty_start()
339 tty->ctrl.pktstatus |= TIOCPKT_START; in pty_start()
340 spin_unlock_irqrestore(&tty->ctrl.lock, flags); in pty_start()
341 wake_up_interruptible_poll(&tty->link->read_wait, EPOLLIN); in pty_start()
345 static void pty_stop(struct tty_struct *tty) in pty_stop() argument
349 if (tty->link && tty->link->ctrl.packet) { in pty_stop()
350 spin_lock_irqsave(&tty->ctrl.lock, flags); in pty_stop()
351 tty->ctrl.pktstatus &= ~TIOCPKT_START; in pty_stop()
352 tty->ctrl.pktstatus |= TIOCPKT_STOP; in pty_stop()
353 spin_unlock_irqrestore(&tty->ctrl.lock, flags); in pty_stop()
354 wake_up_interruptible_poll(&tty->link->read_wait, EPOLLIN); in pty_stop()
369 static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty, in pty_common_install() argument
374 int idx = tty->index; in pty_common_install()
399 tty_init_termios(tty); in pty_common_install()
403 driver->ttys[idx] = tty; in pty_common_install()
405 memset(&tty->termios_locked, 0, sizeof(tty->termios_locked)); in pty_common_install()
406 tty->termios = driver->init_termios; in pty_common_install()
407 memset(&o_tty->termios_locked, 0, sizeof(tty->termios_locked)); in pty_common_install()
416 tty->link = o_tty; in pty_common_install()
417 o_tty->link = tty; in pty_common_install()
423 tty->port = ports[1]; in pty_common_install()
429 tty->count++; in pty_common_install()
441 static void pty_cleanup(struct tty_struct *tty) in pty_cleanup() argument
443 tty_port_put(tty->port); in pty_cleanup()
449 static int pty_install(struct tty_driver *driver, struct tty_struct *tty) in pty_install() argument
451 return pty_common_install(driver, tty, true); in pty_install()
454 static void pty_remove(struct tty_driver *driver, struct tty_struct *tty) in pty_remove() argument
456 struct tty_struct *pair = tty->link; in pty_remove()
458 driver->ttys[tty->index] = NULL; in pty_remove()
463 static int pty_bsd_ioctl(struct tty_struct *tty, in pty_bsd_ioctl() argument
468 return pty_set_lock(tty, (int __user *) arg); in pty_bsd_ioctl()
470 return pty_get_lock(tty, (int __user *)arg); in pty_bsd_ioctl()
472 return pty_set_pktmode(tty, (int __user *)arg); in pty_bsd_ioctl()
474 return pty_get_pktmode(tty, (int __user *)arg); in pty_bsd_ioctl()
476 return pty_signal(tty, (int) arg); in pty_bsd_ioctl()
484 static long pty_bsd_compat_ioctl(struct tty_struct *tty, in pty_bsd_compat_ioctl() argument
491 return pty_bsd_ioctl(tty, cmd, (unsigned long)compat_ptr(arg)); in pty_bsd_compat_ioctl()
612 int ptm_open_peer(struct file *master, struct tty_struct *tty, int flags) in ptm_open_peer() argument
619 if (tty->driver != ptm_driver) in ptm_open_peer()
629 path.mnt = devpts_mntget(master, tty->driver_data); in ptm_open_peer()
634 path.dentry = tty->link->driver_data; in ptm_open_peer()
652 static int pty_unix98_ioctl(struct tty_struct *tty, in pty_unix98_ioctl() argument
657 return pty_set_lock(tty, (int __user *)arg); in pty_unix98_ioctl()
659 return pty_get_lock(tty, (int __user *)arg); in pty_unix98_ioctl()
661 return pty_set_pktmode(tty, (int __user *)arg); in pty_unix98_ioctl()
663 return pty_get_pktmode(tty, (int __user *)arg); in pty_unix98_ioctl()
665 return put_user(tty->index, (unsigned int __user *)arg); in pty_unix98_ioctl()
667 return pty_signal(tty, (int) arg); in pty_unix98_ioctl()
674 static long pty_unix98_compat_ioctl(struct tty_struct *tty, in pty_unix98_compat_ioctl() argument
681 return pty_unix98_ioctl(tty, cmd, in pty_unix98_compat_ioctl()
718 struct tty_struct *tty; in pts_unix98_lookup() local
721 tty = devpts_get_priv(file->f_path.dentry); in pts_unix98_lookup()
724 if (!tty) in pts_unix98_lookup()
726 return tty; in pts_unix98_lookup()
729 static int pty_unix98_install(struct tty_driver *driver, struct tty_struct *tty) in pty_unix98_install() argument
731 return pty_common_install(driver, tty, false); in pty_unix98_install()
735 static void pty_unix98_remove(struct tty_driver *driver, struct tty_struct *tty) in pty_unix98_remove() argument
739 if (tty->driver->subtype == PTY_TYPE_MASTER) in pty_unix98_remove()
740 fsi = tty->driver_data; in pty_unix98_remove()
742 fsi = tty->link->driver_data; in pty_unix98_remove()
745 devpts_kill_index(fsi, tty->index); in pty_unix98_remove()
750 static void pty_show_fdinfo(struct tty_struct *tty, struct seq_file *m) in pty_show_fdinfo() argument
752 seq_printf(m, "tty-index:\t%d\n", tty->index); in pty_show_fdinfo()
803 struct tty_struct *tty; in ptmx_open() local
834 tty = tty_init_dev(ptm_driver, index); in ptmx_open()
839 retval = PTR_ERR(tty); in ptmx_open()
840 if (IS_ERR(tty)) in ptmx_open()
847 set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */ in ptmx_open()
848 tty->driver_data = fsi; in ptmx_open()
850 tty_add_file(tty, filp); in ptmx_open()
852 dentry = devpts_pty_new(fsi, index, tty->link); in ptmx_open()
857 tty->link->driver_data = dentry; in ptmx_open()
859 retval = ptm_driver->ops->open(tty, filp); in ptmx_open()
863 tty_debug_hangup(tty, "opening (count=%d)\n", tty->count); in ptmx_open()
865 tty_unlock(tty); in ptmx_open()
868 tty_unlock(tty); in ptmx_open()