Linux-EROFS Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Gao Xiang <xiang@kernel.org>
To: linux-erofs@lists.ozlabs.org
Cc: Gao Xiang <xiang@kernel.org>
Subject: [PATCH 2/4] erofs-utils: lib: use `struct erofs_device_info` for the primary device
Date: Wed, 26 Aug 2026 21:43:18 +0800	[thread overview]
Message-ID: <20260826134321.11835-2-xiang@kernel.org> (raw)
In-Reply-To: <20260826134321.11835-1-xiang@kernel.org>

Source kernel commit: 7b00af2c5414dc01e0718deef7ead81102867636

Signed-off-by: Gao Xiang <xiang@kernel.org>
---
 include/erofs/internal.h |  4 +---
 lib/importer.c           |  3 +--
 lib/io.c                 |  8 ++++----
 lib/rebuild.c            |  6 +++---
 lib/super.c              | 18 +++++++++---------
 lib/vmdk.c               |  4 ++--
 mkfs/main.c              | 12 ++++++------
 7 files changed, 26 insertions(+), 29 deletions(-)

diff --git a/include/erofs/internal.h b/include/erofs/internal.h
index 514cfbd..30dae41 100644
--- a/include/erofs/internal.h
+++ b/include/erofs/internal.h
@@ -93,11 +93,9 @@ struct erofs_metamgr;
 
 struct erofs_sb_info {
 	struct erofs_sb_lz4_info lz4;
-	struct erofs_device_info *devs;
-	char *devname;
+	struct erofs_device_info *devs, dif0;
 
 	u64 total_blocks;
-	u64 primarydevice_blocks;
 
 	s32 meta_blkaddr;
 	u32 xattr_blkaddr;
diff --git a/lib/importer.c b/lib/importer.c
index c404b0f..2a635d2 100644
--- a/lib/importer.c
+++ b/lib/importer.c
@@ -126,8 +126,7 @@ int erofs_importer_flush_all(struct erofs_importer *im)
 
 	fsalignblks = im->params->fsalignblks ?
 		roundup_pow_of_two(im->params->fsalignblks) : 1;
-	sbi->primarydevice_blocks = roundup(erofs_mapbh(sbi->bmgr, NULL),
-					    fsalignblks);
+	sbi->dif0.blocks = roundup(erofs_mapbh(sbi->bmgr, NULL), fsalignblks);
 	err = erofs_write_device_table(sbi);
 	if (err)
 		return err;
diff --git a/lib/io.c b/lib/io.c
index 3ba45cc..5c5449f 100644
--- a/lib/io.c
+++ b/lib/io.c
@@ -368,8 +368,8 @@ repeat:
 	}
 
 out:
-	sbi->devname = strdup(dev);
-	if (!sbi->devname) {
+	sbi->dif0.src_path = strdup(dev);
+	if (!sbi->dif0.src_path) {
 		close(fd);
 		return -ENOMEM;
 	}
@@ -381,8 +381,8 @@ out:
 void erofs_dev_close(struct erofs_sb_info *sbi)
 {
 	erofs_io_close(&sbi->bdev);
-	free(sbi->devname);
-	sbi->devname = NULL;
+	free(sbi->dif0.src_path);
+	sbi->dif0.src_path = NULL;
 	sbi->bdev.fd = -1;
 }
 
diff --git a/lib/rebuild.c b/lib/rebuild.c
index a5308dc..6b03a52 100644
--- a/lib/rebuild.c
+++ b/lib/rebuild.c
@@ -233,7 +233,7 @@ static int erofs_rebuild_write_full_data(struct erofs_inode *inode)
 				return -EFSCORRUPTED;
 			return 0;
 		}
-		inode->rebuild_blobpath = strdup(src_sbi->devname);
+		inode->rebuild_blobpath = strdup(src_sbi->dif0.src_path);
 		if (!inode->rebuild_blobpath)
 			return -ENOMEM;
 		inode->rebuild_src_dataoff =
@@ -244,7 +244,7 @@ static int erofs_rebuild_write_full_data(struct erofs_inode *inode)
 		unsigned int inline_size = inode->i_size % erofs_blksiz(src_sbi);
 
 		if (nblocks > 0 && inode->u.i_blkaddr != EROFS_NULL_ADDR) {
-			inode->rebuild_blobpath = strdup(src_sbi->devname);
+			inode->rebuild_blobpath = strdup(src_sbi->dif0.src_path);
 			if (!inode->rebuild_blobpath)
 				return -ENOMEM;
 			inode->rebuild_src_dataoff =
@@ -500,7 +500,7 @@ int erofs_rebuild_load_tree(struct erofs_inode *root, struct erofs_sb_info *sbi,
 	struct erofs_inode inode = {};
 	struct erofs_rebuild_dir_context ctx;
 	char uuid_str[37];
-	char *fsid = sbi->devname;
+	char *fsid = sbi->dif0.src_path;
 	int ret;
 
 	if (!fsid) {
diff --git a/lib/super.c b/lib/super.c
index d138f84..ead4170 100644
--- a/lib/super.c
+++ b/lib/super.c
@@ -33,7 +33,7 @@ static int erofs_init_devices(struct erofs_sb_info *sbi,
 	erofs_off_t pos;
 	bool _48bit = erofs_sb_has_48bit(sbi);
 
-	sbi->total_blocks = sbi->primarydevice_blocks;
+	sbi->total_blocks = sbi->dif0.blocks;
 
 	if (!erofs_sb_has_device_table(sbi))
 		ondisk_extradevs = 0;
@@ -118,14 +118,14 @@ int erofs_read_superblock(struct erofs_sb_info *sbi)
 		erofs_err("invalid sb_extslots %u", dsb->sb_extslots);
 		return -EINVAL;
 	}
-	sbi->primarydevice_blocks = le32_to_cpu(dsb->blocks_lo);
+	sbi->dif0.blocks = le32_to_cpu(dsb->blocks_lo);
 	sbi->meta_blkaddr = le32_to_cpu(dsb->meta_blkaddr);
 	sbi->xattr_blkaddr = le32_to_cpu(dsb->xattr_blkaddr);
 	sbi->xattr_prefix_start = le32_to_cpu(dsb->xattr_prefix_start);
 	sbi->xattr_prefix_count = dsb->xattr_prefix_count;
 	if (erofs_sb_has_48bit(sbi) && dsb->rootnid_8b) {
 		sbi->root_nid = le64_to_cpu(dsb->rootnid_8b);
-		sbi->primarydevice_blocks = sbi->primarydevice_blocks |
+		sbi->dif0.blocks = sbi->dif0.blocks |
 				((u64)le16_to_cpu(dsb->rb.blocks_hi) << 32);
 	} else {
 		sbi->root_nid = le16_to_cpu(dsb->rb.rootnid_2b);
@@ -230,10 +230,10 @@ int erofs_writesb(struct erofs_sb_info *sbi)
 	char *buf;
 	int ret;
 
-	sb.blocks_lo	= cpu_to_le32(sbi->primarydevice_blocks);
-	if (sbi->primarydevice_blocks > UINT32_MAX ||
+	sb.blocks_lo	= cpu_to_le32(sbi->dif0.blocks);
+	if (sbi->dif0.blocks > UINT32_MAX ||
 	    sbi->root_nid > UINT16_MAX) {
-		sb.rb.blocks_hi = cpu_to_le16(sbi->primarydevice_blocks >> 32);
+		sb.rb.blocks_hi = cpu_to_le16(sbi->dif0.blocks >> 32);
 		sb.rootnid_8b = cpu_to_le64(sbi->root_nid);
 	}
 	memcpy(sb.uuid, sbi->uuid, sizeof(sb.uuid));
@@ -404,7 +404,7 @@ int erofs_mkfs_init_devices(struct erofs_sb_info *sbi, unsigned int devices)
 
 int erofs_write_device_table(struct erofs_sb_info *sbi)
 {
-	erofs_blk_t nblocks = sbi->primarydevice_blocks;
+	erofs_blk_t nblocks = sbi->dif0.blocks;
 	struct erofs_buffer_head *bh = sbi->bh_devt;
 	erofs_off_t pos;
 	unsigned int i, ret;
@@ -484,7 +484,7 @@ int erofs_mkfs_load_fs(struct erofs_sb_info *sbi, unsigned int dsunit)
 	erofs_warn("EXPERIMENTAL incremental build in use. Use at your own risk!");
 	err = erofs_read_superblock(sbi);
 	if (err) {
-		erofs_err("failed to read superblock of %s: %s", sbi->devname,
+		erofs_err("failed to read superblock of %s: %s", sbi->dif0.src_path,
 			  erofs_strerror(err));
 		return err;
 	}
@@ -493,7 +493,7 @@ int erofs_mkfs_load_fs(struct erofs_sb_info *sbi, unsigned int dsunit)
 	if (!err && S_ISREG(u.st.st_mode))
 		u.startblk = DIV_ROUND_UP(u.st.st_size, erofs_blksiz(sbi));
 	else
-		u.startblk = sbi->primarydevice_blocks;
+		u.startblk = sbi->dif0.blocks;
 
 	bmgr = erofs_buffer_init(sbi, u.startblk, NULL);
 	if (!bmgr)
diff --git a/lib/vmdk.c b/lib/vmdk.c
index 316a8ff..28381c8 100644
--- a/lib/vmdk.c
+++ b/lib/vmdk.c
@@ -51,8 +51,8 @@ int erofs_dump_vmdk_desc(FILE *f, struct erofs_sb_info *sbi)
 	int ret, i;
 
 	fprintf(f, desc_template_1, cid, parent_cid, subformat);
-	sectors = sbi->primarydevice_blocks << (sbi->blkszbits - 9);
-	ret = erofs_vmdk_desc_add_extent(f, sectors, (char *)sbi->devname, 0);
+	sectors = sbi->dif0.blocks << (sbi->blkszbits - 9);
+	ret = erofs_vmdk_desc_add_extent(f, sectors, (char *)sbi->dif0.blocks, 0);
 	if (ret)
 		return ret;
 	total_sectors = sectors;
diff --git a/mkfs/main.c b/mkfs/main.c
index 929ce7c..5bf7b8f 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -1685,12 +1685,12 @@ static int erofs_mkfs_rebuild_load_trees(struct erofs_inode *root)
 		ret = erofs_rebuild_load_tree(root, src, datamode);
 		src->xamgr = NULL;
 		if (ret) {
-			erofs_err("failed to load %s", src->devname);
+			erofs_err("failed to load %s", src->dif0.src_path);
 			return ret;
 		}
 		if (src->extra_devices > 1) {
 			erofs_err("%s: unsupported number %u of extra devices",
-				  src->devname, src->extra_devices);
+				  src->dif0.src_path, src->extra_devices);
 			return -EOPNOTSUPP;
 		}
 		extra_devices += src->extra_devices;
@@ -1723,8 +1723,8 @@ static int erofs_mkfs_rebuild_load_trees(struct erofs_inode *root)
 			nblocks = src->devs[0].blocks;
 			tag = src->devs[0].tag;
 		} else {
-			nblocks = src->primarydevice_blocks;
-			devs[idx].src_path = strdup(src->devname);
+			nblocks = src->dif0.blocks;
+			devs[idx].src_path = strdup(src->dif0.src_path);
 		}
 		devs[idx].blocks = nblocks;
 		if (tag && *tag)
@@ -1849,7 +1849,7 @@ int main(int argc, char **argv)
 			goto exit;
 		err = erofs_read_superblock(src);
 		if (err) {
-			erofs_err("failed to read superblock of %s", src->devname);
+			erofs_err("failed to read superblock of %s", src->dif0.src_path);
 			goto exit;
 		}
 		mkfs_blkszbits = src->blkszbits;
@@ -2051,7 +2051,7 @@ int main(int argc, char **argv)
 	if (err)
 		goto exit;
 
-	err = erofs_dev_resize(&g_sbi, g_sbi.primarydevice_blocks);
+	err = erofs_dev_resize(&g_sbi, g_sbi.dif0.blocks);
 
 	if (!err && erofs_sb_has_sb_chksum(&g_sbi)) {
 		err = erofs_enable_sb_chksum(&g_sbi, &crc);
-- 
2.47.3



  reply	other threads:[~2026-08-26 13:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-26 13:43 [PATCH 1/4] erofs-utils: lib: fix wrong forward declaration of `erofs_metamgr` Gao Xiang
2026-08-26 13:43 ` Gao Xiang [this message]
2026-08-27  1:30   ` [PATCH 2/4] erofs-utils: lib: use `struct erofs_device_info` for the primary device Yifan Zhao
2026-08-27  7:59     ` Gao Xiang
2026-08-26 13:43 ` [PATCH 3/4] erofs-utils: lib: refactor unencoded chunk handling Gao Xiang
2026-08-26 13:43 ` [PATCH 4/4] erofs-utils: get rid of hashmap Gao Xiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260826134321.11835-2-xiang@kernel.org \
    --to=xiang@kernel.org \
    --cc=linux-erofs@lists.ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox