2 * kmod-insert - insert a module into the kernel.
4 * Copyright (C) 2015 Intel Corporation. All rights reserved.
5 * Copyright (C) 2011-2013 ProFUSION embedded systems
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include <libkmod/libkmod.h>
30 static const char cmdopts_s[] = "h";
31 static const struct option cmdopts[] = {
32 {"help", no_argument, 0, 'h'},
36 static void help(void)
39 "\t%s insert [options] module\n"
41 "\t-h, --help show this help\n",
42 program_invocation_short_name);
45 static const char *mod_strerror(int err)
48 case KMOD_PROBE_APPLY_BLACKLIST:
49 return "Module is blacklisted";
51 return "Module already in kernel";
53 return "Unknown symbol in module or unknown parameter (see dmesg)";
55 return strerror(-err);
59 static int do_insert(int argc, char *argv[])
62 struct kmod_list *list = NULL, *l;
64 int err, r = EXIT_SUCCESS;
68 c = getopt_long(argc, argv, cmdopts_s, cmdopts, &idx);
76 ERR("Unexpected getopt_long() value '%c'.\n", c);
82 ERR("Missing module name\n");
86 ctx = kmod_new(NULL, NULL);
88 ERR("kmod_new() failed!\n");
93 err = kmod_module_new_from_lookup(ctx, name, &list);
95 ERR("Could not lookup module matching '%s': %s\n", name, strerror(-err));
101 ERR("No module matches '%s'\n", name);
106 kmod_list_foreach(l, list) {
107 struct kmod_module *mod = kmod_module_get_module(l);
109 err = kmod_module_probe_insert_module(mod, KMOD_PROBE_APPLY_BLACKLIST, NULL, NULL, NULL, NULL);
112 ERR("Could not insert '%s': %s\n", kmod_module_get_name(mod), mod_strerror(err));
115 kmod_module_unref(mod);
118 kmod_module_unref_list(list);
124 const struct kmod_cmd kmod_cmd_insert = {
127 .help = "insert a module into the kernel",