LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
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


Reply
  Search this Thread
Old 07-14-2004, 07:43 AM   #1
logularjason
LQ Newbie
 
Registered: Jul 2004
Location: Melbourne, Australia
Distribution: fedora 8
Posts: 12

Rep: Reputation: 0
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.
 
Old 07-14-2004, 02:45 PM   #2
netmask
Member
 
Registered: Jul 2004
Location: Sherbrooke, Quebec, Canada, North America, World, Milky Way
Distribution: Gentoo
Posts: 103

Rep: Reputation: 16
I *think* /var/log/message may output something when a card is inserted,
 
Old 07-14-2004, 04:36 PM   #3
MS3FGX
LQ Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852

Rep: Reputation: 361Reputation: 361Reputation: 361Reputation: 361
If you do:

Code:
tail -f /var/log/messages
A message should go by when you plug in a card.
 
Old 07-14-2004, 06:48 PM   #4
logularjason
LQ Newbie
 
Registered: Jul 2004
Location: Melbourne, Australia
Distribution: fedora 8
Posts: 12

Original Poster
Rep: Reputation: 0
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?
 
Old 07-14-2004, 11:06 PM   #5
MS3FGX
LQ Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852

Rep: Reputation: 361Reputation: 361Reputation: 361Reputation: 361
Your flash disk would show up as a SCSI device under /proc.
 
Old 07-14-2004, 11:57 PM   #6
logularjason
LQ Newbie
 
Registered: Jul 2004
Location: Melbourne, Australia
Distribution: fedora 8
Posts: 12

Original Poster
Rep: Reputation: 0
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).
 
Old 07-17-2004, 07:18 AM   #7
logularjason
LQ Newbie
 
Registered: Jul 2004
Location: Melbourne, Australia
Distribution: fedora 8
Posts: 12

Original Poster
Rep: Reputation: 0
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.
 
Old 07-17-2004, 04:47 PM   #8
Electro
LQ Guru
 
Registered: Jan 2002
Posts: 6,042

Rep: Reputation: Disabled
Here is a few links you can get hints from to make a script to detect if there is a card in one of the reader slots
http://www.cs.sfu.ca/~ggbaker/personal/cf-linux
http://www.linux-sxs.org/hardware/flashreaders.html
 
Old 07-17-2004, 10:43 PM   #9
logularjason
LQ Newbie
 
Registered: Jul 2004
Location: Melbourne, Australia
Distribution: fedora 8
Posts: 12

Original Poster
Rep: Reputation: 0
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.
 
Old 06-24-2006, 04:11 AM   #10
kasimtasdemir
LQ Newbie
 
Registered: Jun 2006
Posts: 3

Rep: Reputation: 0
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.
 
  


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
USB flash card reader in Mandrake 10.1 enrico14569 Linux - Hardware 4 10-02-2005 07:57 PM
USB Flash card reader probs Randomcasualty Linux - Hardware 15 08-09-2005 09:20 PM
JFFS2 on USB Card Reader Flash Denes Linux - Hardware 1 07-14-2005 02:41 PM
suse don't want to detect my usb memory-card-reader theewolizer SUSE / openSUSE 2 11-23-2004 12:29 AM
Need a little help getting USB flash card reader to work Electrode Linux - Hardware 13 10-20-2003 05:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 03:43 AM.

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
Open Source Consulting | Domain Registration