summaryrefslogtreecommitdiff
path: root/lib/sqfs/comp/zstd.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-01 22:42:49 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-01 22:42:49 +0200
commit307107ecd2fc3ffbf6fe91497daf767700f3572f (patch)
tree87c2c5993ab10cd4aa791a4e6d34f251db208ed2 /lib/sqfs/comp/zstd.c
parent2e28c45601a57b1d23e9cad33d2bdcc59e8a3f4f (diff)
Move command line processing stuff out of compressor code
This commit moves stuff like printing help text, command line option processing and enumerating available processors on stdout out of the generic compressor code. The option string is replaced with a structure that directly exposese the tweakable parameters for all compressors. A function for parsing the command line arguments into this structure is added in sqfshelper. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs/comp/zstd.c')
-rw-r--r--lib/sqfs/comp/zstd.c64
1 files changed, 18 insertions, 46 deletions
diff --git a/lib/sqfs/comp/zstd.c b/lib/sqfs/comp/zstd.c
index e206338..c805524 100644
--- a/lib/sqfs/comp/zstd.c
+++ b/lib/sqfs/comp/zstd.c
@@ -16,8 +16,6 @@
#include "internal.h"
-#define ZSTD_DEFAULT_COMPRESSION_LEVEL 15
-
typedef struct {
compressor_t base;
ZSTD_CCtx *zctx;
@@ -34,7 +32,7 @@ static int zstd_write_options(compressor_t *base, int fd)
zstd_options_t opt;
(void)fd;
- if (zstd->level == ZSTD_DEFAULT_COMPRESSION_LEVEL)
+ if (zstd->level == SQFS_ZSTD_DEFAULT_LEVEL)
return 0;
opt.level = htole32(zstd->level);
@@ -119,38 +117,26 @@ static void zstd_destroy(compressor_t *base)
free(zstd);
}
-compressor_t *create_zstd_compressor(bool compress, size_t block_size,
- char *options)
+compressor_t *create_zstd_compressor(const compressor_config_t *cfg)
{
- zstd_compressor_t *zstd = calloc(1, sizeof(*zstd));
- compressor_t *base = (compressor_t *)zstd;
- size_t i;
- (void)block_size;
+ zstd_compressor_t *zstd;
+ compressor_t *base;
- if (zstd == NULL) {
- perror("creating zstd compressor");
- return NULL;
+ if (cfg->flags & ~SQFS_COMP_FLAG_GENERIC_ALL) {
+ fputs("creating zstd compressor: unknown compressor flags\n",
+ stderr);
}
- zstd->level = ZSTD_DEFAULT_COMPRESSION_LEVEL;
-
- if (options != NULL) {
- if (strncmp(options, "level=", 6) == 0) {
- options += 6;
-
- for (i = 0; isdigit(options[i]); ++i)
- ;
-
- if (i == 0 || options[i] != '\0' || i > 6)
- goto fail_level;
-
- zstd->level = atoi(options);
+ if (cfg->opt.zstd.level < 1 ||
+ cfg->opt.zstd.level > ZSTD_maxCLevel()) {
+ goto fail_level;
+ }
- if (zstd->level < 1 || zstd->level > ZSTD_maxCLevel())
- goto fail_level;
- } else {
- goto fail_opt;
- }
+ zstd = calloc(1, sizeof(*zstd));
+ base = (compressor_t *)zstd;
+ if (zstd == NULL) {
+ perror("creating zstd compressor");
+ return NULL;
}
zstd->zctx = ZSTD_createCCtx();
@@ -161,7 +147,8 @@ compressor_t *create_zstd_compressor(bool compress, size_t block_size,
}
base->destroy = zstd_destroy;
- base->do_block = compress ? zstd_comp_block : zstd_uncomp_block;
+ base->do_block = cfg->flags & SQFS_COMP_FLAG_UNCOMPRESS ?
+ zstd_uncomp_block : zstd_comp_block;
base->write_options = zstd_write_options;
base->read_options = zstd_read_options;
base->create_copy = zstd_create_copy;
@@ -169,20 +156,5 @@ compressor_t *create_zstd_compressor(bool compress, size_t block_size,
fail_level:
fprintf(stderr, "zstd compression level must be a number in the range "
"1...%d\n", ZSTD_maxCLevel());
- free(zstd);
return NULL;
-fail_opt:
- fputs("Unsupported extra options for zstd compressor\n", stderr);
- free(zstd);
- return NULL;
-}
-
-void compressor_zstd_print_help(void)
-{
- printf("Available options for zstd compressor:\n"
- "\n"
- " level=<value> Set compression level. Defaults to %d.\n"
- " Maximum is %d.\n"
- "\n",
- ZSTD_DEFAULT_COMPRESSION_LEVEL, ZSTD_maxCLevel());
}