fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / arch / um / drivers / mmapper_kern.c
index 1862691..df3516e 100644 (file)
@@ -8,17 +8,12 @@
  *         Greg Lonnon glonnon@ridgerun.com or info@ridgerun.com
  *
  */
-#include <linux/kdev_t.h>
-#include <linux/time.h>
-#include <linux/devfs_fs_kernel.h>
+
+#include <linux/init.h> 
 #include <linux/module.h>
 #include <linux/mm.h> 
-#include <linux/slab.h>
-#include <linux/init.h> 
-#include <linux/smp_lock.h>
+#include <linux/miscdevice.h>
 #include <asm/uaccess.h>
-#include <asm/irq.h>
-#include <asm/pgtable.h>
 #include "mem_user.h"
 #include "user_util.h"
  
@@ -28,35 +23,22 @@ static unsigned long p_buf = 0;
 static char *v_buf = NULL;
 
 static ssize_t
-mmapper_read(struct file *file, char *buf, size_t count, loff_t *ppos)
+mmapper_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
 {
-       if(*ppos > mmapper_size)
-               return -EINVAL;
-
-       if(count + *ppos > mmapper_size)
-               count = count + *ppos - mmapper_size;
-
-       if(count < 0)
-               return -EINVAL;
-       copy_to_user(buf,&v_buf[*ppos],count);
-       
-       return count;
+       return simple_read_from_buffer(buf, count, ppos, v_buf, mmapper_size);
 }
 
 static ssize_t
-mmapper_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
+mmapper_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
 {
-       if(*ppos > mmapper_size)
+       if (*ppos > mmapper_size)
                return -EINVAL;
 
-       if(count + *ppos > mmapper_size)
-               count = count + *ppos - mmapper_size;
-
-       if(count < 0)
-               return -EINVAL;
+       if (count > mmapper_size - *ppos)
+               count = mmapper_size - *ppos;
 
-       copy_from_user(&v_buf[*ppos],buf,count);
+       if (copy_from_user(&v_buf[*ppos], buf, count))
+               return -EFAULT;
        
        return count;
 }
@@ -74,22 +56,20 @@ mmapper_mmap(struct file *file, struct vm_area_struct * vma)
        int ret = -EINVAL;
        int size;
 
-       lock_kernel();
        if (vma->vm_pgoff != 0)
                goto out;
        
        size = vma->vm_end - vma->vm_start;
        if(size > mmapper_size) return(-EFAULT);
 
-       /* XXX A comment above remap_page_range says it should only be
+       /* XXX A comment above remap_pfn_range says it should only be
         * called when the mm semaphore is held
         */
-       if (remap_page_range(vma, vma->vm_start, p_buf, size, 
+       if (remap_pfn_range(vma, vma->vm_start, p_buf >> PAGE_SHIFT, size,
                             vma->vm_page_prot))
                goto out;
        ret = 0;
 out:
-       unlock_kernel();
        return ret;
 }
 
@@ -105,7 +85,7 @@ mmapper_release(struct inode *inode, struct file *file)
        return 0;
 }
 
-static struct file_operations mmapper_fops = {
+static const struct file_operations mmapper_fops = {
        .owner          = THIS_MODULE,
        .read           = mmapper_read,
        .write          = mmapper_write,
@@ -115,25 +95,40 @@ static struct file_operations mmapper_fops = {
        .release        = mmapper_release,
 };
 
+/* No locking needed - only used (and modified) by below initcall and exitcall. */
+static struct miscdevice mmapper_dev = {
+       .minor          = MISC_DYNAMIC_MINOR,
+       .name           = "mmapper",
+       .fops           = &mmapper_fops
+};
+
 static int __init mmapper_init(void)
 {
+       int err;
+
        printk(KERN_INFO "Mapper v0.1\n");
 
        v_buf = (char *) find_iomem("mmapper", &mmapper_size);
        if(mmapper_size == 0){
                printk(KERN_ERR "mmapper_init - find_iomem failed\n");
-               return(0);
+               goto out;
        }
 
-       p_buf = __pa(v_buf);
+       err = misc_register(&mmapper_dev);
+       if(err){
+               printk(KERN_ERR "mmapper - misc_register failed, err = %d\n",
+                      err);
+               goto out;
+       }
 
-       devfs_mk_cdev(MKDEV(30, 0), S_IFCHR|S_IRUGO|S_IWUGO, "mmapper");
-       devfs_mk_symlink("mmapper0", "mmapper");
-       return(0);
+       p_buf = __pa(v_buf);
+out:
+       return 0;
 }
 
 static void mmapper_exit(void)
 {
+       misc_deregister(&mmapper_dev);
 }
 
 module_init(mmapper_init);