]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
Lookup modules from modules.dep.bin file
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Thu, 1 Dec 2011 17:57:53 +0000 (15:57 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Thu, 1 Dec 2011 17:58:12 +0000 (15:58 -0200)
libkmod/libkmod-module.c
libkmod/libkmod-private.h
libkmod/libkmod.c

index fdfcf45f90326f5ed9f56b169f2fb8edbbd91db3..e0dfc0734c22d5d58b1664c1991c5150b9ed7a8d 100644 (file)
@@ -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);
 
index af1c93eb24601e7b739134e3979d9efa4b870b22..c7ee24eb1a0638365abfd4cd05ee4f207208e86b 100644 (file)
@@ -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 {
index f8d5935361fca2a35f92989c931fe2b270b80a48..612a12ae066adf535e11c8ee9dbef63daa662f64 100644 (file)
@@ -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)
 {