1
0
Fork 0
mirror of https://github.com/pygos/pkg-utils.git synced 2024-11-22 04:49:46 +01:00

pkg2sqfs: add command line option to select compressor

Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
This commit is contained in:
David Oberhollenzer 2019-04-18 00:09:37 +02:00
parent ac8e457c96
commit 576491eae6
2 changed files with 35 additions and 5 deletions

View file

@ -2,6 +2,7 @@
#include "pkg2sqfs.h" #include "pkg2sqfs.h"
static struct option long_opts[] = { static struct option long_opts[] = {
{ "compressor", required_argument, NULL, 'c' },
{ "block-size", required_argument, NULL, 'b' }, { "block-size", required_argument, NULL, 'b' },
{ "dev-block-size", required_argument, NULL, 'B' }, { "dev-block-size", required_argument, NULL, 'B' },
{ "default-uid", required_argument, NULL, 'u' }, { "default-uid", required_argument, NULL, 'u' },
@ -12,7 +13,7 @@ static struct option long_opts[] = {
{ "help", no_argument, NULL, 'h' }, { "help", no_argument, NULL, 'h' },
}; };
static const char *short_opts = "b:B:u:g:m:fhV"; static const char *short_opts = "c:b:B:u:g:m:fhV";
extern char *__progname; extern char *__progname;
@ -32,16 +33,18 @@ static const char *help_string =
"\n" "\n"
"Possible options:\n" "Possible options:\n"
"\n" "\n"
" --compressor, -c <name> Select the compressor to use.\n"
" directories (defaults to 'xz').\n"
" --block-size, -b <size> Block size to use for Squashfs image.\n" " --block-size, -b <size> Block size to use for Squashfs image.\n"
" Defaults to %u.\n" " Defaults to %u.\n"
" --dev-block-size, -B <size> Device block size to padd the image to.\n" " --dev-block-size, -B <size> Device block size to padd the image to.\n"
" Defaults to %u.\n" " Defaults to %u.\n"
" --default-uid, -u <valie> Default user ID for implicitly created\n" " --default-uid, -u <valie> Default user ID for implicitly created\n"
" directories (defaults to 0)." " directories (defaults to 0).\n"
" --default-gid, -g <value> Default group ID for implicitly created\n" " --default-gid, -g <value> Default group ID for implicitly created\n"
" directories (defaults to 0)." " directories (defaults to 0).\n"
" --default-mode, -m <value> Default permissions for implicitly created\n" " --default-mode, -m <value> Default permissions for implicitly created\n"
" directories (defaults to 0755)." " directories (defaults to 0755).\n"
" --force, -f Overwrite the output file if it exists.\n" " --force, -f Overwrite the output file if it exists.\n"
" --help, -h Print help text and exit.\n" " --help, -h Print help text and exit.\n"
" --version, -V Print version information and exit.\n" " --version, -V Print version information and exit.\n"
@ -85,6 +88,15 @@ static void print_tree(int level, node_t *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) static long read_number(const char *name, const char *str, long min, long max)
{ {
long base = 10, result = 0; long base = 10, result = 0;
@ -182,6 +194,7 @@ int main(int argc, char **argv)
{ {
uint32_t blocksize = SQFS_DEFAULT_BLOCK_SIZE, timestamp = 0; uint32_t blocksize = SQFS_DEFAULT_BLOCK_SIZE, timestamp = 0;
int i, outmode = O_WRONLY | O_CREAT | O_EXCL; int i, outmode = O_WRONLY | O_CREAT | O_EXCL;
E_SQFS_COMPRESSOR compressor = SQFS_COMP_XZ;
const char *infile, *outfile; const char *infile, *outfile;
int status = EXIT_FAILURE; int status = EXIT_FAILURE;
compressor_stream_t *cmp; compressor_stream_t *cmp;
@ -199,6 +212,14 @@ int main(int argc, char **argv)
break; break;
switch (i) { switch (i) {
case 'c':
for (i = SQFS_COMP_MIN; i <= SQFS_COMP_MAX; ++i) {
if (strcmp(compressors[i], optarg) == 0) {
compressor = i;
break;
}
}
break;
case 'b': case 'b':
blocksize = read_number("Block size", optarg, blocksize = read_number("Block size", optarg,
1024, 0xFFFFFFFF); 1024, 0xFFFFFFFF);
@ -226,6 +247,12 @@ int main(int argc, char **argv)
case 'h': case 'h':
printf(help_string, __progname, printf(help_string, __progname,
SQFS_DEFAULT_BLOCK_SIZE, SQFS_DEVBLK_SIZE); SQFS_DEFAULT_BLOCK_SIZE, SQFS_DEVBLK_SIZE);
fputs("Available compressors:\n", stdout);
for (i = SQFS_COMP_MIN; i <= SQFS_COMP_MAX; ++i)
printf("\t%s\n", compressors[i]);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
case 'V': case 'V':
printf(version_string, __progname, printf(version_string, __progname,
@ -254,7 +281,7 @@ int main(int argc, char **argv)
goto out_pkg_close; goto out_pkg_close;
} }
if (sqfs_super_init(&info.super, timestamp, blocksize, SQFS_COMP_GZIP)) if (sqfs_super_init(&info.super, timestamp, blocksize, compressor))
goto out_close; goto out_close;
cmp = sqfs_get_compressor(&info.super); cmp = sqfs_get_compressor(&info.super);

View file

@ -123,6 +123,9 @@ typedef enum {
SQFS_COMP_XZ = 4, SQFS_COMP_XZ = 4,
SQFS_COMP_LZ4 = 5, SQFS_COMP_LZ4 = 5,
SQFS_COMP_ZSTD = 6, SQFS_COMP_ZSTD = 6,
SQFS_COMP_MIN = 1,
SQFS_COMP_MAX = 6,
} E_SQFS_COMPRESSOR; } E_SQFS_COMPRESSOR;
typedef enum { typedef enum {