[PATCH 1/2] erofs-utils: add fssum function for fsck

Gao Xiang hsiangkao at linux.alibaba.com
Mon Sep 2 16:41:36 AEST 2024


Hi Jiawei,

On 2024/9/1 10:57, Jiawei Wang via Linux-erofs wrote:
> This patch introduces a fssum option to the erofs-utils fsck tool,
> enabling checksum calculation for erofs image files.
> 
> Signed-off-by: Jiawei Wang <kyr1ewang at qq.com>

There is a rule that each patch should be compilable
but this patch breaks it.

I think you should add fssum
functionality(erofs_fssum_calculate) first before using it.

> ---
>   fsck/Makefile.am |  3 ++-
>   fsck/main.c      | 30 ++++++++++++++++++++++++++++++
>   2 files changed, 32 insertions(+), 1 deletion(-)
> 
> diff --git a/fsck/Makefile.am b/fsck/Makefile.am
> index 5bdee4d..b7f0289 100644
> --- a/fsck/Makefile.am
> +++ b/fsck/Makefile.am
> @@ -4,7 +4,8 @@
>   AUTOMAKE_OPTIONS = foreign
>   bin_PROGRAMS     = fsck.erofs
>   AM_CPPFLAGS = ${libuuid_CFLAGS}
> -fsck_erofs_SOURCES = main.c
> +noinst_HEADERS = fssum.h
> +fsck_erofs_SOURCES = main.c fssum.c
>   fsck_erofs_CFLAGS = -Wall -I$(top_srcdir)/include
>   fsck_erofs_LDADD = $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} \
>   	${liblz4_LIBS} ${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS} \
> diff --git a/fsck/main.c b/fsck/main.c
> index 28f1e7e..abc0a06 100644
> --- a/fsck/main.c
> +++ b/fsck/main.c
> @@ -13,6 +13,7 @@
>   #include "erofs/compress.h"
>   #include "erofs/decompress.h"
>   #include "erofs/dir.h"
> +#include "fssum.h"
>   #include "../lib/compressor.h"
>   
>   static int erofsfsck_check_inode(erofs_nid_t pnid, erofs_nid_t nid);
> @@ -31,6 +32,7 @@ struct erofsfsck_cfg {
>   	bool overwrite;
>   	bool preserve_owner;
>   	bool preserve_perms;
> +	bool checksum;

	bool fssum;   may be better

>   };
>   static struct erofsfsck_cfg fsckcfg;
>   
> @@ -48,6 +50,7 @@ static struct option long_options[] = {
>   	{"no-preserve-owner", no_argument, 0, 10},
>   	{"no-preserve-perms", no_argument, 0, 11},
>   	{"offset", required_argument, 0, 12},
> +	{"fssum", no_argument, 0, 13},
>   	{0, 0, 0, 0},
>   };
>   
> @@ -98,6 +101,7 @@ static void usage(int argc, char **argv)
>   		" --extract[=X]          check if all files are well encoded, optionally\n"
>   		"                        extract to X\n"
>   		" --offset=#             skip # bytes at the beginning of IMAGE\n"
> +		" --fssum                calculate the checksum of iamge\n"
>   		"\n"
>   		" -a, -A, -y             no-op, for compatibility with fsck of other filesystems\n"
>   		"\n"
> @@ -225,6 +229,9 @@ static int erofsfsck_parse_options_cfg(int argc, char **argv)
>   				return -EINVAL;
>   			}
>   			break;
> +		case 13:
> +			fsckcfg.checksum = true;
> +			break;
>   		default:
>   			return -EINVAL;
>   		}
> @@ -932,6 +939,23 @@ out:
>   	return ret;
>   }
>   
> +static int erofsfsck_sum_image(struct erofs_sb_info *sbi)
> +{
> +	int ret = 0;
> +	struct erofs_dir_context ctx = {
> +		.flags = 0,
> +		.pnid = 0,
> +		.dir = NULL,
> +		.de_nid = sbi->root_nid,
> +		.dname = "",
> +		.de_namelen = 0,
> +	};
> +	
> +	ret = erofs_fssum_calculate(&ctx);
> +	
> +	return ret;

Why not `return erofs_fssum_calculate(&ctx);`

Thanks,
Gao Xiang


More information about the Linux-erofs mailing list