aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-05-21 12:16:37 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-05-21 18:21:17 +0200
commitc9d3c2e1628e5b28a553ae098b3b9f3019c45a63 (patch)
treea02caaa953b757bbc74793994db37f62e23690e3 /lib
parent58ced38ac46976c1b0dfa91c513c8ccd170b4e26 (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')
-rw-r--r--lib/comp/compressor.c38
-rw-r--r--lib/comp/gzip.c7
-rw-r--r--lib/comp/internal.h25
-rw-r--r--lib/comp/lz4.c7
-rw-r--r--lib/comp/lzo.c7
-rw-r--r--lib/comp/xz.c7
-rw-r--r--lib/comp/zstd.c7
7 files changed, 85 insertions, 13 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]();
}
diff --git a/lib/comp/gzip.c b/lib/comp/gzip.c
index ea86f98..bc70bcf 100644
--- a/lib/comp/gzip.c
+++ b/lib/comp/gzip.c
@@ -90,7 +90,8 @@ static ssize_t gzip_do_block(compressor_t *base, const uint8_t *in,
return 0;
}
-compressor_t *create_gzip_compressor(bool compress, size_t block_size)
+compressor_t *create_gzip_compressor(bool compress, size_t block_size,
+ char *options)
{
gzip_compressor_t *gzip = calloc(1, sizeof(*gzip));
compressor_t *base = (compressor_t *)gzip;
@@ -122,3 +123,7 @@ compressor_t *create_gzip_compressor(bool compress, size_t block_size)
return base;
}
+
+void compressor_gzip_print_help(void)
+{
+}
diff --git a/lib/comp/internal.h b/lib/comp/internal.h
index 8f880f4..0185f4d 100644
--- a/lib/comp/internal.h
+++ b/lib/comp/internal.h
@@ -8,14 +8,29 @@ int generic_write_options(int fd, const void *data, size_t size);
int generic_read_options(int fd, void *data, size_t size);
-compressor_t *create_xz_compressor(bool compress, size_t block_size);
+compressor_t *create_xz_compressor(bool compress, size_t block_size,
+ char *options);
-compressor_t *create_gzip_compressor(bool compress, size_t block_size);
+compressor_t *create_gzip_compressor(bool compress, size_t block_size,
+ char *options);
-compressor_t *create_lzo_compressor(bool compress, size_t block_size);
+compressor_t *create_lzo_compressor(bool compress, size_t block_size,
+ char *options);
-compressor_t *create_lz4_compressor(bool compress, size_t block_size);
+compressor_t *create_lz4_compressor(bool compress, size_t block_size,
+ char *options);
-compressor_t *create_zstd_compressor(bool compress, size_t block_size);
+compressor_t *create_zstd_compressor(bool compress, size_t block_size,
+ char *options);
+
+void compressor_xz_print_help(void);
+
+void compressor_gzip_print_help(void);
+
+void compressor_lzo_print_help(void);
+
+void compressor_lz4_print_help(void);
+
+void compressor_zstd_print_help(void);
#endif /* INTERNAL_H */
diff --git a/lib/comp/lz4.c b/lib/comp/lz4.c
index f9c753d..63ed528 100644
--- a/lib/comp/lz4.c
+++ b/lib/comp/lz4.c
@@ -87,7 +87,8 @@ static void lz4_destroy(compressor_t *base)
free(base);
}
-compressor_t *create_lz4_compressor(bool compress, size_t block_size)
+compressor_t *create_lz4_compressor(bool compress, size_t block_size,
+ char *options)
{
lz4_compressor_t *lz4 = calloc(1, sizeof(*lz4));
compressor_t *base = (compressor_t *)lz4;
@@ -104,3 +105,7 @@ compressor_t *create_lz4_compressor(bool compress, size_t block_size)
base->read_options = lz4_read_options;
return base;
}
+
+void compressor_lz4_print_help(void)
+{
+}
diff --git a/lib/comp/lzo.c b/lib/comp/lzo.c
index 95ab485..a7b6876 100644
--- a/lib/comp/lzo.c
+++ b/lib/comp/lzo.c
@@ -69,7 +69,8 @@ static void lzo_destroy(compressor_t *base)
free(base);
}
-compressor_t *create_lzo_compressor(bool compress, size_t block_size)
+compressor_t *create_lzo_compressor(bool compress, size_t block_size,
+ char *options)
{
lzo_compressor_t *lzo = calloc(1, sizeof(*lzo));
compressor_t *base = (compressor_t *)lzo;
@@ -86,3 +87,7 @@ compressor_t *create_lzo_compressor(bool compress, size_t block_size)
base->read_options = lzo_read_options;
return base;
}
+
+void compressor_lzo_print_help(void)
+{
+}
diff --git a/lib/comp/xz.c b/lib/comp/xz.c
index dd608ba..3fb3c12 100644
--- a/lib/comp/xz.c
+++ b/lib/comp/xz.c
@@ -88,7 +88,8 @@ static void xz_destroy(compressor_t *base)
free(base);
}
-compressor_t *create_xz_compressor(bool compress, size_t block_size)
+compressor_t *create_xz_compressor(bool compress, size_t block_size,
+ char *options)
{
xz_compressor_t *xz = calloc(1, sizeof(*xz));
compressor_t *base = (compressor_t *)xz;
@@ -105,3 +106,7 @@ compressor_t *create_xz_compressor(bool compress, size_t block_size)
base->read_options = xz_read_options;
return base;
}
+
+void compressor_xz_print_help(void)
+{
+}
diff --git a/lib/comp/zstd.c b/lib/comp/zstd.c
index 6c90505..4cbef38 100644
--- a/lib/comp/zstd.c
+++ b/lib/comp/zstd.c
@@ -69,7 +69,8 @@ static void zstd_destroy(compressor_t *base)
free(zstd);
}
-compressor_t *create_zstd_compressor(bool compress, size_t block_size)
+compressor_t *create_zstd_compressor(bool compress, size_t block_size,
+ char *options)
{
zstd_compressor_t *zstd = calloc(1, sizeof(*zstd));
compressor_t *base = (compressor_t *)zstd;
@@ -93,3 +94,7 @@ compressor_t *create_zstd_compressor(bool compress, size_t block_size)
base->read_options = zstd_read_options;
return base;
}
+
+void compressor_zstd_print_help(void)
+{
+}