The kernel installs a modules.builtin file listing all builtin modules. Let depmod generate a modules.builtin.bin file and use this in modprobe: If a module is not found in modules.dep or modules.alias, check if the module is builtin and either do nothing, or print "builtin <module>" if --show-depends was given. Trying to remove a builtin module returns an error, as does inserting a builtin module with --first-time. Signed-off-by: Michal Marek <mmarek@xxxxxxx> --- depmod.c | 39 ++++++++++++++++++++++++++++++++++++++- modprobe.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletions(-) diff --git a/depmod.c b/depmod.c index 3ac5070..5b90b3a 100644 --- a/depmod.c +++ b/depmod.c @@ -825,6 +825,42 @@ static int output_symbols_bin(struct module *unused, FILE *out, char *dirname) return 1; } +static int output_builtin_bin(struct module *unused, FILE *out, char *dirname) +{ + struct index_node *index; + char *textfile, *line; + unsigned int linenum; + FILE *f; + + nofail_asprintf(&textfile, "%s/modules.builtin", dirname); + if (!(f = fopen(textfile, "r"))) { + if (errno != ENOENT) + fatal("Could not open '%s': %s\n", + textfile, strerror(errno)); + free(textfile); + return 0; + } + free(textfile); + index = index_create(); + + while ((line = getline_wrapped(f, &linenum)) != NULL) { + char *module = line; + + if (!*line || *line == '#') { + free(line); + continue; + } + filename2modname(module, module); + index_insert(index, module, "", 0); + free(line); + } + fclose(f); + index_write(index, out); + index_destroy(index); + + return 1; +} + static int output_aliases(struct module *modules, FILE *out, char *dirname) { struct module *i; @@ -932,7 +968,8 @@ static struct depfile depfiles[] = { { "modules.alias", output_aliases, 0 }, { "modules.alias.bin", output_aliases_bin, 0 }, { "modules.symbols", output_symbols, 0 }, - { "modules.symbols.bin", output_symbols_bin, 0 } + { "modules.symbols.bin", output_symbols_bin, 0 }, + { "modules.builtin.bin", output_builtin_bin, 0 }, }; /* If we can't figure it out, it's safe to say "true". */ diff --git a/modprobe.c b/modprobe.c index 21a3111..eeec286 100644 --- a/modprobe.c +++ b/modprobe.c @@ -537,6 +537,24 @@ static int read_attribute(const char *filename, char *buf, size_t buflen) return (s == NULL) ? -1 : 1; } +/* is this a built-in module? + * 0: no, 1: yes, -1: don't know + */ +static int module_builtin(const char *dirname, const char *modname) +{ + struct index_file *index; + char *filename, *value; + + nofail_asprintf(&filename, "%s/modules.builtin.bin", dirname); + index = index_file_open(filename); + free(filename); + if (!index) + return -1; + value = index_search(index, modname); + free(value); + return value ? 1 : 0; +} + /* Is module in /sys/module? If so, fill in usecount if not NULL. 0 means no, 1 means yes, -1 means unknown. */ @@ -1286,6 +1304,23 @@ static int handle_module(const char *modname, return 0; } +int handle_builtin_module(const char *modname, + errfn_t error, + modprobe_flags_t flags) +{ + if (flags & mit_remove) { + error("Module %s is builtin\n", modname); + return 1; + } else if (flags & mit_first_time) { + error("Module %s already in kernel (builtin).\n", modname); + return 1; + } else if (flags & mit_ignore_loaded) { + /* --show-depends given */ + info("builtin %s\n", modname); + } + return 0; +} + int do_modprobe(char *modname, char *newname, char *cmdline_opts, @@ -1331,6 +1366,11 @@ int do_modprobe(char *modname, modname, 0, flags & mit_remove, &modoptions, &commands, &aliases, &blacklist); + /* builtin module? */ + if (!aliases && module_builtin(dirname, modname) > 0) { + return handle_builtin_module(modname, error, + flags); + } } } -- 1.6.3.3 -- To unsubscribe from this list: send the line "unsubscribe linux-modules" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html