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>
11 #include <linux/errno.h>
12 #include <linux/interrupt.h>
13 #include <linux/tty.h>
14 #include <linux/tty_flip.h>
15 #include <linux/fcntl.h>
16 #include <linux/sched.h>
17 #include <linux/string.h>
18 #include <linux/major.h>
20 #include <linux/init.h>
21 #include <linux/device.h>
22 #include <linux/uaccess.h>
23 #include <linux/bitops.h>
24 #include <linux/devpts_fs.h>
25 #include <linux/slab.h>
26 #include <linux/mutex.h>
28 #ifdef CONFIG_UNIX98_PTYS
29 static struct tty_driver
*ptm_driver
;
30 static struct tty_driver
*pts_driver
;
31 static DEFINE_MUTEX(devpts_mutex
);
34 static void pty_close(struct tty_struct
*tty
, struct file
*filp
)
37 if (tty
->driver
->subtype
== PTY_TYPE_MASTER
)
38 WARN_ON(tty
->count
> 1);
40 if (test_bit(TTY_IO_ERROR
, &tty
->flags
))
45 set_bit(TTY_IO_ERROR
, &tty
->flags
);
46 wake_up_interruptible(&tty
->read_wait
);
47 wake_up_interruptible(&tty
->write_wait
);
49 /* Review - krefs on tty_link ?? */
52 set_bit(TTY_OTHER_CLOSED
, &tty
->link
->flags
);
53 wake_up_interruptible(&tty
->link
->read_wait
);
54 wake_up_interruptible(&tty
->link
->write_wait
);
55 if (tty
->driver
->subtype
== PTY_TYPE_MASTER
) {
56 set_bit(TTY_OTHER_CLOSED
, &tty
->flags
);
57 #ifdef CONFIG_UNIX98_PTYS
58 if (tty
->driver
== ptm_driver
) {
59 mutex_lock(&devpts_mutex
);
60 if (tty
->link
->driver_data
)
61 devpts_pty_kill(tty
->link
->driver_data
);
62 mutex_unlock(&devpts_mutex
);
66 tty_vhangup(tty
->link
);
72 * The unthrottle routine is called by the line discipline to signal
73 * that it can receive more characters. For PTY's, the TTY_THROTTLED
74 * flag is always set, to force the line discipline to always call the
75 * unthrottle routine when there are fewer than TTY_THRESHOLD_UNTHROTTLE
76 * characters in the queue. This is necessary since each time this
77 * happens, we need to wake up any sleeping processes that could be
78 * (1) trying to send data to the pty, or (2) waiting in wait_until_sent()
79 * for the pty buffer to be drained.
81 static void pty_unthrottle(struct tty_struct
*tty
)
83 tty_wakeup(tty
->link
);
84 set_bit(TTY_THROTTLED
, &tty
->flags
);
88 * pty_space - report space left for writing
89 * @to: tty we are writing into
91 * The tty buffers allow 64K but we sneak a peak and clip at 8K this
92 * allows a lot of overspill room for echo and other fun messes to
96 static int pty_space(struct tty_struct
*to
)
98 int n
= 8192 - to
->port
->buf
.memory_used
;
105 * pty_write - write to a pty
106 * @tty: the tty we write from
107 * @buf: kernel buffer of data
108 * @count: bytes to write
110 * Our "hardware" write method. Data is coming from the ldisc which
111 * may be in a non sleeping state. We simply throw this at the other
112 * end of the link as if we were an IRQ handler receiving stuff for
113 * the other side of the pty/tty pair.
116 static int pty_write(struct tty_struct
*tty
, const unsigned char *buf
, int c
)
118 struct tty_struct
*to
= tty
->link
;
124 /* Stuff the data into the input queue of the other end */
125 c
= tty_insert_flip_string(to
->port
, buf
, c
);
128 tty_flip_buffer_push(to
->port
);
136 * pty_write_room - write space
137 * @tty: tty we are writing from
139 * Report how many bytes the ldisc can send into the queue for
143 static int pty_write_room(struct tty_struct
*tty
)
147 return pty_space(tty
->link
);
151 * pty_chars_in_buffer - characters currently in our tx queue
154 * Report how much we have in the transmit queue. As everything is
155 * instantly at the other end this is easy to implement.
158 static int pty_chars_in_buffer(struct tty_struct
*tty
)
163 /* Set the lock flag on a pty */
164 static int pty_set_lock(struct tty_struct
*tty
, int __user
*arg
)
167 if (get_user(val
, arg
))
170 set_bit(TTY_PTY_LOCK
, &tty
->flags
);
172 clear_bit(TTY_PTY_LOCK
, &tty
->flags
);
176 static int pty_get_lock(struct tty_struct
*tty
, int __user
*arg
)
178 int locked
= test_bit(TTY_PTY_LOCK
, &tty
->flags
);
179 return put_user(locked
, arg
);
182 /* Set the packet mode on a pty */
183 static int pty_set_pktmode(struct tty_struct
*tty
, int __user
*arg
)
188 if (get_user(pktmode
, arg
))
191 spin_lock_irqsave(&tty
->ctrl_lock
, flags
);
195 tty
->link
->ctrl_status
= 0;
199 spin_unlock_irqrestore(&tty
->ctrl_lock
, flags
);
204 /* Get the packet mode of a pty */
205 static int pty_get_pktmode(struct tty_struct
*tty
, int __user
*arg
)
207 int pktmode
= tty
->packet
;
208 return put_user(pktmode
, arg
);
211 /* Send a signal to the slave */
212 static int pty_signal(struct tty_struct
*tty
, int sig
)
217 if (sig
!= SIGINT
&& sig
!= SIGQUIT
&& sig
!= SIGTSTP
)
221 spin_lock_irqsave(&tty
->link
->ctrl_lock
, flags
);
222 pgrp
= get_pid(tty
->link
->pgrp
);
223 spin_unlock_irqrestore(&tty
->link
->ctrl_lock
, flags
);
225 kill_pgrp(pgrp
, sig
, 1);
231 static void pty_flush_buffer(struct tty_struct
*tty
)
233 struct tty_struct
*to
= tty
->link
;
238 /* tty_buffer_flush(to); FIXME */
240 spin_lock_irqsave(&tty
->ctrl_lock
, flags
);
241 tty
->ctrl_status
|= TIOCPKT_FLUSHWRITE
;
242 wake_up_interruptible(&to
->read_wait
);
243 spin_unlock_irqrestore(&tty
->ctrl_lock
, flags
);
247 static int pty_open(struct tty_struct
*tty
, struct file
*filp
)
249 if (!tty
|| !tty
->link
)
252 if (test_bit(TTY_OTHER_CLOSED
, &tty
->flags
))
254 if (test_bit(TTY_PTY_LOCK
, &tty
->link
->flags
))
256 if (tty
->driver
->subtype
== PTY_TYPE_SLAVE
&& tty
->link
->count
!= 1)
259 clear_bit(TTY_IO_ERROR
, &tty
->flags
);
260 clear_bit(TTY_OTHER_CLOSED
, &tty
->link
->flags
);
261 set_bit(TTY_THROTTLED
, &tty
->flags
);
265 set_bit(TTY_IO_ERROR
, &tty
->flags
);
269 static void pty_set_termios(struct tty_struct
*tty
,
270 struct ktermios
*old_termios
)
272 tty
->termios
.c_cflag
&= ~(CSIZE
| PARENB
);
273 tty
->termios
.c_cflag
|= (CS8
| CREAD
);
277 * pty_do_resize - resize event
278 * @tty: tty being resized
279 * @ws: window size being set.
281 * Update the termios variables and send the necessary signals to
282 * peform a terminal resize correctly
285 static int pty_resize(struct tty_struct
*tty
, struct winsize
*ws
)
287 struct pid
*pgrp
, *rpgrp
;
289 struct tty_struct
*pty
= tty
->link
;
291 /* For a PTY we need to lock the tty side */
292 mutex_lock(&tty
->termios_mutex
);
293 if (!memcmp(ws
, &tty
->winsize
, sizeof(*ws
)))
296 /* Get the PID values and reference them so we can
297 avoid holding the tty ctrl lock while sending signals.
298 We need to lock these individually however. */
300 spin_lock_irqsave(&tty
->ctrl_lock
, flags
);
301 pgrp
= get_pid(tty
->pgrp
);
302 spin_unlock_irqrestore(&tty
->ctrl_lock
, flags
);
304 spin_lock_irqsave(&pty
->ctrl_lock
, flags
);
305 rpgrp
= get_pid(pty
->pgrp
);
306 spin_unlock_irqrestore(&pty
->ctrl_lock
, flags
);
309 kill_pgrp(pgrp
, SIGWINCH
, 1);
310 if (rpgrp
!= pgrp
&& rpgrp
)
311 kill_pgrp(rpgrp
, SIGWINCH
, 1);
317 pty
->winsize
= *ws
; /* Never used so will go away soon */
319 mutex_unlock(&tty
->termios_mutex
);
324 * pty_common_install - set up the pty pair
325 * @driver: the pty driver
326 * @tty: the tty being instantiated
327 * @bool: legacy, true if this is BSD style
329 * Perform the initial set up for the tty/pty pair. Called from the
330 * tty layer when the port is first opened.
332 * Locking: the caller must hold the tty_mutex
334 static int pty_common_install(struct tty_driver
*driver
, struct tty_struct
*tty
,
337 struct tty_struct
*o_tty
;
338 struct tty_port
*ports
[2];
339 int idx
= tty
->index
;
340 int retval
= -ENOMEM
;
342 o_tty
= alloc_tty_struct();
345 ports
[0] = kmalloc(sizeof **ports
, GFP_KERNEL
);
346 ports
[1] = kmalloc(sizeof **ports
, GFP_KERNEL
);
347 if (!ports
[0] || !ports
[1])
349 if (!try_module_get(driver
->other
->owner
)) {
350 /* This cannot in fact currently happen */
353 initialize_tty_struct(o_tty
, driver
->other
, idx
);
356 /* We always use new tty termios data so we can do this
358 retval
= tty_init_termios(tty
);
362 retval
= tty_init_termios(o_tty
);
364 goto err_free_termios
;
366 driver
->other
->ttys
[idx
] = o_tty
;
367 driver
->ttys
[idx
] = tty
;
369 memset(&tty
->termios_locked
, 0, sizeof(tty
->termios_locked
));
370 tty
->termios
= driver
->init_termios
;
371 memset(&o_tty
->termios_locked
, 0, sizeof(tty
->termios_locked
));
372 o_tty
->termios
= driver
->other
->init_termios
;
376 * Everything allocated ... set up the o_tty structure.
378 tty_driver_kref_get(driver
->other
);
379 if (driver
->subtype
== PTY_TYPE_MASTER
)
381 /* Establish the links in both directions */
384 tty_port_init(ports
[0]);
385 tty_port_init(ports
[1]);
386 o_tty
->port
= ports
[0];
387 tty
->port
= ports
[1];
388 o_tty
->port
->itty
= o_tty
;
390 tty_driver_kref_get(driver
);
395 tty_free_termios(tty
);
397 deinitialize_tty_struct(o_tty
);
398 module_put(o_tty
->driver
->owner
);
402 free_tty_struct(o_tty
);
407 static void pty_cleanup(struct tty_struct
*tty
)
409 tty_port_put(tty
->port
);
412 /* Traditional BSD devices */
413 #ifdef CONFIG_LEGACY_PTYS
415 static int pty_install(struct tty_driver
*driver
, struct tty_struct
*tty
)
417 return pty_common_install(driver
, tty
, true);
420 static void pty_remove(struct tty_driver
*driver
, struct tty_struct
*tty
)
422 struct tty_struct
*pair
= tty
->link
;
423 driver
->ttys
[tty
->index
] = NULL
;
425 pair
->driver
->ttys
[pair
->index
] = NULL
;
428 static int pty_bsd_ioctl(struct tty_struct
*tty
,
429 unsigned int cmd
, unsigned long arg
)
432 case TIOCSPTLCK
: /* Set PT Lock (disallow slave open) */
433 return pty_set_lock(tty
, (int __user
*) arg
);
434 case TIOCGPTLCK
: /* Get PT Lock status */
435 return pty_get_lock(tty
, (int __user
*)arg
);
436 case TIOCPKT
: /* Set PT packet mode */
437 return pty_set_pktmode(tty
, (int __user
*)arg
);
438 case TIOCGPKT
: /* Get PT packet mode */
439 return pty_get_pktmode(tty
, (int __user
*)arg
);
440 case TIOCSIG
: /* Send signal to other side of pty */
441 return pty_signal(tty
, (int) arg
);
442 case TIOCGPTN
: /* TTY returns ENOTTY, but glibc expects EINVAL here */
448 static int legacy_count
= CONFIG_LEGACY_PTY_COUNT
;
449 module_param(legacy_count
, int, 0);
452 * The master side of a pty can do TIOCSPTLCK and thus
455 static const struct tty_operations master_pty_ops_bsd
= {
456 .install
= pty_install
,
460 .write_room
= pty_write_room
,
461 .flush_buffer
= pty_flush_buffer
,
462 .chars_in_buffer
= pty_chars_in_buffer
,
463 .unthrottle
= pty_unthrottle
,
464 .set_termios
= pty_set_termios
,
465 .ioctl
= pty_bsd_ioctl
,
466 .cleanup
= pty_cleanup
,
467 .resize
= pty_resize
,
471 static const struct tty_operations slave_pty_ops_bsd
= {
472 .install
= pty_install
,
476 .write_room
= pty_write_room
,
477 .flush_buffer
= pty_flush_buffer
,
478 .chars_in_buffer
= pty_chars_in_buffer
,
479 .unthrottle
= pty_unthrottle
,
480 .set_termios
= pty_set_termios
,
481 .cleanup
= pty_cleanup
,
482 .resize
= pty_resize
,
486 static void __init
legacy_pty_init(void)
488 struct tty_driver
*pty_driver
, *pty_slave_driver
;
490 if (legacy_count
<= 0)
493 pty_driver
= tty_alloc_driver(legacy_count
,
494 TTY_DRIVER_RESET_TERMIOS
|
495 TTY_DRIVER_REAL_RAW
|
496 TTY_DRIVER_DYNAMIC_ALLOC
);
497 if (IS_ERR(pty_driver
))
498 panic("Couldn't allocate pty driver");
500 pty_slave_driver
= tty_alloc_driver(legacy_count
,
501 TTY_DRIVER_RESET_TERMIOS
|
502 TTY_DRIVER_REAL_RAW
|
503 TTY_DRIVER_DYNAMIC_ALLOC
);
504 if (IS_ERR(pty_slave_driver
))
505 panic("Couldn't allocate pty slave driver");
507 pty_driver
->driver_name
= "pty_master";
508 pty_driver
->name
= "pty";
509 pty_driver
->major
= PTY_MASTER_MAJOR
;
510 pty_driver
->minor_start
= 0;
511 pty_driver
->type
= TTY_DRIVER_TYPE_PTY
;
512 pty_driver
->subtype
= PTY_TYPE_MASTER
;
513 pty_driver
->init_termios
= tty_std_termios
;
514 pty_driver
->init_termios
.c_iflag
= 0;
515 pty_driver
->init_termios
.c_oflag
= 0;
516 pty_driver
->init_termios
.c_cflag
= B38400
| CS8
| CREAD
;
517 pty_driver
->init_termios
.c_lflag
= 0;
518 pty_driver
->init_termios
.c_ispeed
= 38400;
519 pty_driver
->init_termios
.c_ospeed
= 38400;
520 pty_driver
->other
= pty_slave_driver
;
521 tty_set_operations(pty_driver
, &master_pty_ops_bsd
);
523 pty_slave_driver
->driver_name
= "pty_slave";
524 pty_slave_driver
->name
= "ttyp";
525 pty_slave_driver
->major
= PTY_SLAVE_MAJOR
;
526 pty_slave_driver
->minor_start
= 0;
527 pty_slave_driver
->type
= TTY_DRIVER_TYPE_PTY
;
528 pty_slave_driver
->subtype
= PTY_TYPE_SLAVE
;
529 pty_slave_driver
->init_termios
= tty_std_termios
;
530 pty_slave_driver
->init_termios
.c_cflag
= B38400
| CS8
| CREAD
;
531 pty_slave_driver
->init_termios
.c_ispeed
= 38400;
532 pty_slave_driver
->init_termios
.c_ospeed
= 38400;
533 pty_slave_driver
->other
= pty_driver
;
534 tty_set_operations(pty_slave_driver
, &slave_pty_ops_bsd
);
536 if (tty_register_driver(pty_driver
))
537 panic("Couldn't register pty driver");
538 if (tty_register_driver(pty_slave_driver
))
539 panic("Couldn't register pty slave driver");
542 static inline void legacy_pty_init(void) { }
546 #ifdef CONFIG_UNIX98_PTYS
548 static struct cdev ptmx_cdev
;
550 static int pty_unix98_ioctl(struct tty_struct
*tty
,
551 unsigned int cmd
, unsigned long arg
)
554 case TIOCSPTLCK
: /* Set PT Lock (disallow slave open) */
555 return pty_set_lock(tty
, (int __user
*)arg
);
556 case TIOCGPTLCK
: /* Get PT Lock status */
557 return pty_get_lock(tty
, (int __user
*)arg
);
558 case TIOCPKT
: /* Set PT packet mode */
559 return pty_set_pktmode(tty
, (int __user
*)arg
);
560 case TIOCGPKT
: /* Get PT packet mode */
561 return pty_get_pktmode(tty
, (int __user
*)arg
);
562 case TIOCGPTN
: /* Get PT Number */
563 return put_user(tty
->index
, (unsigned int __user
*)arg
);
564 case TIOCSIG
: /* Send signal to other side of pty */
565 return pty_signal(tty
, (int) arg
);
572 * ptm_unix98_lookup - find a pty master
573 * @driver: ptm driver
576 * Look up a pty master device. Called under the tty_mutex for now.
577 * This provides our locking.
580 static struct tty_struct
*ptm_unix98_lookup(struct tty_driver
*driver
,
581 struct inode
*ptm_inode
, int idx
)
583 /* Master must be open via /dev/ptmx */
584 return ERR_PTR(-EIO
);
588 * pts_unix98_lookup - find a pty slave
589 * @driver: pts driver
592 * Look up a pty master device. Called under the tty_mutex for now.
593 * This provides our locking for the tty pointer.
596 static struct tty_struct
*pts_unix98_lookup(struct tty_driver
*driver
,
597 struct inode
*pts_inode
, int idx
)
599 struct tty_struct
*tty
;
601 mutex_lock(&devpts_mutex
);
602 tty
= devpts_get_priv(pts_inode
);
603 mutex_unlock(&devpts_mutex
);
604 /* Master must be open before slave */
606 return ERR_PTR(-EIO
);
610 /* We have no need to install and remove our tty objects as devpts does all
613 static int pty_unix98_install(struct tty_driver
*driver
, struct tty_struct
*tty
)
615 return pty_common_install(driver
, tty
, false);
618 static void pty_unix98_remove(struct tty_driver
*driver
, struct tty_struct
*tty
)
622 /* this is called once with whichever end is closed last */
623 static void pty_unix98_shutdown(struct tty_struct
*tty
)
625 struct inode
*ptmx_inode
;
627 if (tty
->driver
->subtype
== PTY_TYPE_MASTER
)
628 ptmx_inode
= tty
->driver_data
;
630 ptmx_inode
= tty
->link
->driver_data
;
631 devpts_kill_index(ptmx_inode
, tty
->index
);
632 devpts_del_ref(ptmx_inode
);
635 static const struct tty_operations ptm_unix98_ops
= {
636 .lookup
= ptm_unix98_lookup
,
637 .install
= pty_unix98_install
,
638 .remove
= pty_unix98_remove
,
642 .write_room
= pty_write_room
,
643 .flush_buffer
= pty_flush_buffer
,
644 .chars_in_buffer
= pty_chars_in_buffer
,
645 .unthrottle
= pty_unthrottle
,
646 .set_termios
= pty_set_termios
,
647 .ioctl
= pty_unix98_ioctl
,
648 .resize
= pty_resize
,
649 .shutdown
= pty_unix98_shutdown
,
650 .cleanup
= pty_cleanup
653 static const struct tty_operations pty_unix98_ops
= {
654 .lookup
= pts_unix98_lookup
,
655 .install
= pty_unix98_install
,
656 .remove
= pty_unix98_remove
,
660 .write_room
= pty_write_room
,
661 .flush_buffer
= pty_flush_buffer
,
662 .chars_in_buffer
= pty_chars_in_buffer
,
663 .unthrottle
= pty_unthrottle
,
664 .set_termios
= pty_set_termios
,
665 .shutdown
= pty_unix98_shutdown
,
666 .cleanup
= pty_cleanup
,
670 * ptmx_open - open a unix 98 pty master
671 * @inode: inode of device file
672 * @filp: file pointer to tty
674 * Allocate a unix98 pty master device from the ptmx driver.
676 * Locking: tty_mutex protects the init_dev work. tty->count should
678 * allocated_ptys_lock handles the list of free pty numbers
681 static int ptmx_open(struct inode
*inode
, struct file
*filp
)
683 struct tty_struct
*tty
;
684 struct inode
*slave_inode
;
688 nonseekable_open(inode
, filp
);
690 /* We refuse fsnotify events on ptmx, since it's a shared resource */
691 filp
->f_mode
|= FMODE_NONOTIFY
;
693 retval
= tty_alloc_file(filp
);
697 /* find a device that is not in use. */
698 mutex_lock(&devpts_mutex
);
699 index
= devpts_new_index(inode
);
702 mutex_unlock(&devpts_mutex
);
706 mutex_unlock(&devpts_mutex
);
708 mutex_lock(&tty_mutex
);
709 tty
= tty_init_dev(ptm_driver
, index
);
712 retval
= PTR_ERR(tty
);
716 /* The tty returned here is locked so we can safely
718 mutex_unlock(&tty_mutex
);
720 set_bit(TTY_PTY_LOCK
, &tty
->flags
); /* LOCK THE SLAVE */
721 tty
->driver_data
= inode
;
724 * In the case where all references to ptmx inode are dropped and we
725 * still have /dev/tty opened pointing to the master/slave pair (ptmx
726 * is closed/released before /dev/tty), we must make sure that the inode
727 * is still valid when we call the final pty_unix98_shutdown, thus we
728 * hold an additional reference to the ptmx inode. For the same /dev/tty
729 * last close case, we also need to make sure the super_block isn't
730 * destroyed (devpts instance unmounted), before /dev/tty is closed and
731 * on its release devpts_kill_index is called.
733 devpts_add_ref(inode
);
735 tty_add_file(tty
, filp
);
737 slave_inode
= devpts_pty_new(inode
,
738 MKDEV(UNIX98_PTY_SLAVE_MAJOR
, index
), index
,
740 if (IS_ERR(slave_inode
)) {
741 retval
= PTR_ERR(slave_inode
);
744 tty
->link
->driver_data
= slave_inode
;
746 retval
= ptm_driver
->ops
->open(tty
, filp
);
754 tty_release(inode
, filp
);
757 mutex_unlock(&tty_mutex
);
758 devpts_kill_index(inode
, index
);
764 static struct file_operations ptmx_fops
;
766 static void __init
unix98_pty_init(void)
768 ptm_driver
= tty_alloc_driver(NR_UNIX98_PTY_MAX
,
769 TTY_DRIVER_RESET_TERMIOS
|
770 TTY_DRIVER_REAL_RAW
|
771 TTY_DRIVER_DYNAMIC_DEV
|
772 TTY_DRIVER_DEVPTS_MEM
|
773 TTY_DRIVER_DYNAMIC_ALLOC
);
774 if (IS_ERR(ptm_driver
))
775 panic("Couldn't allocate Unix98 ptm driver");
776 pts_driver
= tty_alloc_driver(NR_UNIX98_PTY_MAX
,
777 TTY_DRIVER_RESET_TERMIOS
|
778 TTY_DRIVER_REAL_RAW
|
779 TTY_DRIVER_DYNAMIC_DEV
|
780 TTY_DRIVER_DEVPTS_MEM
|
781 TTY_DRIVER_DYNAMIC_ALLOC
);
782 if (IS_ERR(pts_driver
))
783 panic("Couldn't allocate Unix98 pts driver");
785 ptm_driver
->driver_name
= "pty_master";
786 ptm_driver
->name
= "ptm";
787 ptm_driver
->major
= UNIX98_PTY_MASTER_MAJOR
;
788 ptm_driver
->minor_start
= 0;
789 ptm_driver
->type
= TTY_DRIVER_TYPE_PTY
;
790 ptm_driver
->subtype
= PTY_TYPE_MASTER
;
791 ptm_driver
->init_termios
= tty_std_termios
;
792 ptm_driver
->init_termios
.c_iflag
= 0;
793 ptm_driver
->init_termios
.c_oflag
= 0;
794 ptm_driver
->init_termios
.c_cflag
= B38400
| CS8
| CREAD
;
795 ptm_driver
->init_termios
.c_lflag
= 0;
796 ptm_driver
->init_termios
.c_ispeed
= 38400;
797 ptm_driver
->init_termios
.c_ospeed
= 38400;
798 ptm_driver
->other
= pts_driver
;
799 tty_set_operations(ptm_driver
, &ptm_unix98_ops
);
801 pts_driver
->driver_name
= "pty_slave";
802 pts_driver
->name
= "pts";
803 pts_driver
->major
= UNIX98_PTY_SLAVE_MAJOR
;
804 pts_driver
->minor_start
= 0;
805 pts_driver
->type
= TTY_DRIVER_TYPE_PTY
;
806 pts_driver
->subtype
= PTY_TYPE_SLAVE
;
807 pts_driver
->init_termios
= tty_std_termios
;
808 pts_driver
->init_termios
.c_cflag
= B38400
| CS8
| CREAD
;
809 pts_driver
->init_termios
.c_ispeed
= 38400;
810 pts_driver
->init_termios
.c_ospeed
= 38400;
811 pts_driver
->other
= ptm_driver
;
812 tty_set_operations(pts_driver
, &pty_unix98_ops
);
814 if (tty_register_driver(ptm_driver
))
815 panic("Couldn't register Unix98 ptm driver");
816 if (tty_register_driver(pts_driver
))
817 panic("Couldn't register Unix98 pts driver");
819 /* Now create the /dev/ptmx special device */
820 tty_default_fops(&ptmx_fops
);
821 ptmx_fops
.open
= ptmx_open
;
823 cdev_init(&ptmx_cdev
, &ptmx_fops
);
824 if (cdev_add(&ptmx_cdev
, MKDEV(TTYAUX_MAJOR
, 2), 1) ||
825 register_chrdev_region(MKDEV(TTYAUX_MAJOR
, 2), 1, "/dev/ptmx") < 0)
826 panic("Couldn't register /dev/ptmx driver");
827 device_create(tty_class
, NULL
, MKDEV(TTYAUX_MAJOR
, 2), NULL
, "ptmx");
831 static inline void unix98_pty_init(void) { }
834 static int __init
pty_init(void)
840 module_init(pty_init
);