In this project you will be undeleting files from the fat filesystem. Instead of dedicating a partition on the hard drive, or using a floppy disk, we will instead use the loopback device. The Linux loopback device lets you use a regular file as a virtual disk. This takes advantage of the Unix 'everything is a file' concept. Normally you access a disk by mountinng the file /dev/hda2, or some variant. The os knows that this file corresponds to the hard disk. But since the API to access devices is a file API, it allows us to use regular files as devices.

To mount a disk image, use the mount command: mount -o loop [Image filename] [Mount location] [-t fstype]. Image filename is the name of the file containing the disk image, mount location is the place in the fs you want the virtual disk mounted. You can optionally specify the filesystem type, i.e. vfat, or msdos. For example mount vfat.img /mnt/floppy -t vfat -o loop.

To mount arbitrary images in arbitrary locations, you need root access. However, there's a file (/etc/fstab) that specifies what devices should be mounted where and has an option to allow normal users to do the mounting and unmounting. On the lab machines, I've added two entries: /boot/cs111/vfat /mnt/vfat -t vfat -o loop and /boot/cs111/msdos /mnt/msdos -t msdos -o loop. You can copy what ever image you want to mount into /boot/cs111/vfat or msdos and then mount it by using mount /mnt/vfat or mount /mnt/msdos.

To unmount mounted filesystems, use the umount command (not unmount, but umount). It will take as a parameter either the mounted device, or the mount location. I.e. umount /mnt/msdos

Vfat is the module which can deal with long filenames in Linux. Msdos is the module that does not understand them. So, if you want to examine things by their short filenames, you can use the msdos mount point. Otherwise you may want to use the vfat mount point.

You can view the contents of a disk image to investigate how things are written to the disk (or to debug your code which reads or writes to the disk). A decent hex editor that should be on most linux machines is khexedit. There may be a way to go into a hex mode in emacs, but I don't know it. There's a variant of vi that has a good hex editor mode, elvis.

A hex editor is an easy way to see what is going on, or to make small changes, but to test your code, or to make an image for testing purposes, you have to create an appropriately sized file, then create a filesystem on it:

  1. dd if=/dev/zero of=[Image filename] bs=1k count=N
    (N is the number of KB of your image, it seems that N must be at least 20)
  2. /sbin/mkdosfs [Image filename] (This formats the filesystem)

Look at the man page for mkdosfs. There are options to change various parameters of the fat filesystem.