1 /* vi: set sw=4 ts=4: */
3 * modinfo - retrieve module info
4 * Copyright (c) 2008 Pascal Bellard
6 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
9 //applet:IF_MODINFO(APPLET(modinfo, _BB_DIR_SBIN, _BB_SUID_DROP))
11 //kbuild:lib-$(CONFIG_MODINFO) += modinfo.o
13 //config:config MODINFO
14 //config: bool "modinfo"
17 //config: Show information about a Linux Kernel module
20 #include <sys/utsname.h> /* uname() */
26 OPT_TAGS = (1 << 6) - 1,
27 OPT_F = (1 << 6), /* field name */
28 OPT_0 = (1 << 7), /* \0 as separator */
36 static int display(const char *data, const char *pattern, int flag)
39 int n = printf("%s:", pattern);
43 return printf("%s%c", data, (option_mask32 & OPT_0) ? '\0' : '\n');
46 static void modinfo(const char *path, struct modinfo_env *env)
48 static const char *const shortcuts[] = {
58 char *ptr, *the_module;
59 const char *field = env->field;
62 if (tags & 1) { /* filename */
63 display(path, shortcuts[0], 1 != tags);
65 len = MAXINT(ssize_t);
66 the_module = xmalloc_open_zipped_read_close(path, &len);
71 for (j = 1; (1<<j) & (OPT_TAGS + OPT_F); j++) {
72 const char *pattern = field;
73 if ((1<<j) & OPT_TAGS)
74 pattern = shortcuts[j];
77 length = strlen(pattern);
80 ptr = memchr(ptr, *pattern, len - (ptr - (char*)the_module));
81 if (ptr == NULL) /* no occurance left, done */
83 if (strncmp(ptr, pattern, length) == 0 && ptr[length] == '=') {
85 ptr += display(ptr, pattern, (1<<j) != tags);
93 //usage:#define modinfo_trivial_usage
94 //usage: "[-adlp0] [-F keyword] MODULE"
95 //usage:#define modinfo_full_usage "\n\n"
97 //usage: "\n -a Shortcut for '-F author'"
98 //usage: "\n -d Shortcut for '-F description'"
99 //usage: "\n -l Shortcut for '-F license'"
100 //usage: "\n -p Shortcut for '-F parm'"
101 //usage: "\n -F keyword Keyword to look for"
102 //usage: "\n -0 Separate output with NULs"
103 //usage:#define modinfo_example_usage
104 //usage: "$ modinfo -F vermagic loop\n"
106 int modinfo_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
107 int modinfo_main(int argc UNUSED_PARAM, char **argv)
109 struct modinfo_env env;
110 char name[MODULE_NAME_LEN];
113 char *colon, *tokens[2];
118 opt_complementary = "-1"; /* minimum one param */
119 opts = getopt32(argv, "fdalvpF:0", &env.field);
120 env.tags = opts & OPT_TAGS ? opts & OPT_TAGS : OPT_TAGS;
126 concat_path_file(CONFIG_DEFAULT_MODULES_DIR, uts.release),
127 CONFIG_DEFAULT_DEPMOD_FILE),
131 while (config_read(p, tokens, 2, 1, "# \t", PARSE_NORMAL)) {
132 colon = last_char_is(tokens[0], ':');
136 filename2modname(tokens[0], name);
137 for (i = 0; argv[i]; i++) {
138 if (fnmatch(argv[i], name, 0) == 0) {
139 modinfo(tokens[0], &env);
140 argv[i] = (char *) "";
144 for (i = 0; argv[i]; i++) {
146 modinfo(argv[i], &env);