]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/char/pty.c
tty: Finish fixing up the init_dev interface to use ERR_PTR
[linux-2.6-omap-h63xx.git] / drivers / char / pty.c
index 328e8ac1230667d5b8b015dfa65c541279311505..c98450023030304611dda20532098bb4caf6bd92 100644 (file)
@@ -391,6 +391,41 @@ static int pty_unix98_ioctl(struct tty_struct *tty, struct file *file,
        return -ENOIOCTLCMD;
 }
 
+/**
+ *     ptm_unix98_lookup       -       find a pty master
+ *     @driver: ptm driver
+ *     @idx: tty index
+ *
+ *     Look up a pty master device. Called under the tty_mutex for now.
+ *     This provides our locking.
+ */
+
+static struct tty_struct *ptm_unix98_lookup(struct tty_driver *driver, int idx)
+{
+       struct tty_struct *tty = devpts_get_tty(idx);
+       if (tty)
+               tty = tty->link;
+       return tty;
+}
+
+/**
+ *     pts_unix98_lookup       -       find a pty slave
+ *     @driver: pts driver
+ *     @idx: tty index
+ *
+ *     Look up a pty master device. Called under the tty_mutex for now.
+ *     This provides our locking.
+ */
+
+static struct tty_struct *pts_unix98_lookup(struct tty_driver *driver, int idx)
+{
+       struct tty_struct *tty = devpts_get_tty(idx);
+       /* Master must be open before slave */
+       if (!tty)
+               return ERR_PTR(-EIO);
+       return tty;
+}
+
 static void pty_shutdown(struct tty_struct *tty)
 {
        /* We have our own method as we don't use the tty index */
@@ -398,7 +433,22 @@ static void pty_shutdown(struct tty_struct *tty)
        kfree(tty->termios_locked);
 }
 
+/* We have no need to install and remove our tty objects as devpts does all
+   the work for us */
+
+static int pty_install(struct tty_driver *driver, struct tty_struct *tty)
+{
+       return 0;
+}
+
+static void pty_remove(struct tty_driver *driver, struct tty_struct *tty)
+{
+}
+
 static const struct tty_operations ptm_unix98_ops = {
+       .lookup = ptm_unix98_lookup,
+       .install = pty_install,
+       .remove = pty_remove,
        .open = pty_open,
        .close = pty_close,
        .write = pty_write,
@@ -411,6 +461,19 @@ static const struct tty_operations ptm_unix98_ops = {
        .shutdown = pty_shutdown
 };
 
+static const struct tty_operations pty_unix98_ops = {
+       .lookup = pts_unix98_lookup,
+       .install = pty_install,
+       .remove = pty_remove,
+       .open = pty_open,
+       .close = pty_close,
+       .write = pty_write,
+       .write_room = pty_write_room,
+       .flush_buffer = pty_flush_buffer,
+       .chars_in_buffer = pty_chars_in_buffer,
+       .unthrottle = pty_unthrottle,
+       .set_termios = pty_set_termios,
+};
 
 /**
  *     ptmx_open               -       open a unix 98 pty master
@@ -438,11 +501,13 @@ static int __ptmx_open(struct inode *inode, struct file *filp)
                return index;
 
        mutex_lock(&tty_mutex);
-       retval = tty_init_dev(ptm_driver, index, &tty, 1);
+       tty = tty_init_dev(ptm_driver, index, 1);
        mutex_unlock(&tty_mutex);
 
-       if (retval)
+       if (IS_ERR(tty)) {
+               retval = PTR_ERR(tty);
                goto out;
+       }
 
        set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */
        filp->private_data = tty;
@@ -517,15 +582,18 @@ static void __init unix98_pty_init(void)
        pts_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW |
                TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_DEVPTS_MEM;
        pts_driver->other = ptm_driver;
-       tty_set_operations(pts_driver, &pty_ops);
+       tty_set_operations(pts_driver, &pty_unix98_ops);
        
        if (tty_register_driver(ptm_driver))
                panic("Couldn't register Unix98 ptm driver");
        if (tty_register_driver(pts_driver))
                panic("Couldn't register Unix98 pts driver");
 
+       /* FIXME: WTF */
+#if 0  
        pty_table[1].data = &ptm_driver->refcount;
-       register_sysctl_table(pty_root_table);
+#endif 
+       register_sysctl_table(pty_root_table);  
 
        /* Now create the /dev/ptmx special device */
        tty_default_fops(&ptmx_fops);