Everyone:
Next week, we will begin our exploration of file systems and in particular the venerable FFS and LFS.
For this reading assignment, you are to read about file systems, and submit your responses to the Reading 11 Quiz.
The readings for this week are:
Using Learn About from Google, have a conversation about file systems, and LFS by asking the following questions:
- Why does the unix file system have a superblock?
- How does a file system store metadata?
- What is an indirect block in the context of a file system?
- How does FFS compare to the traditional unix file system?
- How does LFS compare to the traditional unix file system?
As you explore, feel free to dive into the suggested related questions or to "simplify", "go deeper", and "get images".
Once you have done the readings, answer the following Reading 11 Quiz questions:
For this week, you are to take your program
from Reading 02 and modify
it so that it supports directories as arguments.
The standard sha1sum does not understand directories:
$ sha1sum .
sha1sum: .: Is a directory
Your program
, however, should recursively walk any directories given to
it as an argument and check the files (and directories) with in the given
folder:
# Compute checksum on Makefile, current directory, and non-existent file
$ ./program Makefile . asdf
6e63c0859f0dfc9bf56996ae593ca048b809fc27 Makefile
6e63c0859f0dfc9bf56996ae593ca048b809fc27 ./Makefile
8cb3fa236aa278e3557f962e156f2358bd8e6c24 ./README.md
3e43745ae7f331f11a8102f47a74043f27539e1e ./program
8c53ff3421b9ed6bca45d866e1b8add47e63bdfa ./answers.json
f51db4f87ed1d34124cb92c7be1c932546f652f4 ./program.c
7ec632ad54439235effa874731326fb82ce31d00 ./test_program.sh
$ echo $?
1
Your program must compile cleanly with no warnings.
Your program may only use I/O system calls such as open, read, and close to access the contents of each file.
Your program must use the SHA1()
function provided by OpenSSL.
Your program must use file system functions such as opendir, readdir, and closedir, and use file system calls such as stat.
Your program must not have any resource leaks or memory errors as detected by valgrind.
To handle directories as arguments, you can structure your program as follows:
cksum_file(path):
if sha1sum_file(path, cksum):
print(...)
return 0
return 1
cksum_directory(root):
for each entry in root directory:
if entry in ('.', '..'):
continue
if entry is directory:
status += cksum_directory(full path of entry)
else:
status += cksum_file(full path of entry)
return status
main:
for each argument:
if argument is directory:
status += cksum_directory(argument)
else:
status += cksum_file(argument)
return status
In main
, you can use stat to check the type of the argument.
In cksum_directory
, you can use sprintf to build the full path of
each entry
.
If you do not remember how to programmatically manipulate the file system, I recommend the following resources:
To submit you work, follow the same process outlined in Reading 01:
$ git switch master # Make sure we are in master branch
$ git pull --rebase # Make sure we are up-to-date with GitLab
$ git checkout -b reading11 # Create reading11 branch and check it out
$ cd reading11 # Go into reading11 folder
$ $EDITOR answers.json # Edit your answers.json file
$ ../.scripts/check.py # Check reading11 quiz
Checking reading11 quiz ...
Checking reading11 quiz ...
Q01 0.50
Q02 0.25
Q03 0.30
Q04 0.15
Q05 0.20
Q06 0.10
Q07 0.50
Score 2.00 / 2.00
Status Success
$ git add answers.json # Add answers.json to staging area
$ git commit -m "Reading 11: Quiz" # Commit work
$ $EDITOR program.c # Edit your program.c file
$ make test-program # Check reading11 program
Testing reading11 program...
I/O System Calls ... Success
I/O Functions ... Success
SHA1 Functions ... Success
File System System Calls ... Success
File System Functions ... Success
program ... Success
program (valgrind) ... Success
program Makefile ... Success
program Makefile (valgrind) ... Success
program Makefile README.md ... Success
program Makefile README.md (valgrind) ... Success
program Makefile README.md program.c ... Success
program Makefile README.md program.c (valgrind) ... Success
program Makefile README.md asdf program.c ... Success
program Makefile README.md asdf program.c (valgrind) ... Success
program Makefile README.md /bin/ls /bin/bash ... Success
program Makefile README.md /bin/ls /bin/bash (valgrind) ... Success
program . ... Success
program . (valgrind) ... Success
program .. ... Success
program .. (valgrind) ... Success
program Makefile . asdf /bin/ls ... Success
program Makefile . asdf /bin/ls (valgrind) ... Success
program . .. /root ... Success
program . .. /root (valgrind) ... Success
Score 2.00 / 2.00
Status Success
$ git add Makefile # Add Makefile to staging area
$ git add program.c # Add program.c to staging area
$ git commit -m "Reading 11: Code" # Commit work
$ git push -u origin reading11 # Push branch to GitHub
Once you have committed your work and pushed it to GitHub, remember to create a pull request and assign it to the appropriate teaching assistant from the Reading 11 TA List.