diff options
author | Andreas Robinson <andr345@gmail.com> | 2009-05-10 01:35:16 +0200 |
---|---|---|
committer | Andreas Robinson <andr345@gmail.com> | 2009-05-12 12:55:40 +0200 |
commit | 5af0c0f484bde37beb80313a339ea53fcab6b8a7 (patch) | |
tree | 1a619afb39f135a62dae98c6813adfb340e51100 | |
parent | a7c7a51d9552501d63cf28260592881fb258e37c (diff) | |
download | module-init-tools-5af0c0f484bde37beb80313a339ea53fcab6b8a7.tar.gz |
depmod: Introduce struct elf_file
Remove the last remnants of struct module from moduleops*.[ch]
Signed-off-by: Andreas Robinson <andr345@gmail.com>
-rw-r--r-- | depmod.c | 37 | ||||
-rw-r--r-- | depmod.h | 24 | ||||
-rw-r--r-- | moduleops.h | 14 | ||||
-rw-r--r-- | moduleops_core.c | 17 | ||||
-rw-r--r-- | tables.c | 16 |
5 files changed, 63 insertions, 45 deletions
@@ -264,6 +264,7 @@ static int ends_in(const char *name, const char *ext) static struct module *grab_module(const char *dirname, const char *filename) { struct module *new; + struct elf_file *file; new = NOFAIL(malloc(sizeof(*new) + strlen(dirname?:"") + 1 + strlen(filename) + 1)); @@ -276,19 +277,21 @@ static struct module *grab_module(const char *dirname, const char *filename) INIT_LIST_HEAD(&new->dep_list); new->order = INDEX_PRIORITY_MIN; - new->data = grab_file(new->pathname, &new->len); - if (!new->data) { + file = &new->file; + + file->data = grab_file(new->pathname, &file->len); + if (!file->data) { warn("Can't read module %s: %s\n", new->pathname, strerror(errno)); goto fail_data; } - switch (elf_ident(new->data, new->len, &new->conv)) { + switch (elf_ident(file->data, file->len, &file->conv)) { case ELFCLASS32: - new->ops = &mod_ops32; + file->ops = &mod_ops32; break; case ELFCLASS64: - new->ops = &mod_ops64; + file->ops = &mod_ops64; break; case -ENOEXEC: warn("Module %s is not an elf object\n", new->pathname); @@ -303,7 +306,7 @@ static struct module *grab_module(const char *dirname, const char *filename) return new; fail: - release_file(new->data, new->len); + release_file(file->data, new->file.len); fail_data: free(new); return NULL; @@ -673,11 +676,13 @@ static void calculate_deps(struct module *module) unsigned int i; struct string_table *symnames; struct string_table *symtypes; + struct elf_file *file; module->num_deps = 0; module->deps = NULL; + file = &module->file; - symnames = module->ops->load_dep_syms(module, &symtypes); + symnames = file->ops->load_dep_syms(module->pathname, file, &symtypes); if (!symnames || !symtypes) return; @@ -704,17 +709,19 @@ static void calculate_deps(struct module *module) static struct module *parse_modules(struct module *list) { struct module *i; + struct elf_file *file; struct string_table *syms; int j; for (i = list; i; i = i->next) { - syms = i->ops->load_symbols(i); + file = &i->file; + syms = file->ops->load_symbols(file); if (syms) { for (j = 0; j < syms->cnt; j++) add_symbol(syms->str[j], i); free(syms); } - i->ops->fetch_tables(i, &i->tables); + file->ops->fetch_tables(file, &i->tables); } for (i = list; i; i = i->next) @@ -788,6 +795,7 @@ static void output_symbols_bin(struct module *unused, FILE *out, char *dirname) static void output_aliases(struct module *modules, FILE *out, char *dirname) { struct module *i; + struct elf_file *file; const char *p; unsigned long size; @@ -795,16 +803,17 @@ static void output_aliases(struct module *modules, FILE *out, char *dirname) for (i = modules; i; i = i->next) { char modname[strlen(i->pathname)+1]; + file = &i->file; filename2modname(modname, i->pathname); /* Grab from old-style .modalias section. */ - for (p = i->ops->get_aliases(i, &size); + for (p = file->ops->get_aliases(file, &size); p; p = next_string(p, &size)) fprintf(out, "alias %s %s\n", p, modname); /* Grab form new-style .modinfo section. */ - for (p = i->ops->get_modinfo(i, &size); + for (p = file->ops->get_modinfo(file, &size); p; p = next_string(p, &size)) { if (strstarts(p, "alias=")) @@ -817,6 +826,7 @@ static void output_aliases(struct module *modules, FILE *out, char *dirname) static void output_aliases_bin(struct module *modules, FILE *out, char *dirname) { struct module *i; + struct elf_file *file; const char *p; char *alias; unsigned long size; @@ -828,10 +838,11 @@ static void output_aliases_bin(struct module *modules, FILE *out, char *dirname) for (i = modules; i; i = i->next) { char modname[strlen(i->pathname)+1]; + file = &i->file; filename2modname(modname, i->pathname); /* Grab from old-style .modalias section. */ - for (p = i->ops->get_aliases(i, &size); + for (p = file->ops->get_aliases(file, &size); p; p = next_string(p, &size)) { alias = NOFAIL(strdup(p)); @@ -844,7 +855,7 @@ static void output_aliases_bin(struct module *modules, FILE *out, char *dirname) } /* Grab from new-style .modinfo section. */ - for (p = i->ops->get_modinfo(i, &size); + for (p = file->ops->get_modinfo(file, &size); p; p = next_string(p, &size)) { if (strstarts(p, "alias=")) { @@ -26,6 +26,20 @@ struct module_tables { void *of_table; }; +struct elf_file +{ + /* File operations */ + struct module_ops *ops; + + /* Convert endian? */ + int conv; + + /* File contents and length. */ + void *data; + unsigned long len; +}; + + struct module; struct module @@ -33,12 +47,6 @@ struct module /* Next module in list of all modules */ struct module *next; - /* 64 or 32 bit? */ - struct module_ops *ops; - - /* Convert endian? */ - int conv; - /* Dependencies: filled in by ops->calculate_deps() */ unsigned int num_deps; struct module **deps; @@ -52,9 +60,7 @@ struct module /* Tables extracted from module by ops->fetch_tables(). */ struct module_tables tables; - /* File contents and length. */ - void *data; - unsigned long len; + struct elf_file file; char *basename; /* points into pathname */ char pathname[0]; diff --git a/moduleops.h b/moduleops.h index 8860889..dd74432 100644 --- a/moduleops.h +++ b/moduleops.h @@ -16,15 +16,15 @@ struct kernel_symbol64 { struct module_ops { - struct string_table *(*load_strings)(struct module *module, + struct string_table *(*load_strings)(struct elf_file *module, const char *secname, struct string_table *tbl); - struct string_table *(*load_symbols)(struct module *module); - struct string_table *(*load_dep_syms)(struct module *module, - struct string_table **types); - void (*fetch_tables)(struct module *module, + struct string_table *(*load_symbols)(struct elf_file *module); + struct string_table *(*load_dep_syms)(const char *pathname, + struct elf_file *module, struct string_table **types); + void (*fetch_tables)(struct elf_file *module, struct module_tables *tables); - char *(*get_aliases)(struct module *module, unsigned long *size); - char *(*get_modinfo)(struct module *module, unsigned long *size); + char *(*get_aliases)(struct elf_file *module, unsigned long *size); + char *(*get_modinfo)(struct elf_file *module, unsigned long *size); }; extern struct module_ops mod_ops32, mod_ops64; diff --git a/moduleops_core.c b/moduleops_core.c index d5589f0..e2440d7 100644 --- a/moduleops_core.c +++ b/moduleops_core.c @@ -1,12 +1,12 @@ /* Load the given section: NULL on error. */ -static void *PERBIT(load_section)(struct module *module, +static void *PERBIT(load_section)(struct elf_file *module, const char *secname, unsigned long *secsize) { return PERBIT(get_section)(module->data, 0, secname, secsize, module->conv); } -static struct string_table *PERBIT(load_strings)(struct module *module, +static struct string_table *PERBIT(load_strings)(struct elf_file *module, const char *secname, struct string_table *tbl) { @@ -27,7 +27,7 @@ static struct string_table *PERBIT(load_strings)(struct module *module, return tbl; } -static struct string_table *PERBIT(load_symbols)(struct module *module) +static struct string_table *PERBIT(load_symbols)(struct elf_file *module) { struct PERBIT(kernel_symbol) *ksyms; struct string_table *symtbl; @@ -54,12 +54,12 @@ static struct string_table *PERBIT(load_symbols)(struct module *module) return symtbl; } -static char *PERBIT(get_aliases)(struct module *module, unsigned long *size) +static char *PERBIT(get_aliases)(struct elf_file *module, unsigned long *size) { return PERBIT(load_section)(module, ".modalias", size); } -static char *PERBIT(get_modinfo)(struct module *module, unsigned long *size) +static char *PERBIT(get_modinfo)(struct elf_file *module, unsigned long *size) { return PERBIT(load_section)(module, ".modinfo", size); } @@ -68,7 +68,8 @@ static char *PERBIT(get_modinfo)(struct module *module, unsigned long *size) #define STT_REGISTER 13 /* Global register reserved to app. */ #endif -static struct string_table *PERBIT(load_dep_syms)(struct module *module, +static struct string_table *PERBIT(load_dep_syms)(const char *pathname, + struct elf_file *module, struct string_table **types) { unsigned int i; @@ -88,7 +89,7 @@ static struct string_table *PERBIT(load_dep_syms)(struct module *module, if (!strings || !syms) { warn("Couldn't find symtab and strtab in module %s\n", - module->pathname); + pathname); return NULL; } @@ -144,7 +145,7 @@ static void *PERBIT(deref_sym)(ElfPERBIT(Ehdr) *hdr, } /* FIXME: Check size, unless we end up using aliases anyway --RR */ -static void PERBIT(fetch_tables)(struct module *module, +static void PERBIT(fetch_tables)(struct elf_file *module, struct module_tables *tables) { unsigned int i; @@ -51,7 +51,7 @@ void output_pci_table(struct module *modules, FILE *out, char *dirname) make_shortname(shortname, i->pathname); for (e = t->pci_table; e->vendor; e = (void *)e + t->pci_size) - output_pci_entry(e, shortname, out, i->conv); + output_pci_entry(e, shortname, out, i->file.conv); } } @@ -102,7 +102,7 @@ void output_usb_table(struct module *modules, FILE *out, char *dirname) for (e = t->usb_table; e->idVendor || e->bDeviceClass || e->bInterfaceClass; e = (void *)e + t->usb_size) - output_usb_entry(e, shortname, out, i->conv); + output_usb_entry(e, shortname, out, i->file.conv); } } @@ -136,7 +136,7 @@ void output_ieee1394_table(struct module *modules, FILE *out, char *dirname) make_shortname(shortname, i->pathname); for (fw = t->ieee1394_table; fw->match_flags; fw = (void *) fw + t->ieee1394_size) - output_ieee1394_entry(fw, shortname, out, i->conv); + output_ieee1394_entry(fw, shortname, out, i->file.conv); } } @@ -170,7 +170,7 @@ void output_ccw_table(struct module *modules, FILE *out, char *dirname) for (e = t->ccw_table; e->cu_type || e->cu_model || e->dev_type || e->dev_model; e = (void *) e + t->ccw_size) - output_ccw_entry(e, shortname, out, i->conv); + output_ccw_entry(e, shortname, out, i->file.conv); } } @@ -450,21 +450,21 @@ void output_input_table(struct module *modules, FILE *out, char *dirname) done = output_input_entry_64_old(p, shortname, out, - i->conv); + i->file.conv); break; case sizeof(struct input_device_id_64): done = output_input_entry_64(p, shortname, - out, i->conv); + out, i->file.conv); break; case sizeof(struct input_device_id_old_32): done = output_input_entry_32_old(p, shortname, out, - i->conv); + i->file.conv); break; case sizeof(struct input_device_id_32): done = output_input_entry_32(p, shortname, - out, i->conv); + out, i->file.conv); break; } } |