On occasion compact flash cards can get corrupted. I think the most common case is you forget to ``unmount'' them and then insert another card. Certain operating system then happily writes the old FAT table onto the new card. This happens in XP/2K/NT, as well as Linux. The net effect is you need to reformat the card, losing all of your images. This is a bummer, so here is a quick routine that will recover *most* of your image data.
On a Unix system (Linux, Mac OS X, etc), issue the command:
dd if=/dev/disks1 of=image.img bs=512
Make sure that the /dev/? input device is the RAW disk, not the partition (which may be corrupted). You want a snap shot of the entire disk. The above device is for OS X, but a Linux device is something like /dev/hdb
Next, grab this source code and compile it for your operating system. Then execute the command:
You will then get a collection of files save_img_001.jpg, save_img_002.jpg, ... Some of these files will be ok, some will be corrupt. To determine which, you can use your favorite image editor, or download the netpbm tools (or certain gimp installations have these as well). Using the program "jpegtran" you can process the images from the command line. jpegtran will identify good from bad.
How does this work? Usually, you use an almost blank compact flash card in your digital camera when you begin taking pictures. With the FAT file system this means that files are stored sequentially onto the raw device. What the saveimg program does is assume the input file is a collection of JPEG files that have been cat'ed together (and aligned on 512 byte boundaries -- like a physical disk). It then slices up the input file by looking for the header bytes of a JPEG image. When it finds those it starts a new output file.
A couple of notes: the first output file "save_img_001.jpg" is always garbage. The first file is the partition table and FAT tables and other misc. Second thing to note is that if your compact flash card was *NOT* blank prior to inserting it into your camera, then your milage may very substantially. However, using this simple hack I've been able to recover a totally messed up compact flash card (one with a corrupted FAT table) and get back about 90% of the images in perfect form. YMMV.
Some updated notes....