LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices

Reply
 
Search this Thread
Old 11-12-2008, 11:22 AM   #1
ebinjose
LQ Newbie
 
Registered: Jan 2008
Posts: 14

Rep: Reputation: 0
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.
 
Old 11-13-2008, 04:26 AM   #2
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
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.)
 
Old 03-10-2011, 02:00 PM   #3
alephan
Member
 
Registered: Dec 2010
Location: Bucharest
Distribution: ubuntu
Posts: 45

Rep: Reputation: 0
Any practical solution to this problem?
 
Old 05-01-2011, 03:31 PM   #4
alephan
Member
 
Registered: Dec 2010
Location: Bucharest
Distribution: ubuntu
Posts: 45

Rep: Reputation: 0
closed

Done with udev. Can be closed. Thanks guyz.
 
Old 04-29-2012, 09:26 AM   #5
Alla147
LQ Newbie
 
Registered: Apr 2012
Posts: 1

Rep: Reputation: Disabled
Can you please explain how you did it with udev?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
fstab and my "device node" d0nuts Linux - Newbie 2 12-04-2007 01:19 AM
"the device node /dev/hda6 for the root filsystem is missing" after a sudden halt braungiobi Linux - General 0 05-09-2006 03:53 PM
"Unable to open USB device "usb://hp/LaserJet%201000": No such device" lordshipmayhem Mandriva 2 08-08-2004 05:56 PM
USB storage device works in 2.4 not 2.6 "no device error" critch Linux - Hardware 4 05-18-2004 12:13 PM


All times are GMT -5. The time now is 06:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration