<div dir="ltr"><div>Thanks Gao,</div><div><br></div><div>Let me know when we can work on debug utility OR atleast list out things we want to achieve through the utility.</div><div>Regarding the superblock checksum calculations, Yes I will dedicate sometime this week for it. will start exploring it.</div><div><br></div><div>--Pratik.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Aug 21, 2019 at 10:26 PM Gao Xiang <<a href="mailto:hsiangkao@aol.com">hsiangkao@aol.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Pratik,<br>
<br>
On Wed, Aug 21, 2019 at 10:08:08PM +0530, Pratik Shinde wrote:<br>
> Hello Maintainers,<br>
> <br>
> After going through the recent mail thread between linux's filesystem folks<br>
> on erofs channel, I felt erofs needs an interactive debug utility (like xfs_db)<br>
> which can be used to examine erofs images & can also be used to inject errors OR<br>
> fuzzing for testing purpose & dumping different erofs meta data structures<br>
> for debugging.<br>
> In order to demonstrate above I wrote an experimental patch that simply dumps<br>
> the superblock of an image after mkfs completes.the full fletch utility will run<br>
> independently and be able to seek / print / modify any byte of an erofs image,<br>
> dump structures/lists/directory content of an image.<br>
<br>
Yes, I think we really need that interactive tools, actually I'm stuggling in<br>
modifing Guifu's erofs-fuse now, we need to add the parsing ability to "lib/"<br>
first.<br>
<br>
I mean, first, I will add a "fuse" field to "cfg". If it is false, it will<br>
generate a image, or it will parse a image...<br>
And then we need to add parsing logic into "lib/" as well, and use <br>
"if (cfg.fuse)" to differnate whether it should read or write data.<br>
<br>
That is my prelimitary thought.. I will work on this framework in this weekend.<br>
and then we can work together on it. :)<br>
<br>
p.s. Pratik, if you have some time, could you take some extra time adding the<br>
super checksum calulation to EROFS? I mean we can add EROFS_FEATURE_SB_CHKSUM<br>
to the compat superblock field ("features"), and do crc32_le on kernel and mkfs...<br>
If you dont have time, I will do it later instead... (since we are using EROFS<br>
on the top of dm-verity, but completing the superblock chksum is also a good idea.)<br>
<br>
And then we can add block-based verification layer to EROFS, it can be seen<br>
as a hash tree like dm-verity or just simply CRC32 arrays for user to choise.<br>
<br>
Thanks,<br>
Gao Xiang<br>
<br>
> <br>
> NOTE:This is an experimental patch just to demonstrate the purpose. The patch<br>
> lacks a lot of things like coding standard, and new code runs in the context<br>
> of mkfs itself.kindly ignore it.<br>
> <br>
> kindly provide your feedback on this.<br>
> <br>
> Signed-off-by: Pratik Shinde <<a href="mailto:pratikshinde320@gmail.com" target="_blank">pratikshinde320@gmail.com</a>><br>
> ---<br>
>  include/erofs/io.h |  8 ++++++++<br>
>  lib/io.c           | 27 +++++++++++++++++++++++++++<br>
>  mkfs/main.c        | 36 ++++++++++++++++++++++++++++++++++++<br>
>  3 files changed, 71 insertions(+)<br>
> <br>
> diff --git a/include/erofs/io.h b/include/erofs/io.h<br>
> index 4b574bd..e91d6ee 100644<br>
> --- a/include/erofs/io.h<br>
> +++ b/include/erofs/io.h<br>
> @@ -18,6 +18,7 @@<br>
>  <br>
>  int dev_open(const char *devname);<br>
>  void dev_close(void);<br>
> +int dev_read(void *buf, u64 offset, size_t len);<br>
>  int dev_write(const void *buf, u64 offset, size_t len);<br>
>  int dev_fillzero(u64 offset, size_t len, bool padding);<br>
>  int dev_fsync(void);<br>
> @@ -30,5 +31,12 @@ static inline int blk_write(const void *buf, erofs_blk_t blkaddr,<br>
>                        blknr_to_addr(nblocks));<br>
>  }<br>
>  <br>
> +static inline int blk_read(void *buf, erofs_blk_t blkaddr,<br>
> +                        u32 nblocks)<br>
> +{<br>
> +     return dev_read(buf, blknr_to_addr(blkaddr),<br>
> +                     blknr_to_addr(nblocks));<br>
> +}<br>
> +<br>
>  #endif<br>
>  <br>
> diff --git a/lib/io.c b/lib/io.c<br>
> index 15c5a35..87d7d6c 100644<br>
> --- a/lib/io.c<br>
> +++ b/lib/io.c<br>
> @@ -109,6 +109,33 @@ u64 dev_length(void)<br>
>       return erofs_devsz;<br>
>  }<br>
>  <br>
> +int dev_read(void *buf, u64 offset, size_t len)<br>
> +{<br>
> +     int ret;<br>
> +<br>
> +     if (cfg.c_dry_run)<br>
> +             return 0;<br>
> +<br>
> +     if (!buf) {<br>
> +             erofs_err("buf is NULL");<br>
> +             return -EINVAL;<br>
> +     }<br>
> +     if (offset >= erofs_devsz || len > erofs_devsz ||<br>
> +         offset > erofs_devsz - len) {<br>
> +             erofs_err("read posion[%" PRIu64 ", %zd] is too large beyond the end of device(%" PRIu64 ").",<br>
> +                       offset, len, erofs_devsz);<br>
> +             return -EINVAL;<br>
> +     }<br>
> +<br>
> +     ret = pread64(erofs_devfd, buf, len, (off64_t)offset);<br>
> +     if (ret != (int)len) {<br>
> +             erofs_err("Failed to read data from device - %s:[%" PRIu64 ", %zd].",<br>
> +                       erofs_devname, offset, len);<br>
> +             return -errno;<br>
> +     }<br>
> +     return 0;<br>
> +}<br>
> +<br>
>  int dev_write(const void *buf, u64 offset, size_t len)<br>
>  {<br>
>       int ret;<br>
> diff --git a/mkfs/main.c b/mkfs/main.c<br>
> index f127fe1..109486e 100644<br>
> --- a/mkfs/main.c<br>
> +++ b/mkfs/main.c<br>
> @@ -182,6 +182,41 @@ int erofs_mkfs_update_super_block(struct erofs_buffer_head *bh,<br>
>       return 0;<br>
>  }<br>
>  <br>
> +void erofs_dump_super(char *img_path)<br>
> +{<br>
> +     struct erofs_super_block *sb;<br>
> +     char buf[EROFS_BLKSIZ];<br>
> +     unsigned int blksz;<br>
> +     int ret = 0;<br>
> +<br>
> +     if (img_path == NULL) {<br>
> +             erofs_err("image path cannot be null");<br>
> +             return;<br>
> +     }<br>
> +     ret = blk_read(buf, 0, 1);<br>
> +     if (ret) {<br>
> +             erofs_err("error reading super-block structure");<br>
> +             return;<br>
> +     }<br>
> +<br>
> +     sb = (struct erofs_super_block *)((u8 *)buf + EROFS_SUPER_OFFSET);<br>
> +     if (le32_to_cpu(sb->magic) != EROFS_SUPER_MAGIC_V1) {<br>
> +             erofs_err("not a erofs image");<br>
> +             return;<br>
> +     }<br>
> +<br>
> +     erofs_dump("magic: 0x%x\n", le32_to_cpu(sb->magic));<br>
> +     blksz = 1 << sb->blkszbits;<br>
> +     erofs_dump("block size: %d\n", blksz);<br>
> +     erofs_dump("root inode: %d\n", le32_to_cpu(sb->root_nid));<br>
> +     erofs_dump("inodes: %llu\n", le64_to_cpu(sb->inos));<br>
> +     erofs_dump("build time: %u\n", le32_to_cpu(sb->build_time));<br>
> +     erofs_dump("blocks: %u\n", le32_to_cpu(sb->blocks));<br>
> +     erofs_dump("meta block: %u\n", le32_to_cpu(sb->meta_blkaddr));<br>
> +     erofs_dump("xattr block: %u\n", le32_to_cpu(sb->xattr_blkaddr));<br>
> +     erofs_dump("requirements: 0x%x\n", le32_to_cpu(sb->requirements));<br>
> +}<br>
> +<br>
>  int main(int argc, char **argv)<br>
>  {<br>
>       int err = 0;<br>
> @@ -268,6 +303,7 @@ int main(int argc, char **argv)<br>
>               err = -EIO;<br>
>  exit:<br>
>       z_erofs_compress_exit();<br>
> +     erofs_dump_super("dummy");<br>
>       dev_close();<br>
>       erofs_exit_configure();<br>
>  <br>
> -- <br>
> 2.9.3<br>
> <br>
</blockquote></div>