diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-03-05 22:55:09 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-03-05 22:55:09 +0100 |
commit | dfab234dfae735103d2e5206b0f335c8449ee3d5 (patch) | |
tree | 1b5d79f6a5f5a01896562233ee40973085755c21 | |
parent | 85e36aab1258d8d9ec7b61ce013f167ef8e03ae0 (diff) |
Get rid of sqfs_compressor_exists
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r-- | difftool/sqfsdiff.c | 13 | ||||
-rw-r--r-- | extras/browse.c | 5 | ||||
-rw-r--r-- | extras/list_files.c | 5 | ||||
-rw-r--r-- | include/sqfs/compressor.h | 18 | ||||
-rw-r--r-- | lib/common/compress.c | 51 | ||||
-rw-r--r-- | lib/sqfs/comp/compressor.c | 8 | ||||
-rw-r--r-- | tar/sqfs2tar.c | 12 | ||||
-rw-r--r-- | unpack/rdsquashfs.c | 13 |
8 files changed, 42 insertions, 83 deletions
diff --git a/difftool/sqfsdiff.c b/difftool/sqfsdiff.c index 6415165..2871322 100644 --- a/difftool/sqfsdiff.c +++ b/difftool/sqfsdiff.c @@ -22,19 +22,6 @@ static int open_sfqs(sqfs_state_t *state, const char *path) goto fail_file; } - ret = sqfs_compressor_exists(state->super.compression_id); - -#ifdef WITH_LZO - if (state->super.compression_id == SQFS_COMP_LZO) - ret = true; -#endif - - if (!ret) { - fprintf(stderr, "%s: unknown compressor used.\n", - path); - goto fail_file; - } - sqfs_compressor_config_init(&state->cfg, state->super.compression_id, state->super.block_size, SQFS_COMP_FLAG_UNCOMPRESS); diff --git a/extras/browse.c b/extras/browse.c index 9dd735a..a238793 100644 --- a/extras/browse.c +++ b/extras/browse.c @@ -502,11 +502,6 @@ int main(int argc, char **argv) goto out_fd; } - if (!sqfs_compressor_exists(super.compression_id)) { - fprintf(stderr, "%s: unknown compressor used.\n", argv[1]); - goto out_fd; - } - sqfs_compressor_config_init(&cfg, super.compression_id, super.block_size, SQFS_COMP_FLAG_UNCOMPRESS); diff --git a/extras/list_files.c b/extras/list_files.c index eba4fff..61184bf 100644 --- a/extras/list_files.c +++ b/extras/list_files.c @@ -75,11 +75,6 @@ int main(int argc, char **argv) goto out_fd; } - if (!sqfs_compressor_exists(super.compression_id)) { - fprintf(stderr, "%s: unknown compressor used.\n", argv[1]); - goto out_fd; - } - sqfs_compressor_config_init(&cfg, super.compression_id, super.block_size, SQFS_COMP_FLAG_UNCOMPRESS); diff --git a/include/sqfs/compressor.h b/include/sqfs/compressor.h index 1a36c82..4190c67 100644 --- a/include/sqfs/compressor.h +++ b/include/sqfs/compressor.h @@ -339,16 +339,6 @@ SQFS_API int sqfs_compressor_config_init(sqfs_compressor_config_t *cfg, size_t block_size, sqfs_u16 flags); /** - * @brief Check if a specified compressor implementation is available. - * - * @param id An @ref SQFS_COMPRESSOR identifier. - * - * @return true if the implementation is available and can be instantiated - * through @ref sqfs_compressor_create. - */ -SQFS_API bool sqfs_compressor_exists(SQFS_COMPRESSOR id); - -/** * @brief Create an instance of a compressor implementation. * * If this function returns @ref SQFS_ERROR_UNSUPPORTED, it can mean that @@ -368,10 +358,6 @@ SQFS_API int sqfs_compressor_create(const sqfs_compressor_config_t *cfg, /** * @brief Get the name of a compressor backend from its ID. * - * This function will even resolve compressor names that are not built in, so - * use @ref sqfs_compressor_exists to check if a compressor is actually - * available. - * * @param id An @ref SQFS_COMPRESSOR identifier. * * @return A string holding the name of the compressor, NULL if the compressor @@ -382,10 +368,6 @@ SQFS_API const char *sqfs_compressor_name_from_id(SQFS_COMPRESSOR id); /** * @brief Get the compressor ID using just the name of the backend. * - * This function will even resolve compressor names that are not built in, so - * use @ref sqfs_compressor_exists to check if a compressor is actually - * available. - * * @param name The name of the compressor backend. * * @return A positive, @ref SQFS_COMPRESSOR identifier on success diff --git a/lib/common/compress.c b/lib/common/compress.c index 3ee242d..cb4ce10 100644 --- a/lib/common/compress.c +++ b/lib/common/compress.c @@ -6,31 +6,64 @@ */ #include "common.h" +static int cmp_ids[] = { + SQFS_COMP_XZ, + SQFS_COMP_ZSTD, + SQFS_COMP_GZIP, + SQFS_COMP_LZ4, + SQFS_COMP_LZO, +}; + SQFS_COMPRESSOR compressor_get_default(void) { - if (sqfs_compressor_exists(SQFS_COMP_XZ)) - return SQFS_COMP_XZ; + sqfs_compressor_config_t cfg; + sqfs_compressor_t *temp; + size_t i; + int ret; + + for (i = 0; i < sizeof(cmp_ids) / sizeof(cmp_ids[0]); ++i) { + sqfs_compressor_config_init(&cfg, cmp_ids[i], + SQFS_DEFAULT_BLOCK_SIZE, 0); - if (sqfs_compressor_exists(SQFS_COMP_ZSTD)) - return SQFS_COMP_ZSTD; + ret = sqfs_compressor_create(&cfg, &temp); - return SQFS_COMP_GZIP; + if (ret == 0) { + sqfs_destroy(temp); + return cmp_ids[i]; + } + } + +#ifdef WITH_LZO + return SQFS_COMP_LZO; +#else + assert(0); +#endif } void compressor_print_available(void) { + sqfs_compressor_config_t cfg; + sqfs_compressor_t *temp; bool have_compressor; - int i; + int i, ret; fputs("Available compressors:\n", stdout); for (i = SQFS_COMP_MIN; i <= SQFS_COMP_MAX; ++i) { - have_compressor = sqfs_compressor_exists(i); + sqfs_compressor_config_init(&cfg, i, + SQFS_DEFAULT_BLOCK_SIZE, 0); -#ifdef WITH_LZO - if (i == SQFS_COMP_LZO) + ret = sqfs_compressor_create(&cfg, &temp); + + if (ret == 0) { + sqfs_destroy(temp); have_compressor = true; + } else { +#ifdef WITH_LZO + if (i == SQFS_COMP_LZO) + have_compressor = true; #endif + } if (have_compressor) printf("\t%s\n", sqfs_compressor_name_from_id(i)); diff --git a/lib/sqfs/comp/compressor.c b/lib/sqfs/comp/compressor.c index 3b48030..946ee25 100644 --- a/lib/sqfs/comp/compressor.c +++ b/lib/sqfs/comp/compressor.c @@ -73,14 +73,6 @@ int sqfs_generic_read_options(sqfs_file_t *file, void *data, size_t size) return 0; } -bool sqfs_compressor_exists(SQFS_COMPRESSOR id) -{ - if (id < SQFS_COMP_MIN || id > SQFS_COMP_MAX) - return false; - - return (compressors[id] != NULL); -} - int sqfs_compressor_create(const sqfs_compressor_config_t *cfg, sqfs_compressor_t **out) { diff --git a/tar/sqfs2tar.c b/tar/sqfs2tar.c index 2b013d6..925ae9c 100644 --- a/tar/sqfs2tar.c +++ b/tar/sqfs2tar.c @@ -540,18 +540,6 @@ int main(int argc, char **argv) goto out_fd; } - ret = sqfs_compressor_exists(super.compression_id); - -#ifdef WITH_LZO - if (super.compression_id == SQFS_COMP_LZO) - ret = true; -#endif - - if (!ret) { - fprintf(stderr, "%s: unknown compressor used.\n", filename); - goto out_fd; - } - sqfs_compressor_config_init(&cfg, super.compression_id, super.block_size, SQFS_COMP_FLAG_UNCOMPRESS); diff --git a/unpack/rdsquashfs.c b/unpack/rdsquashfs.c index 5ca9de4..c166f4a 100644 --- a/unpack/rdsquashfs.c +++ b/unpack/rdsquashfs.c @@ -35,19 +35,6 @@ int main(int argc, char **argv) goto out_file; } - ret = sqfs_compressor_exists(super.compression_id); - -#ifdef WITH_LZO - if (super.compression_id == SQFS_COMP_LZO) - ret = true; -#endif - - if (!ret) { - fprintf(stderr, "%s: unknown compressor used.\n", - opt.image_name); - goto out_file; - } - sqfs_compressor_config_init(&cfg, super.compression_id, super.block_size, SQFS_COMP_FLAG_UNCOMPRESS); |