Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux? |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
07-14-2004, 07:43 AM
|
#1
|
LQ Newbie
Registered: Jul 2004
Location: Melbourne, Australia
Distribution: fedora 8
Posts: 12
Rep:
|
How to detect insertion/removal of flash card in usb reader?
I have a Belkin USB flash card reader that is working nicely under Redhat 9.
Is there a way for me to determine when a card has been inserted/removed from the reader? I'd rather not poll, but if I have to, I don't want the test to be: attempt a mount and see if it succeeds.
The drive is an F5U140 (catalog.belkin.com/IWCatProductPage.process?Merchant_Id=&Section_Id=200406&pcount=&Product_Id=122161)
Thanks,
Jason.
|
|
|
07-14-2004, 02:45 PM
|
#2
|
Member
Registered: Jul 2004
Location: Sherbrooke, Quebec, Canada, North America, World, Milky Way
Distribution: Gentoo
Posts: 103
Rep:
|
I *think* /var/log/message may output something when a card is inserted,
|
|
|
07-14-2004, 04:36 PM
|
#3
|
LQ Guru
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852
|
If you do:
Code:
tail -f /var/log/messages
A message should go by when you plug in a card.
|
|
|
07-14-2004, 06:48 PM
|
#4
|
LQ Newbie
Registered: Jul 2004
Location: Melbourne, Australia
Distribution: fedora 8
Posts: 12
Original Poster
Rep:
|
Nothing appears in my log, which is set up to record *.info and above. Seems like an unfortunate way to determine whether a card is in the reader anyway. Is there something analogous to hotplug that will allow a script to be called on card insertion/removal, or perhaps a flag that shows up somewhere under /proc?
|
|
|
07-14-2004, 11:06 PM
|
#5
|
LQ Guru
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852
|
Your flash disk would show up as a SCSI device under /proc.
|
|
|
07-14-2004, 11:57 PM
|
#6
|
LQ Newbie
Registered: Jul 2004
Location: Melbourne, Australia
Distribution: fedora 8
Posts: 12
Original Poster
Rep:
|
Sure, but the SCSI device represents the USB card *reader*. I want to know if a card is in the reader...
(and before someone suggests a hook in /etc/hotplug/usb.agent, it's the same deal there too - it notifies when a USB device is attached/removed, however that's not what I'm after).
|
|
|
07-17-2004, 07:18 AM
|
#7
|
LQ Newbie
Registered: Jul 2004
Location: Melbourne, Australia
Distribution: fedora 8
Posts: 12
Original Poster
Rep:
|
My initial query remains unresolved, so I'll try and rephrase it:
I have a USB flash card reader as described above. Is there a way for me to detect when a flash card has been inserted into it? (Note that I do *not* want to detect whether the reader itself is connected to the PC - I know how to do that).
Thanks, Jason.
|
|
|
07-17-2004, 10:43 PM
|
#9
|
LQ Newbie
Registered: Jul 2004
Location: Melbourne, Australia
Distribution: fedora 8
Posts: 12
Original Poster
Rep:
|
The links above mainly concentrate on how to identify the right SCSI device and mount it.
I worked it out for myself in the end. The SCSI kernel driver returns a "no medium" code when an open() call is made and removable media (e.g. flash card) is not present. So all I need to do is make an open() call, and see what the return code is. I want to work at the bash level, so rather than writing c code to do this, I just used sg_dd from the sg3_utils suite, which does calls open - I grep out the 'no media' error. Of course, this works whether the reader has been mounted or not.
|
|
|
06-24-2006, 04:11 AM
|
#10
|
LQ Newbie
Registered: Jun 2006
Posts: 3
Rep:
|
Hi,
I am a newbie in Linux. I want to detect Usb flash drive in C whether polling or not. I thing I found a solution in this message:
Quote:
Originally Posted by logularjason
...I worked it out for myself in the end. The SCSI kernel driver returns a "no medium" code when an open() call is made and removable media (e.g. flash card) is not present. So all I need to do is make an open() call, and see what the return code is.
|
However I did not understand that how can I call "open()" in C in order to see the existance of USB flash drive? Could you give an samle code block,please? Thanks.
|
|
|
All times are GMT -5. The time now is 03:43 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|