tty: remove filp from the USB tty ioctls
[linux-2.6-block.git] / drivers / tty / tty_io.c
index 35480dd57a307e72b2893d484a86783659c6a45d..83af24ca1e5e2ff683e757707a15955f8a19f436 100644 (file)
@@ -2465,12 +2465,12 @@ out:
  *     Locking: none (up to the driver)
  */
 
-static int tty_tiocmget(struct tty_struct *tty, struct file *file, int __user *p)
+static int tty_tiocmget(struct tty_struct *tty, int __user *p)
 {
        int retval = -EINVAL;
 
        if (tty->ops->tiocmget) {
-               retval = tty->ops->tiocmget(tty, file);
+               retval = tty->ops->tiocmget(tty);
 
                if (retval >= 0)
                        retval = put_user(retval, p);
@@ -2481,7 +2481,6 @@ static int tty_tiocmget(struct tty_struct *tty, struct file *file, int __user *p
 /**
  *     tty_tiocmset            -       set modem status
  *     @tty: tty device
- *     @file: user file pointer
  *     @cmd: command - clear bits, set bits or set all
  *     @p: pointer to desired bits
  *
@@ -2491,7 +2490,7 @@ static int tty_tiocmget(struct tty_struct *tty, struct file *file, int __user *p
  *     Locking: none (up to the driver)
  */
 
-static int tty_tiocmset(struct tty_struct *tty, struct file *file, unsigned int cmd,
+static int tty_tiocmset(struct tty_struct *tty, unsigned int cmd,
             unsigned __user *p)
 {
        int retval;
@@ -2518,7 +2517,7 @@ static int tty_tiocmset(struct tty_struct *tty, struct file *file, unsigned int
        }
        set &= TIOCM_DTR|TIOCM_RTS|TIOCM_OUT1|TIOCM_OUT2|TIOCM_LOOP;
        clear &= TIOCM_DTR|TIOCM_RTS|TIOCM_OUT1|TIOCM_OUT2|TIOCM_LOOP;
-       return tty->ops->tiocmset(tty, file, set, clear);
+       return tty->ops->tiocmset(tty, set, clear);
 }
 
 static int tty_tiocgicount(struct tty_struct *tty, void __user *arg)
@@ -2627,6 +2626,11 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                return put_user(tty->ldisc->ops->num, (int __user *)p);
        case TIOCSETD:
                return tiocsetd(tty, p);
+       case TIOCGDEV:
+       {
+               unsigned int ret = new_encode_dev(tty_devnum(real_tty));
+               return put_user(ret, (unsigned int __user *)p);
+       }
        /*
         * Break handling
         */
@@ -2650,11 +2654,11 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                return send_break(tty, arg ? arg*100 : 250);
 
        case TIOCMGET:
-               return tty_tiocmget(tty, file, p);
+               return tty_tiocmget(tty, p);
        case TIOCMSET:
        case TIOCMBIC:
        case TIOCMBIS:
-               return tty_tiocmset(tty, file, cmd, p);
+               return tty_tiocmset(tty, cmd, p);
        case TIOCGICOUNT:
                retval = tty_tiocgicount(tty, p);
                /* For the moment allow fall through to the old method */
@@ -3241,9 +3245,45 @@ static int __init tty_class_init(void)
 postcore_initcall(tty_class_init);
 
 /* 3/2004 jmc: why do these devices exist? */
-
 static struct cdev tty_cdev, console_cdev;
 
+static ssize_t show_cons_active(struct device *dev,
+                               struct device_attribute *attr, char *buf)
+{
+       struct console *cs[16];
+       int i = 0;
+       struct console *c;
+       ssize_t count = 0;
+
+       console_lock();
+       for_each_console(c) {
+               if (!c->device)
+                       continue;
+               if (!c->write)
+                       continue;
+               if ((c->flags & CON_ENABLED) == 0)
+                       continue;
+               cs[i++] = c;
+               if (i >= ARRAY_SIZE(cs))
+                       break;
+       }
+       while (i--)
+               count += sprintf(buf + count, "%s%d%c",
+                                cs[i]->name, cs[i]->index, i ? ' ':'\n');
+       console_unlock();
+
+       return count;
+}
+static DEVICE_ATTR(active, S_IRUGO, show_cons_active, NULL);
+
+static struct device *consdev;
+
+void console_sysfs_notify(void)
+{
+       if (consdev)
+               sysfs_notify(&consdev->kobj, NULL, "active");
+}
+
 /*
  * Ok, now we can initialize the rest of the tty devices and can count
  * on memory allocations, interrupts etc..
@@ -3254,15 +3294,18 @@ int __init tty_init(void)
        if (cdev_add(&tty_cdev, MKDEV(TTYAUX_MAJOR, 0), 1) ||
            register_chrdev_region(MKDEV(TTYAUX_MAJOR, 0), 1, "/dev/tty") < 0)
                panic("Couldn't register /dev/tty driver\n");
-       device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 0), NULL,
-                             "tty");
+       device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 0), NULL, "tty");
 
        cdev_init(&console_cdev, &console_fops);
        if (cdev_add(&console_cdev, MKDEV(TTYAUX_MAJOR, 1), 1) ||
            register_chrdev_region(MKDEV(TTYAUX_MAJOR, 1), 1, "/dev/console") < 0)
                panic("Couldn't register /dev/console driver\n");
-       device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 1), NULL,
+       consdev = device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 1), NULL,
                              "console");
+       if (IS_ERR(consdev))
+               consdev = NULL;
+       else
+               WARN_ON(device_create_file(consdev, &dev_attr_active) < 0);
 
 #ifdef CONFIG_VT
        vty_init(&console_fops);