Lab Handout 1: File Systems and System Calls
This lab was designed by Jerry Cain.
The first and last exercises are problem set-esque questions that could easily appear on a midterm or final exam (or, in your case, a self-assessment). In fact, all of the questions asked in Problem 3 were on previous midterms and finals. The middle problem is an experiment that'll require you fire up your laptop and run some programs and development tools.
Lab Overview
Your weekly lab is a chance to experiment and explore, ask and answer questions, and get hands-on practice in a supported environment. We provide a set of lab exercises that revisit topics from recent lectures/readings and prepare you to succeed at the upcoming assignment.
Lab is collaborative! We're all in this together! We will work together on the exercises. The entire group is one learning community working together to advance the knowledge and mastery of everyone. Stuck on an issue? Ask for help. Have an insight? Please share!
To track lab participation, we have an online checkoff form for you to fill out as you work. Lab is not a race to find answers to exactly and only the checkoff questions-- the checkoff questions are used only to record attendance and get a read on how far you got. Lab credit is awarded based on your sincere participation for the full lab period. Your other rewards for investing in lab are to further practice your skills, work together to resolve open questions, satisfy your curiosity, and reach a place of understanding and mastery. The combination of active exploration, give and take with your peers, and the guidance of the TA makes lab time awesome. We hope you enjoy it!
Get Started
Clone the lab starter code by using the command below. This command creates a lab1
directory containing the project files.
git clone /afs/ir/class/cs110/repos/lab1/shared lab1
Next, pull up the online lab checkoff and have it open in a browser so you can jot things down as you go.
Exercises
1) Direct, Singly Indirect, and Doubly Indirect Block Numbers
Assume blocks are 512 bytes in size, block numbers are four-byte int
s, and that inodes include space for 6 block numbers. The first three are direct block numbers, the next two are singly indirect block numbers, and the final one is a doubly indirect block number.
- What's the maximum file size?
- How large does a file need to be before the relevant inode requires the first singly indirect block number be used?
- How large does a file need to be before the relevant inode requires the first doubly indirect block number be used?
- Draw as detailed an inode as you can if it's to represent a regular file that's 2049 bytes in size.
2) valgrind
and orphaned file descriptors
Here's a very short exercise to enhance your understanding of valgrind
and what it can do for you. To get started, go into your lab1
directory and compile the provided program. Now open the code file and trace through the code to keep tabs on what file descriptors are created, properly closed, and orphaned.
With this information, try tracing through the program to better understand the file descriptors that are created, closed, and left open. In particular, with the knowledge that open
will use the lowest unused file descriptor, calculate the actual file descriptor numbers. Then run valgrind ./open-fds
to confirm that there aren't any memory leaks or errors (how could there be?), but then run valgrind --track-fds=yes ./open-fds
to get information about the file descriptors that were (intentionally) left open.
Without changing the logic of the program, insert as many close statements as necessary so that all file descriptors (including 0, 1, and 2) are properly donated back. (In general, you do not have to close file descriptors 0, 1, and 2, but for this problem you should.)
3) Short Answer Questions
Provide clear answers and/or illustrations for each of the short answer questions below. Each of these questions is either drawn from old exams or based on old exam questions. Questions like this will certainly appear on assessments.
-
The
dup
system call accepts a valid file descriptor, claims a new, previously unused file descriptor, configures that new descriptor to alias the same file session as the incoming one, and then returns it. Briefly outline what happens to the relevant file entry table and vnode table entries as a result ofdup
being called. (Readman dup
if you'd like, though don't worry about error scenarios). -
Now consider the prototype for the
link
system call (peruseman link
). A successful call tolink
updates the file system so the file identified byoldpath
is also identified bynewpath
. Oncelink
returns, it’s impossible to tell which name was created first. (To be clear,newpath
isn’t just a symbolic link, since it could eventually be the only name for the file.) In the context of the file system discussed in lecture and/or the file system discussed in Section 2.5 of the secondary textbook (S&K), explain howlink
might be implemented. -
Explain what happens when you type
cd .././../.
at the shell prompt. Frame your explanation in terms of the file system described in Section 2.5 of the secondary textbook, and the fact that the inode number of the current working directory is the only relevant global variable maintained by your shell. -
All modern file systems allow symbolic links to exist as shortcuts for longer absolute and relative paths (e.g.
search_soln
might be a symbolic link for/usr/class/cs110/samples/assign1/search_soln
, andtests.txt
might be a symbolic link for./mytests/tests.txt
). Explain how the absolute pathname resolution process we discussed in lecture would need to change to resolve absolute pathnames to inode numbers when some of the pathname components might be symbolic links.