Lines Matching refs:tty
36 static void pty_close(struct tty_struct *tty, struct file *filp) in pty_close() argument
38 BUG_ON(!tty); in pty_close()
39 if (tty->driver->subtype == PTY_TYPE_MASTER) in pty_close()
40 WARN_ON(tty->count > 1); in pty_close()
42 if (test_bit(TTY_IO_ERROR, &tty->flags)) in pty_close()
44 if (tty->count > 2) in pty_close()
47 set_bit(TTY_IO_ERROR, &tty->flags); in pty_close()
48 wake_up_interruptible(&tty->read_wait); in pty_close()
49 wake_up_interruptible(&tty->write_wait); in pty_close()
50 spin_lock_irq(&tty->ctrl_lock); in pty_close()
51 tty->packet = 0; in pty_close()
52 spin_unlock_irq(&tty->ctrl_lock); in pty_close()
54 if (!tty->link) in pty_close()
56 set_bit(TTY_OTHER_CLOSED, &tty->link->flags); in pty_close()
57 wake_up_interruptible(&tty->link->read_wait); in pty_close()
58 wake_up_interruptible(&tty->link->write_wait); in pty_close()
59 if (tty->driver->subtype == PTY_TYPE_MASTER) { in pty_close()
60 set_bit(TTY_OTHER_CLOSED, &tty->flags); in pty_close()
62 if (tty->driver == ptm_driver) { in pty_close()
64 if (tty->link->driver_data) in pty_close()
65 devpts_pty_kill(tty->link->driver_data); in pty_close()
69 tty_vhangup(tty->link); in pty_close()
83 static void pty_unthrottle(struct tty_struct *tty) in pty_unthrottle() argument
85 tty_wakeup(tty->link); in pty_unthrottle()
86 set_bit(TTY_THROTTLED, &tty->flags); in pty_unthrottle()
101 static int pty_write(struct tty_struct *tty, const unsigned char *buf, int c) in pty_write() argument
103 struct tty_struct *to = tty->link; in pty_write()
105 if (tty->stopped) in pty_write()
126 static int pty_write_room(struct tty_struct *tty) in pty_write_room() argument
128 if (tty->stopped) in pty_write_room()
130 return tty_buffer_space_avail(tty->link->port); in pty_write_room()
141 static int pty_chars_in_buffer(struct tty_struct *tty) in pty_chars_in_buffer() argument
147 static int pty_set_lock(struct tty_struct *tty, int __user *arg) in pty_set_lock() argument
153 set_bit(TTY_PTY_LOCK, &tty->flags); in pty_set_lock()
155 clear_bit(TTY_PTY_LOCK, &tty->flags); in pty_set_lock()
159 static int pty_get_lock(struct tty_struct *tty, int __user *arg) in pty_get_lock() argument
161 int locked = test_bit(TTY_PTY_LOCK, &tty->flags); in pty_get_lock()
166 static int pty_set_pktmode(struct tty_struct *tty, int __user *arg) in pty_set_pktmode() argument
173 spin_lock_irq(&tty->ctrl_lock); in pty_set_pktmode()
175 if (!tty->packet) { in pty_set_pktmode()
176 tty->link->ctrl_status = 0; in pty_set_pktmode()
178 tty->packet = 1; in pty_set_pktmode()
181 tty->packet = 0; in pty_set_pktmode()
182 spin_unlock_irq(&tty->ctrl_lock); in pty_set_pktmode()
188 static int pty_get_pktmode(struct tty_struct *tty, int __user *arg) in pty_get_pktmode() argument
190 int pktmode = tty->packet; in pty_get_pktmode()
195 static int pty_signal(struct tty_struct *tty, int sig) in pty_signal() argument
202 if (tty->link) { in pty_signal()
203 pgrp = tty_get_pgrp(tty->link); in pty_signal()
211 static void pty_flush_buffer(struct tty_struct *tty) in pty_flush_buffer() argument
213 struct tty_struct *to = tty->link; in pty_flush_buffer()
225 spin_lock_irq(&tty->ctrl_lock); in pty_flush_buffer()
226 tty->ctrl_status |= TIOCPKT_FLUSHWRITE; in pty_flush_buffer()
228 spin_unlock_irq(&tty->ctrl_lock); in pty_flush_buffer()
232 static int pty_open(struct tty_struct *tty, struct file *filp) in pty_open() argument
234 if (!tty || !tty->link) in pty_open()
237 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) in pty_open()
239 if (test_bit(TTY_PTY_LOCK, &tty->link->flags)) in pty_open()
241 if (tty->driver->subtype == PTY_TYPE_SLAVE && tty->link->count != 1) in pty_open()
244 clear_bit(TTY_IO_ERROR, &tty->flags); in pty_open()
245 clear_bit(TTY_OTHER_CLOSED, &tty->link->flags); in pty_open()
246 set_bit(TTY_THROTTLED, &tty->flags); in pty_open()
250 set_bit(TTY_IO_ERROR, &tty->flags); in pty_open()
254 static void pty_set_termios(struct tty_struct *tty, in pty_set_termios() argument
258 if (tty->link && tty->link->packet) { in pty_set_termios()
260 (tty->termios.c_lflag & EXTPROC); in pty_set_termios()
264 int new_flow = (I_IXON(tty) && in pty_set_termios()
265 STOP_CHAR(tty) == '\023' && in pty_set_termios()
266 START_CHAR(tty) == '\021'); in pty_set_termios()
268 spin_lock_irq(&tty->ctrl_lock); in pty_set_termios()
270 tty->ctrl_status &= ~(TIOCPKT_DOSTOP | TIOCPKT_NOSTOP); in pty_set_termios()
272 tty->ctrl_status |= TIOCPKT_DOSTOP; in pty_set_termios()
274 tty->ctrl_status |= TIOCPKT_NOSTOP; in pty_set_termios()
277 tty->ctrl_status |= TIOCPKT_IOCTL; in pty_set_termios()
278 spin_unlock_irq(&tty->ctrl_lock); in pty_set_termios()
279 wake_up_interruptible(&tty->link->read_wait); in pty_set_termios()
283 tty->termios.c_cflag &= ~(CSIZE | PARENB); in pty_set_termios()
284 tty->termios.c_cflag |= (CS8 | CREAD); in pty_set_termios()
296 static int pty_resize(struct tty_struct *tty, struct winsize *ws) in pty_resize() argument
299 struct tty_struct *pty = tty->link; in pty_resize()
302 mutex_lock(&tty->winsize_mutex); in pty_resize()
303 if (!memcmp(ws, &tty->winsize, sizeof(*ws))) in pty_resize()
307 pgrp = tty_get_pgrp(tty); in pty_resize()
318 tty->winsize = *ws; in pty_resize()
321 mutex_unlock(&tty->winsize_mutex); in pty_resize()
335 static void pty_start(struct tty_struct *tty) in pty_start() argument
339 if (tty->link && tty->link->packet) { in pty_start()
340 spin_lock_irqsave(&tty->ctrl_lock, flags); in pty_start()
341 tty->ctrl_status &= ~TIOCPKT_STOP; in pty_start()
342 tty->ctrl_status |= TIOCPKT_START; in pty_start()
343 spin_unlock_irqrestore(&tty->ctrl_lock, flags); in pty_start()
344 wake_up_interruptible_poll(&tty->link->read_wait, POLLIN); in pty_start()
348 static void pty_stop(struct tty_struct *tty) in pty_stop() argument
352 if (tty->link && tty->link->packet) { in pty_stop()
353 spin_lock_irqsave(&tty->ctrl_lock, flags); in pty_stop()
354 tty->ctrl_status &= ~TIOCPKT_START; in pty_stop()
355 tty->ctrl_status |= TIOCPKT_STOP; in pty_stop()
356 spin_unlock_irqrestore(&tty->ctrl_lock, flags); in pty_stop()
357 wake_up_interruptible_poll(&tty->link->read_wait, POLLIN); in pty_stop()
372 static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty, in pty_common_install() argument
377 int idx = tty->index; in pty_common_install()
402 retval = tty_init_termios(tty); in pty_common_install()
411 driver->ttys[idx] = tty; in pty_common_install()
413 memset(&tty->termios_locked, 0, sizeof(tty->termios_locked)); in pty_common_install()
414 tty->termios = driver->init_termios; in pty_common_install()
415 memset(&o_tty->termios_locked, 0, sizeof(tty->termios_locked)); in pty_common_install()
424 tty->link = o_tty; in pty_common_install()
425 o_tty->link = tty; in pty_common_install()
431 tty->port = ports[1]; in pty_common_install()
437 tty->count++; in pty_common_install()
442 tty_free_termios(tty); in pty_common_install()
454 static void pty_cleanup(struct tty_struct *tty) in pty_cleanup() argument
456 tty_port_put(tty->port); in pty_cleanup()
462 static int pty_install(struct tty_driver *driver, struct tty_struct *tty) in pty_install() argument
464 return pty_common_install(driver, tty, true); in pty_install()
467 static void pty_remove(struct tty_driver *driver, struct tty_struct *tty) in pty_remove() argument
469 struct tty_struct *pair = tty->link; in pty_remove()
470 driver->ttys[tty->index] = NULL; in pty_remove()
475 static int pty_bsd_ioctl(struct tty_struct *tty, in pty_bsd_ioctl() argument
480 return pty_set_lock(tty, (int __user *) arg); in pty_bsd_ioctl()
482 return pty_get_lock(tty, (int __user *)arg); in pty_bsd_ioctl()
484 return pty_set_pktmode(tty, (int __user *)arg); in pty_bsd_ioctl()
486 return pty_get_pktmode(tty, (int __user *)arg); in pty_bsd_ioctl()
488 return pty_signal(tty, (int) arg); in pty_bsd_ioctl()
598 static int pty_unix98_ioctl(struct tty_struct *tty, in pty_unix98_ioctl() argument
603 return pty_set_lock(tty, (int __user *)arg); in pty_unix98_ioctl()
605 return pty_get_lock(tty, (int __user *)arg); in pty_unix98_ioctl()
607 return pty_set_pktmode(tty, (int __user *)arg); in pty_unix98_ioctl()
609 return pty_get_pktmode(tty, (int __user *)arg); in pty_unix98_ioctl()
611 return put_user(tty->index, (unsigned int __user *)arg); in pty_unix98_ioctl()
613 return pty_signal(tty, (int) arg); in pty_unix98_ioctl()
647 struct tty_struct *tty; in pts_unix98_lookup() local
650 tty = devpts_get_priv(pts_inode); in pts_unix98_lookup()
653 if (!tty) in pts_unix98_lookup()
655 return tty; in pts_unix98_lookup()
661 static int pty_unix98_install(struct tty_driver *driver, struct tty_struct *tty) in pty_unix98_install() argument
663 return pty_common_install(driver, tty, false); in pty_unix98_install()
666 static void pty_unix98_remove(struct tty_driver *driver, struct tty_struct *tty) in pty_unix98_remove() argument
671 static void pty_unix98_shutdown(struct tty_struct *tty) in pty_unix98_shutdown() argument
675 if (tty->driver->subtype == PTY_TYPE_MASTER) in pty_unix98_shutdown()
676 ptmx_inode = tty->driver_data; in pty_unix98_shutdown()
678 ptmx_inode = tty->link->driver_data; in pty_unix98_shutdown()
679 devpts_kill_index(ptmx_inode, tty->index); in pty_unix98_shutdown()
732 struct tty_struct *tty; in ptmx_open() local
758 tty = tty_init_dev(ptm_driver, index); in ptmx_open()
760 if (IS_ERR(tty)) { in ptmx_open()
761 retval = PTR_ERR(tty); in ptmx_open()
769 set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */ in ptmx_open()
770 tty->driver_data = inode; in ptmx_open()
784 tty_add_file(tty, filp); in ptmx_open()
788 tty->link); in ptmx_open()
793 tty->link->driver_data = slave_inode; in ptmx_open()
795 retval = ptm_driver->ops->open(tty, filp); in ptmx_open()
799 tty_unlock(tty); in ptmx_open()
802 tty_unlock(tty); in ptmx_open()