Lookup modules from modules.dep.bin file
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 @@
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 @@
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 @@
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 @@
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)
{