Due: Wednesday December 3, 10 p.m.
In this assignment, you will explore the implementation of a particular file system, ext2, and will write tools to modify ext2-format virtual disks. To do this work, you will need to be comfortable working with binary data and will need to learn about the ext2 filesystem.
Your task is to write four programs (in C) that add or remove files from an ext2 formatted virtual disk. The executables must be named ext2_cp, ext2_mkdir, ext2_ln, and ext2_rm and must take the specified arguments.
All of these programs should be minimalist. Don't implement what isn't specified: only provide the required functionality and specified errors. (For example, don't implement wildcards. Also, can't delete directories? Too bad!)
You will find it very useful for these programs to share code. You will want a function that performs a path walk, for example. You will also want a function that opens a specific directory entry and writes to it.
Here are six sample virtual disk images:
These disks were each created and formatted in the same way:
% dd if=/dev/zero of=~/DISKNAME.img bs=1024 count=128 % mke2fs DISKNAME.img % sudo mount -o loop ~/DISKNAME.img /home/petersen/mntpoint % cd /home/petersen/mntpoint % ...... normal linux commands to add/remove files/directories/links ..... % cd ~ % umount /home/petersen/mntpoint
Since we are creating images with mke2fs, the disks are formatted with the ext2 file system. You may wish to read about this system before doing some exploration. The wikipedia page for ext2 provides a good overview, but Dave Poirer's Second Extended File System article provides more detail on how the system places data onto a disk. It's a good reference to keep on hand as you explore.
However, you will probably also want to explore the disk images to get an intuitive sense of how they are structured.
There are two good ways to interface with these images. The first way is to interact with it like a user by mounting the file system so that you can use standard commands (mkdir, cp, rm, ln) to interact with it. Details of how to do this are below. The second way is to interact with the disk as if it is a flat binary file. Use xxd to create hex dumps, diff to look for differences between the dumps, and your favorite text editor to view the diffs. For example (YMMV):
% diff <(xxd emptydisk.img) <(xxd onefile.img) > empty-onefile.diff % vimdiff empty-onefile.diff
You should be able to use a combination of these techniques to understand how files are placed on disk and how they are removed. For example, you can create a new disk image, use mount to place files of various sizes on it, unmount it, and then use xxd and diff to see how the image differs from the other images you have.
If you have root access on a Linux machine (or Linux virtual machine), you can use mount to mount the disk into your file system and to peruse its contents. (Note: this requires sudo, so you will need to do this on a machine (or virtual machine) that you administer.
On CDF, you can use a tool called FUSE that allows you to mount a file system at user-level (from your regular account). It may not work on an NFS mounted file system, so you should use the following steps on the machine you want to work on (CDF workstation or wolf (it may not work on NX)).
Note: <CDFID> should be replaced with your own CDF user id below.
# create a directory in /tmp and go there mkdir -m 700 /tmp/<CDFID>-csc369h cd /tmp/<CDFID>-csc369h # to create your own disk image dd if=/dev/zero of=DISKNAME.img bs=1024 count=128 /sbin/mke2fs -F DISKNAME.img # create a mount point and mount the image # CWD is /tmp/<CDFID>-csc369h mkdir mnt fuseext2 -o rw+ DISKNAME.img mnt # check to see if it is mounted df -hl # now you can use the mounted file system, for example mkdir mnt/test # unmount the image fusermount -u mnt
You can use the same strategy to mount one of the images provided above.
The assignment should be submitted to an a3 directory in your svn repository. Don't forget to add and commit all of the code for the required programs. Please also provide a Makefile that will create all of the programs if make is invoked without arguments. (There should be no error or warnings when -Wall is used.) We will pull the last commit before the deadline for marking.
If you are unable to complete all aspects of this assignment, please add a README file (text or pdf format only) to your a3 folder that explains what is not implemented and describes what features you have completed. You can receive partial credit for functionality that is implemented but that does not complete one of the four required programs.