aboutsummaryrefslogtreecommitdiff
path: root/modutils
diff options
context:
space:
mode:
Diffstat (limited to 'modutils')
-rw-r--r--modutils/insmod.c22
-rw-r--r--modutils/modprobe-small.c13
-rw-r--r--modutils/modprobe.c171
-rw-r--r--modutils/modutils.h41
4 files changed, 193 insertions, 54 deletions
diff --git a/modutils/insmod.c b/modutils/insmod.c
index c4fb9279d..b88446c10 100644
--- a/modutils/insmod.c
+++ b/modutils/insmod.c
@@ -10,6 +10,28 @@
10#include "libbb.h" 10#include "libbb.h"
11#include "modutils.h" 11#include "modutils.h"
12 12
13/* 2.6 style insmod has no options and required filename
14 * (not module name - .ko can't be omitted) */
15
16//usage:#define insmod_trivial_usage
17//usage: IF_FEATURE_2_4_MODULES("[OPTIONS] MODULE ")
18//usage: IF_NOT_FEATURE_2_4_MODULES("FILE ")
19//usage: "[symbol=value]..."
20//usage:#define insmod_full_usage "\n\n"
21//usage: "Load the specified kernel modules into the kernel"
22//usage: IF_FEATURE_2_4_MODULES( "\n"
23//usage: "\nOptions:"
24//usage: "\n -f Force module to load into the wrong kernel version"
25//usage: "\n -k Make module autoclean-able"
26//usage: "\n -v Verbose"
27//usage: "\n -q Quiet"
28//usage: "\n -L Lock: prevent simultaneous loads"
29//usage: IF_FEATURE_INSMOD_LOAD_MAP(
30//usage: "\n -m Output load map to stdout"
31//usage: )
32//usage: "\n -x Don't export externs"
33//usage: )
34
13int insmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 35int insmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
14int insmod_main(int argc UNUSED_PARAM, char **argv) 36int insmod_main(int argc UNUSED_PARAM, char **argv)
15{ 37{
diff --git a/modutils/modprobe-small.c b/modutils/modprobe-small.c
index cf22b9471..0e1874ed4 100644
--- a/modutils/modprobe-small.c
+++ b/modutils/modprobe-small.c
@@ -685,6 +685,19 @@ The following options are useful for people managing distributions:
685 Use the file instead of the current kernel symbols 685 Use the file instead of the current kernel symbols
686*/ 686*/
687 687
688//usage:#if ENABLE_MODPROBE_SMALL
689//usage:#define modprobe_trivial_usage
690//usage: "[-qfwrsv] MODULE [symbol=value]..."
691//usage:#define modprobe_full_usage "\n\n"
692//usage: "Options:"
693//usage: "\n -r Remove MODULE (stacks) or do autoclean"
694//usage: "\n -q Quiet"
695//usage: "\n -v Verbose"
696//usage: "\n -f Force"
697//usage: "\n -w Wait for unload"
698//usage: "\n -s Report via syslog instead of stderr"
699//usage:#endif /* ENABLE_MODPROBE_SMALL */
700
688int modprobe_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 701int modprobe_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
689int modprobe_main(int argc UNUSED_PARAM, char **argv) 702int modprobe_main(int argc UNUSED_PARAM, char **argv)
690{ 703{
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) {
diff --git a/modutils/modutils.h b/modutils/modutils.h
index 131a5087b..d46870ca6 100644
--- a/modutils/modutils.h
+++ b/modutils/modutils.h
@@ -23,32 +23,27 @@ int string_to_llist(char *string, llist_t **llist, const char *delim) FAST_FUNC;
23char *filename2modname(const char *filename, char *modname) FAST_FUNC; 23char *filename2modname(const char *filename, char *modname) FAST_FUNC;
24char *parse_cmdline_module_options(char **argv) FAST_FUNC; 24char *parse_cmdline_module_options(char **argv) FAST_FUNC;
25 25
26/* insmod for 2.4 and modprobe's options (insmod 2.6 has no options at all): */
26#define INSMOD_OPTS \ 27#define INSMOD_OPTS \
27 "vq" \ 28 "vqs" \
28 IF_FEATURE_2_4_MODULES("sLo:fkx") \ 29 IF_FEATURE_2_4_MODULES("Lfkx" IF_FEATURE_INSMOD_LOAD_MAP("m"))
29 IF_FEATURE_INSMOD_LOAD_MAP("m") 30#define INSMOD_ARGS /* (was meant to support -o NAME) , NULL */
30
31#define INSMOD_ARGS IF_FEATURE_2_4_MODULES(, NULL)
32 31
33enum { 32enum {
34 INSMOD_OPT_VERBOSE = 0x0001, 33 INSMOD_OPT_VERBOSE = (1 << 0),
35 INSMOD_OPT_SILENT = 0x0002, 34 INSMOD_OPT_SILENT = (1 << 1),
36 INSMOD_OPT_SYSLOG = 0x0004 * ENABLE_FEATURE_2_4_MODULES, 35 INSMOD_OPT_SYSLOG = (1 << 2),
37 INSMOD_OPT_LOCK = 0x0008 * ENABLE_FEATURE_2_4_MODULES, 36 //INSMOD_OPT_OUTPUTNAME = (1 << x) - not supported yet
38 INSMOD_OPT_OUTPUTNAME = 0x0010 * ENABLE_FEATURE_2_4_MODULES, 37 INSMOD_OPT_LOCK = (1 << 3) * ENABLE_FEATURE_2_4_MODULES,
39 INSMOD_OPT_FORCE = 0x0020 * ENABLE_FEATURE_2_4_MODULES, 38 INSMOD_OPT_FORCE = (1 << 4) * ENABLE_FEATURE_2_4_MODULES,
40 INSMOD_OPT_KERNELD = 0x0040 * ENABLE_FEATURE_2_4_MODULES, 39 INSMOD_OPT_KERNELD = (1 << 5) * ENABLE_FEATURE_2_4_MODULES,
41 INSMOD_OPT_NO_EXPORT = 0x0080 * ENABLE_FEATURE_2_4_MODULES, 40 INSMOD_OPT_NO_EXPORT = (1 << 6) * ENABLE_FEATURE_2_4_MODULES,
42 INSMOD_OPT_PRINT_MAP = 0x0100 * ENABLE_FEATURE_INSMOD_LOAD_MAP, 41 INSMOD_OPT_PRINT_MAP = (1 << 7) * ENABLE_FEATURE_INSMOD_LOAD_MAP,
43#if ENABLE_FEATURE_2_4_MODULES 42 INSMOD_OPT_UNUSED =
44# if ENABLE_FEATURE_INSMOD_LOAD_MAP 43 (INSMOD_OPT_PRINT_MAP ? INSMOD_OPT_PRINT_MAP
45 INSMOD_OPT_UNUSED = 0x0200, 44 : INSMOD_OPT_NO_EXPORT ? INSMOD_OPT_NO_EXPORT
46# else 45 : INSMOD_OPT_SYSLOG
47 INSMOD_OPT_UNUSED = 0x0100, 46 ) << 1
48# endif
49#else
50 INSMOD_OPT_UNUSED = 0x0004,
51#endif
52}; 47};
53 48
54#if ENABLE_FEATURE_INSMOD_TRY_MMAP 49#if ENABLE_FEATURE_INSMOD_TRY_MMAP