blob: 8f7163e25b4363b149ca0cab88ae3ed7827e01a9 [file] [log] [blame]
Erik Andersene49d5ec2000-02-08 19:58:47 +00001/* vi: set sw=4 ts=4: */
Erik Andersen02104321999-12-17 18:57:34 +00002/*
3 * Mini insmod implementation for busybox
Eric Andersen2835efe2001-07-25 16:58:58 +00004 *
Denis Vlasenkoba1315d2008-09-13 14:59:38 +00005 * Copyright (C) 2008 Timo Teras <timo.teras@iki.fi>
Erik Andersen02104321999-12-17 18:57:34 +00006 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02007 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Erik Andersen02104321999-12-17 18:57:34 +00008 */
Denys Vlasenkoe32b64c2016-11-23 07:54:52 +01009//config:config INSMOD
Denys Vlasenko4eed2c62017-07-18 22:01:24 +020010//config: bool "insmod (22 kb)"
Denys Vlasenko3bf4d692016-12-23 15:22:44 +010011//config: default y
Denys Vlasenkoe32b64c2016-11-23 07:54:52 +010012//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020013//config: insmod is used to load specified modules in the running kernel.
Erik Andersen02104321999-12-17 18:57:34 +000014
Denys Vlasenko3346b4a2017-08-04 02:56:39 +020015//applet:IF_INSMOD(IF_NOT_MODPROBE_SMALL(APPLET_NOEXEC(insmod, insmod, BB_DIR_SBIN, BB_SUID_DROP, insmod)))
Denys Vlasenkoc15613c2010-10-15 11:29:02 +020016
Denys Vlasenkoa1cd0d92016-12-23 15:12:27 +010017//kbuild:ifneq ($(CONFIG_MODPROBE_SMALL),y)
Denys Vlasenkoe32b64c2016-11-23 07:54:52 +010018//kbuild:lib-$(CONFIG_INSMOD) += insmod.o modutils.o
Denys Vlasenkoa1cd0d92016-12-23 15:12:27 +010019//kbuild:endif
Denys Vlasenkoe32b64c2016-11-23 07:54:52 +010020
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000021#include "libbb.h"
Denis Vlasenkoba1315d2008-09-13 14:59:38 +000022#include "modutils.h"
Eric Andersene7047882003-12-11 01:42:13 +000023
Pascal Bellardb82b34e2010-06-07 01:16:45 +020024/* 2.6 style insmod has no options and required filename
25 * (not module name - .ko can't be omitted) */
26
Denys Vlasenko1a5e11c2010-10-16 01:56:41 +020027//usage:#if !ENABLE_MODPROBE_SMALL
Pascal Bellardb82b34e2010-06-07 01:16:45 +020028//usage:#define insmod_trivial_usage
Denys Vlasenko84d5edd2020-12-13 22:34:05 +010029//usage: IF_FEATURE_2_4_MODULES("[-fkvqLx] MODULE")
Kang-Che Sungb1d6a2c2017-01-31 21:09:17 +080030//usage: IF_NOT_FEATURE_2_4_MODULES("FILE")
31//usage: IF_FEATURE_CMDLINE_MODULE_OPTIONS(" [SYMBOL=VALUE]...")
Pascal Bellardb82b34e2010-06-07 01:16:45 +020032//usage:#define insmod_full_usage "\n\n"
Denys Vlasenko5fd3ddf2014-04-19 15:04:39 +020033//usage: "Load kernel module"
Pascal Bellardb82b34e2010-06-07 01:16:45 +020034//usage: IF_FEATURE_2_4_MODULES( "\n"
Pascal Bellardb82b34e2010-06-07 01:16:45 +020035//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 Vlasenko1a5e11c2010-10-16 01:56:41 +020045//usage:#endif
Pascal Bellardb82b34e2010-06-07 01:16:45 +020046
Denis Vlasenkob68979a2007-11-02 23:31:10 +000047int insmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000048int insmod_main(int argc UNUSED_PARAM, char **argv)
Eric Andersene7047882003-12-11 01:42:13 +000049{
Denis Vlasenkoba1315d2008-09-13 14:59:38 +000050 char *filename;
51 int rc;
52
Denis Vlasenko36309cf2008-11-22 18:29:01 +000053 /* Compat note:
54 * 2.6 style insmod has no options and required filename
55 * (not module name - .ko can't be omitted).
Bernhard Reutner-Fischer9a280fa2008-11-22 20:30:53 +000056 * 2.4 style insmod can take module name without .o
Denis Vlasenko36309cf2008-11-22 18:29:01 +000057 * and performs module search in default directories
58 * or in $MODPATH.
59 */
60
Denis Vlasenko5e34ff22009-04-21 11:09:40 +000061 IF_FEATURE_2_4_MODULES(
Denis Vlasenkoba1315d2008-09-13 14:59:38 +000062 getopt32(argv, INSMOD_OPTS INSMOD_ARGS);
Denis Vlasenko36309cf2008-11-22 18:29:01 +000063 argv += optind - 1;
Denis Vlasenkoba1315d2008-09-13 14:59:38 +000064 );
Eric Andersen3b1a7442003-12-24 20:30:45 +000065
Denis Vlasenko92297942006-11-21 11:58:14 +000066 filename = *++argv;
67 if (!filename)
Eric Andersene7047882003-12-11 01:42:13 +000068 bb_show_usage();
Eric Andersene7047882003-12-11 01:42:13 +000069
Denys Vlasenkoc5830bd2011-02-02 00:00:36 +010070 rc = bb_init_module(filename, parse_cmdline_module_options(argv, /*quote_spaces:*/ 0));
Denis Vlasenkoba1315d2008-09-13 14:59:38 +000071 if (rc)
Denis Vlasenko1f632292009-04-13 02:25:40 +000072 bb_error_msg("can't insert '%s': %s", filename, moderror(rc));
Eric Andersene7047882003-12-11 01:42:13 +000073
Denis Vlasenkoba1315d2008-09-13 14:59:38 +000074 return rc;
Eric Andersene7047882003-12-11 01:42:13 +000075}