#ifndef OMIT_COM_ERR
if (bitmap->description)
com_err(0, bitmap->base_error_code+code,
- "#%llu for %s", arg, bitmap->description);
+ "#%llu for %s", (unsigned long long) arg,
+ bitmap->description);
else
- com_err(0, bitmap->base_error_code + code, "#%llu", arg);
+ com_err(0, bitmap->base_error_code + code, "#%llu",
+ (unsigned long long) arg);
#endif
}
#ifdef ENABLE_BMAP_STATS_OPS
float mark_seq_perc = 0.0, test_seq_perc = 0.0;
float mark_back_perc = 0.0, test_back_perc = 0.0;
-#endif
- double inuse;
struct timeval now;
+ double inuse;
-#ifdef ENABLE_BMAP_STATS_OPS
if (stats->test_count) {
test_seq_perc = ((float)stats->test_seq /
stats->test_count) * 100;
mark_back_perc = ((float)stats->mark_back /
stats->mark_count) * 100;
}
-#endif
if (gettimeofday(&now, (struct timezone *) NULL) == -1) {
perror("gettimeofday");
(((double) now.tv_usec) * 0.000001);
inuse -= (double) stats->created.tv_sec + \
(((double) stats->created.tv_usec) * 0.000001);
+#endif /* ENABLE_BMAP_STATS_OPS */
fprintf(stderr, "\n[+] %s bitmap (type %d)\n", bitmap->description,
stats->type);
(bm1->end != bm2->end))
return neq;
- for (i = bm1->end - ((bm1->end - bm1->start) % 8); i <= bm1->end; i++)
- if (ext2fs_test_generic_bmap(gen_bm1, i) !=
- ext2fs_test_generic_bmap(gen_bm2, i))
+ for (i = bm1->start; i < bm1->end; i++) {
+ int ret1, ret2;
+ ret1 = !!ext2fs_test_generic_bmap(gen_bm1, i);
+ ret2 = !!ext2fs_test_generic_bmap(gen_bm2, i);
+ if (ret1 != ret2) {
return neq;
+ }
+ }
return 0;
}
bmap, block);
if (EXT2FS_IS_32_BITMAP(bmap)) {
- if ((block+num-1) & ~0xffffffffULL) {
+ if ((block & ~0xffffffffULL) ||
+ ((block+num-1) & ~0xffffffffULL)) {
ext2fs_warn_bitmap2((ext2fs_generic_bitmap) bmap,
EXT2FS_UNMARK_ERROR, 0xffffffff);
return EINVAL;
/* convert to clusters if necessary */
block >>= bmap->cluster_bits;
- end += (1 << bmap->cluster_bits) - 1;
+ end += (1ULL << bmap->cluster_bits) - 1;
end >>= bmap->cluster_bits;
num = end - block;
- if ((block < bmap->start) || (block+num-1 > bmap->end)) {
+ if ((block < bmap->start) || (block > bmap->end) ||
+ (block+num-1 > bmap->end)) {
ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_TEST, block,
bmap->description);
return EINVAL;
return;
if (EXT2FS_IS_32_BITMAP(bmap)) {
- if ((block+num-1) & ~0xffffffffULL) {
+ if ((block & ~0xffffffffULL) ||
+ ((block+num-1) & ~0xffffffffULL)) {
ext2fs_warn_bitmap2((ext2fs_generic_bitmap) bmap,
EXT2FS_UNMARK_ERROR, 0xffffffff);
return;
/* convert to clusters if necessary */
block >>= bmap->cluster_bits;
- end += (1 << bmap->cluster_bits) - 1;
+ end += (1ULL << bmap->cluster_bits) - 1;
end >>= bmap->cluster_bits;
num = end - block;
- if ((block < bmap->start) || (block+num-1 > bmap->end)) {
+ if ((block < bmap->start) || (block > bmap->end) ||
+ (block+num-1 > bmap->end)) {
ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_MARK, block,
bmap->description);
return;
return;
if (EXT2FS_IS_32_BITMAP(bmap)) {
- if ((block+num-1) & ~0xffffffffULL) {
+ if ((block & ~0xffffffffULL) ||
+ ((block+num-1) & ~0xffffffffULL)) {
ext2fs_warn_bitmap2((ext2fs_generic_bitmap) bmap,
EXT2FS_UNMARK_ERROR, 0xffffffff);
return;
/* convert to clusters if necessary */
block >>= bmap->cluster_bits;
- end += (1 << bmap->cluster_bits) - 1;
+ end += (1ULL << bmap->cluster_bits) - 1;
end >>= bmap->cluster_bits;
num = end - block;
- if ((block < bmap->start) || (block+num-1 > bmap->end)) {
+ if ((block < bmap->start) || (block > bmap->end) ||
+ (block+num-1 > bmap->end)) {
ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_UNMARK, block,
bmap->description);
return;
ext2fs_generic_bitmap_64 bmap, cmap;
ext2fs_block_bitmap gen_bmap = *bitmap, gen_cmap;
errcode_t retval;
- blk64_t i, b_end, c_end;
- int n, ratio;
+ blk64_t i, next, b_end, c_end;
bmap = (ext2fs_generic_bitmap_64) gen_bmap;
if (fs->cluster_ratio_bits == ext2fs_get_bitmap_granularity(gen_bmap))
bmap->end = bmap->real_end;
c_end = cmap->end;
cmap->end = cmap->real_end;
- n = 0;
- ratio = 1 << fs->cluster_ratio_bits;
while (i < bmap->real_end) {
- if (ext2fs_test_block_bitmap2(gen_bmap, i)) {
- ext2fs_mark_block_bitmap2(gen_cmap, i);
- i += ratio - n;
- n = 0;
- continue;
- }
- i++; n++;
- if (n >= ratio)
- n = 0;
+ retval = ext2fs_find_first_set_block_bitmap2(gen_bmap,
+ i, bmap->real_end, &next);
+ if (retval)
+ break;
+ ext2fs_mark_block_bitmap2(gen_cmap, next);
+ i = EXT2FS_C2B(fs, EXT2FS_B2C(fs, next) + 1);
}
bmap->end = b_end;
cmap->end = c_end;
return ENOENT;
}
+
+errcode_t ext2fs_count_used_clusters(ext2_filsys fs, blk64_t start,
+ blk64_t end, blk64_t *out)
+{
+ blk64_t next;
+ blk64_t tot_set = 0;
+ errcode_t retval = 0;
+
+ while (start < end) {
+ retval = ext2fs_find_first_set_block_bitmap2(fs->block_map,
+ start, end, &next);
+ if (retval) {
+ if (retval == ENOENT)
+ retval = 0;
+ break;
+ }
+ start = next;
+
+ retval = ext2fs_find_first_zero_block_bitmap2(fs->block_map,
+ start, end, &next);
+ if (retval == 0) {
+ tot_set += next - start;
+ start = next + 1;
+ } else if (retval == ENOENT) {
+ retval = 0;
+ tot_set += end - start + 1;
+ break;
+ } else
+ break;
+ }
+
+ if (!retval)
+ *out = EXT2FS_NUM_B2C(fs, tot_set);
+ return retval;
+}