Exercise #6
Each program in this exercise should take as its first parameter an Xv6 file-system image (such as fs.img found in your Xv6 directory) to operate on.
An image (fs.img
) is provided that has multiple levels of directories with
various files in them, but you may use your own.
df.c
- This program should scan the block bitmap of each image given on the
command line and print the size of the file-system in blocks, the number
of blocks used and available and a percentage used.
> ./df fs.img test.img Filesystem Size Used Avail Use% fs.img 1000 758 242 75 test.img 1000 788 212 78
Note: you should not use the inode information to determine space used, use only the free block bitmap.
tree.c
- This program should recursively list all the files in the file-system starting with the root directory (inode 1). Try to implement it with proper tree lines and/or properly sort the output.
fcat.c
- This program should attempt to find a files inode by a given name, then output the data of the file to the console. It should recursively look for the file by breaking the path up into individual components and searching through the directories starting at the root directory. You may assume the path starts at the root directory (i.e. starts with a /)
fcp.c
- This program should attempt to copy a local file (i.e. not already in the file system image file,) and copy it into the image file, storing it by default in the root directory or alternatively in a optionally supplied directory path within the image.
Note: A directory entry with a inum value of 0 does not mean that you've reached the end of the directory entries, it represents a "hole" in the directory to skip over.
The C files contain function stubs from my working solutions, you are free to use them or ignore/replace them with your own. They are meant to help guide you toward one possible solution, but are in no way required.
Provided is a disksb.c
which shows code used to scan the superblock and
read and output the data from inode 3 (nomally the README file within the
image.)