Lines Matching full:tty

13 #include <linux/tty.h>
32 #include "tty.h"
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 scoped_guard(spinlock_irq, &tty->ctrl.lock) in pty_close()
61 tty->ctrl.packet = false; in pty_close()
63 if (!tty->link) in pty_close()
65 set_bit(TTY_OTHER_CLOSED, &tty->link->flags); in pty_close()
66 wake_up_interruptible(&tty->link->read_wait); in pty_close()
67 wake_up_interruptible(&tty->link->write_wait); in pty_close()
68 if (tty->driver->subtype == PTY_TYPE_MASTER) { in pty_close()
69 set_bit(TTY_OTHER_CLOSED, &tty->flags); in pty_close()
71 if (tty->driver == ptm_driver) { in pty_close()
73 if (tty->link->driver_data) in pty_close()
74 devpts_pty_kill(tty->link->driver_data); in pty_close()
77 tty_vhangup(tty->link); in pty_close()
91 static void pty_unthrottle(struct tty_struct *tty) in pty_unthrottle() argument
93 tty_wakeup(tty->link); in pty_unthrottle()
94 set_bit(TTY_THROTTLED, &tty->flags); in pty_unthrottle()
99 * @tty: the tty we write from
106 * the other side of the pty/tty pair.
109 static ssize_t pty_write(struct tty_struct *tty, const u8 *buf, size_t c) in pty_write() argument
111 struct tty_struct *to = tty->link; in pty_write()
113 if (tty->flow.stopped || !c) in pty_write()
121 * @tty: tty we are writing from
127 static unsigned int pty_write_room(struct tty_struct *tty) in pty_write_room() argument
129 if (tty->flow.stopped) in pty_write_room()
131 return tty_buffer_space_avail(tty->link->port); in pty_write_room()
135 static int pty_set_lock(struct tty_struct *tty, int __user *arg) in pty_set_lock() argument
142 set_bit(TTY_PTY_LOCK, &tty->flags); in pty_set_lock()
144 clear_bit(TTY_PTY_LOCK, &tty->flags); in pty_set_lock()
148 static int pty_get_lock(struct tty_struct *tty, int __user *arg) in pty_get_lock() argument
150 int locked = test_bit(TTY_PTY_LOCK, &tty->flags); in pty_get_lock()
156 static int pty_set_pktmode(struct tty_struct *tty, int __user *arg) in pty_set_pktmode() argument
163 guard(spinlock_irq)(&tty->ctrl.lock); in pty_set_pktmode()
165 tty->ctrl.packet = false; in pty_set_pktmode()
169 if (tty->ctrl.packet) in pty_set_pktmode()
172 tty->link->ctrl.pktstatus = 0; in pty_set_pktmode()
174 tty->ctrl.packet = true; in pty_set_pktmode()
180 static int pty_get_pktmode(struct tty_struct *tty, int __user *arg) in pty_get_pktmode() argument
182 int pktmode = tty->ctrl.packet; in pty_get_pktmode()
188 static int pty_signal(struct tty_struct *tty, int sig) in pty_signal() argument
195 if (tty->link) { in pty_signal()
196 pgrp = tty_get_pgrp(tty->link); in pty_signal()
204 static void pty_flush_buffer(struct tty_struct *tty) in pty_flush_buffer() argument
206 struct tty_struct *to = tty->link; in pty_flush_buffer()
213 guard(spinlock_irq)(&tty->ctrl.lock); in pty_flush_buffer()
214 tty->ctrl.pktstatus |= TIOCPKT_FLUSHWRITE; in pty_flush_buffer()
219 static int pty_open(struct tty_struct *tty, struct file *filp) in pty_open() argument
221 if (!tty || !tty->link) in pty_open()
224 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) in pty_open()
226 if (test_bit(TTY_PTY_LOCK, &tty->link->flags)) in pty_open()
228 if (tty->driver->subtype == PTY_TYPE_SLAVE && tty->link->count != 1) in pty_open()
231 clear_bit(TTY_IO_ERROR, &tty->flags); in pty_open()
232 clear_bit(TTY_OTHER_CLOSED, &tty->link->flags); in pty_open()
233 set_bit(TTY_THROTTLED, &tty->flags); in pty_open()
237 set_bit(TTY_IO_ERROR, &tty->flags); in pty_open()
241 static void pty_set_termios(struct tty_struct *tty, in pty_set_termios() argument
245 if (tty->link && tty->link->ctrl.packet) { in pty_set_termios()
246 int extproc = (old_termios->c_lflag & EXTPROC) | L_EXTPROC(tty); in pty_set_termios()
250 int new_flow = (I_IXON(tty) && in pty_set_termios()
251 STOP_CHAR(tty) == '\023' && in pty_set_termios()
252 START_CHAR(tty) == '\021'); in pty_set_termios()
254 scoped_guard(spinlock_irq, &tty->ctrl.lock) { in pty_set_termios()
256 tty->ctrl.pktstatus &= ~(TIOCPKT_DOSTOP | TIOCPKT_NOSTOP); in pty_set_termios()
258 tty->ctrl.pktstatus |= TIOCPKT_DOSTOP; in pty_set_termios()
260 tty->ctrl.pktstatus |= TIOCPKT_NOSTOP; in pty_set_termios()
263 tty->ctrl.pktstatus |= TIOCPKT_IOCTL; in pty_set_termios()
265 wake_up_interruptible(&tty->link->read_wait); in pty_set_termios()
269 tty->termios.c_cflag &= ~(CSIZE | PARENB); in pty_set_termios()
270 tty->termios.c_cflag |= (CS8 | CREAD); in pty_set_termios()
275 * @tty: tty being resized
282 static int pty_resize(struct tty_struct *tty, struct winsize *ws) in pty_resize() argument
285 struct tty_struct *pty = tty->link; in pty_resize()
287 /* For a PTY we need to lock the tty side */ in pty_resize()
288 guard(mutex)(&tty->winsize_mutex); in pty_resize()
289 if (!memcmp(ws, &tty->winsize, sizeof(*ws))) in pty_resize()
293 pgrp = tty_get_pgrp(tty); in pty_resize()
304 tty->winsize = *ws; in pty_resize()
313 * @tty: tty being flow-controlled
320 static void pty_start(struct tty_struct *tty) in pty_start() argument
322 if (!tty->link || !tty->link->ctrl.packet) in pty_start()
325 scoped_guard(spinlock_irqsave, &tty->ctrl.lock) { in pty_start()
326 tty->ctrl.pktstatus &= ~TIOCPKT_STOP; in pty_start()
327 tty->ctrl.pktstatus |= TIOCPKT_START; in pty_start()
329 wake_up_interruptible_poll(&tty->link->read_wait, EPOLLIN); in pty_start()
332 static void pty_stop(struct tty_struct *tty) in pty_stop() argument
334 if (!tty->link || !tty->link->ctrl.packet) in pty_stop()
337 scoped_guard(spinlock_irqsave, &tty->ctrl.lock) { in pty_stop()
338 tty->ctrl.pktstatus &= ~TIOCPKT_START; in pty_stop()
339 tty->ctrl.pktstatus |= TIOCPKT_STOP; in pty_stop()
341 wake_up_interruptible_poll(&tty->link->read_wait, EPOLLIN); in pty_stop()
347 * @tty: the tty being instantiated
350 * Perform the initial set up for the tty/pty pair. Called from the
351 * tty layer when the port is first opened.
355 static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty, in pty_common_install() argument
360 int idx = tty->index; in pty_common_install()
383 /* We always use new tty termios data so we can do this in pty_common_install()
385 tty_init_termios(tty); in pty_common_install()
389 driver->ttys[idx] = tty; in pty_common_install()
391 memset(&tty->termios_locked, 0, sizeof(tty->termios_locked)); in pty_common_install()
392 tty->termios = driver->init_termios; in pty_common_install()
393 memset(&o_tty->termios_locked, 0, sizeof(tty->termios_locked)); in pty_common_install()
402 tty->link = o_tty; in pty_common_install()
403 o_tty->link = tty; in pty_common_install()
409 tty->port = ports[1]; in pty_common_install()
415 tty->count++; in pty_common_install()
427 static void pty_cleanup(struct tty_struct *tty) in pty_cleanup() argument
429 tty_port_put(tty->port); in pty_cleanup()
435 static int pty_install(struct tty_driver *driver, struct tty_struct *tty) in pty_install() argument
437 return pty_common_install(driver, tty, true); in pty_install()
440 static void pty_remove(struct tty_driver *driver, struct tty_struct *tty) in pty_remove() argument
442 struct tty_struct *pair = tty->link; in pty_remove()
444 driver->ttys[tty->index] = NULL; in pty_remove()
449 static int pty_bsd_ioctl(struct tty_struct *tty, in pty_bsd_ioctl() argument
454 return pty_set_lock(tty, (int __user *) arg); in pty_bsd_ioctl()
456 return pty_get_lock(tty, (int __user *)arg); in pty_bsd_ioctl()
458 return pty_set_pktmode(tty, (int __user *)arg); in pty_bsd_ioctl()
460 return pty_get_pktmode(tty, (int __user *)arg); in pty_bsd_ioctl()
462 return pty_signal(tty, (int) arg); in pty_bsd_ioctl()
463 case TIOCGPTN: /* TTY returns ENOTTY, but glibc expects EINVAL here */ in pty_bsd_ioctl()
470 static long pty_bsd_compat_ioctl(struct tty_struct *tty, in pty_bsd_compat_ioctl() argument
477 return pty_bsd_ioctl(tty, cmd, (unsigned long)compat_ptr(arg)); in pty_bsd_compat_ioctl()
589 struct tty_struct *tty, int flags) in ptm_open_peer_file() argument
595 path.mnt = devpts_mntget(master, tty->driver_data); in ptm_open_peer_file()
598 path.dentry = tty->link->driver_data; in ptm_open_peer_file()
608 * @tty: the master of the pty being opened
615 int ptm_open_peer(struct file *master, struct tty_struct *tty, int flags) in ptm_open_peer() argument
617 if (tty->driver != ptm_driver) in ptm_open_peer()
620 return FD_ADD(flags, ptm_open_peer_file(master, tty, flags)); in ptm_open_peer()
623 static int pty_unix98_ioctl(struct tty_struct *tty, in pty_unix98_ioctl() argument
628 return pty_set_lock(tty, (int __user *)arg); in pty_unix98_ioctl()
630 return pty_get_lock(tty, (int __user *)arg); in pty_unix98_ioctl()
632 return pty_set_pktmode(tty, (int __user *)arg); in pty_unix98_ioctl()
634 return pty_get_pktmode(tty, (int __user *)arg); in pty_unix98_ioctl()
636 return put_user(tty->index, (unsigned int __user *)arg); in pty_unix98_ioctl()
638 return pty_signal(tty, (int) arg); in pty_unix98_ioctl()
645 static long pty_unix98_compat_ioctl(struct tty_struct *tty, in pty_unix98_compat_ioctl() argument
652 return pty_unix98_ioctl(tty, cmd, in pty_unix98_compat_ioctl()
663 * @idx: tty index
679 * @file: file pointer to tty
680 * @idx: tty index
683 * This provides our locking for the tty pointer.
694 static int pty_unix98_install(struct tty_driver *driver, struct tty_struct *tty) in pty_unix98_install() argument
696 return pty_common_install(driver, tty, false); in pty_unix98_install()
700 static void pty_unix98_remove(struct tty_driver *driver, struct tty_struct *tty) in pty_unix98_remove() argument
704 if (tty->driver->subtype == PTY_TYPE_MASTER) in pty_unix98_remove()
705 fsi = tty->driver_data; in pty_unix98_remove()
707 fsi = tty->link->driver_data; in pty_unix98_remove()
710 devpts_kill_index(fsi, tty->index); in pty_unix98_remove()
715 static void pty_show_fdinfo(struct tty_struct *tty, struct seq_file *m) in pty_show_fdinfo() argument
717 seq_printf(m, "tty-index:\t%d\n", tty->index); in pty_show_fdinfo()
756 * @filp: file pointer to tty
760 * Locking: tty_mutex protects the init_dev work. tty->count should
768 struct tty_struct *tty; in ptmx_open() local
797 /* The tty returned here is locked so we can safely drop the mutex */ in ptmx_open()
799 tty = tty_init_dev(ptm_driver, index); in ptmx_open()
801 retval = PTR_ERR(tty); in ptmx_open()
802 if (IS_ERR(tty)) in ptmx_open()
806 * From here on out, the tty is "live", and the index and in ptmx_open()
809 set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */ in ptmx_open()
810 tty->driver_data = fsi; in ptmx_open()
812 tty_add_file(tty, filp); in ptmx_open()
814 dentry = devpts_pty_new(fsi, index, tty->link); in ptmx_open()
819 tty->link->driver_data = dentry; in ptmx_open()
821 retval = ptm_driver->ops->open(tty, filp); in ptmx_open()
825 tty_debug_hangup(tty, "opening (count=%d)\n", tty->count); in ptmx_open()
827 tty_unlock(tty); in ptmx_open()
830 tty_unlock(tty); in ptmx_open()