summaryrefslogtreecommitdiff
path: root/libkmod
diff options
context:
space:
mode:
authorAlexey Gladkov <gladkov.alexey@gmail.com>2019-11-08 18:25:21 +0100
committerLucas De Marchi <lucas.demarchi@intel.com>2019-12-18 16:56:36 -0800
commit73eed2aba3cbe18bbda40f18f7bc32e8de1ec81f (patch)
treea39568885154ab8481f7ef47b26cdb93000b57da /libkmod
parent60084cf1cb24dc3a257976c0d539a4c3ffda5db5 (diff)
downloadkmod-73eed2aba3cbe18bbda40f18f7bc32e8de1ec81f.tar.gz
kmod-73eed2aba3cbe18bbda40f18f7bc32e8de1ec81f.tar.bz2
kmod-73eed2aba3cbe18bbda40f18f7bc32e8de1ec81f.zip
libkmod: Add function to get list of built-in modules
Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
Diffstat (limited to 'libkmod')
-rw-r--r--libkmod/libkmod-internal.h1
-rw-r--r--libkmod/libkmod-module.c40
2 files changed, 41 insertions, 0 deletions
diff --git a/libkmod/libkmod-internal.h b/libkmod/libkmod-internal.h
index df01df1..ee4b97b 100644
--- a/libkmod/libkmod-internal.h
+++ b/libkmod/libkmod-internal.h
@@ -145,6 +145,7 @@ void kmod_module_set_visited(struct kmod_module *mod, bool visited) __attribute_
void kmod_module_set_builtin(struct kmod_module *mod, bool builtin) __attribute__((nonnull((1))));
void kmod_module_set_required(struct kmod_module *mod, bool required) __attribute__((nonnull(1)));
bool kmod_module_is_builtin(struct kmod_module *mod) __attribute__((nonnull(1)));
+int kmod_module_get_builtin(struct kmod_ctx *ctx, struct kmod_list **list) __attribute__((nonnull(1, 2)));
/* libkmod-file.c */
struct kmod_file *kmod_file_open(const struct kmod_ctx *ctx, const char *filename) _must_check_ __attribute__((nonnull(1,2)));
diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c
index bffe715..8fbabd2 100644
--- a/libkmod/libkmod-module.c
+++ b/libkmod/libkmod-module.c
@@ -2866,3 +2866,43 @@ KMOD_EXPORT void kmod_module_dependency_symbols_free_list(struct kmod_list *list
list = kmod_list_remove(list);
}
}
+
+/**
+ * kmod_module_get_builtin:
+ * @ctx: kmod library context
+ * @list: where to save the builtin module list
+ *
+ * Returns: 0 on success or < 0 otherwise.
+ */
+int kmod_module_get_builtin(struct kmod_ctx *ctx, struct kmod_list **list)
+{
+ struct kmod_builtin_iter *iter;
+ int err = 0;
+
+ iter = kmod_builtin_iter_new(ctx);
+ if (!iter)
+ return -errno;
+
+ while (kmod_builtin_iter_next(iter)) {
+ struct kmod_module *mod = NULL;
+ char modname[PATH_MAX];
+
+ if (!kmod_builtin_iter_get_modname(iter, modname)) {
+ err = -errno;
+ goto fail;
+ }
+
+ kmod_module_new_from_name(ctx, modname, &mod);
+ kmod_module_set_builtin(mod, true);
+
+ *list = kmod_list_append(*list, mod);
+ }
+
+ kmod_builtin_iter_free(iter);
+ return err;
+fail:
+ kmod_builtin_iter_free(iter);
+ kmod_module_unref_list(*list);
+ *list = NULL;
+ return err;
+}