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.

TL;DR

The focus of this reading is to explore system calls related to I/O, files, and directories in C.

Readings

The readings for Monday, April 9 are:

  1. Operating Systems: Three Easy Pieces

Optional References

  1. System Programming Wiki

Quiz

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 GitLab

$ git checkout -b reading10           # Create reading10 branch and check it out

$ cd reading10                        # Go into reading10 folder

# Download Reading 10 Makefile
$ curl -LO https://gitlab.com/nd-cse-20289-sp18/cse-20289-sp18-assignments/raw/master/reading10/Makefile

# Download, build, and execute tests
$ make test

Questions

Record the answers to the following Reading 10 Quiz questions in your reading10 branch:

Programs

Write the C equivalent, walk.c, to the Python code below (walk.py):

#!/usr/bin/env python3

import os

for name in os.listdir('.'):
    if os.path.isfile(name):
        print(name, os.path.getsize(name))

This should output something like this:

$ ./walk.py
walk.c 844
test_walk.sh 1297
walk 14464
Makefile 565
README.md 22
answers.json 303
walk.py 136

Makefile

Update the Makefile such that it contains a rule that builds the walk program:

$ make                # Build walk program
gcc -g -gdwarf-2 -Wall -Werror -std=gnu99 -o walk walk.c

$ ./walk              # Run walk program
walk.c 844
test_walk.sh 1297
walk 14464
Makefile 565
README.md 22
answers.json 303
walk.py 136

$ make clean          # Cleanup
rm -f walk

Requirements

Your program must:

Hints

Consider using the following system calls:

Submission

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 reading10           # Create reading10 branch and check it out

$ cd reading10                        # Go into reading10 folder

$ $EDITOR answers.json                # Edit your answers.json file

$ ../.scripts/submit.py               # Check reading10 quiz
Submitting reading10 assignment ...
Submitting reading10 quiz ...
      Q1 0.50
      Q2 0.50
      Q3 1.00
   Score 2.00

$ git add answers.json                # Add answers.json to staging area
$ git commit -m "Reading 10: Quiz"    # Commit work

$ $EDITOR walk.c                      # Edit source code

$ make test                           # Build and Run tests
Testing walk ...
 walk (syscalls)                          ... Success
 walk (output)                            ... Success
 walk (output w/ dir)                     ... Success
 walk (valgrind)                          ... Success
   Score 2.00

$ git add Makefile                    # Add Makefile to staging area
$ git add walk.c                      # Add source code to staging area
$ git commit -m "Reading 10: Code"    # Commit work

$ git push -u origin reading10        # Push branch to GitLab

Remember to create a merge request and assign the appropriate TA from the Reading 10 TA List.