Camera Crash
My digital camera crashed while taking pictures at the annual Family Christmas Gathering. Unlike the episode I described in the December 2004 column, the camera popped up a MEMORY STICK ERROR after snapping the 44th picture of the day. I inserted another Memory Stick and continued the mission.
Back home, I inserted the crashed Memory Stick into a USB card reader and found that, while it was recognized as a USB Mass Storage device, it had no partition table. I used dd to copy the entire 128-MB Memory Stick to an image file.
Browsing through that file with khexedit showed that the camera had zeroed much of the partition table and trashed some of the FAT area, but left the JPG files intact. The block of binary zeros at the start of the file evidently confused the grep text-searching utility into returning offsets that didn't match up at all with the values shown by khexedit.
Running the file through strings -t x MemStick.bin | grep Exif returned the correct offsets. As before, I imported those lines into a spreadsheet, rounded the values down to multiples of the 512-byte sector size, produced dd commands that extracted 3-MB hunks of Memstick.bin into separate JPG files, then fed them to ImageMagick's convert utility to extract the JPG images.
The first 43 images were perfect, the bottom of the 44th image was missing, and 8 deleted images from a previous session also appeared. The fact that deleting a file doesn't actually remove its data sometimes comes back to haunt folks with something to hide, but in this case it was okay.
Those restored pictures went out on a CD of the Gathering and all was well.
Continuing Education
Any embedded system large enough to require an operating system also uses a filesystem to organize external storage. Smaller, data-intensive systems without a formal OS, such as a single-chip MP3 player with a voice recorder, may write sound files into the same large Flash memory used for read-only music. Even deeply embedded systems without removable storage generally have a filesystem of some sort on their Flash program memory.
Below the level of the filesystem, partitions divide storage into chunks that resemble disk drives. For example, the cfdisk utility lists nearly 100 different partition types from Amoeba through XENIX, some of which you'll actually find in contemporary systems.
Understanding how all this works may not be on your to-do list, but knowing how to rebuild a filesystem or recover critical data from a crashed Flash device may well come in very, very handy. With the Linux kernel worming its way into embedded systems, knowing how to drive UNIX-oid tools and work with Windows filesystems can also be valuable. Just start with SRCd and work your way up.