Categories
computers suck

CF Card Undelete for Linux

I hope you never need this. But this worked for me.

I accidentally deleted a bunch of files from the CF card that was in my card reader. I recovered them all perfectly.

First, before you do anything else, unmount the card’s file system. This will stop any additional changes being made to the card.

You’ll need to know:

  1. the device name of the card’s file system. It could be something as simple as /dev/sda1, or it could be something complex, like /dev/scsi/host1/bus0/target0/lun0/part1 (as it is with me).
  2. the names of the files you accidentally deleted. For example, if you deleted dsc_1017.jpg and dsc_1018.jpg in the dcim/100ncd70 directory, you’ll specify these as /dcim/100ncd70/dsc_1017.jpg and /dcim/100ncd70/dsc_1018.jpg.

First, check that the files can be undeleted:

# fsck.vfat -u /dcim/100ncd70/dsc_1017.jpg -u /dcim/100ncd70/dsc_1018.jpg /dev/scsi/host1/bus0/target0/lun0/part1

If you get the message Warning: did not undelete file ..., that’s a file that has been overwritten, perhaps in your camera. It’s gone; only the name remains. You won’t get it back.

Then, you can actually restore the files:

# fsck.vfat -r -u /dcim/100ncd70/dsc_1017.jpg -u /dcim/100ncd70/dsc_1018.jpg /dev/scsi/host1/bus0/target0/lun0/part1

If all goes well, your files will be back. Makes backups, and don’t do it again.

Categories
computers suck goatee-stroking musing, or something

simple cheapo CF card adaptor and Linux

As I’m about to go (almost) entirely digital, I’m looking for ways of reading CF cards on my Linux-based ThinkPad. I was in Henry’s clearance store yesterday, and they had PCMCIA CF card readers for $10. I’ve found that it works well, though it took me a while to get it going. Here’s what I did:

You will need to install Card Services for Linux, if you haven’t already. After that’s done, you can check which cards are installed with cardctl ident:

Socket 0:
  product info: "Wireless Network CardBus PC Card", "Global", "", ""
  manfid: 0x0097, 0x8402
Socket 1:
  product info: "LEXAR ATA FLASH CARD     ", "STORM  ", "ST BM"
  manfid: 0x4e01, 0x0200
  function: 4 (fixed disk)

Ignore the Socket 0 output — it’s my wireless network card. The adaptor in socket 1 does contain a Lexar CF card; you’ll get a different message if yours is a different manufacturer.

If you don’t get this, it’s likely that (somehow) your system isn’t preloading the ide-cs module; check the /etc/pcmcia/config file, and read the various pcmcia-cs manual pages.

If you check the output of the kernel messages (with dmesg, or your tool of choice), you should see:

hde: LEXAR ATA FLASH, CFA DISK drive

You’ll want to make a mount point for this disk, so mkdir -m777 /mnt/flash. Then you can edit /etc/fstab, and add:

/dev/hde1 /mnt/flash auto noauto,user,rw 0 0

From now on, you can access your camera’s CF card from /mnt/flash. No messing around with USB required!