*: make GNU licensing statement forms more regular
[platform/upstream/busybox.git] / modutils / insmod.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * Mini insmod implementation for busybox
4  *
5  * Copyright (C) 2008 Timo Teras <timo.teras@iki.fi>
6  *
7  * Licensed under GPLv2 or later, see file LICENSE in this source tree.
8  */
9
10 #include "libbb.h"
11 #include "modutils.h"
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
35 int insmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
36 int insmod_main(int argc UNUSED_PARAM, char **argv)
37 {
38         char *filename;
39         int rc;
40
41         /* Compat note:
42          * 2.6 style insmod has no options and required filename
43          * (not module name - .ko can't be omitted).
44          * 2.4 style insmod can take module name without .o
45          * and performs module search in default directories
46          * or in $MODPATH.
47          */
48
49         IF_FEATURE_2_4_MODULES(
50                 getopt32(argv, INSMOD_OPTS INSMOD_ARGS);
51                 argv += optind - 1;
52         );
53
54         filename = *++argv;
55         if (!filename)
56                 bb_show_usage();
57
58         rc = bb_init_module(filename, parse_cmdline_module_options(argv));
59         if (rc)
60                 bb_error_msg("can't insert '%s': %s", filename, moderror(rc));
61
62         return rc;
63 }