[PATCH] reiserfs_write_full_page() should not get_block past eof
[pandora-kernel.git] / fs / reiserfs / inode.c
index b33d67b..52f1e21 100644 (file)
@@ -2,7 +2,6 @@
  * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
  */
 
-#include <linux/config.h>
 #include <linux/time.h>
 #include <linux/fs.h>
 #include <linux/reiserfs_fs.h>
@@ -40,14 +39,10 @@ void reiserfs_delete_inode(struct inode *inode)
 
        /* The = 0 happens when we abort creating a new inode for some reason like lack of space.. */
        if (!(inode->i_state & I_NEW) && INODE_PKEY(inode)->k_objectid != 0) {  /* also handles bad_inode case */
-               mutex_lock(&inode->i_mutex);
-
                reiserfs_delete_xattrs(inode);
 
-               if (journal_begin(&th, inode->i_sb, jbegin_count)) {
-                       mutex_unlock(&inode->i_mutex);
+               if (journal_begin(&th, inode->i_sb, jbegin_count))
                        goto out;
-               }
                reiserfs_update_inode_transaction(inode);
 
                err = reiserfs_delete_object(&th, inode);
@@ -58,12 +53,8 @@ void reiserfs_delete_inode(struct inode *inode)
                if (!err) 
                        DQUOT_FREE_INODE(inode);
 
-               if (journal_end(&th, inode->i_sb, jbegin_count)) {
-                       mutex_unlock(&inode->i_mutex);
+               if (journal_end(&th, inode->i_sb, jbegin_count))
                        goto out;
-               }
-
-               mutex_unlock(&inode->i_mutex);
 
                /* check return value from reiserfs_delete_object after
                 * ending the transaction
@@ -466,7 +457,6 @@ static int reiserfs_get_block_create_0(struct inode *inode, sector_t block,
    direct_IO request. */
 static int reiserfs_get_blocks_direct_io(struct inode *inode,
                                         sector_t iblock,
-                                        unsigned long max_blocks,
                                         struct buffer_head *bh_result,
                                         int create)
 {
@@ -627,11 +617,6 @@ int reiserfs_get_block(struct inode *inode, sector_t block,
        reiserfs_write_lock(inode->i_sb);
        version = get_inode_item_key_version(inode);
 
-       if (block < 0) {
-               reiserfs_write_unlock(inode->i_sb);
-               return -EIO;
-       }
-
        if (!file_capable(inode, block)) {
                reiserfs_write_unlock(inode->i_sb);
                return -EFBIG;
@@ -934,12 +919,13 @@ int reiserfs_get_block(struct inode *inode, sector_t block,
                                     //pos_in_item * inode->i_sb->s_blocksize,
                                     TYPE_INDIRECT, 3); // key type is unimportant
 
+                       RFALSE(cpu_key_k_offset(&tmp_key) > cpu_key_k_offset(&key),
+                              "green-805: invalid offset");
                        blocks_needed =
                            1 +
                            ((cpu_key_k_offset(&key) -
                              cpu_key_k_offset(&tmp_key)) >> inode->i_sb->
                             s_blocksize_bits);
-                       RFALSE(blocks_needed < 0, "green-805: invalid offset");
 
                        if (blocks_needed == 1) {
                                un = &unf_single;
@@ -2354,6 +2340,7 @@ static int reiserfs_write_full_page(struct page *page,
        unsigned long end_index = inode->i_size >> PAGE_CACHE_SHIFT;
        int error = 0;
        unsigned long block;
+       sector_t last_block;
        struct buffer_head *head, *bh;
        int partial = 0;
        int nr = 0;
@@ -2401,10 +2388,19 @@ static int reiserfs_write_full_page(struct page *page,
        }
        bh = head;
        block = page->index << (PAGE_CACHE_SHIFT - s->s_blocksize_bits);
+       last_block = (i_size_read(inode) - 1) >> inode->i_blkbits;
        /* first map all the buffers, logging any direct items we find */
        do {
-               if ((checked || buffer_dirty(bh)) && (!buffer_mapped(bh) ||
-                                                     (buffer_mapped(bh)
+               if (block > last_block) {
+                       /*
+                        * This can happen when the block size is less than
+                        * the page size.  The corresponding bytes in the page
+                        * were zero filled above
+                        */
+                       clear_buffer_dirty(bh);
+                       set_buffer_uptodate(bh);
+               } else if ((checked || buffer_dirty(bh)) &&
+                          (!buffer_mapped(bh) || (buffer_mapped(bh)
                                                       && bh->b_blocknr ==
                                                       0))) {
                        /* not mapped yet, or it points to a direct item, search
@@ -2797,7 +2793,7 @@ static int invalidatepage_can_drop(struct inode *inode, struct buffer_head *bh)
 }
 
 /* clm -- taken from fs/buffer.c:block_invalidate_page */
-static int reiserfs_invalidatepage(struct page *page, unsigned long offset)
+static void reiserfs_invalidatepage(struct page *page, unsigned long offset)
 {
        struct buffer_head *head, *bh, *next;
        struct inode *inode = page->mapping->host;
@@ -2836,10 +2832,12 @@ static int reiserfs_invalidatepage(struct page *page, unsigned long offset)
         * The get_block cached value has been unconditionally invalidated,
         * so real IO is not possible anymore.
         */
-       if (!offset && ret)
+       if (!offset && ret) {
                ret = try_to_release_page(page, 0);
+               /* maybe should BUG_ON(!ret); - neilb */
+       }
       out:
-       return ret;
+       return;
 }
 
 static int reiserfs_set_page_dirty(struct page *page)
@@ -2936,6 +2934,11 @@ int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
                        }
                        if (error)
                                goto out;
+                       /*
+                        * file size is changed, ctime and mtime are
+                        * to be updated
+                        */
+                       attr->ia_valid |= (ATTR_MTIME | ATTR_CTIME);
                }
        }
 
@@ -2999,7 +3002,7 @@ int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
        return error;
 }
 
-struct address_space_operations reiserfs_address_space_operations = {
+const struct address_space_operations reiserfs_address_space_operations = {
        .writepage = reiserfs_writepage,
        .readpage = reiserfs_readpage,
        .readpages = reiserfs_readpages,