Lab 7: File Systems

In this lab assignment you will get experience working with file systems: creating a new FS, manipulating files, and inspecting the data organized on a disk. As you work through the lab, write the answers to each of the questions below in docs/fs.md.

The Disk

As usual, everything on a Unix system is a file. The first thing we should do is find out what ‘file’ represents our main (boot) disk on gojira. You can use the df command to print out all the currently-mounted file systems, including their sizes and space available (use the -H option for human-readable sizes).

(1.) What device file represents the root (/) partition?

(2.) What is the output of ls -l on this file? What is different about this file compared to most?

Since disks are just files, we can create a disk by creating a file:

dd if=/dev/zero of=./my-disk bs=1048576 count=100

(3.) How big is this file, in megabytes? How long did it take to write this file to the disk?

Okay, so we created a blank file (filled with zeros from /dev/zero – which is also a device file, by the way). Now we can put a file system on it:

mkfs.ext4 ./my-disk

(4.) How many inodes are created by this process?

Next, let’s get some information about this file system. Use tune2fs -l my-disk.

(5.) You’ll be able to see how many blocks are allocated to the file system, as well as reserved blocks and free blocks. How much free space does the disk have, expressed as a percentage?

(6.) For our last experiment, use the debugfs command to find out how many files and directories exist in the file system you created, and what they are named. You may need to check the man pages or help menu of debugfs to do this. Put the names in your lab notes.

Manipulating The File System

Let’s experiment with some file permissions next. Create a new directory to work in called fs, and cd into it. Then:

touch fileA
umask 000    # Will affect next 'touch'
touch fileB
umask 777    # Will affect next 'touch'
touch fileC
umask 077
whoami | md5sum > whoami.txt

(7.) What is the output of cat whoami.txt and ls -l? What difference does the umask command make to the file permissions?

(8.) What umask command would set the default permissions for files to ------r-- ?

(9.) What inode number is associated with fileB? (ls -li)

(10.) In xv6, a directory is “an inode with special contents (list of other inodes!)” according to kernel/fs.c. Given this, explain the process required to list the contents of a directory, like how ls does it. Specifically, provide an example of what the contents of the inode may look like. (Check kernel/fs.h and user/ls.c for hints).