Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Erik Andersen | 0210432 | 1999-12-17 18:57:34 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Mini insmod implementation for busybox |
Eric Andersen | 2835efe | 2001-07-25 16:58:58 +0000 | [diff] [blame] | 4 | * |
Denis Vlasenko | ba1315d | 2008-09-13 14:59:38 +0000 | [diff] [blame] | 5 | * Copyright (C) 2008 Timo Teras <timo.teras@iki.fi> |
Erik Andersen | 0210432 | 1999-12-17 18:57:34 +0000 | [diff] [blame] | 6 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Erik Andersen | 0210432 | 1999-12-17 18:57:34 +0000 | [diff] [blame] | 8 | */ |
Denys Vlasenko | e32b64c | 2016-11-23 07:54:52 +0100 | [diff] [blame] | 9 | //config:config INSMOD |
Denys Vlasenko | 4eed2c6 | 2017-07-18 22:01:24 +0200 | [diff] [blame] | 10 | //config: bool "insmod (22 kb)" |
Denys Vlasenko | 3bf4d69 | 2016-12-23 15:22:44 +0100 | [diff] [blame] | 11 | //config: default y |
Denys Vlasenko | e32b64c | 2016-11-23 07:54:52 +0100 | [diff] [blame] | 12 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 13 | //config: insmod is used to load specified modules in the running kernel. |
Erik Andersen | 0210432 | 1999-12-17 18:57:34 +0000 | [diff] [blame] | 14 | |
Denys Vlasenko | 3346b4a | 2017-08-04 02:56:39 +0200 | [diff] [blame] | 15 | //applet:IF_INSMOD(IF_NOT_MODPROBE_SMALL(APPLET_NOEXEC(insmod, insmod, BB_DIR_SBIN, BB_SUID_DROP, insmod))) |
Denys Vlasenko | c15613c | 2010-10-15 11:29:02 +0200 | [diff] [blame] | 16 | |
Denys Vlasenko | a1cd0d9 | 2016-12-23 15:12:27 +0100 | [diff] [blame] | 17 | //kbuild:ifneq ($(CONFIG_MODPROBE_SMALL),y) |
Denys Vlasenko | e32b64c | 2016-11-23 07:54:52 +0100 | [diff] [blame] | 18 | //kbuild:lib-$(CONFIG_INSMOD) += insmod.o modutils.o |
Denys Vlasenko | a1cd0d9 | 2016-12-23 15:12:27 +0100 | [diff] [blame] | 19 | //kbuild:endif |
Denys Vlasenko | e32b64c | 2016-11-23 07:54:52 +0100 | [diff] [blame] | 20 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 21 | #include "libbb.h" |
Denis Vlasenko | ba1315d | 2008-09-13 14:59:38 +0000 | [diff] [blame] | 22 | #include "modutils.h" |
Eric Andersen | e704788 | 2003-12-11 01:42:13 +0000 | [diff] [blame] | 23 | |
Pascal Bellard | b82b34e | 2010-06-07 01:16:45 +0200 | [diff] [blame] | 24 | /* 2.6 style insmod has no options and required filename |
| 25 | * (not module name - .ko can't be omitted) */ |
| 26 | |
Denys Vlasenko | 1a5e11c | 2010-10-16 01:56:41 +0200 | [diff] [blame] | 27 | //usage:#if !ENABLE_MODPROBE_SMALL |
Pascal Bellard | b82b34e | 2010-06-07 01:16:45 +0200 | [diff] [blame] | 28 | //usage:#define insmod_trivial_usage |
Denys Vlasenko | 84d5edd | 2020-12-13 22:34:05 +0100 | [diff] [blame] | 29 | //usage: IF_FEATURE_2_4_MODULES("[-fkvqLx] MODULE") |
Kang-Che Sung | b1d6a2c | 2017-01-31 21:09:17 +0800 | [diff] [blame] | 30 | //usage: IF_NOT_FEATURE_2_4_MODULES("FILE") |
| 31 | //usage: IF_FEATURE_CMDLINE_MODULE_OPTIONS(" [SYMBOL=VALUE]...") |
Pascal Bellard | b82b34e | 2010-06-07 01:16:45 +0200 | [diff] [blame] | 32 | //usage:#define insmod_full_usage "\n\n" |
Denys Vlasenko | 5fd3ddf | 2014-04-19 15:04:39 +0200 | [diff] [blame] | 33 | //usage: "Load kernel module" |
Pascal Bellard | b82b34e | 2010-06-07 01:16:45 +0200 | [diff] [blame] | 34 | //usage: IF_FEATURE_2_4_MODULES( "\n" |
Pascal Bellard | b82b34e | 2010-06-07 01:16:45 +0200 | [diff] [blame] | 35 | //usage: "\n -f Force module to load into the wrong kernel version" |
| 36 | //usage: "\n -k Make module autoclean-able" |
| 37 | //usage: "\n -v Verbose" |
| 38 | //usage: "\n -q Quiet" |
| 39 | //usage: "\n -L Lock: prevent simultaneous loads" |
| 40 | //usage: IF_FEATURE_INSMOD_LOAD_MAP( |
| 41 | //usage: "\n -m Output load map to stdout" |
| 42 | //usage: ) |
| 43 | //usage: "\n -x Don't export externs" |
| 44 | //usage: ) |
Denys Vlasenko | 1a5e11c | 2010-10-16 01:56:41 +0200 | [diff] [blame] | 45 | //usage:#endif |
Pascal Bellard | b82b34e | 2010-06-07 01:16:45 +0200 | [diff] [blame] | 46 | |
Denis Vlasenko | b68979a | 2007-11-02 23:31:10 +0000 | [diff] [blame] | 47 | int insmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 48 | int insmod_main(int argc UNUSED_PARAM, char **argv) |
Eric Andersen | e704788 | 2003-12-11 01:42:13 +0000 | [diff] [blame] | 49 | { |
Denis Vlasenko | ba1315d | 2008-09-13 14:59:38 +0000 | [diff] [blame] | 50 | char *filename; |
| 51 | int rc; |
| 52 | |
Denis Vlasenko | 36309cf | 2008-11-22 18:29:01 +0000 | [diff] [blame] | 53 | /* Compat note: |
| 54 | * 2.6 style insmod has no options and required filename |
| 55 | * (not module name - .ko can't be omitted). |
Bernhard Reutner-Fischer | 9a280fa | 2008-11-22 20:30:53 +0000 | [diff] [blame] | 56 | * 2.4 style insmod can take module name without .o |
Denis Vlasenko | 36309cf | 2008-11-22 18:29:01 +0000 | [diff] [blame] | 57 | * and performs module search in default directories |
| 58 | * or in $MODPATH. |
| 59 | */ |
| 60 | |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 61 | IF_FEATURE_2_4_MODULES( |
Denis Vlasenko | ba1315d | 2008-09-13 14:59:38 +0000 | [diff] [blame] | 62 | getopt32(argv, INSMOD_OPTS INSMOD_ARGS); |
Denis Vlasenko | 36309cf | 2008-11-22 18:29:01 +0000 | [diff] [blame] | 63 | argv += optind - 1; |
Denis Vlasenko | ba1315d | 2008-09-13 14:59:38 +0000 | [diff] [blame] | 64 | ); |
Eric Andersen | 3b1a744 | 2003-12-24 20:30:45 +0000 | [diff] [blame] | 65 | |
Denis Vlasenko | 9229794 | 2006-11-21 11:58:14 +0000 | [diff] [blame] | 66 | filename = *++argv; |
| 67 | if (!filename) |
Eric Andersen | e704788 | 2003-12-11 01:42:13 +0000 | [diff] [blame] | 68 | bb_show_usage(); |
Eric Andersen | e704788 | 2003-12-11 01:42:13 +0000 | [diff] [blame] | 69 | |
Denys Vlasenko | c5830bd | 2011-02-02 00:00:36 +0100 | [diff] [blame] | 70 | rc = bb_init_module(filename, parse_cmdline_module_options(argv, /*quote_spaces:*/ 0)); |
Denis Vlasenko | ba1315d | 2008-09-13 14:59:38 +0000 | [diff] [blame] | 71 | if (rc) |
Denis Vlasenko | 1f63229 | 2009-04-13 02:25:40 +0000 | [diff] [blame] | 72 | bb_error_msg("can't insert '%s': %s", filename, moderror(rc)); |
Eric Andersen | e704788 | 2003-12-11 01:42:13 +0000 | [diff] [blame] | 73 | |
Denis Vlasenko | ba1315d | 2008-09-13 14:59:38 +0000 | [diff] [blame] | 74 | return rc; |
Eric Andersen | e704788 | 2003-12-11 01:42:13 +0000 | [diff] [blame] | 75 | } |