* How to obtain sysfs-path from bus_info
[not found] ` <200901221657.37189.laurent.pinchart@skynet.be>
@ 2009-01-23 13:59 ` Carsten Meier
[not found] ` <4978E128.3050701@free.fr>
1 sibling, 0 replies; 2+ messages in thread
From: Carsten Meier @ 2009-01-23 13:59 UTC (permalink / raw)
To: Laurent Pinchart; +Cc: linux-media
Am Thu, 22 Jan 2009 16:57:36 +0100
schrieb Laurent Pinchart <laurent.pinchart@skynet.be>:
> On Thursday 22 January 2009, Carsten Meier wrote:
> > Am Thu, 22 Jan 2009 00:20:00 +0100
> >
> > schrieb Laurent Pinchart <laurent.pinchart@skynet.be>:
> > > Hi Carsten,
> > >
> > > On Wednesday 21 January 2009, Carsten Meier wrote:
> > > > now I want to translate bus_info into a sysfs-path to obtain
> > > > device-info like serial numbers. Given a device reports
> > > > "usb-0000:00:1d.2-2" as bus_info, then the device-info is
> > > > located under "/sys/bus/usb/devices/2-2", which is a symlink to
> > > > the appropriate /sys/devices/ directory, right?
> > >
> > > I'm afraid not. In the above bus_info value, 0000:00:1d.2 is the
> > > PCI bus path of your USB controller, and the last digit after the
> > > dash is the USB device path.
> > >
> > > > All I have to do is to compare the first 4 chars of bus_info
> > > > against "usb-", get the chars after "." and append it to
> > > > "/sys/bus/usb/devices/" to obatin a sysfs-path, right?
> > > >
> > > > Is there a more elegant solution or already a function for
> > > > this? Can the "." appear more than once before the last one?
> > >
> > > Probably not before, but definitely after.
> > >
> > > Root hubs get a USB device path set to '0'. Every other device is
> > > numbered according to the hub port number it is connected to. If
> > > you have an external hub connected on port 2 of your root hub,
> > > and have a webcam connected to port 3 of the external hub,
> > > usb_make_path() will return "usb-0000:00:1d.2-2.3".
> > >
> > > Cheers,
> > >
> > > Laurent Pinchart
> >
> > Hi,
> >
> > On my machine, my pvrusb2 (connected directly to my mini-pc) shows
> > up under "/sys/bus/usb/devices/7-2/" which is a symbolic link to
> > "../../../devices/pci0000:00/0000:00:1d.7/usb7/7-2"
>
> You're just lucky that USB bus 7 (usb7/7) is connected to the 7th
> function of your USB host controller (1d.7).
>
> Here's an example of what I get on my computer:
>
> /sys/bus/usb/devices/4-2
> -> ../../../devices/pci0000:00/0000:00:1d.2/usb4/4-2
>
> > I can't test for the new bus_info-string, because it's not fixed
> > yet in the driver. But if I got it correctly it should be
> > "usb-0000:00:1d.7-7.2" ?
>
> I think you will get usb-0000:00:1d.7-2
>
> > Then I've to simply take the string after the last dash, replace
> > "." by "-" and append it to "/sys/bus/usb/devices/" for a
> > sysfs-path?
>
> Unfortunately the mapping is not that direct. The part before the
> last dash identifies the USB host controller. The part after the last
> dash identifies the device path related to the controller, expressed
> as a combination of port numbers.
>
> The sysfs device path /sys/bus/usb/devices/7-2/ includes a USB bus
> number (in this case 7) that is not present in usb_make_path()'s
> output.
>
> To find the sysfs path of your USB peripheral, you will have to find
> out which bus number the bus name (0000:00:1d.7) corresponds to. You
> might be able to find that by checking each usb[0-9]+ links
> in /sys/bus/usb/devices and comparing the link's target with the bus
> name.
>
> Best regards,
>
> Laurent Pinchart
Hi,
I'll scan the link-targets of /sys/bus/usb/devices/usb[0-9] and compare
them against the bus name. Now I've the problem of extracting the right
path component of the link-target to compare with.
E.g. /sys/bus/usb/devices/usb7 points
to ../../../devices/pci0000:00/0000:00:1d.7/usb7 .
My plan is to check the bus name against the component before
last and then extract the bus num from the last component's digit.
Now again a question: Does this always work or is there probably
another parent directory for usb7 in the global devices-directory?
Thanks again...
Regards,
Carsten
^ permalink raw reply [flat|nested] 2+ messages in thread
* How to obtain sysfs-path from bus_info
[not found] ` <4978E128.3050701@free.fr>
@ 2009-01-23 14:04 ` Carsten Meier
0 siblings, 0 replies; 2+ messages in thread
From: Carsten Meier @ 2009-01-23 14:04 UTC (permalink / raw)
To: Thierry Merle; +Cc: Laurent Pinchart, linux-media
Am Thu, 22 Jan 2009 22:12:08 +0100
schrieb Thierry Merle <thierry.merle@free.fr>:
> Laurent Pinchart a écrit :
> > On Thursday 22 January 2009, Carsten Meier wrote:
> >> Am Thu, 22 Jan 2009 00:20:00 +0100
> >>
> >> schrieb Laurent Pinchart <laurent.pinchart@skynet.be>:
> >>> Hi Carsten,
> >>>
> >>> On Wednesday 21 January 2009, Carsten Meier wrote:
> >>>> now I want to translate bus_info into a sysfs-path to obtain
> >>>> device-info like serial numbers. Given a device reports
> >>>> "usb-0000:00:1d.2-2" as bus_info, then the device-info is located
> >>>> under "/sys/bus/usb/devices/2-2", which is a symlink to the
> >>>> appropriate /sys/devices/ directory, right?
> >>> I'm afraid not. In the above bus_info value, 0000:00:1d.2 is the
> >>> PCI bus path of your USB controller, and the last digit after the
> >>> dash is the USB device path.
> >>>
> >>>> All I have to do is to compare the first 4 chars of bus_info
> >>>> against "usb-", get the chars after "." and append it to
> >>>> "/sys/bus/usb/devices/" to obatin a sysfs-path, right?
> >>>>
> >>>> Is there a more elegant solution or already a function for this?
> >>>> Can the "." appear more than once before the last one?
> >>> Probably not before, but definitely after.
> >>>
> >>> Root hubs get a USB device path set to '0'. Every other device is
> >>> numbered according to the hub port number it is connected to. If
> >>> you have an external hub connected on port 2 of your root hub,
> >>> and have a webcam connected to port 3 of the external hub,
> >>> usb_make_path() will return "usb-0000:00:1d.2-2.3".
> >>>
> >>> Cheers,
> >>>
> >>> Laurent Pinchart
> >> Hi,
> >>
> >> On my machine, my pvrusb2 (connected directly to my mini-pc) shows
> >> up under "/sys/bus/usb/devices/7-2/" which is a symbolic link to
> >> "../../../devices/pci0000:00/0000:00:1d.7/usb7/7-2"
> >
> > You're just lucky that USB bus 7 (usb7/7) is connected to the 7th
> > function of your USB host controller (1d.7).
> >
> > Here's an example of what I get on my computer:
> >
> > /sys/bus/usb/devices/4-2
> > -> ../../../devices/pci0000:00/0000:00:1d.2/usb4/4-2
> >
> >> I can't test for the new bus_info-string, because it's not fixed
> >> yet in the driver. But if I got it correctly it should be
> >> "usb-0000:00:1d.7-7.2" ?
> >
> > I think you will get usb-0000:00:1d.7-2
> >
> >> Then I've to simply take the string after the last dash, replace
> >> "." by "-" and append it to "/sys/bus/usb/devices/" for a
> >> sysfs-path?
> >
> > Unfortunately the mapping is not that direct. The part before the
> > last dash identifies the USB host controller. The part after the
> > last dash identifies the device path related to the controller,
> > expressed as a combination of port numbers.
> >
> > The sysfs device path /sys/bus/usb/devices/7-2/ includes a USB bus
> > number (in this case 7) that is not present in usb_make_path()'s
> > output.
> >
> > To find the sysfs path of your USB peripheral, you will have to
> > find out which bus number the bus name (0000:00:1d.7) corresponds
> > to. You might be able to find that by checking each usb[0-9]+ links
> > in /sys/bus/usb/devices and comparing the link's target with the
> > bus name.
> >
> To ease this processing, using libsysfs can be a good idea...
> On my system, the documentation of libsysfs is here:
> /usr/doc/sysfsutils-2.1.0/libsysfs.txt
> Knowing the bus-id, it won't be hard to look at it in data structures.
> Just my 2 cents.
Hi,
I already looked at it, but it doesn't help very much if you don't know
how sysfs is organized in detail. The sysfs-reference at
http://www.kernel.org/pub/linux/kernel/people/mochel/doc/papers/ols-2005/
also doesn't help very much as it only gives a brief overview.
Regards,
Carsten
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-01-23 14:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20090115184133.724d1d70@tuvok>
[not found] ` <200901220020.00520.laurent.pinchart@skynet.be>
[not found] ` <20090122012111.00634e0b@tuvok>
[not found] ` <200901221657.37189.laurent.pinchart@skynet.be>
2009-01-23 13:59 ` How to obtain sysfs-path from bus_info Carsten Meier
[not found] ` <4978E128.3050701@free.fr>
2009-01-23 14:04 ` Carsten Meier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox