Whamcloud - gitweb
libext2fs: fix block iterator when the callback function modifies an extent
authorTheodore Ts'o <tytso@mit.edu>
Sun, 10 Jul 2011 02:25:52 +0000 (22:25 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 10 Jul 2011 02:25:52 +0000 (22:25 -0400)
If the callback interator modifies a block in the middle of an extent
during a call to the block iterator, causing the extent to be split,
ext2_block_iterate3() will end up calling the callback function twice
for some number of blocks.  Fix this.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
lib/ext2fs/block.c

index 0e4ec77..95ad31e 100644 (file)
@@ -453,6 +453,17 @@ errcode_t ext2fs_block_iterate3(ext2_filsys fs,
                        uninit = 0;
                        if (extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT)
                                uninit = EXT2_EXTENT_SET_BMAP_UNINIT;
+#if 0
+                       printf("lblk %llu pblk %llu len %d blockcnt %llu\n",
+                              extent.e_lblk, extent.e_pblk,
+                              extent.e_len, blockcnt);
+#endif
+                       if (extent.e_lblk + extent.e_len <= blockcnt)
+                               continue;
+                       if (extent.e_lblk > blockcnt)
+                               blockcnt = extent.e_lblk;
+                       j = blockcnt - extent.e_lblk;
+                       blk += j;
                        for (blockcnt = extent.e_lblk, j = 0;
                             j < extent.e_len;
                             blk++, blockcnt++, j++) {