wok-6.x annotate busybox/stuff/busybox-1.12.0-modinfo.u @ rev 3878

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