Export information to /sbin/hotplug for PCMCIA devices: card_id, manf_id, func_id, bus_id (like pcmcia1.0) and crc32-hashes of the prod_id strings. Why not the prod_id strings themselves? a) They may contain all sorts of strange and difficult to handle characters, like " ". b) It's impossible to pass multiple strings to userspace. Signed-off-by: Dominik Brodowski --- drivers/pcmcia/ds.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 84 insertions(+) Index: 2.6.10-rc3/drivers/pcmcia/ds.c =================================================================== --- 2.6.10-rc3.orig/drivers/pcmcia/ds.c 2004-12-14 00:06:54.874528195 +0100 +++ 2.6.10-rc3/drivers/pcmcia/ds.c 2004-12-14 00:08:58.974245479 +0100 @@ -35,6 +35,7 @@ #include #include #include +#include #include @@ -602,6 +603,97 @@ return 0; } +#ifdef CONFIG_HOTPLUG + +static int pcmcia_bus_hotplug(struct device *dev, char **envp, int num_envp, + char *buffer, int buffer_size) +{ + struct pcmcia_device *p_dev; + char *scratch; + int i, length = 0; + u32 hash[4] = { 0, 0, 0, 0}; + + if (!dev) + return -ENODEV; + + p_dev = to_pcmcia_dev(dev); + + /* calculate hashes */ + for (i=0; i<4; i++) { + if (!p_dev->prod_id[i]) + continue; + hash[i] = crc32(0, p_dev->prod_id[i], strlen(p_dev->prod_id[i])); + } + + scratch = buffer; + + /* stuff we want to pass to /sbin/hotplug */ + envp[i++] = scratch; + length += scnprintf (scratch, buffer_size - length, + "PCMCIA_DEVICE=%01X", + p_dev->device_no); + if ((buffer_size - length <= 0) || (i >= num_envp)) + return -ENOMEM; + ++length; + scratch += length; + + envp[i++] = scratch; + length += scnprintf (scratch, buffer_size - length, + "PCMCIA_DEVICE_FUNC=%01X", + p_dev->func); + if ((buffer_size - length <= 0) || (i >= num_envp)) + return -ENOMEM; + ++length; + scratch += length; + + envp[i++] = scratch; + length += scnprintf (scratch, buffer_size - length, "PCMCIA_FUNC_ID=%01X", + p_dev->has_func_id ? p_dev->func_id : 0); + if ((buffer_size - length <= 0) || (i >= num_envp)) + return -ENOMEM; + ++length; + scratch += length; + + envp[i++] = scratch; + length += scnprintf (scratch, buffer_size - length, "PCMCIA_ID=%04X:%04X", + p_dev->has_manf_id ? p_dev->manf_id : 0, + p_dev->has_card_id ? p_dev->card_id : 0); + if ((buffer_size - length <= 0) || (i >= num_envp)) + return -ENOMEM; + ++length; + scratch += length; + + envp[i++] = scratch; + length += scnprintf (scratch, buffer_size - length, + "PCMCIA_PRODUCT=%04X:%04X:%04X:%04X", + hash[0], hash[1], hash[2], hash[3]); + if ((buffer_size - length <= 0) || (i >= num_envp)) + return -ENOMEM; + ++length; + scratch += length; + + envp[i++] = scratch; + length += scnprintf (scratch, buffer_size - length, + "PCMCIA_SLOT_NAME=%s", + p_dev->dev.bus_id); + if ((buffer_size - length <= 0) || (i >= num_envp)) + return -ENOMEM; + + envp[i] = NULL; + + return 0; +} + +#else + +static int pcmcia_bus_hotplug(struct device *dev, char **envp, int num_envp, + char *buffer, int buffer_size) +{ + return -ENODEV; +} + +#endif + /************************ per-device sysfs output ***************************/ #define pcmcia_device_attr(field, test, format) \ @@ -1612,6 +1704,7 @@ struct bus_type pcmcia_bus_type = { .name = "pcmcia", + .hotplug = pcmcia_bus_hotplug, .match = pcmcia_bus_match, .dev_attrs = pcmcia_dev_attrs, };