aboutsummaryrefslogtreecommitdiff
path: root/dump/main.c
diff options
context:
space:
mode:
authorJingbo Xu <jefflexu@linux.alibaba.com>2023-07-20 15:31:04 +0800
committerGao Xiang <hsiangkao@linux.alibaba.com>2023-07-27 15:31:27 +0800
commitb569147c823fa0fdbf597eba178beb475f9cc9b2 (patch)
tree428b277e213d9feb226b6bc51313fe4fa6a22cbc /dump/main.c
parent7c81cf4b53b5b346c6004412cefc0963b1361ad7 (diff)
downloaderofs-utils-b569147c823fa0fdbf597eba178beb475f9cc9b2.tar.gz
erofs-utils: lib: avoid global sbi dependencies (take 1)
Later mkfs is going to be able to convert multiple erofs images into one merged erofs image, in which case there are multiple device contexts and sbi instances. In preparation for that, remove global device context and sbi if possible except the buffer cache implementation, as there's still only one erofs output image. The device context is now folded into sbi. Global sbi still exists but it is only used by binaries directly, e.g. mkfs/dump/fsck. Signed-off-by: Jingbo Xu <jefflexu@linux.alibaba.com> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com> Link: https://lore.kernel.org/r/20230720073104.116439-1-hsiangkao@linux.alibaba.com
Diffstat (limited to 'dump/main.c')
-rw-r--r--dump/main.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/dump/main.c b/dump/main.c
index 7e75719..409c851 100644
--- a/dump/main.c
+++ b/dump/main.c
@@ -154,7 +154,7 @@ static int erofsdump_parse_options_cfg(int argc, char **argv)
usage();
exit(0);
case 3:
- err = blob_open_ro(optarg);
+ err = blob_open_ro(&sbi, optarg);
if (err)
return err;
++sbi.extra_devices;
@@ -202,7 +202,7 @@ static int erofsdump_get_occupied_size(struct erofs_inode *inode,
case EROFS_INODE_COMPRESSED_FULL:
case EROFS_INODE_COMPRESSED_COMPACT:
stats.compressed_files++;
- *size = inode->u.i_blocks * erofs_blksiz();
+ *size = inode->u.i_blocks * erofs_blksiz(inode->sbi);
break;
default:
erofs_err("unknown datalayout");
@@ -270,9 +270,9 @@ static int erofsdump_read_packed_inode(void)
{
int err;
erofs_off_t occupied_size = 0;
- struct erofs_inode vi = { .nid = sbi.packed_nid };
+ struct erofs_inode vi = { .sbi = &sbi, .nid = sbi.packed_nid };
- if (!(erofs_sb_has_fragments() && sbi.packed_nid > 0))
+ if (!(erofs_sb_has_fragments(&sbi) && sbi.packed_nid > 0))
return 0;
err = erofs_read_inode_from_disk(&vi);
@@ -296,7 +296,7 @@ static int erofsdump_readdir(struct erofs_dir_context *ctx)
{
int err;
erofs_off_t occupied_size = 0;
- struct erofs_inode vi = { .nid = ctx->de_nid };
+ struct erofs_inode vi = { .sbi = &sbi, .nid = ctx->de_nid };
err = erofs_read_inode_from_disk(&vi);
if (err) {
@@ -351,7 +351,7 @@ static void erofsdump_show_fileinfo(bool show_extent)
int err, i;
erofs_off_t size;
u16 access_mode;
- struct erofs_inode inode = { .nid = dumpcfg.nid };
+ struct erofs_inode inode = { .sbi = &sbi, .nid = dumpcfg.nid };
char path[PATH_MAX];
char access_mode_str[] = "rwxrwxrwx";
char timebuf[128] = {0};
@@ -382,7 +382,7 @@ static void erofsdump_show_fileinfo(bool show_extent)
return;
}
- err = erofs_get_pathname(inode.nid, path, sizeof(path));
+ err = erofs_get_pathname(inode.sbi, inode.nid, path, sizeof(path));
if (err < 0) {
strncpy(path, "(not found)", sizeof(path) - 1);
path[sizeof(path) - 1] = '\0';
@@ -447,7 +447,7 @@ static void erofsdump_show_fileinfo(bool show_extent)
.m_deviceid = map.m_deviceid,
.m_pa = map.m_pa,
};
- err = erofs_map_dev(&mdev);
+ err = erofs_map_dev(inode.sbi, &mdev);
if (err) {
erofs_err("failed to map device");
return;
@@ -604,7 +604,7 @@ static void erofsdump_show_superblock(void)
sbi.xattr_blkaddr);
fprintf(stdout, "Filesystem root nid: %llu\n",
sbi.root_nid | 0ULL);
- if (erofs_sb_has_fragments() && sbi.packed_nid > 0)
+ if (erofs_sb_has_fragments(&sbi) && sbi.packed_nid > 0)
fprintf(stdout, "Filesystem packed nid: %llu\n",
sbi.packed_nid | 0ULL);
fprintf(stdout, "Filesystem inode count: %llu\n",
@@ -636,13 +636,13 @@ int main(int argc, char **argv)
goto exit;
}
- err = dev_open_ro(cfg.c_img_path);
+ err = dev_open_ro(&sbi, cfg.c_img_path);
if (err) {
erofs_err("failed to open image file");
goto exit;
}
- err = erofs_read_superblock();
+ err = erofs_read_superblock(&sbi);
if (err) {
erofs_err("failed to read superblock");
goto exit_dev_close;
@@ -667,11 +667,11 @@ int main(int argc, char **argv)
erofsdump_show_fileinfo(dumpcfg.show_extent);
exit_put_super:
- erofs_put_super();
+ erofs_put_super(&sbi);
exit_dev_close:
- dev_close();
+ dev_close(&sbi);
exit:
- blob_closeall();
+ blob_closeall(&sbi);
erofs_exit_configure();
return err;
}