From: Nithurshen <nithurshen.dev@gmail.com>
To: linux-erofs@lists.ozlabs.org
Cc: xiang@kernel.org, hsiangkao@linux.alibaba.com,
zhaoyifan28@huawei.com, Nithurshen <nithurshen.dev@gmail.com>
Subject: [PATCH v2] mkfs: support block map for blob devices
Date: Mon, 9 Mar 2026 17:54:34 +0530 [thread overview]
Message-ID: <20260309122434.49204-1-nithurshen.dev@gmail.com> (raw)
In-Reply-To: <20260307062810.19862-1-nithurshen.dev@gmail.com>
Currently, using --blobdev to specify an extra device is restricted
from working with the block map chunk format. This was previously
noted as a task that could be implemented by mapping the device
blocks using a global address.
This patch implements this support by allowing the block map to
reference chunks residing on extra devices. This is achieved by:
1) Removing the -EINVAL check in mkfs/main.c.
2) Calculating the global startblk address for the block map by
summing the blocks of the primary device and preceding devices.
3) Ensuring EROFS_CHUNK_FORMAT_INDEXES is only set if the user
has not forced the block map format.
4) Updating erofs_inode_fixup_chunkformat to error out if the
mapped address exceeds UINT32_MAX, as block maps cannot
support 48-bit addressing.
In addition, erofs_map_dev() is updated to correctly identify the
device ID when a global block address is used with block maps,
enabling userspace tools to read these images.
Signed-off-by: Nithurshen <nithurshen.dev@gmail.com>
---
lib/blobchunk.c | 34 ++++++++++++++++++++++++++++------
lib/data.c | 1 +
mkfs/main.c | 7 -------
3 files changed, 29 insertions(+), 13 deletions(-)
diff --git a/lib/blobchunk.c b/lib/blobchunk.c
index 96c161b..fdcf4b3 100644
--- a/lib/blobchunk.c
+++ b/lib/blobchunk.c
@@ -159,7 +159,17 @@ void erofs_inode_fixup_chunkformat(struct erofs_inode *inode)
if (chunk->blkaddr == EROFS_NULL_ADDR)
continue;
if (chunk->device_id) {
- if (chunk->blkaddr > UINT32_MAX) {
+ if (!(inode->u.chunkformat & EROFS_CHUNK_FORMAT_INDEXES)) {
+ erofs_blk_t mapped_blkaddr = inode->sbi->primarydevice_blocks;
+ unsigned int i;
+
+ for (i = 0; i < chunk->device_id - 1; i++)
+ mapped_blkaddr += inode->sbi->devs[i].blocks;
+ if (mapped_blkaddr + chunk->blkaddr > UINT32_MAX) {
+ erofs_err("block map cannot support addresses > UINT32_MAX");
+ return;
+ }
+ } else if (chunk->blkaddr > UINT32_MAX) {
_48bit = true;
break;
}
@@ -201,8 +211,16 @@ int erofs_write_chunk_indexes(struct erofs_inode *inode, struct erofs_vfile *vf,
if (chunk->blkaddr == EROFS_NULL_ADDR) {
startblk = EROFS_NULL_ADDR;
} else if (chunk->device_id) {
- DBG_BUGON(!(inode->u.chunkformat & EROFS_CHUNK_FORMAT_INDEXES));
- startblk = chunk->blkaddr;
+ if (inode->u.chunkformat & EROFS_CHUNK_FORMAT_INDEXES) {
+ startblk = chunk->blkaddr;
+ } else {
+ unsigned int i;
+
+ startblk = sbi->primarydevice_blocks;
+ for (i = 0; i < chunk->device_id - 1; i++)
+ startblk += sbi->devs[i].blocks;
+ startblk += chunk->blkaddr;
+ }
extent_start = EROFS_NULL_ADDR;
} else {
startblk = remapped_base + chunk->blkaddr;
@@ -324,7 +342,7 @@ int erofs_blob_write_chunked_file(struct erofs_inode *inode, int fd,
chunksize = 1ULL << chunkbits;
count = DIV_ROUND_UP(inode->i_size, chunksize);
- if (sbi->extra_devices)
+ if (sbi->extra_devices && cfg.c_force_chunkformat != FORCE_INODE_BLOCK_MAP)
inode->u.chunkformat |= EROFS_CHUNK_FORMAT_INDEXES;
if (inode->u.chunkformat & EROFS_CHUNK_FORMAT_INDEXES)
unit = sizeof(struct erofs_inode_chunk_index);
@@ -494,8 +512,12 @@ int tarerofs_write_chunkes(struct erofs_inode *inode, erofs_off_t data_offset)
inode->u.chunkformat |= chunkbits - sbi->blkszbits;
if (sbi->extra_devices) {
device_id = 1;
- inode->u.chunkformat |= EROFS_CHUNK_FORMAT_INDEXES;
- unit = sizeof(struct erofs_inode_chunk_index);
+ if (cfg.c_force_chunkformat != FORCE_INODE_BLOCK_MAP)
+ inode->u.chunkformat |= EROFS_CHUNK_FORMAT_INDEXES;
+ if (inode->u.chunkformat & EROFS_CHUNK_FORMAT_INDEXES)
+ unit = sizeof(struct erofs_inode_chunk_index);
+ else
+ unit = EROFS_BLOCK_MAP_ENTRY_SIZE;
DBG_BUGON(erofs_blkoff(sbi, data_offset));
blkaddr = erofs_blknr(sbi, data_offset);
} else {
diff --git a/lib/data.c b/lib/data.c
index 6fd1389..5aeb0c1 100644
--- a/lib/data.c
+++ b/lib/data.c
@@ -184,6 +184,7 @@ int erofs_map_dev(struct erofs_sb_info *sbi, struct erofs_map_dev *map)
if (map->m_pa >= startoff &&
map->m_pa < startoff + length) {
map->m_pa -= startoff;
+ map->m_deviceid = id + 1;
break;
}
}
diff --git a/mkfs/main.c b/mkfs/main.c
index 58c18f9..07ef086 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -1565,13 +1565,6 @@ static int mkfs_parse_options_cfg(struct erofs_importer_params *params,
return -EINVAL;
}
- /* TODO: can be implemented with (deviceslot) mapped_blkaddr */
- if (cfg.c_blobdev_path &&
- cfg.c_force_chunkformat == FORCE_INODE_BLOCK_MAP) {
- erofs_err("--blobdev cannot work with block map currently");
- return -EINVAL;
- }
-
if (optind >= argc) {
erofs_err("missing argument: FILE");
return -EINVAL;
--
2.51.0
next prev parent reply other threads:[~2026-03-09 12:24 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-07 6:28 [PATCH] mkfs: support block map for blob devices Nithurshen
2026-03-09 11:38 ` zhaoyifan (H)
2026-03-09 13:01 ` Nithurshen Karthikeyan
2026-03-12 9:56 ` Nithurshen Karthikeyan
2026-03-12 11:40 ` Gao Xiang
2026-03-12 13:21 ` Nithurshen Karthikeyan
2026-03-19 3:19 ` Nithurshen Karthikeyan
2026-03-09 12:24 ` Nithurshen [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-03-06 8:57 [PATCH 0/2] erofs-utils: minor cleanups and enhancements Nithurshen
2026-03-16 10:52 ` [PATCH v2 " Nithurshen
2026-03-16 10:52 ` [PATCH v2] mkfs: support block map for blob devices Nithurshen
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=20260309122434.49204-1-nithurshen.dev@gmail.com \
--to=nithurshen.dev@gmail.com \
--cc=hsiangkao@linux.alibaba.com \
--cc=linux-erofs@lists.ozlabs.org \
--cc=xiang@kernel.org \
--cc=zhaoyifan28@huawei.com \
/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