mirror of
https://github.com/AuxXxilium/kmod.git
synced 2024-12-18 20:48:11 +07:00
Lookup modules from modules.dep.bin file
This commit is contained in:
parent
23fc91c642
commit
64700e4747
@ -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);
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user