[PATCH 2/2] erofs-utils: record sb_size instead of sb_extslots
Gao Xiang
hsiangkao at linux.alibaba.com
Tue Jun 4 18:40:15 AEST 2024
Just follow the kernel implementation.
Signed-off-by: Gao Xiang <hsiangkao at 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);
--
2.39.3
More information about the Linux-erofs
mailing list