Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 39588C6FD1C for ; Tue, 14 Mar 2023 06:21:39 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4PbNhd47yLz3cLf for ; Tue, 14 Mar 2023 17:21:37 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.alibaba.com (client-ip=115.124.30.111; helo=out30-111.freemail.mail.aliyun.com; envelope-from=hsiangkao@linux.alibaba.com; receiver=) Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4PbNhX5sW4z3cBp for ; Tue, 14 Mar 2023 17:21:31 +1100 (AEDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045192;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=2;SR=0;TI=SMTPD_---0VdqrT9p_1678774882; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VdqrT9p_1678774882) by smtp.aliyun-inc.com; Tue, 14 Mar 2023 14:21:26 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org Subject: [PATCH v2 1/4] erofs-utils: mkfs: validate chunk/pcluster sizes in the end Date: Tue, 14 Mar 2023 14:21:18 +0800 Message-Id: <20230314062121.115020-1-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: linux-erofs@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development of Linux EROFS file system List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gao Xiang Errors-To: linux-erofs-bounces+linux-erofs=archiver.kernel.org@lists.ozlabs.org Sender: "Linux-erofs" Laterly, erofs-utils will support sub-page block sizes and an arbitrary block size can be given at any position of the command line. Therefore, chunk/pcluster sizes needs to be validated in the end. Signed-off-by: Gao Xiang --- v2: no change. mkfs/main.c | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/mkfs/main.c b/mkfs/main.c index 94f51df..8e5a421 100644 --- a/mkfs/main.c +++ b/mkfs/main.c @@ -126,6 +126,8 @@ static void usage(void) print_available_compressors(stderr, ", "); } +static unsigned int pclustersize_packed, pclustersize_max; + static int parse_extended_opts(const char *opts) { #define MATCH_EXTENTED_OPT(opt, token, keylen) \ @@ -222,13 +224,12 @@ handle_fragment: cfg.c_fragments = true; if (vallen) { i = strtoull(value, &endptr, 0); - if (endptr - value != vallen || - i < EROFS_BLKSIZ || i % EROFS_BLKSIZ) { + if (endptr - value != vallen) { erofs_err("invalid pcluster size for the packed file %s", next); return -EINVAL; } - cfg.c_pclusterblks_packed = i / EROFS_BLKSIZ; + pclustersize_packed = i; } } @@ -415,14 +416,12 @@ static int mkfs_parse_options_cfg(int argc, char *argv[]) #endif case 'C': i = strtoull(optarg, &endptr, 0); - if (*endptr != '\0' || - i < EROFS_BLKSIZ || i % EROFS_BLKSIZ) { + if (*endptr != '\0') { erofs_err("invalid physical clustersize %s", optarg); return -EINVAL; } - cfg.c_pclusterblks_max = i / EROFS_BLKSIZ; - cfg.c_pclusterblks_def = cfg.c_pclusterblks_max; + pclustersize_max = i; break; case 11: i = strtol(optarg, &endptr, 0); @@ -436,11 +435,6 @@ static int mkfs_parse_options_cfg(int argc, char *argv[]) optarg); return -EINVAL; } - if (i < EROFS_BLKSIZ) { - erofs_err("chunksize %s must be larger than block size", - optarg); - return -EINVAL; - } erofs_sb_set_chunked_file(); break; case 12: @@ -521,6 +515,32 @@ static int mkfs_parse_options_cfg(int argc, char *argv[]) cfg.c_dbg_lvl = EROFS_ERR; cfg.c_showprogress = false; } + + if (pclustersize_max) { + if (pclustersize_max < EROFS_BLKSIZ || + pclustersize_max % EROFS_BLKSIZ) { + erofs_err("invalid physical clustersize %u", + pclustersize_max); + return -EINVAL; + } + cfg.c_pclusterblks_max = pclustersize_max / EROFS_BLKSIZ; + cfg.c_pclusterblks_def = cfg.c_pclusterblks_max; + } + if (cfg.c_chunkbits && 1u << cfg.c_chunkbits < EROFS_BLKSIZ) { + erofs_err("chunksize %u must be larger than block size", + 1u << cfg.c_chunkbits); + return -EINVAL; + } + + if (pclustersize_packed) { + if (pclustersize_max < EROFS_BLKSIZ || + pclustersize_max % EROFS_BLKSIZ) { + erofs_err("invalid pcluster size for the packed file %u", + pclustersize_packed); + return -EINVAL; + } + cfg.c_pclusterblks_packed = pclustersize_packed / EROFS_BLKSIZ; + } return 0; } -- 2.24.4