aboutsummaryrefslogtreecommitdiff
path: root/modutils
diff options
context:
space:
mode:
Diffstat (limited to 'modutils')
-rw-r--r--modutils/Config.src (renamed from modutils/Config.in)8
-rw-r--r--modutils/Kbuild.src (renamed from modutils/Kbuild)1
-rw-r--r--modutils/modinfo.c150
3 files changed, 156 insertions, 3 deletions
diff --git a/modutils/Config.in b/modutils/Config.src
index 83c12b67f..2ced9b308 100644
--- a/modutils/Config.in
+++ b/modutils/Config.src
@@ -5,9 +5,11 @@
5 5
6menu "Linux Module Utilities" 6menu "Linux Module Utilities"
7 7
8INSERT
9
8config MODPROBE_SMALL 10config MODPROBE_SMALL
9 bool "Simplified modutils" 11 bool "Simplified modutils"
10 default n 12 default y
11 help 13 help
12 Simplified modutils. 14 Simplified modutils.
13 15
@@ -40,14 +42,14 @@ config MODPROBE_SMALL
40 42
41config FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE 43config FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE
42 bool "Accept module options on modprobe command line" 44 bool "Accept module options on modprobe command line"
43 default n 45 default y
44 depends on MODPROBE_SMALL 46 depends on MODPROBE_SMALL
45 help 47 help
46 Allow insmod and modprobe take module options from command line. 48 Allow insmod and modprobe take module options from command line.
47 49
48config FEATURE_MODPROBE_SMALL_CHECK_ALREADY_LOADED 50config FEATURE_MODPROBE_SMALL_CHECK_ALREADY_LOADED
49 bool "Skip loading of already loaded modules" 51 bool "Skip loading of already loaded modules"
50 default n 52 default y
51 depends on MODPROBE_SMALL 53 depends on MODPROBE_SMALL
52 help 54 help
53 Check if the module is already loaded. 55 Check if the module is already loaded.
diff --git a/modutils/Kbuild b/modutils/Kbuild.src
index 31f7cbf93..fc0808d7f 100644
--- a/modutils/Kbuild
+++ b/modutils/Kbuild.src
@@ -5,6 +5,7 @@
5# Licensed under the GPL v2, see the file LICENSE in this tarball. 5# Licensed under the GPL v2, see the file LICENSE in this tarball.
6 6
7lib-y:= 7lib-y:=
8INSERT
8lib-$(CONFIG_MODPROBE_SMALL) += modprobe-small.o 9lib-$(CONFIG_MODPROBE_SMALL) += modprobe-small.o
9lib-$(CONFIG_DEPMOD) += depmod.o modutils.o 10lib-$(CONFIG_DEPMOD) += depmod.o modutils.o
10lib-$(CONFIG_INSMOD) += insmod.o modutils.o 11lib-$(CONFIG_INSMOD) += insmod.o modutils.o
diff --git a/modutils/modinfo.c b/modutils/modinfo.c
new file mode 100644
index 000000000..c68d2e974
--- /dev/null
+++ b/modutils/modinfo.c
@@ -0,0 +1,150 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * modinfo - retrieve module info
4 * Copyright (c) 2008 Pascal Bellard
5 *
6 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
7 */
8
9//applet:IF_MODINFO(APPLET(modinfo, _BB_DIR_SBIN, _BB_SUID_DROP))
10
11//kbuild:lib-$(CONFIG_MODINFO) += modinfo.o
12
13//config:config MODINFO
14//config: bool "modinfo"
15//config: default y
16//config: help
17//config: Show information about a Linux Kernel module
18
19#include <fnmatch.h>
20#include <sys/utsname.h> /* uname() */
21#include "libbb.h"
22#include "modutils.h"
23
24
25enum {
26 OPT_TAGS = (1 << 6) - 1,
27 OPT_F = (1 << 6), /* field name */
28 OPT_0 = (1 << 7), /* \0 as separator */
29};
30
31struct modinfo_env {
32 char *field;
33 int tags;
34};
35
36static int display(const char *data, const char *pattern, int flag)
37{
38 if (flag) {
39 int n = printf("%s:", pattern);
40 while (n++ < 16)
41 bb_putchar(' ');
42 }
43 return printf("%s%c", data, (option_mask32 & OPT_0) ? '\0' : '\n');
44}
45
46static void modinfo(const char *path, struct modinfo_env *env)
47{
48 static const char *const shortcuts[] = {
49 "filename",
50 "description",
51 "author",
52 "license",
53 "vermagic",
54 "parm",
55 };
56 size_t len;
57 int j, length;
58 char *ptr, *the_module;
59 const char *field = env->field;
60 int tags = env->tags;
61
62 if (tags & 1) { /* filename */
63 display(path, shortcuts[0], 1 != tags);
64 }
65 len = MAXINT(ssize_t);
66 the_module = xmalloc_open_zipped_read_close(path, &len);
67 if (!the_module)
68 return;
69 if (field)
70 tags |= OPT_F;
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];
75 if (!((1<<j) & tags))
76 continue;
77 length = strlen(pattern);
78 ptr = the_module;
79 while (1) {
80 ptr = memchr(ptr, *pattern, len - (ptr - (char*)the_module));
81 if (ptr == NULL) /* no occurance left, done */
82 break;
83 if (strncmp(ptr, pattern, length) == 0 && ptr[length] == '=') {
84 ptr += length + 1;
85 ptr += display(ptr, pattern, (1<<j) != tags);
86 }
87 ++ptr;
88 }
89 }
90 free(the_module);
91}
92
93//usage:#define modinfo_trivial_usage
94//usage: "[-adlp0] [-F keyword] MODULE"
95//usage:#define modinfo_full_usage "\n\n"
96//usage: "Options:"
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"
105
106int modinfo_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
107int modinfo_main(int argc UNUSED_PARAM, char **argv)
108{
109 struct modinfo_env env;
110 char name[MODULE_NAME_LEN];
111 struct utsname uts;
112 parser_t *p;
113 char *colon, *tokens[2];
114 unsigned opts;
115 unsigned i;
116
117 env.field = NULL;
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;
121 argv += optind;
122
123 uname(&uts);
124 p = config_open2(
125 concat_path_file(
126 concat_path_file(CONFIG_DEFAULT_MODULES_DIR, uts.release),
127 CONFIG_DEFAULT_DEPMOD_FILE),
128 xfopen_for_read
129 );
130
131 while (config_read(p, tokens, 2, 1, "# \t", PARSE_NORMAL)) {
132 colon = last_char_is(tokens[0], ':');
133 if (colon == NULL)
134 continue;
135 *colon = '\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 *) "";
141 }
142 }
143 }
144 for (i = 0; argv[i]; i++) {
145 if (argv[i][0]) {
146 modinfo(argv[i], &env);
147 }
148 }
149 return 0;
150}