* Re: how to determine physical bus of a device and find it there
2004-01-20 2:52 how to determine physical bus of a device and find it there Kay Sievers
@ 2004-01-20 14:09 ` Olaf Hering
2004-01-22 22:40 ` Greg KH
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Olaf Hering @ 2004-01-20 14:09 UTC (permalink / raw)
To: linux-hotplug
On Tue, Jan 20, Kay Sievers wrote:
> Do we need some magic here :)
Maybe something like that, where D is pwd -P:
d="`echo $D | sed -e 's@/[^/]{1,}/host[0-9]{1,}/[0-9]{1,}:[0-9]{1,}:[0-9]{1,}:[0-9]{1,}@@'`"
But having a symlink inside the scsi target to the 'real' device would
fix not only this bug, also firewire would be usable.
--
USB is for mice, FireWire is for men!
sUse lINUX ag, n√úRNBERG
-------------------------------------------------------
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
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: how to determine physical bus of a device and find it there
2004-01-20 2:52 how to determine physical bus of a device and find it there Kay Sievers
2004-01-20 14:09 ` Olaf Hering
@ 2004-01-22 22:40 ` Greg KH
2004-01-22 22:58 ` Greg KH
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Greg KH @ 2004-01-22 22:40 UTC (permalink / raw)
To: linux-hotplug
On Tue, Jan 20, 2004 at 03:52:30AM +0100, Kay Sievers wrote:
>
> Hi,
> I want to collect all possible attributes of a device with the udevinfo
> program. This issue is also still unresolved with udev.
>
> We need to determine the device on its physical bus not only the logical.
> Here is a example for a usb-storage device with its logical 'scsi' and
> physical 'usb' bus:
>
> First I look in the hotplug provided directory and I find:
>
> /sys/block/sda
>
> SYSFS_dev="8:0"
> SYSFS_range="16"
> SYSFS_size="31360"
> SYSFS_stat=" 12 0 96 87 0 0 0 0 0 87 87"
>
> then following the "device" link, I get on the scsi bus
> /sys/devices/pci0000:00/0000:00:1d.0/usb1/1-1/1-1:1.0/host5/5:0:0:0
>
> SYSFS_detach_state="0"
> SYSFS_type="0"
> SYSFS_vendor="SMSC "
> SYSFS_device_blocked="0"
> SYSFS_queue_depth="1"
> SYSFS_scsi_level="3"
> SYSFS_model="USB 2 HS-CF"
> SYSFS_rev="1.25"
> SYSFS_online="1"
>
> but the really interesting attributes are on the usb bus:
> /sys/devices/pci0000:00/0000:00:1d.0/usb1/1-1':
>
> SYSFS_detach_state="0"
> SYSFS_bNumConfigurations="1"
> SYSFS_bNumInterfaces=" 1"
> SYSFS_bConfigurationValue="1"
> SYSFS_bmAttributes="80"
> SYSFS_bMaxPower=" 48mA"
> SYSFS_idVendor="0424"
> SYSFS_idProduct="20fc"
> SYSFS_bcdDevice="0125"
> SYSFS_bDeviceClass="00"
> SYSFS_bDeviceSubClass="00"
> SYSFS_bDeviceProtocol="00"
> SYSFS_speed="12"
> SYSFS_manufacturer="SMSC"
> SYSFS_product="USB 2 Flash Media Device"
> SYSFS_serial="0305037000C2"
>
>
> So, how do I reliable get there?
We need to set up a "stack" (for lack of a better word) of sysfs
devices. We can now do this with some libsysfs calls.
So for your example, we would create the following device "stack"
- class device "scsi" located at /sys/block/sda
- main device structure on bus "scsi" at /sys/devices/pci0000:00/0000:00:1d.0/usb1/1-1/1-1:1.0/host5/5:0:0:0
- device of bus type "scsi host" at /sys/devices/pci0000:00/0000:00:1d.0/usb1/1-1/1-1:1.0/host5
- device of bus type "usb" at /sys/devices/pci0000:00/0000:00:1d.0/usb1/1-1/1-1:1.0
- device of bus type "usb" at /sys/devices/pci0000:00/0000:00:1d.0/usb1/1-1
- device of bus type "usb" at /sys/devices/pci0000:00/0000:00:1d.0/usb1
- device of bus type "pci" at /sys/devices/pci0000:00/0000:00:1d.0
- device of bus type "pci" at /sys/devices/pci0000:00
Note that the first usb device we find is really a usb interface device,
not the main usb device itself. That is going to mess with some
people's minds until they realize that usb drivers bind to usb
interfaces, not the the device itself (a usb device may have lots of usb
interfaces, all with different drivers, like a speaker with a audio and
a hid driver bound to different interfaces.)
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.
Does that make more sense now?
thanks,
greg k-h
-------------------------------------------------------
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
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: how to determine physical bus of a device and find it there
2004-01-20 2:52 how to determine physical bus of a device and find it there Kay Sievers
2004-01-20 14:09 ` Olaf Hering
2004-01-22 22:40 ` Greg KH
@ 2004-01-22 22:58 ` Greg KH
2004-01-22 23:27 ` Kay Sievers
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Greg KH @ 2004-01-22 22:58 UTC (permalink / raw)
To: linux-hotplug
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
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: how to determine physical bus of a device and find it there
2004-01-20 2:52 how to determine physical bus of a device and find it there Kay Sievers
` (2 preceding siblings ...)
2004-01-22 22:58 ` Greg KH
@ 2004-01-22 23:27 ` Kay Sievers
2004-01-22 23:42 ` Kay Sievers
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Kay Sievers @ 2004-01-22 23:27 UTC (permalink / raw)
To: linux-hotplug
On Thu, Jan 22, 2004 at 02:58:35PM -0800, Greg KH wrote:
> 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.
Oh, I like goto's too. :)
Cool, works for me.
Maybe "try_parent:" sounds better than "no_good" :)
I will port it to udevinfo and print the keys with its correspondig BUS,
so it should be easy for the user to build a rule.
Btw. another question, do you know why this ugly multiline info is here?
Doesn't it violate the sysfs conventions?
kay@pim:/sys$ cat ./devices/pci0000:00/0000:00:1d.0/usb1/1-1/1-1.3/1-1.3:1.0/host32/32:0:0:1/info
Host scsi32: usb-storage
Vendor: SMSC
Product: USB 2 Flash Media Device
Serial Number: 0305037000C2
Protocol: Transparent SCSI
Transport: Bulk
Quirks:
thanks,
Kay
-------------------------------------------------------
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
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: how to determine physical bus of a device and find it there
2004-01-20 2:52 how to determine physical bus of a device and find it there Kay Sievers
` (3 preceding siblings ...)
2004-01-22 23:27 ` Kay Sievers
@ 2004-01-22 23:42 ` Kay Sievers
2004-01-23 1:42 ` Greg KH
2004-01-23 1:43 ` Greg KH
6 siblings, 0 replies; 8+ messages in thread
From: Kay Sievers @ 2004-01-22 23:42 UTC (permalink / raw)
To: linux-hotplug
On Thu, Jan 22, 2004 at 02:40:46PM -0800, Greg KH wrote:
> On Tue, Jan 20, 2004 at 03:52:30AM +0100, Kay Sievers wrote:
> >
> > but the really interesting attributes are on the usb bus:
> > /sys/devices/pci0000:00/0000:00:1d.0/usb1/1-1':
> >
> > SYSFS_manufacturer="SMSC"
> > SYSFS_product="USB 2 Flash Media Device"
> > SYSFS_serial="0305037000C2"
> >
> >
> > So, how do I reliable get there?
>
> We need to set up a "stack" (for lack of a better word) of sysfs
> devices. We can now do this with some libsysfs calls.
Oh, my english is not quite good, but for me it sounds like a 'chain'?
> 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.
>
> Does that make more sense now?
Yes, I'm happy now.
And libsysfs is very helpful here. Nice work, guys.
thanks,
Kay
-------------------------------------------------------
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
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: how to determine physical bus of a device and find it there
2004-01-20 2:52 how to determine physical bus of a device and find it there Kay Sievers
` (4 preceding siblings ...)
2004-01-22 23:42 ` Kay Sievers
@ 2004-01-23 1:42 ` Greg KH
2004-01-23 1:43 ` Greg KH
6 siblings, 0 replies; 8+ messages in thread
From: Greg KH @ 2004-01-23 1:42 UTC (permalink / raw)
To: linux-hotplug
On Fri, Jan 23, 2004 at 12:27:23AM +0100, Kay Sievers wrote:
> On Thu, Jan 22, 2004 at 02:58:35PM -0800, Greg KH wrote:
> > 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.
>
> Oh, I like goto's too. :)
>
> Cool, works for me.
> Maybe "try_parent:" sounds better than "no_good" :)
I cleaned the code up a bit more and checked it in, but perhaps that
change would be nice too :)
> I will port it to udevinfo and print the keys with its correspondig BUS,
> so it should be easy for the user to build a rule.
Nice.
> Btw. another question, do you know why this ugly multiline info is here?
> Doesn't it violate the sysfs conventions?
{sigh} Yeah it does. Time to get out my big stick and go after the
scsi people again... Ick, wait, I just accepted that patch from the usb
storage people... I'll go fix that...
thanks,
greg k-h
-------------------------------------------------------
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
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: how to determine physical bus of a device and find it there
2004-01-20 2:52 how to determine physical bus of a device and find it there Kay Sievers
` (5 preceding siblings ...)
2004-01-23 1:42 ` Greg KH
@ 2004-01-23 1:43 ` Greg KH
6 siblings, 0 replies; 8+ messages in thread
From: Greg KH @ 2004-01-23 1:43 UTC (permalink / raw)
To: linux-hotplug
On Fri, Jan 23, 2004 at 12:42:36AM +0100, Kay Sievers wrote:
> On Thu, Jan 22, 2004 at 02:40:46PM -0800, Greg KH wrote:
> > On Tue, Jan 20, 2004 at 03:52:30AM +0100, Kay Sievers wrote:
> > >
> > > but the really interesting attributes are on the usb bus:
> > > /sys/devices/pci0000:00/0000:00:1d.0/usb1/1-1':
> > >
> > > SYSFS_manufacturer="SMSC"
> > > SYSFS_product="USB 2 Flash Media Device"
> > > SYSFS_serial="0305037000C2"
> > >
> > >
> > > So, how do I reliable get there?
> >
> > We need to set up a "stack" (for lack of a better word) of sysfs
> > devices. We can now do this with some libsysfs calls.
>
> Oh, my english is not quite good, but for me it sounds like a 'chain'?
Yes, that is a much better name for that, thanks.
greg k-h
-------------------------------------------------------
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
^ permalink raw reply [flat|nested] 8+ messages in thread