• Home
  • Raw
  • Download

Lines Matching +full:- +full:- +full:exclude +full:- +full:subdir

2  * kmod-depmod - calculate modules.dep  using libkmod.
4 * Copyright (C) 2011-2013 ProFUSION embedded systems
41 #include <libkmod/libkmod-internal.h>
51 static const char CFG_BUILTIN_KEY[] = "built-in";
70 { "unresolved-error", no_argument, 0, 'u' }, /* deprecated */
75 { "dry-run", no_argument, 0, 'n' },
76 { "symbol-prefix", required_argument, 0, 'P' },
87 "\t%s -[aA] [options] [forced_version]\n" in help()
89 "If no arguments (except options) are given, \"depmod -a\" is assumed\n" in help()
94 "\t-a, --all Probe all modules\n" in help()
95 "\t-A, --quick Only does the work if there's a new module\n" in help()
96 "\t-e, --errsyms Report not supplied symbols\n" in help()
97 "\t-n, --show Write the dependency file on stdout only\n" in help()
98 "\t-P, --symbol-prefix Architecture symbol prefix\n" in help()
99 "\t-C, --config=PATH Read configuration from PATH\n" in help()
100 "\t-v, --verbose Enable verbose mode\n" in help()
101 "\t-w, --warn Warn on duplicates\n" in help()
102 "\t-V, --version show version\n" in help()
103 "\t-h, --help show this help\n" in help()
106 "\t-b, --basedir=DIR Use an image of a module tree.\n" in help()
107 "\t-F, --filesyms=FILE Use the file instead of the\n" in help()
109 "\t-E, --symvers=FILE Use Module.symvers file to check\n" in help()
132 /* BEGIN: code from module-init-tools/index.c just modified to compile here.
136 * Copyright (C) 2008 Alan Jenkins <alan-jenkins@tuffmail.co.uk>.
152 /* see documentation in libkmod/libkmod-index.c */
166 /* In-memory index (depmod only) */
191 node->prefix = NOFAIL(strdup("")); in index_create()
192 node->first = INDEX_CHILDMAX; in index_create()
202 values = value->next; in index_values_free()
211 for (c = node->first; c <= node->last; c++) { in index_destroy()
212 struct index_node *child = node->children[c]; in index_destroy()
217 index_values_free(node->values); in index_destroy()
218 free(node->prefix); in index_destroy()
230 CRIT("Module index: bad character '%c'=0x%x - only 7-bit ASCII is supported:" in index__checkstring()
243 for (v = *values; v; v = v->next) { in index_add_value()
244 if (streq(v->value, value)) in index_add_value()
249 while (*values && (*values)->priority < priority) in index_add_value()
250 values = &(*values)->next; in index_add_value()
254 v->next = *values; in index_add_value()
255 v->priority = priority; in index_add_value()
256 memcpy(v->value, value, len + 1); in index_add_value()
272 int j; /* index within node->prefix */ in index_insert()
274 /* Ensure node->prefix is a prefix of &str[i]. in index_insert()
276 for (j = 0; node->prefix[j]; j++) { in index_insert()
277 ch = node->prefix[j]; in index_insert()
280 char *prefix = node->prefix; in index_insert()
286 n->prefix = NOFAIL(strdup(&prefix[j+1])); in index_insert()
291 node->prefix = prefix; in index_insert()
292 node->first = ch; in index_insert()
293 node->last = ch; in index_insert()
294 node->children[ch] = n; in index_insert()
299 /* j is now length of node->prefix */ in index_insert()
304 return index_add_value(&node->values, value, priority); in index_insert()
306 if (!node->children[ch]) { in index_insert()
309 if (ch < node->first) in index_insert()
310 node->first = ch; in index_insert()
311 if (ch > node->last) in index_insert()
312 node->last = ch; in index_insert()
313 node->children[ch] = NOFAIL(calloc(sizeof(struct index_node), 1)); in index_insert()
315 child = node->children[ch]; in index_insert()
316 child->prefix = NOFAIL(strdup(&key[i+1])); in index_insert()
317 child->first = INDEX_CHILDMAX; in index_insert()
318 index_add_value(&child->values, value, priority); in index_insert()
324 node = node->children[ch]; in index_insert()
331 return node->first < INDEX_CHILDMAX; in index__haschildren()
334 /* Recursive post-order traversal
336 Pre-order would make for better read-side buffering / readahead / caching.
337 (post-order means you go backwards in the file as you descend the tree).
339 Pre-order is simpler for writing, and depmod is already slow.
355 child_count = node->last - node->first + 1; in index_write__node()
359 child = node->children[node->first + i]; in index_write__node()
367 if (node->prefix[0]) { in index_write__node()
368 fputs(node->prefix, out); in index_write__node()
374 fputc(node->first, out); in index_write__node()
375 fputc(node->last, out); in index_write__node()
382 if (node->values) { in index_write__node()
388 for (v = node->values; v != NULL; v = v->next) in index_write__node()
393 for (v = node->values; v != NULL; v = v->next) { in index_write__node()
394 u = htonl(v->priority); in index_write__node()
396 fputs(v->value, out); in index_write__node()
432 /* END: code from module-init-tools/index.c just modified to compile here.
505 return -ENOMEM; in cfg_search_add()
507 s->type = type; in cfg_search_add()
509 s->len = 0; in cfg_search_add()
511 s->len = len - 1; in cfg_search_add()
512 memcpy(s->path, path, len); in cfg_search_add()
517 s->next = cfg->searches; in cfg_search_add()
518 cfg->searches = s; in cfg_search_add()
527 static int cfg_override_add(struct cfg *cfg, const char *modname, const char *subdir) in cfg_override_add() argument
531 size_t subdirlen = strlen(subdir); in cfg_override_add()
538 return -ENOMEM; in cfg_override_add()
540 memcpy(o->path, subdir, subdirlen); in cfg_override_add()
542 o->path[i] = '/'; in cfg_override_add()
545 memcpy(o->path + i, modname, modnamelen); in cfg_override_add()
547 o->path[i] = '\0'; /* no extension, so we can match .ko/.ko.gz */ in cfg_override_add()
549 o->len = i; in cfg_override_add()
551 DBG("override add: %s\n", o->path); in cfg_override_add()
553 o->next = cfg->overrides; in cfg_override_add()
554 cfg->overrides = o; in cfg_override_add()
571 return -ENOMEM; in cfg_external_add()
574 strcpy(ext->path, path); in cfg_external_add()
575 ext->len = len; in cfg_external_add()
577 DBG("external add: %s\n", ext->path); in cfg_external_add()
579 ext->next = cfg->externals; in cfg_external_add()
580 cfg->externals = ext; in cfg_external_add()
596 ERR("exclude add: out of memory\n"); in cfg_exclude_add()
597 return -ENOMEM; in cfg_exclude_add()
599 memcpy(exc->exclude_dir, path, len + 1); in cfg_exclude_add()
601 DBG("exclude add: %s\n", path); in cfg_exclude_add()
603 exc->next = cfg->excludes; in cfg_exclude_add()
604 cfg->excludes = exc; in cfg_exclude_add()
625 status = regexec(&re, cfg->kversion, 0, NULL, 0); in cfg_kernel_matches()
640 err = -errno; in cfg_file_parse()
663 const char *subdir = strtok_r(NULL, "\t ", &saveptr); in cfg_file_parse() local
666 subdir == NULL) in cfg_file_parse()
675 cfg_override_add(cfg, modname, subdir); in cfg_file_parse()
690 } else if (streq(cmd, "exclude")) { in cfg_file_parse()
722 if (len < 6 || !streq(name + len - 5, ".conf")) { in cfg_files_filter_out()
762 dirlen -= namelen + 1; in cfg_files_insert_sorted()
768 int cmp = strcmp(name, files[i]->name); in cfg_files_insert_sorted()
772 return -EEXIST; in cfg_files_insert_sorted()
780 return -ENOMEM; in cfg_files_insert_sorted()
787 return -ENOMEM; in cfg_files_insert_sorted()
793 sizeof(struct cfg_file *) * (n_files - i)); in cfg_files_insert_sorted()
797 f->dirlen = dirlen; in cfg_files_insert_sorted()
798 f->namelen = namelen; in cfg_files_insert_sorted()
799 f->name = f->path + dirlen + 1; in cfg_files_insert_sorted()
800 memcpy(f->path, dir, dirlen); in cfg_files_insert_sorted()
801 f->path[dirlen] = '/'; in cfg_files_insert_sorted()
802 memcpy(f->path + dirlen + 1, name, namelen); in cfg_files_insert_sorted()
803 f->path[dirlen + 1 + namelen] = '\0'; in cfg_files_insert_sorted()
821 err = -errno; in cfg_files_list()
834 return -EINVAL; in cfg_files_list()
838 if (cfg_files_filter_out(d, path, dent->d_name)) in cfg_files_list()
841 cfg_files_insert_sorted(p_files, p_n_files, path, dent->d_name); in cfg_files_list()
862 cfg_file_parse(cfg, f->path); in cfg_load()
870 if (cfg->searches == NULL) in cfg_load()
878 while (cfg->overrides) { in cfg_free()
879 struct cfg_override *tmp = cfg->overrides; in cfg_free()
880 cfg->overrides = cfg->overrides->next; in cfg_free()
884 while (cfg->searches) { in cfg_free()
885 struct cfg_search *tmp = cfg->searches; in cfg_free()
886 cfg->searches = cfg->searches->next; in cfg_free()
890 while (cfg->externals) { in cfg_free()
891 struct cfg_external *tmp = cfg->externals; in cfg_free()
892 cfg->externals = cfg->externals->next; in cfg_free()
896 while (cfg->excludes) { in cfg_free()
897 struct cfg_exclude *tmp = cfg->excludes; in cfg_free()
898 cfg->excludes = cfg->excludes->next; in cfg_free()
918 uint16_t idx; /* index in depmod->modules.array */
942 DBG("free %p kmod=%p, path=%s\n", mod, mod->kmod, mod->path); in mod_free()
943 array_free_array(&mod->deps); in mod_free()
944 kmod_module_unref(mod->kmod); in mod_free()
945 kmod_module_info_free_list(mod->info_list); in mod_free()
946 kmod_module_dependency_symbols_free_list(mod->dep_sym_list); in mod_free()
947 free(mod->uncrelpath); in mod_free()
948 free(mod->path); in mod_free()
956 DBG("%s depends on %s %s\n", mod->path, sym->name, in mod_add_dependency()
957 sym->owner != NULL ? sym->owner->path : "(unknown)"); in mod_add_dependency()
959 if (sym->owner == NULL) in mod_add_dependency()
962 err = array_append_unique(&mod->deps, sym->owner); in mod_add_dependency()
963 if (err == -EEXIST) in mod_add_dependency()
968 sym->owner->users++; in mod_add_dependency()
969 SHOW("%s needs \"%s\": %s\n", mod->path, sym->name, sym->owner->path); in mod_add_dependency()
975 DBG("free %p sym=%s, owner=%p %s\n", sym, sym->name, sym->owner, in symbol_free()
976 sym->owner != NULL ? sym->owner->path : ""); in symbol_free()
985 depmod->cfg = cfg; in depmod_init()
986 depmod->ctx = ctx; in depmod_init()
988 array_init(&depmod->modules, 128); in depmod_init()
990 depmod->modules_by_uncrelpath = hash_new(512, NULL); in depmod_init()
991 if (depmod->modules_by_uncrelpath == NULL) { in depmod_init()
992 err = -errno; in depmod_init()
996 depmod->modules_by_name = hash_new(512, NULL); in depmod_init()
997 if (depmod->modules_by_name == NULL) { in depmod_init()
998 err = -errno; in depmod_init()
1002 depmod->symbols = hash_new(2048, (void (*)(void *))symbol_free); in depmod_init()
1003 if (depmod->symbols == NULL) { in depmod_init()
1004 err = -errno; in depmod_init()
1011 hash_free(depmod->modules_by_name); in depmod_init()
1013 hash_free(depmod->modules_by_uncrelpath); in depmod_init()
1022 hash_free(depmod->symbols); in depmod_shutdown()
1024 hash_free(depmod->modules_by_uncrelpath); in depmod_shutdown()
1026 hash_free(depmod->modules_by_name); in depmod_shutdown()
1028 for (i = 0; i < depmod->modules.count; i++) in depmod_shutdown()
1029 mod_free(depmod->modules.array[i]); in depmod_shutdown()
1030 array_free_array(&depmod->modules); in depmod_shutdown()
1032 kmod_unref(depmod->ctx); in depmod_shutdown()
1037 const struct cfg *cfg = depmod->cfg; in depmod_module_add()
1048 return -ENOMEM; in depmod_module_add()
1049 mod->kmod = kmod; in depmod_module_add()
1050 mod->sort_idx = depmod->modules.count + 1; in depmod_module_add()
1051 mod->dep_sort_idx = INT32_MAX; in depmod_module_add()
1052 memcpy(mod->modname, modname, modnamesz); in depmod_module_add()
1053 mod->modnamesz = modnamesz; in depmod_module_add()
1055 array_init(&mod->deps, 4); in depmod_module_add()
1057 mod->path = strdup(kmod_module_get_path(kmod)); in depmod_module_add()
1058 lastslash = strrchr(mod->path, '/'); in depmod_module_add()
1059 mod->baselen = lastslash - mod->path; in depmod_module_add()
1060 if (strncmp(mod->path, cfg->dirname, cfg->dirnamelen) == 0 && in depmod_module_add()
1061 mod->path[cfg->dirnamelen] == '/') in depmod_module_add()
1062 mod->relpath = mod->path + cfg->dirnamelen + 1; in depmod_module_add()
1064 mod->relpath = NULL; in depmod_module_add()
1066 err = hash_add_unique(depmod->modules_by_name, mod->modname, mod); in depmod_module_add()
1068 ERR("hash_add_unique %s: %s\n", mod->modname, strerror(-err)); in depmod_module_add()
1072 if (mod->relpath != NULL) { in depmod_module_add()
1073 size_t uncrelpathlen = lastslash - mod->relpath + modnamesz in depmod_module_add()
1075 mod->uncrelpath = memdup(mod->relpath, uncrelpathlen + 1); in depmod_module_add()
1076 mod->uncrelpath[uncrelpathlen] = '\0'; in depmod_module_add()
1077 err = hash_add_unique(depmod->modules_by_uncrelpath, in depmod_module_add()
1078 mod->uncrelpath, mod); in depmod_module_add()
1081 mod->uncrelpath, strerror(-err)); in depmod_module_add()
1082 hash_del(depmod->modules_by_name, mod->modname); in depmod_module_add()
1087 DBG("add %p kmod=%p, path=%s\n", mod, kmod, mod->path); in depmod_module_add()
1092 free(mod->uncrelpath); in depmod_module_add()
1099 DBG("del %p kmod=%p, path=%s\n", mod, mod->kmod, mod->path); in depmod_module_del()
1101 if (mod->uncrelpath != NULL) in depmod_module_del()
1102 hash_del(depmod->modules_by_uncrelpath, mod->uncrelpath); in depmod_module_del()
1104 hash_del(depmod->modules_by_name, mod->modname); in depmod_module_del()
1112 switch(s->type) { in search_to_string()
1116 return "built-in"; in search_to_string()
1118 return s->path; in search_to_string()
1138 * note this is the inverse of module-init-tools is_higher_priority()
1142 const struct cfg *cfg = depmod->cfg; in depmod_module_is_higher_priority()
1147 /* baselen includes the last '/' and mod->baselen doesn't. So it's in depmod_module_is_higher_priority()
1151 size_t oldlen = mod->baselen + mod->modnamesz; in depmod_module_is_higher_priority()
1152 const char *oldpath = mod->path; in depmod_module_is_higher_priority()
1153 int i, bprio = -1, oldprio = -1, newprio = -1; in depmod_module_is_higher_priority()
1162 if (strncmp(newpath, cfg->dirname, cfg->dirnamelen) == 0) { in depmod_module_is_higher_priority()
1163 relnewpath = newpath + cfg->dirnamelen + 1; in depmod_module_is_higher_priority()
1164 relnewlen = newlen - (cfg->dirnamelen + 1); in depmod_module_is_higher_priority()
1166 if (strncmp(oldpath, cfg->dirname, cfg->dirnamelen) == 0) { in depmod_module_is_higher_priority()
1167 reloldpath = oldpath + cfg->dirnamelen + 1; in depmod_module_is_higher_priority()
1168 reloldlen = oldlen - (cfg->dirnamelen + 1); in depmod_module_is_higher_priority()
1171 for (ov = cfg->overrides; ov != NULL; ov = ov->next) { in depmod_module_is_higher_priority()
1172 DBG("override %s\n", ov->path); in depmod_module_is_higher_priority()
1173 if (relnewlen == ov->len && in depmod_module_is_higher_priority()
1174 memcmp(ov->path, relnewpath, relnewlen) == 0) in depmod_module_is_higher_priority()
1176 if (reloldlen == ov->len && in depmod_module_is_higher_priority()
1177 memcmp(ov->path, reloldpath, reloldlen) == 0) in depmod_module_is_higher_priority()
1181 for (i = 0, se = cfg->searches; se != NULL; se = se->next, i++) { in depmod_module_is_higher_priority()
1183 if (se->type == SEARCH_BUILTIN) in depmod_module_is_higher_priority()
1185 else if (se->type == SEARCH_EXTERNAL) { in depmod_module_is_higher_priority()
1186 for (ext = cfg->externals; ext != NULL; ext = ext->next, i++) { in depmod_module_is_higher_priority()
1189 ext->path, in depmod_module_is_higher_priority()
1190 ext->len)) in depmod_module_is_higher_priority()
1194 ext->path, in depmod_module_is_higher_priority()
1195 ext->len)) in depmod_module_is_higher_priority()
1198 } else if (relnewlen > se->len && relnewpath[se->len] == '/' && in depmod_module_is_higher_priority()
1199 memcmp(se->path, relnewpath, se->len) == 0) in depmod_module_is_higher_priority()
1201 else if (reloldlen > se->len && reloldpath[se->len] == '/' && in depmod_module_is_higher_priority()
1202 memcmp(se->path, reloldpath, se->len) == 0) in depmod_module_is_higher_priority()
1211 DBG("priorities: built-in: %d, old: %d, new: %d\n", in depmod_module_is_higher_priority()
1231 return -EINVAL; in depmod_modules_search_file()
1234 relpath = path + depmod->cfg->dirnamelen + 1; in depmod_modules_search_file()
1237 mod = hash_find(depmod->modules_by_name, modname); in depmod_modules_search_file()
1244 path, mod->path); in depmod_modules_search_file()
1249 mod->relpath, relpath); in depmod_modules_search_file()
1252 ERR("could not del module %s: %s\n", mod->path, strerror(-err)); in depmod_modules_search_file()
1257 err = kmod_module_new_from_path(depmod->ctx, path, &kmod); in depmod_modules_search_file()
1259 ERR("could not create module %s: %s\n", path, strerror(-err)); in depmod_modules_search_file()
1266 path, strerror(-err)); in depmod_modules_search_file()
1284 for (exc = cfg->excludes; exc != NULL; exc = exc->next) { in should_exclude_dir()
1285 if (streq(name, exc->exclude_dir)) in should_exclude_dir()
1299 const char *name = de->d_name; in depmod_modules_search_dir()
1303 if (should_exclude_dir(depmod->cfg, name)) in depmod_modules_search_dir()
1308 err = -ENOMEM; in depmod_modules_search_dir()
1316 if (de->d_type == DT_REG) in depmod_modules_search_dir()
1318 else if (de->d_type == DT_DIR) in depmod_modules_search_dir()
1338 DIR *subdir; in depmod_modules_search_dir() local
1345 subdir = fdopendir(fd); in depmod_modules_search_dir()
1346 if (subdir == NULL) { in depmod_modules_search_dir()
1353 err = depmod_modules_search_dir(depmod, subdir, in depmod_modules_search_dir()
1356 closedir(subdir); in depmod_modules_search_dir()
1364 ERR("failed %s: %s\n", path, strerror(-err)); in depmod_modules_search_dir()
1384 err = -errno; in depmod_modules_search_path()
1392 err = -ENOMEM; in depmod_modules_search_path()
1413 err = depmod_modules_search_path(depmod, depmod->cfg->dirname); in depmod_modules_search()
1417 for (ext = depmod->cfg->externals; ext != NULL; ext = ext->next) { in depmod_modules_search()
1418 err = depmod_modules_search_path(depmod, ext->path); in depmod_modules_search()
1419 if (err < 0 && err == -ENOENT) in depmod_modules_search()
1430 return a->sort_idx - b->sort_idx; in mod_cmp()
1439 hash_iter_init(depmod->modules_by_name, &module_iter); in depmod_modules_build_array()
1442 mod->idx = depmod->modules.count; in depmod_modules_build_array()
1443 err = array_append(&depmod->modules, mod); in depmod_modules_build_array()
1487 fp = dfdopen(depmod->cfg->dirname, order_file, O_RDONLY, "r"); in depmod_modules_sort()
1496 if (line[len - 1] != '\n') { in depmod_modules_sort()
1498 depmod->cfg->dirname, order_file, idx); in depmod_modules_sort()
1512 line[len - 1] = '\0'; in depmod_modules_sort()
1514 mod = hash_find(depmod->modules_by_uncrelpath, line); in depmod_modules_sort()
1517 mod->sort_idx = idx - total; in depmod_modules_sort()
1520 array_sort(&depmod->modules, mod_cmp); in depmod_modules_sort()
1521 for (idx = 0; idx < depmod->modules.count; idx++) { in depmod_modules_sort()
1522 struct mod *m = depmod->modules.array[idx]; in depmod_modules_sort()
1523 m->idx = idx; in depmod_modules_sort()
1538 if (!prefix_skipped && (name[0] == depmod->cfg->sym_prefix)) in depmod_symbol_add()
1544 return -ENOMEM; in depmod_symbol_add()
1546 sym->owner = (struct mod *)owner; in depmod_symbol_add()
1547 sym->crc = crc; in depmod_symbol_add()
1548 memcpy(sym->name, name, namelen); in depmod_symbol_add()
1550 err = hash_add(depmod->symbols, sym->name, sym); in depmod_symbol_add()
1556 DBG("add %p sym=%s, owner=%p %s\n", sym, sym->name, owner, in depmod_symbol_add()
1557 owner != NULL ? owner->path : ""); in depmod_symbol_add()
1567 if (name[0] == depmod->cfg->sym_prefix) in depmod_symbol_find()
1569 return hash_find(depmod->symbols, name); in depmod_symbol_find()
1576 DBG("load symbols (%zd modules)\n", depmod->modules.count); in depmod_load_modules()
1578 itr = (struct mod **)depmod->modules.array; in depmod_load_modules()
1579 itr_end = itr + depmod->modules.count; in depmod_load_modules()
1583 int err = kmod_module_get_symbols(mod->kmod, &list); in depmod_load_modules()
1585 if (err == -ENOENT) in depmod_load_modules()
1586 DBG("ignoring %s: no symbols\n", mod->path); in depmod_load_modules()
1589 mod->path, strerror(-err)); in depmod_load_modules()
1600 kmod_module_get_info(mod->kmod, &mod->info_list); in depmod_load_modules()
1601 kmod_module_get_dependency_symbols(mod->kmod, in depmod_load_modules()
1602 &mod->dep_sym_list); in depmod_load_modules()
1603 kmod_module_unref(mod->kmod); in depmod_load_modules()
1604 mod->kmod = NULL; in depmod_load_modules()
1608 depmod->modules.count, hash_get_count(depmod->symbols)); in depmod_load_modules()
1615 const struct cfg *cfg = depmod->cfg; in depmod_load_module_dependencies()
1618 DBG("do dependencies of %s\n", mod->path); in depmod_load_module_dependencies()
1619 kmod_list_foreach(l, mod->dep_sym_list) { in depmod_load_module_dependencies()
1628 mod->path, bindtype, name); in depmod_load_module_dependencies()
1629 if (cfg->print_unknown && !is_weak) in depmod_load_module_dependencies()
1631 mod->path, name); in depmod_load_module_dependencies()
1635 if (cfg->check_symvers && sym->crc != crc && !is_weak) { in depmod_load_module_dependencies()
1637 sym->name, sym->crc, mod->path, crc); in depmod_load_module_dependencies()
1638 if (cfg->print_unknown) in depmod_load_module_dependencies()
1640 mod->path, name); in depmod_load_module_dependencies()
1654 depmod->modules.count, hash_get_count(depmod->symbols)); in depmod_load_dependencies()
1656 itr = (struct mod **)depmod->modules.array; in depmod_load_dependencies()
1657 itr_end = itr + depmod->modules.count; in depmod_load_dependencies()
1661 if (mod->dep_sym_list == NULL) { in depmod_load_dependencies()
1662 DBG("ignoring %s: no dependency symbols\n", mod->path); in depmod_load_dependencies()
1670 depmod->modules.count, hash_get_count(depmod->symbols)); in depmod_load_dependencies()
1679 return a->dep_sort_idx - b->dep_sort_idx; in dep_cmp()
1685 itr = (struct mod **)depmod->modules.array; in depmod_sort_dependencies()
1686 itr_end = itr + depmod->modules.count; in depmod_sort_dependencies()
1689 if (m->deps.count > 1) in depmod_sort_dependencies()
1690 array_sort(&m->deps, dep_cmp); in depmod_sort_dependencies()
1707 v->parent = parent; in vertex_new()
1708 v->mod = mod; in vertex_new()
1725 const char sep[] = " -> "; in depmod_report_one_cycle()
1737 for (v = vertex->parent, n = 0; in depmod_report_one_cycle()
1739 v = v->parent, n++) { in depmod_report_one_cycle()
1741 sz += v->mod->modnamesz - 1; in depmod_report_one_cycle()
1743 rc = hash_add(loop_set, v->mod->modname, NULL); in depmod_report_one_cycle()
1748 sz += vertex->mod->modnamesz - 1; in depmod_report_one_cycle()
1753 for (i = reverse.count - 1; i >= 0; i--) { in depmod_report_one_cycle()
1758 len = v->mod->modnamesz - 1; in depmod_report_one_cycle()
1759 memcpy(buf + sz, v->mod->modname, len); in depmod_report_one_cycle()
1764 depmod_list_remove_data(roots, v->mod); in depmod_report_one_cycle()
1766 strcpy(buf + sz, vertex->mod->modname); in depmod_report_one_cycle()
1790 int ret = -ENOMEM; in depmod_report_cycles_from_root()
1809 vertex = stack[--is]; in depmod_report_cycles_from_root()
1810 m = vertex->mod; in depmod_report_cycles_from_root()
1815 if (m->visited && m == root->mod) { in depmod_report_cycles_from_root()
1826 m->visited = true; in depmod_report_cycles_from_root()
1827 if (m->deps.count == 0) { in depmod_report_cycles_from_root()
1832 * m->visited because more then one, in depmod_report_cycles_from_root()
1833 * m == root->mod since it is a single node. in depmod_report_cycles_from_root()
1842 itr = (struct mod **) m->deps.array; in depmod_report_cycles_from_root()
1843 itr_end = itr + m->deps.count; in depmod_report_cycles_from_root()
1867 v = free_list->data; in depmod_report_cycles_from_root()
1893 m = depmod->modules.array[i]; in depmod_report_cycles()
1916 root = roots->data; in depmod_report_cycles()
1943 uint16_t i, n_roots = 0, n_sorted = 0, n_mods = depmod->modules.count; in depmod_calculate_dependencies()
1948 return -ENOMEM; in depmod_calculate_dependencies()
1954 assert(depmod->modules.count < UINT16_MAX); in depmod_calculate_dependencies()
1957 itrm = (const struct mod **)depmod->modules.array; in depmod_calculate_dependencies()
1960 users[i] = m->users; in depmod_calculate_dependencies()
1971 uint16_t src_idx = roots[--n_roots]; in depmod_calculate_dependencies()
1973 src = depmod->modules.array[src_idx]; in depmod_calculate_dependencies()
1974 src->dep_sort_idx = n_sorted; in depmod_calculate_dependencies()
1978 itr_dst = (const struct mod **)src->deps.array; in depmod_calculate_dependencies()
1979 itr_dst_end = itr_dst + src->deps.count; in depmod_calculate_dependencies()
1982 uint16_t dst_idx = dst->idx; in depmod_calculate_dependencies()
1984 users[dst_idx]--; in depmod_calculate_dependencies()
1994 ret = -EINVAL; in depmod_calculate_dependencies()
2029 for (i = 0; i < mod->deps.count; i++) { in mod_count_all_dependencies()
2030 const struct mod *d = mod->deps.array[i]; in mod_count_all_dependencies()
2040 for (i = 0; i < mod->deps.count; i++) { in mod_fill_all_unique_dependencies()
2041 const struct mod *d = mod->deps.array[i]; in mod_fill_all_unique_dependencies()
2056 return -ENOSPC; in mod_fill_all_unique_dependencies()
2091 if (mod->relpath != NULL) in mod_get_compressed_path()
2092 return mod->relpath; in mod_get_compressed_path()
2093 return mod->path; in mod_get_compressed_path()
2100 for (i = 0; i < depmod->modules.count; i++) { in output_deps()
2101 const struct mod **deps, *mod = depmod->modules.array[i]; in output_deps()
2107 if (mod->deps.count == 0) in output_deps()
2138 return -ENOMEM; in output_deps_bin()
2140 for (i = 0; i < depmod->modules.count; i++) { in output_deps_bin()
2141 const struct mod **deps, *mod = depmod->modules.array[i]; in output_deps_bin()
2187 duplicate = index_insert(idx, mod->modname, line, mod->idx); in output_deps_bin()
2188 if (duplicate && depmod->cfg->warn_dups) in output_deps_bin()
2206 for (i = 0; i < depmod->modules.count; i++) { in output_aliases()
2207 const struct mod *mod = depmod->modules.array[i]; in output_aliases()
2210 kmod_list_foreach(l, mod->info_list) { in output_aliases()
2217 fprintf(out, "alias %s %s\n", value, mod->modname); in output_aliases()
2234 return -ENOMEM; in output_aliases_bin()
2236 for (i = 0; i < depmod->modules.count; i++) { in output_aliases_bin()
2237 const struct mod *mod = depmod->modules.array[i]; in output_aliases_bin()
2240 kmod_list_foreach(l, mod->info_list) { in output_aliases_bin()
2256 duplicate = index_insert(idx, alias, mod->modname, in output_aliases_bin()
2257 mod->idx); in output_aliases_bin()
2258 if (duplicate && depmod->cfg->warn_dups) in output_aliases_bin()
2260 alias, mod->modname); in output_aliases_bin()
2276 for (i = 0; i < depmod->modules.count; i++) { in output_softdeps()
2277 const struct mod *mod = depmod->modules.array[i]; in output_softdeps()
2280 kmod_list_foreach(l, mod->info_list) { in output_softdeps()
2287 fprintf(out, "softdep %s %s\n", mod->modname, value); in output_softdeps()
2301 hash_iter_init(depmod->symbols, &iter); in output_symbols()
2305 if (sym->owner == NULL) in output_symbols()
2309 sym->name, sym->owner->modname); in output_symbols()
2321 size_t baselen = sizeof("symbol:") - 1; in output_symbols_bin()
2331 return -ENOMEM; in output_symbols_bin()
2335 hash_iter_init(depmod->symbols, &iter); in output_symbols_bin()
2342 if (sym->owner == NULL) in output_symbols_bin()
2345 len = strlen(sym->name); in output_symbols_bin()
2348 ret = -ENOMEM; in output_symbols_bin()
2351 memcpy(scratchbuf_str(&salias) + baselen, sym->name, len + 1); in output_symbols_bin()
2352 duplicate = index_insert(idx, alias, sym->owner->modname, in output_symbols_bin()
2353 sym->owner->idx); in output_symbols_bin()
2355 if (duplicate && depmod->cfg->warn_dups) in output_symbols_bin()
2357 alias, sym->owner->modname); in output_symbols_bin()
2366 ERR("output symbols: %s\n", strerror(-ret)); in output_symbols_bin()
2380 in = dfdopen(depmod->cfg->dirname, "modules.builtin", O_RDONLY, "r"); in output_builtin_bin()
2387 return -ENOMEM; in output_builtin_bin()
2433 i--; in flush_stream_to()
2448 in = dfdopen(depmod->cfg->dirname, "modules.builtin.modinfo", O_RDONLY, "r"); in output_builtin_alias_bin()
2455 return -ENOMEM; in output_builtin_alias_bin()
2492 ret = -EINVAL; in output_builtin_alias_bin()
2509 for (i = 0; i < depmod->modules.count; i++) { in output_devname()
2510 const struct mod *mod = depmod->modules.array[i]; in output_devname()
2516 kmod_list_foreach(l, mod->info_list) { in output_devname()
2525 devname = value + sizeof("devname:") - 1; in output_devname()
2526 else if (sscanf(value, "char-major-%u-%u", in output_devname()
2531 } else if (sscanf(value, "block-major-%u-%u", in output_devname()
2545 fputs("# Device nodes to trigger on-demand module loading.\n", in output_devname()
2549 fprintf(out, "%s %s %c%u:%u\n", mod->modname, in output_devname()
2554 "Ignoring.\n", mod->modname, devname); in output_devname()
2579 const char *dname = depmod->cfg->dirname; in depmod_output()
2586 dfd = -1; in depmod_output()
2590 err = -errno; in depmod_output()
2596 for (itr = depfiles; itr->name != NULL; itr++) { in depmod_output()
2606 snprintf(tmp, sizeof(tmp), "%s.%i.%li.%li", itr->name, getpid(), in depmod_output()
2622 r = itr->cb(depmod, fp); in depmod_output()
2632 ERR("Could not write index '%s': %s\n", itr->name, in depmod_output()
2633 strerror(-r)); in depmod_output()
2634 err = -errno; in depmod_output()
2638 if (renameat(dfd, tmp, dfd, itr->name) != 0) { in depmod_output()
2639 err = -errno; in depmod_output()
2641 dname, tmp, dname, itr->name); in depmod_output()
2646 err = -ENOSPC; in depmod_output()
2648 itr->name, strerror(-err)); in depmod_output()
2678 int err = -errno; in depmod_load_symvers()
2721 const size_t ksymstr_len = sizeof(ksymstr) - 1; in depmod_load_system_map()
2728 int err = -errno; in depmod_load_system_map()
2750 if (p[0] == depmod->cfg->sym_prefix) in depmod_load_system_map()
2753 /* Covers gpl-only and normal symbols. */ in depmod_load_system_map()
2782 const char *name = de->d_name; in depfile_up_to_date_dir()
2805 DIR *subdir; in depfile_up_to_date_dir() local
2817 subdir = fdopendir(fd); in depfile_up_to_date_dir()
2818 if (subdir == NULL) { in depfile_up_to_date_dir()
2825 err = depfile_up_to_date_dir(subdir, mtime, in depfile_up_to_date_dir()
2828 closedir(subdir); in depfile_up_to_date_dir()
2850 ERR("failed %s: %s\n", path, strerror(-err)); in depfile_up_to_date_dir()
2867 err = -errno; in depfile_up_to_date()
2873 err = -errno; in depfile_up_to_date()
2916 if (c == -1) in do_depmod()
2934 fputs("Error: out-of-memory\n", stderr); in do_depmod()
2961 CRIT("-P only takes a single char\n"); in do_depmod()
2974 WRN("Ignored deprecated option --%s\n", in do_depmod()
2977 WRN("Ignored deprecated option -%c\n", c); in do_depmod()
3020 /* ignore up-to-date errors (< 0) */ in do_depmod()
3036 CRIT("depmod_init: %s\n", strerror(-err)); in do_depmod()
3045 strerror(-err)); in do_depmod()
3052 strerror(-err)); in do_depmod()
3056 WRN("-e needs -E or -F\n"); in do_depmod()
3068 CRIT("could not search modules: %s\n", strerror(-err)); in do_depmod()
3086 path, strerror(-err)); in do_depmod()
3093 path, strerror(-err)); in do_depmod()
3103 strerror(-err)); in do_depmod()