Using a USB Mass Storage digital camera with Unix


Some digital cameras exhibit a USB interface which is a USB "mass storage" device. On Unix, we deal with this exactly like other USB mass storage devices, such as a USB floppy drive. This is rather convenient, since (a) one doesn't need special software like gphoto to extract the files, and (b) there is no difficulty in terms of needing drivers and information that is specific to the camera. If you see any camera that says it supports the USB mass storage standard, it ought to just work with Unix without any fuss.

Warning: I believe these instructions are quite general, but I have only tested then with a few toys:

  1. IBM Thinkpad X20, running Linux 2.2.18#1,
  2. Olympus D-510 digital camera.
  3. Nikon 995 digital camera.
  4. A "Y-E DATA USB-FDU" USB floppy drive, Rev 3.12. This is bundled as an IBM branded USB floppy drive with the Thinkpad X20.

Principles

You need to build the kernel modules usb-uhci and usb-storage. You also need SCSI in your kernel, since the USB implementation makes the USB mass storage device look like a logical SCSI device. Once these are loaded into the kernel, the device appears as /dev/sda1. You mount this "as usual" and proceed to read files, delete files, etc. If your digital camera exhibits a VFAT file system (like the Olympus D-510 does), you'll need a kernel module for the vfat file system.

Warning. It is dangerous to mount the camera, modify the files, and then unplug the camera and walk away! The file system may be in an inconsistent state because of write cacheing on Unix. I have had serious problems with this so I know that things can go wrong. Do take the trouble of umounting the device before you unplug the camera and walk away.

Shell scripts that I keep in /usr/local/bin

mount-ums-digicam
This script mounts the digital camera. At the top are some configuration parameters. The defaults, which I use, are : (a) I mount it on /mnt/ums and (b) the Nikon 995, which exhibits a vfat file system, has image files in /mnt/ums/dcim/100nikon
umount-usb
This umounts the digital camera.
cp-from-ums-digicam
This script puts it all together. It:
  1. Mounts the digicam,
  2. Copies all the image files into $destination (/tmp/digicamfiles by default),
  3. Deletes them on the flash RAM, and
  4. Umounts the device.

It's convenient to use this shellscript : you just have to issue one command. It's also safer, since there's no possibility of mistakenly unplugging the camera and walking away.

These shellscripts are in this tarfile.

I use a set of defaults in these shell scripts - directory location for source image files on the digicam, mount point, destination for images in /tmp. You can easily modify these to suit your preferences.

Using a USB Mass Storage digicam as a removable storage device

I have a 128 Meg flash memory card on the D-510. It can be used as a removable storage medium! Mount it on computer A, copy files into it, umount it. Then mount it on computer B, and copy the files out! :-) A high speed, high reliability method for moving upto 128 Meg at a time.

The .mov files produced by the Olympus D-510

The Olympus shoots 15 second movies and stores them as .mov files. They work quite fine with xanim. Just avoid using vertical format, I don't think xanim supports vertical format. I just used Debian's reportbug to put in a feature request....

Watch me use the scripts --

sanna:/tmp# mount-ums-digicam
Waiting 5s for USB negotiation to settle in...
Trying to mount a VFAT volume on /dev/sda1...
Okay, your mount seems to be fine. Here is the df --
Filesystem           1k-blocks      Used Available Use% Mounted on
/dev/sda1               127936      5712    122224   5% /mnt/ums

The image files are --
total 5680
 960 p8220001.jpg*   960 p8230002.jpg*	 960 p8230003.jpg*   960 p8230004.jpg*
 912 p8230005.jpg*   928 p8230006.jpg*

BE CAREFUL - IF YOU DELETE FILES THEN DO UMOUNT BEFORE DISCONNECTING

sanna:/tmp# umount-usb 
Will valiantly try to get rid of all traces of USB mass storage
Do not worry about errors, I am just trying hard.
Warning - this program just tries stuff on best-efforts basis.
At the end, you judge whether or not the work got done.

Umount ums device, whether or not it is mounted.
Remove all modules.
Let us see where we stand

For your information -- mount
   /dev/hda2 on / type ext2 (rw,errors=remount-ro,errors=remount-ro)
   proc on /proc type proc (rw)
   devpts on /dev/pts type devpts (rw,gid=5,mode=620)
   /dev/hda1 on /windows type ext2 (rw,noexec,nosuid,nodev)
   /dev/hda5 on /usr/local type ext2 (rw)
   /dev/hda6 on /home type ext2 (rw)
   usbdevfs on /proc/bus/usb type usbdevfs (rw)
For your information -- kernel modules
   Module                  Size  Used by
   cs4281                 16672   0  (autoclean)
   soundcore               2800   3  (autoclean) [cs4281]
   usbcore                49008   1 
   lockd                  45328   0  (autoclean) (unused)
   sunrpc                 60976   0  (autoclean) [lockd]
   ds                      6416   2 
   i82365                 22448   2 
   pcmcia_core            45568   0  [ds i82365]
   serial                 18432   0  (autoclean)

sanna:/tmp# cp-from-ums-digicam 
Copied all files from digicam into /tmp/digicamfiles

sanna:/tmp# exit

Todo -- new features

Generalise to other cameras. These scripts are hardcoded for the Olympus D-510 camera. I'd like to generalise this. The script should use /proc/bus/usb information to know what is the device, and then know what directory the images are found in. Help me to do this - I only have access to one digital camera.

The scripts assume you have no SCSI!. They try to always mount the USB device on /dev/sda1. If you already have one or more SCSI devices / controllers, then this assumption is incorrect. E.g. I have a USB disk, which I use for backups. When this is mounted, the digicam appears as /dev/sdb1. I am not sure I know quite how to handle this in a general way.


Back up to Ajay Shah's home page -- Free software