Everyone:

Next week, we will begin our exploration of file systems and in particular the venerable FFS and LFS.

TL;DR

For this reading assignment, you are to read about file systems, and submit your responses to the Reading 11 Quiz.

Reading

The readings for this week are:

  1. Operating Systems: Three Easy Pieces

Optional AI Conversation

Using Learn About from Google, have a conversation about file systems, and LFS by asking the following questions:

  1. Why does the unix file system have a superblock?
  2. How does a file system store metadata?
  3. What is an indirect block in the context of a file system?
  4. How does FFS compare to the traditional unix file system?
  5. 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".

Quiz

Once you have done the readings, answer the following Reading 11 Quiz questions:

Program

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

Requirements

Hints

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

If you do not remember how to programmatically manipulate the file system, I recommend the following resources:

  1. Files and Directories

  2. Reading 11: File System

  3. list.c

Submission

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 ...
     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 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

Pull Request

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.