@@ -69,10 +69,12 @@ void ext2fs_block_alloc_stats2(ext2_filsys fs, blk64_t blk, int inuse)
#endif
return;
}
- if (inuse > 0)
+ if (inuse > 0) {
ext2fs_mark_block_bitmap2(fs->block_map, blk);
- else
+ } else {
ext2fs_unmark_block_bitmap2(fs->block_map, blk);
+ ext2fs_bg_flags_clear(fs, group, EXT2_BG_WAS_TRIMMED);
+ }
ext2fs_bg_free_blocks_count_set(fs, group, ext2fs_bg_free_blocks_count(fs, group) - inuse);
ext2fs_bg_flags_clear(fs, group, EXT2_BG_BLOCK_UNINIT);
ext2fs_group_desc_csum_set(fs, group);
@@ -138,6 +140,8 @@ void ext2fs_block_alloc_stats_range(ext2_filsys fs, blk64_t blk,
ext2fs_bg_free_blocks_count(fs, group) -
inuse*n/EXT2FS_CLUSTER_RATIO(fs));
ext2fs_bg_flags_clear(fs, group, EXT2_BG_BLOCK_UNINIT);
+ if (inuse < 0)
+ ext2fs_bg_flags_clear(fs, group, EXT2_BG_WAS_TRIMMED);
ext2fs_group_desc_csum_set(fs, group);
ext2fs_free_blocks_count_add(fs->super, -inuse * (blk64_t) n);
blk += n;
@@ -250,6 +250,8 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
}
ext2fs_inode_table_loc_set(fs, group, new_blk);
}
+ if (fs->flags & EXT2_FLAG_BG_WAS_TRIMMED)
+ ext2fs_bg_flags_set(fs, group, EXT2_BG_WAS_TRIMMED);
ext2fs_group_desc_csum_set(fs, group);
return 0;
}
@@ -211,6 +211,7 @@ struct ext4_group_desc
#define EXT2_BG_INODE_UNINIT 0x0001 /* Inode table/bitmap not initialized */
#define EXT2_BG_BLOCK_UNINIT 0x0002 /* Block bitmap not initialized */
#define EXT2_BG_INODE_ZEROED 0x0004 /* On-disk itable initialized to zero */
+#define EXT2_BG_WAS_TRIMMED 0x0008 /* Block group was trimmed */
/*
* Data structures used by the directory indexing feature
@@ -206,6 +206,7 @@ typedef struct ext2_file *ext2_file_t;
#define EXT2_FLAG_IGNORE_SB_ERRORS 0x800000
#define EXT2_FLAG_BBITMAP_TAIL_PROBLEM 0x1000000
#define EXT2_FLAG_IBITMAP_TAIL_PROBLEM 0x2000000
+#define EXT2_FLAG_BG_WAS_TRIMMED 0x4000000
/*
* Special flag in the ext2 inode i_flag field that means that this is
@@ -131,6 +131,8 @@ static void print_bg_opts(ext2_filsys fs, dgrp_t i)
&first);
print_bg_opt(bg_flags, EXT2_BG_INODE_ZEROED, "ITABLE_ZEROED",
&first);
+ print_bg_opt(bg_flags, EXT2_BG_WAS_TRIMMED, "WAS_TRIMMED",
+ &first);
if (!first)
fputc(']', stdout);
fputc('\n', stdout);
@@ -403,6 +403,7 @@ static errcode_t packed_allocate_tables(ext2_filsys fs)
ext2fs_block_alloc_stats_range(fs, goal,
fs->inode_blocks_per_group, +1);
ext2fs_inode_table_loc_set(fs, i, goal);
+ ext2fs_bg_flags_set(fs, i, EXT2_BG_WAS_TRIMMED);
ext2fs_group_desc_csum_set(fs, i);
}
return 0;
@@ -3037,6 +3038,8 @@ int main (int argc, char *argv[])
/* Can't undo discard ... */
if (!noaction && discard && dev_size && (io_ptr != undo_io_manager)) {
retval = mke2fs_discard_device(fs);
+ if (!retval)
+ fs->flags |= EXT2_FLAG_BG_WAS_TRIMMED;
if (!retval && io_channel_discard_zeroes_data(fs->io)) {
if (verbose)
printf("%s",