LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-26-2011, 05:45 AM   #1
caerphoto
LQ Newbie
 
Registered: Jan 2011
Posts: 3

Rep: Reputation: 0
How to identify USB card reader device?


Hello!

I am writing a Ruby program that automatically copies files from a memory card in my card reader to directories on my external HDD named by file date.

I have a few cameras, and because each names the memory card differently, Ubuntu (10.10) mounts each one in a different place. My program attempts to automatically locate the correct source, and so far it's working great, but only because I'm assuming my card reader device will be identified in /proc/mounts as /dev/sd*.

I would like to make the program available to others, but I am uneasy about making the above assumption. Ideally I'd like to find a way to identify the card reader (and find its mount point) that works on most, if not all, Linux systems.

Here is the current Ruby code I have for getting the mount points:
Code:
def src_dirs
    # Look for USB devices and return an array of their mount points.
    mounts = IO.readlines("/proc/mounts")
    usb_devices = mounts.map { |mount| mount if mount.include? "dev/sd" }
    # Extract mount point.
    usb_devices.compact.map { |usb_device| usb_device.split(" ")[1] }
end
 
Old 01-26-2011, 10:39 PM   #2
agreimann
LQ Newbie
 
Registered: Sep 2010
Posts: 28

Rep: Reputation: 6
You really don't need a Ruby program to accomplish what you are talking about, if I'm understanding right here. (Also, might I recommend bash shell scripting? It's a fun language to work with.)

And, actually, depending on your computer's configuration, your devices could be listed with values that are different from what would be expected on another Linux machine. Remember to give your cards labels that you can distinguish with easily. An easy way to do this is simply to go to a Windows computer, open Computer from the Start menu, and change the labels of the drives. You could also use gparted to work with your drive labels.

To mount any drive, you will need to open a shell. Type in:
Code:
sudo mkdir /mnt/my_card
(where my_card could be card1, mycard, or anything, as long as it's one title (not 'my camera card', but 'my_camera_card' instead). You will need to type in your password.

If all's successful, a new, blank line will appear. Now, you will need to type in fdisk -l. What disk out of that list matches your card best? Is it the label you assigned? If it's anywhere very close, it's probably it. So, let's suppose your card is /dev/mmc1.

In that case, you would type (and note yours will be different than this example):
Code:
sudo mount /dev/mmc1 /mnt/my_card
OK--the card is mounted and you can now access it like you would a flash drive or any other device. To find it, open your favorite file manager (Dolphin, Nautilus, etc.) and navigate to, (from the example here), /mnt/my_card. You should find your card's contents spilled out here, and you can now work with your card.

Hope this helps.

Last edited by agreimann; 01-26-2011 at 10:51 PM.
 
Old 01-27-2011, 06:52 AM   #3
caerphoto
LQ Newbie
 
Registered: Jan 2011
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Remember to give your cards labels that you can distinguish with easily.
This is the problem - I can't label the cards because when they're formatted in camera, the camera will label the card instead. My SLR actually doesn't label the card, while my compact calls the card 'RICOHDCX'. I'm sure other cameras label the cards differently.

As for the mounting part, Ubuntu mounts the cards automatically. If I know the device name of the card/reader, I can get its mount point easily enough.

Getting the device name, or rather, automatically recognising it as a memory card from which to copy files, is the issue.

If none of this works, I guess I could always get a list of every mounted device and go looking for a 'DCIM' directory in the root of each one.

The Ruby script is here if anyone wants to take a look: http://www.caerphoto.com/cfc.rb . I wrote it in Ruby because that's what I'm most familiar with.
 
Old 01-27-2011, 07:27 AM   #4
Larry Webb
LQ Veteran
 
Registered: Jul 2006
Location: Crystal Beach, Texas
Distribution: Suse for mail +
Posts: 5,100
Blog Entries: 7

Rep: Reputation: 229Reputation: 229Reputation: 229
I am not familiar with programing but I do have three cameras and see what you are talking about. All three us sd cards and they label them different. On my desktop I have a internal usb reader and it does seem to use the same /dev. I guess if you use an external reader and use the same usb port the /dev would stay the same.
 
Old 01-27-2011, 02:03 PM   #5
agreimann
LQ Newbie
 
Registered: Sep 2010
Posts: 28

Rep: Reputation: 6
OK--the "automatic" labeling from the camera does indeed pose a little bit of a problem. And, yes, I'm aware Ubuntu automounts cards, however, I was merely mentioning that by manually mounting, if you have the card names the cameras generate memorized, you could get to them faster is all.

However, whatever works best for your machine is what I'd say go with. Hope your Ruby program works as expected.
 
Old 01-27-2011, 02:05 PM   #6
Larry Webb
LQ Veteran
 
Registered: Jul 2006
Location: Crystal Beach, Texas
Distribution: Suse for mail +
Posts: 5,100
Blog Entries: 7

Rep: Reputation: 229Reputation: 229Reputation: 229
My cards I mount through /dev/sde

and it seems to be the same if I am using Tiny Me (which does not auto mount), ubuntu, suse or which ever.

Last edited by Larry Webb; 01-27-2011 at 02:08 PM.
 
Old 01-28-2011, 03:14 AM   #7
caerphoto
LQ Newbie
 
Registered: Jan 2011
Posts: 3

Original Poster
Rep: Reputation: 0
Thank you all for your help!

For now I'm just going to assume the card will be mounted in /dev/sd* - it works on my machine and it seems like it'd work on most others too
 
  


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 device detection, manual insertion card(smart card) reader problem, zapkhiel Linux - Hardware 4 07-17-2009 08:50 AM
Slackware thinks USB Card Reader is an Ethernet device apachedude Linux - Hardware 3 02-04-2005 07:59 AM
How to identify a card with wrong device id? gnu_1 Linux - Laptop and Netbook 2 09-23-2004 05:54 PM
USB CF Card Reader/Write not a valid block device cromwell Linux - Hardware 10 01-06-2004 10:11 PM
Smartcard/Flash card reader (usb storage device) Redhat 9 i0scanw Linux - Newbie 0 10-19-2003 05:43 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:24 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
Open Source Consulting | Domain Registration