On Fri, 23 Feb 2007, Diego Zuccato wrote: > Alan Stern wrote: > >> How do I get the "plug" event (and "unplug" too...) ? > >> Are there some docs I couldn't find? > >> As you may think the system is quite resource-constrained, so the less > >> sw is installed, the better. > > The short answer is "hotplug events". > Yep. Sorry. I've not been clear (some weeks looking for an answer to a > problem makes one think that all is obvious :( ). > My problem with hotplug is the translation between the shell variable > DEVICE and "struct device" libusb expects (well, actually I should pass > that variable to a running daemon, too, but that's another problem). > > > If you are using udev then you can > > write scripts to do what you want. Otherwise you will have to receive the > > hotplug event notifications in some other way. > Same problem. shell -> libusb translation. > > What I have is a daemon that handles all the connected devices. It gets > notified of the relevant (un)plug events, so it knows when a certain > /proc/bus/usb/BUS/DEV exists. What I don't know how to handle is the > "opening" of that device (even better verifying it's the right device, > too), even in presence of many other similar devices.
I see. You want to know the BUS and DEV values, given the sysfs pathname. Let's take a simple example. Right now I have a USB device with this sysfs path: /sys/devices/pci0000:00/0000:00:07.2/usb1/1-1/. You can get the BUS value directly from the last component of the path; it is the number before the '-' character (in this case, bus 1). The DEV value can be found by reading the devnum file in that sysfs directory. For instance, on my machine: $ cat /sys/devices/pci0000:00/0000:00:07.2/usb1/1-1/devnum 2 So DEV is 2. Alan Stern ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Linux-usb-users@lists.sourceforge.net To unsubscribe, use the last form field at: https://lists.sourceforge.net/lists/listinfo/linux-usb-users