LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Embedded & Single-board computer (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/)
-   -   detect usb device insert/remove and get device node from "C" program (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/detect-usb-device-insert-remove-and-get-device-node-from-c-program-682915/)

ebinjose 11-12-2008 10:22 AM

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.

pinniped 11-13-2008 03:26 AM

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.)

alephan 03-10-2011 01:00 PM

Any practical solution to this problem?

alephan 05-01-2011 02:31 PM

closed
 
Done with udev. Can be closed. Thanks guyz.

Alla147 04-29-2012 08:26 AM

Can you please explain how you did it with udev?


All times are GMT -5. The time now is 02:57 AM.