[PATCH 2/2] modprobe: handle built-in modules (v2)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

Signed-off-by: Michal Marek <mmarek@xxxxxxx>
---
 depmod.c   |   46 +++++++++++++++++++++++++++++++++++++++++++++-
 modprobe.c |   31 +++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+), 1 deletions(-)

diff --git a/depmod.c b/depmod.c
index 3ac5070..43ff28f 100644
--- a/depmod.c
+++ b/depmod.c
@@ -825,6 +825,49 @@ 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 = strrchr(line, '/');
+
+		if (!*line || *line == '#') {
+			free(line);
+			continue;
+		}
+		module = strrchr(line, '/');
+		if (module)
+			module++;
+		else
+			module = line;
+		if (ends_in(module, ".ko"))
+			module[strlen(module) - 3] = '\0';
+		underscores(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 +975,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..ffcceb3 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.
  */
@@ -1331,6 +1349,19 @@ int do_modprobe(char *modname,
 					  modname, 0, flags & mit_remove,
 					  &modoptions, &commands,
 					  &aliases, &blacklist);
+			/* builtin module? */
+			if (!aliases && !(flags & mit_remove) &&
+			    module_builtin(dirname, modname) == 1) {
+				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;
+			}
 		}
 	}
 
-- 
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

[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux