2019-01-19 17:26:41 +01:00
|
|
|
#include "dump.h"
|
|
|
|
|
|
|
|
static const struct option long_opts[] = {
|
2019-01-29 00:14:06 +01:00
|
|
|
{ "dependencies", no_argument, NULL, 'd' },
|
|
|
|
{ "list-files", no_argument, NULL, 'l' },
|
2019-01-19 17:26:41 +01:00
|
|
|
{ "format", required_argument, NULL, 'f' },
|
|
|
|
{ "root", required_argument, NULL, 'r' },
|
|
|
|
{ NULL, 0, NULL, 0 },
|
|
|
|
};
|
|
|
|
|
2019-01-29 00:14:06 +01:00
|
|
|
static const char *short_opts = "dlf:r:";
|
2019-01-19 17:26:41 +01:00
|
|
|
|
|
|
|
static int cmd_dump(int argc, char **argv)
|
|
|
|
{
|
|
|
|
TOC_FORMAT format = TOC_FORMAT_PRETTY;
|
|
|
|
image_entry_t *list = NULL;
|
|
|
|
const char *root = NULL;
|
|
|
|
int ret = EXIT_FAILURE;
|
|
|
|
pkg_reader_t *rd;
|
2019-01-29 00:14:06 +01:00
|
|
|
int i, flags = 0;
|
2019-01-19 17:26:41 +01:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
i = getopt_long(argc, argv, short_opts, long_opts, NULL);
|
|
|
|
if (i == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch (i) {
|
|
|
|
case 'f':
|
|
|
|
if (strcmp(optarg, "sqfs") == 0) {
|
|
|
|
format = TOC_FORMAT_SQFS;
|
|
|
|
} else if (strcmp(optarg, "initrd") == 0) {
|
|
|
|
format = TOC_FORMAT_INITRD;
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "unknown format '%s'\n",
|
|
|
|
optarg);
|
|
|
|
tell_read_help(argv[0]);
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
root = optarg;
|
|
|
|
break;
|
2019-01-29 00:14:06 +01:00
|
|
|
case 'l':
|
|
|
|
flags |= DUMP_TOC;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
flags |= DUMP_DEPS;
|
|
|
|
break;
|
2019-01-19 17:26:41 +01:00
|
|
|
default:
|
|
|
|
tell_read_help(argv[0]);
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-29 00:14:06 +01:00
|
|
|
if (flags == 0)
|
|
|
|
flags = DUMP_ALL;
|
|
|
|
|
2019-01-19 17:26:41 +01:00
|
|
|
if (optind >= argc) {
|
|
|
|
fputs("missing argument: package file\n", stderr);
|
|
|
|
tell_read_help(argv[0]);
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
rd = pkg_reader_open(argv[optind++]);
|
|
|
|
if (rd == NULL)
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
|
|
|
if (optind < argc)
|
|
|
|
fputs("warning: ignoring extra arguments\n", stderr);
|
|
|
|
|
2019-01-29 00:14:06 +01:00
|
|
|
if (flags & DUMP_DEPS) {
|
|
|
|
if (dump_header(rd, flags))
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2019-01-19 17:26:41 +01:00
|
|
|
list = image_entry_list_from_package(rd);
|
|
|
|
if (list == NULL)
|
|
|
|
goto out;
|
|
|
|
|
2019-01-29 00:14:06 +01:00
|
|
|
if (flags & DUMP_TOC) {
|
|
|
|
if (dump_toc(list, root, format))
|
|
|
|
goto out;
|
|
|
|
}
|
2019-01-19 17:26:41 +01:00
|
|
|
|
|
|
|
ret = EXIT_SUCCESS;
|
|
|
|
out:
|
|
|
|
if (list != NULL)
|
|
|
|
image_entry_free_list(list);
|
|
|
|
pkg_reader_close(rd);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static command_t dump = {
|
|
|
|
.cmd = "dump",
|
|
|
|
.usage = "[OPTIONS...] <pkgfile>",
|
|
|
|
.s_desc = "read dump all information from a package file",
|
|
|
|
.l_desc =
|
|
|
|
"Parse a package file and dump information it contains, such as the list of\n"
|
|
|
|
"files, et cetera.\n"
|
|
|
|
"\n"
|
|
|
|
"Possible options:\n"
|
2019-01-29 00:14:06 +01:00
|
|
|
" --dependencies, -d Show dependency information of a package.\n"
|
|
|
|
"\n"
|
|
|
|
" --list-files, -l Produce a list of files. The format for the list\n"
|
|
|
|
" can be specified with --format.\n"
|
|
|
|
"\n"
|
2019-01-19 17:26:41 +01:00
|
|
|
" --format, -f <format> Specify what format to use for printing the table\n"
|
|
|
|
" of contents. Default is a pretty printed, human\n"
|
|
|
|
" readable version.\n"
|
|
|
|
"\n"
|
|
|
|
" If \"sqfs\" is specified, a squashfs pseudo file\n"
|
|
|
|
" is genareated for setting permissions bits and\n"
|
|
|
|
" ownership appropriately.\n"
|
|
|
|
"\n"
|
|
|
|
" If \"initrd\" is specified, a format appropriate\n"
|
|
|
|
" for Linux gen_init_cpio is produced.\n"
|
|
|
|
"\n"
|
|
|
|
" --root, -r <path> If a format is used that requires absoulute input\n"
|
|
|
|
" paths (e.g. initrd), prefix all file paths with\n"
|
|
|
|
" this. Can be used, for instance to unpack a\n"
|
|
|
|
" package to a staging directory and generate a\n"
|
|
|
|
" a listing for Linux CONFIG_INITRAMFS_SOURCE.\n",
|
|
|
|
.run_cmd = cmd_dump,
|
|
|
|
};
|
|
|
|
|
|
|
|
REGISTER_COMMAND(dump)
|