diff options
| author | Pascal Bellard <pascal.bellard@ads-lu.com> | 2010-06-06 04:55:13 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-06-06 04:55:13 +0200 |
| commit | 22bdf90334515e047fcccf36ae80a543b6a056de (patch) | |
| tree | 96e10780f25e2ba2d10df3d17418fe9100deb521 /modutils | |
| parent | 2f32bf8be63f70125049402ba43101d8c6083d46 (diff) | |
| download | busybox-w32-22bdf90334515e047fcccf36ae80a543b6a056de.tar.gz busybox-w32-22bdf90334515e047fcccf36ae80a543b6a056de.tar.bz2 busybox-w32-22bdf90334515e047fcccf36ae80a543b6a056de.zip | |
modinfo: new applet
function old new delta
modinfo_main - 307 +307
modinfo - 280 +280
packed_usage 27037 27131 +94
display - 74 +74
static.shortcuts - 24 +24
applet_names 2254 2262 +8
applet_main 1324 1328 +4
applet_nameofs 662 664 +2
------------------------------------------------------------------------------
(add/remove: 5/0 grow/shrink: 4/0 up/down: 793/0) Total: 793 bytes
Signed-off-by: Pascal Bellard <pascal.bellard@ads-lu.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'modutils')
| -rw-r--r-- | modutils/Config.src | 2 | ||||
| -rw-r--r-- | modutils/Kbuild.src | 1 | ||||
| -rw-r--r-- | modutils/modinfo.c | 150 |
3 files changed, 153 insertions, 0 deletions
diff --git a/modutils/Config.src b/modutils/Config.src index 3d02f87ee..2ced9b308 100644 --- a/modutils/Config.src +++ b/modutils/Config.src | |||
| @@ -5,6 +5,8 @@ | |||
| 5 | 5 | ||
| 6 | menu "Linux Module Utilities" | 6 | menu "Linux Module Utilities" |
| 7 | 7 | ||
| 8 | INSERT | ||
| 9 | |||
| 8 | config MODPROBE_SMALL | 10 | config MODPROBE_SMALL |
| 9 | bool "Simplified modutils" | 11 | bool "Simplified modutils" |
| 10 | default y | 12 | default y |
diff --git a/modutils/Kbuild.src b/modutils/Kbuild.src index 31f7cbf93..fc0808d7f 100644 --- a/modutils/Kbuild.src +++ 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 | ||
| 7 | lib-y:= | 7 | lib-y:= |
| 8 | INSERT | ||
| 8 | lib-$(CONFIG_MODPROBE_SMALL) += modprobe-small.o | 9 | lib-$(CONFIG_MODPROBE_SMALL) += modprobe-small.o |
| 9 | lib-$(CONFIG_DEPMOD) += depmod.o modutils.o | 10 | lib-$(CONFIG_DEPMOD) += depmod.o modutils.o |
| 10 | lib-$(CONFIG_INSMOD) += insmod.o modutils.o | 11 | lib-$(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 | |||
| 25 | enum { | ||
| 26 | OPT_TAGS = (1 << 6) - 1, | ||
| 27 | OPT_F = (1 << 6), /* field name */ | ||
| 28 | OPT_0 = (1 << 7), /* \0 as separator */ | ||
| 29 | }; | ||
| 30 | |||
| 31 | struct modinfo_env { | ||
| 32 | char *field; | ||
| 33 | int tags; | ||
| 34 | }; | ||
| 35 | |||
| 36 | static 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 | |||
| 46 | static 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 | |||
| 106 | int modinfo_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||
| 107 | int 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 | } | ||
