From 837014acd25834c885af7859b41198c896d7c00f Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Mon, 24 May 2010 16:15:05 +0200 Subject: [PATCH] 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: 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 --- depmod.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) 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". */ -- 2.11.4.GIT