wok-4.x view busybox/stuff/busybox-1.12.0-modinfo.u @ rev 3913

Add: xtrkcad (4.0.3a)
author Matthew Sheets <rcx@zoominternet.net>
date Mon Aug 17 16:40:30 2009 +0000 (2009-08-17)
parents 85fbd04c1fd6
children
line source
1 --- busybox-1.12.0/include/applets.h
2 +++ busybox-1.12.0/include/applets.h
3 @@ -251,6 +251,7 @@ USE_MKFS_MINIX(APPLET_ODDNAME(mkfs.minix
4 USE_MKNOD(APPLET(mknod, _BB_DIR_BIN, _BB_SUID_NEVER))
5 USE_MKSWAP(APPLET(mkswap, _BB_DIR_SBIN, _BB_SUID_NEVER))
6 USE_MKTEMP(APPLET(mktemp, _BB_DIR_BIN, _BB_SUID_NEVER))
7 +USE_MODINFO(APPLET(modinfo, _BB_DIR_SBIN, _BB_SUID_NEVER))
8 USE_MODPROBE(APPLET(modprobe, _BB_DIR_SBIN, _BB_SUID_NEVER))
9 USE_MODPROBE_SMALL(APPLET(modprobe, _BB_DIR_SBIN, _BB_SUID_NEVER))
10 USE_MORE(APPLET(more, _BB_DIR_BIN, _BB_SUID_NEVER))
12 --- busybox-1.12.0/include/usage.h
13 +++ busybox-1.12.0/include/usage.h
14 @@ -2629,6 +2629,20 @@
15 " which are the default for alias 'tulip2' overridden by the options 'irq=2 io=0x210'\n\n" \
16 " from the command line\n"
18 +#define modinfo_trivial_usage \
19 + "[-adlp0] [-F keyword] MODULE"
20 +#define modinfo_full_usage "\n\n" \
21 + "Options:" \
22 + "\n -a Shortcut for '-F author'" \
23 + "\n -d Shortcut for '-F description'" \
24 + "\n -l Shortcut for '-F license'" \
25 + "\n -p Shortcut for '-F parm'" \
26 + "\n -F keyword Keyword to look for" \
27 + "\n -0 Use \\0 string separator. Not \\n" \
28 +
29 +#define modinfo_example_usage \
30 + "$ modinfo -F vermagic loop\n"
31 +
32 #define more_trivial_usage \
33 "[FILE...]"
34 #define more_full_usage "\n\n" \
36 --- busybox-1.12.0/modutils/Config.in
37 +++ busybox-1.12.0/modutils/Config.in
38 @@ -213,6 +213,12 @@ config FEATURE_MODPROBE_BLACKLIST
39 hardware autodetection scripts to load modules like evdev, frame
40 buffer drivers etc.
42 +config MODINFO
43 + bool "modinfo"
44 + default n
45 + help
46 + Show information about a Linux Kernel module
47 +
48 comment "Options common to multiple modutils"
49 depends on INSMOD || RMMOD || MODPROBE || LSMOD || DEPMOD
52 --- busybox-1.12.0/modutils/Kbuild
53 +++ busybox-1.12.0/modutils/Kbuild
54 @@ -11,3 +11,4 @@ lib-$(CONFIG_LSMOD) += lsmod
55 lib-$(CONFIG_MODPROBE) += modprobe.o
56 lib-$(CONFIG_MODPROBE_SMALL) += modprobe-small.o
57 lib-$(CONFIG_RMMOD) += rmmod.o
58 +lib-$(CONFIG_MODINFO) += modinfo.o
60 --- busybox-1.12.0/modutils/modinfo.c
61 +++ busybox-1.12.0/modutils/modinfo.c
62 @@ -0,0 +1,104 @@
63 +/* vi: set sw=4 ts=4: */
64 +/*
65 + * modinfo - retrieve module info
66 + * Copyright (c) 2008 Pascal Bellard
67 + *
68 + * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
69 + */
70 +
71 +#undef _GNU_SOURCE
72 +#define _GNU_SOURCE
73 +#include <libbb.h>
74 +#include <fnmatch.h>
75 +
76 +#define ALL_TAGS 0x3F
77 +
78 +enum {
79 + ARG_F = (1<<6), /* field name */
80 + ARG_0 = (1<<7) /* \0 as separator */
81 +};
82 +
83 +struct modinfo_env {
84 + char **argv;
85 + const char **literals;
86 + char *field;
87 + int tags;
88 +};
89 +
90 +static int display(char *data, const char *pattern, int flag)
91 +{
92 + if (flag) {
93 + int n = printf("%s:",pattern);
94 + while (n++ < 16) bb_putchar(' ');
95 + }
96 + return printf("%s%c",data, (option_mask32 & ARG_0) ? '\0' : '\n');
97 +}
98 +
99 +static void modinfo(char *name, char *path, void *env)
100 +{
101 + size_t len;
102 + int i, j, length;
103 + char *ptr, *the_module;
104 + char **argv = ((struct modinfo_env *) env)->argv;
105 + const char **literals = ((struct modinfo_env *) env)->literals;
106 + const char *field = ((struct modinfo_env *) env)->field;
107 + int tags = ((struct modinfo_env *) env)->tags;
108 + extern void *xalloc_load_module(const char filename[], size_t *len);
109 +
110 + for (i = 0; argv[i]; i++) {
111 + if (fnmatch(argv[i],name,0) == 0) {
112 + if (tags & 1) { /* filename */
113 + display(path,literals[0],1 != tags);
114 + }
115 + len = MAXINT(ssize_t);
116 + the_module = xalloc_load_module(path, &len);
117 + if (field) tags |= ALL_TAGS+1;
118 + for (j = 1; (1<<j) & (ALL_TAGS+ALL_TAGS+1); j++) {
119 + const char *pattern = field;
120 + if ((1<<j) & ALL_TAGS) pattern = literals[j];
121 + if (!((1<<j) & tags)) continue;
122 + length = strlen(pattern);
123 + ptr = the_module;
124 + do {
125 + ptr = memchr(ptr, *pattern, len - (ptr - (char*)the_module));
126 + if (ptr == NULL) /* no occurance left, done */
127 + break;
128 + if (!strncmp(ptr, pattern, length) && ptr[length] == '=') {
129 + ptr += length + 1;
130 + ptr += display(ptr,pattern,(1<<j) != tags);
131 + }
132 + ++ptr;
133 + } while (1);
134 + }
135 + free(the_module);
136 + }
137 + }
138 +}
139 +
140 +int modinfo_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
141 +int modinfo_main(int argc UNUSED_PARAM, char **argv)
142 +{
143 + static const char *shortcuts[] = {
144 + "filename",
145 + "description",
146 + "author",
147 + "license",
148 + "vermagic",
149 + "parm",
150 + };
151 + struct modinfo_env env;
152 + extern void mod_walk(void (*action)(char *name, char *path, void *env),
153 + void *data);
154 +
155 + env.field = NULL;
156 + env.literals = shortcuts;
157 + getopt32(argv, "fdalvpF:0", &env.field);
158 + env.argv = argv += optind;
159 + env.tags = (option_mask32) ? option_mask32 & ALL_TAGS : ALL_TAGS;
160 +
161 + if (!*env.argv)
162 + bb_show_usage();
163 +
164 + mod_walk(modinfo, &env);
165 + return 0;
166 +}