*** empty log message ***
[yaffs/.git] / yaffs_fs.c
index 080d875d1d52c2ef3df44f66c4b86c15569d15a1..c0b101ae6688becef805553f9c2eb4bae03b03a0 100644 (file)
@@ -28,7 +28,7 @@
  */
 
 
-const char *yaffs_fs_c_version = "$Id: yaffs_fs.c,v 1.29 2003-08-30 05:15:49 charles Exp $";
+const char *yaffs_fs_c_version = "$Id: yaffs_fs.c,v 1.32 2003-10-29 20:42:34 charles Exp $";
 extern const char *yaffs_guts_c_version;
 
 
@@ -142,7 +142,7 @@ static void yaffs_delete_inode(struct inode *);
 static void yaffs_clear_inode(struct inode *);
 
 static int yaffs_readpage(struct file *file, struct page * page);
-
+static int yaffs_writepage(struct page *page);
 static int yaffs_prepare_write(struct file *f, struct page *pg, unsigned offset, unsigned to);
 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset, unsigned to);
 
@@ -154,6 +154,7 @@ static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
 
 static struct address_space_operations yaffs_file_address_operations = {
        readpage:               yaffs_readpage,
+       writepage:              yaffs_writepage,
        prepare_write:  yaffs_prepare_write,
        commit_write:   yaffs_commit_write
 };
@@ -413,12 +414,12 @@ static int yaffs_readpage_nolock(struct file *f, struct page * pg)
        // Lifted from jffs2
        
        yaffs_Object *obj;
-       unsigned char *pg_buf;  
+       unsigned char *pg_buf;
        int ret;
-       
+
        yaffs_Device *dev;
-       
-       T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readpage at %08x, size %08x\n", 
+
+       T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readpage at %08x, size %08x\n",
                      (unsigned)(pg->index << PAGE_CACHE_SHIFT), (unsigned)PAGE_CACHE_SIZE));
 
        obj  = yaffs_DentryToObject(f->f_dentry);
@@ -468,6 +469,63 @@ static int yaffs_readpage(struct file *f, struct page * pg)
        return yaffs_readpage_unlock(f,pg);
 }
 
+// writepage inspired by/stolen from smbfs
+//
+
+static int yaffs_writepage(struct page *page)
+{
+       struct address_space *mapping = page->mapping;
+       struct inode *inode;
+       unsigned long end_index;
+       char *buffer;
+       yaffs_Object *obj;
+       int nWritten = 0;
+       unsigned nBytes;
+
+       if (!mapping)
+               BUG();
+       inode = mapping->host;
+       if (!inode)
+               BUG();
+
+       end_index = inode->i_size >> PAGE_CACHE_SHIFT;
+
+       /* easy case */
+       if (page->index < end_index)
+       {
+               nBytes = PAGE_CACHE_SIZE;
+       }
+       else
+       {
+               nBytes = inode->i_size & (PAGE_CACHE_SIZE-1);
+       }
+       //  What's happening here?
+       ///* OK, are we completely out? */
+       //if (page->index >= end_index+1 || !offset)
+       //      return -EIO;
+
+       get_page(page);
+
+
+       buffer = kmap(page);
+
+       obj = yaffs_InodeToObject(inode);
+       yaffs_GrossLock(obj->myDev);
+
+
+       nWritten = yaffs_WriteDataToFile(obj,buffer,page->index << PAGE_CACHE_SHIFT,nBytes);
+
+       yaffs_GrossUnlock(obj->myDev);
+       
+       kunmap(page);
+       SetPageUptodate(page);
+       UnlockPage(page);
+       put_page(page);
+
+       return (nWritten == nBytes) ? 0  : -ENOSPC;
+}
+
+
 
 static int yaffs_prepare_write(struct file *f, struct page *pg, unsigned offset, unsigned to)
 {
@@ -648,7 +706,7 @@ static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_
        dev = obj->myDev;
        
        yaffs_GrossLock(dev);
-       
+
        inode = f->f_dentry->d_inode;
 
        if(!S_ISBLK(inode->i_mode) && f->f_flags & O_APPEND)
@@ -688,7 +746,7 @@ static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_
        }
        yaffs_GrossUnlock(dev);
        
-       return nWritten != n ? -ENOSPC : nWritten;      
+       return nWritten != n ? -ENOSPC : nWritten;
 }
 
 
@@ -1247,7 +1305,13 @@ static struct super_block *yaffs_internal_read_super(int useRam, struct super_bl
                printk(KERN_DEBUG "yaffs: Attempting MTD mount on %u.%u, \"%s\"\n",
                 MAJOR(sb->s_dev),MINOR(sb->s_dev),kdevname(sb->s_dev));
                        
-               // Hope it's a NAND mtd
+               // Check it's an mtd device.....
+               if(MAJOR(sb->s_dev) != MTD_BLOCK_MAJOR)
+               {
+                       return NULL; // This isn't an mtd device
+               } 
+               
+               // Get the device
                mtd = get_mtd_device(NULL, MINOR(sb->s_dev));
                if (!mtd) 
                {
@@ -1255,6 +1319,7 @@ static struct super_block *yaffs_internal_read_super(int useRam, struct super_bl
                        return NULL;
                }
                
+               // Check it's NAND
                if(mtd->type != MTD_NANDFLASH)
                {
                        printk(KERN_DEBUG "yaffs: MTD device is not NAND it's type %d\n", mtd->type);