Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/modutils/depmod.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/modutils/depmod.c
r3232 r3621 22 22 */ 23 23 24 typedef 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 33 24 static int FAST_FUNC parse_module(const char *fname, struct stat *sb UNUSED_PARAM, 34 25 void *data, int depth UNUSED_PARAM) 35 26 { 36 char modname[MODULE_NAME_LEN]; 37 module_info **first = (module_info **) data; 27 module_db *modules = data; 38 28 char *image, *ptr; 39 module_info *info; 29 module_entry *e; 30 40 31 /* Arbitrary. Was sb->st_size, but that breaks .gz etc */ 41 32 size_t len = (64*1024*1024 - 4096); … … 45 36 46 37 image = xmalloc_open_zipped_read_close(fname, &len); 47 info = xzalloc(sizeof(*info)); 48 49 info->next = *first; 50 *first = info; 51 52 info->dnext = info->dprev = info; 53 info->name = xstrdup(fname + 2); /* skip "./" */ 54 info->modname = xstrdup(filename2modname(fname, modname)); 38 39 e = moddb_get_or_create(modules, bb_get_last_path_component_nostrip(fname)); 40 e->name = xstrdup(fname + 2); /* skip "./" */ 41 55 42 for (ptr = image; ptr < image + len - 10; ptr++) { 56 if ( strncmp(ptr, "depends=", 8) == 0) {43 if (is_prefixed_with(ptr, "depends=")) { 57 44 char *u; 58 45 … … 61 48 if (*u == '-') 62 49 *u = '_'; 63 ptr += string_to_llist(ptr, & info->dependencies, ",");50 ptr += string_to_llist(ptr, &e->deps, ","); 64 51 } else if (ENABLE_FEATURE_MODUTILS_ALIAS 65 && strncmp(ptr, "alias=", 6) == 052 && is_prefixed_with(ptr, "alias=") 66 53 ) { 67 llist_add_to(& info->aliases, xstrdup(ptr + 6));54 llist_add_to(&e->aliases, xstrdup(ptr + 6)); 68 55 ptr += strlen(ptr); 69 56 } else if (ENABLE_FEATURE_MODUTILS_SYMBOLS 70 && strncmp(ptr, "__ksymtab_", 10) == 057 && is_prefixed_with(ptr, "__ksymtab_") 71 58 ) { 72 59 ptr += 10; 73 if ( strncmp(ptr, "gpl", 3) == 060 if (is_prefixed_with(ptr, "gpl") 74 61 || strcmp(ptr, "strings") == 0 75 62 ) { 76 63 continue; 77 64 } 78 llist_add_to(& info->symbols, xstrdup(ptr));65 llist_add_to(&e->symbols, xstrdup(ptr)); 79 66 ptr += strlen(ptr); 80 67 } … … 85 72 } 86 73 87 static module_info *find_module(module_info *modules, const char *modname) 88 { 89 module_info *m; 90 91 for (m = modules; m != NULL; m = m->next) 92 if (strcmp(m->modname, modname) == 0) 93 return m; 94 return NULL; 95 } 96 97 static void order_dep_list(module_info *modules, module_info *start, 98 llist_t *add) 99 { 100 module_info *m; 74 static void order_dep_list(module_db *modules, module_entry *start, llist_t *add) 75 { 76 module_entry *m; 101 77 llist_t *n; 102 78 103 79 for (n = add; n != NULL; n = n->link) { 104 m = find_module(modules, n->data);80 m = moddb_get(modules, n->data); 105 81 if (m == NULL) 106 82 continue; … … 117 93 118 94 /* recurse */ 119 order_dep_list(modules, start, m->dep endencies);95 order_dep_list(modules, start, m->deps); 120 96 } 121 97 } … … 183 159 int depmod_main(int argc UNUSED_PARAM, char **argv) 184 160 { 185 module_info *modules, *m, *dep; 161 module_db modules; 162 module_entry *m, *dep; 186 163 const char *moddir_base = "/"; 187 164 char *moddir, *version; 188 165 struct utsname uts; 166 unsigned i; 189 167 int tmp; 190 168 … … 210 188 211 189 /* Scan modules */ 212 m odules = NULL;190 memset(&modules, 0, sizeof(modules)); 213 191 if (*argv) { 214 192 do { … … 223 201 if (!(option_mask32 & OPT_n)) 224 202 xfreopen_write(CONFIG_DEFAULT_DEPMOD_FILE, stdout); 225 for (m = modules; m != NULL; m = m->next) { 203 204 moddb_foreach_module(&modules, m, i) { 226 205 printf("%s:", m->name); 227 206 228 order_dep_list( modules, m, m->dependencies);207 order_dep_list(&modules, m, m->deps); 229 208 while (m->dnext != m) { 230 209 dep = m->dnext; … … 242 221 if (!(option_mask32 & OPT_n)) 243 222 xfreopen_write("modules.alias", stdout); 244 for (m = modules; m != NULL; m = m->next) { 245 const char *fname = bb_basename(m->name); 246 int fnlen = strchrnul(fname, '.') - fname; 223 moddb_foreach_module(&modules, m, i) { 247 224 while (m->aliases) { 248 /* Last word can well be m->modname instead, 249 * but depmod from module-init-tools 3.4 250 * uses module basename, i.e., no s/-/_/g. 251 * (pathname and .ko.* are still stripped) 252 * Mimicking that... */ 253 printf("alias %s %.*s\n", 225 /* 226 * Last word used to be a basename 227 * (filename with path and .ko.* stripped) 228 * at the time of module-init-tools 3.4. 229 * kmod v.12 uses module name, i.e., s/-/_/g. 230 */ 231 printf("alias %s %s\n", 254 232 (char*)llist_pop(&m->aliases), 255 fnlen, fname);233 m->modname); 256 234 } 257 235 } … … 260 238 if (!(option_mask32 & OPT_n)) 261 239 xfreopen_write("modules.symbols", stdout); 262 for (m = modules; m != NULL; m = m->next) { 263 const char *fname = bb_basename(m->name); 264 int fnlen = strchrnul(fname, '.') - fname; 240 moddb_foreach_module(&modules, m, i) { 265 241 while (m->symbols) { 266 printf("alias symbol:%s % .*s\n",242 printf("alias symbol:%s %s\n", 267 243 (char*)llist_pop(&m->symbols), 268 fnlen, fname);244 m->modname); 269 245 } 270 246 } 271 247 #endif 272 248 273 if (ENABLE_FEATURE_CLEAN_UP) { 274 while (modules) { 275 module_info *old = modules; 276 modules = modules->next; 277 free(old->name); 278 free(old->modname); 279 free(old); 280 } 281 } 249 if (ENABLE_FEATURE_CLEAN_UP) 250 moddb_free(&modules); 282 251 283 252 return EXIT_SUCCESS;
Note:
See TracChangeset
for help on using the changeset viewer.