[PATCH v2 17/17] erofs-utils: introduce extented options setting
Gao Xiang
gaoxiang25 at huawei.com
Tue Jul 16 17:04:19 AEST 2019
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 at huawei.com>
---
README | 11 +++++++++
include/erofs/defs.h | 4 ++++
mkfs/main.c | 53 +++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 67 insertions(+), 1 deletion(-)
diff --git a/README b/README
index fec20aa..312c7cd 100644
--- a/README
+++ b/README
@@ -48,6 +48,17 @@ On Fedora, static lz4 can be installed using:
However, it's not recommended to use those versions since there was a bug
in these compressors, see [2] as well.
+How to generate legacy erofs images
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Decompression inplace and compacted indexes have been introduced in
+linux-5.3, which are not backward-compatible with older kernels.
+
+In order to generate _legacy_ erofs images for old kernels,
+add "-E legacy-compress" to the command line, e.g.
+
+ $ mkfs.erofs -E legacy-compress -zlz4hc foo.erofs.img foo/
+
Obsoleted erofs.mkfs
~~~~~~~~~~~~~~~~~~~~
diff --git a/include/erofs/defs.h b/include/erofs/defs.h
index 111b703..0d9910c 100644
--- a/include/erofs/defs.h
+++ b/include/erofs/defs.h
@@ -155,5 +155,9 @@ typedef int64_t s64;
#define DBG_BUGON(condition) BUG_ON(condition)
#endif
+#ifndef __maybe_unused
+#define __maybe_unused __attribute__((__unused__))
+#endif
+
#endif
diff --git a/mkfs/main.c b/mkfs/main.c
index eb75bdb..184b2e4 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;
}
--
2.17.1
More information about the Linux-erofs
mailing list