From 04b067cbb91b0665590c970215f1f9459b482a34 Mon Sep 17 00:00:00 2001 From: Chao Yu Date: Thu, 6 Oct 2022 23:16:57 +0800 Subject: [PATCH] fsck.f2fs: export valid image size Change to calculate and export max image size with valid blocks used of image rather than last used block of image. [FSCK] Max image size: xx MB, Free space: xx MB Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim --- fsck/f2fs.h | 2 ++ fsck/fsck.c | 15 +++++++++++---- include/f2fs_fs.h | 1 - lib/libf2fs_io.c | 9 --------- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/fsck/f2fs.h b/fsck/f2fs.h index 2fd241f..703f340 100644 --- a/fsck/f2fs.h +++ b/fsck/f2fs.h @@ -421,6 +421,8 @@ static inline block_t __end_block_addr(struct f2fs_sb_info *sbi) sbi->log_blocks_per_seg); } +#define BLKS_PER_SEC(sbi) \ + ((sbi)->segs_per_sec * (sbi)->blocks_per_seg) #define GET_ZONENO_FROM_SEGNO(sbi, segno) \ ((segno / sbi->segs_per_sec) / sbi->secs_per_zone) diff --git a/fsck/fsck.c b/fsck/fsck.c index b1b6722..2f6cc72 100644 --- a/fsck/fsck.c +++ b/fsck/fsck.c @@ -3179,6 +3179,7 @@ int fsck_verify(struct f2fs_sb_info *sbi) struct f2fs_fsck *fsck = F2FS_FSCK(sbi); struct hard_link_node *node = NULL; bool verify_failed = false; + uint64_t max_blks, data_secs, node_secs, free_blks; if (c.show_file_map) return 0; @@ -3229,10 +3230,16 @@ int fsck_verify(struct f2fs_sb_info *sbi) } c.bug_on = 1; } - printf("[FSCK] Max image size: %"PRIu64" MB, Free space: %u MB\n", - c.max_size >> 20, - (sbi->user_block_count - sbi->total_valid_block_count) >> - (20 - F2FS_BLKSIZE_BITS)); + + data_secs = round_up(sbi->total_valid_node_count, BLKS_PER_SEC(sbi)); + node_secs = round_up(sbi->total_valid_block_count - + sbi->total_valid_node_count, BLKS_PER_SEC(sbi)); + free_blks = (sbi->total_sections - data_secs - node_secs) * + BLKS_PER_SEC(sbi); + max_blks = SM_I(sbi)->main_blkaddr + (data_secs + node_secs) * + BLKS_PER_SEC(sbi); + printf("[FSCK] Max image size: %"PRIu64" MB, Free space: %"PRIu64" MB\n", + max_blks >> 8, free_blks >> 8); printf("[FSCK] Unreachable nat entries "); if (nr_unref_nid == 0x0) { printf(" [Ok..] [0x%x]\n", nr_unref_nid); diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h index 509d75a..c36c623 100644 --- a/include/f2fs_fs.h +++ b/include/f2fs_fs.h @@ -480,7 +480,6 @@ struct f2fs_configuration { uint64_t wanted_total_sectors; uint64_t wanted_sector_size; uint64_t target_sectors; - uint64_t max_size; uint32_t sectors_per_blk; uint32_t blks_per_seg; __u8 init_version[VERSION_LEN + 1]; diff --git a/lib/libf2fs_io.c b/lib/libf2fs_io.c index bf9ef7b..0b98f29 100644 --- a/lib/libf2fs_io.c +++ b/lib/libf2fs_io.c @@ -521,9 +521,6 @@ int dev_read(void *buf, __u64 offset, size_t len) int fd; int err; - if (c.max_size < (offset + len)) - c.max_size = offset + len; - if (c.sparse_mode) return sparse_read_blk(offset / F2FS_BLKSIZE, len / F2FS_BLKSIZE, buf); @@ -563,9 +560,6 @@ int dev_write(void *buf, __u64 offset, size_t len) { int fd; - if (c.max_size < (offset + len)) - c.max_size = offset + len; - if (c.dry_run) return 0; @@ -604,9 +598,6 @@ int dev_fill(void *buf, __u64 offset, size_t len) { int fd; - if (c.max_size < (offset + len)) - c.max_size = offset + len; - if (c.sparse_mode) return sparse_write_zeroed_blk(offset / F2FS_BLKSIZE, len / F2FS_BLKSIZE);