From 7d1abe3d5d947ab4bb662888e6fa1669b610cc2f Mon Sep 17 00:00:00 2001 From: Gao Xiang Date: Tue, 4 Jun 2024 16:40:15 +0800 Subject: erofs-utils: record sb_size instead of sb_extslots Just follow the kernel implementation. Signed-off-by: Gao Xiang Link: https://lore.kernel.org/r/20240604084015.2291157-2-hsiangkao@linux.alibaba.com --- dump/main.c | 4 ++-- include/erofs/internal.h | 7 ++++--- lib/super.c | 7 ++++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/dump/main.c b/dump/main.c index dd2c620..50f4662 100644 --- a/dump/main.c +++ b/dump/main.c @@ -654,8 +654,8 @@ static void erofsdump_show_superblock(void) fprintf(stdout, "Filesystem lz4_max_distance: %u\n", sbi.lz4_max_distance | 0U); } - fprintf(stdout, "Filesystem sb_extslots: %u\n", - sbi.extslots | 0U); + fprintf(stdout, "Filesystem sb_size: %u\n", + sbi.sb_size | 0U); fprintf(stdout, "Filesystem inode count: %llu\n", sbi.inos | 0ULL); fprintf(stdout, "Filesystem created: %s", diff --git a/include/erofs/internal.h b/include/erofs/internal.h index 46345e0..9fdff71 100644 --- a/include/erofs/internal.h +++ b/include/erofs/internal.h @@ -84,13 +84,14 @@ struct erofs_sb_info { u32 feature_compat; u32 feature_incompat; - u64 build_time; - u32 build_time_nsec; - u8 extslots; unsigned char islotbits; unsigned char blkszbits; + u32 sb_size; /* total superblock size */ + u32 build_time_nsec; + u64 build_time; + /* what we really care is nid, rather than ino.. */ erofs_nid_t root_nid; /* used for statfs, f_files - f_favail */ diff --git a/lib/super.c b/lib/super.c index f952f7e..4d16d29 100644 --- a/lib/super.c +++ b/lib/super.c @@ -104,6 +104,12 @@ int erofs_read_superblock(struct erofs_sb_info *sbi) return ret; } + sbi->sb_size = 128 + dsb->sb_extslots * EROFS_SB_EXTSLOT_SIZE; + if (sbi->sb_size > (1 << sbi->blkszbits) - EROFS_SUPER_OFFSET) { + erofs_err("invalid sb_extslots %u (more than a fs block)", + dsb->sb_extslots); + return -EINVAL; + } sbi->primarydevice_blocks = le32_to_cpu(dsb->blocks); sbi->meta_blkaddr = le32_to_cpu(dsb->meta_blkaddr); sbi->xattr_blkaddr = le32_to_cpu(dsb->xattr_blkaddr); @@ -114,7 +120,6 @@ int erofs_read_superblock(struct erofs_sb_info *sbi) sbi->packed_nid = le64_to_cpu(dsb->packed_nid); sbi->inos = le64_to_cpu(dsb->inos); sbi->checksum = le32_to_cpu(dsb->checksum); - sbi->extslots = dsb->sb_extslots; sbi->build_time = le64_to_cpu(dsb->build_time); sbi->build_time_nsec = le32_to_cpu(dsb->build_time_nsec); -- cgit v1.2.3