aboutsummaryrefslogtreecommitdiff
path: root/modutils/depmod.c
diff options
context:
space:
mode:
Diffstat (limited to 'modutils/depmod.c')
-rw-r--r--modutils/depmod.c86
1 files changed, 25 insertions, 61 deletions
diff --git a/modutils/depmod.c b/modutils/depmod.c
index 9713aef92..e5f0e3d2b 100644
--- a/modutils/depmod.c
+++ b/modutils/depmod.c
@@ -21,21 +21,13 @@
21 * for each depends, look through our list of full paths and emit if found 21 * for each depends, look through our list of full paths and emit if found
22 */ 22 */
23 23
24typedef struct module_info {
25 struct module_info *next;
26 char *name, *modname;
27 llist_t *dependencies;
28 llist_t *aliases;
29 llist_t *symbols;
30 struct module_info *dnext, *dprev;
31} module_info;
32
33static int FAST_FUNC parse_module(const char *fname, struct stat *sb UNUSED_PARAM, 24static int FAST_FUNC parse_module(const char *fname, struct stat *sb UNUSED_PARAM,
34 void *data, int depth UNUSED_PARAM) 25 void *data, int depth UNUSED_PARAM)
35{ 26{
36 module_info **first = (module_info **) data; 27 module_db *modules = data;
37 char *image, *ptr; 28 char *image, *ptr;
38 module_info *info; 29 module_entry *e;
30
39 /* Arbitrary. Was sb->st_size, but that breaks .gz etc */ 31 /* Arbitrary. Was sb->st_size, but that breaks .gz etc */
40 size_t len = (64*1024*1024 - 4096); 32 size_t len = (64*1024*1024 - 4096);
41 33
@@ -43,17 +35,10 @@ static int FAST_FUNC parse_module(const char *fname, struct stat *sb UNUSED_PARA
43 return TRUE; 35 return TRUE;
44 36
45 image = xmalloc_open_zipped_read_close(fname, &len); 37 image = xmalloc_open_zipped_read_close(fname, &len);
46 info = xzalloc(sizeof(*info));
47 38
48 info->next = *first; 39 e = moddb_get_or_create(modules, bb_get_last_path_component_nostrip(fname));
49 *first = info; 40 e->name = xstrdup(fname + 2); /* skip "./" */
50 41
51 info->dnext = info->dprev = info;
52 info->name = xstrdup(fname + 2); /* skip "./" */
53 info->modname = filename2modname(
54 bb_get_last_path_component_nostrip(fname),
55 NULL
56 );
57 for (ptr = image; ptr < image + len - 10; ptr++) { 42 for (ptr = image; ptr < image + len - 10; ptr++) {
58 if (is_prefixed_with(ptr, "depends=")) { 43 if (is_prefixed_with(ptr, "depends=")) {
59 char *u; 44 char *u;
@@ -62,11 +47,11 @@ static int FAST_FUNC parse_module(const char *fname, struct stat *sb UNUSED_PARA
62 for (u = ptr; *u; u++) 47 for (u = ptr; *u; u++)
63 if (*u == '-') 48 if (*u == '-')
64 *u = '_'; 49 *u = '_';
65 ptr += string_to_llist(ptr, &info->dependencies, ","); 50 ptr += string_to_llist(ptr, &e->deps, ",");
66 } else if (ENABLE_FEATURE_MODUTILS_ALIAS 51 } else if (ENABLE_FEATURE_MODUTILS_ALIAS
67 && is_prefixed_with(ptr, "alias=") 52 && is_prefixed_with(ptr, "alias=")
68 ) { 53 ) {
69 llist_add_to(&info->aliases, xstrdup(ptr + 6)); 54 llist_add_to(&e->aliases, xstrdup(ptr + 6));
70 ptr += strlen(ptr); 55 ptr += strlen(ptr);
71 } else if (ENABLE_FEATURE_MODUTILS_SYMBOLS 56 } else if (ENABLE_FEATURE_MODUTILS_SYMBOLS
72 && is_prefixed_with(ptr, "__ksymtab_") 57 && is_prefixed_with(ptr, "__ksymtab_")
@@ -77,7 +62,7 @@ static int FAST_FUNC parse_module(const char *fname, struct stat *sb UNUSED_PARA
77 ) { 62 ) {
78 continue; 63 continue;
79 } 64 }
80 llist_add_to(&info->symbols, xstrdup(ptr)); 65 llist_add_to(&e->symbols, xstrdup(ptr));
81 ptr += strlen(ptr); 66 ptr += strlen(ptr);
82 } 67 }
83 } 68 }
@@ -86,24 +71,13 @@ static int FAST_FUNC parse_module(const char *fname, struct stat *sb UNUSED_PARA
86 return TRUE; 71 return TRUE;
87} 72}
88 73
89static module_info *find_module(module_info *modules, const char *modname) 74static void order_dep_list(module_db *modules, module_entry *start, llist_t *add)
90{
91 module_info *m;
92
93 for (m = modules; m != NULL; m = m->next)
94 if (strcmp(m->modname, modname) == 0)
95 return m;
96 return NULL;
97}
98
99static void order_dep_list(module_info *modules, module_info *start,
100 llist_t *add)
101{ 75{
102 module_info *m; 76 module_entry *m;
103 llist_t *n; 77 llist_t *n;
104 78
105 for (n = add; n != NULL; n = n->link) { 79 for (n = add; n != NULL; n = n->link) {
106 m = find_module(modules, n->data); 80 m = moddb_get(modules, n->data);
107 if (m == NULL) 81 if (m == NULL)
108 continue; 82 continue;
109 83
@@ -118,7 +92,7 @@ static void order_dep_list(module_info *modules, module_info *start,
118 start->dprev = m; 92 start->dprev = m;
119 93
120 /* recurse */ 94 /* recurse */
121 order_dep_list(modules, start, m->dependencies); 95 order_dep_list(modules, start, m->deps);
122 } 96 }
123} 97}
124 98
@@ -184,10 +158,12 @@ enum {
184int depmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 158int depmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
185int depmod_main(int argc UNUSED_PARAM, char **argv) 159int depmod_main(int argc UNUSED_PARAM, char **argv)
186{ 160{
187 module_info *modules, *m, *dep; 161 module_db modules;
162 module_entry *m, *dep;
188 const char *moddir_base = "/"; 163 const char *moddir_base = "/";
189 char *moddir, *version; 164 char *moddir, *version;
190 struct utsname uts; 165 struct utsname uts;
166 unsigned i;
191 int tmp; 167 int tmp;
192 168
193 getopt32(argv, "aAb:eF:nruqC:", &moddir_base, NULL, NULL); 169 getopt32(argv, "aAb:eF:nruqC:", &moddir_base, NULL, NULL);
@@ -211,7 +187,7 @@ int depmod_main(int argc UNUSED_PARAM, char **argv)
211 free(moddir); 187 free(moddir);
212 188
213 /* Scan modules */ 189 /* Scan modules */
214 modules = NULL; 190 memset(&modules, 0, sizeof(modules));
215 if (*argv) { 191 if (*argv) {
216 do { 192 do {
217 parse_module(*argv, /*sb (unused):*/ NULL, &modules, 0); 193 parse_module(*argv, /*sb (unused):*/ NULL, &modules, 0);
@@ -224,10 +200,11 @@ int depmod_main(int argc UNUSED_PARAM, char **argv)
224 /* Generate dependency and alias files */ 200 /* Generate dependency and alias files */
225 if (!(option_mask32 & OPT_n)) 201 if (!(option_mask32 & OPT_n))
226 xfreopen_write(CONFIG_DEFAULT_DEPMOD_FILE, stdout); 202 xfreopen_write(CONFIG_DEFAULT_DEPMOD_FILE, stdout);
227 for (m = modules; m != NULL; m = m->next) { 203
204 moddb_foreach_module(&modules, m, i) {
228 printf("%s:", m->name); 205 printf("%s:", m->name);
229 206
230 order_dep_list(modules, m, m->dependencies); 207 order_dep_list(&modules, m, m->deps);
231 while (m->dnext != m) { 208 while (m->dnext != m) {
232 dep = m->dnext; 209 dep = m->dnext;
233 printf(" %s", dep->name); 210 printf(" %s", dep->name);
@@ -243,10 +220,7 @@ int depmod_main(int argc UNUSED_PARAM, char **argv)
243#if ENABLE_FEATURE_MODUTILS_ALIAS 220#if ENABLE_FEATURE_MODUTILS_ALIAS
244 if (!(option_mask32 & OPT_n)) 221 if (!(option_mask32 & OPT_n))
245 xfreopen_write("modules.alias", stdout); 222 xfreopen_write("modules.alias", stdout);
246 for (m = modules; m != NULL; m = m->next) { 223 moddb_foreach_module(&modules, m, i) {
247 char modname[MODULE_NAME_LEN];
248 const char *fname = bb_basename(m->name);
249 filename2modname(fname, modname);
250 while (m->aliases) { 224 while (m->aliases) {
251 /* 225 /*
252 * Last word used to be a basename 226 * Last word used to be a basename
@@ -256,34 +230,24 @@ int depmod_main(int argc UNUSED_PARAM, char **argv)
256 */ 230 */
257 printf("alias %s %s\n", 231 printf("alias %s %s\n",
258 (char*)llist_pop(&m->aliases), 232 (char*)llist_pop(&m->aliases),
259 modname); 233 m->modname);
260 } 234 }
261 } 235 }
262#endif 236#endif
263#if ENABLE_FEATURE_MODUTILS_SYMBOLS 237#if ENABLE_FEATURE_MODUTILS_SYMBOLS
264 if (!(option_mask32 & OPT_n)) 238 if (!(option_mask32 & OPT_n))
265 xfreopen_write("modules.symbols", stdout); 239 xfreopen_write("modules.symbols", stdout);
266 for (m = modules; m != NULL; m = m->next) { 240 moddb_foreach_module(&modules, m, i) {
267 char modname[MODULE_NAME_LEN];
268 const char *fname = bb_basename(m->name);
269 filename2modname(fname, modname);
270 while (m->symbols) { 241 while (m->symbols) {
271 printf("alias symbol:%s %s\n", 242 printf("alias symbol:%s %s\n",
272 (char*)llist_pop(&m->symbols), 243 (char*)llist_pop(&m->symbols),
273 modname); 244 m->modname);
274 } 245 }
275 } 246 }
276#endif 247#endif
277 248
278 if (ENABLE_FEATURE_CLEAN_UP) { 249 if (ENABLE_FEATURE_CLEAN_UP)
279 while (modules) { 250 moddb_free(&modules);
280 module_info *old = modules;
281 modules = modules->next;
282 free(old->name);
283 free(old->modname);
284 free(old);
285 }
286 }
287 251
288 return EXIT_SUCCESS; 252 return EXIT_SUCCESS;
289} 253}