From a85c6025903a2b6e97e1938b201b3361a0cbed66 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Tue, 30 Apr 2019 10:50:13 +0200 Subject: Add compressor library Signed-off-by: David Oberhollenzer --- mkfs/Makemodule.am | 10 +++++++++- mkfs/options.c | 23 +++++++++++++++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) (limited to 'mkfs') diff --git a/mkfs/Makemodule.am b/mkfs/Makemodule.am index 1d062b9..ad3f166 100644 --- a/mkfs/Makemodule.am +++ b/mkfs/Makemodule.am @@ -1,5 +1,13 @@ mksquashfs_SOURCES = mkfs/mksquashfs.c mkfs/options.c mkfs/options.h mksquashfs_SOURCES += include/squashfs.h -mksquashfs_LDADD = libfstree.a +mksquashfs_LDADD = libfstree.a libcompress.a + +if WITH_LZMA +mksquashfs_LDADD += $(XZ_LIBS) +endif + +if WITH_ZLIB +mksquashfs_LDADD += $(ZLIB_LIBS) +endif bin_PROGRAMS += mksquashfs diff --git a/mkfs/options.c b/mkfs/options.c index 513e76a..e3371aa 100644 --- a/mkfs/options.c +++ b/mkfs/options.c @@ -1,4 +1,5 @@ /* SPDX-License-Identifier: GPL-3.0-or-later */ +#include "compress.h" #include "squashfs.h" #include "options.h" #include "config.h" @@ -221,6 +222,7 @@ static void process_defaults(options_t *opt, char *subopts) void process_command_line(options_t *opt, int argc, char **argv) { + bool have_compressor; int i; opt->def_uid = 0; @@ -241,12 +243,23 @@ void process_command_line(options_t *opt, int argc, char **argv) switch (i) { case 'c': + have_compressor = false; + for (i = SQFS_COMP_MIN; i <= SQFS_COMP_MAX; ++i) { if (strcmp(compressors[i], optarg) == 0) { - opt->compressor = i; - break; + if (compressor_exists(i)) { + have_compressor = true; + opt->compressor = i; + break; + } } } + + if (!have_compressor) { + fprintf(stderr, "Unsupported compressor '%s'\n", + optarg); + exit(EXIT_FAILURE); + } break; case 'b': opt->blksz = read_number("Block size", optarg, @@ -268,8 +281,10 @@ void process_command_line(options_t *opt, int argc, char **argv) fputs("Available compressors:\n", stdout); - for (i = SQFS_COMP_MIN; i <= SQFS_COMP_MAX; ++i) - printf("\t%s\n", compressors[i]); + for (i = SQFS_COMP_MIN; i <= SQFS_COMP_MAX; ++i) { + if (compressor_exists(i)) + printf("\t%s\n", compressors[i]); + } exit(EXIT_SUCCESS); case 'V': -- cgit v1.2.3