[PATCH] erofs-utils: mkfs: error return if meets an unknown extended option

Gao Xiang hsiangkao at linux.alibaba.com
Tue Sep 12 13:02:23 AEST 2023



On 2023/9/9 20:36, Yifan Zhao wrote:
> Currently mkfs would ignore any unknown extended option, which keeps
> silent if a mistyped option is given. Return failure in this case allows
> users to catch their errors more easily.

Applied with some modification:

https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git/commit/?id=e6dd153f48dbb64369b5d4480b734bb61782b8b1

BTW, this patch missed a "Signed-off-by" tag (I added one since we often
talked via WeChat these days), you'd better to add this when submitting
a patch to open-source communities.


> ---
>   mkfs/main.c | 27 ++++++++++++++++-----------
>   1 file changed, 16 insertions(+), 11 deletions(-)
> 
> diff --git a/mkfs/main.c b/mkfs/main.c
> index 607c883..4caf267 100644
> --- a/mkfs/main.c
> +++ b/mkfs/main.c
> @@ -186,55 +186,55 @@ static int parse_extended_opts(const char *opts)
>   			cfg.c_legacy_compress = true;
>   		}
>   
> -		if (MATCH_EXTENTED_OPT("force-inode-compact", token, keylen)) {
> +		else if (MATCH_EXTENTED_OPT("force-inode-compact", token, keylen)) {
>   			if (vallen)
>   				return -EINVAL;
>   			cfg.c_force_inodeversion = FORCE_INODE_COMPACT;
>   			cfg.c_ignore_mtime = true;
>   		}
>   
> -		if (MATCH_EXTENTED_OPT("force-inode-extended", token, keylen)) {
> +		else if (MATCH_EXTENTED_OPT("force-inode-extended", token, keylen)) {
>   			if (vallen)
>   				return -EINVAL;
>   			cfg.c_force_inodeversion = FORCE_INODE_EXTENDED;
>   		}
>   
> -		if (MATCH_EXTENTED_OPT("nosbcrc", token, keylen)) {
> +		else if (MATCH_EXTENTED_OPT("nosbcrc", token, keylen)) {
>   			if (vallen)
>   				return -EINVAL;
>   			erofs_sb_clear_sb_chksum(&sbi);
>   		}
>   
> -		if (MATCH_EXTENTED_OPT("noinline_data", token, keylen)) {
> +		else if (MATCH_EXTENTED_OPT("noinline_data", token, keylen)) {
>   			if (vallen)
>   				return -EINVAL;
>   			cfg.c_noinline_data = true;
>   		}
>   
> -		if (MATCH_EXTENTED_OPT("force-inode-blockmap", token, keylen)) {
> +		else if (MATCH_EXTENTED_OPT("force-inode-blockmap", token, keylen)) {
>   			if (vallen)
>   				return -EINVAL;
>   			cfg.c_force_chunkformat = FORCE_INODE_BLOCK_MAP;
>   		}
>   
> -		if (MATCH_EXTENTED_OPT("force-chunk-indexes", token, keylen)) {
> +		else if (MATCH_EXTENTED_OPT("force-chunk-indexes", token, keylen)) {
>   			if (vallen)
>   				return -EINVAL;
>   			cfg.c_force_chunkformat = FORCE_INODE_CHUNK_INDEXES;
>   		}
>   
> -		if (MATCH_EXTENTED_OPT("ztailpacking", token, keylen)) {
> +		else if (MATCH_EXTENTED_OPT("ztailpacking", token, keylen)) {
>   			if (vallen)
>   				return -EINVAL;
>   			cfg.c_ztailpacking = true;
>   		}
>   
> -		if (MATCH_EXTENTED_OPT("all-fragments", token, keylen)) {
> +		else if (MATCH_EXTENTED_OPT("all-fragments", token, keylen)) {
>   			cfg.c_all_fragments = true;
>   			goto handle_fragment;
>   		}
>   
> -		if (MATCH_EXTENTED_OPT("fragments", token, keylen)) {
> +		else if (MATCH_EXTENTED_OPT("fragments", token, keylen)) {
>   			char *endptr;
>   			u64 i;
>   
> @@ -251,17 +251,22 @@ handle_fragment:
>   			}
>   		}
>   
> -		if (MATCH_EXTENTED_OPT("dedupe", token, keylen)) {
> +		else if (MATCH_EXTENTED_OPT("dedupe", token, keylen)) {
>   			if (vallen)
>   				return -EINVAL;
>   			cfg.c_dedupe = true;
>   		}
>   
> -		if (MATCH_EXTENTED_OPT("xattr-name-filter", token, keylen)) {
> +		else if (MATCH_EXTENTED_OPT("xattr-name-filter", token, keylen)) {
>   			if (vallen)
>   				return -EINVAL;
>   			cfg.c_xattr_name_filter = !clear;
>   		}
> +
> +		else {
> +			erofs_err("unknown extended option %s", token);
> +			return -EINVAL;
> +		}
>   	}
>   	return 0;
>   }


More information about the Linux-erofs mailing list