*** empty log message ***
authorcharles <charles>
Mon, 27 Oct 2003 08:27:01 +0000 (08:27 +0000)
committercharles <charles>
Mon, 27 Oct 2003 08:27:01 +0000 (08:27 +0000)
yaffs_fs.c

index 418f378bf2487a69abac6037c52e419e83a4891d..69039af0601f11f146d79178c650e5f12f5bde4a 100644 (file)
@@ -28,7 +28,7 @@
  */
 
 
-const char *yaffs_fs_c_version = "$Id: yaffs_fs.c,v 1.30 2003-09-20 01:13:48 charles Exp $";
+const char *yaffs_fs_c_version = "$Id: yaffs_fs.c,v 1.31 2003-10-27 08:27:01 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>0 ? nWritten : -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;
 }