aboutsummaryrefslogtreecommitdiff
path: root/modutils/modprobe.c
diff options
context:
space:
mode:
authorPascal Bellard <pascal.bellard@ads-lu.com>2010-06-07 01:16:45 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2010-06-07 01:18:53 +0200
commitb82b34e06d0f8b91a1a30a847e0b1dd80ed0a046 (patch)
tree17527de763a7e688023cb72a8ead602293b3b7b9 /modutils/modprobe.c
parente3657dcdd655ec96fc6bf38c40dd6a6f015a83de (diff)
downloadbusybox-w32-b82b34e06d0f8b91a1a30a847e0b1dd80ed0a046.tar.gz
busybox-w32-b82b34e06d0f8b91a1a30a847e0b1dd80ed0a046.tar.bz2
busybox-w32-b82b34e06d0f8b91a1a30a847e0b1dd80ed0a046.zip
modprobe: add support for -l and -s. Remove some unsupported options
Fixed some goofs in help text function old new delta modprobe_main 494 653 +159 packed_usage 27129 27145 +16 insmod_main 98 95 -3 Signed-off-by: Pascal Bellard <pascal.bellard@ads-lu.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'modutils/modprobe.c')
-rw-r--r--modutils/modprobe.c171
1 files changed, 140 insertions, 31 deletions
diff --git a/modutils/modprobe.c b/modutils/modprobe.c
index 69b9e4687..b4de65b1f 100644
--- a/modutils/modprobe.c
+++ b/modutils/modprobe.c
@@ -20,6 +20,104 @@
20//#define DBG(fmt, ...) bb_error_msg("%s: " fmt, __func__, ## __VA_ARGS__) 20//#define DBG(fmt, ...) bb_error_msg("%s: " fmt, __func__, ## __VA_ARGS__)
21#define DBG(...) ((void)0) 21#define DBG(...) ((void)0)
22 22
23//usage:#if !ENABLE_MODPROBE_SMALL
24//usage:#define modprobe_notes_usage
25//usage: "modprobe can (un)load a stack of modules, passing each module options (when\n"
26//usage: "loading). modprobe uses a configuration file to determine what option(s) to\n"
27//usage: "pass each module it loads.\n"
28//usage: "\n"
29//usage: "The configuration file is searched (in this order):\n"
30//usage: "\n"
31//usage: " /etc/modprobe.conf (2.6 only)\n"
32//usage: " /etc/modules.conf\n"
33//usage: " /etc/conf.modules (deprecated)\n"
34//usage: "\n"
35//usage: "They all have the same syntax (see below). If none is present, it is\n"
36//usage: "_not_ an error; each loaded module is then expected to load without\n"
37//usage: "options. Once a file is found, the others are tested for.\n"
38//usage: "\n"
39//usage: "/etc/modules.conf entry format:\n"
40//usage: "\n"
41//usage: " alias <alias_name> <mod_name>\n"
42//usage: " Makes it possible to modprobe alias_name, when there is no such module.\n"
43//usage: " It makes sense if your mod_name is long, or you want a more representative\n"
44//usage: " name for that module (eg. 'scsi' in place of 'aha7xxx').\n"
45//usage: " This makes it also possible to use a different set of options (below) for\n"
46//usage: " the module and the alias.\n"
47//usage: " A module can be aliased more than once.\n"
48//usage: "\n"
49//usage: " options <mod_name|alias_name> <symbol=value...>\n"
50//usage: " When loading module mod_name (or the module aliased by alias_name), pass\n"
51//usage: " the \"symbol=value\" pairs as option to that module.\n"
52//usage: "\n"
53//usage: "Sample /etc/modules.conf file:\n"
54//usage: "\n"
55//usage: " options tulip irq=3\n"
56//usage: " alias tulip tulip2\n"
57//usage: " options tulip2 irq=4 io=0x308\n"
58//usage: "\n"
59//usage: "Other functionality offered by 'classic' modprobe is not available in\n"
60//usage: "this implementation.\n"
61//usage: "\n"
62//usage: "If module options are present both in the config file, and on the command line,\n"
63//usage: "then the options from the command line will be passed to the module _after_\n"
64//usage: "the options from the config file. That way, you can have defaults in the config\n"
65//usage: "file, and override them for a specific usage from the command line.\n"
66//usage:#define modprobe_example_usage
67//usage: "(with the above /etc/modules.conf):\n\n"
68//usage: "$ modprobe tulip\n"
69//usage: " will load the module 'tulip' with default option 'irq=3'\n\n"
70//usage: "$ modprobe tulip irq=5\n"
71//usage: " will load the module 'tulip' with option 'irq=5', thus overriding the default\n\n"
72//usage: "$ modprobe tulip2\n"
73//usage: " will load the module 'tulip' with default options 'irq=4 io=0x308',\n"
74//usage: " which are the default for alias 'tulip2'\n\n"
75//usage: "$ modprobe tulip2 irq=8\n"
76//usage: " will load the module 'tulip' with default options 'irq=4 io=0x308 irq=8',\n"
77//usage: " which are the default for alias 'tulip2' overridden by the option 'irq=8'\n\n"
78//usage: " from the command line\n\n"
79//usage: "$ modprobe tulip2 irq=2 io=0x210\n"
80//usage: " will load the module 'tulip' with default options 'irq=4 io=0x308 irq=4 io=0x210',\n"
81//usage: " which are the default for alias 'tulip2' overridden by the options 'irq=2 io=0x210'\n\n"
82//usage: " from the command line\n"
83//usage:
84//usage:#define modprobe_trivial_usage
85//usage: "[-alrqvs"
86//usage: IF_FEATURE_MODPROBE_BLACKLIST("b")
87//usage: "] MODULE [symbol=value]..."
88//usage:#define modprobe_full_usage "\n\n"
89//usage: "Options:"
90//usage: "\n -a Load multiple MODULEs"
91//usage: "\n -l List (MODULE is a pattern)"
92//usage: "\n -r Remove MODULE (stacks) or do autoclean"
93//usage: "\n -q Quiet"
94//usage: "\n -v Verbose"
95//usage: "\n -s Log to syslog"
96//usage: IF_FEATURE_MODPROBE_BLACKLIST(
97//usage: "\n -b Apply blacklist to module names too"
98//usage: )
99//usage:#endif /* !ENABLE_MODPROBE_SMALL */
100
101/* Note that usage text doesn't document various 2.4 options
102 * we pull in through INSMOD_OPTS define */
103
104#define MODPROBE_COMPLEMENTARY "q-v:v-q:l--ar:a--lr:r--al"
105#define MODPROBE_OPTS "alr" IF_FEATURE_MODPROBE_BLACKLIST("b")
106//#define MODPROBE_COMPLEMENTARY "q-v:v-q:l--acr:a--lr:r--al"
107//#define MODPROBE_OPTS "acd:lnrt:C:" IF_FEATURE_MODPROBE_BLACKLIST("b")
108enum {
109 MODPROBE_OPT_INSERT_ALL = (INSMOD_OPT_UNUSED << 0), /* a */
110 //MODPROBE_OPT_DUMP_ONLY= (INSMOD_OPT_UNUSED << x), /* c */
111 //MODPROBE_OPT_DIRNAME = (INSMOD_OPT_UNUSED << x), /* d */
112 MODPROBE_OPT_LIST_ONLY = (INSMOD_OPT_UNUSED << 1), /* l */
113 //MODPROBE_OPT_SHOW_ONLY= (INSMOD_OPT_UNUSED << x), /* n */
114 MODPROBE_OPT_REMOVE = (INSMOD_OPT_UNUSED << 2), /* r */
115 //MODPROBE_OPT_RESTRICT = (INSMOD_OPT_UNUSED << x), /* t */
116 //MODPROBE_OPT_VERONLY = (INSMOD_OPT_UNUSED << x), /* V */
117 //MODPROBE_OPT_CONFIGFILE=(INSMOD_OPT_UNUSED << x), /* C */
118 MODPROBE_OPT_BLACKLIST = (INSMOD_OPT_UNUSED << 3) * ENABLE_FEATURE_MODPROBE_BLACKLIST,
119};
120
23#define MODULE_FLAG_LOADED 0x0001 121#define MODULE_FLAG_LOADED 0x0001
24#define MODULE_FLAG_NEED_DEPS 0x0002 122#define MODULE_FLAG_NEED_DEPS 0x0002
25/* "was seen in modules.dep": */ 123/* "was seen in modules.dep": */
@@ -37,32 +135,6 @@ struct module_entry { /* I'll call it ME. */
37 llist_t *deps; /* strings. modules we depend on */ 135 llist_t *deps; /* strings. modules we depend on */
38}; 136};
39 137
40/* NB: INSMOD_OPT_SILENT bit suppresses ONLY non-existent modules,
41 * not deleted ones (those are still listed in modules.dep).
42 * module-init-tools version 3.4:
43 * # modprobe bogus
44 * FATAL: Module bogus not found. [exitcode 1]
45 * # modprobe -q bogus [silent, exitcode still 1]
46 * but:
47 * # rm kernel/drivers/net/dummy.ko
48 * # modprobe -q dummy
49 * FATAL: Could not open '/lib/modules/xxx/kernel/drivers/net/dummy.ko': No such file or directory
50 * [exitcode 1]
51 */
52#define MODPROBE_OPTS "acdlnrt:VC:" IF_FEATURE_MODPROBE_BLACKLIST("b")
53enum {
54 MODPROBE_OPT_INSERT_ALL = (INSMOD_OPT_UNUSED << 0), /* a */
55 MODPROBE_OPT_DUMP_ONLY = (INSMOD_OPT_UNUSED << 1), /* c */
56 MODPROBE_OPT_D = (INSMOD_OPT_UNUSED << 2), /* d */
57 MODPROBE_OPT_LIST_ONLY = (INSMOD_OPT_UNUSED << 3), /* l */
58 MODPROBE_OPT_SHOW_ONLY = (INSMOD_OPT_UNUSED << 4), /* n */
59 MODPROBE_OPT_REMOVE = (INSMOD_OPT_UNUSED << 5), /* r */
60 MODPROBE_OPT_RESTRICT = (INSMOD_OPT_UNUSED << 6), /* t */
61 MODPROBE_OPT_VERONLY = (INSMOD_OPT_UNUSED << 7), /* V */
62 MODPROBE_OPT_CONFIGFILE = (INSMOD_OPT_UNUSED << 8), /* C */
63 MODPROBE_OPT_BLACKLIST = (INSMOD_OPT_UNUSED << 9) * ENABLE_FEATURE_MODPROBE_BLACKLIST,
64};
65
66struct globals { 138struct globals {
67 llist_t *db; /* MEs of all modules ever seen (caching for speed) */ 139 llist_t *db; /* MEs of all modules ever seen (caching for speed) */
68 llist_t *probes; /* MEs of module(s) requested on cmdline */ 140 llist_t *probes; /* MEs of module(s) requested on cmdline */
@@ -264,6 +336,18 @@ static char *parse_and_add_kcmdline_module_options(char *options, const char *mo
264 * -errno on open/read error, 336 * -errno on open/read error,
265 * errno on init_module() error 337 * errno on init_module() error
266 */ 338 */
339/* NB: INSMOD_OPT_SILENT bit suppresses ONLY non-existent modules,
340 * not deleted ones (those are still listed in modules.dep).
341 * module-init-tools version 3.4:
342 * # modprobe bogus
343 * FATAL: Module bogus not found. [exitcode 1]
344 * # modprobe -q bogus [silent, exitcode still 1]
345 * but:
346 * # rm kernel/drivers/net/dummy.ko
347 * # modprobe -q dummy
348 * FATAL: Could not open '/lib/modules/xxx/kernel/drivers/net/dummy.ko': No such file or directory
349 * [exitcode 1]
350 */
267static int do_modprobe(struct module_entry *m) 351static int do_modprobe(struct module_entry *m)
268{ 352{
269 struct module_entry *m2 = m2; /* for compiler */ 353 struct module_entry *m2 = m2; /* for compiler */
@@ -395,13 +479,38 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
395 unsigned opt; 479 unsigned opt;
396 struct module_entry *me; 480 struct module_entry *me;
397 481
398 opt_complementary = "q-v:v-q"; 482 opt_complementary = MODPROBE_COMPLEMENTARY;
399 opt = getopt32(argv, INSMOD_OPTS MODPROBE_OPTS INSMOD_ARGS, NULL, NULL); 483 opt = getopt32(argv, INSMOD_OPTS MODPROBE_OPTS INSMOD_ARGS);
400 argv += optind; 484 argv += optind;
401 485
402 if (opt & (MODPROBE_OPT_DUMP_ONLY | MODPROBE_OPT_LIST_ONLY | 486 if (opt & MODPROBE_OPT_LIST_ONLY) {
403 MODPROBE_OPT_SHOW_ONLY)) 487 char name[MODULE_NAME_LEN];
404 bb_error_msg_and_die("not supported"); 488 char *colon, *tokens[2];
489 parser_t *p = config_open2(CONFIG_DEFAULT_DEPMOD_FILE, xfopen_for_read);
490
491 while (config_read(p, tokens, 2, 1, "# \t", PARSE_NORMAL)) {
492 colon = last_char_is(tokens[0], ':');
493 if (!colon)
494 continue;
495 *colon = '\0';
496 filename2modname(tokens[0], name);
497 if (!argv[0])
498 puts(tokens[0]);
499 else {
500 int i;
501 for (i = 0; argv[i]; i++) {
502 if (fnmatch(argv[i], name, 0) == 0) {
503 puts(tokens[0]);
504 }
505 }
506 }
507 }
508 return EXIT_SUCCESS;
509 }
510
511 /* Yes, for some reason -l ignores -s... */
512 if (opt & INSMOD_OPT_SYSLOG)
513 logmode = LOGMODE_SYSLOG;
405 514
406 if (!argv[0]) { 515 if (!argv[0]) {
407 if (opt & MODPROBE_OPT_REMOVE) { 516 if (opt & MODPROBE_OPT_REMOVE) {