summaryrefslogtreecommitdiff
path: root/modutils
diff options
context:
space:
mode:
authorErik Andersen <andersen@codepoet.org>1999-12-21 02:55:11 +0000
committerErik Andersen <andersen@codepoet.org>1999-12-21 02:55:11 +0000
commitd387d01f11c3b9438322c951cd1eac8f29ea6afc (patch)
treeed81f0f41ce4af3de74c5025180ca158f93f5809 /modutils
parentf294a0288d5f90616c5a096c2236442394112daa (diff)
downloadbusybox-w32-d387d01f11c3b9438322c951cd1eac8f29ea6afc.tar.gz
busybox-w32-d387d01f11c3b9438322c951cd1eac8f29ea6afc.tar.bz2
busybox-w32-d387d01f11c3b9438322c951cd1eac8f29ea6afc.zip
Sync to my local tree
Diffstat (limited to 'modutils')
-rw-r--r--modutils/insmod.c101
1 files changed, 97 insertions, 4 deletions
diff --git a/modutils/insmod.c b/modutils/insmod.c
index 9a0daa73b..9cb635f40 100644
--- a/modutils/insmod.c
+++ b/modutils/insmod.c
@@ -29,6 +29,16 @@
29#include <sys/syscall.h> 29#include <sys/syscall.h>
30#include <linux/module.h> 30#include <linux/module.h>
31 31
32#define _PATH_MODULES "/lib/modules"
33
34#warning "Danger Will Robinson, Danger!!!"
35#warning " "
36#warning "insmod is still under construction. Don't use it."
37#warning " "
38#warning " You have been warned!"
39#warning " "
40
41
32/* Some firendly syscalls to cheer everyone's day... */ 42/* Some firendly syscalls to cheer everyone's day... */
33_syscall2(int, init_module, const char *, name, 43_syscall2(int, init_module, const char *, name,
34 const struct module *, info) 44 const struct module *, info)
@@ -57,6 +67,8 @@ _syscall2(unsigned long, create_module, const char *, name, size_t, size)
57#endif 67#endif
58 68
59 69
70static char m_filename[PATH_MAX] = "\0";
71static char m_fullName[PATH_MAX] ="\0";
60static const char insmod_usage[] = 72static const char insmod_usage[] =
61 "insmod [OPTION]... MODULE [symbol=value]...\n\n" 73 "insmod [OPTION]... MODULE [symbol=value]...\n\n"
62 "Loads the specified kernel modules into the kernel.\n\n" 74 "Loads the specified kernel modules into the kernel.\n\n"
@@ -65,14 +77,32 @@ static const char insmod_usage[] =
65 "\t-k\tMake module autoclean-able.\n"; 77 "\t-k\tMake module autoclean-able.\n";
66 78
67 79
80static int findNamedModule(const char *fileName, struct stat* statbuf)
81{
82 if (m_fullName[0]=='\0')
83 return( FALSE);
84 else {
85 char* tmp = strrchr( fileName, '/');
86 if (tmp == NULL)
87 tmp = (char*)fileName;
88 else
89 tmp++;
90 if (check_wildcard_match(tmp, m_fullName) == TRUE) {
91 /* Stop searching if we find a match */
92 memcpy(m_filename, fileName, strlen(fileName));
93 return( FALSE);
94 }
95 }
96 return( TRUE);
97}
98
68 99
69extern int insmod_main(int argc, char **argv) 100extern int insmod_main(int argc, char **argv)
70{ 101{
71 int len; 102 int len;
72 char m_name[PATH_MAX]; 103 char *tmp;
73 char* tmp; 104 char m_name[PATH_MAX] ="\0";
74 105 FILE *fp;
75
76 106
77 if (argc<=1) { 107 if (argc<=1) {
78 usage( insmod_usage); 108 usage( insmod_usage);
@@ -105,9 +135,72 @@ extern int insmod_main(int argc, char **argv)
105 if (len > 2 && tmp[len - 2] == '.' && tmp[len - 1] == 'o') 135 if (len > 2 && tmp[len - 2] == '.' && tmp[len - 1] == 'o')
106 len -= 2; 136 len -= 2;
107 memcpy(m_name, tmp, len); 137 memcpy(m_name, tmp, len);
138 strcpy(m_fullName, m_name);
139 strcat(m_fullName, ".o");
140
141 /* Get a filedesc for the module */
142 if ((fp = fopen(*argv, "r")) == NULL) {
143 /* Hmpf. Could not open it. Search through _PATH_MODULES to find a module named m_name */
144 if (recursiveAction(_PATH_MODULES, TRUE, FALSE, FALSE,
145 findNamedModule, findNamedModule) == FALSE) {
146 if ( m_filename[0] == '\0' || ((fp = fopen(m_filename, "r")) == NULL)) {
147 perror("No module by that name found in " _PATH_MODULES "\n");
148 exit( FALSE);
149 }
150 }
151 } else
152 memcpy(m_filename, *argv, strlen(*argv));
108 153
154
155 fprintf(stderr, "m_filename='%s'\n", m_filename);
109 fprintf(stderr, "m_name='%s'\n", m_name); 156 fprintf(stderr, "m_name='%s'\n", m_name);
110 157
158
159 /* TODO: do something roughtly like this... */
160#if 0
161
162 if ((f = obj_load(fp)) == NULL) {
163 perror("Could not load the module\n");
164 exit( FALSE);
165 }
111 166
167 /* Let the module know about the kernel symbols. */
168 add_kernel_symbols(f);
169
170 if (!create_this_module(f, m_name)) {
171 perror("Could not create the module\n");
172 exit( FALSE);
173 }
174
175 if (!obj_check_undefineds(f, quiet)) {
176 perror("Undefined symbols in the module\n");
177 exit( FALSE);
178 }
179 obj_allocate_commons(f);
180
181 /* Perse the module's arguments */
182 while (argc-- >0 && *(argv++) != '\0') {
183 if (!process_module_arguments(f, argc - optind, argv + optind)) {
184 perror("Undefined symbols in the module\n");
185 exit( FALSE);
186 }
187 }
188
189 /* Find current size of the module */
190 m_size = obj_load_size(f);
191
192
193 errno = 0;
194 m_addr = create_module(m_name, m_size);
195 switch (errno) {
196 /* yada yada */
197 default:
198 perror("create_module: %m");
199
200 }
201
202#endif
203
204 fclose( fp);
112 exit( TRUE); 205 exit( TRUE);
113} 206}