Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
affggh committed Aug 19, 2023
2 parents a4c337e + ac3b2b1 commit e8c2845
Show file tree
Hide file tree
Showing 41 changed files with 1,295 additions and 820 deletions.
57 changes: 43 additions & 14 deletions dump/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ static struct erofsdump_feature feature_lists[] = {
{ true, EROFS_FEATURE_COMPAT_SB_CHKSUM, "sb_csum" },
{ true, EROFS_FEATURE_COMPAT_MTIME, "mtime" },
{ false, EROFS_FEATURE_INCOMPAT_ZERO_PADDING, "0padding" },
{ false, EROFS_FEATURE_INCOMPAT_COMPR_CFGS, "compr_cfgs" },
{ false, EROFS_FEATURE_INCOMPAT_BIG_PCLUSTER, "big_pcluster" },
{ false, EROFS_FEATURE_INCOMPAT_CHUNKED_FILE, "chunked_file" },
{ false, EROFS_FEATURE_INCOMPAT_DEVICE_TABLE, "device_table" },
{ false, EROFS_FEATURE_INCOMPAT_ZTAILPACKING, "ztailpacking" },
{ false, EROFS_FEATURE_INCOMPAT_FRAGMENTS, "fragments" },
{ false, EROFS_FEATURE_INCOMPAT_DEDUPE, "dedupe" },
{ false, EROFS_FEATURE_INCOMPAT_XATTR_PREFIXES, "xattr_prefixes" },
};

static int erofsdump_readdir(struct erofs_dir_context *ctx);
Expand Down Expand Up @@ -154,7 +156,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;
Expand Down Expand Up @@ -202,7 +204,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");
Expand Down Expand Up @@ -270,9 +272,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);
Expand All @@ -296,7 +298,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) {
Expand Down Expand Up @@ -351,7 +353,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};
Expand Down Expand Up @@ -382,7 +384,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';
Expand Down Expand Up @@ -447,7 +449,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;
Expand Down Expand Up @@ -588,6 +590,23 @@ static void erofsdump_print_statistic(void)
erofsdump_filetype_distribution(file_types, OTHERFILETYPE);
}

static void erofsdump_print_supported_compressors(FILE *f, unsigned int mask)
{
unsigned int i = 0;
bool comma = false;
const char *s;

while ((s = z_erofs_list_supported_algorithms(i++, &mask)) != NULL) {
if (*s == '\0')
continue;
if (comma)
fputs(", ", f);
fputs(s, f);
comma = true;
}
fputc('\n', f);
}

static void erofsdump_show_superblock(void)
{
time_t time = sbi.build_time;
Expand All @@ -604,9 +623,19 @@ 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);
if (erofs_sb_has_compr_cfgs(&sbi)) {
fprintf(stdout, "Filesystem compr_algs: ");
erofsdump_print_supported_compressors(stdout,
sbi.available_compr_algs);
} else {
fprintf(stdout, "Filesystem lz4_max_distance: %u\n",
sbi.lz4_max_distance | 0U);
}
fprintf(stdout, "Filesystem sb_extslots: %u\n",
sbi.extslots | 0U);
fprintf(stdout, "Filesystem inode count: %llu\n",
sbi.inos | 0ULL);
fprintf(stdout, "Filesystem created: %s",
Expand Down Expand Up @@ -636,13 +665,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;
Expand All @@ -667,11 +696,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;
}
46 changes: 25 additions & 21 deletions fsck/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ static struct list_head erofsfsck_link_hashtable[NR_HARDLINK_HASHTABLE];

static void print_available_decompressors(FILE *f, const char *delim)
{
unsigned int i = 0;
int i = 0;
bool comma = false;
const char *s;

while ((s = z_erofs_list_available_compressors(i)) != NULL) {
if (i++)
while ((s = z_erofs_list_available_compressors(&i)) != NULL) {
if (comma)
fputs(delim, f);
fputs(s, f);
comma = true;
}
fputc('\n', f);
}
Expand Down Expand Up @@ -158,7 +160,7 @@ static int erofsfsck_parse_options_cfg(int argc, char **argv)
}
break;
case 3:
ret = blob_open_ro(optarg);
ret = blob_open_ro(&sbi, optarg);
if (ret)
return ret;
++sbi.extra_devices;
Expand Down Expand Up @@ -279,7 +281,7 @@ static int erofs_check_sb_chksum(void)
struct erofs_super_block *sb;
int ret;

ret = blk_read(0, buf, 0, 1);
ret = blk_read(&sbi, 0, buf, 0, 1);
if (ret) {
erofs_err("failed to read superblock to check checksum: %d",
ret);
Expand All @@ -289,7 +291,7 @@ static int erofs_check_sb_chksum(void)
sb = (struct erofs_super_block *)(buf + EROFS_SUPER_OFFSET);
sb->checksum = 0;

crc = erofs_crc32c(~0, (u8 *)sb, erofs_blksiz() - EROFS_SUPER_OFFSET);
crc = erofs_crc32c(~0, (u8 *)sb, erofs_blksiz(&sbi) - EROFS_SUPER_OFFSET);
if (crc != sbi.checksum) {
erofs_err("superblock chksum doesn't match: saved(%08xh) calculated(%08xh)",
sbi.checksum, crc);
Expand All @@ -302,6 +304,7 @@ static int erofs_check_sb_chksum(void)

static int erofs_verify_xattr(struct erofs_inode *inode)
{
struct erofs_sb_info *sbi = inode->sbi;
unsigned int xattr_hdr_size = sizeof(struct erofs_xattr_ibody_header);
unsigned int xattr_entry_size = sizeof(struct erofs_xattr_entry);
erofs_off_t addr;
Expand All @@ -326,7 +329,7 @@ static int erofs_verify_xattr(struct erofs_inode *inode)
}

addr = erofs_iloc(inode) + inode->inode_isize;
ret = dev_read(0, buf, addr, xattr_hdr_size);
ret = dev_read(sbi, 0, buf, addr, xattr_hdr_size);
if (ret < 0) {
erofs_err("failed to read xattr header @ nid %llu: %d",
inode->nid | 0ULL, ret);
Expand All @@ -335,12 +338,12 @@ static int erofs_verify_xattr(struct erofs_inode *inode)
ih = (struct erofs_xattr_ibody_header *)buf;
xattr_shared_count = ih->h_shared_count;

ofs = erofs_blkoff(addr) + xattr_hdr_size;
ofs = erofs_blkoff(sbi, addr) + xattr_hdr_size;
addr += xattr_hdr_size;
remaining -= xattr_hdr_size;
for (i = 0; i < xattr_shared_count; ++i) {
if (ofs >= erofs_blksiz()) {
if (ofs != erofs_blksiz()) {
if (ofs >= erofs_blksiz(sbi)) {
if (ofs != erofs_blksiz(sbi)) {
erofs_err("unaligned xattr entry in xattr shared area @ nid %llu",
inode->nid | 0ULL);
ret = -EFSCORRUPTED;
Expand All @@ -356,7 +359,7 @@ static int erofs_verify_xattr(struct erofs_inode *inode)
while (remaining > 0) {
unsigned int entry_sz;

ret = dev_read(0, buf, addr, xattr_entry_size);
ret = dev_read(sbi, 0, buf, addr, xattr_entry_size);
if (ret) {
erofs_err("failed to read xattr entry @ nid %llu: %d",
inode->nid | 0ULL, ret);
Expand Down Expand Up @@ -483,7 +486,7 @@ static int erofs_verify_inode_data(struct erofs_inode *inode, int outfd)
u64 count = min_t(u64, alloc_rawsize,
map.m_llen);

ret = erofs_read_one_data(&map, raw, p, count);
ret = erofs_read_one_data(inode, &map, raw, p, count);
if (ret)
goto out;

Expand All @@ -497,8 +500,8 @@ static int erofs_verify_inode_data(struct erofs_inode *inode, int outfd)

if (fsckcfg.print_comp_ratio) {
if (!erofs_is_packed_inode(inode))
fsckcfg.logical_blocks += BLK_ROUND_UP(inode->i_size);
fsckcfg.physical_blocks += BLK_ROUND_UP(pchunk_len);
fsckcfg.logical_blocks += BLK_ROUND_UP(inode->sbi, inode->i_size);
fsckcfg.physical_blocks += BLK_ROUND_UP(inode->sbi, pchunk_len);
}
out:
if (raw)
Expand Down Expand Up @@ -845,6 +848,7 @@ static int erofsfsck_check_inode(erofs_nid_t pnid, erofs_nid_t nid)
erofs_dbg("check inode: nid(%llu)", nid | 0ULL);

inode.nid = nid;
inode.sbi = &sbi;
ret = erofs_read_inode_from_disk(&inode);
if (ret) {
if (ret == -EIO)
Expand Down Expand Up @@ -920,27 +924,27 @@ int main(int argc, char *argv[])
cfg.c_dbg_lvl = -1;
#endif

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;
}

if (erofs_sb_has_sb_chksum() && erofs_check_sb_chksum()) {
if (erofs_sb_has_sb_chksum(&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.packed_nid > 0) {
if (erofs_sb_has_fragments(&sbi) && sbi.packed_nid > 0) {
err = erofsfsck_check_inode(sbi.packed_nid, sbi.packed_nid);
if (err) {
erofs_err("failed to verify packed file");
Expand Down Expand Up @@ -974,11 +978,11 @@ int main(int argc, char *argv[])
if (fsckcfg.extract_path)
erofsfsck_hardlink_exit();
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 ? 1 : 0;
}
Expand Down
Loading

0 comments on commit e8c2845

Please sign in to comment.