/* vi: set sw=4 ts=4: */ /* * modinfo - retrieve module info * Copyright (c) 2008 Pascal Bellard * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ //config:config MODINFO //config: bool "modinfo (24 kb)" //config: default y //config: help //config: Show information about a Linux Kernel module //applet:IF_MODINFO(APPLET_NOEXEC(modinfo, modinfo, BB_DIR_SBIN, BB_SUID_DROP, modinfo)) //kbuild:lib-$(CONFIG_MODINFO) += modinfo.o modutils.o #include #include /* uname() */ #include "libbb.h" #include "modutils.h" static const char *const shortcuts[] ALIGN_PTR = { "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_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 = 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(' '); } printf("%s%c", data, (option_mask32 & OPT_0) ? '\0' : '\n'); } static void modinfo(const char *path, const char *version, const char *field) { size_t len; int j; char *ptr, *the_module; 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 = allocated = xasprintf("%s/%s/%s", CONFIG_DEFAULT_MODULES_DIR, version, path); the_module = xmalloc_open_zipped_read_close(path, &len); if (!the_module) { bb_error_msg("module '%s' not found", path); goto ret; } } for (j = 1; (1<