How to detect insertion/removal of flash card in usb reader?
Linux - HardwareThis 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.
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)
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?
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).
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:
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.