aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGao Xiang <hsiangkao@linux.alibaba.com>2023-03-14 14:21:18 +0800
committerGao Xiang <hsiangkao@linux.alibaba.com>2023-03-15 16:29:12 +0800
commit44262327852606a9595b9b8f699a795a08f0f0e4 (patch)
tree8dcd271de65a050f35e023048ef7f1965fe1380e
parent5024ab562ca760361c6dadc2797ac4f12fff24bd (diff)
downloaderofs-utils-44262327852606a9595b9b8f699a795a08f0f0e4.tar.gz
erofs-utils: mkfs: validate chunk/pcluster sizes in the end
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 <hsiangkao@linux.alibaba.com> Link: https://lore.kernel.org/r/20230314062121.115020-1-hsiangkao@linux.alibaba.com
-rw-r--r--mkfs/main.c44
1 files 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;
}