2 * Copyright (C) 1991, 1992 Linus Torvalds
4 * Added support for a Unix98-style ptmx device.
5 * -- C. Scott Ananian <cananian@alumni.princeton.edu>, 14-Jan-1998
9 #include <linux/module.h>
10 #include <linux/errno.h>
11 #include <linux/interrupt.h>
12 #include <linux/tty.h>
13 #include <linux/tty_flip.h>
14 #include <linux/fcntl.h>
15 #include <linux/sched.h>
16 #include <linux/string.h>
17 #include <linux/major.h>
19 #include <linux/init.h>
20 #include <linux/device.h>
21 #include <linux/uaccess.h>
22 #include <linux/bitops.h>
23 #include <linux/devpts_fs.h>
24 #include <linux/slab.h>
25 #include <linux/mutex.h>
26 #include <linux/poll.h>
28 #undef TTY_DEBUG_HANGUP
29 #ifdef TTY_DEBUG_HANGUP
30 # define tty_debug_hangup(tty, f, args...) tty_debug(tty, f, ##args)
32 # define tty_debug_hangup(tty, f, args...) do {} while (0)
35 #ifdef CONFIG_UNIX98_PTYS
36 static struct tty_driver *ptm_driver;
37 static struct tty_driver *pts_driver;
38 static DEFINE_MUTEX(devpts_mutex);
41 static void pty_close(struct tty_struct *tty, struct file *filp)
44 if (tty->driver->subtype == PTY_TYPE_MASTER)
45 WARN_ON(tty->count > 1);
47 if (tty_io_error(tty))
52 set_bit(TTY_IO_ERROR, &tty->flags);
53 wake_up_interruptible(&tty->read_wait);
54 wake_up_interruptible(&tty->write_wait);
55 spin_lock_irq(&tty->ctrl_lock);
57 spin_unlock_irq(&tty->ctrl_lock);
58 /* Review - krefs on tty_link ?? */
61 set_bit(TTY_OTHER_CLOSED, &tty->link->flags);
62 wake_up_interruptible(&tty->link->read_wait);
63 wake_up_interruptible(&tty->link->write_wait);
64 if (tty->driver->subtype == PTY_TYPE_MASTER) {
65 set_bit(TTY_OTHER_CLOSED, &tty->flags);
66 #ifdef CONFIG_UNIX98_PTYS
67 if (tty->driver == ptm_driver) {
68 mutex_lock(&devpts_mutex);
69 if (tty->link->driver_data)
70 devpts_pty_kill(tty->link->driver_data);
71 mutex_unlock(&devpts_mutex);
74 tty_vhangup(tty->link);
79 * The unthrottle routine is called by the line discipline to signal
80 * that it can receive more characters. For PTY's, the TTY_THROTTLED
81 * flag is always set, to force the line discipline to always call the
82 * unthrottle routine when there are fewer than TTY_THRESHOLD_UNTHROTTLE
83 * characters in the queue. This is necessary since each time this
84 * happens, we need to wake up any sleeping processes that could be
85 * (1) trying to send data to the pty, or (2) waiting in wait_until_sent()
86 * for the pty buffer to be drained.
88 static void pty_unthrottle(struct tty_struct *tty)
90 tty_wakeup(tty->link);
91 set_bit(TTY_THROTTLED, &tty->flags);
95 * pty_write - write to a pty
96 * @tty: the tty we write from
97 * @buf: kernel buffer of data
98 * @count: bytes to write
100 * Our "hardware" write method. Data is coming from the ldisc which
101 * may be in a non sleeping state. We simply throw this at the other
102 * end of the link as if we were an IRQ handler receiving stuff for
103 * the other side of the pty/tty pair.
106 static int pty_write(struct tty_struct *tty, const unsigned char *buf, int c)
108 struct tty_struct *to = tty->link;
110 if (tty->stopped || !c)
113 return tty_insert_flip_string_and_push_buffer(to->port, buf, c);
117 * pty_write_room - write space
118 * @tty: tty we are writing from
120 * Report how many bytes the ldisc can send into the queue for
124 static int pty_write_room(struct tty_struct *tty)
128 return tty_buffer_space_avail(tty->link->port);
132 * pty_chars_in_buffer - characters currently in our tx queue
135 * Report how much we have in the transmit queue. As everything is
136 * instantly at the other end this is easy to implement.
139 static int pty_chars_in_buffer(struct tty_struct *tty)
144 /* Set the lock flag on a pty */
145 static int pty_set_lock(struct tty_struct *tty, int __user *arg)
148 if (get_user(val, arg))
151 set_bit(TTY_PTY_LOCK, &tty->flags);
153 clear_bit(TTY_PTY_LOCK, &tty->flags);
157 static int pty_get_lock(struct tty_struct *tty, int __user *arg)
159 int locked = test_bit(TTY_PTY_LOCK, &tty->flags);
160 return put_user(locked, arg);
163 /* Set the packet mode on a pty */
164 static int pty_set_pktmode(struct tty_struct *tty, int __user *arg)
168 if (get_user(pktmode, arg))
171 spin_lock_irq(&tty->ctrl_lock);
174 tty->link->ctrl_status = 0;
180 spin_unlock_irq(&tty->ctrl_lock);
185 /* Get the packet mode of a pty */
186 static int pty_get_pktmode(struct tty_struct *tty, int __user *arg)
188 int pktmode = tty->packet;
189 return put_user(pktmode, arg);
192 /* Send a signal to the slave */
193 static int pty_signal(struct tty_struct *tty, int sig)
197 if (sig != SIGINT && sig != SIGQUIT && sig != SIGTSTP)
201 pgrp = tty_get_pgrp(tty->link);
203 kill_pgrp(pgrp, sig, 1);
209 static void pty_flush_buffer(struct tty_struct *tty)
211 struct tty_struct *to = tty->link;
216 tty_buffer_flush(to, NULL);
218 spin_lock_irq(&tty->ctrl_lock);
219 tty->ctrl_status |= TIOCPKT_FLUSHWRITE;
220 wake_up_interruptible(&to->read_wait);
221 spin_unlock_irq(&tty->ctrl_lock);
225 static int pty_open(struct tty_struct *tty, struct file *filp)
227 if (!tty || !tty->link)
230 if (test_bit(TTY_OTHER_CLOSED, &tty->flags))
232 if (test_bit(TTY_PTY_LOCK, &tty->link->flags))
234 if (tty->driver->subtype == PTY_TYPE_SLAVE && tty->link->count != 1)
237 clear_bit(TTY_IO_ERROR, &tty->flags);
238 clear_bit(TTY_OTHER_CLOSED, &tty->link->flags);
239 set_bit(TTY_THROTTLED, &tty->flags);
243 set_bit(TTY_IO_ERROR, &tty->flags);
247 static void pty_set_termios(struct tty_struct *tty,
248 struct ktermios *old_termios)
250 /* See if packet mode change of state. */
251 if (tty->link && tty->link->packet) {
252 int extproc = (old_termios->c_lflag & EXTPROC) | L_EXTPROC(tty);
253 int old_flow = ((old_termios->c_iflag & IXON) &&
254 (old_termios->c_cc[VSTOP] == '\023') &&
255 (old_termios->c_cc[VSTART] == '\021'));
256 int new_flow = (I_IXON(tty) &&
257 STOP_CHAR(tty) == '\023' &&
258 START_CHAR(tty) == '\021');
259 if ((old_flow != new_flow) || extproc) {
260 spin_lock_irq(&tty->ctrl_lock);
261 if (old_flow != new_flow) {
262 tty->ctrl_status &= ~(TIOCPKT_DOSTOP | TIOCPKT_NOSTOP);
264 tty->ctrl_status |= TIOCPKT_DOSTOP;
266 tty->ctrl_status |= TIOCPKT_NOSTOP;
269 tty->ctrl_status |= TIOCPKT_IOCTL;
270 spin_unlock_irq(&tty->ctrl_lock);
271 wake_up_interruptible(&tty->link->read_wait);
275 tty->termios.c_cflag &= ~(CSIZE | PARENB);
276 tty->termios.c_cflag |= (CS8 | CREAD);
280 * pty_do_resize - resize event
281 * @tty: tty being resized
282 * @ws: window size being set.
284 * Update the termios variables and send the necessary signals to
285 * peform a terminal resize correctly
288 static int pty_resize(struct tty_struct *tty, struct winsize *ws)
290 struct pid *pgrp, *rpgrp;
291 struct tty_struct *pty = tty->link;
293 /* For a PTY we need to lock the tty side */
294 mutex_lock(&tty->winsize_mutex);
295 if (!memcmp(ws, &tty->winsize, sizeof(*ws)))
298 /* Signal the foreground process group of both ptys */
299 pgrp = tty_get_pgrp(tty);
300 rpgrp = tty_get_pgrp(pty);
303 kill_pgrp(pgrp, SIGWINCH, 1);
304 if (rpgrp != pgrp && rpgrp)
305 kill_pgrp(rpgrp, SIGWINCH, 1);
311 pty->winsize = *ws; /* Never used so will go away soon */
313 mutex_unlock(&tty->winsize_mutex);
318 * pty_start - start() handler
319 * pty_stop - stop() handler
320 * @tty: tty being flow-controlled
322 * Propagates the TIOCPKT status to the master pty.
324 * NB: only the master pty can be in packet mode so only the slave
325 * needs start()/stop() handlers
327 static void pty_start(struct tty_struct *tty)
331 if (tty->link && tty->link->packet) {
332 spin_lock_irqsave(&tty->ctrl_lock, flags);
333 tty->ctrl_status &= ~TIOCPKT_STOP;
334 tty->ctrl_status |= TIOCPKT_START;
335 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
336 wake_up_interruptible_poll(&tty->link->read_wait, POLLIN);
340 static void pty_stop(struct tty_struct *tty)
344 if (tty->link && tty->link->packet) {
345 spin_lock_irqsave(&tty->ctrl_lock, flags);
346 tty->ctrl_status &= ~TIOCPKT_START;
347 tty->ctrl_status |= TIOCPKT_STOP;
348 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
349 wake_up_interruptible_poll(&tty->link->read_wait, POLLIN);
354 * pty_common_install - set up the pty pair
355 * @driver: the pty driver
356 * @tty: the tty being instantiated
357 * @legacy: true if this is BSD style
359 * Perform the initial set up for the tty/pty pair. Called from the
360 * tty layer when the port is first opened.
362 * Locking: the caller must hold the tty_mutex
364 static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty,
367 struct tty_struct *o_tty;
368 struct tty_port *ports[2];
369 int idx = tty->index;
370 int retval = -ENOMEM;
372 /* Opening the slave first has always returned -EIO */
373 if (driver->subtype != PTY_TYPE_MASTER)
376 ports[0] = kmalloc(sizeof **ports, GFP_KERNEL);
377 ports[1] = kmalloc(sizeof **ports, GFP_KERNEL);
378 if (!ports[0] || !ports[1])
380 if (!try_module_get(driver->other->owner)) {
381 /* This cannot in fact currently happen */
384 o_tty = alloc_tty_struct(driver->other, idx);
388 tty_set_lock_subclass(o_tty);
389 lockdep_set_subclass(&o_tty->termios_rwsem, TTY_LOCK_SLAVE);
392 /* We always use new tty termios data so we can do this
394 tty_init_termios(tty);
395 tty_init_termios(o_tty);
397 driver->other->ttys[idx] = o_tty;
398 driver->ttys[idx] = tty;
400 memset(&tty->termios_locked, 0, sizeof(tty->termios_locked));
401 tty->termios = driver->init_termios;
402 memset(&o_tty->termios_locked, 0, sizeof(tty->termios_locked));
403 o_tty->termios = driver->other->init_termios;
407 * Everything allocated ... set up the o_tty structure.
409 tty_driver_kref_get(driver->other);
410 /* Establish the links in both directions */
413 tty_port_init(ports[0]);
414 tty_port_init(ports[1]);
415 tty_buffer_set_limit(ports[0], 8192);
416 tty_buffer_set_limit(ports[1], 8192);
417 o_tty->port = ports[0];
418 tty->port = ports[1];
419 o_tty->port->itty = o_tty;
421 tty_buffer_set_lock_subclass(o_tty->port);
423 tty_driver_kref_get(driver);
429 module_put(driver->other->owner);
436 static void pty_cleanup(struct tty_struct *tty)
438 tty_port_put(tty->port);
441 /* Traditional BSD devices */
442 #ifdef CONFIG_LEGACY_PTYS
444 static int pty_install(struct tty_driver *driver, struct tty_struct *tty)
446 return pty_common_install(driver, tty, true);
449 static void pty_remove(struct tty_driver *driver, struct tty_struct *tty)
451 struct tty_struct *pair = tty->link;
452 driver->ttys[tty->index] = NULL;
454 pair->driver->ttys[pair->index] = NULL;
457 static int pty_bsd_ioctl(struct tty_struct *tty,
458 unsigned int cmd, unsigned long arg)
461 case TIOCSPTLCK: /* Set PT Lock (disallow slave open) */
462 return pty_set_lock(tty, (int __user *) arg);
463 case TIOCGPTLCK: /* Get PT Lock status */
464 return pty_get_lock(tty, (int __user *)arg);
465 case TIOCPKT: /* Set PT packet mode */
466 return pty_set_pktmode(tty, (int __user *)arg);
467 case TIOCGPKT: /* Get PT packet mode */
468 return pty_get_pktmode(tty, (int __user *)arg);
469 case TIOCSIG: /* Send signal to other side of pty */
470 return pty_signal(tty, (int) arg);
471 case TIOCGPTN: /* TTY returns ENOTTY, but glibc expects EINVAL here */
477 static int legacy_count = CONFIG_LEGACY_PTY_COUNT;
479 * not really modular, but the easiest way to keep compat with existing
480 * bootargs behaviour is to continue using module_param here.
482 module_param(legacy_count, int, 0);
485 * The master side of a pty can do TIOCSPTLCK and thus
488 static const struct tty_operations master_pty_ops_bsd = {
489 .install = pty_install,
493 .write_room = pty_write_room,
494 .flush_buffer = pty_flush_buffer,
495 .chars_in_buffer = pty_chars_in_buffer,
496 .unthrottle = pty_unthrottle,
497 .ioctl = pty_bsd_ioctl,
498 .cleanup = pty_cleanup,
499 .resize = pty_resize,
503 static const struct tty_operations slave_pty_ops_bsd = {
504 .install = pty_install,
508 .write_room = pty_write_room,
509 .flush_buffer = pty_flush_buffer,
510 .chars_in_buffer = pty_chars_in_buffer,
511 .unthrottle = pty_unthrottle,
512 .set_termios = pty_set_termios,
513 .cleanup = pty_cleanup,
514 .resize = pty_resize,
520 static void __init legacy_pty_init(void)
522 struct tty_driver *pty_driver, *pty_slave_driver;
524 if (legacy_count <= 0)
527 pty_driver = tty_alloc_driver(legacy_count,
528 TTY_DRIVER_RESET_TERMIOS |
529 TTY_DRIVER_REAL_RAW |
530 TTY_DRIVER_DYNAMIC_ALLOC);
531 if (IS_ERR(pty_driver))
532 panic("Couldn't allocate pty driver");
534 pty_slave_driver = tty_alloc_driver(legacy_count,
535 TTY_DRIVER_RESET_TERMIOS |
536 TTY_DRIVER_REAL_RAW |
537 TTY_DRIVER_DYNAMIC_ALLOC);
538 if (IS_ERR(pty_slave_driver))
539 panic("Couldn't allocate pty slave driver");
541 pty_driver->driver_name = "pty_master";
542 pty_driver->name = "pty";
543 pty_driver->major = PTY_MASTER_MAJOR;
544 pty_driver->minor_start = 0;
545 pty_driver->type = TTY_DRIVER_TYPE_PTY;
546 pty_driver->subtype = PTY_TYPE_MASTER;
547 pty_driver->init_termios = tty_std_termios;
548 pty_driver->init_termios.c_iflag = 0;
549 pty_driver->init_termios.c_oflag = 0;
550 pty_driver->init_termios.c_cflag = B38400 | CS8 | CREAD;
551 pty_driver->init_termios.c_lflag = 0;
552 pty_driver->init_termios.c_ispeed = 38400;
553 pty_driver->init_termios.c_ospeed = 38400;
554 pty_driver->other = pty_slave_driver;
555 tty_set_operations(pty_driver, &master_pty_ops_bsd);
557 pty_slave_driver->driver_name = "pty_slave";
558 pty_slave_driver->name = "ttyp";
559 pty_slave_driver->major = PTY_SLAVE_MAJOR;
560 pty_slave_driver->minor_start = 0;
561 pty_slave_driver->type = TTY_DRIVER_TYPE_PTY;
562 pty_slave_driver->subtype = PTY_TYPE_SLAVE;
563 pty_slave_driver->init_termios = tty_std_termios;
564 pty_slave_driver->init_termios.c_cflag = B38400 | CS8 | CREAD;
565 pty_slave_driver->init_termios.c_ispeed = 38400;
566 pty_slave_driver->init_termios.c_ospeed = 38400;
567 pty_slave_driver->other = pty_driver;
568 tty_set_operations(pty_slave_driver, &slave_pty_ops_bsd);
570 if (tty_register_driver(pty_driver))
571 panic("Couldn't register pty driver");
572 if (tty_register_driver(pty_slave_driver))
573 panic("Couldn't register pty slave driver");
576 static inline void legacy_pty_init(void) { }
580 #ifdef CONFIG_UNIX98_PTYS
582 static struct cdev ptmx_cdev;
584 static int pty_unix98_ioctl(struct tty_struct *tty,
585 unsigned int cmd, unsigned long arg)
588 case TIOCSPTLCK: /* Set PT Lock (disallow slave open) */
589 return pty_set_lock(tty, (int __user *)arg);
590 case TIOCGPTLCK: /* Get PT Lock status */
591 return pty_get_lock(tty, (int __user *)arg);
592 case TIOCPKT: /* Set PT packet mode */
593 return pty_set_pktmode(tty, (int __user *)arg);
594 case TIOCGPKT: /* Get PT packet mode */
595 return pty_get_pktmode(tty, (int __user *)arg);
596 case TIOCGPTN: /* Get PT Number */
597 return put_user(tty->index, (unsigned int __user *)arg);
598 case TIOCSIG: /* Send signal to other side of pty */
599 return pty_signal(tty, (int) arg);
606 * ptm_unix98_lookup - find a pty master
607 * @driver: ptm driver
610 * Look up a pty master device. Called under the tty_mutex for now.
611 * This provides our locking.
614 static struct tty_struct *ptm_unix98_lookup(struct tty_driver *driver,
615 struct file *file, int idx)
617 /* Master must be open via /dev/ptmx */
618 return ERR_PTR(-EIO);
622 * pts_unix98_lookup - find a pty slave
623 * @driver: pts driver
626 * Look up a pty master device. Called under the tty_mutex for now.
627 * This provides our locking for the tty pointer.
630 static struct tty_struct *pts_unix98_lookup(struct tty_driver *driver,
631 struct file *file, int idx)
633 struct tty_struct *tty;
635 mutex_lock(&devpts_mutex);
636 tty = devpts_get_priv(file->f_path.dentry);
637 mutex_unlock(&devpts_mutex);
638 /* Master must be open before slave */
640 return ERR_PTR(-EIO);
644 static int pty_unix98_install(struct tty_driver *driver, struct tty_struct *tty)
646 return pty_common_install(driver, tty, false);
649 /* this is called once with whichever end is closed last */
650 static void pty_unix98_remove(struct tty_driver *driver, struct tty_struct *tty)
652 struct pts_fs_info *fsi;
654 if (tty->driver->subtype == PTY_TYPE_MASTER)
655 fsi = tty->driver_data;
657 fsi = tty->link->driver_data;
660 devpts_kill_index(fsi, tty->index);
665 static const struct tty_operations ptm_unix98_ops = {
666 .lookup = ptm_unix98_lookup,
667 .install = pty_unix98_install,
668 .remove = pty_unix98_remove,
672 .write_room = pty_write_room,
673 .flush_buffer = pty_flush_buffer,
674 .chars_in_buffer = pty_chars_in_buffer,
675 .unthrottle = pty_unthrottle,
676 .ioctl = pty_unix98_ioctl,
677 .resize = pty_resize,
678 .cleanup = pty_cleanup
681 static const struct tty_operations pty_unix98_ops = {
682 .lookup = pts_unix98_lookup,
683 .install = pty_unix98_install,
684 .remove = pty_unix98_remove,
688 .write_room = pty_write_room,
689 .flush_buffer = pty_flush_buffer,
690 .chars_in_buffer = pty_chars_in_buffer,
691 .unthrottle = pty_unthrottle,
692 .set_termios = pty_set_termios,
695 .cleanup = pty_cleanup,
699 * ptmx_open - open a unix 98 pty master
700 * @inode: inode of device file
701 * @filp: file pointer to tty
703 * Allocate a unix98 pty master device from the ptmx driver.
705 * Locking: tty_mutex protects the init_dev work. tty->count should
707 * allocated_ptys_lock handles the list of free pty numbers
710 static int ptmx_open(struct inode *inode, struct file *filp)
712 struct pts_fs_info *fsi;
713 struct tty_struct *tty;
714 struct dentry *dentry;
718 nonseekable_open(inode, filp);
720 /* We refuse fsnotify events on ptmx, since it's a shared resource */
721 filp->f_mode |= FMODE_NONOTIFY;
723 retval = tty_alloc_file(filp);
727 fsi = devpts_acquire(filp);
729 retval = PTR_ERR(fsi);
733 /* find a device that is not in use. */
734 mutex_lock(&devpts_mutex);
735 index = devpts_new_index(fsi);
736 mutex_unlock(&devpts_mutex);
743 mutex_lock(&tty_mutex);
744 tty = tty_init_dev(ptm_driver, index);
745 /* The tty returned here is locked so we can safely
747 mutex_unlock(&tty_mutex);
749 retval = PTR_ERR(tty);
754 * From here on out, the tty is "live", and the index and
755 * fsi will be killed/put by the tty_release()
757 set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */
758 tty->driver_data = fsi;
760 tty_add_file(tty, filp);
762 dentry = devpts_pty_new(fsi, index, tty->link);
763 if (IS_ERR(dentry)) {
764 retval = PTR_ERR(dentry);
767 tty->link->driver_data = dentry;
769 retval = ptm_driver->ops->open(tty, filp);
773 tty_debug_hangup(tty, "opening (count=%d)\n", tty->count);
779 // This will also put-ref the fsi
780 tty_release(inode, filp);
783 devpts_kill_index(fsi, index);
791 static struct file_operations ptmx_fops __ro_after_init;
793 static void __init unix98_pty_init(void)
795 ptm_driver = tty_alloc_driver(NR_UNIX98_PTY_MAX,
796 TTY_DRIVER_RESET_TERMIOS |
797 TTY_DRIVER_REAL_RAW |
798 TTY_DRIVER_DYNAMIC_DEV |
799 TTY_DRIVER_DEVPTS_MEM |
800 TTY_DRIVER_DYNAMIC_ALLOC);
801 if (IS_ERR(ptm_driver))
802 panic("Couldn't allocate Unix98 ptm driver");
803 pts_driver = tty_alloc_driver(NR_UNIX98_PTY_MAX,
804 TTY_DRIVER_RESET_TERMIOS |
805 TTY_DRIVER_REAL_RAW |
806 TTY_DRIVER_DYNAMIC_DEV |
807 TTY_DRIVER_DEVPTS_MEM |
808 TTY_DRIVER_DYNAMIC_ALLOC);
809 if (IS_ERR(pts_driver))
810 panic("Couldn't allocate Unix98 pts driver");
812 ptm_driver->driver_name = "pty_master";
813 ptm_driver->name = "ptm";
814 ptm_driver->major = UNIX98_PTY_MASTER_MAJOR;
815 ptm_driver->minor_start = 0;
816 ptm_driver->type = TTY_DRIVER_TYPE_PTY;
817 ptm_driver->subtype = PTY_TYPE_MASTER;
818 ptm_driver->init_termios = tty_std_termios;
819 ptm_driver->init_termios.c_iflag = 0;
820 ptm_driver->init_termios.c_oflag = 0;
821 ptm_driver->init_termios.c_cflag = B38400 | CS8 | CREAD;
822 ptm_driver->init_termios.c_lflag = 0;
823 ptm_driver->init_termios.c_ispeed = 38400;
824 ptm_driver->init_termios.c_ospeed = 38400;
825 ptm_driver->other = pts_driver;
826 tty_set_operations(ptm_driver, &ptm_unix98_ops);
828 pts_driver->driver_name = "pty_slave";
829 pts_driver->name = "pts";
830 pts_driver->major = UNIX98_PTY_SLAVE_MAJOR;
831 pts_driver->minor_start = 0;
832 pts_driver->type = TTY_DRIVER_TYPE_PTY;
833 pts_driver->subtype = PTY_TYPE_SLAVE;
834 pts_driver->init_termios = tty_std_termios;
835 pts_driver->init_termios.c_cflag = B38400 | CS8 | CREAD;
836 pts_driver->init_termios.c_ispeed = 38400;
837 pts_driver->init_termios.c_ospeed = 38400;
838 pts_driver->other = ptm_driver;
839 tty_set_operations(pts_driver, &pty_unix98_ops);
841 if (tty_register_driver(ptm_driver))
842 panic("Couldn't register Unix98 ptm driver");
843 if (tty_register_driver(pts_driver))
844 panic("Couldn't register Unix98 pts driver");
846 /* Now create the /dev/ptmx special device */
847 tty_default_fops(&ptmx_fops);
848 ptmx_fops.open = ptmx_open;
850 cdev_init(&ptmx_cdev, &ptmx_fops);
851 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
852 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0)
853 panic("Couldn't register /dev/ptmx driver");
854 device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 2), NULL, "ptmx");
858 static inline void unix98_pty_init(void) { }
861 static int __init pty_init(void)
867 device_initcall(pty_init);