blob: 9a0daa73b21d7638109c1ace7688c8a60b615588 [file] [log] [blame]
Erik Andersen02104321999-12-17 18:57:34 +00001/*
2 * Mini insmod implementation for busybox
3 *
4 * Copyright (C) 1999 by Lineo, inc.
5 * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
6 *
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.
11 *
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 GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22
23#include "internal.h"
24#include <stdlib.h>
25#include <stdio.h>
26#include <errno.h>
27#include <unistd.h>
28#include <dirent.h>
29#include <sys/syscall.h>
30#include <linux/module.h>
31
32/* Some firendly syscalls to cheer everyone's day... */
33_syscall2(int, init_module, const char *, name,
34 const struct module *, info)
35
36#ifndef BB_RMMOD
37_syscall1(int, delete_module, const char *, name)
38#else
39extern int delete_module(const char *);
40#endif
41
42#if defined(__i386__) || defined(__m68k__) || defined(__arm__)
43/* Jump through hoops to fixup error return codes */
44#define __NR__create_module __NR_create_module
45static inline _syscall2(long, _create_module, const char *, name, size_t, size)
46unsigned long create_module(const char *name, size_t size)
47{
48 long ret = _create_module(name, size);
49 if (ret == -1 && errno > 125) {
50 ret = -errno;
51 errno = 0;
52 }
53 return ret;
54}
55#else
56_syscall2(unsigned long, create_module, const char *, name, size_t, size)
57#endif
58
59
60static const char insmod_usage[] =
61 "insmod [OPTION]... MODULE [symbol=value]...\n\n"
62 "Loads the specified kernel modules into the kernel.\n\n"
63 "Options:\n"
64 "\t-f\tForce module to load into the wrong kernel version.\n"
65 "\t-k\tMake module autoclean-able.\n";
66
67
68
69extern int insmod_main(int argc, char **argv)
70{
71 int len;
72 char m_name[PATH_MAX];
73 char* tmp;
74
75
76
77 if (argc<=1) {
78 usage( insmod_usage);
79 }
80
81 /* Parse any options */
82 while (--argc > 0 && **(++argv) == '-') {
83 while (*(++(*argv))) {
84 switch (**argv) {
85 case 'f':
86 break;
87 case 'k':
88 break;
89 default:
90 usage(insmod_usage);
91 }
92 }
93 }
94
95 if (argc <= 0 )
96 usage(insmod_usage);
97
98 /* Grab the module name */
99 if ((tmp = strrchr(*argv, '/')) != NULL)
100 tmp++;
101 else
102 tmp = *argv;
103 len = strlen(tmp);
104
105 if (len > 2 && tmp[len - 2] == '.' && tmp[len - 1] == 'o')
106 len -= 2;
107 memcpy(m_name, tmp, len);
108
109 fprintf(stderr, "m_name='%s'\n", m_name);
110
111
112 exit( TRUE);
113}