[WIP] [PATCH v3 05/12] erofs-utils: fuse: kill sbk
Gao Xiang
hsiangkao at aol.com
Tue Nov 3 02:55:51 AEDT 2020
(will fold into the original patch.)
Signed-off-by: Gao Xiang <hsiangkao at aol.com>
---
fuse/init.c | 78 +++++++++++++++++++---------------------
fuse/init.h | 2 +-
fuse/main.c | 2 +-
include/erofs/internal.h | 7 ++++
4 files changed, 45 insertions(+), 44 deletions(-)
diff --git a/fuse/init.c b/fuse/init.c
index 09e7b1210006..f3f7f9750468 100644
--- a/fuse/init.c
+++ b/fuse/init.c
@@ -18,8 +18,6 @@
struct erofs_super_block super;
-/* XXX: sbk needs to be replaced with sbi */
-static struct erofs_super_block *sbk = &super;
struct erofs_sb_info sbi;
static bool check_layout_compatibility(struct erofs_sb_info *sbi,
@@ -38,65 +36,61 @@ static bool check_layout_compatibility(struct erofs_sb_info *sbi,
return true;
}
-int erofs_init_super(void)
+int erofs_read_superblock(void)
{
+ char data[EROFS_BLKSIZ];
+ struct erofs_super_block *dsb;
+ unsigned int blkszbits;
int ret;
- char buf[EROFS_BLKSIZ];
- struct erofs_super_block *sb;
- memset(buf, 0, sizeof(buf));
- ret = blk_read(buf, 0, 1);
+ ret = blk_read(data, 0, 1);
if (ret < 0) {
- erofs_err("Failed to read super block ret=%d", ret);
- return -EINVAL;
+ erofs_err("cannot read erofs superblock: %d", ret);
+ return -EIO;
}
+ dsb = (struct erofs_super_block *)(data + EROFS_SUPER_OFFSET);
- sb = (struct erofs_super_block *) (buf + BOOT_SECTOR_SIZE);
- sbk->magic = le32_to_cpu(sb->magic);
- if (sbk->magic != EROFS_SUPER_MAGIC_V1) {
- erofs_err("EROFS magic[0x%X] NOT matched to [0x%X] ",
- super.magic, EROFS_SUPER_MAGIC_V1);
- return -EINVAL;
+ ret = -EINVAL;
+ if (le32_to_cpu(dsb->magic) != EROFS_SUPER_MAGIC_V1) {
+ erofs_err("cannot find valid erofs superblock");
+ return ret;
}
- if (!check_layout_compatibility(&sbi, sb))
- return -EINVAL;
+ sbi.feature_compat = le32_to_cpu(dsb->feature_compat);
- sbk->checksum = le32_to_cpu(sb->checksum);
- sbk->feature_compat = le32_to_cpu(sb->feature_compat);
- sbk->blkszbits = sb->blkszbits;
+ blkszbits = dsb->blkszbits;
+ /* 9(512 bytes) + LOG_SECTORS_PER_BLOCK == LOG_BLOCK_SIZE */
+ if (blkszbits != LOG_BLOCK_SIZE) {
+ erofs_err("blksize %u isn't supported on this platform",
+ 1 << blkszbits);
+ return ret;
+ }
+
+ if (!check_layout_compatibility(&sbi, dsb))
+ return ret;
- sbk->inos = le64_to_cpu(sb->inos);
- sbk->build_time = le64_to_cpu(sb->build_time);
- sbk->build_time_nsec = le32_to_cpu(sb->build_time_nsec);
- sbk->blocks = le32_to_cpu(sb->blocks);
- sbk->meta_blkaddr = le32_to_cpu(sb->meta_blkaddr);
- sbi.meta_blkaddr = sbk->meta_blkaddr;
- sbk->xattr_blkaddr = le32_to_cpu(sb->xattr_blkaddr);
+ sbi.blocks = le32_to_cpu(dsb->blocks);
+ sbi.meta_blkaddr = le32_to_cpu(dsb->meta_blkaddr);
+ sbi.xattr_blkaddr = le32_to_cpu(dsb->xattr_blkaddr);
sbi.islotbits = EROFS_ISLOTBITS;
- memcpy(sbk->uuid, sb->uuid, 16);
- memcpy(sbk->volume_name, sb->volume_name, 16);
- sbk->root_nid = le16_to_cpu(sb->root_nid);
-
- erofs_dump("%-15s:0x%X\n", STR(magic), SUPER_MEM(magic));
- erofs_dump("%-15s:0x%X\n", STR(feature_incompat), sbi.feature_incompat);
- erofs_dump("%-15s:0x%X\n", STR(feature_compat), SUPER_MEM(feature_compat));
- erofs_dump("%-15s:%u\n", STR(blkszbits), SUPER_MEM(blkszbits));
- erofs_dump("%-15s:%u\n", STR(root_nid), SUPER_MEM(root_nid));
- erofs_dump("%-15s:%llu\n", STR(inos), (unsigned long long)SUPER_MEM(inos));
- erofs_dump("%-15s:%d\n", STR(meta_blkaddr), SUPER_MEM(meta_blkaddr));
- erofs_dump("%-15s:%d\n", STR(xattr_blkaddr), SUPER_MEM(xattr_blkaddr));
+ sbi.root_nid = le16_to_cpu(dsb->root_nid);
+ sbi.inos = le64_to_cpu(dsb->inos);
+
+ sbi.build_time = le64_to_cpu(dsb->build_time);
+ sbi.build_time_nsec = le32_to_cpu(dsb->build_time_nsec);
+
+ memcpy(&sbi.uuid, dsb->uuid, sizeof(dsb->uuid));
return 0;
}
erofs_nid_t erofs_get_root_nid(void)
{
- return sbk->root_nid;
+ return sbi.root_nid;
}
erofs_nid_t addr2nid(erofs_off_t addr)
{
- erofs_nid_t offset = (erofs_nid_t)sbk->meta_blkaddr * EROFS_BLKSIZ;
+ erofs_nid_t offset = (erofs_nid_t)sbi.meta_blkaddr * EROFS_BLKSIZ;
DBG_BUGON(!IS_SLOT_ALIGN(addr));
return (addr - offset) >> EROFS_ISLOTBITS;
@@ -104,7 +98,7 @@ erofs_nid_t addr2nid(erofs_off_t addr)
erofs_off_t nid2addr(erofs_nid_t nid)
{
- erofs_off_t offset = (erofs_off_t)sbk->meta_blkaddr * EROFS_BLKSIZ;
+ erofs_off_t offset = (erofs_off_t)sbi.meta_blkaddr * EROFS_BLKSIZ;
return (nid << EROFS_ISLOTBITS) + offset;
}
diff --git a/fuse/init.h b/fuse/init.h
index 34085f2b548d..062cd69f6e4d 100644
--- a/fuse/init.h
+++ b/fuse/init.h
@@ -13,7 +13,7 @@
#define BOOT_SECTOR_SIZE 0x400
-int erofs_init_super(void);
+int erofs_read_superblock(void);
erofs_nid_t erofs_get_root_nid(void);
erofs_off_t nid2addr(erofs_nid_t nid);
erofs_nid_t addr2nid(erofs_off_t addr);
diff --git a/fuse/main.c b/fuse/main.c
index 26f49f6fc299..fed4488081d8 100644
--- a/fuse/main.c
+++ b/fuse/main.c
@@ -147,7 +147,7 @@ int main(int argc, char *argv[])
goto exit;
}
- if (erofs_init_super()) {
+ if (erofs_read_superblock()) {
fprintf(stderr, "Failed to read erofs super block\n");
goto exit_dev;
}
diff --git a/include/erofs/internal.h b/include/erofs/internal.h
index 54038071bf84..306005dea2a7 100644
--- a/include/erofs/internal.h
+++ b/include/erofs/internal.h
@@ -63,6 +63,8 @@ typedef u32 erofs_blk_t;
struct erofs_buffer_head;
struct erofs_sb_info {
+ u64 blocks;
+
erofs_blk_t meta_blkaddr;
erofs_blk_t xattr_blkaddr;
@@ -73,6 +75,11 @@ struct erofs_sb_info {
unsigned char islotbits;
+ /* what we really care is nid, rather than ino.. */
+ erofs_nid_t root_nid;
+ /* used for statfs, f_files - f_favail */
+ u64 inos;
+
u8 uuid[16];
};
--
2.24.0
More information about the Linux-erofs
mailing list