[PATCH v4 02/10] erofs-utils: lib: keep erofs_init_devices in sync with kernel
Jingbo Xu
jefflexu at linux.alibaba.com
Wed Aug 23 17:15:09 AEST 2023
Keep erofs_init_devices() in sync with kernel erofs_scan_devices()[1],
which scans the devtable (if any) automatically if sbi->extra_devices is
not explicitly specified.
Also fix the missing le32_to_cpu() when parsing the device slot. Read
and cache the number of blocks of each device for later use.
Fixes: 0ce853a01123 ("erofs-utils: fuse: add multiple device support")
[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ba73eadd23d1c
Signed-off-by: Jingbo Xu <jefflexu at linux.alibaba.com>
---
lib/super.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/lib/super.c b/lib/super.c
index 21dc51f..fc709fc 100644
--- a/lib/super.c
+++ b/lib/super.c
@@ -37,7 +37,8 @@ static int erofs_init_devices(struct erofs_sb_info *sbi,
else
ondisk_extradevs = le16_to_cpu(dsb->extra_devices);
- if (ondisk_extradevs != sbi->extra_devices) {
+ if (sbi->extra_devices &&
+ ondisk_extradevs != sbi->extra_devices) {
erofs_err("extra devices don't match (ondisk %u, given %u)",
ondisk_extradevs, sbi->extra_devices);
return -EINVAL;
@@ -45,6 +46,7 @@ static int erofs_init_devices(struct erofs_sb_info *sbi,
if (!ondisk_extradevs)
return 0;
+ sbi->extra_devices = ondisk_extradevs;
sbi->device_id_mask = roundup_pow_of_two(ondisk_extradevs + 1) - 1;
sbi->devs = calloc(ondisk_extradevs, sizeof(*sbi->devs));
if (!sbi->devs)
@@ -60,8 +62,9 @@ static int erofs_init_devices(struct erofs_sb_info *sbi,
return ret;
}
- sbi->devs[i].mapped_blkaddr = dis.mapped_blkaddr;
- sbi->total_blocks += dis.blocks;
+ sbi->devs[i].mapped_blkaddr = le32_to_cpu(dis.mapped_blkaddr);
+ sbi->devs[i].blocks = le32_to_cpu(dis.blocks);
+ sbi->total_blocks += sbi->devs[i].blocks;
pos += EROFS_DEVT_SLOT_SIZE;
}
return 0;
--
2.19.1.6.gb485710b
More information about the Linux-erofs
mailing list