aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ext2fs/gen_bitmap64.c
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2013-01-19 23:21:11 -0500
committerTheodore Ts'o <tytso@mit.edu>2013-01-19 23:21:11 -0500
commit3e1816b8cc9086354453bd75aaaeade558f98b3e (patch)
treeb1684d1714f912cb905ee906c35e5994c22bc1ba /lib/ext2fs/gen_bitmap64.c
parent8359f626a4e94757312f68759366f06c9ad4c1ac (diff)
downloade2fsprogs-3e1816b8cc9086354453bd75aaaeade558f98b3e.tar.gz
e2fsprogs-3e1816b8cc9086354453bd75aaaeade558f98b3e.tar.xz
e2fsprogs-3e1816b8cc9086354453bd75aaaeade558f98b3e.zip
libext2fs: teach the ext2fs_*_block_bitmap_range2() about clusters
The ext2fs_{mark,unmark,test}_block_bitmap2() functions understand about clusters, and will take block numbers and convert them to clusters before checking the bitmap. The ext2fs_*_block_bitmap_range2() functions did not do this, which made them inconsistent. Fortunately, nothing has depended on this incorrect behavior, and in fact most of the usage of these functions have only recently been added, and only for optimizations that were only enabled for non-bigalloc file systems. So this is a change in previously exported functions, but (a) it doesn't change the behavior at all for non-bigalloc file systems, and (b) the change is more likely to fix bugs for bigalloc file systems. For example, this change fixes a problem with resize2fs and bigalloc file systems. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'lib/ext2fs/gen_bitmap64.c')
-rw-r--r--lib/ext2fs/gen_bitmap64.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/ext2fs/gen_bitmap64.c b/lib/ext2fs/gen_bitmap64.c
index 07d6d522..82a552d3 100644
--- a/lib/ext2fs/gen_bitmap64.c
+++ b/lib/ext2fs/gen_bitmap64.c
@@ -624,6 +624,8 @@ void ext2fs_set_generic_bmap_padding(ext2fs_generic_bitmap bmap)
int ext2fs_test_block_bitmap_range2(ext2fs_block_bitmap bmap,
blk64_t block, unsigned int num)
{
+ __u64 end = block + num;
+
if (!bmap)
return EINVAL;
@@ -646,12 +648,26 @@ int ext2fs_test_block_bitmap_range2(ext2fs_block_bitmap bmap,
INC_STAT(bmap, test_ext_count);
+ /* convert to clusters if necessary */
+ block >>= bmap->cluster_bits;
+ end += (1 << bmap->cluster_bits) - 1;
+ end >>= bmap->cluster_bits;
+ num = end - block;
+
+ if ((block < bmap->start) || (block+num-1 > bmap->end)) {
+ ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_TEST, block,
+ bmap->description);
+ return;
+ }
+
return bmap->bitmap_ops->test_clear_bmap_extent(bmap, block, num);
}
void ext2fs_mark_block_bitmap_range2(ext2fs_block_bitmap bmap,
blk64_t block, unsigned int num)
{
+ __u64 end = block + num;
+
if (!bmap)
return;
@@ -670,6 +686,12 @@ void ext2fs_mark_block_bitmap_range2(ext2fs_block_bitmap bmap,
INC_STAT(bmap, mark_ext_count);
+ /* convert to clusters if necessary */
+ block >>= bmap->cluster_bits;
+ end += (1 << bmap->cluster_bits) - 1;
+ end >>= bmap->cluster_bits;
+ num = end - block;
+
if ((block < bmap->start) || (block+num-1 > bmap->end)) {
ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_MARK, block,
bmap->description);
@@ -682,6 +704,8 @@ void ext2fs_mark_block_bitmap_range2(ext2fs_block_bitmap bmap,
void ext2fs_unmark_block_bitmap_range2(ext2fs_block_bitmap bmap,
blk64_t block, unsigned int num)
{
+ __u64 end = block + num;
+
if (!bmap)
return;
@@ -700,6 +724,12 @@ void ext2fs_unmark_block_bitmap_range2(ext2fs_block_bitmap bmap,
INC_STAT(bmap, unmark_ext_count);
+ /* convert to clusters if necessary */
+ block >>= bmap->cluster_bits;
+ end += (1 << bmap->cluster_bits) - 1;
+ end >>= bmap->cluster_bits;
+ num = end - block;
+
if ((block < bmap->start) || (block+num-1 > bmap->end)) {
ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_UNMARK, block,
bmap->description);