From 4c8576fea18552d93d43c367638bacc54c26f2b7 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 28 Oct 2015 18:07:46 +0100 Subject: modinfo: fix "-F firmware", add "intree" field display function old new delta shortcuts - 52 +52 modinfo 317 330 +13 display 77 87 +10 packed_usage 30752 30761 +9 modinfo_main 351 345 -6 static.shortcuts 48 - -48 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 3/1 up/down: 84/-54) Total: 30 bytes Signed-off-by: Denys Vlasenko --- modutils/modinfo.c | 114 +++++++++++++++++++++++++++++------------------------ 1 file changed, 62 insertions(+), 52 deletions(-) (limited to 'modutils/modinfo.c') diff --git a/modutils/modinfo.c b/modutils/modinfo.c index 8e74b6438..aa641ad54 100644 --- a/modutils/modinfo.c +++ b/modutils/modinfo.c @@ -5,11 +5,6 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ - -//applet:IF_MODINFO(APPLET(modinfo, BB_DIR_SBIN, BB_SUID_DROP)) - -//kbuild:lib-$(CONFIG_MODINFO) += modinfo.o modutils.o - //config:config MODINFO //config: bool "modinfo" //config: default y @@ -17,26 +12,46 @@ //config: help //config: Show information about a Linux Kernel module +//applet:IF_MODINFO(APPLET(modinfo, BB_DIR_SBIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_MODINFO) += modinfo.o modutils.o + #include #include /* uname() */ #include "libbb.h" #include "modutils.h" - -enum { - OPT_TAGS = (1 << 12) - 1, /* shortcut count */ - OPT_F = (1 << 12), /* field name */ - OPT_0 = (1 << 13), /* \0 as separator */ +static const char *const shortcuts[] = { + "filename", // -n + "author", // -a + "description", // -d + "license", // -l + "parm", // -p + "version", // the rest has no shortcut options + "alias", + "srcversion", + "depends", + "uts_release", + "intree", + "vermagic", + "firmware", }; -struct modinfo_env { - char *field; - int tags; +enum { + OPT_0 = (1 << 0), /* \0 as separator */ + OPT_F = (1 << 1), /* field name */ + /* first bits are for -nadlp options, the rest are for + * fields not selectable with "shortcut" options + */ + OPT_n = (1 << 2), + OPT_TAGS = ((1 << ARRAY_SIZE(shortcuts)) - 1) << 2, }; -static void display(const char *data, const char *pattern, int flag) +static void display(const char *data, const char *pattern) { - if (flag) { + int flag = option_mask32 >> 1; /* shift out -0 bit */ + if (flag & (flag-1)) { + /* more than one field to show: print "FIELD:" pfx */ int n = printf("%s:", pattern); while (n++ < 16) bb_putchar(' '); @@ -45,55 +60,45 @@ static void display(const char *data, const char *pattern, int flag) } static void modinfo(const char *path, const char *version, - const struct modinfo_env *env) + const char *field) { - static const char *const shortcuts[] = { - "filename", - "license", - "author", - "description", - "version", - "alias", - "srcversion", - "depends", - "uts_release", - "vermagic", - "parm", - "firmware", - }; size_t len; int j; char *ptr, *the_module; - const char *field = env->field; - int tags = env->tags; - - if (tags & 1) { /* filename */ - display(path, shortcuts[0], 1 != tags); - } + char *allocated; + int tags = option_mask32; + allocated = NULL; len = MAXINT(ssize_t); the_module = xmalloc_open_zipped_read_close(path, &len); if (!the_module) { if (path[0] == '/') return; /* Newer depmod puts relative paths in modules.dep */ - path = xasprintf("%s/%s/%s", CONFIG_DEFAULT_MODULES_DIR, version, path); + path = allocated = xasprintf("%s/%s/%s", CONFIG_DEFAULT_MODULES_DIR, version, path); the_module = xmalloc_open_zipped_read_close(path, &len); - free((char*)path); - if (!the_module) - return; + if (!the_module) { + bb_error_msg("module '%s' not found", path); + goto ret; + } } - if (field) - tags |= OPT_F; - for (j = 1; (1<