VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / drivers / char / raw.c
index e58dab4..a2e33ec 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/capability.h>
 #include <linux/uio.h>
 #include <linux/cdev.h>
+#include <linux/device.h>
 
 #include <asm/uaccess.h>
 
@@ -26,6 +27,7 @@ struct raw_device_data {
        int inuse;
 };
 
+static struct class_simple *raw_class;
 static struct raw_device_data raw_devices[MAX_RAW_MINORS];
 static DECLARE_MUTEX(raw_mutex);
 static struct file_operations raw_ctl_fops;         /* forward declaration */
@@ -123,6 +125,13 @@ raw_ioctl(struct inode *inode, struct file *filp,
        return ioctl_by_bdev(bdev, command, arg);
 }
 
+static void bind_device(struct raw_config_request *rq)
+{
+       class_simple_device_remove(MKDEV(RAW_MAJOR, rq->raw_minor));
+       class_simple_device_add(raw_class, MKDEV(RAW_MAJOR, rq->raw_minor),
+                                     NULL, "raw%d", rq->raw_minor);
+}
+
 /*
  * Deal with ioctls against the raw-device control interface, to bind
  * and unbind other raw devices.
@@ -140,7 +149,7 @@ static int raw_ctl_ioctl(struct inode *inode, struct file *filp,
 
                /* First, find out which raw minor we want */
 
-               if (copy_from_user(&rq, (void *) arg, sizeof(rq))) {
+               if (copy_from_user(&rq, (void __user *) arg, sizeof(rq))) {
                        err = -EFAULT;
                        goto out;
                }
@@ -191,12 +200,16 @@ static int raw_ctl_ioctl(struct inode *inode, struct file *filp,
                        if (rq.block_major == 0 && rq.block_minor == 0) {
                                /* unbind */
                                rawdev->binding = NULL;
+                               class_simple_device_remove(MKDEV(RAW_MAJOR,
+                                                               rq.raw_minor));
                        } else {
                                rawdev->binding = bdget(dev);
                                if (rawdev->binding == NULL)
                                        err = -ENOMEM;
-                               else
+                               else {
                                        __module_get(THIS_MODULE);
+                                       bind_device(&rq);
+                               }
                        }
                        up(&raw_mutex);
                } else {
@@ -211,7 +224,7 @@ static int raw_ctl_ioctl(struct inode *inode, struct file *filp,
                                rq.block_major = rq.block_minor = 0;
                        }
                        up(&raw_mutex);
-                       if (copy_to_user((void *)arg, &rq, sizeof(rq))) {
+                       if (copy_to_user((void __user *)arg, &rq, sizeof(rq))) {
                                err = -EFAULT;
                                goto out;
                        }
@@ -225,18 +238,24 @@ out:
        return err;
 }
 
-static ssize_t raw_file_write(struct file *file, const char *buf,
+static ssize_t raw_file_write(struct file *file, const char __user *buf,
                                   size_t count, loff_t *ppos)
 {
-       struct iovec local_iov = { .iov_base = (void *)buf, .iov_len = count };
+       struct iovec local_iov = {
+               .iov_base = (char __user *)buf,
+               .iov_len = count
+       };
 
        return generic_file_write_nolock(file, &local_iov, 1, ppos);
 }
 
-static ssize_t raw_file_aio_write(struct kiocb *iocb, const char *buf,
+static ssize_t raw_file_aio_write(struct kiocb *iocb, const char __user *buf,
                                        size_t count, loff_t pos)
 {
-       struct iovec local_iov = { .iov_base = (void *)buf, .iov_len = count };
+       struct iovec local_iov = {
+               .iov_base = (char __user *)buf,
+               .iov_len = count
+       };
 
        return generic_file_aio_write_nolock(iocb, &local_iov, 1, &iocb->ki_pos);
 }
@@ -281,6 +300,15 @@ static int __init raw_init(void)
                goto error;
        }
 
+       raw_class = class_simple_create(THIS_MODULE, "raw");
+       if (IS_ERR(raw_class)) {
+               printk(KERN_ERR "Error creating raw class.\n");
+               cdev_del(&raw_cdev);
+               unregister_chrdev_region(dev, MAX_RAW_MINORS);
+               goto error;
+       }
+       class_simple_device_add(raw_class, MKDEV(RAW_MAJOR, 0), NULL, "rawctl");
+
        devfs_mk_cdev(MKDEV(RAW_MAJOR, 0),
                      S_IFCHR | S_IRUGO | S_IWUGO,
                      "raw/rawctl");
@@ -303,6 +331,8 @@ static void __exit raw_exit(void)
                devfs_remove("raw/raw%d", i);
        devfs_remove("raw/rawctl");
        devfs_remove("raw");
+       class_simple_device_remove(MKDEV(RAW_MAJOR, 0));
+       class_simple_destroy(raw_class);
        cdev_del(&raw_cdev);
        unregister_chrdev_region(MKDEV(RAW_MAJOR, 0), MAX_RAW_MINORS);
 }