aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Marek <mmarek@suse.cz>2009-09-10 16:26:34 +0200
committerJon Masters <jcm@jonmasters.org>2009-10-01 02:21:14 -0400
commitd2cc5cecad6e754bb107c8a54c49a4868ac9995a (patch)
tree6fe1e5160e0038c974e71bf0961f82cd1b3fc2a9
parente553ec09e0c96e3c44ea8c341ac74ab2effc8463 (diff)
downloadmodule-init-tools-d2cc5cecad6e754bb107c8a54c49a4868ac9995a.tar.gz
modprobe: handle built-in modules (v4, this time tested...)
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@suse.cz> Signed-off-by: Jon Masters <jcm@jonmasters.org>
-rw-r--r--depmod.c39
-rw-r--r--modprobe.c40
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 a34709e..f97f17d 100644
--- a/modprobe.c
+++ b/modprobe.c
@@ -538,6 +538,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.
*/
@@ -1287,6 +1305,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,
@@ -1332,6 +1367,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);
+ }
}
}