wok view busybox/stuff/busybox-1.12.0-modinfo.u @ rev 1711

clamav: update BUILD_DEPENDS
author Paul Issott <paul@slitaz.org>
date Sun Nov 16 17:19:15 2008 +0000 (2008-11-16)
parents 8a7fbe920ac6
children 22791a4ca944
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,82 @@
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 +enum {
77 + ARG_F = (1<<4), /* field name */
78 + ARG_0 = (1<<5) /* \0 as separator */
79 +};
80 +
81 +struct modinfo_env {
82 + char **argv;
83 + char *field;
84 +};
85 +
86 +static void modinfo(char *name, char *path, void *env)
87 +{
88 + size_t len;
89 + int i, length;
90 + char *ptr, *the_module;
91 + char **argv = ((struct modinfo_env *) env)->argv;
92 + char *field = ((struct modinfo_env *) env)->field;
93 + extern void *xalloc_load_module(const char filename[], size_t *len);
94 +
95 + for (i = 0; argv[i]; i++) {
96 + if (fnmatch(argv[i],name,0) == 0) {
97 + len = MAXINT(ssize_t);
98 + ptr = the_module = xalloc_load_module(path, &len);
99 + length = strlen(field);
100 + do {
101 + ptr = memchr(ptr, *field, len - (ptr - (char*)the_module));
102 + if (ptr == NULL) /* no occurance left, done */
103 + break;
104 + if (!strncmp(ptr, field, length) && ptr[length] == '=') {
105 + ptr += length + 1;
106 + ptr += printf("%s%c",ptr,
107 + (option_mask32 & ARG_0) ? '\0' : '\n');
108 + }
109 + ++ptr;
110 + } while (1);
111 + free(the_module);
112 + break;
113 + }
114 + }
115 +}
116 +
117 +int modinfo_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
118 +int modinfo_main(int argc UNUSED_PARAM, char **argv)
119 +{
120 + static const char *shortcuts[] = {
121 + "author",
122 + "description",
123 + "license",
124 + "parm"
125 + };
126 + int i;
127 + struct modinfo_env env;
128 + extern void mod_walk(void (*action)(char *name, char *path, void *env),
129 + void *data);
130 +
131 + env.field = NULL;
132 + getopt32(argv, "adlpF:0", &env.field);
133 + env.argv = argv += optind;
134 +
135 + for (i = 0; i < sizeof(shortcuts)/sizeof(shortcuts[0]); i++)
136 + if (option_mask32 & (1 << i))
137 + env.field = (char *) shortcuts[i];
138 +
139 + if (!env.field || !*env.argv)
140 + bb_show_usage();
141 +
142 + mod_walk(modinfo, &env);
143 + return 0;
144 +}