summaryrefslogtreecommitdiff
path: root/mkfs
diff options
context:
space:
mode:
authorGao Xiang <gaoxiang25@huawei.com>2019-07-16 11:15:27 +0800
committerGao Xiang <hsiangkao@aol.com>2019-08-03 11:27:42 +0800
commit1f11cf0463b503e86af3e07a84feafe05c0b10d7 (patch)
treee1adf7871a3c8fdd28f14531d73ffaed801199fd /mkfs
parentd90641d76b41f2b142439f3b1ee360daecaf0baa (diff)
erofs-utils: introduce extented options setting
Introduce option "-E" for extented options. Legacy images (linux-4.19~5.2) can be generated by "-E legacy-compress". Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Diffstat (limited to 'mkfs')
-rw-r--r--mkfs/main.c53
1 files changed, 52 insertions, 1 deletions
diff --git a/mkfs/main.c b/mkfs/main.c
index 17e4d09..1348587 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -27,6 +27,7 @@ static void usage(void)
fprintf(stderr, "Generate erofs image from DIRECTORY to FILE, and [options] are:\n");
fprintf(stderr, " -zX[,Y] X=compressor (Y=compression level, optional)\n");
fprintf(stderr, " -d# set output message level to # (maximum 9)\n");
+ fprintf(stderr, " -EX[,...] X=extended options\n");
}
u64 parse_num_from_str(const char *str)
@@ -39,11 +40,55 @@ u64 parse_num_from_str(const char *str)
return num;
}
+static int parse_extended_opts(const char *opts)
+{
+#define MATCH_EXTENTED_OPT(opt, token, keylen) \
+ (keylen == sizeof(opt) && !memcmp(token, opt, sizeof(opt)))
+
+ const char *token, *next, *tokenend, *value __maybe_unused;
+ unsigned int keylen, vallen;
+
+ value = NULL;
+ for (token = opts; *token != '\0'; token = next) {
+ const char *p = strchr(token, ',');
+
+ next = NULL;
+ if (p)
+ next = p + 1;
+ else {
+ p = token + strlen(token);
+ next = p;
+ }
+
+ tokenend = memchr(token, '=', p - token);
+ if (tokenend) {
+ keylen = tokenend - token;
+ vallen = p - tokenend - 1;
+ if (!vallen)
+ return -EINVAL;
+
+ value = tokenend + 1;
+ } else {
+ keylen = p - token;
+ vallen = 0;
+ }
+
+ if (MATCH_EXTENTED_OPT("legacy-compress", token, keylen)) {
+ if (vallen)
+ return -EINVAL;
+ /* disable compacted indexes and 0padding */
+ cfg.c_legacy_compress = true;
+ sbi.requirements &= ~EROFS_REQUIREMENT_LZ4_0PADDING;
+ }
+ }
+ return 0;
+}
+
static int mkfs_parse_options_cfg(int argc, char *argv[])
{
int opt, i;
- while ((opt = getopt(argc, argv, "d:z:")) != -1) {
+ while ((opt = getopt(argc, argv, "d:z:E:")) != -1) {
switch (opt) {
case 'z':
if (!optarg) {
@@ -66,6 +111,12 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
cfg.c_dbg_lvl = parse_num_from_str(optarg);
break;
+ case 'E':
+ opt = parse_extended_opts(optarg);
+ if (opt)
+ return opt;
+ break;
+
default: /* '?' */
return -EINVAL;
}