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 <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
Chao Yu 2022-10-06 23:16:57 +08:00 committed by sunshenshen
parent 0bed51f3ad
commit 04b067cbb9
4 changed files with 13 additions and 14 deletions

View File

@ -421,6 +421,8 @@ static inline block_t __end_block_addr(struct f2fs_sb_info *sbi)
sbi->log_blocks_per_seg); 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) \ #define GET_ZONENO_FROM_SEGNO(sbi, segno) \
((segno / sbi->segs_per_sec) / sbi->secs_per_zone) ((segno / sbi->segs_per_sec) / sbi->secs_per_zone)

View File

@ -3179,6 +3179,7 @@ int fsck_verify(struct f2fs_sb_info *sbi)
struct f2fs_fsck *fsck = F2FS_FSCK(sbi); struct f2fs_fsck *fsck = F2FS_FSCK(sbi);
struct hard_link_node *node = NULL; struct hard_link_node *node = NULL;
bool verify_failed = false; bool verify_failed = false;
uint64_t max_blks, data_secs, node_secs, free_blks;
if (c.show_file_map) if (c.show_file_map)
return 0; return 0;
@ -3229,10 +3230,16 @@ int fsck_verify(struct f2fs_sb_info *sbi)
} }
c.bug_on = 1; c.bug_on = 1;
} }
printf("[FSCK] Max image size: %"PRIu64" MB, Free space: %u MB\n",
c.max_size >> 20, data_secs = round_up(sbi->total_valid_node_count, BLKS_PER_SEC(sbi));
(sbi->user_block_count - sbi->total_valid_block_count) >> node_secs = round_up(sbi->total_valid_block_count -
(20 - F2FS_BLKSIZE_BITS)); 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 "); printf("[FSCK] Unreachable nat entries ");
if (nr_unref_nid == 0x0) { if (nr_unref_nid == 0x0) {
printf(" [Ok..] [0x%x]\n", nr_unref_nid); printf(" [Ok..] [0x%x]\n", nr_unref_nid);

View File

@ -480,7 +480,6 @@ struct f2fs_configuration {
uint64_t wanted_total_sectors; uint64_t wanted_total_sectors;
uint64_t wanted_sector_size; uint64_t wanted_sector_size;
uint64_t target_sectors; uint64_t target_sectors;
uint64_t max_size;
uint32_t sectors_per_blk; uint32_t sectors_per_blk;
uint32_t blks_per_seg; uint32_t blks_per_seg;
__u8 init_version[VERSION_LEN + 1]; __u8 init_version[VERSION_LEN + 1];

View File

@ -521,9 +521,6 @@ int dev_read(void *buf, __u64 offset, size_t len)
int fd; int fd;
int err; int err;
if (c.max_size < (offset + len))
c.max_size = offset + len;
if (c.sparse_mode) if (c.sparse_mode)
return sparse_read_blk(offset / F2FS_BLKSIZE, return sparse_read_blk(offset / F2FS_BLKSIZE,
len / F2FS_BLKSIZE, buf); len / F2FS_BLKSIZE, buf);
@ -563,9 +560,6 @@ int dev_write(void *buf, __u64 offset, size_t len)
{ {
int fd; int fd;
if (c.max_size < (offset + len))
c.max_size = offset + len;
if (c.dry_run) if (c.dry_run)
return 0; return 0;
@ -604,9 +598,6 @@ int dev_fill(void *buf, __u64 offset, size_t len)
{ {
int fd; int fd;
if (c.max_size < (offset + len))
c.max_size = offset + len;
if (c.sparse_mode) if (c.sparse_mode)
return sparse_write_zeroed_blk(offset / F2FS_BLKSIZE, return sparse_write_zeroed_blk(offset / F2FS_BLKSIZE,
len / F2FS_BLKSIZE); len / F2FS_BLKSIZE);