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 source tree.
9 //applet:IF_MODINFO(APPLET(modinfo, BB_DIR_SBIN, BB_SUID_DROP))
11 //kbuild:lib-$(CONFIG_MODINFO) += modinfo.o modutils.o
13 //config:config MODINFO
14 //config: bool "modinfo"
16 //config: select PLATFORM_LINUX
18 //config: Show information about a Linux Kernel module
21 #include <sys/utsname.h> /* uname() */
27 OPT_TAGS
= (1 << 8) - 1,
28 OPT_F
= (1 << 8), /* field name */
29 OPT_0
= (1 << 9), /* \0 as separator */
37 static int display(const char *data
, const char *pattern
, int flag
)
40 int n
= printf("%s:", pattern
);
44 return printf("%s%c", data
, (option_mask32
& OPT_0
) ? '\0' : '\n');
47 static void modinfo(const char *path
, const char *version
,
48 const struct modinfo_env
*env
)
50 static const char *const shortcuts
[] = {
62 char *ptr
, *the_module
;
63 const char *field
= env
->field
;
66 if (tags
& 1) { /* filename */
67 display(path
, shortcuts
[0], 1 != tags
);
70 len
= MAXINT(ssize_t
);
71 the_module
= xmalloc_open_zipped_read_close(path
, &len
);
75 /* Newer depmod puts relative paths in modules.dep */
76 path
= xasprintf("%s/%s/%s", CONFIG_DEFAULT_MODULES_DIR
, version
, path
);
77 the_module
= xmalloc_open_zipped_read_close(path
, &len
);
85 for (j
= 1; (1<<j
) & (OPT_TAGS
+ OPT_F
); j
++) {
91 if ((1<<j
) & OPT_TAGS
)
92 pattern
= shortcuts
[j
];
93 length
= strlen(pattern
);
96 ptr
= memchr(ptr
, *pattern
, len
- (ptr
- (char*)the_module
));
97 if (ptr
== NULL
) /* no occurance left, done */
99 if (strncmp(ptr
, pattern
, length
) == 0 && ptr
[length
] == '=') {
101 ptr
+= display(ptr
, pattern
, (1<<j
) != tags
);
109 //usage:#define modinfo_trivial_usage
110 //usage: "[-adlp0] [-F keyword] MODULE"
111 //usage:#define modinfo_full_usage "\n\n"
112 //usage: " -a Shortcut for '-F author'"
113 //usage: "\n -d Shortcut for '-F description'"
114 //usage: "\n -l Shortcut for '-F license'"
115 //usage: "\n -p Shortcut for '-F parm'"
116 //usage: "\n -F keyword Keyword to look for"
117 //usage: "\n -0 Separate output with NULs"
118 //usage:#define modinfo_example_usage
119 //usage: "$ modinfo -F vermagic loop\n"
121 int modinfo_main(int argc
, char **argv
) MAIN_EXTERNALLY_VISIBLE
;
122 int modinfo_main(int argc UNUSED_PARAM
, char **argv
)
124 struct modinfo_env env
;
125 char name
[MODULE_NAME_LEN
];
128 char *colon
, *tokens
[2];
133 opt_complementary
= "-1"; /* minimum one param */
134 opts
= getopt32(argv
, "fdalvpF:0", &env
.field
);
135 env
.tags
= opts
& OPT_TAGS
? opts
& OPT_TAGS
: OPT_TAGS
;
139 parser
= config_open2(
140 xasprintf("%s/%s/%s", CONFIG_DEFAULT_MODULES_DIR
, uts
.release
, CONFIG_DEFAULT_DEPMOD_FILE
),
144 while (config_read(parser
, tokens
, 2, 1, "# \t", PARSE_NORMAL
)) {
145 colon
= last_char_is(tokens
[0], ':');
149 filename2modname(tokens
[0], name
);
150 for (i
= 0; argv
[i
]; i
++) {
151 if (fnmatch(argv
[i
], name
, 0) == 0) {
152 modinfo(tokens
[0], uts
.release
, &env
);
153 argv
[i
] = (char *) "";
157 if (ENABLE_FEATURE_CLEAN_UP
)
158 config_close(parser
);
160 for (i
= 0; argv
[i
]; i
++) {
162 modinfo(argv
[i
], uts
.release
, &env
);