From c42d8e4ead7c20d29bf3996a6a87db0b348f8692 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 26 May 2019 22:44:45 +0200 Subject: gensquashfs: add option to simply pack an input directory Signed-off-by: David Oberhollenzer --- mkfs/mkfs.c | 14 ++++++-- mkfs/mkfs.h | 8 +++++ mkfs/options.c | 110 ++++++++++++++++++++++++++++++++++----------------------- 3 files changed, 86 insertions(+), 46 deletions(-) (limited to 'mkfs') diff --git a/mkfs/mkfs.c b/mkfs/mkfs.c index 1fd95be..63b9c98 100644 --- a/mkfs/mkfs.c +++ b/mkfs/mkfs.c @@ -70,8 +70,18 @@ int main(int argc, char **argv) goto out_outfd; } - if (fstree_from_file(&info.fs, info.opt.infile)) - goto out_fstree; + switch (info.opt.mode) { + case PACK_FILE: + if (fstree_from_file(&info.fs, info.opt.infile)) + goto out_fstree; + break; + case PACK_DIR: + if (fstree_from_dir(&info.fs, info.opt.infile)) + goto out_fstree; + break; + default: + assert(0); + } #ifdef WITH_SELINUX if (info.opt.selinux != NULL) { diff --git a/mkfs/mkfs.h b/mkfs/mkfs.h index ca998ac..67dc994 100644 --- a/mkfs/mkfs.h +++ b/mkfs/mkfs.h @@ -9,6 +9,7 @@ #include "config.h" #include "table.h" +#include #include #include #include @@ -16,6 +17,12 @@ #include #include +typedef enum { + PACK_NONE, + PACK_FILE, + PACK_DIR, +} E_PACK_MODE; + typedef struct { unsigned int def_uid; unsigned int def_gid; @@ -30,6 +37,7 @@ typedef struct { const char *outfile; const char *selinux; char *comp_extra; + E_PACK_MODE mode; } options_t; typedef struct { diff --git a/mkfs/options.c b/mkfs/options.c index 36539b7..56bc7d6 100644 --- a/mkfs/options.c +++ b/mkfs/options.c @@ -17,6 +17,8 @@ static struct option long_opts[] = { { "dev-block-size", required_argument, NULL, 'B' }, { "defaults", required_argument, NULL, 'd' }, { "comp-extra", required_argument, NULL, 'X' }, + { "pack-file", required_argument, NULL, 'F' }, + { "pack-dir", required_argument, NULL, 'D' }, { "force", no_argument, NULL, 'f' }, { "quiet", no_argument, NULL, 'q' }, #ifdef WITH_SELINUX @@ -27,9 +29,9 @@ static struct option long_opts[] = { }; #ifdef WITH_SELINUX -static const char *short_opts = "s:X:c:b:B:d:fqhV"; +static const char *short_opts = "s:F:D:X:c:b:B:d:fqhV"; #else -static const char *short_opts = "X:c:b:B:d:fqhV"; +static const char *short_opts = "F:D:X:c:b:B:d:fqhV"; #endif enum { @@ -50,48 +52,18 @@ static const char *defaults[] = { extern char *__progname; static const char *help_string = -"Usage: %s [OPTIONS] \n" -"\n" -" is a file containing newline separated entries that describe\n" -"the files to be included in the squashfs image:\n" -"\n" -"# a comment\n" -"file []\n" -"dir \n" -"nod \n" -"slink \n" -"pipe \n" -"sock \n" -"\n" -" Absolute path of the entry in the image.\n" -" If given, location of the input file. Either absolute or relative\n" -" to the description file. If omitted, the image path is used,\n" -" relative to the description file.\n" -" Symlink target.\n" -" Mode/permissions of the entry.\n" -" Numeric user id.\n" -" Numeric group id.\n" -" Device type (b=block, c=character).\n" -" Major number of a device special file.\n" -" Minor number of a device special file.\n" -"\n" -"Example:\n" -"# A simple squashfs image\n" -"dir /dev 0755 0 0\n" -"nod /dev/console 0600 0 0 c 5 1\n" -"dir /root 0700 0 0\n" -"dir /sbin 0755 0 0\n" -"\n" -"# Add a file. Input is relative to this listing.\n" -"file /sbin/init 0755 0 0 ../init/sbin/init\n" -"\n" -"# Read from ./bin/bash. /bin is created implicitly with default attributes.\n" -"file /bin/bash 0755 0 0" +"Usage: %s [OPTIONS...] \n" "\n" "Possible options:\n" "\n" +" --pack-file, -F Use a `gen_init_cpio` style description file.\n" +" The file format is specified below.\n" +" --pack-dir, -D Pack the contents of the given directory into\n" +" a SquashFS image. The directory becomes the\n" +" root of the file system.\n" " --compressor, -c Select the compressor to use.\n" -" directories (defaults to 'xz').\n" +" A list of available compressors is below.\n" +" Defaults to 'xz'.\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" @@ -116,7 +88,44 @@ static const char *help_string = " --quiet, -q Do not print out progress reports.\n" " --help, -h Print help text and exit.\n" " --version, -V Print version information and exit.\n" -"\n"; +"\n" +"When using the pack file option, the given file is expected to contain\n" +"newline separated entries that describe the files to be included in the\n" +"SquashFS image. The following entry types can be specified:\n" +"\n" +"# a comment\n" +"file []\n" +"dir \n" +"nod \n" +"slink \n" +"pipe \n" +"sock \n" +"\n" +" Absolute path of the entry in the image.\n" +" If given, location of the input file. Either absolute or relative\n" +" to the description file. If omitted, the image path is used,\n" +" relative to the description file.\n" +" Symlink target.\n" +" Mode/permissions of the entry.\n" +" Numeric user id.\n" +" Numeric group id.\n" +" Device type (b=block, c=character).\n" +" Major number of a device special file.\n" +" Minor number of a device special file.\n" +"\n" +"Example:\n" +" # A simple squashfs image\n" +" dir /dev 0755 0 0\n" +" nod /dev/console 0600 0 0 c 5 1\n" +" dir /root 0700 0 0\n" +" dir /sbin 0755 0 0\n" +" \n" +" # Add a file. Input is relative to this listing.\n" +" file /sbin/init 0755 0 0 ../init/sbin/init\n" +" \n" +" # Read from bin/bash relative to the listing. Implicitly create /bin.\n" +" file /bin/bash 0755 0 0" +"\n\n"; static const char *compressors[] = { [SQFS_COMP_GZIP] = "gzip", @@ -237,6 +246,7 @@ void process_command_line(options_t *opt, int argc, char **argv) opt->devblksz = SQFS_DEVBLK_SIZE; opt->infile = NULL; opt->outfile = NULL; + opt->mode = PACK_NONE; for (;;) { i = getopt_long(argc, argv, short_opts, long_opts, NULL); @@ -283,6 +293,14 @@ void process_command_line(options_t *opt, int argc, char **argv) case 'X': opt->comp_extra = optarg; break; + case 'F': + opt->mode = PACK_FILE; + opt->infile = optarg; + break; + case 'D': + opt->mode = PACK_DIR; + opt->infile = optarg; + break; #ifdef WITH_SELINUX case 's': opt->selinux = optarg; @@ -313,12 +331,16 @@ void process_command_line(options_t *opt, int argc, char **argv) exit(EXIT_SUCCESS); } - if ((optind + 1) >= argc) { - fputs("Missing arguments: input and output files.\n", stderr); + if (opt->mode == PACK_NONE) { + fputs("No input file or directory specified.\n", stderr); + goto fail_arg; + } + + if (optind >= argc) { + fputs("No output file specified.\n", stderr); goto fail_arg; } - opt->infile = argv[optind++]; opt->outfile = argv[optind++]; return; fail_arg: -- cgit v1.2.3