aboutsummaryrefslogtreecommitdiff
path: root/lib/common
diff options
context:
space:
mode:
Diffstat (limited to 'lib/common')
-rw-r--r--lib/common/compress.c51
1 files changed, 42 insertions, 9 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));