wok view busybox/stuff/busybox-1.16.1-modinfo.u @ rev 5738

Add 'git-gui' package, v0.12.0.66.
Tested on Stable (built & installed) and Cooking (installed after upgrade) successfully.
author Ben Arnold <ben@seawolfsanctuary.com>
date Sat Jun 26 13:59:56 2010 +0100 (2010-06-26)
parents 2a5e098a34ac
children
line source
1 --- busybox-1.16.1/include/applets.h
2 +++ busybox-1.16.1/include/applets.h
3 @@ -273,6 +273,7 @@
4 IF_CRYPTPW(APPLET_ODDNAME(mkpasswd, cryptpw, _BB_DIR_USR_BIN, _BB_SUID_DROP, mkpasswd))
5 IF_MKSWAP(APPLET(mkswap, _BB_DIR_SBIN, _BB_SUID_DROP))
6 IF_MKTEMP(APPLET(mktemp, _BB_DIR_BIN, _BB_SUID_DROP))
7 +IF_MODINFO(APPLET(modinfo, _BB_DIR_SBIN, _BB_SUID_DROP))
8 IF_MODPROBE(APPLET(modprobe, _BB_DIR_SBIN, _BB_SUID_DROP))
9 IF_MODPROBE_SMALL(APPLET(modprobe, _BB_DIR_SBIN, _BB_SUID_DROP))
10 IF_MORE(APPLET(more, _BB_DIR_BIN, _BB_SUID_DROP))
12 --- busybox-1.16.1/include/usage.h
13 +++ busybox-1.16.1/include/usage.h
14 @@ -2984,6 +2984,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.16.0/modutils/Config.in
37 +++ busybox-1.16.0/modutils/Config.in
38 @@ -110,6 +110,12 @@
39 and modules.symbols) that contain dependency information
40 for modprobe.
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"
50 config FEATURE_2_4_MODULES
52 --- busybox-1.16.1/modutils/Kbuild
53 +++ busybox-1.16.1/modutils/Kbuild
54 @@ -12,3 +12,4 @@
55 lib-$(CONFIG_MODPROBE) += modprobe.o modutils.o
56 lib-$(CONFIG_RMMOD) += rmmod.o modutils.o
57 lib-$(CONFIG_FEATURE_2_4_MODULES) += modutils-24.o
58 +lib-$(CONFIG_MODINFO) += modinfo.o
60 --- busybox-1.16.1/modutils/modinfo.c
61 +++ busybox-1.16.1/modutils/modinfo.c
62 @@ -0,0 +1,121 @@
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 +#include "modutils.h"
76 +#include <sys/utsname.h> /* uname() */
77 +
78 +#define ALL_TAGS 0x3F
79 +
80 +enum {
81 + ARG_F = (1<<6), /* field name */
82 + ARG_0 = (1<<7) /* \0 as separator */
83 +};
84 +
85 +struct modinfo_env {
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 *path, struct modinfo_env *env)
100 +{
101 + static const char *shortcuts[] = {
102 + "filename",
103 + "description",
104 + "author",
105 + "license",
106 + "vermagic",
107 + "parm",
108 + };
109 + size_t len;
110 + int j, length;
111 + char *ptr, *the_module;
112 + const char *field = env->field;
113 + int tags = env->tags;
114 +
115 + if (tags & 1) { /* filename */
116 + display(path,shortcuts[0],1 != tags);
117 + }
118 + len = MAXINT(ssize_t);
119 + the_module = xmalloc_open_zipped_read_close(path, &len);
120 + if (!the_module) return;
121 + if (field) tags |= ALL_TAGS+1;
122 + for (j = 1; (1<<j) & (ALL_TAGS+ALL_TAGS+1); j++) {
123 + const char *pattern = field;
124 + if ((1<<j) & ALL_TAGS) pattern = shortcuts[j];
125 + if (!((1<<j) & tags)) continue;
126 + length = strlen(pattern);
127 + ptr = the_module;
128 + do {
129 + ptr = memchr(ptr, *pattern, len - (ptr - (char*)the_module));
130 + if (ptr == NULL) /* no occurance left, done */
131 + break;
132 + if (!strncmp(ptr, pattern, length) && ptr[length] == '=') {
133 + ptr += length + 1;
134 + ptr += display(ptr,pattern,(1<<j) != tags);
135 + }
136 + ++ptr;
137 + } while (1);
138 + }
139 + free(the_module);
140 +}
141 +
142 +int modinfo_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
143 +int modinfo_main(int argc, char **argv)
144 +{
145 + struct modinfo_env env;
146 + char name[MODULE_NAME_LEN];
147 + struct utsname uts;
148 + parser_t *p;
149 + char *colon, *tokens[2];
150 + int i;
151 +
152 + env.field = NULL;
153 + getopt32(argv, "fdalvpF:0", &env.field);
154 + env.tags = (option_mask32) ? option_mask32 & ALL_TAGS : ALL_TAGS;
155 +
156 + if (optind >= argc)
157 + bb_show_usage();
158 +
159 + uname(&uts);
160 + p = config_open2(concat_path_file(concat_path_file(
161 + CONFIG_DEFAULT_MODULES_DIR, uts.release),
162 + CONFIG_DEFAULT_DEPMOD_FILE), xfopen_for_read);
163 +
164 + while (config_read(p, tokens, 2, 1, "# \t", PARSE_NORMAL)) {
165 + colon = last_char_is(tokens[0], ':');
166 + if (colon == NULL)
167 + continue;
168 + *colon = 0;
169 + filename2modname(tokens[0], name);
170 + for (i = optind; i < argc; i++) {
171 + if (fnmatch(argv[i],name,0) == 0) {
172 + modinfo(tokens[0], &env);
173 + argv[i] = (char *) "";
174 + }
175 + }
176 + }
177 + for (i = optind; i < argc; i++) {
178 + if (*argv[i]) {
179 + modinfo(argv[i], &env);
180 + }
181 + }
182 + return 0;
183 +}