patch-2.1.115 linux/drivers/char/pty.c

Next file: linux/drivers/char/radio-aimslab.c
Previous file: linux/drivers/char/psaux.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.114/linux/drivers/char/pty.c linux/drivers/char/pty.c
@@ -35,9 +35,9 @@
 #define PTY_MAGIC 0x5001
 
 static struct tty_driver pty_driver, pty_slave_driver;
-static struct tty_driver old_pty_driver, old_pty_slave_driver;
 static int pty_refcount;
 
+/* Note: one set of tables for BSD and one for Unix98 */
 static struct tty_struct *pty_table[NR_PTYS];
 static struct termios *pty_termios[NR_PTYS];
 static struct termios *pty_termios_locked[NR_PTYS];
@@ -46,6 +46,20 @@
 static struct termios *ttyp_termios_locked[NR_PTYS];
 static struct pty_struct pty_state[NR_PTYS];
 
+#ifdef CONFIG_UNIX98_PTYS
+/* These are global because they are accessed in tty_io.c */
+struct tty_driver ptm_driver[UNIX98_NR_MAJORS];
+struct tty_driver pts_driver[UNIX98_NR_MAJORS];
+
+static struct tty_struct *ptm_table[UNIX98_NR_MAJORS][NR_PTYS];
+static struct termios *ptm_termios[UNIX98_NR_MAJORS][NR_PTYS];
+static struct termios *ptm_termios_locked[UNIX98_NR_MAJORS][NR_PTYS];
+static struct tty_struct *pts_table[UNIX98_NR_MAJORS][NR_PTYS];
+static struct termios *pts_termios[UNIX98_NR_MAJORS][NR_PTYS];
+static struct termios *pts_termios_locked[UNIX98_NR_MAJORS][NR_PTYS];
+static struct pty_struct ptm_state[UNIX98_NR_MAJORS][NR_PTYS];
+#endif
+
 #define MIN(a,b)	((a) < (b) ? (a) : (b))
 
 static void pty_close(struct tty_struct * tty, struct file * filp)
@@ -267,7 +281,7 @@
 	line = MINOR(tty->device) - tty->driver.minor_start;
 	if ((line < 0) || (line >= NR_PTYS))
 		goto out;
-	pty = pty_state + line;
+	pty = (struct pty_struct *)(tty->driver.driver_state) + line;
 	tty->driver_data = pty;
 
 	retval = -EIO;
@@ -294,6 +308,10 @@
 
 __initfunc(int pty_init(void))
 {
+	int i;
+
+	/* Traditional BSD devices */
+
 	memset(&pty_state, 0, sizeof(pty_state));
 	memset(&pty_driver, 0, sizeof(struct tty_driver));
 	pty_driver.magic = TTY_DRIVER_MAGIC;
@@ -314,6 +332,7 @@
 	pty_driver.table = pty_table;
 	pty_driver.termios = pty_termios;
 	pty_driver.termios_locked = pty_termios_locked;
+	pty_driver.driver_state = pty_state;
 	pty_driver.other = &pty_slave_driver;
 
 	pty_driver.open = pty_open;
@@ -337,37 +356,58 @@
 	pty_slave_driver.table = ttyp_table;
 	pty_slave_driver.termios = ttyp_termios;
 	pty_slave_driver.termios_locked = ttyp_termios_locked;
+	pty_slave_driver.driver_state = pty_state;
 	pty_slave_driver.other = &pty_driver;
 
-	old_pty_driver = pty_driver;
-	old_pty_driver.driver_name = "compat_pty_master";
-	old_pty_driver.proc_entry = 0;
-	old_pty_driver.major = TTY_MAJOR;
-	old_pty_driver.minor_start = 128;
-	old_pty_driver.num = (NR_PTYS > 64) ? 64 : NR_PTYS;
-	old_pty_driver.other = &old_pty_slave_driver;
-	
-	old_pty_slave_driver = pty_slave_driver;
-	old_pty_slave_driver.driver_name = "compat_pty_slave";
-	old_pty_slave_driver.proc_entry = 0;
-	old_pty_slave_driver.major = TTY_MAJOR;
-	old_pty_slave_driver.minor_start = 192;
-	old_pty_slave_driver.num = (NR_PTYS > 64) ? 64 : NR_PTYS;
-	old_pty_slave_driver.other = &old_pty_driver;
+	if (tty_register_driver(&pty_driver))
+		panic("Couldn't register pty driver");
+	if (tty_register_driver(&pty_slave_driver))
+		panic("Couldn't register pty slave driver");
 
-	/* only the master pty gets this ioctl (which is why we
+	/* 
+	 * only the master pty gets this ioctl (which is why we
 	 * assign it here, instead of up with the rest of the
 	 * pty_driver initialization. <cananian@alumni.princeton.edu>
 	 */
 	pty_driver.ioctl = pty_ioctl;
 
-	if (tty_register_driver(&pty_driver))
-		panic("Couldn't register pty driver");
-	if (tty_register_driver(&pty_slave_driver))
-		panic("Couldn't register pty slave driver");
-	if (tty_register_driver(&old_pty_driver))
-		panic("Couldn't register compat pty driver");
-	if (tty_register_driver(&old_pty_slave_driver))
-		panic("Couldn't register compat pty slave driver");
+	/* Unix98 devices */
+#ifdef CONFIG_UNIX98_PTYS
+	printk("pty: %d Unix98 ptys configured\n", UNIX98_NR_MAJORS*NR_PTYS);
+	for ( i = 0 ; i < UNIX98_NR_MAJORS ; i++ ) {
+		ptm_driver[i] = pty_driver;
+		ptm_driver[i].name = "ptm";
+		ptm_driver[i].proc_entry = 0;
+		ptm_driver[i].major = UNIX98_PTY_MASTER_MAJOR+i;
+		ptm_driver[i].minor_start = 0;
+		ptm_driver[i].num = NR_PTYS;
+		ptm_driver[i].other = &pts_driver[i];
+		ptm_driver[i].table = ptm_table[i];
+		ptm_driver[i].termios = ptm_termios[i];
+		ptm_driver[i].termios_locked = ptm_termios_locked[i];
+		ptm_driver[i].driver_state = ptm_state[i];
+		
+		pts_driver[i] = pty_slave_driver;
+		pts_driver[i].name = "pts";
+		pts_driver[i].proc_entry = 0;
+		pts_driver[i].major = UNIX98_PTY_SLAVE_MAJOR+i;
+		pts_driver[i].minor_start = 0;
+		pts_driver[i].num = ptm_driver[i].num;
+		pts_driver[i].other = &ptm_driver[i];
+		pts_driver[i].table = pts_table[i];
+		pts_driver[i].termios = pts_termios[i];
+		pts_driver[i].termios_locked = pts_termios_locked[i];
+		pts_driver[i].driver_state = ptm_state[i];
+		
+		ptm_driver[i].ioctl = pty_ioctl;
+		
+		if (tty_register_driver(&ptm_driver[i]))
+			panic("Couldn't register Unix98 ptm driver major %d",
+			      ptm_driver[i].major);
+		if (tty_register_driver(&pts_driver[i]))
+			panic("Couldn't register Unix98 pts driver major %d",
+			      pts_driver[i].major);
+	}
+#endif
 	return 0;
 }

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov