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. |
I *think* /var/log/message may output something when a card is inserted,
|
If you do:
Code:
tail -f /var/log/messages |
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?
|
Your flash disk would show up as a SCSI device under /proc.
|
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). |
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. |
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 |
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. |
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:
|
All times are GMT -5. The time now is 11:05 PM. |