Fix an error in writepage when a file is extended.
authorluc <luc>
Thu, 4 Aug 2005 22:47:36 +0000 (22:47 +0000)
committerluc <luc>
Thu, 4 Aug 2005 22:47:36 +0000 (22:47 +0000)
When a file is extended with truncate(), the call to inode_setattr() in yaffs_setattr()
call vmtruncate() which itself call a bunches of yaffs_writepage().
There we must NOT fill page whit index greater that the one given by the inode
'cos these pages refers to parts of the file which doesn't physically exists.

yaffs_fs.c

index 4ae8a6e9309fd207f8c60ef0f23f7a926e37513c..35d0f41a8b7bc11fc91dcd4036591572a2ebce3d 100644 (file)
@@ -30,7 +30,7 @@
  */
 
 
  */
 
 
-const char *yaffs_fs_c_version = "$Id: yaffs_fs.c,v 1.26 2005-08-01 21:02:22 luc Exp $";
+const char *yaffs_fs_c_version = "$Id: yaffs_fs.c,v 1.27 2005-08-04 22:47:36 luc Exp $";
 extern const char *yaffs_guts_c_version;
 
 
 extern const char *yaffs_guts_c_version;
 
 
@@ -488,6 +488,7 @@ static int yaffs_writepage(struct page *page)
 #endif
 {
        struct address_space *mapping = page->mapping;
 #endif
 {
        struct address_space *mapping = page->mapping;
+       loff_t offset = (loff_t)page->index << PAGE_CACHE_SHIFT;
        struct inode *inode;
        unsigned long end_index;
        char *buffer;
        struct inode *inode;
        unsigned long end_index;
        char *buffer;
@@ -501,6 +502,14 @@ static int yaffs_writepage(struct page *page)
        if (!inode)
                BUG();
 
        if (!inode)
                BUG();
 
+       if (offset > inode->i_size)
+       {
+               T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_writepage at %08x, inode size = %08x!!!\n", (unsigned)(page->index << PAGE_CACHE_SHIFT), (unsigned) inode->i_size));
+               T(YAFFS_TRACE_OS,(KERN_DEBUG"                -> don't care!!\n"));
+               unlock_page(page);
+               return 0;
+       }
+
        end_index = inode->i_size >> PAGE_CACHE_SHIFT;
 
        /* easy case */
        end_index = inode->i_size >> PAGE_CACHE_SHIFT;
 
        /* easy case */
@@ -525,9 +534,13 @@ static int yaffs_writepage(struct page *page)
        obj = yaffs_InodeToObject(inode);
        yaffs_GrossLock(obj->myDev);
 
        obj = yaffs_InodeToObject(inode);
        yaffs_GrossLock(obj->myDev);
 
+       T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_writepage at %08x, size %08x\n", (unsigned)(page->index << PAGE_CACHE_SHIFT), nBytes));
+       T(YAFFS_TRACE_OS,(KERN_DEBUG"writepag0: obj = %05x, ino = %05x\n", (int) obj->variant.fileVariant.fileSize, (int) inode->i_size));
 
        nWritten = yaffs_WriteDataToFile(obj,buffer,page->index << PAGE_CACHE_SHIFT,nBytes,0);
 
 
        nWritten = yaffs_WriteDataToFile(obj,buffer,page->index << PAGE_CACHE_SHIFT,nBytes,0);
 
+       T(YAFFS_TRACE_OS,(KERN_DEBUG"writepag1: obj = %05x, ino = %05x\n", (int) obj->variant.fileVariant.fileSize, (int) inode->i_size));
+
        yaffs_GrossUnlock(obj->myDev);
        
        kunmap(page);
        yaffs_GrossUnlock(obj->myDev);
        
        kunmap(page);