From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thierry Vignaud Date: Sun, 07 Aug 2005 20:55:16 +0000 Subject: [PATCH] add USB coldplay support into udevstart Message-Id: MIME-Version: 1 Content-Type: multipart/mixed; boundary="=-=-=" List-Id: To: linux-hotplug@vger.kernel.org --=-=-= the following patch from Olivier Blin adds USB coldplay support into udevstart (patch is against udev-065): --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=udev-065-usb-coldplug.patch --- udev-065/udevstart.c.usb-coldplug 2005-08-02 22:56:41.000000000 +0200 +++ udev-065/udevstart.c 2005-08-06 13:49:17.000000000 +0200 @@ -138,11 +138,20 @@ udev_init_device(&udev, devpath, subsystem, "add"); udev.devt = get_devt(class_dev); - if (!udev.devt && udev.type != DEV_NET) { - dbg("sysfs_open_class_device_path failed"); + if (udev.devt || udev.type == DEV_NET) { + udev_rules_get_name(&rules, &udev, class_dev); + } else if (udev.type == DEV_DEVICE) { + struct sysfs_device *sysfs_dev; + sysfs_dev = sysfs_open_device_path(path); + if (sysfs_dev == NULL) { + dbg("sysfs_open_device_path failed"); + return -1; + } + udev_rules_get_run(&rules, &udev, NULL, sysfs_dev); + } else { + dbg("get_devt failed"); return -1; } - udev_rules_get_name(&rules, &udev, class_dev); if (udev.ignore_device) { dbg("device event will be ignored"); goto exit; @@ -329,6 +338,59 @@ exec_list(&device_list); } +static int has_modalias(const char *directory) +{ + char filename[PATH_SIZE]; + struct stat statbuf; + + snprintf(filename, sizeof(filename), "%s/modalias", directory); + filename[sizeof(filename)-1] = '\0'; + + if (stat(filename, &statbuf) == 0) + return 1; + + return 0; +} + +static void udev_scan_usb(void) +{ + char base[PATH_SIZE]; + DIR *dir; + struct dirent *dent; + LIST_HEAD(device_list); + + snprintf(base, sizeof(base), "%s/bus/usb/devices", sysfs_path); + base[sizeof(base)-1] = '\0'; + + dir = opendir(base); + if (dir != NULL) { + for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) { + char linkname[PATH_SIZE]; + char dirname_short[PATH_SIZE]; + char *dirname = NULL; + + if (dent->d_name[0] == '.') + continue; + + snprintf(linkname, sizeof(linkname), "%s/%s", base, dent->d_name); + linkname[sizeof(linkname)-1] = '\0'; + + if (has_modalias(linkname)) { + int ret = readlink(linkname, dirname_short, PATH_SIZE); + if (ret > 8) { + dirname_short[ret] = '\0'; + /* replace ../../.. with /sys */ + dirname = dirname_short + 4; + memcpy(dirname, "/sys", 4); + device_list_insert(dirname, "usb", &device_list); + } + } + } + closedir(dir); + } + exec_list(&device_list); +} + static void asmlinkage sig_handler(int signum) { switch (signum) { @@ -371,6 +433,7 @@ udev_scan_block(); udev_scan_class(); + udev_scan_usb(); udev_rules_close(&rules); logging_close(); --=-=-= btw, note that according to olivier, there's code from udev_event.c duplicated in udevstartc.c --=-=-=-- ------------------------------------------------------- SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel