This course website is from a previous semester. If you are currently in the class, please make sure you are viewing the latest course website instead of this old one.
Everyone:
Next week, we will descending further down the system stack and introduce system calls, which are services or operations performed by the operating system kernel on our behalf. In particular, we will explore system calls related to I/O, files, and directories and discuss how many of the utilities we use every day are implemented.
The focus of this reading is to explore system calls related to I/O, files, and directories in C.
The readings for this week are:
This week, the reading is split into two sections: the first part is a dredd quiz, while the second part involves one C program: walk.c.
To test the C program, you will need to download the Makefile and test scripts:
$ git checkout master # Make sure we are in master branch
$ git pull --rebase # Make sure we are up-to-date with GitHub
$ git checkout -b reading11 # Create reading11 branch and check it out
$ cd reading11 # Go into reading11 folder
# Download Reading 11 Makefile
$ curl -LO https://raw.githubusercontent.com/nd-cse-20289-sp23/cse-20289-sp23-assignments/master/reading11/Makefile
# Download Reading 11 walk.c
$ curl -LO https://raw.githubusercontent.com/nd-cse-20289-sp23/cse-20289-sp23-assignments/master/reading11/walk.c
# Download, build, and execute tests
$ make test
Record the answers to the following Reading 11 Quiz questions in your
reading11
branch:
Given the provided Makefile and walk.c, you are to do the following:
Modify Makefile to include a rule for the walk
program. Be sure to
use the CC
and CFLAGS
variables in your rule.
Once you have a working Makefile, you should be able to use the make command to run your recipes:
$ make clean # Remove targets
rm -f walk
$ make # Build targets
gcc -Wall -std=gnu99 -g -o walk walk.c
Modify walk.c so that it uses system calls in C to implement the equivalent Python script:
import os
import sys
root = sys.argv[1] if len(sys.argv) > 1 else '.'
for name in os.listdir(root):
path = os.path.join(root, name)
if os.path.isfile(path) and not os.path.islink(path):
print(name, os.path.getsize(path))
That is, given a root
command-line argument (default is "." if nothing
is specified), the program should iterate through the contents of that
root
directory and print out the name and size of each regular file.
The code has a few ____
placeholders. You will need to replace these
placeholders with the appropriate functions and variables to
complete the program.
Here is a list of some possible functions and variables you may wish to use:
Once you have a working walk.c
, you should be able to build and run it:
$ ./walk # No arguments (current directory)
Makefile 446
walk 24864
README.md 13
answers.json 303
test_walk.sh 1824
walk.c 1000
$ ./walk .. # Parent directory
Makefile 385
README.md 2654
.replit 17
.gitignore 34
Dockerfile 499
To submit you work, follow the same process outlined in Reading 01:
#--------------------------------------------------
# BE SURE TO DO THE PREPARATION STEPS ABOVE
#--------------------------------------------------
$ cd reading11 # Go into reading11 folder
$ $EDITOR answers.json # Edit your answers.json file
$ ../.scripts/check.py # Check reading11 quiz
Checking reading11 quiz ...
Q01 0.50
Q02 0.50
Q03 1.00
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 walk.c # Edit source code
$ make test # Build and Run tests
Checking reading11 walk ...
walk (no arguments) ... Success
walk . ... Success
walk .. ... Success
walk ~ ... Success
walk /etc ... Success
walk asdf ... Success
Score 2.00 / 2.00
Status Success
$ git add Makefile # Add Makefile to staging area
$ git add walk.c # Add source code to staging area
$ git commit -m "Reading 11: Code" # Commit work
$ git push -u origin reading11 # Push branch to GitHub
Remember to create a Pull Request and assign the appropriate TA from the Reading 11 TA List.
DO NOT MERGE your own Pull Request. The TAs use open Pull Requests to keep track of which assignments to grade. Closing them yourself will cause a delay in grading and confuse the TAs.