aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2010-05-24 16:15:05 +0200
committerJon Masters <jcm@jonmasters.org>2010-05-25 14:53:50 -0400
commit837014acd25834c885af7859b41198c896d7c00f (patch)
treea890bb165605eed143ce73ad353453bc399672f1
parent58438d6fa97b00c4c86aa130869598229e92c267 (diff)
downloadmodule-init-tools-837014acd25834c885af7859b41198c896d7c00f.tar.gz
depmod: export static device node information to modules.devname
To be able to let udev support kernel module on-demand loading, the next kernel will export: alias: devname:<name> for some well-defined common kernel modules. This will let the kernel call modprobe when the device node is accessed, the subsystem/driver will be initialized and the open() of the device node will magically succeed. The static device node aliases will be carried in the module itself. depmod extracts this information: $ cat /lib/modules/2.6.34-00650-g537b60d-dirty/modules.devname # Device nodes to trigger on-demand module loading. microcode cpu/microcode c10:184 fuse fuse c10:229 ppp_generic ppp c108:0 tun net/tun c10:200 dm_mod mapper/control c10:235 Udev will pick up the depmod created file on startup and create all the static device nodes which the kernel modules specify, so that these modules get automatically loaded when the device node is accessed: $ /sbin/udevd --debug ... static_dev_create_from_modules: mknod '/dev/cpu/microcode' c10:184 static_dev_create_from_modules: mknod '/dev/fuse' c10:229 static_dev_create_from_modules: mknod '/dev/ppp' c108:0 static_dev_create_from_modules: mknod '/dev/net/tun' c10:200 static_dev_create_from_modules: mknod '/dev/mapper/control' c10:235 udev_rules_apply_static_dev_perms: chmod '/dev/net/tun' 0666 udev_rules_apply_static_dev_perms: chmod '/dev/fuse' 0666 Signed-off-by: Jon Masters <jcm@jonmasters.org>
-rw-r--r--depmod.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/depmod.c b/depmod.c
index 89e4c43..647e5e6 100644
--- a/depmod.c
+++ b/depmod.c
@@ -979,6 +979,43 @@ static int output_softdeps(struct module *modules, FILE *out, char *dirname)
return 1;
}
+static int output_devname(struct module *modules, FILE *out, char *dirname)
+{
+ struct module *m;
+
+ fprintf(out, "# Device nodes to trigger on-demand module loading.\n");
+ for (m = modules; m != NULL; m = m->next) {
+ struct string_table *tbl;
+ int i;
+ char type = '\0';
+ const char *devname = NULL;
+
+ tbl = m->file->ops->load_strings(m->file, ".modinfo", NULL);
+ for (i = 0; tbl && i < tbl->cnt; i++) {
+ const char *p = tbl->str[i];
+ unsigned int maj, min;
+
+ if (sscanf(p, "alias=char-major-%u-%u", &maj, &min) == 2)
+ type = 'c';
+ else if (sscanf(p, "alias=block-major-%u-%u", &maj, &min) == 2)
+ type = 'b';
+ else if (strstarts(p, "alias=devname:"))
+ devname = &p[strlen("alias=devname:")];
+
+ if (type && devname) {
+ char modname[strlen(m->pathname)+1];
+
+ filename2modname(modname, m->pathname);
+ fprintf(out, "%s %s %c%u:%u\n",
+ modname, devname, type, maj, min);
+ break;
+ }
+ }
+ strtbl_free(tbl);
+ }
+ return 1;
+}
+
struct depfile {
char *name;
int (*func)(struct module *, FILE *, char *dirname);
@@ -1002,6 +1039,7 @@ static struct depfile depfiles[] = {
{ "modules.symbols", output_symbols, 0 },
{ "modules.symbols.bin", output_symbols_bin, 0 },
{ "modules.builtin.bin", output_builtin_bin, 0 },
+ { "modules.devname", output_devname, 0 },
};
/* If we can't figure it out, it's safe to say "true". */