From c0d83d9e9f2da4c78feeb544562f43e258c0b2f4 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Wed, 8 Aug 2012 15:03:15 +0400 Subject: [PATCH] show: Add 'hinting' ability The crtools produces not only dump in its internal format (i.e. -- pb), but also may call other tools to create files with some state (e.g. ip tool dumps route and ifaddr info, tmpfs will be tar-ed, iptables utility will produce the iptables-save file, etc.). The show functionality cannot read these images, but we can guess what can be in the file provided by its magic. Signed-off-by: Pavel Emelyanov --- cr-show.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/cr-show.c b/cr-show.c index a354837aa..dd9bd8c88 100644 --- a/cr-show.c +++ b/cr-show.c @@ -357,6 +357,26 @@ void show_mm(int fd_mm, struct cr_options *o) pb_show_vertical(fd_mm, PB_MM); } +static struct { + u32 magic; + u32 mask; + char *hint; +} magic_hints[] = { + { .magic = 0x45311224, .mask = 0xffffffff, .hint = "ip route dump", }, + { .magic = 0x47361222, .mask = 0xffffffff, .hint = "ip ifaddr dump", }, + { .magic = 0x00008b1f, .mask = 0x0000ffff, .hint = "gzip file", }, + { }, +}; + +static void try_hint_magic(u32 magic) +{ + int i; + + for (i = 0; magic_hints[i].hint != 0; i++) + if ((magic & magic_hints[i].mask) == magic_hints[i].magic) + pr_msg("This can be %s\n", magic_hints[i].hint); +} + static int cr_parse_file(struct cr_options *opts) { u32 magic; @@ -378,6 +398,7 @@ static int cr_parse_file(struct cr_options *opts) if (i == CR_FD_MAX) { pr_err("Unknown magic %#x in %s\n", magic, opts->show_dump_file); + try_hint_magic(magic); goto err; }