Lines Matching refs:tty
13 #include <linux/tty.h>
32 #include "tty.h"
36 # define tty_debug_hangup(tty, f, args...) tty_debug(tty, f, ##args)
38 # define tty_debug_hangup(tty, f, args...) do {} while (0)
47 static void pty_close(struct tty_struct *tty, struct file *filp)
49 BUG_ON(!tty);
50 if (tty->driver->subtype == PTY_TYPE_MASTER)
51 WARN_ON(tty->count > 1);
53 if (tty_io_error(tty))
55 if (tty->count > 2)
58 set_bit(TTY_IO_ERROR, &tty->flags);
59 wake_up_interruptible(&tty->read_wait);
60 wake_up_interruptible(&tty->write_wait);
61 spin_lock_irq(&tty->ctrl_lock);
62 tty->packet = 0;
63 spin_unlock_irq(&tty->ctrl_lock);
65 if (!tty->link)
67 set_bit(TTY_OTHER_CLOSED, &tty->link->flags);
68 wake_up_interruptible(&tty->link->read_wait);
69 wake_up_interruptible(&tty->link->write_wait);
70 if (tty->driver->subtype == PTY_TYPE_MASTER) {
71 set_bit(TTY_OTHER_CLOSED, &tty->flags);
73 if (tty->driver == ptm_driver) {
75 if (tty->link->driver_data)
76 devpts_pty_kill(tty->link->driver_data);
80 tty_vhangup(tty->link);
94 static void pty_unthrottle(struct tty_struct *tty)
96 tty_wakeup(tty->link);
97 set_bit(TTY_THROTTLED, &tty->flags);
102 * @tty: the tty we write from
109 * the other side of the pty/tty pair.
112 static int pty_write(struct tty_struct *tty, const unsigned char *buf, int c)
114 struct tty_struct *to = tty->link;
116 if (tty->stopped || !c)
124 * @tty: tty we are writing from
130 static int pty_write_room(struct tty_struct *tty)
132 if (tty->stopped)
134 return tty_buffer_space_avail(tty->link->port);
139 * @tty: our tty
145 static int pty_chars_in_buffer(struct tty_struct *tty)
151 static int pty_set_lock(struct tty_struct *tty, int __user *arg)
157 set_bit(TTY_PTY_LOCK, &tty->flags);
159 clear_bit(TTY_PTY_LOCK, &tty->flags);
163 static int pty_get_lock(struct tty_struct *tty, int __user *arg)
165 int locked = test_bit(TTY_PTY_LOCK, &tty->flags);
170 static int pty_set_pktmode(struct tty_struct *tty, int __user *arg)
177 spin_lock_irq(&tty->ctrl_lock);
179 if (!tty->packet) {
180 tty->link->ctrl_status = 0;
182 tty->packet = 1;
185 tty->packet = 0;
186 spin_unlock_irq(&tty->ctrl_lock);
192 static int pty_get_pktmode(struct tty_struct *tty, int __user *arg)
194 int pktmode = tty->packet;
199 static int pty_signal(struct tty_struct *tty, int sig)
206 if (tty->link) {
207 pgrp = tty_get_pgrp(tty->link);
215 static void pty_flush_buffer(struct tty_struct *tty)
217 struct tty_struct *to = tty->link;
224 spin_lock_irq(&tty->ctrl_lock);
225 tty->ctrl_status |= TIOCPKT_FLUSHWRITE;
227 spin_unlock_irq(&tty->ctrl_lock);
231 static int pty_open(struct tty_struct *tty, struct file *filp)
233 if (!tty || !tty->link)
236 if (test_bit(TTY_OTHER_CLOSED, &tty->flags))
238 if (test_bit(TTY_PTY_LOCK, &tty->link->flags))
240 if (tty->driver->subtype == PTY_TYPE_SLAVE && tty->link->count != 1)
243 clear_bit(TTY_IO_ERROR, &tty->flags);
244 clear_bit(TTY_OTHER_CLOSED, &tty->link->flags);
245 set_bit(TTY_THROTTLED, &tty->flags);
249 set_bit(TTY_IO_ERROR, &tty->flags);
253 static void pty_set_termios(struct tty_struct *tty,
257 if (tty->link && tty->link->packet) {
258 int extproc = (old_termios->c_lflag & EXTPROC) | L_EXTPROC(tty);
262 int new_flow = (I_IXON(tty) &&
263 STOP_CHAR(tty) == '\023' &&
264 START_CHAR(tty) == '\021');
266 spin_lock_irq(&tty->ctrl_lock);
268 tty->ctrl_status &= ~(TIOCPKT_DOSTOP | TIOCPKT_NOSTOP);
270 tty->ctrl_status |= TIOCPKT_DOSTOP;
272 tty->ctrl_status |= TIOCPKT_NOSTOP;
275 tty->ctrl_status |= TIOCPKT_IOCTL;
276 spin_unlock_irq(&tty->ctrl_lock);
277 wake_up_interruptible(&tty->link->read_wait);
281 tty->termios.c_cflag &= ~(CSIZE | PARENB);
282 tty->termios.c_cflag |= (CS8 | CREAD);
287 * @tty: tty being resized
294 static int pty_resize(struct tty_struct *tty, struct winsize *ws)
297 struct tty_struct *pty = tty->link;
299 /* For a PTY we need to lock the tty side */
300 mutex_lock(&tty->winsize_mutex);
301 if (!memcmp(ws, &tty->winsize, sizeof(*ws)))
305 pgrp = tty_get_pgrp(tty);
316 tty->winsize = *ws;
319 mutex_unlock(&tty->winsize_mutex);
326 * @tty: tty being flow-controlled
333 static void pty_start(struct tty_struct *tty)
337 if (tty->link && tty->link->packet) {
338 spin_lock_irqsave(&tty->ctrl_lock, flags);
339 tty->ctrl_status &= ~TIOCPKT_STOP;
340 tty->ctrl_status |= TIOCPKT_START;
341 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
342 wake_up_interruptible_poll(&tty->link->read_wait, EPOLLIN);
346 static void pty_stop(struct tty_struct *tty)
350 if (tty->link && tty->link->packet) {
351 spin_lock_irqsave(&tty->ctrl_lock, flags);
352 tty->ctrl_status &= ~TIOCPKT_START;
353 tty->ctrl_status |= TIOCPKT_STOP;
354 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
355 wake_up_interruptible_poll(&tty->link->read_wait, EPOLLIN);
362 * @tty: the tty being instantiated
365 * Perform the initial set up for the tty/pty pair. Called from the
366 * tty layer when the port is first opened.
370 static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty,
375 int idx = tty->index;
398 /* We always use new tty termios data so we can do this
400 tty_init_termios(tty);
404 driver->ttys[idx] = tty;
406 memset(&tty->termios_locked, 0, sizeof(tty->termios_locked));
407 tty->termios = driver->init_termios;
408 memset(&o_tty->termios_locked, 0, sizeof(tty->termios_locked));
417 tty->link = o_tty;
418 o_tty->link = tty;
424 tty->port = ports[1];
430 tty->count++;
442 static void pty_cleanup(struct tty_struct *tty)
444 tty_port_put(tty->port);
450 static int pty_install(struct tty_driver *driver, struct tty_struct *tty)
452 return pty_common_install(driver, tty, true);
455 static void pty_remove(struct tty_driver *driver, struct tty_struct *tty)
457 struct tty_struct *pair = tty->link;
458 driver->ttys[tty->index] = NULL;
463 static int pty_bsd_ioctl(struct tty_struct *tty,
468 return pty_set_lock(tty, (int __user *) arg);
470 return pty_get_lock(tty, (int __user *)arg);
472 return pty_set_pktmode(tty, (int __user *)arg);
474 return pty_get_pktmode(tty, (int __user *)arg);
476 return pty_signal(tty, (int) arg);
484 static long pty_bsd_compat_ioctl(struct tty_struct *tty,
491 return pty_bsd_ioctl(tty, cmd, (unsigned long)compat_ptr(arg));
607 * @tty: the master of the pty being opened
614 int ptm_open_peer(struct file *master, struct tty_struct *tty, int flags)
621 if (tty->driver != ptm_driver)
631 path.mnt = devpts_mntget(master, tty->driver_data);
636 path.dentry = tty->link->driver_data;
654 static int pty_unix98_ioctl(struct tty_struct *tty,
659 return pty_set_lock(tty, (int __user *)arg);
661 return pty_get_lock(tty, (int __user *)arg);
663 return pty_set_pktmode(tty, (int __user *)arg);
665 return pty_get_pktmode(tty, (int __user *)arg);
667 return put_user(tty->index, (unsigned int __user *)arg);
669 return pty_signal(tty, (int) arg);
676 static long pty_unix98_compat_ioctl(struct tty_struct *tty,
683 return pty_unix98_ioctl(tty, cmd,
693 * @idx: tty index
709 * @idx: tty index
712 * This provides our locking for the tty pointer.
718 struct tty_struct *tty;
721 tty = devpts_get_priv(file->f_path.dentry);
724 if (!tty)
726 return tty;
729 static int pty_unix98_install(struct tty_driver *driver, struct tty_struct *tty)
731 return pty_common_install(driver, tty, false);
735 static void pty_unix98_remove(struct tty_driver *driver, struct tty_struct *tty)
739 if (tty->driver->subtype == PTY_TYPE_MASTER)
740 fsi = tty->driver_data;
742 fsi = tty->link->driver_data;
745 devpts_kill_index(fsi, tty->index);
750 static void pty_show_fdinfo(struct tty_struct *tty, struct seq_file *m)
752 seq_printf(m, "tty-index:\t%d\n", tty->index);
793 * @filp: file pointer to tty
797 * Locking: tty_mutex protects the init_dev work. tty->count should
805 struct tty_struct *tty;
836 tty = tty_init_dev(ptm_driver, index);
837 /* The tty returned here is locked so we can safely
841 retval = PTR_ERR(tty);
842 if (IS_ERR(tty))
846 * From here on out, the tty is "live", and the index and
849 set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */
850 tty->driver_data = fsi;
852 tty_add_file(tty, filp);
854 dentry = devpts_pty_new(fsi, index, tty->link);
859 tty->link->driver_data = dentry;
861 retval = ptm_driver->ops->open(tty, filp);
865 tty_debug_hangup(tty, "opening (count=%d)\n", tty->count);
867 tty_unlock(tty);
870 tty_unlock(tty);