LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How to identify USB card reader device? (https://www.linuxquestions.org/questions/linux-software-2/how-to-identify-usb-card-reader-device-858735/)

caerphoto 01-26-2011 05:45 AM

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


agreimann 01-26-2011 10:39 PM

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. :)

caerphoto 01-27-2011 06:52 AM

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.

Larry Webb 01-27-2011 07:27 AM

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.

agreimann 01-27-2011 02:03 PM

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. :)

Larry Webb 01-27-2011 02:05 PM

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.

caerphoto 01-28-2011 03:14 AM

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 :)


All times are GMT -5. The time now is 06:30 PM.