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 12 Quiz.
The readings for this week are:
Once you have done the readings, answer the following Reading 12 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 checkout master # Make sure we are in master branch
$ git pull --rebase # Make sure we are up-to-date with GitLab
$ git checkout -b reading12 # Create reading12 branch and check it out
$ cd reading12 # Go into reading12 folder
$ $EDITOR answers.json # Edit your answers.json file
$ ../.scripts/check.py # Check reading12 quiz
Checking reading12 quiz ...
Q01 0.80
Q02 0.50
Q03 0.30
Q04 0.30
Q05 0.40
Q06 0.20
Q07 0.50
Score 3.00 / 3.00
Status Success
$ git add answers.json # Add answers.json to staging area
$ git commit -m "Reading 12: Quiz" # Commit work
$ $EDITOR program.c # Edit your program.c file
$ make test-program # Check reading12 program
Testing reading12 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 3.00 / 3.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 12: Code" # Commit work
$ git push -u origin reading12 # 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 12 TA List.