usage(argc, argv);
exit(0);
case 3:
- err = erofs_blob_open_ro(&sbi, optarg);
+ err = erofs_blob_open_ro(&g_sbi, optarg);
if (err)
return err;
- ++sbi.extra_devices;
+ ++g_sbi.extra_devices;
break;
case 4:
dumpcfg.inode_path = optarg;
dumpcfg.show_subdirectories = true;
break;
case 6:
- sbi.bdev.offset = strtoull(optarg, &endptr, 0);
+ g_sbi.bdev.offset = strtoull(optarg, &endptr, 0);
if (*endptr != '\0') {
erofs_err("invalid disk offset %s", optarg);
return -EINVAL;
{
int err;
erofs_off_t occupied_size = 0;
- struct erofs_inode vi = { .sbi = &sbi, .nid = sbi.packed_nid };
+ struct erofs_inode vi = { .sbi = &g_sbi, .nid = g_sbi.packed_nid };
- if (!(erofs_sb_has_fragments(&sbi) && sbi.packed_nid > 0))
+ if (!(erofs_sb_has_fragments(&g_sbi) && g_sbi.packed_nid > 0))
return 0;
err = erofs_read_inode_from_disk(&vi);
{
int err;
erofs_off_t occupied_size = 0;
- struct erofs_inode vi = { .sbi = &sbi, .nid = ctx->de_nid };
+ struct erofs_inode vi = { .sbi = &g_sbi, .nid = ctx->de_nid };
err = erofs_read_inode_from_disk(&vi);
if (err) {
int err, i;
erofs_off_t size;
u16 access_mode;
- struct erofs_inode inode = { .sbi = &sbi, .nid = dumpcfg.nid };
+ struct erofs_inode inode = { .sbi = &g_sbi, .nid = dumpcfg.nid };
char path[PATH_MAX];
char access_mode_str[] = "rwxrwxrwx";
char timebuf[128] = {0};
.pnid = 0,
.dir = NULL,
.cb = erofsdump_dirent_iter,
- .de_nid = sbi.root_nid,
+ .de_nid = g_sbi.root_nid,
.dname = "",
.de_namelen = 0,
};
static void erofsdump_show_superblock(void)
{
- time_t time = sbi.build_time;
+ time_t time = g_sbi.build_time;
char uuid_str[37];
int i = 0;
fprintf(stdout, "Filesystem magic number: 0x%04X\n",
EROFS_SUPER_MAGIC_V1);
fprintf(stdout, "Filesystem blocksize: %u\n",
- erofs_blksiz(&sbi));
+ erofs_blksiz(&g_sbi));
fprintf(stdout, "Filesystem blocks: %llu\n",
- sbi.total_blocks | 0ULL);
+ g_sbi.total_blocks | 0ULL);
fprintf(stdout, "Filesystem inode metadata start block: %u\n",
- sbi.meta_blkaddr);
+ g_sbi.meta_blkaddr);
fprintf(stdout, "Filesystem shared xattr metadata start block: %u\n",
- sbi.xattr_blkaddr);
+ g_sbi.xattr_blkaddr);
fprintf(stdout, "Filesystem root nid: %llu\n",
- sbi.root_nid | 0ULL);
- if (erofs_sb_has_fragments(&sbi) && sbi.packed_nid > 0)
+ g_sbi.root_nid | 0ULL);
+ if (erofs_sb_has_fragments(&g_sbi) && g_sbi.packed_nid > 0)
fprintf(stdout, "Filesystem packed nid: %llu\n",
- sbi.packed_nid | 0ULL);
- if (erofs_sb_has_compr_cfgs(&sbi)) {
+ g_sbi.packed_nid | 0ULL);
+ if (erofs_sb_has_compr_cfgs(&g_sbi)) {
fprintf(stdout, "Filesystem compr_algs: ");
erofsdump_print_supported_compressors(stdout,
- sbi.available_compr_algs);
+ g_sbi.available_compr_algs);
} else {
fprintf(stdout, "Filesystem lz4_max_distance: %u\n",
- sbi.lz4_max_distance | 0U);
+ g_sbi.lz4_max_distance | 0U);
}
fprintf(stdout, "Filesystem sb_size: %u\n",
- sbi.sb_size | 0U);
+ g_sbi.sb_size | 0U);
fprintf(stdout, "Filesystem inode count: %llu\n",
- sbi.inos | 0ULL);
+ g_sbi.inos | 0ULL);
fprintf(stdout, "Filesystem created: %s",
ctime(&time));
fprintf(stdout, "Filesystem features: ");
for (; i < ARRAY_SIZE(feature_lists); i++) {
u32 feat = le32_to_cpu(feature_lists[i].compat ?
- sbi.feature_compat :
- sbi.feature_incompat);
+ g_sbi.feature_compat :
+ g_sbi.feature_incompat);
if (feat & feature_lists[i].flag)
fprintf(stdout, "%s ", feature_lists[i].name);
}
- erofs_uuid_unparse_lower(sbi.uuid, uuid_str);
+ erofs_uuid_unparse_lower(g_sbi.uuid, uuid_str);
fprintf(stdout, "\nFilesystem UUID: %s\n",
uuid_str);
}
goto exit;
}
- err = erofs_dev_open(&sbi, cfg.c_img_path, O_RDONLY | O_TRUNC);
+ err = erofs_dev_open(&g_sbi, cfg.c_img_path, O_RDONLY | O_TRUNC);
if (err) {
erofs_err("failed to open image file");
goto exit;
}
- err = erofs_read_superblock(&sbi);
+ err = erofs_read_superblock(&g_sbi);
if (err) {
erofs_err("failed to read superblock");
goto exit_dev_close;
erofsdump_show_fileinfo(dumpcfg.show_extent);
exit_put_super:
- erofs_put_super(&sbi);
+ erofs_put_super(&g_sbi);
exit_dev_close:
- erofs_dev_close(&sbi);
+ erofs_dev_close(&g_sbi);
exit:
- erofs_blob_closeall(&sbi);
+ erofs_blob_closeall(&g_sbi);
erofs_exit_configure();
return err;
}
}
break;
case 3:
- ret = erofs_blob_open_ro(&sbi, optarg);
+ ret = erofs_blob_open_ro(&g_sbi, optarg);
if (ret)
return ret;
- ++sbi.extra_devices;
+ ++g_sbi.extra_devices;
break;
case 4:
fsckcfg.force = true;
has_opt_preserve = true;
break;
case 12:
- sbi.bdev.offset = strtoull(optarg, &endptr, 0);
+ g_sbi.bdev.offset = strtoull(optarg, &endptr, 0);
if (*endptr != '\0') {
erofs_err("invalid disk offset %s", optarg);
return -EINVAL;
struct erofs_super_block *sb;
int ret;
- ret = erofs_blk_read(&sbi, 0, buf, 0, 1);
+ ret = erofs_blk_read(&g_sbi, 0, buf, 0, 1);
if (ret) {
erofs_err("failed to read superblock to check checksum: %d",
ret);
sb = (struct erofs_super_block *)(buf + EROFS_SUPER_OFFSET);
sb->checksum = 0;
- crc = erofs_crc32c(~0, (u8 *)sb, erofs_blksiz(&sbi) - EROFS_SUPER_OFFSET);
- if (crc != sbi.checksum) {
+ crc = erofs_crc32c(~0, (u8 *)sb, erofs_blksiz(&g_sbi) - EROFS_SUPER_OFFSET);
+ if (crc != g_sbi.checksum) {
erofs_err("superblock chksum doesn't match: saved(%08xh) calculated(%08xh)",
- sbi.checksum, crc);
+ g_sbi.checksum, crc);
fsckcfg.corrupted = true;
return -1;
}
erofs_dbg("check inode: nid(%llu)", nid | 0ULL);
inode.nid = nid;
- inode.sbi = &sbi;
+ inode.sbi = &g_sbi;
ret = erofs_read_inode_from_disk(&inode);
if (ret) {
if (ret == -EIO)
cfg.c_dbg_lvl = -1;
#endif
- err = erofs_dev_open(&sbi, cfg.c_img_path, O_RDONLY);
+ err = erofs_dev_open(&g_sbi, cfg.c_img_path, O_RDONLY);
if (err) {
erofs_err("failed to open image file");
goto exit;
}
- err = erofs_read_superblock(&sbi);
+ err = erofs_read_superblock(&g_sbi);
if (err) {
erofs_err("failed to read superblock");
goto exit_dev_close;
}
- if (erofs_sb_has_sb_chksum(&sbi) && erofs_check_sb_chksum()) {
+ if (erofs_sb_has_sb_chksum(&g_sbi) && erofs_check_sb_chksum()) {
erofs_err("failed to verify superblock checksum");
goto exit_put_super;
}
if (fsckcfg.extract_path)
erofsfsck_hardlink_init();
- if (erofs_sb_has_fragments(&sbi) && sbi.packed_nid > 0) {
- err = erofsfsck_check_inode(sbi.packed_nid, sbi.packed_nid);
+ if (erofs_sb_has_fragments(&g_sbi) && g_sbi.packed_nid > 0) {
+ err = erofsfsck_check_inode(g_sbi.packed_nid, g_sbi.packed_nid);
if (err) {
erofs_err("failed to verify packed file");
goto exit_hardlink;
}
}
- err = erofsfsck_check_inode(sbi.root_nid, sbi.root_nid);
+ err = erofsfsck_check_inode(g_sbi.root_nid, g_sbi.root_nid);
if (fsckcfg.corrupted) {
if (!fsckcfg.extract_path)
erofs_err("Found some filesystem corruption");
if (fsckcfg.extract_path)
erofsfsck_hardlink_exit();
exit_put_super:
- erofs_put_super(&sbi);
+ erofs_put_super(&g_sbi);
exit_dev_close:
- erofs_dev_close(&sbi);
+ erofs_dev_close(&g_sbi);
exit:
- erofs_blob_closeall(&sbi);
+ erofs_blob_closeall(&g_sbi);
erofs_exit_configure();
return err ? 1 : 0;
}
static inline erofs_nid_t erofsfuse_to_nid(fuse_ino_t ino)
{
if (ino == FUSE_ROOT_ID)
- return sbi.root_nid;
+ return g_sbi.root_nid;
return (erofs_nid_t)(ino - FUSE_ROOT_ID);
}
static inline fuse_ino_t erofsfuse_to_ino(erofs_nid_t nid)
{
- if (nid == sbi.root_nid)
+ if (nid == g_sbi.root_nid)
return FUSE_ROOT_ID;
return (nid + FUSE_ROOT_ID);
}
stbuf->st_mode = vi->i_mode;
stbuf->st_nlink = vi->i_nlink;
stbuf->st_size = vi->i_size;
- stbuf->st_blocks = roundup(vi->i_size, erofs_blksiz(&sbi)) >> 9;
+ stbuf->st_blocks = roundup(vi->i_size, erofs_blksiz(&g_sbi)) >> 9;
stbuf->st_uid = vi->i_uid;
stbuf->st_gid = vi->i_gid;
stbuf->st_ctime = vi->i_mtime;
#if FUSE_MAJOR_VERSION >= 3
int ret;
struct erofs_inode vi = {
- .sbi = &sbi,
+ .sbi = &g_sbi,
.nid = ctx->de_nid
};
if (!strncmp(lookup_ctx->target_name, ctx->dname, ctx->de_namelen)) {
int ret;
struct erofs_inode vi = {
- .sbi = &sbi,
+ .sbi = &g_sbi,
.nid = (erofs_nid_t)ctx->de_nid,
};
return;
}
- vi->sbi = &sbi;
+ vi->sbi = &g_sbi;
vi->nid = erofsfuse_to_nid(ino);
ret = erofs_read_inode_from_disk(vi);
if (ret < 0) {
{
int ret;
struct stat stbuf = { 0 };
- struct erofs_inode vi = { .sbi = &sbi, .nid = erofsfuse_to_nid(ino) };
+ struct erofs_inode vi = { .sbi = &g_sbi, .nid = erofsfuse_to_nid(ino) };
ret = erofs_read_inode_from_disk(&vi);
if (ret < 0)
return;
}
- vi->sbi = &sbi;
+ vi->sbi = &g_sbi;
vi->nid = erofsfuse_to_nid(ino);
ret = erofs_read_inode_from_disk(vi);
if (ret < 0) {
return;
}
- vi->sbi = &sbi;
+ vi->sbi = &g_sbi;
vi->nid = erofsfuse_to_nid(parent);
ret = erofs_read_inode_from_disk(vi);
if (ret < 0) {
{
int ret;
char *buf = NULL;
- struct erofs_inode vi = { .sbi = &sbi, .nid = erofsfuse_to_nid(ino) };
+ struct erofs_inode vi = { .sbi = &g_sbi, .nid = erofsfuse_to_nid(ino) };
ret = erofs_read_inode_from_disk(&vi);
if (ret < 0) {
{
int ret;
char *buf = NULL;
- struct erofs_inode vi = { .sbi = &sbi, .nid = erofsfuse_to_nid(ino) };
+ struct erofs_inode vi = { .sbi = &g_sbi, .nid = erofsfuse_to_nid(ino) };
erofs_dbg("getattr(%llu): name = %s, size = %zu", ino | 0ULL, name, size);
{
int ret;
char *buf = NULL;
- struct erofs_inode vi = { .sbi = &sbi, .nid = erofsfuse_to_nid(ino) };
+ struct erofs_inode vi = { .sbi = &g_sbi, .nid = erofsfuse_to_nid(ino) };
erofs_dbg("listxattr(%llu): size = %zu", ino | 0ULL, size);
switch (key) {
case 1:
- ret = erofs_blob_open_ro(&sbi, arg + sizeof("--device=") - 1);
+ ret = erofs_blob_open_ro(&g_sbi, arg + sizeof("--device=") - 1);
if (ret)
return -1;
- ++sbi.extra_devices;
+ ++g_sbi.extra_devices;
return 0;
case FUSE_OPT_KEY_NONOPT:
if (fusecfg.mountpoint)
if (fusecfg.odebug && cfg.c_dbg_lvl < EROFS_DBG)
cfg.c_dbg_lvl = EROFS_DBG;
- sbi.bdev.offset = fusecfg.offset;
- ret = erofs_dev_open(&sbi, fusecfg.disk, O_RDONLY);
+ g_sbi.bdev.offset = fusecfg.offset;
+ ret = erofs_dev_open(&g_sbi, fusecfg.disk, O_RDONLY);
if (ret) {
fprintf(stderr, "failed to open: %s\n", fusecfg.disk);
goto err_fuse_free_args;
}
- ret = erofs_read_superblock(&sbi);
+ ret = erofs_read_superblock(&g_sbi);
if (ret) {
fprintf(stderr, "failed to read erofs super block\n");
goto err_dev_close;
#endif
err_super_put:
- erofs_put_super(&sbi);
+ erofs_put_super(&g_sbi);
err_dev_close:
- erofs_blob_closeall(&sbi);
- erofs_dev_close(&sbi);
+ erofs_blob_closeall(&g_sbi);
+ erofs_dev_close(&g_sbi);
err_fuse_free_args:
free(opts.mountpoint);
fuse_opt_free_args(&args);
static inline const int get_alignsize(int type, int *type_ret)
{
if (type == DATA)
- return erofs_blksiz(&sbi);
+ return erofs_blksiz(&g_sbi);
if (type == INODE) {
*type_ret = META;
return sizeof(struct erofs_inode_compact);
} else if (type == DIRA) {
*type_ret = META;
- return erofs_blksiz(&sbi);
+ return erofs_blksiz(&g_sbi);
} else if (type == XATTR) {
*type_ret = META;
return sizeof(struct erofs_xattr_entry);
if (bb->blkaddr == NULL_ADDR)
return NULL_ADDR_UL;
- return erofs_pos(&sbi, bb->blkaddr) +
+ return erofs_pos(&g_sbi, bb->blkaddr) +
(end ? list_next_entry(bh, list)->off : bh->off);
}
#define NULL_ADDR_UL ((unsigned long)-1)
/* global sbi */
-extern struct erofs_sb_info sbi;
+extern struct erofs_sb_info g_sbi;
#define erofs_blksiz(sbi) (1u << (sbi)->blkszbits)
#define erofs_blknr(sbi, addr) ((addr) >> (sbi)->blkszbits)
return;
bkt = mapped_buckets[bb->type] +
- (bb->buffers.off & (erofs_blksiz(&sbi) - 1));
+ (bb->buffers.off & (erofs_blksiz(&g_sbi) - 1));
list_del(&bb->mapped_list);
list_add_tail(&bb->mapped_list, bkt);
}
unsigned int extrasize,
bool dryrun)
{
- const unsigned int blksiz = erofs_blksiz(&sbi);
+ const unsigned int blksiz = erofs_blksiz(&g_sbi);
const unsigned int blkmask = blksiz - 1;
erofs_off_t boff = bb->buffers.off;
const erofs_off_t alignedoffset = roundup(boff, alignsize);
blkaddr = bb->blkaddr;
if (blkaddr != NULL_ADDR) {
tailupdate = (tail_blkaddr == blkaddr +
- BLK_ROUND_UP(&sbi, boff));
+ BLK_ROUND_UP(&g_sbi, boff));
if (oob && !tailupdate)
return -EINVAL;
}
bb->buffers.off = boff;
/* need to update the tail_blkaddr */
if (tailupdate)
- tail_blkaddr = blkaddr + BLK_ROUND_UP(&sbi, boff);
+ tail_blkaddr = blkaddr + BLK_ROUND_UP(&g_sbi, boff);
erofs_bupdate_mapped(bb);
}
return ((alignedoffset + incr - 1) & blkmask) + 1;
unsigned int alignsize,
struct erofs_buffer_block **bbp)
{
- const unsigned int blksiz = erofs_blksiz(&sbi);
+ const unsigned int blksiz = erofs_blksiz(&g_sbi);
struct erofs_buffer_block *cur, *bb;
unsigned int used0, used_before, usedmax, used;
int ret;
erofs_bupdate_mapped(bb);
}
- blkaddr = bb->blkaddr + BLK_ROUND_UP(&sbi, bb->buffers.off);
+ blkaddr = bb->blkaddr + BLK_ROUND_UP(&g_sbi, bb->buffers.off);
if (blkaddr > tail_blkaddr)
tail_blkaddr = blkaddr;
int erofs_bflush(struct erofs_buffer_block *bb)
{
- const unsigned int blksiz = erofs_blksiz(&sbi);
+ const unsigned int blksiz = erofs_blksiz(&g_sbi);
struct erofs_buffer_block *p, *n;
erofs_blk_t blkaddr;
padding = blksiz - (p->buffers.off & (blksiz - 1));
if (padding != blksiz)
- erofs_dev_fillzero(&sbi, erofs_pos(&sbi, blkaddr) - padding,
+ erofs_dev_fillzero(&g_sbi, erofs_pos(&g_sbi, blkaddr) - padding,
padding, true);
if (p->type != DATA)
- erofs_metablkcnt += BLK_ROUND_UP(&sbi, p->buffers.off);
+ erofs_metablkcnt += BLK_ROUND_UP(&g_sbi, p->buffers.off);
erofs_dbg("block %u to %u flushed", p->blkaddr, blkaddr - 1);
erofs_bfree(p);
}
/* tail_blkaddr could be rolled back after revoking all bhs */
if (tryrevoke && blkaddr != NULL_ADDR &&
- tail_blkaddr == blkaddr + BLK_ROUND_UP(&sbi, bb->buffers.off))
+ tail_blkaddr == blkaddr + BLK_ROUND_UP(&g_sbi, bb->buffers.off))
rollback = true;
bh->op = &erofs_drop_directly_bhops;
return;
if (!rollback && bb->type != DATA)
- erofs_metablkcnt += BLK_ROUND_UP(&sbi, bb->buffers.off);
+ erofs_metablkcnt += BLK_ROUND_UP(&g_sbi, bb->buffers.off);
erofs_bfree(bb);
if (rollback)
tail_blkaddr = blkaddr;
#endif
struct erofs_configure cfg;
-struct erofs_sb_info sbi;
+struct erofs_sb_info g_sbi;
bool erofs_stdout_tty;
void erofs_init_configure(void)
struct stat st;
/* try to use the devfd for regfiles on stream 0 */
- if (strm == dbufstrm && !sbi.bdev.ops) {
+ if (strm == dbufstrm && !g_sbi.bdev.ops) {
strm->devpos = 1ULL << 40;
- if (!ftruncate(sbi.bdev.fd, strm->devpos << 1)) {
- strm->fd = dup(sbi.bdev.fd);
+ if (!ftruncate(g_sbi.bdev.fd, strm->devpos << 1)) {
+ strm->fd = dup(g_sbi.bdev.fd);
if (lseek(strm->fd, strm->devpos,
SEEK_SET) != strm->devpos)
return -EIO;
inode->i_ino[1] = inode->nid;
inode->i_nlink = 1;
- ret = erofs_rebuild_update_inode(&sbi, inode,
+ ret = erofs_rebuild_update_inode(&g_sbi, inode,
rctx->datamode);
if (ret) {
erofs_iput(inode);
}
/* reset sbi, nid after subdirs are all loaded for the final dump */
- inode->sbi = &sbi;
+ inode->sbi = &g_sbi;
inode->nid = 0;
out:
free(path);
} else if (MATCH_EXTENTED_OPT("nosbcrc", token, keylen)) {
if (vallen)
return -EINVAL;
- erofs_sb_clear_sb_chksum(&sbi);
+ erofs_sb_clear_sb_chksum(&g_sbi);
} else if (MATCH_EXTENTED_OPT("noinline_data", token, keylen)) {
if (vallen)
return -EINVAL;
erofs_err("invalid block size %s", optarg);
return -EINVAL;
}
- sbi.blkszbits = ilog2(i);
+ g_sbi.blkszbits = ilog2(i);
break;
case 'd':
case 'L':
if (optarg == NULL ||
- strlen(optarg) > sizeof(sbi.volume_name)) {
+ strlen(optarg) > sizeof(g_sbi.volume_name)) {
erofs_err("invalid volume label");
return -EINVAL;
}
- strncpy(sbi.volume_name, optarg,
- sizeof(sbi.volume_name));
+ strncpy(g_sbi.volume_name, optarg,
+ sizeof(g_sbi.volume_name));
break;
case 'T':
cfg.c_timeinherit = TIMESTAMP_FIXED;
break;
case 'U':
- if (erofs_uuid_parse(optarg, sbi.uuid)) {
+ if (erofs_uuid_parse(optarg, g_sbi.uuid)) {
erofs_err("invalid UUID %s", optarg);
return -EINVAL;
}
optarg);
return -EINVAL;
}
- erofs_sb_set_chunked_file(&sbi);
+ erofs_sb_set_chunked_file(&g_sbi);
break;
case 12:
quiet = true;
cfg.c_ovlfs_strip = false;
break;
case 517:
- sbi.bdev.offset = strtoull(optarg, &endptr, 0);
+ g_sbi.bdev.offset = strtoull(optarg, &endptr, 0);
if (*endptr != '\0') {
erofs_err("invalid disk offset %s", optarg);
return -EINVAL;
}
}
- if (cfg.c_blobdev_path && cfg.c_chunkbits < sbi.blkszbits) {
+ if (cfg.c_blobdev_path && cfg.c_chunkbits < g_sbi.blkszbits) {
erofs_err("--blobdev must be used together with --chunksize");
return -EINVAL;
}
cfg.c_showprogress = false;
}
- if (cfg.c_compr_opts[0].alg && erofs_blksiz(&sbi) != getpagesize())
+ if (cfg.c_compr_opts[0].alg && erofs_blksiz(&g_sbi) != getpagesize())
erofs_warn("Please note that subpage blocksize with compression isn't yet supported in kernel. "
"This compressed image will only work with bs = ps = %u bytes",
- erofs_blksiz(&sbi));
+ erofs_blksiz(&g_sbi));
if (pclustersize_max) {
- if (pclustersize_max < erofs_blksiz(&sbi) ||
- pclustersize_max % erofs_blksiz(&sbi)) {
+ if (pclustersize_max < erofs_blksiz(&g_sbi) ||
+ pclustersize_max % erofs_blksiz(&g_sbi)) {
erofs_err("invalid physical clustersize %u",
pclustersize_max);
return -EINVAL;
cfg.c_mkfs_pclustersize_max = pclustersize_max;
cfg.c_mkfs_pclustersize_def = cfg.c_mkfs_pclustersize_max;
}
- if (cfg.c_chunkbits && cfg.c_chunkbits < sbi.blkszbits) {
+ if (cfg.c_chunkbits && cfg.c_chunkbits < g_sbi.blkszbits) {
erofs_err("chunksize %u must be larger than block size",
1u << cfg.c_chunkbits);
return -EINVAL;
}
if (pclustersize_packed) {
- if (pclustersize_packed < erofs_blksiz(&sbi) ||
- pclustersize_packed % erofs_blksiz(&sbi)) {
+ if (pclustersize_packed < erofs_blksiz(&g_sbi) ||
+ pclustersize_packed % erofs_blksiz(&g_sbi)) {
erofs_err("invalid pcluster size for the packed file %u",
pclustersize_packed);
return -EINVAL;
cfg.c_mt_workers = erofs_get_available_processors();
cfg.c_mkfs_segment_size = 16ULL * 1024 * 1024;
#endif
- sbi.blkszbits = ilog2(min_t(u32, getpagesize(), EROFS_MAX_BLOCK_SIZE));
- cfg.c_mkfs_pclustersize_max = erofs_blksiz(&sbi);
+ g_sbi.blkszbits = ilog2(min_t(u32, getpagesize(), EROFS_MAX_BLOCK_SIZE));
+ cfg.c_mkfs_pclustersize_max = erofs_blksiz(&g_sbi);
cfg.c_mkfs_pclustersize_def = cfg.c_mkfs_pclustersize_max;
- sbi.feature_incompat = EROFS_FEATURE_INCOMPAT_ZERO_PADDING;
- sbi.feature_compat = EROFS_FEATURE_COMPAT_SB_CHKSUM |
+ g_sbi.feature_incompat = EROFS_FEATURE_INCOMPAT_ZERO_PADDING;
+ g_sbi.feature_compat = EROFS_FEATURE_COMPAT_SB_CHKSUM |
EROFS_FEATURE_COMPAT_MTIME;
}
return -EOPNOTSUPP;
}
- ret = erofs_mkfs_init_devices(&sbi, rebuild_src_count);
+ ret = erofs_mkfs_init_devices(&g_sbi, rebuild_src_count);
if (ret)
return ret;
}
DBG_BUGON(src->dev < 1);
idx = src->dev - 1;
- sbi.devs[idx].blocks = nblocks;
+ g_sbi.devs[idx].blocks = nblocks;
if (tag && *tag)
- memcpy(sbi.devs[idx].tag, tag, sizeof(sbi.devs[0].tag));
+ memcpy(g_sbi.devs[idx].tag, tag, sizeof(g_sbi.devs[0].tag));
else
/* convert UUID of the source image to a hex string */
- sprintf((char *)sbi.devs[idx].tag,
+ sprintf((char *)g_sbi.devs[idx].tag,
"%04x%04x%04x%04x%04x%04x%04x%04x",
(src->uuid[0] << 8) | src->uuid[1],
(src->uuid[2] << 8) | src->uuid[3],
if (!(cfg.c_dbg_lvl > EROFS_ERR && cfg.c_showprogress))
return;
- erofs_uuid_unparse_lower(sbi.uuid, uuid_str);
+ erofs_uuid_unparse_lower(g_sbi.uuid, uuid_str);
fprintf(stdout, "------\nFilesystem UUID: %s\n"
"Filesystem total blocks: %u (of %u-byte blocks)\n"
"Filesystem total inodes: %llu\n"
"Filesystem %s metadata blocks: %u\n"
"Filesystem %s deduplicated bytes (of source files): %llu\n",
- uuid_str, nblocks, 1U << sbi.blkszbits, sbi.inos | 0ULL,
+ uuid_str, nblocks, 1U << g_sbi.blkszbits, g_sbi.inos | 0ULL,
incr, erofs_total_metablocks(),
- incr, sbi.saved_by_deduplication | 0ULL);
+ incr, g_sbi.saved_by_deduplication | 0ULL);
}
int main(int argc, char **argv)
}
if (cfg.c_unix_timestamp != -1) {
- sbi.build_time = cfg.c_unix_timestamp;
- sbi.build_time_nsec = 0;
+ g_sbi.build_time = cfg.c_unix_timestamp;
+ g_sbi.build_time_nsec = 0;
} else if (!gettimeofday(&t, NULL)) {
- sbi.build_time = t.tv_sec;
- sbi.build_time_nsec = t.tv_usec;
+ g_sbi.build_time = t.tv_sec;
+ g_sbi.build_time_nsec = t.tv_usec;
}
- err = erofs_dev_open(&sbi, cfg.c_img_path, O_RDWR |
+ err = erofs_dev_open(&g_sbi, cfg.c_img_path, O_RDWR |
(incremental_mode ? 0 : O_TRUNC));
if (err) {
fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]);
* If mapfile is unspecified for tarfs index mode,
* 512-byte block size is enforced here.
*/
- sbi.blkszbits = 9;
+ g_sbi.blkszbits = 9;
}
}
erofs_err("failed to read superblock of %s", src->devname);
goto exit;
}
- sbi.blkszbits = src->blkszbits;
+ g_sbi.blkszbits = src->blkszbits;
}
if (!incremental_mode) {
goto exit;
}
/* generate new UUIDs for clean builds */
- erofs_uuid_generate(sbi.uuid);
+ erofs_uuid_generate(g_sbi.uuid);
} else {
union {
struct stat st;
} u;
erofs_warn("EXPERIMENTAL incremental build in use. Use at your own risk!");
- err = erofs_read_superblock(&sbi);
+ err = erofs_read_superblock(&g_sbi);
if (err) {
- erofs_err("failed to read superblock of %s", sbi.devname);
+ erofs_err("failed to read superblock of %s", g_sbi.devname);
goto exit;
}
- err = erofs_io_fstat(&sbi.bdev, &u.st);
+ err = erofs_io_fstat(&g_sbi.bdev, &u.st);
if (!err && S_ISREG(u.st.st_mode))
- u.startblk = DIV_ROUND_UP(u.st.st_size, erofs_blksiz(&sbi));
+ u.startblk = DIV_ROUND_UP(u.st.st_size, erofs_blksiz(&g_sbi));
else
- u.startblk = sbi.primarydevice_blocks;
+ u.startblk = g_sbi.primarydevice_blocks;
erofs_buffer_init(u.startblk);
sb_bh = NULL;
}
}
}
- err = erofs_load_compress_hints(&sbi);
+ err = erofs_load_compress_hints(&g_sbi);
if (err) {
erofs_err("failed to load compress hints %s",
cfg.c_compress_hints_file);
goto exit;
}
- err = z_erofs_compress_init(&sbi, sb_bh);
+ err = z_erofs_compress_init(&g_sbi, sb_bh);
if (err) {
erofs_err("failed to initialize compressor: %s",
erofs_strerror(err));
if (cfg.c_dedupe) {
if (!cfg.c_compr_opts[0].alg) {
erofs_err("Compression is not enabled. Turn on chunk-based data deduplication instead.");
- cfg.c_chunkbits = sbi.blkszbits;
+ cfg.c_chunkbits = g_sbi.blkszbits;
} else {
- err = z_erofs_dedupe_init(erofs_blksiz(&sbi));
+ err = z_erofs_dedupe_init(erofs_blksiz(&g_sbi));
if (err) {
erofs_err("failed to initialize deduplication: %s",
erofs_strerror(err));
if (((erofstar.index_mode && !erofstar.headeronly_mode) &&
!erofstar.mapfile) || cfg.c_blobdev_path) {
- err = erofs_mkfs_init_devices(&sbi, 1);
+ err = erofs_mkfs_init_devices(&g_sbi, 1);
if (err) {
erofs_err("failed to generate device table: %s",
erofs_strerror(err));
erofs_inode_manager_init();
if (tar_mode) {
- root = erofs_rebuild_make_root(&sbi);
+ root = erofs_rebuild_make_root(&g_sbi);
if (IS_ERR(root)) {
err = PTR_ERR(root);
goto exit;
if (err < 0)
goto exit;
} else if (rebuild_mode) {
- root = erofs_rebuild_make_root(&sbi);
+ root = erofs_rebuild_make_root(&g_sbi);
if (IS_ERR(root)) {
err = PTR_ERR(root);
goto exit;
if (err)
goto exit;
} else {
- err = erofs_build_shared_xattrs_from_path(&sbi, cfg.c_src_path);
+ err = erofs_build_shared_xattrs_from_path(&g_sbi, cfg.c_src_path);
if (err) {
erofs_err("failed to build shared xattrs: %s",
erofs_strerror(err));
}
if (cfg.c_extra_ea_name_prefixes)
- erofs_xattr_write_name_prefixes(&sbi, packedfile);
+ erofs_xattr_write_name_prefixes(&g_sbi, packedfile);
- root = erofs_mkfs_build_tree_from_path(&sbi, cfg.c_src_path);
+ root = erofs_mkfs_build_tree_from_path(&g_sbi, cfg.c_src_path);
if (IS_ERR(root)) {
err = PTR_ERR(root);
goto exit;
}
}
- if (erofstar.index_mode && sbi.extra_devices && !erofstar.mapfile)
- sbi.devs[0].blocks = BLK_ROUND_UP(&sbi, erofstar.offset);
+ if (erofstar.index_mode && g_sbi.extra_devices && !erofstar.mapfile)
+ g_sbi.devs[0].blocks = BLK_ROUND_UP(&g_sbi, erofstar.offset);
- if (erofs_sb_has_fragments(&sbi)) {
+ if (erofs_sb_has_fragments(&g_sbi)) {
erofs_update_progressinfo("Handling packed data ...");
- err = erofs_flush_packed_inode(&sbi);
+ err = erofs_flush_packed_inode(&g_sbi);
if (err)
goto exit;
}
- if (erofstar.index_mode || cfg.c_chunkbits || sbi.extra_devices) {
- err = erofs_mkfs_dump_blobs(&sbi);
+ if (erofstar.index_mode || cfg.c_chunkbits || g_sbi.extra_devices) {
+ err = erofs_mkfs_dump_blobs(&g_sbi);
if (err)
goto exit;
}
erofs_iput(root);
root = NULL;
- err = erofs_writesb(&sbi, sb_bh, &nblocks);
+ err = erofs_writesb(&g_sbi, sb_bh, &nblocks);
if (err)
goto exit;
if (err)
goto exit;
- err = erofs_dev_resize(&sbi, nblocks);
+ err = erofs_dev_resize(&g_sbi, nblocks);
- if (!err && erofs_sb_has_sb_chksum(&sbi)) {
- err = erofs_enable_sb_chksum(&sbi, &crc);
+ if (!err && erofs_sb_has_sb_chksum(&g_sbi)) {
+ err = erofs_enable_sb_chksum(&g_sbi, &crc);
if (!err)
erofs_info("superblock checksum 0x%08x written", crc);
}
blklst = erofs_blocklist_close();
if (blklst)
fclose(blklst);
- erofs_dev_close(&sbi);
+ erofs_dev_close(&g_sbi);
erofs_cleanup_compress_hints();
erofs_cleanup_exclude_rules();
if (cfg.c_chunkbits)