Lines Matching refs:tty
34 # define tty_debug_hangup(tty, f, args...) tty_debug(tty, f, ##args) argument
36 # define tty_debug_hangup(tty, f, args...) do {} while (0) argument
45 static void pty_close(struct tty_struct *tty, struct file *filp) in pty_close() argument
47 BUG_ON(!tty); in pty_close()
48 if (tty->driver->subtype == PTY_TYPE_MASTER) in pty_close()
49 WARN_ON(tty->count > 1); in pty_close()
51 if (tty_io_error(tty)) in pty_close()
53 if (tty->count > 2) in pty_close()
56 set_bit(TTY_IO_ERROR, &tty->flags); in pty_close()
57 wake_up_interruptible(&tty->read_wait); in pty_close()
58 wake_up_interruptible(&tty->write_wait); in pty_close()
59 spin_lock_irq(&tty->ctrl_lock); in pty_close()
60 tty->packet = 0; in pty_close()
61 spin_unlock_irq(&tty->ctrl_lock); 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()
78 tty_vhangup(tty->link); in pty_close()
92 static void pty_unthrottle(struct tty_struct *tty) in pty_unthrottle() argument
94 tty_wakeup(tty->link); in pty_unthrottle()
95 set_bit(TTY_THROTTLED, &tty->flags); in pty_unthrottle()
110 static int pty_write(struct tty_struct *tty, const unsigned char *buf, int c) in pty_write() argument
112 struct tty_struct *to = tty->link; in pty_write()
115 if (tty->stopped) in pty_write()
138 static int pty_write_room(struct tty_struct *tty) in pty_write_room() argument
140 if (tty->stopped) in pty_write_room()
142 return tty_buffer_space_avail(tty->link->port); in pty_write_room()
153 static int pty_chars_in_buffer(struct tty_struct *tty) in pty_chars_in_buffer() argument
159 static int pty_set_lock(struct tty_struct *tty, int __user *arg) in pty_set_lock() argument
165 set_bit(TTY_PTY_LOCK, &tty->flags); in pty_set_lock()
167 clear_bit(TTY_PTY_LOCK, &tty->flags); in pty_set_lock()
171 static int pty_get_lock(struct tty_struct *tty, int __user *arg) in pty_get_lock() argument
173 int locked = test_bit(TTY_PTY_LOCK, &tty->flags); in pty_get_lock()
178 static int pty_set_pktmode(struct tty_struct *tty, int __user *arg) in pty_set_pktmode() argument
185 spin_lock_irq(&tty->ctrl_lock); in pty_set_pktmode()
187 if (!tty->packet) { in pty_set_pktmode()
188 tty->link->ctrl_status = 0; in pty_set_pktmode()
190 tty->packet = 1; in pty_set_pktmode()
193 tty->packet = 0; in pty_set_pktmode()
194 spin_unlock_irq(&tty->ctrl_lock); in pty_set_pktmode()
200 static int pty_get_pktmode(struct tty_struct *tty, int __user *arg) in pty_get_pktmode() argument
202 int pktmode = tty->packet; in pty_get_pktmode()
207 static int pty_signal(struct tty_struct *tty, int sig) in pty_signal() argument
214 if (tty->link) { in pty_signal()
215 pgrp = tty_get_pgrp(tty->link); in pty_signal()
223 static void pty_flush_buffer(struct tty_struct *tty) in pty_flush_buffer() argument
225 struct tty_struct *to = tty->link; in pty_flush_buffer()
232 spin_lock_irq(&tty->ctrl_lock); in pty_flush_buffer()
233 tty->ctrl_status |= TIOCPKT_FLUSHWRITE; in pty_flush_buffer()
235 spin_unlock_irq(&tty->ctrl_lock); in pty_flush_buffer()
239 static int pty_open(struct tty_struct *tty, struct file *filp) in pty_open() argument
241 if (!tty || !tty->link) in pty_open()
244 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) in pty_open()
246 if (test_bit(TTY_PTY_LOCK, &tty->link->flags)) in pty_open()
248 if (tty->driver->subtype == PTY_TYPE_SLAVE && tty->link->count != 1) in pty_open()
251 clear_bit(TTY_IO_ERROR, &tty->flags); in pty_open()
252 clear_bit(TTY_OTHER_CLOSED, &tty->link->flags); in pty_open()
253 set_bit(TTY_THROTTLED, &tty->flags); in pty_open()
257 set_bit(TTY_IO_ERROR, &tty->flags); in pty_open()
261 static void pty_set_termios(struct tty_struct *tty, in pty_set_termios() argument
265 if (tty->link && tty->link->packet) { in pty_set_termios()
266 int extproc = (old_termios->c_lflag & EXTPROC) | L_EXTPROC(tty); in pty_set_termios()
270 int new_flow = (I_IXON(tty) && in pty_set_termios()
271 STOP_CHAR(tty) == '\023' && in pty_set_termios()
272 START_CHAR(tty) == '\021'); in pty_set_termios()
274 spin_lock_irq(&tty->ctrl_lock); in pty_set_termios()
276 tty->ctrl_status &= ~(TIOCPKT_DOSTOP | TIOCPKT_NOSTOP); in pty_set_termios()
278 tty->ctrl_status |= TIOCPKT_DOSTOP; in pty_set_termios()
280 tty->ctrl_status |= TIOCPKT_NOSTOP; in pty_set_termios()
283 tty->ctrl_status |= TIOCPKT_IOCTL; in pty_set_termios()
284 spin_unlock_irq(&tty->ctrl_lock); in pty_set_termios()
285 wake_up_interruptible(&tty->link->read_wait); in pty_set_termios()
289 tty->termios.c_cflag &= ~(CSIZE | PARENB); in pty_set_termios()
290 tty->termios.c_cflag |= (CS8 | CREAD); in pty_set_termios()
302 static int pty_resize(struct tty_struct *tty, struct winsize *ws) in pty_resize() argument
305 struct tty_struct *pty = tty->link; in pty_resize()
308 mutex_lock(&tty->winsize_mutex); in pty_resize()
309 if (!memcmp(ws, &tty->winsize, sizeof(*ws))) in pty_resize()
313 pgrp = tty_get_pgrp(tty); in pty_resize()
324 tty->winsize = *ws; in pty_resize()
327 mutex_unlock(&tty->winsize_mutex); in pty_resize()
341 static void pty_start(struct tty_struct *tty) in pty_start() argument
345 if (tty->link && tty->link->packet) { in pty_start()
346 spin_lock_irqsave(&tty->ctrl_lock, flags); in pty_start()
347 tty->ctrl_status &= ~TIOCPKT_STOP; in pty_start()
348 tty->ctrl_status |= TIOCPKT_START; in pty_start()
349 spin_unlock_irqrestore(&tty->ctrl_lock, flags); in pty_start()
350 wake_up_interruptible_poll(&tty->link->read_wait, EPOLLIN); in pty_start()
354 static void pty_stop(struct tty_struct *tty) in pty_stop() argument
358 if (tty->link && tty->link->packet) { in pty_stop()
359 spin_lock_irqsave(&tty->ctrl_lock, flags); in pty_stop()
360 tty->ctrl_status &= ~TIOCPKT_START; in pty_stop()
361 tty->ctrl_status |= TIOCPKT_STOP; in pty_stop()
362 spin_unlock_irqrestore(&tty->ctrl_lock, flags); in pty_stop()
363 wake_up_interruptible_poll(&tty->link->read_wait, EPOLLIN); in pty_stop()
378 static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty, in pty_common_install() argument
383 int idx = tty->index; in pty_common_install()
408 tty_init_termios(tty); in pty_common_install()
412 driver->ttys[idx] = tty; in pty_common_install()
414 memset(&tty->termios_locked, 0, sizeof(tty->termios_locked)); in pty_common_install()
415 tty->termios = driver->init_termios; in pty_common_install()
416 memset(&o_tty->termios_locked, 0, sizeof(tty->termios_locked)); in pty_common_install()
425 tty->link = o_tty; in pty_common_install()
426 o_tty->link = tty; in pty_common_install()
432 tty->port = ports[1]; in pty_common_install()
438 tty->count++; in pty_common_install()
450 static void pty_cleanup(struct tty_struct *tty) in pty_cleanup() argument
452 tty_port_put(tty->port); in pty_cleanup()
458 static int pty_install(struct tty_driver *driver, struct tty_struct *tty) in pty_install() argument
460 return pty_common_install(driver, tty, true); in pty_install()
463 static void pty_remove(struct tty_driver *driver, struct tty_struct *tty) in pty_remove() argument
465 struct tty_struct *pair = tty->link; in pty_remove()
466 driver->ttys[tty->index] = NULL; in pty_remove()
471 static int pty_bsd_ioctl(struct tty_struct *tty, in pty_bsd_ioctl() argument
476 return pty_set_lock(tty, (int __user *) arg); in pty_bsd_ioctl()
478 return pty_get_lock(tty, (int __user *)arg); in pty_bsd_ioctl()
480 return pty_set_pktmode(tty, (int __user *)arg); in pty_bsd_ioctl()
482 return pty_get_pktmode(tty, (int __user *)arg); in pty_bsd_ioctl()
484 return pty_signal(tty, (int) arg); in pty_bsd_ioctl()
491 static long pty_bsd_compat_ioctl(struct tty_struct *tty, in pty_bsd_compat_ioctl() argument
498 return pty_bsd_ioctl(tty, cmd, arg); in pty_bsd_compat_ioctl()
618 int ptm_open_peer(struct file *master, struct tty_struct *tty, int flags) in ptm_open_peer() argument
625 if (tty->driver != ptm_driver) in ptm_open_peer()
635 path.mnt = devpts_mntget(master, tty->driver_data); in ptm_open_peer()
640 path.dentry = tty->link->driver_data; in ptm_open_peer()
658 static int pty_unix98_ioctl(struct tty_struct *tty, in pty_unix98_ioctl() argument
663 return pty_set_lock(tty, (int __user *)arg); in pty_unix98_ioctl()
665 return pty_get_lock(tty, (int __user *)arg); in pty_unix98_ioctl()
667 return pty_set_pktmode(tty, (int __user *)arg); in pty_unix98_ioctl()
669 return pty_get_pktmode(tty, (int __user *)arg); in pty_unix98_ioctl()
671 return put_user(tty->index, (unsigned int __user *)arg); in pty_unix98_ioctl()
673 return pty_signal(tty, (int) arg); in pty_unix98_ioctl()
679 static long pty_unix98_compat_ioctl(struct tty_struct *tty, in pty_unix98_compat_ioctl() argument
686 return pty_unix98_ioctl(tty, cmd, arg); in pty_unix98_compat_ioctl()
717 struct tty_struct *tty; in pts_unix98_lookup() local
720 tty = devpts_get_priv(file->f_path.dentry); in pts_unix98_lookup()
723 if (!tty) in pts_unix98_lookup()
725 return tty; in pts_unix98_lookup()
728 static int pty_unix98_install(struct tty_driver *driver, struct tty_struct *tty) in pty_unix98_install() argument
730 return pty_common_install(driver, tty, false); in pty_unix98_install()
734 static void pty_unix98_remove(struct tty_driver *driver, struct tty_struct *tty) in pty_unix98_remove() argument
738 if (tty->driver->subtype == PTY_TYPE_MASTER) in pty_unix98_remove()
739 fsi = tty->driver_data; in pty_unix98_remove()
741 fsi = tty->link->driver_data; in pty_unix98_remove()
744 devpts_kill_index(fsi, tty->index); in pty_unix98_remove()
749 static void pty_show_fdinfo(struct tty_struct *tty, struct seq_file *m) in pty_show_fdinfo() argument
751 seq_printf(m, "tty-index:\t%d\n", tty->index); in pty_show_fdinfo()
804 struct tty_struct *tty; in ptmx_open() local
835 tty = tty_init_dev(ptm_driver, index); in ptmx_open()
840 retval = PTR_ERR(tty); in ptmx_open()
841 if (IS_ERR(tty)) in ptmx_open()
848 set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */ in ptmx_open()
849 tty->driver_data = fsi; in ptmx_open()
851 tty_add_file(tty, filp); in ptmx_open()
853 dentry = devpts_pty_new(fsi, index, tty->link); in ptmx_open()
858 tty->link->driver_data = dentry; in ptmx_open()
860 retval = ptm_driver->ops->open(tty, filp); in ptmx_open()
864 tty_debug_hangup(tty, "opening (count=%d)\n", tty->count); in ptmx_open()
866 tty_unlock(tty); in ptmx_open()
869 tty_unlock(tty); in ptmx_open()