diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-05-21 12:16:37 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-05-21 18:21:17 +0200 |
commit | c9d3c2e1628e5b28a553ae098b3b9f3019c45a63 (patch) | |
tree | a02caaa953b757bbc74793994db37f62e23690e3 /lib/comp/compressor.c | |
parent | 58ced38ac46976c1b0dfa91c513c8ccd170b4e26 (diff) |
Add command line flag for compressor options, pass them to compressors
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/comp/compressor.c')
-rw-r--r-- | lib/comp/compressor.c | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/lib/comp/compressor.c b/lib/comp/compressor.c index 369cbea..44b3643 100644 --- a/lib/comp/compressor.c +++ b/lib/comp/compressor.c @@ -5,7 +5,10 @@ #include "internal.h" #include "util.h" -typedef compressor_t *(*compressor_fun_t)(bool compress, size_t block_size); +typedef compressor_t *(*compressor_fun_t)(bool compress, size_t block_size, + char *options); + +typedef void (*compressor_help_fun_t)(void); static compressor_fun_t compressors[SQFS_COMP_MAX + 1] = { #ifdef WITH_GZIP @@ -25,6 +28,24 @@ static compressor_fun_t compressors[SQFS_COMP_MAX + 1] = { #endif }; +static const compressor_help_fun_t helpfuns[SQFS_COMP_MAX + 1] = { +#ifdef WITH_GZIP + [SQFS_COMP_GZIP] = compressor_gzip_print_help, +#endif +#ifdef WITH_XZ + [SQFS_COMP_XZ] = compressor_xz_print_help, +#endif +#ifdef WITH_LZO + [SQFS_COMP_LZO] = compressor_lzo_print_help, +#endif +#ifdef WITH_LZ4 + [SQFS_COMP_LZ4] = compressor_lz4_print_help, +#endif +#ifdef WITH_ZSTD + [SQFS_COMP_ZSTD] = compressor_zstd_print_help, +#endif +}; + int generic_write_options(int fd, const void *data, size_t size) { uint8_t buffer[size + 2]; @@ -85,7 +106,7 @@ bool compressor_exists(E_SQFS_COMPRESSOR id) } compressor_t *compressor_create(E_SQFS_COMPRESSOR id, bool compress, - size_t block_size) + size_t block_size, char *options) { if (id < SQFS_COMP_MIN || id > SQFS_COMP_MAX) return NULL; @@ -93,5 +114,16 @@ compressor_t *compressor_create(E_SQFS_COMPRESSOR id, bool compress, if (compressors[id] == NULL) return NULL; - return compressors[id](compress, block_size); + return compressors[id](compress, block_size, options); +} + +void compressor_print_help(E_SQFS_COMPRESSOR id) +{ + if (id < SQFS_COMP_MIN || id > SQFS_COMP_MAX) + return; + + if (compressors[id] == NULL) + return; + + helpfuns[id](); } |