vserver 1.9.5.x5
[linux-2.6.git] / drivers / mtd / mtdchar.c
index 3db73d8..3792140 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: mtdchar.c,v 1.64 2004/08/09 13:59:46 dwmw2 Exp $
+ * $Id: mtdchar.c,v 1.66 2005/01/05 18:05:11 dwmw2 Exp $
  *
  * Character-device access to raw MTD devices.
  *
@@ -61,7 +61,7 @@ static inline void mtdchar_devfs_exit(void)
 
 static loff_t mtd_lseek (struct file *file, loff_t offset, int orig)
 {
-       struct mtd_info *mtd=(struct mtd_info *)file->private_data;
+       struct mtd_info *mtd = file->private_data;
 
        switch (orig) {
        case 0:
@@ -134,7 +134,7 @@ static int mtd_close(struct inode *inode, struct file *file)
 
        DEBUG(MTD_DEBUG_LEVEL0, "MTD_close\n");
 
-       mtd = (struct mtd_info *)file->private_data;
+       mtd = file->private_data;
        
        if (mtd->sync)
                mtd->sync(mtd);
@@ -151,7 +151,7 @@ static int mtd_close(struct inode *inode, struct file *file)
 
 static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t *ppos)
 {
-       struct mtd_info *mtd = (struct mtd_info *)file->private_data;
+       struct mtd_info *mtd = file->private_data;
        size_t retlen=0;
        size_t total_retlen=0;
        int ret=0;
@@ -179,7 +179,13 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t
                        return -ENOMEM;
                
                ret = MTD_READ(mtd, *ppos, len, &retlen, kbuf);
-               if (!ret) {
+               /* Nand returns -EBADMSG on ecc errors, but it returns
+                * the data. For our userspace tools it is important
+                * to dump areas with ecc errors ! 
+                * Userspace software which accesses NAND this way
+                * must be aware of the fact that it deals with NAND
+                */
+               if (!ret || (ret == -EBADMSG)) {
                        *ppos += retlen;
                        if (copy_to_user(buf, kbuf, retlen)) {
                                kfree(kbuf);
@@ -198,13 +204,13 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t
                
                kfree(kbuf);
        }
-       
+
        return total_retlen;
 } /* mtd_read */
 
 static ssize_t mtd_write(struct file *file, const char __user *buf, size_t count,loff_t *ppos)
 {
-       struct mtd_info *mtd = (struct mtd_info *)file->private_data;
+       struct mtd_info *mtd = file->private_data;
        char *kbuf;
        size_t retlen;
        size_t total_retlen=0;
@@ -270,7 +276,7 @@ static void mtdchar_erase_callback (struct erase_info *instr)
 static int mtd_ioctl(struct inode *inode, struct file *file,
                     u_int cmd, u_long arg)
 {
-       struct mtd_info *mtd = (struct mtd_info *)file->private_data;
+       struct mtd_info *mtd = file->private_data;
        void __user *argp = (void __user *)arg;
        int ret = 0;
        u_long size;