summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/common/compress.c51
-rw-r--r--lib/sqfs/comp/compressor.c8
2 files changed, 42 insertions, 17 deletions
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)
{