123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- #include "libbb.h"
- #include "modutils.h"
- #include <sys/utsname.h> /* uname() */
- static int FAST_FUNC parse_module(struct recursive_state *state,
- const char *fname,
- struct stat *sb UNUSED_PARAM)
- {
- module_db *modules = state->userData;
- char *image, *ptr;
- module_entry *e;
-
- size_t len = (64*1024*1024 - 4096);
- if (strrstr(fname, ".ko") == NULL)
- return TRUE;
- image = xmalloc_open_zipped_read_close(fname, &len);
- e = moddb_get_or_create(modules, bb_get_last_path_component_nostrip(fname));
- e->name = xstrdup(fname + 2);
- for (ptr = image; ptr < image + len - 10; ptr++) {
- if (is_prefixed_with(ptr, "depends=")) {
- char *u;
- ptr += 8;
- for (u = ptr; *u; u++)
- if (*u == '-')
- *u = '_';
- ptr += string_to_llist(ptr, &e->deps, ",");
- } else if (ENABLE_FEATURE_MODUTILS_ALIAS
- && is_prefixed_with(ptr, "alias=")
- ) {
- llist_add_to(&e->aliases, xstrdup(ptr + 6));
- ptr += strlen(ptr);
- } else if (ENABLE_FEATURE_MODUTILS_SYMBOLS
- && is_prefixed_with(ptr, "__ksymtab_")
- ) {
- ptr += 10;
- if (is_prefixed_with(ptr, "gpl")
- || strcmp(ptr, "strings") == 0
- ) {
- continue;
- }
- llist_add_to(&e->symbols, xstrdup(ptr));
- ptr += strlen(ptr);
- }
- }
- free(image);
- return TRUE;
- }
- static void order_dep_list(module_db *modules, module_entry *start, llist_t *add)
- {
- module_entry *m;
- llist_t *n;
- for (n = add; n != NULL; n = n->link) {
- m = moddb_get(modules, n->data);
- if (m == NULL)
- continue;
-
- m->dnext->dprev = m->dprev;
- m->dprev->dnext = m->dnext;
-
- m->dnext = start;
- m->dprev = start->dprev;
- start->dprev->dnext = m;
- start->dprev = m;
-
- order_dep_list(modules, start, m->deps);
- }
- }
- static void xfreopen_write(const char *file, FILE *f)
- {
- if (freopen(file, "w", f) == NULL)
- bb_perror_msg_and_die("can't open '%s'", file);
- }
- enum {
-
-
- OPT_b = (1 << 2),
-
-
- OPT_n = (1 << 5),
- OPT_r = (1 << 6),
- OPT_u = (1 << 7),
- OPT_q = (1 << 8),
- OPT_C = (1 << 9),
- };
- int depmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
- int depmod_main(int argc UNUSED_PARAM, char **argv)
- {
- module_db modules;
- module_entry *m, *dep;
- const char *moddir_base = "/";
- char *moddir, *version;
- struct utsname uts;
- unsigned i;
- int tmp;
- getopt32(argv, "aAb:eF:nruqC:", &moddir_base, NULL, NULL);
- argv += optind;
-
- xchdir(moddir_base);
-
- if (*argv && sscanf(*argv, "%u.%u.%u", &tmp, &tmp, &tmp) == 3) {
- version = *argv++;
- } else {
- uname(&uts);
- version = uts.release;
- }
- moddir = concat_path_file(&CONFIG_DEFAULT_MODULES_DIR[1], version);
- xchdir(moddir);
- if (ENABLE_FEATURE_CLEAN_UP)
- free(moddir);
-
- memset(&modules, 0, sizeof(modules));
- if (*argv) {
- do {
- recursive_action(*argv, 0 ,
- parse_module, NULL, &modules);
- } while (*++argv);
- } else {
- recursive_action(".", ACTION_RECURSE,
- parse_module, NULL, &modules);
- }
-
- if (!(option_mask32 & OPT_n))
- xfreopen_write(CONFIG_DEFAULT_DEPMOD_FILE, stdout);
- moddb_foreach_module(&modules, m, i) {
- printf("%s:", m->name);
- order_dep_list(&modules, m, m->deps);
- while (m->dnext != m) {
- dep = m->dnext;
- printf(" %s", dep->name);
-
- dep->dnext->dprev = dep->dprev;
- dep->dprev->dnext = dep->dnext;
- dep->dnext = dep->dprev = dep;
- }
- bb_putchar('\n');
- }
- #if ENABLE_FEATURE_MODUTILS_ALIAS
- if (!(option_mask32 & OPT_n))
- xfreopen_write("modules.alias", stdout);
- moddb_foreach_module(&modules, m, i) {
- while (m->aliases) {
-
- printf("alias %s %s\n",
- (char*)llist_pop(&m->aliases),
- m->modname);
- }
- }
- #endif
- #if ENABLE_FEATURE_MODUTILS_SYMBOLS
- if (!(option_mask32 & OPT_n))
- xfreopen_write("modules.symbols", stdout);
- moddb_foreach_module(&modules, m, i) {
- while (m->symbols) {
- printf("alias symbol:%s %s\n",
- (char*)llist_pop(&m->symbols),
- m->modname);
- }
- }
- #endif
- if (ENABLE_FEATURE_CLEAN_UP)
- moddb_free(&modules);
- return EXIT_SUCCESS;
- }
|