diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-06-04 07:24:52 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-06-04 07:24:52 +0200 |
commit | b6d0bcbf1fa9c8088578c959f442e219f590ebf9 (patch) | |
tree | 2aaffddd7c46e1850b651796797c8df18622b14e /lib/sqfs | |
parent | 30597cc7c5d566f671c84c025de97cb1fc2d242e (diff) |
Cleanup: Pull compression level parameter out into compressor config
Every compressor (except LC4) has a compression level parameter. This
commit pulls the compression level field out into the generic
configuration structure and applies some code clean ups as a result
from this.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs')
-rw-r--r-- | lib/sqfs/comp/compressor.c | 14 | ||||
-rw-r--r-- | lib/sqfs/comp/gzip.c | 10 | ||||
-rw-r--r-- | lib/sqfs/comp/lz4.c | 3 | ||||
-rw-r--r-- | lib/sqfs/comp/lzma.c | 6 | ||||
-rw-r--r-- | lib/sqfs/comp/xz.c | 6 | ||||
-rw-r--r-- | lib/sqfs/comp/zstd.c | 8 |
6 files changed, 22 insertions, 25 deletions
diff --git a/lib/sqfs/comp/compressor.c b/lib/sqfs/comp/compressor.c index ff7ce0c..42ee436 100644 --- a/lib/sqfs/comp/compressor.c +++ b/lib/sqfs/comp/compressor.c @@ -106,10 +106,6 @@ int sqfs_compressor_create(const sqfs_compressor_config_t *cfg, ret = memcmp(cfg->opt.lzo.padd0, padd0, sizeof(cfg->opt.lzo.padd0)); break; - case SQFS_COMP_ZSTD: - ret = memcmp(cfg->opt.zstd.padd0, padd0, - sizeof(cfg->opt.zstd.padd0)); - break; case SQFS_COMP_GZIP: ret = memcmp(cfg->opt.gzip.padd0, padd0, sizeof(cfg->opt.gzip.padd0)); @@ -156,20 +152,20 @@ int sqfs_compressor_config_init(sqfs_compressor_config_t *cfg, switch (id) { case SQFS_COMP_GZIP: flag_mask |= SQFS_COMP_FLAG_GZIP_ALL; - cfg->opt.gzip.level = SQFS_GZIP_DEFAULT_LEVEL; + cfg->level = SQFS_GZIP_DEFAULT_LEVEL; cfg->opt.gzip.window_size = SQFS_GZIP_DEFAULT_WINDOW; break; case SQFS_COMP_LZO: cfg->opt.lzo.algorithm = SQFS_LZO_DEFAULT_ALG; - cfg->opt.lzo.level = SQFS_LZO_DEFAULT_LEVEL; + cfg->level = SQFS_LZO_DEFAULT_LEVEL; break; case SQFS_COMP_ZSTD: - cfg->opt.zstd.level = SQFS_ZSTD_DEFAULT_LEVEL; + cfg->level = SQFS_ZSTD_DEFAULT_LEVEL; break; case SQFS_COMP_XZ: flag_mask |= SQFS_COMP_FLAG_XZ_ALL; + cfg->level = SQFS_XZ_DEFAULT_LEVEL; cfg->opt.xz.dict_size = block_size; - cfg->opt.xz.level = SQFS_XZ_DEFAULT_LEVEL; cfg->opt.xz.lc = SQFS_XZ_DEFAULT_LC; cfg->opt.xz.lp = SQFS_XZ_DEFAULT_LP; cfg->opt.xz.pb = SQFS_XZ_DEFAULT_PB; @@ -179,8 +175,8 @@ int sqfs_compressor_config_init(sqfs_compressor_config_t *cfg, break; case SQFS_COMP_LZMA: flag_mask |= SQFS_COMP_FLAG_LZMA_ALL; + cfg->level = SQFS_LZMA_DEFAULT_LEVEL; cfg->opt.lzma.dict_size = block_size; - cfg->opt.lzma.level = SQFS_LZMA_DEFAULT_LEVEL; cfg->opt.lzma.lc = SQFS_LZMA_DEFAULT_LC; cfg->opt.lzma.lp = SQFS_LZMA_DEFAULT_LP; cfg->opt.lzma.pb = SQFS_LZMA_DEFAULT_PB; diff --git a/lib/sqfs/comp/gzip.c b/lib/sqfs/comp/gzip.c index d702da1..9be84db 100644 --- a/lib/sqfs/comp/gzip.c +++ b/lib/sqfs/comp/gzip.c @@ -53,7 +53,7 @@ static void gzip_get_configuration(const sqfs_compressor_t *base, cfg->id = SQFS_COMP_GZIP; cfg->flags = gzip->opt.strategies; cfg->block_size = gzip->block_size; - cfg->opt.gzip.level = gzip->opt.level; + cfg->level = gzip->opt.level; cfg->opt.gzip.window_size = gzip->opt.window; if (!gzip->compress) @@ -259,8 +259,8 @@ int gzip_compressor_create(const sqfs_compressor_config_t *cfg, return SQFS_ERROR_UNSUPPORTED; } - if (cfg->opt.gzip.level < SQFS_GZIP_MIN_LEVEL || - cfg->opt.gzip.level > SQFS_GZIP_MAX_LEVEL) { + if (cfg->level < SQFS_GZIP_MIN_LEVEL || + cfg->level > SQFS_GZIP_MAX_LEVEL) { return SQFS_ERROR_UNSUPPORTED; } @@ -275,7 +275,7 @@ int gzip_compressor_create(const sqfs_compressor_config_t *cfg, if (gzip == NULL) return SQFS_ERROR_ALLOC; - gzip->opt.level = cfg->opt.gzip.level; + gzip->opt.level = cfg->level; gzip->opt.window = cfg->opt.gzip.window_size; gzip->opt.strategies = cfg->flags & SQFS_COMP_FLAG_GZIP_ALL; gzip->compress = (cfg->flags & SQFS_COMP_FLAG_UNCOMPRESS) == 0; @@ -288,7 +288,7 @@ int gzip_compressor_create(const sqfs_compressor_config_t *cfg, ((sqfs_object_t *)base)->destroy = gzip_destroy; if (gzip->compress) { - ret = deflateInit2(&gzip->strm, cfg->opt.gzip.level, + ret = deflateInit2(&gzip->strm, cfg->level, Z_DEFLATED, cfg->opt.gzip.window_size, 8, Z_DEFAULT_STRATEGY); } else { diff --git a/lib/sqfs/comp/lz4.c b/lib/sqfs/comp/lz4.c index 090ec50..f326870 100644 --- a/lib/sqfs/comp/lz4.c +++ b/lib/sqfs/comp/lz4.c @@ -148,6 +148,9 @@ int lz4_compressor_create(const sqfs_compressor_config_t *cfg, return SQFS_ERROR_UNSUPPORTED; } + if (cfg->level != 0) + return SQFS_ERROR_UNSUPPORTED; + lz4 = calloc(1, sizeof(*lz4)); base = (sqfs_compressor_t *)lz4; if (lz4 == NULL) diff --git a/lib/sqfs/comp/lzma.c b/lib/sqfs/comp/lzma.c index b674af9..01e6042 100644 --- a/lib/sqfs/comp/lzma.c +++ b/lib/sqfs/comp/lzma.c @@ -185,8 +185,8 @@ static void lzma_get_configuration(const sqfs_compressor_t *base, cfg->id = SQFS_COMP_LZMA; cfg->block_size = lzma->block_size; cfg->flags = lzma->flags; + cfg->level = lzma->level; cfg->opt.lzma.dict_size = lzma->dict_size; - cfg->opt.lzma.level = lzma->level; cfg->opt.lzma.lc = lzma->lc; cfg->opt.lzma.lp = lzma->lp; cfg->opt.lzma.pb = lzma->pb; @@ -220,7 +220,7 @@ int lzma_compressor_create(const sqfs_compressor_config_t *cfg, return SQFS_ERROR_UNSUPPORTED; /* XXX: values are unsigned and minimum is 0 */ - if (cfg->opt.lzma.level > SQFS_LZMA_MAX_LEVEL) + if (cfg->level > SQFS_LZMA_MAX_LEVEL) return SQFS_ERROR_UNSUPPORTED; if (cfg->opt.lzma.lc > SQFS_LZMA_MAX_LC) @@ -262,8 +262,8 @@ int lzma_compressor_create(const sqfs_compressor_config_t *cfg, lzma->block_size = cfg->block_size; lzma->flags = cfg->flags; + lzma->level = cfg->level; lzma->dict_size = cfg->opt.lzma.dict_size; - lzma->level = cfg->opt.lzma.level; lzma->lc = cfg->opt.lzma.lc; lzma->lp = cfg->opt.lzma.lp; lzma->pb = cfg->opt.lzma.pb; diff --git a/lib/sqfs/comp/xz.c b/lib/sqfs/comp/xz.c index 662a49f..7d7991d 100644 --- a/lib/sqfs/comp/xz.c +++ b/lib/sqfs/comp/xz.c @@ -242,8 +242,8 @@ static void xz_get_configuration(const sqfs_compressor_t *base, cfg->id = SQFS_COMP_XZ; cfg->flags = xz->flags; cfg->block_size = xz->block_size; + cfg->level = xz->level; cfg->opt.xz.dict_size = xz->dict_size; - cfg->opt.xz.level = xz->level; cfg->opt.xz.lc = xz->lc; cfg->opt.xz.lp = xz->lp; cfg->opt.xz.pb = xz->pb; @@ -288,7 +288,7 @@ int xz_compressor_create(const sqfs_compressor_config_t *cfg, if (cfg->opt.xz.pb > SQFS_XZ_MAX_PB) return SQFS_ERROR_UNSUPPORTED; - if (cfg->opt.xz.level > SQFS_XZ_MAX_LEVEL) + if (cfg->level > SQFS_XZ_MAX_LEVEL) return SQFS_ERROR_UNSUPPORTED; if (cfg->opt.xz.dict_size < SQFS_XZ_MIN_DICT_SIZE) @@ -308,7 +308,7 @@ int xz_compressor_create(const sqfs_compressor_config_t *cfg, xz->lc = cfg->opt.xz.lc; xz->lp = cfg->opt.xz.lp; xz->pb = cfg->opt.xz.pb; - xz->level = cfg->opt.xz.level; + xz->level = cfg->level; base->get_configuration = xz_get_configuration; base->do_block = (cfg->flags & SQFS_COMP_FLAG_UNCOMPRESS) ? xz_uncomp_block : xz_comp_block; diff --git a/lib/sqfs/comp/zstd.c b/lib/sqfs/comp/zstd.c index 18289fe..af5bd84 100644 --- a/lib/sqfs/comp/zstd.c +++ b/lib/sqfs/comp/zstd.c @@ -101,7 +101,7 @@ static void zstd_get_configuration(const sqfs_compressor_t *base, cfg->id = SQFS_COMP_ZSTD; cfg->block_size = zstd->block_size; - cfg->opt.zstd.level = zstd->level; + cfg->level = zstd->level; if (base->do_block == zstd_uncomp_block) cfg->flags |= SQFS_COMP_FLAG_UNCOMPRESS; @@ -143,10 +143,8 @@ int zstd_compressor_create(const sqfs_compressor_config_t *cfg, if (cfg->flags & ~SQFS_COMP_FLAG_GENERIC_ALL) return SQFS_ERROR_UNSUPPORTED; - if (cfg->opt.zstd.level < 1 || - cfg->opt.zstd.level > ZSTD_maxCLevel()) { + if (cfg->level < 1 || cfg->level > (unsigned int)ZSTD_maxCLevel()) return SQFS_ERROR_UNSUPPORTED; - } zstd = calloc(1, sizeof(*zstd)); base = (sqfs_compressor_t *)zstd; @@ -154,7 +152,7 @@ int zstd_compressor_create(const sqfs_compressor_config_t *cfg, return SQFS_ERROR_ALLOC; zstd->block_size = cfg->block_size; - zstd->level = cfg->opt.zstd.level; + zstd->level = cfg->level; zstd->zctx = ZSTD_createCCtx(); if (zstd->zctx == NULL) { free(zstd); |