summaryrefslogtreecommitdiff
path: root/lib/sqfs/comp/lz4.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/lz4.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/lz4.c')
-rw-r--r--lib/sqfs/comp/lz4.c42
1 files changed, 14 insertions, 28 deletions
diff --git a/lib/sqfs/comp/lz4.c b/lib/sqfs/comp/lz4.c
index abb6c5c..4a15198 100644
--- a/lib/sqfs/comp/lz4.c
+++ b/lib/sqfs/comp/lz4.c
@@ -27,14 +27,14 @@ typedef struct {
} lz4_options;
#define LZ4LEGACY 1
-#define LZ4_FLAG_HC 0x01
static int lz4_write_options(compressor_t *base, int fd)
{
lz4_compressor_t *lz4 = (lz4_compressor_t *)base;
lz4_options opt = {
.version = htole32(LZ4LEGACY),
- .flags = htole32(lz4->high_compression ? LZ4_FLAG_HC : 0),
+ .flags = htole32(lz4->high_compression ?
+ SQFS_COMP_FLAG_LZ4_HC : 0),
};
return generic_write_options(fd, &opt, sizeof(opt));
@@ -115,45 +115,31 @@ static void lz4_destroy(compressor_t *base)
free(base);
}
-compressor_t *create_lz4_compressor(bool compress, size_t block_size,
- char *options)
+compressor_t *create_lz4_compressor(const compressor_config_t *cfg)
{
lz4_compressor_t *lz4 = calloc(1, sizeof(*lz4));
compressor_t *base = (compressor_t *)lz4;
- (void)block_size;
+ if (cfg->flags & ~(SQFS_COMP_FLAG_LZ4_ALL |
+ SQFS_COMP_FLAG_GENERIC_ALL)) {
+ fputs("creating lz4 compressor: unknown compressor flags\n",
+ stderr);
+ }
+
+ lz4 = calloc(1, sizeof(*lz4));
+ base = (compressor_t *)lz4;
if (lz4 == NULL) {
perror("creating lz4 compressor");
return NULL;
}
- lz4->high_compression = false;
-
- if (options != NULL) {
- if (strcmp(options, "hc") == 0) {
- lz4->high_compression = true;
- } else {
- fputs("Unsupported extra options for lz4 "
- "compressor.\n", stderr);
- free(lz4);
- return NULL;
- }
- }
+ lz4->high_compression = (cfg->flags & SQFS_COMP_FLAG_LZ4_HC) != 0;
base->destroy = lz4_destroy;
- base->do_block = compress ? lz4_comp_block : lz4_uncomp_block;
+ base->do_block = (cfg->flags & SQFS_COMP_FLAG_UNCOMPRESS) ?
+ lz4_uncomp_block : lz4_comp_block;
base->write_options = lz4_write_options;
base->read_options = lz4_read_options;
base->create_copy = lz4_create_copy;
return base;
}
-
-void compressor_lz4_print_help(void)
-{
- fputs("Available options for lz4 compressor:\n"
- "\n"
- " hc If present, use slower but better compressing\n"
- " variant of lz4.\n"
- "\n",
- stdout);
-}