CS360 Midterm Exam: March 2, 2004. Answer to Question 2
When jl executes, the directory ex1 has the following
contents:
. -- the current directory. Its size will be 512 bytes, and it will
have three links (../ex1, ., and d1/..).
.. -- the parent directory. We don't know what its size is, or how
many links it has. Certainly its size will be at least 512, and
it will have at least 3 links.
f2: Its size is 5 bytes ("Exam" and the newline), and it
has two links (f2 and d1/f2).
f3: Its size is 4 bytes ("Hi!" and the newline), and it
has one link (the link to f4 is a symbolic link, and f1
has been deleted).
f4: This is a symbolic link to f3. Since our program
calls stat(), and not lstat(), it will appear to have
the same inode as f3, although it is not included in the
nlink field of the stat struct.
f5: This is a symbolic link to f3, which is gone. Therefore,
stat("f5", &buf) will return -1, and jl will not print anything
for it.
f6: This has been created by the shell
before jl executes. Its size will be zero when the stat()
call is made.
d1: This is a directory with one file, so its size will be
512 bytes. It has two links (./d1 and ./d1/.).