wok view busybox/stuff/busybox-1.12.0-zmodules.u @ rev 1299

Up busybox (1.12.0) with built in module-init-tools
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Aug 21 20:11:27 2008 +0000 (2008-08-21)
parents
children ce72aad145d4
line source
1 --- busybox-1.12.0/modutils/depmod.c
2 +++ busybox-1.12.0/modutils/depmod.c
3 @@ -53,27 +53,14 @@ static int FAST_FUNC fileAction(const ch
4 size_t len = sb->st_size;
5 void *the_module;
6 char *ptr;
7 - int fd;
8 char *depends, *deps;
9 dep_lst_t *this;
10 + extern void *xalloc_load_module(const char filename[], size_t *len);
12 if (strrstr(fname, ".ko") == NULL) /* not a module */
13 goto skip;
15 -/*XXX: FIXME: does not handle compressed modules!
16 - * There should be a function that looks at the extension and sets up
17 - * open_transformer for us.
18 - */
19 - fd = xopen(fname, O_RDONLY);
20 - the_module = mmap(NULL, len, PROT_READ, MAP_SHARED
21 -#if defined MAP_POPULATE
22 - |MAP_POPULATE
23 -#endif
24 - , fd, 0);
25 - close(fd);
26 - if (the_module == MAP_FAILED)
27 - bb_perror_msg_and_die("mmap");
28 -
29 + the_module = xalloc_load_module(fname, &len);
30 this = xzalloc(sizeof(dep_lst_t));
31 this->name = xstrdup(fname);
32 this->next = G.lst;
33 @@ -104,7 +91,7 @@ static int FAST_FUNC fileAction(const ch
34 pos = (ptr - (char*)the_module);
35 } while (1);
36 }
37 - munmap(the_module, sb->st_size);
38 + free(the_module);
39 skip:
40 return TRUE;
41 }
43 --- busybox-1.12.0/modutils/insmod.c
44 +++ busybox-1.12.0/modutils/insmod.c
45 @@ -59,6 +59,7 @@
46 */
48 #include "libbb.h"
49 +#include "unarchive.h"
50 #include <libgen.h>
51 #include <sys/utsname.h>
53 @@ -4212,6 +4213,45 @@ static const char *moderror(int err)
54 }
55 }
57 +void *xalloc_load_module(const char filename[], size_t *len);
58 +void *xalloc_load_module(const char filename[], size_t *len)
59 +{
60 + int fd, max;
61 + unsigned char head[16];
62 + void *map;
63 + size_t l;
64 +
65 + max = 8 * 1024;
66 + fd = open(filename, O_RDONLY);
67 + if (fd < 0) return NULL;
68 + xread(fd,head,sizeof(head));
69 + lseek(fd,0L,SEEK_SET);
70 + if (head[0] == 0x1f && head[1] == 0x8b) { /* gzip */
71 + open_transformer(fd, unpack_gz_stream, "gunzip");
72 + }
73 + else if (head[0] == 'B' && head[1] == 'Z' &&
74 + head[2] == 'h' && isdigit(head[3])) { /* bzip2 */
75 + open_transformer(fd, unpack_bz2_stream, "bunzip2");
76 + }
77 + else if (head[1] != 'E' || head[2] != 'L' || head[3] != 'F') {
78 + open_transformer(fd, unpack_lzma_stream, "unlzma");
79 + if (* (unsigned *) (head + 9) == 0)
80 + max = 1 + head[5] + (head[6]<<8)
81 + + (head[7]<<16) + (head[8]<<24);
82 + }
83 + l = 0;
84 + map = xmalloc(max);
85 + while (1) {
86 + l += full_read(fd, l + (char *) map, max - l);
87 + if (l != max) break;
88 + max <<= 1;
89 + map = xrealloc(map, max);
90 + }
91 + if (len)
92 + *len = l;
93 + return xrealloc(map, l);
94 +}
95 +
96 #if !ENABLE_FEATURE_2_4_MODULES
97 int insmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
98 int insmod_main(int argc UNUSED_PARAM, char **argv)
99 @@ -4264,8 +4304,7 @@ static int insmod_ng_main(int argc UNUSE
100 xread(fd, map, len);
101 }
102 #else
103 - len = MAXINT(ssize_t);
104 - map = xmalloc_open_read_close(filename, &len);
105 + map = xalloc_load_module(filename, &len);
106 #endif
108 if (init_module(map, len, options) != 0)
110 --- busybox-1.12.0/modutils/modprobe.c
111 +++ busybox-1.12.0/modutils/modprobe.c
112 @@ -396,6 +396,29 @@ static int include_conf_file2(struct inc
113 return include_conf_file(conf, oldname);
114 }
116 +static int ext_size(char *end USE_FEATURE_2_6_MODULES(, int k_version))
117 +{
118 + int ext;
119 + char *next;
120 +
121 + ext = 0;
122 + if (end[-2] == '.' && end[-1] == 'g' && end[0] == 'z')
123 + ext = 3;
124 + if (end[-3] == '.' && end[-2] == 'b' && end[-1] == 'z' && end[0] == '2')
125 + ext = 4;
126 + next = end - ext;
127 +#if ENABLE_FEATURE_2_6_MODULES
128 + if (ENABLE_FEATURE_2_6_MODULES
129 + && (k_version > 4) && (next[-2] == '.')
130 + && (next[-1] == 'k') && (next[0] == 'o'))
131 + ext += 3;
132 + else
133 +#endif
134 + if ((next[-1] == '.') && (next[0] == 'o'))
135 + ext += 2;
136 + return ext;
137 +}
138 +
139 /*
140 * This function builds a list of dependency rules from /lib/modules/`uname -r`/modules.dep.
141 * It then fills every modules and aliases with their default options, found by parsing
142 @@ -464,12 +487,7 @@ static struct dep_t *build_dep(void)
143 if (!modpath)
144 modpath = line_buffer; /* module with no path */
145 /* find the end of the module name in the file name */
146 - if (ENABLE_FEATURE_2_6_MODULES &&
147 - (k_version > 4) && (col[-3] == '.') &&
148 - (col[-2] == 'k') && (col[-1] == 'o'))
149 - dot = col - 3;
150 - else if ((col[-2] == '.') && (col[-1] == 'o'))
151 - dot = col - 2;
152 + dot = col - ext_size(col - 1 USE_FEATURE_2_6_MODULES(, k_version));
154 mod = xstrndup(mods, dot - mods);
156 @@ -522,12 +540,7 @@ static struct dep_t *build_dep(void)
157 deps = skip_whitespace(deps);
159 /* find the end of the module name in the file name */
160 - if (ENABLE_FEATURE_2_6_MODULES
161 - && (k_version > 4) && (next[-2] == '.')
162 - && (next[-1] == 'k') && (next[0] == 'o'))
163 - ext = 3;
164 - else if ((next[-1] == '.') && (next[0] == 'o'))
165 - ext = 2;
166 + ext = ext_size(next USE_FEATURE_2_6_MODULES(, k_version));
168 /* Cope with blank lines */
169 if ((next - deps - ext + 1) <= 0)