From 0b22d6ad0ebed2af239259dbfa36cd9920c6f4a2 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 23 Jun 2019 02:14:52 +0200 Subject: Move all handling of compressor names to libcompress.a This commit removes handling of compressor names from gensquashfs. Instead, functions are added to libcompress to obtain name from ID, ID from name and to print out defaults. Signed-off-by: David Oberhollenzer --- mkfs/mkfs.h | 2 +- mkfs/options.c | 36 +++++++----------------------------- 2 files changed, 8 insertions(+), 30 deletions(-) (limited to 'mkfs') diff --git a/mkfs/mkfs.h b/mkfs/mkfs.h index cea9ebc..4a39eb5 100644 --- a/mkfs/mkfs.h +++ b/mkfs/mkfs.h @@ -28,8 +28,8 @@ typedef struct { unsigned int def_gid; unsigned int def_mode; unsigned int def_mtime; + E_SQFS_COMPRESSOR compressor; int outmode; - int compressor; int blksz; int devblksz; bool quiet; diff --git a/mkfs/options.c b/mkfs/options.c index a746ba4..e298a6c 100644 --- a/mkfs/options.c +++ b/mkfs/options.c @@ -61,7 +61,6 @@ static const char *help_string = "\n" " --compressor, -c Select the compressor to use.\n" " A list of available compressors is below.\n" -" Defaults to '%s'.\n" " --comp-extra, -X A comma seperated list of extra options for\n" " the selected compressor. Specify 'help' to\n" " get a list of available options.\n" @@ -126,15 +125,6 @@ static const char *help_string = " file /bin/bash 0755 0 0" "\n\n"; -static const char *compressors[] = { - [SQFS_COMP_GZIP] = "gzip", - [SQFS_COMP_LZMA] = "lzma", - [SQFS_COMP_LZO] = "lzo", - [SQFS_COMP_XZ] = "xz", - [SQFS_COMP_LZ4] = "lz4", - [SQFS_COMP_ZSTD] = "zstd", -}; - static long read_number(const char *name, const char *str, long min, long max) { long result = strtol(str, NULL, 0); @@ -217,17 +207,13 @@ void process_command_line(options_t *opt, int argc, char **argv) switch (i) { case 'c': - have_compressor = false; + have_compressor = true; - for (i = SQFS_COMP_MIN; i <= SQFS_COMP_MAX; ++i) { - if (strcmp(compressors[i], optarg) == 0) { - if (compressor_exists(i)) { - have_compressor = true; - opt->compressor = i; - break; - } - } - } + if (compressor_id_from_name(optarg, &opt->compressor)) + have_compressor = false; + + if (!compressor_exists(opt->compressor)) + have_compressor = false; if (!have_compressor) { fprintf(stderr, "Unsupported compressor '%s'\n", @@ -268,16 +254,8 @@ void process_command_line(options_t *opt, int argc, char **argv) #endif case 'h': printf(help_string, __progname, - compressors[compressor_get_default()], SQFS_DEFAULT_BLOCK_SIZE, SQFS_DEVBLK_SIZE); - - fputs("Available compressors:\n", stdout); - - for (i = SQFS_COMP_MIN; i <= SQFS_COMP_MAX; ++i) { - if (compressor_exists(i)) - printf("\t%s\n", compressors[i]); - } - + compressor_print_available(); exit(EXIT_SUCCESS); case 'V': print_version(); -- cgit v1.2.3