From: Thierry Vignaud <tvignaud@mandriva.com>
To: linux-hotplug@vger.kernel.org
Subject: [PATCH] add USB coldplay support into udevstart
Date: Sun, 07 Aug 2005 20:55:16 +0000 [thread overview]
Message-ID: <m2ll3dxya3.fsf@vador.mandriva.com> (raw)
[-- 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
next reply other threads:[~2005-08-07 20:55 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-08-07 20:55 Thierry Vignaud [this message]
2005-08-08 13:12 ` [PATCH] add USB coldplay support into udevstart 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2ll3dxya3.fsf@vador.mandriva.com \
--to=tvignaud@mandriva.com \
--cc=linux-hotplug@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).