int kmod_lookup_alias_from_aliases_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3)));
int kmod_lookup_alias_from_moddep_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3)));
int kmod_lookup_alias_from_builtin_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3)));
+bool kmod_lookup_alias_is_builtin(struct kmod_ctx *ctx, const char *name) __attribute__((nonnull(1, 2)));
int kmod_lookup_alias_from_commands(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3)));
void kmod_set_modules_visited(struct kmod_ctx *ctx, bool visited) __attribute__((nonnull((1))));
void kmod_set_modules_required(struct kmod_ctx *ctx, bool required) __attribute__((nonnull((1))));
void kmod_module_set_visited(struct kmod_module *mod, bool visited) __attribute__((nonnull(1)));
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)));
/* libkmod-file.c */
struct kmod_file *kmod_file_open(const struct kmod_ctx *ctx, const char *filename) _must_check_ __attribute__((nonnull(1,2)));
* @short_description: operate on kernel modules
*/
+enum kmod_module_builtin {
+ KMOD_MODULE_BUILTIN_UNKNOWN,
+ KMOD_MODULE_BUILTIN_NO,
+ KMOD_MODULE_BUILTIN_YES,
+};
+
/**
* kmod_module:
*
} init;
/*
+ * mark if module is builtin, i.e. it's present on modules.builtin
+ * file. This is set as soon as it is needed or as soon as we know
+ * about it, i.e. the module was created from builtin lookup.
+ */
+ enum kmod_module_builtin builtin;
+
+ /*
* private field used by kmod_module_get_probe_list() to detect
* dependency loops
*/
* is a softdep only
*/
bool required : 1;
-
- /*
- * if module was created by searching the modules.builtin file, this
- * is set. There's nothing much useful one can do with such a
- * "module", except knowing it's builtin.
- */
- bool builtin : 1;
};
static inline const char *path_join(const char *path, size_t prefixlen,
void kmod_module_set_builtin(struct kmod_module *mod, bool builtin)
{
- mod->builtin = builtin;
+ mod->builtin =
+ builtin ? KMOD_MODULE_BUILTIN_YES : KMOD_MODULE_BUILTIN_NO;
}
void kmod_module_set_required(struct kmod_module *mod, bool required)
mod->required = required;
}
+bool kmod_module_is_builtin(struct kmod_module *mod)
+{
+ if (mod->builtin == KMOD_MODULE_BUILTIN_UNKNOWN) {
+ kmod_module_set_builtin(mod,
+ kmod_lookup_alias_is_builtin(mod->ctx, mod->name));
+ }
+
+ return mod->builtin == KMOD_MODULE_BUILTIN_YES;
+}
/*
* Memory layout with alias:
*
module_is_blacklisted(mod))
continue;
- if ((filter_type & KMOD_FILTER_BUILTIN) && mod->builtin)
+ if ((filter_type & KMOD_FILTER_BUILTIN)
+ && kmod_module_is_builtin(mod))
continue;
node = kmod_list_append(*output, mod);
if (mod == NULL)
return -ENOENT;
- if (mod->builtin)
+ /* remove const: this can only change internal state */
+ if (kmod_module_is_builtin((struct kmod_module *)mod))
return KMOD_MODULE_BUILTIN;
pathlen = snprintf(path, sizeof(path),
struct stat st;
path[pathlen - (sizeof("/initstate") - 1)] = '\0';
if (stat(path, &st) == 0 && S_ISDIR(st.st_mode))
- return KMOD_MODULE_BUILTIN;
+ return KMOD_MODULE_COMING;
}
DBG(mod->ctx, "could not open '%s': %s\n",
name, list);
}
-int kmod_lookup_alias_from_builtin_file(struct kmod_ctx *ctx, const char *name,
- struct kmod_list **list)
+static char *lookup_builtin_file(struct kmod_ctx *ctx, const char *name)
{
- char *line = NULL;
- int err = 0;
-
- assert(*list == NULL);
+ char *line;
if (ctx->indexes[KMOD_INDEX_MODULES_BUILTIN]) {
DBG(ctx, "use mmaped index '%s' modname=%s\n",
idx = index_file_open(fn);
if (idx == NULL) {
DBG(ctx, "could not open builtin file '%s'\n", fn);
- goto finish;
+ return NULL;
}
line = index_search(idx, name);
index_file_close(idx);
}
+ return line;
+}
+
+int kmod_lookup_alias_from_builtin_file(struct kmod_ctx *ctx, const char *name,
+ struct kmod_list **list)
+{
+ char *line;
+ int err = 0;
+
+ assert(*list == NULL);
+
+ line = lookup_builtin_file(ctx, name);
if (line != NULL) {
struct kmod_module *mod;
goto finish;
}
+ /* already mark it as builtin since it's being created from
+ * this index */
kmod_module_set_builtin(mod, true);
*list = kmod_list_append(*list, mod);
if (*list == NULL)
return err;
}
+bool kmod_lookup_alias_is_builtin(struct kmod_ctx *ctx, const char *name)
+{
+ _cleanup_free_ char *line;
+
+ line = lookup_builtin_file(ctx, name);
+
+ return line != NULL;
+}
+
char *kmod_search_moddep(struct kmod_ctx *ctx, const char *name)
{
struct index_file *idx;