2019-03-08 18:18:31 +01:00
|
|
|
/* SPDX-License-Identifier: ISC */
|
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' },
|
2019-03-08 19:16:59 +01:00
|
|
|
{ "list-files", required_argument, NULL, 'l' },
|
2019-01-19 17:26:41 +01:00
|
|
|
{ "root", required_argument, NULL, 'r' },
|
|
|
|
{ NULL, 0, NULL, 0 },
|
|
|
|
};
|
|
|
|
|
2019-03-08 19:16:59 +01:00
|
|
|
static const char *short_opts = "dl: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) {
|
2019-03-08 19:16:59 +01:00
|
|
|
case 'l':
|
|
|
|
flags |= DUMP_TOC;
|
2019-01-19 17:26:41 +01:00
|
|
|
if (strcmp(optarg, "sqfs") == 0) {
|
|
|
|
format = TOC_FORMAT_SQFS;
|
|
|
|
} else if (strcmp(optarg, "initrd") == 0) {
|
|
|
|
format = TOC_FORMAT_INITRD;
|
2019-02-04 18:47:34 +01:00
|
|
|
} else if (strcmp(optarg, "pkg") == 0) {
|
|
|
|
format = TOC_FORMAT_PKG;
|
2019-03-08 19:16:59 +01:00
|
|
|
} else if (strcmp(optarg, "detail") == 0) {
|
|
|
|
format = TOC_FORMAT_PRETTY;
|
2019-01-19 17:26:41 +01:00
|
|
|
} 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 '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-02-07 23:14:45 +01:00
|
|
|
if (image_entry_list_from_package(rd, &list))
|
2019-01-19 17:26:41 +01:00
|
|
|
goto out;
|
|
|
|
|
2019-02-07 23:14:45 +01:00
|
|
|
if (flags & DUMP_TOC && list != NULL) {
|
2019-01-29 00:14:06 +01:00
|
|
|
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"
|
2019-03-08 19:16:59 +01:00
|
|
|
" --list-files, -l <format> Produce a list of files with a specified\n"
|
|
|
|
" formating.\n"
|
2019-01-29 00:14:06 +01:00
|
|
|
"\n"
|
2019-03-08 19:16:59 +01:00
|
|
|
" If \"detail\" is specified, a human readable,\n"
|
|
|
|
" pretty printed format with details is used.\n"
|
2019-01-19 17:26:41 +01:00
|
|
|
"\n"
|
2019-03-08 19:16:59 +01:00
|
|
|
" If \"sqfs\" is specified, a squashfs pseudo\n"
|
|
|
|
" file is genareated for setting permissions\n"
|
|
|
|
" bits and ownership appropriately.\n"
|
2019-01-19 17:26:41 +01:00
|
|
|
"\n"
|
2019-03-08 19:16:59 +01:00
|
|
|
" If \"initrd\" is specified, the format of\n"
|
|
|
|
" Linux gen_init_cpio is produced.\n"
|
2019-01-19 17:26:41 +01:00
|
|
|
"\n"
|
2019-03-08 19:16:59 +01:00
|
|
|
" --root, -r <path> If a format is used that requires absoulute\n"
|
|
|
|
" input paths (e.g. initrd), prefix all file\n"
|
|
|
|
" paths with this. Can be used, for instance to\n"
|
|
|
|
" unpack a package to a staging directory and\n"
|
|
|
|
" generate a a listing for Linux\n"
|
|
|
|
" CONFIG_INITRAMFS_SOURCE.\n",
|
2019-01-19 17:26:41 +01:00
|
|
|
.run_cmd = cmd_dump,
|
|
|
|
};
|
|
|
|
|
|
|
|
REGISTER_COMMAND(dump)
|