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" +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", +}; enum { - OPT_TAGS = (1 << 12) - 1, /* shortcut count */ - OPT_F = (1 << 12), /* field name */ - OPT_0 = (1 << 13), /* \0 as separator */ + 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, }; -struct modinfo_env { - char *field; - int tags; -}; - -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<