Whamcloud - gitweb
libext2fs: fix i_blocks for extent leaf create/delete with bigalloc
authorAditya Kali <adityakali@google.com>
Mon, 11 Jun 2012 03:52:11 +0000 (23:52 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 11 Jun 2012 03:52:11 +0000 (23:52 -0400)
When libext2fs allocates/deletes an extent leaf, the i_blocks
value is incremented/decremented by fs->blocksize / 512. This
is incorrect in case of bigalloc. The correct way here is to
use cluster_size / 512.

The problem is seen if we try to create a large inode using
libext2fs (say using ext2fs_block_iterate3()) on a bigalloc
filesystem. fsck catches this and complains.

Signed-off-by: Aditya Kali <adityakali@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/ext2fs/extent.c

index eb096d6..8828764 100644 (file)
@@ -1027,7 +1027,8 @@ static errcode_t extent_node_split(ext2_extent_handle_t handle)
                goto done;
 
        /* new node hooked in, so update inode block count (do this here?) */
-       handle->inode->i_blocks += handle->fs->blocksize / 512;
+       handle->inode->i_blocks += (handle->fs->blocksize *
+                                   EXT2FS_CLUSTER_RATIO(handle->fs)) / 512;
        retval = ext2fs_write_inode(handle->fs, handle->ino,
                                    handle->inode);
        if (retval)
@@ -1501,7 +1502,9 @@ errcode_t ext2fs_extent_delete(ext2_extent_handle_t handle, int flags)
                                return retval;
 
                        retval = ext2fs_extent_delete(handle, flags);
-                       handle->inode->i_blocks -= handle->fs->blocksize / 512;
+                       handle->inode->i_blocks -=
+                               (handle->fs->blocksize *
+                                EXT2FS_CLUSTER_RATIO(handle->fs)) / 512;
                        retval = ext2fs_write_inode(handle->fs, handle->ino,
                                                    handle->inode);
                        ext2fs_block_alloc_stats2(handle->fs,