Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/modutils/depmod.c


Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/modutils/depmod.c

    r3232 r3621  
    2222 */
    2323
    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 
    3324static int FAST_FUNC parse_module(const char *fname, struct stat *sb UNUSED_PARAM,
    3425                void *data, int depth UNUSED_PARAM)
    3526{
    36     char modname[MODULE_NAME_LEN];
    37     module_info **first = (module_info **) data;
     27    module_db *modules = data;
    3828    char *image, *ptr;
    39     module_info *info;
     29    module_entry *e;
     30
    4031    /* Arbitrary. Was sb->st_size, but that breaks .gz etc */
    4132    size_t len = (64*1024*1024 - 4096);
     
    4536
    4637    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
    5542    for (ptr = image; ptr < image + len - 10; ptr++) {
    56         if (strncmp(ptr, "depends=", 8) == 0) {
     43        if (is_prefixed_with(ptr, "depends=")) {
    5744            char *u;
    5845
     
    6148                if (*u == '-')
    6249                    *u = '_';
    63             ptr += string_to_llist(ptr, &info->dependencies, ",");
     50            ptr += string_to_llist(ptr, &e->deps, ",");
    6451        } else if (ENABLE_FEATURE_MODUTILS_ALIAS
    65          && strncmp(ptr, "alias=", 6) == 0
     52         && is_prefixed_with(ptr, "alias=")
    6653        ) {
    67             llist_add_to(&info->aliases, xstrdup(ptr + 6));
     54            llist_add_to(&e->aliases, xstrdup(ptr + 6));
    6855            ptr += strlen(ptr);
    6956        } else if (ENABLE_FEATURE_MODUTILS_SYMBOLS
    70          && strncmp(ptr, "__ksymtab_", 10) == 0
     57         && is_prefixed_with(ptr, "__ksymtab_")
    7158        ) {
    7259            ptr += 10;
    73             if (strncmp(ptr, "gpl", 3) == 0
     60            if (is_prefixed_with(ptr, "gpl")
    7461             || strcmp(ptr, "strings") == 0
    7562            ) {
    7663                continue;
    7764            }
    78             llist_add_to(&info->symbols, xstrdup(ptr));
     65            llist_add_to(&e->symbols, xstrdup(ptr));
    7966            ptr += strlen(ptr);
    8067        }
     
    8572}
    8673
    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;
     74static void order_dep_list(module_db *modules, module_entry *start, llist_t *add)
     75{
     76    module_entry *m;
    10177    llist_t *n;
    10278
    10379    for (n = add; n != NULL; n = n->link) {
    104         m = find_module(modules, n->data);
     80        m = moddb_get(modules, n->data);
    10581        if (m == NULL)
    10682            continue;
     
    11793
    11894        /* recurse */
    119         order_dep_list(modules, start, m->dependencies);
     95        order_dep_list(modules, start, m->deps);
    12096    }
    12197}
     
    183159int depmod_main(int argc UNUSED_PARAM, char **argv)
    184160{
    185     module_info *modules, *m, *dep;
     161    module_db modules;
     162    module_entry *m, *dep;
    186163    const char *moddir_base = "/";
    187164    char *moddir, *version;
    188165    struct utsname uts;
     166    unsigned i;
    189167    int tmp;
    190168
     
    210188
    211189    /* Scan modules */
    212     modules = NULL;
     190    memset(&modules, 0, sizeof(modules));
    213191    if (*argv) {
    214192        do {
     
    223201    if (!(option_mask32 & OPT_n))
    224202        xfreopen_write(CONFIG_DEFAULT_DEPMOD_FILE, stdout);
    225     for (m = modules; m != NULL; m = m->next) {
     203
     204    moddb_foreach_module(&modules, m, i) {
    226205        printf("%s:", m->name);
    227206
    228         order_dep_list(modules, m, m->dependencies);
     207        order_dep_list(&modules, m, m->deps);
    229208        while (m->dnext != m) {
    230209            dep = m->dnext;
     
    242221    if (!(option_mask32 & OPT_n))
    243222        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) {
    247224        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",
    254232                (char*)llist_pop(&m->aliases),
    255                 fnlen, fname);
     233                m->modname);
    256234        }
    257235    }
     
    260238    if (!(option_mask32 & OPT_n))
    261239        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) {
    265241        while (m->symbols) {
    266             printf("alias symbol:%s %.*s\n",
     242            printf("alias symbol:%s %s\n",
    267243                (char*)llist_pop(&m->symbols),
    268                 fnlen, fname);
     244                m->modname);
    269245        }
    270246    }
    271247#endif
    272248
    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);
    282251
    283252    return EXIT_SUCCESS;
Note: See TracChangeset for help on using the changeset viewer.