From 7c5cd1e104f23ec7d9c23086993630f398e2d8e0 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Thu, 25 Jul 2019 14:03:55 +0200 Subject: Implement simple, fork() based parallel unpacking in rdsquashfs Signed-off-by: David Oberhollenzer --- unpack/options.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'unpack/options.c') diff --git a/unpack/options.c b/unpack/options.c index c42f16a..e7911e5 100644 --- a/unpack/options.c +++ b/unpack/options.c @@ -12,6 +12,7 @@ static struct option long_opts[] = { { "no-slink", no_argument, NULL, 'L' }, { "no-empty-dir", no_argument, NULL, 'E' }, { "no-sparse", no_argument, NULL, 'Z' }, + { "jobs", required_argument, NULL, 'j' }, { "describe", no_argument, NULL, 'd' }, { "chmod", no_argument, NULL, 'C' }, { "chown", no_argument, NULL, 'O' }, @@ -20,7 +21,7 @@ static struct option long_opts[] = { { "version", no_argument, NULL, 'V' }, }; -static const char *short_opts = "l:c:u:p:DSFLCOEZdqhV"; +static const char *short_opts = "l:c:u:p:DSFLCOEZj:dqhV"; static const char *help_string = "Usage: %s [OPTIONS] \n" @@ -50,6 +51,7 @@ static const char *help_string = " empty after applying the above rules.\n" " --no-sparse, -Z Do not create sparse files, always write zero\n" " blocks to disk.\n" +" --jobs, -j Number of parallel unpacking jobs to start.\n" " --chmod, -C Change permission flags of unpacked files to\n" " those store in the squashfs image.\n" " --chown, -O Change ownership of unpacked files to the\n" @@ -85,7 +87,7 @@ static char *get_path(char *old, const char *arg) void process_command_line(options_t *opt, int argc, char **argv) { - int i; + int i, j; opt->op = OP_NONE; opt->rdtree_flags = 0; @@ -93,6 +95,7 @@ void process_command_line(options_t *opt, int argc, char **argv) opt->cmdpath = NULL; opt->unpack_root = NULL; opt->image_name = NULL; + opt->num_jobs = 1; for (;;) { i = getopt_long(argc, argv, short_opts, long_opts, NULL); @@ -124,6 +127,17 @@ void process_command_line(options_t *opt, int argc, char **argv) case 'Z': opt->flags |= UNPACK_NO_SPARSE; break; + case 'j': + for (j = 0; optarg[j] != '\0'; ++j) { + if (j > 6 || !isdigit(optarg[j])) + goto fail_num_jobs; + } + + opt->num_jobs = atoi(optarg); + + if (opt->num_jobs < 1) + goto fail_num_jobs; + break; case 'c': opt->op = OP_CAT; opt->cmdpath = get_path(opt->cmdpath, optarg); @@ -176,4 +190,7 @@ fail_arg: fprintf(stderr, "Try `%s --help' for more information.\n", __progname); free(opt->cmdpath); exit(EXIT_FAILURE); +fail_num_jobs: + fputs("Expected a positive integer for --jobs.\n", stderr); + goto fail_arg; } -- cgit v1.2.3