From 64700e4747d4331a8c833f234246128b9069a888 Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Thu, 1 Dec 2011 15:57:53 -0200 Subject: [PATCH] Lookup modules from modules.dep.bin file --- libkmod/libkmod-module.c | 4 +++- libkmod/libkmod-private.h | 1 + libkmod/libkmod.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index fdfcf45..e0dfc07 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -170,7 +170,6 @@ KMOD_EXPORT int kmod_module_new_from_lookup(struct kmod_ctx *ctx, if (ctx == NULL || alias == NULL) return -ENOENT; - if (list == NULL || *list != NULL) { ERR(ctx, "An empty list is needed to create lookup\n"); return -ENOSYS; @@ -180,6 +179,9 @@ KMOD_EXPORT int kmod_module_new_from_lookup(struct kmod_ctx *ctx, err = kmod_lookup_alias_from_config(ctx, alias, list); CHECK_ERR_AND_FINISH(err, fail, list, finish); + err = kmod_lookup_alias_from_moddep_file(ctx, alias, list); + CHECK_ERR_AND_FINISH(err, fail, list, finish); + err = kmod_lookup_alias_from_symbols_file(ctx, alias, list); CHECK_ERR_AND_FINISH(err, fail, list, finish); diff --git a/libkmod/libkmod-private.h b/libkmod/libkmod-private.h index af1c93e..c7ee24e 100644 --- a/libkmod/libkmod-private.h +++ b/libkmod/libkmod-private.h @@ -58,6 +58,7 @@ struct kmod_list *kmod_list_remove_n_latest(struct kmod_list *list, const char *kmod_get_dirname(struct kmod_ctx *ctx) __attribute__((nonnull(1))); int kmod_lookup_alias_from_config(struct kmod_ctx *ctx, const char *name, struct kmod_list **list); int kmod_lookup_alias_from_symbols_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list); +int kmod_lookup_alias_from_moddep_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list); /* libkmod-config.c */ struct kmod_config { diff --git a/libkmod/libkmod.c b/libkmod/libkmod.c index f8d5935..612a12a 100644 --- a/libkmod/libkmod.c +++ b/libkmod/libkmod.c @@ -317,6 +317,54 @@ fail: return err; } +static const char *moddep_file = "modules.dep"; + +int kmod_lookup_alias_from_moddep_file(struct kmod_ctx *ctx, const char *name, + struct kmod_list **list) +{ + char *fn, *line, *p; + struct index_file *index; + int n = 0; + + /* + * Module names do not contain ':'. Return early if we know it will + * not be found. + */ + if (strchr(name, ':')) + return 0; + + if (asprintf(&fn, "%s/%s.bin", ctx->dirname, moddep_file) < 0) + return -ENOMEM; + + DBG(ctx, "file=%s modname=%s", fn, name); + + index = index_file_open(fn); + if (index == NULL) { + free(fn); + return -ENOSYS; + } + + line = index_search(index, name); + if (line != NULL) { + struct kmod_module *mod; + + n = kmod_module_new_from_name(ctx, name, &mod); + if (n < 0) { + ERR(ctx, "%s\n", strerror(-n)); + goto finish; + } + + *list = kmod_list_append(*list, mod); + } + +finish: + free(line); + index_file_close(index); + free(fn); + + return n; +} + int kmod_lookup_alias_from_config(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) { -- 2.7.4