aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Anderson <dvander@google.com>2020-02-11 02:54:54 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2020-02-11 02:54:54 +0000
commit1c68004c18d44c71cc7ba300a2fdbc798cb32b94 (patch)
tree8a2a7a45e572f560e5faac2351364d1149349e26
parente754e6de22cc2ac7ee07a00023aa1990600d8384 (diff)
parent346bee6f8b97aefe7714688f738606c116099fbc (diff)
downloade2fsprogs-1c68004c18d44c71cc7ba300a2fdbc798cb32b94.tar.gz
Merge "e2fsdroid: Properly free the dedup block map."
-rw-r--r--contrib/android/basefs_allocator.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/contrib/android/basefs_allocator.c b/contrib/android/basefs_allocator.c
index 8a2b27e6..32305319 100644
--- a/contrib/android/basefs_allocator.c
+++ b/contrib/android/basefs_allocator.c
@@ -39,6 +39,28 @@ static void fs_free_blocks_range(ext2_filsys fs,
}
}
+/*
+ * Free any blocks in the bitmap that were reserved but never used. This is
+ * needed to free dedup_block_map and ensure the free block bitmap is
+ * internally consistent.
+ */
+static void fs_free_blocks_bitmap(ext2_filsys fs, ext2fs_block_bitmap bitmap)
+{
+ blk64_t block = 0;
+ blk64_t start = fs->super->s_first_data_block;
+ blk64_t end = ext2fs_blocks_count(fs->super) - 1;
+ errcode_t retval;
+
+ for (;;) {
+ retval = ext2fs_find_first_set_block_bitmap2(bitmap, start, end,
+ &block);
+ if (retval)
+ break;
+ ext2fs_unmark_block_bitmap2(fs->block_map, block);
+ start = block + 1;
+ }
+}
+
static void basefs_allocator_free(ext2_filsys fs,
struct base_fs_allocator *allocator)
{
@@ -53,6 +75,7 @@ static void basefs_allocator_free(ext2_filsys fs,
}
ext2fs_hashmap_free(entries);
}
+ fs_free_blocks_bitmap(fs, allocator->dedup_block_map);
ext2fs_free_block_bitmap(allocator->exclusive_block_map);
ext2fs_free_block_bitmap(allocator->dedup_block_map);
free(allocator);