Lab 1 Design Document

Aaron Bauer

January 9, 2022

Lab 1 Design Doc: System Calls

Overview

The goal of this lab is to implement an interface for users to interact with persistent media or with other I/O devices, without having to distinguish between them.

Major Parts

File Interface: Provide an abstraction for the user that doesn’t depend on the type of file. This will allow user applications to interact with different types of files without large changes in the code. For example, the method for attaining bytes will be the same when reading input from a file and as when reading from stdin.

System Calls: The system call interface provides a barrier for the kernel to validate user program input. This way, we can keep the I/O device state consistent. No user program can directly affect the state of the kernel’s data structures. Furthermore, when we are in the kernel code, we then don’t have to go through the syscall interface, which cuts down superfluous error checking for trusted code.

In-depth Analysis and Implementation

File Interface

Bookkeeping

include/kernel/fs.h provides a struct file that we can use to back each file descriptor. include/kernel/console.h provides console file structs for stdin and stdout.

Process View

Each process will have an array of open files (Bounded by PROC_MAX_FILE) in the process struct. The file descriptor will be the respective index into the file table. Ex: stdin is typically file descriptor 0, so the corresponding file struct will be the first element. A system call can use proc_current() to get a pointer to the process control block (i.e., the struct proc) for the currently-running process.

System Calls

We need to parse arguments from the user and validate them (we never trust the user). There are a few useful functions provided by osv:

Since all our system calls will be dealing with files, we think it will be useful to add a function that allocates a file descriptor, and another that validates a file descriptor:

The main goals of the sys_* functions is to do argument parsing and validation, and then calling the associated fs_*_file functions.

File System

We will need to use several file system functions declared in include/kernel/fs.h. These are:

Risk Analysis

Unanswered Questions

Staging of Work

First, I will implement the per process open file table. Then I will retrieve and validate syscall inputs, and call the respective file functions. I will also update process initialization so that fd 0 and 1 point to stdin and stdout from console.h.

Time Estimation

When you author your own design documents on future labs, you will include a time estimate for the various tasks. You might practice your estimation skills by making estimates for this lab and keep track of your time to check them.