aboutsummaryrefslogtreecommitdiff
path: root/lib/sqfs/comp
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-02-25 09:13:39 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-02-27 01:05:42 +0100
commit3c1a4c2548cbbae96f44469278b53046c8b48868 (patch)
treecf528c5338f850012744e3376eae502767bfdc21 /lib/sqfs/comp
parentc9429aeece3b8642de637f7a21e68046bd690658 (diff)
Add a function to the compressor interface to get the configuration
This allows getting the compressor configuration back after creating it, for various purposes. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs/comp')
-rw-r--r--lib/sqfs/comp/gzip.c17
-rw-r--r--lib/sqfs/comp/lz4.c19
-rw-r--r--lib/sqfs/comp/lzma.c14
-rw-r--r--lib/sqfs/comp/xz.c16
-rw-r--r--lib/sqfs/comp/zstd.c18
5 files changed, 84 insertions, 0 deletions
diff --git a/lib/sqfs/comp/gzip.c b/lib/sqfs/comp/gzip.c
index 37491bb..34164a6 100644
--- a/lib/sqfs/comp/gzip.c
+++ b/lib/sqfs/comp/gzip.c
@@ -44,6 +44,22 @@ static void gzip_destroy(sqfs_object_t *base)
free(gzip);
}
+static void gzip_get_configuration(const sqfs_compressor_t *base,
+ sqfs_compressor_config_t *cfg)
+{
+ const gzip_compressor_t *gzip = (const gzip_compressor_t *)base;
+
+ memset(cfg, 0, sizeof(*cfg));
+ cfg->id = SQFS_COMP_GZIP;
+ cfg->flags = gzip->opt.strategies;
+ cfg->block_size = gzip->block_size;
+ cfg->opt.gzip.level = gzip->opt.level;
+ cfg->opt.gzip.window_size = gzip->opt.window;
+
+ if (!gzip->compress)
+ cfg->flags |= SQFS_COMP_FLAG_UNCOMPRESS;
+}
+
static int gzip_write_options(sqfs_compressor_t *base, sqfs_file_t *file)
{
gzip_compressor_t *gzip = (gzip_compressor_t *)base;
@@ -263,6 +279,7 @@ sqfs_compressor_t *gzip_compressor_create(const sqfs_compressor_config_t *cfg)
gzip->opt.strategies = cfg->flags & SQFS_COMP_FLAG_GZIP_ALL;
gzip->compress = (cfg->flags & SQFS_COMP_FLAG_UNCOMPRESS) == 0;
gzip->block_size = cfg->block_size;
+ base->get_configuration = gzip_get_configuration;
base->do_block = gzip_do_block;
base->write_options = gzip_write_options;
base->read_options = gzip_read_options;
diff --git a/lib/sqfs/comp/lz4.c b/lib/sqfs/comp/lz4.c
index 7656d67..f298c67 100644
--- a/lib/sqfs/comp/lz4.c
+++ b/lib/sqfs/comp/lz4.c
@@ -18,6 +18,7 @@
typedef struct {
sqfs_compressor_t base;
+ size_t block_size;
bool high_compression;
} lz4_compressor_t;
@@ -99,6 +100,22 @@ static sqfs_s32 lz4_uncomp_block(sqfs_compressor_t *base, const sqfs_u8 *in,
return ret;
}
+static void lz4_get_configuration(const sqfs_compressor_t *base,
+ sqfs_compressor_config_t *cfg)
+{
+ const lz4_compressor_t *lz4 = (const lz4_compressor_t *)base;
+
+ memset(cfg, 0, sizeof(*cfg));
+ cfg->id = SQFS_COMP_LZ4;
+ cfg->block_size = lz4->block_size;
+
+ if (lz4->high_compression)
+ cfg->flags |= SQFS_COMP_FLAG_LZ4_HC;
+
+ if (base->do_block == lz4_uncomp_block)
+ cfg->flags |= SQFS_COMP_FLAG_UNCOMPRESS;
+}
+
static sqfs_compressor_t *lz4_create_copy(sqfs_compressor_t *cmp)
{
lz4_compressor_t *lz4 = malloc(sizeof(*lz4));
@@ -131,7 +148,9 @@ sqfs_compressor_t *lz4_compressor_create(const sqfs_compressor_config_t *cfg)
return NULL;
lz4->high_compression = (cfg->flags & SQFS_COMP_FLAG_LZ4_HC) != 0;
+ lz4->block_size = cfg->block_size;
+ base->get_configuration = lz4_get_configuration;
base->do_block = (cfg->flags & SQFS_COMP_FLAG_UNCOMPRESS) ?
lz4_uncomp_block : lz4_comp_block;
base->write_options = lz4_write_options;
diff --git a/lib/sqfs/comp/lzma.c b/lib/sqfs/comp/lzma.c
index 900cc14..451a6ca 100644
--- a/lib/sqfs/comp/lzma.c
+++ b/lib/sqfs/comp/lzma.c
@@ -143,6 +143,19 @@ static sqfs_s32 lzma_uncomp_block(sqfs_compressor_t *base, const sqfs_u8 *in,
return hdrsize;
}
+static void lzma_get_configuration(const sqfs_compressor_t *base,
+ sqfs_compressor_config_t *cfg)
+{
+ const lzma_compressor_t *lzma = (const lzma_compressor_t *)base;
+
+ memset(cfg, 0, sizeof(*cfg));
+ cfg->id = SQFS_COMP_LZMA;
+ cfg->block_size = lzma->block_size;
+
+ if (base->do_block == lzma_uncomp_block)
+ cfg->flags |= SQFS_COMP_FLAG_UNCOMPRESS;
+}
+
static sqfs_compressor_t *lzma_create_copy(sqfs_compressor_t *cmp)
{
lzma_compressor_t *copy = malloc(sizeof(*copy));
@@ -176,6 +189,7 @@ sqfs_compressor_t *lzma_compressor_create(const sqfs_compressor_config_t *cfg)
if (lzma->block_size < SQFS_META_BLOCK_SIZE)
lzma->block_size = SQFS_META_BLOCK_SIZE;
+ base->get_configuration = lzma_get_configuration;
base->do_block = (cfg->flags & SQFS_COMP_FLAG_UNCOMPRESS) ?
lzma_uncomp_block : lzma_comp_block;
base->write_options = lzma_write_options;
diff --git a/lib/sqfs/comp/xz.c b/lib/sqfs/comp/xz.c
index d612729..a600956 100644
--- a/lib/sqfs/comp/xz.c
+++ b/lib/sqfs/comp/xz.c
@@ -196,6 +196,21 @@ static sqfs_s32 xz_uncomp_block(sqfs_compressor_t *base, const sqfs_u8 *in,
return SQFS_ERROR_COMPRESSOR;
}
+static void xz_get_configuration(const sqfs_compressor_t *base,
+ sqfs_compressor_config_t *cfg)
+{
+ const xz_compressor_t *xz = (const xz_compressor_t *)base;
+
+ memset(cfg, 0, sizeof(*cfg));
+ cfg->id = SQFS_COMP_XZ;
+ cfg->flags = xz->flags;
+ cfg->block_size = xz->block_size;
+ cfg->opt.xz.dict_size = xz->dict_size;
+
+ if (base->do_block == xz_uncomp_block)
+ cfg->flags |= SQFS_COMP_FLAG_UNCOMPRESS;
+}
+
static sqfs_compressor_t *xz_create_copy(sqfs_compressor_t *cmp)
{
xz_compressor_t *xz = malloc(sizeof(*xz));
@@ -233,6 +248,7 @@ sqfs_compressor_t *xz_compressor_create(const sqfs_compressor_config_t *cfg)
xz->flags = cfg->flags;
xz->dict_size = cfg->opt.xz.dict_size;
xz->block_size = cfg->block_size;
+ base->get_configuration = xz_get_configuration;
base->do_block = (cfg->flags & SQFS_COMP_FLAG_UNCOMPRESS) ?
xz_uncomp_block : xz_comp_block;
base->write_options = xz_write_options;
diff --git a/lib/sqfs/comp/zstd.c b/lib/sqfs/comp/zstd.c
index 4bd9456..e01f87d 100644
--- a/lib/sqfs/comp/zstd.c
+++ b/lib/sqfs/comp/zstd.c
@@ -18,6 +18,7 @@
typedef struct {
sqfs_compressor_t base;
+ size_t block_size;
ZSTD_CCtx *zctx;
int level;
} zstd_compressor_t;
@@ -91,6 +92,21 @@ static sqfs_s32 zstd_uncomp_block(sqfs_compressor_t *base, const sqfs_u8 *in,
return ret;
}
+static void zstd_get_configuration(const sqfs_compressor_t *base,
+ sqfs_compressor_config_t *cfg)
+{
+ const zstd_compressor_t *zstd = (const zstd_compressor_t *)base;
+
+ memset(cfg, 0, sizeof(*cfg));
+ cfg->id = SQFS_COMP_ZSTD;
+
+ cfg->block_size = zstd->block_size;
+ cfg->opt.zstd.level = zstd->level;
+
+ if (base->do_block == zstd_uncomp_block)
+ cfg->flags |= SQFS_COMP_FLAG_UNCOMPRESS;
+}
+
static sqfs_compressor_t *zstd_create_copy(sqfs_compressor_t *cmp)
{
zstd_compressor_t *zstd = malloc(sizeof(*zstd));
@@ -136,12 +152,14 @@ sqfs_compressor_t *zstd_compressor_create(const sqfs_compressor_config_t *cfg)
if (zstd == NULL)
return NULL;
+ zstd->block_size = cfg->block_size;
zstd->zctx = ZSTD_createCCtx();
if (zstd->zctx == NULL) {
free(zstd);
return NULL;
}
+ base->get_configuration = zstd_get_configuration;
base->do_block = cfg->flags & SQFS_COMP_FLAG_UNCOMPRESS ?
zstd_uncomp_block : zstd_comp_block;
base->write_options = zstd_write_options;