CSE Roadmap

Core tier · about 3 hours · 7 parts

Part 7 of 7 · 3 min read

Exercises

Easy

Easy 1: What is hidden (20 minutes)

A directory /data holds three files. A file system is mounted on /data. Where are the three files, and how do you see them again?

Done when: they are on the old file system, hidden, and they return after umount /data.

Hint

the files stay where they are, and the mount only changes where the path leads.

Easy 2: Size of a tmpfs (20 minutes)

A tmpfs is mounted with size=64m. How many 4 KiB blocks does statfs report?

Done when: 16,384.

Hint

64 MiB / 4 KiB.

Easy 3: Same file or not (20 minutes)

Two stat lines show the pairs (dev 1792, inode 11) and (dev 1792, inode 11). Are they the same file?

Done when: yes, since the device and the inode are both equal, which a bind mount or a hard link would give.

Hint

compare both numbers.

Medium

Medium 1: Try the hiding (45 minutes)

Make a 16 MiB ext4 image, mount it, create t/hidden.txt, mount a tmpfs on t, and list it. Then unmount the tmpfs and list it again.

Done when: a three-line listing that matches section 1 (hidden.txt, nothing, hidden.txt).

Hint

use mount -o loop image dir and mount -t tmpfs tmpfs dir/t.

Medium 2: Run the program (45 minutes)

Compile the program of section 3 and run it on /, /proc, /sys, /dev/shm and your home directory. Say which are on a disk.

Done when: a table of five rows and a note naming the ones with zero blocks.

Hint

the numbers of blocks are in the blocks column of the output.

Medium 3: Read the options (45 minutes)

Run cat /proc/mounts on your machine. Find one mount with ro, one with nosuid, and one with noexec, and say what each prevents.

Done when: three lines with their meaning, or a note that your machine has none of them and which one you would add.

Hint

the options are the fourth column of /proc/mounts.

Hard

Hard 1: Add a file system (90 minutes)

Add a fourth file system to the miniature VFS, countfs, that returns the text "count 1", "count 2" and so on at each read, mounted on /count. Add a write operation to the table and make memfs accept it.

Done when: three reads of /count print increasing numbers, and a write to /note followed by a read returns the new text.

Hint

add a field write to the struct and a counter variable inside countfs.

Hard 2: Stay on one file system (90 minutes)

Write a program that walks a directory tree with nftw and the flag FTW_MOUNT, and counts the files. Run it on / and compare with a run without the flag.

Done when: two counts, with the second much larger or slower, and a sentence that says that the first stayed on one device.

Hint

nftw(path, fn, 20, FTW_PHYS | FTW_MOUNT).

Hard 3: Read mountinfo (90 minutes)

Write a program that reads /proc/self/mountinfo and prints, for each mount, the mount point, the type and the source. Then add a function that, for a given path, finds the mount with the longest matching mount point.

Done when: the list of your mounts, and the correct mount found for three test paths, one of them inside a tmpfs.

Hint

the fields of mountinfo are separated by spaces and the type follows a single dash.