123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- #include <fnmatch.h>
- #include <sys/utsname.h> /* uname() */
- #include "libbb.h"
- #include "modutils.h"
- static const char *const shortcuts[] = {
- "filename",
- "author",
- "description",
- "license",
- "parm",
- "version",
- "alias",
- "srcversion",
- "depends",
- "uts_release",
- "intree",
- "vermagic",
- "firmware",
- };
- enum {
- OPT_0 = (1 << 0),
- OPT_F = (1 << 1),
-
- 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;
- if (flag & (flag-1)) {
-
- 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;
-
- 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<<j) & (OPT_TAGS|OPT_F); j++) {
- const char *pattern;
- if (!((1<<j) & tags))
- continue;
- pattern = field;
- if ((1<<j) & OPT_TAGS)
- pattern = shortcuts[j-2];
- if (strcmp(pattern, shortcuts[0]) == 0) {
-
- display(path, shortcuts[0]);
- continue;
- }
- ptr = the_module;
- while (1) {
- char *after_pattern;
- ptr = memchr(ptr, *pattern, len - (ptr - (char*)the_module));
- if (ptr == NULL)
- break;
- after_pattern = is_prefixed_with(ptr, pattern);
- if (after_pattern && *after_pattern == '=') {
-
- if ((ptr[-1] & 0x7F) == 0x00) {
- ptr = after_pattern + 1;
- display(ptr, pattern);
- ptr += strlen(ptr);
- }
- }
- ++ptr;
- }
- }
- free(the_module);
- ret:
- free(allocated);
- }
- int modinfo_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
- int modinfo_main(int argc UNUSED_PARAM, char **argv)
- {
- const char *field;
- char name[MODULE_NAME_LEN];
- struct utsname uts;
- parser_t *parser;
- char *colon, *tokens[2];
- unsigned opts;
- unsigned i;
- field = NULL;
- opts = getopt32(argv, "^" "0F:nadlp" "\0" "-1", &field);
-
- if (!(opts & (OPT_TAGS|OPT_F)))
- option_mask32 |= OPT_TAGS;
- argv += optind;
- uname(&uts);
- parser = config_open2(
- xasprintf("%s/%s/%s", CONFIG_DEFAULT_MODULES_DIR, uts.release, CONFIG_DEFAULT_DEPMOD_FILE),
- xfopen_for_read
- );
- while (config_read(parser, tokens, 2, 1, "# \t", PARSE_NORMAL)) {
- colon = last_char_is(tokens[0], ':');
- if (colon == NULL)
- continue;
- *colon = '\0';
- filename2modname(bb_basename(tokens[0]), name);
- for (i = 0; argv[i]; i++) {
- if (fnmatch(argv[i], name, 0) == 0) {
- modinfo(tokens[0], uts.release, field);
- argv[i] = (char *) "";
- }
- }
- }
- if (ENABLE_FEATURE_CLEAN_UP)
- config_close(parser);
- for (i = 0; argv[i]; i++) {
- if (argv[i][0]) {
- modinfo(argv[i], uts.release, field);
- }
- }
- return 0;
- }
|