From mboxrd@z Thu Jan 1 00:00:00 1970 From: Greg KH Date: Thu, 22 Jan 2004 22:58:35 +0000 Subject: Re: how to determine physical bus of a device and find it there Message-Id: <20040122225835.GA15928@kroah.com> List-Id: References: <20040120025230.GA26199@vrfy.org> In-Reply-To: <20040120025230.GA26199@vrfy.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: linux-hotplug@vger.kernel.org On Thu, Jan 22, 2004 at 02:40:46PM -0800, Greg KH wrote: > > So what udev needs to do is look at each device along that "stack" in > order to get a match. If a user specifies a idProduct sysfs file that > is on the usb device at > /sys/devices/pci0000:00/0000:00:1d.0/usb1/1-1/1-1:1.0 we should be able > to match that up with this scsi block device, if so asked. > > It would also "solve" the problem where someone wanted to specify the > idProduct and idVendor for a usb printer, but udev couldn't find it. And here's a horrible abuse of gotos that adds this support to udev. I'll go clean it up in a bit, but I'm actually amazed that this wasn't that hard... thanks, greg k-h --- 1.95/namedev.c Wed Jan 21 16:54:51 2004 +++ edited/namedev.c Thu Jan 22 14:53:41 2004 @@ -588,6 +588,7 @@ int namedev_name_device(struct sysfs_class_device *class_dev, struct udevice *udev) { struct sysfs_device *sysfs_device = NULL; + struct sysfs_device *s_device = NULL; struct config_device *dev; struct perm_device *perm; char *pos; @@ -619,16 +620,18 @@ list_for_each_entry(dev, &config_device_list, node) { dbg("process rule"); + s_device = sysfs_device; +loop: /* check for matching bus value */ if (dev->bus[0] != '\0') { - if (sysfs_device = NULL) { + if (s_device = NULL) { dbg("device has no bus"); - continue; + goto no_good; } - dbg("check for " FIELD_BUS " dev->bus='%s' sysfs_device->bus='%s'", dev->bus, sysfs_device->bus); - if (strcmp_pattern(dev->bus, sysfs_device->bus) != 0) { + dbg("check for " FIELD_BUS " dev->bus='%s' s_device->bus='%s'", dev->bus, s_device->bus); + if (strcmp_pattern(dev->bus, s_device->bus) != 0) { dbg(FIELD_BUS " is not matching"); - continue; + goto no_good; } else { dbg(FIELD_BUS " matches"); } @@ -639,7 +642,7 @@ dbg("check for " FIELD_KERNEL " dev->kernel='%s' class_dev->name='%s'", dev->kernel, class_dev->name); if (strcmp_pattern(dev->kernel, class_dev->name) != 0) { dbg(FIELD_KERNEL " is not matching"); - continue; + goto no_good; } else { dbg(FIELD_KERNEL " matches"); } @@ -648,9 +651,9 @@ /* check for matching bus id */ if (dev->id[0] != '\0') { dbg("check " FIELD_ID); - if (match_id(dev, class_dev, sysfs_device) != 0) { + if (match_id(dev, class_dev, s_device) != 0) { dbg(FIELD_ID " is not matching"); - continue; + goto no_good; } else { dbg(FIELD_ID " matches"); } @@ -659,9 +662,9 @@ /* check for matching place of device */ if (dev->place[0] != '\0') { dbg("check " FIELD_PLACE); - if (match_place(dev, class_dev, sysfs_device) != 0) { + if (match_place(dev, class_dev, s_device) != 0) { dbg(FIELD_PLACE " is not matching"); - continue; + goto no_good; } else { dbg(FIELD_PLACE " matches"); } @@ -670,9 +673,9 @@ /* check for matching sysfs pairs */ if (dev->sysfs_pair[0].file[0] != '\0') { dbg("check " FIELD_SYSFS " pairs"); - if (match_sysfs_pairs(dev, class_dev, sysfs_device) != 0) { + if (match_sysfs_pairs(dev, class_dev, s_device) != 0) { dbg(FIELD_SYSFS " is not matching"); - continue; + goto no_good; } else { dbg(FIELD_SYSFS " matches"); } @@ -684,7 +687,7 @@ apply_format(udev, dev->program); if (execute_program(dev->program, udev->program_result, NAME_SIZE) != 0) { dbg(FIELD_PROGRAM " returned nozero"); - continue; + goto no_good; } else { dbg(FIELD_PROGRAM " returned successful"); } @@ -697,7 +700,7 @@ dev->result, udev->program_result); if (strcmp_pattern(dev->result, udev->program_result) != 0) { dbg(FIELD_RESULT " is not matching"); - continue; + goto no_good; } else { dbg(FIELD_RESULT " matches"); } @@ -715,6 +718,13 @@ strfieldcpy(udev->name, dev->name); strfieldcpy(udev->symlink, dev->symlink); goto found; + +no_good: + s_device = sysfs_get_device_parent(s_device); + if (s_device = NULL) + continue; + goto loop; + } /* no rule was found so we use the kernel name */ ------------------------------------------------------- The SF.Net email is sponsored by EclipseCon 2004 Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA. http://www.eclipsecon.org/osdn _______________________________________________ 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