blob: 94e4e28632f294bd5e2cadc22b5dbec144653faa [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 */
9
Denys Vlasenkob9f2d9f2011-01-18 13:58:01 +010010//applet:IF_INSMOD(APPLET(insmod, BB_DIR_SBIN, BB_SUID_DROP))
Denys Vlasenkoc15613c2010-10-15 11:29:02 +020011
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000012#include "libbb.h"
Denis Vlasenkoba1315d2008-09-13 14:59:38 +000013#include "modutils.h"
Eric Andersene7047882003-12-11 01:42:13 +000014
Pascal Bellardb82b34e2010-06-07 01:16:45 +020015/* 2.6 style insmod has no options and required filename
16 * (not module name - .ko can't be omitted) */
17
Denys Vlasenko1a5e11c2010-10-16 01:56:41 +020018//usage:#if !ENABLE_MODPROBE_SMALL
Pascal Bellardb82b34e2010-06-07 01:16:45 +020019//usage:#define insmod_trivial_usage
20//usage: IF_FEATURE_2_4_MODULES("[OPTIONS] MODULE ")
21//usage: IF_NOT_FEATURE_2_4_MODULES("FILE ")
Denys Vlasenko3b2acb72010-10-09 21:10:32 +020022//usage: "[SYMBOL=VALUE]..."
Pascal Bellardb82b34e2010-06-07 01:16:45 +020023//usage:#define insmod_full_usage "\n\n"
24//usage: "Load the specified kernel modules into the kernel"
25//usage: IF_FEATURE_2_4_MODULES( "\n"
26//usage: "\nOptions:"
27//usage: "\n -f Force module to load into the wrong kernel version"
28//usage: "\n -k Make module autoclean-able"
29//usage: "\n -v Verbose"
30//usage: "\n -q Quiet"
31//usage: "\n -L Lock: prevent simultaneous loads"
32//usage: IF_FEATURE_INSMOD_LOAD_MAP(
33//usage: "\n -m Output load map to stdout"
34//usage: )
35//usage: "\n -x Don't export externs"
36//usage: )
Denys Vlasenko1a5e11c2010-10-16 01:56:41 +020037//usage:#endif
Pascal Bellardb82b34e2010-06-07 01:16:45 +020038
Denis Vlasenkob68979a2007-11-02 23:31:10 +000039int insmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000040int insmod_main(int argc UNUSED_PARAM, char **argv)
Eric Andersene7047882003-12-11 01:42:13 +000041{
Denis Vlasenkoba1315d2008-09-13 14:59:38 +000042 char *filename;
43 int rc;
44
Denis Vlasenko36309cf2008-11-22 18:29:01 +000045 /* Compat note:
46 * 2.6 style insmod has no options and required filename
47 * (not module name - .ko can't be omitted).
Bernhard Reutner-Fischer9a280fa2008-11-22 20:30:53 +000048 * 2.4 style insmod can take module name without .o
Denis Vlasenko36309cf2008-11-22 18:29:01 +000049 * and performs module search in default directories
50 * or in $MODPATH.
51 */
52
Denis Vlasenko5e34ff22009-04-21 11:09:40 +000053 IF_FEATURE_2_4_MODULES(
Denis Vlasenkoba1315d2008-09-13 14:59:38 +000054 getopt32(argv, INSMOD_OPTS INSMOD_ARGS);
Denis Vlasenko36309cf2008-11-22 18:29:01 +000055 argv += optind - 1;
Denis Vlasenkoba1315d2008-09-13 14:59:38 +000056 );
Eric Andersen3b1a7442003-12-24 20:30:45 +000057
Denis Vlasenko92297942006-11-21 11:58:14 +000058 filename = *++argv;
59 if (!filename)
Eric Andersene7047882003-12-11 01:42:13 +000060 bb_show_usage();
Eric Andersene7047882003-12-11 01:42:13 +000061
Denys Vlasenkoc5830bd2011-02-02 00:00:36 +010062 rc = bb_init_module(filename, parse_cmdline_module_options(argv, /*quote_spaces:*/ 0));
Denis Vlasenkoba1315d2008-09-13 14:59:38 +000063 if (rc)
Denis Vlasenko1f632292009-04-13 02:25:40 +000064 bb_error_msg("can't insert '%s': %s", filename, moderror(rc));
Eric Andersene7047882003-12-11 01:42:13 +000065
Denis Vlasenkoba1315d2008-09-13 14:59:38 +000066 return rc;
Eric Andersene7047882003-12-11 01:42:13 +000067}