detect usb device insert/remove and get device node from "C" program
Hello Everybody,
My application (running on an embedded MIPS based platform, running linux and has 2 USB ports) needs to detect USB devices such as Mass Storage devices that has been inserted/removed. The application need to know that a usb device has been inserted/removed along with the device node (like /dev/sda1, /dev/sdb1 etc). Then I need to mount this device node to a known location in the application. Is there a way to get these 2 things, from my application, which is in C language. 1) usb device inserted/removed (Is there a way like an interrupt or polling). 2) device node Thanks in advance, Ebin. |
With kernels that have 'udev', you can abuse udev to alert your program of any USB related event (for example, send -SIGUSR1 for a connect event and -SIGUSR2 for a disconnect). You can then go through the sysfs virtual filesystem and get the information you need.
If you use the 'RUN+=' feature of udev, whatever program you invoke will have access to a *lot* of information about the device being connected/disconnected via environment variables; the program invoked can then send the relevant information to your other software via a pipe or some such - personally I prefer a UNIX socket - or even a TCP socket communicating on 127.0.0.1. The udev documentation has improved significantly, but there are still numerous features which are undocumented; if you want to do anything serious with udev, there is a good chance you'll have to find the time to read the source. (And while at it, I'm sure that people would appreciate patches to the documentation.) |
Any practical solution to this problem?
|
closed
Done with udev. Can be closed. Thanks guyz.
|
Can you please explain how you did it with udev?
|
All times are GMT -5. The time now is 11:57 AM. |