linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] add USB coldplay support into udevstart
@ 2005-08-07 20:55 Thierry Vignaud
  2005-08-08 13:12 ` Greg KH
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: Thierry Vignaud @ 2005-08-07 20:55 UTC (permalink / raw)
  To: linux-hotplug

[-- Attachment #1: Type: text/plain, Size: 109 bytes --]

the following patch from Olivier Blin adds USB coldplay support into
udevstart (patch is against udev-065):


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: udev-065-usb-coldplug.patch --]
[-- Type: text/x-patch, Size: 2392 bytes --]

--- 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();

[-- Attachment #3: Type: text/plain, Size: 96 bytes --]


btw, note that according to olivier, there's code from udev_event.c
duplicated in udevstartc.c

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2005-08-10 15:06 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-07 20:55 [PATCH] add USB coldplay support into udevstart Thierry Vignaud
2005-08-08 13:12 ` Greg KH
2005-08-08 13:49 ` Greg KH
2005-08-08 14:21 ` Greg KH
2005-08-08 16:09 ` Kay Sievers
2005-08-08 16:14 ` Thierry Vignaud
2005-08-08 16:17 ` Kay Sievers
2005-08-08 16:30 ` Olaf Hering
2005-08-08 19:40 ` Greg KH
2005-08-10 10:59 ` Olivier Blin
2005-08-10 14:47 ` Kay Sievers
2005-08-10 15:06 ` Marco d'Itri

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).