CS 134

System Calls

file_syscalls.c, syscall.c, and proc_syscalls.c

sys_chdir()

We will call syscall to call vfs_chdir.

sys_execv()

To implement execv(), we will use as_create to make a new struct addrspace * and replace the old address space in struct proc with the new one. There are still things we need to figure out here, but we need to keep in mind that we traverse userspace and the kernel multiple times.

sys___getcwd()

We will call syscall to call vfs_getcwd.

sys_fork()

We will make a new struct proc and duplicate our current process file table and assign it to the new proccess. We will make a new PID for the child and add it to the PID table. We will call thread_fork() with the new proc we created and use the trapframe to then call enter_forked_process().

sys__exit()

We will remove process from process table and deallocate the struct for the terminated process. We will set the exit code in the PID table and signals the parents process.

File System

openfile.c and openfile.h

We are planning hold file information in one struct called fileinfo that contains data about the following fields:

  • a pointer to the file vnode, a struct vnode *
  • the number of references, an int
  • the seek index, an int
  • the flags regarding how to open / access the file, an int
  • a lock to protect data, a lock *

openfile_open()

To implement this, we will use vfs_open() from the kernel code. We will also set the descriptor index to the lowest available file descriptor. By default, the seek index will be 0 and the references will be 1. If an error occur, we will set the appropriate error code.

open will need to be protected by a lock, which we will do with locks and condition variables.

Relevant functions are vop_creat if a certain flag is passed in, vfs_open, and vop_pathname.

openfile_read()

To implement this, we will use VOP_READ. If this file can be written to, then we should protect this with a lock. We will use the given buffer argument to store the data from VOP_READ.

Relevant functions are uio_move().

openfile_write()

To implement this, we will use VOP_WRITE. We should protect this function with a lock. We will use the given buffer argument as input to write to the given file.

Relevant functions are uio_move().

openfile_close()

To implement this, we will use vfs_close(). We will remove the file descriptor from the file table and deallocate the fileinfo struct for the given file.

close should be protected by a lock.

openfile_lseek()

To implement this, we will modify the offset parameter in the uio struct within fileinfo to the given offset. We will protect this with a lock.

filetable.c and filetable.h

To implement the file table, we will create a struct filetable which contains array of 128 struct fileinfo*s, each of which point to their respective file. The index in the file table will be the file descriptor, with index 0 corresponding to stdin, index 1 corresponding to stdout, and index 2 will be stderr.

filetable init --> set to null, check within bounds,

filetable_dup2()

To implement this, we will check that newfd and oldfd are valid. Then, we will close newfd if it is already in use. We will assign the file descriptor at newfd to the file at file descriptor oldfd. We will increment references in the file that it points to.

We will protect this with a lock.

Process Calls

We will add:

  • a struct filetable to struct proc, such that every process gets its own filetable
  • the process's pid
  • the parent's pid

proc.c and proc.h

proc_getpid()

This will return the given process' PID, as given in struct proc.

pid.c and pid.h

We will have a similar implementation to the code in Week 5, Lesson 2. We will keep track of all the pid's with a struct with an array called pid_array.

pid_waitpid()

We will have a global lock and a global CV indicating when a parent should read the child's exit status. If the process is finished (signaled by CV), the parent process will deallocate the child's procinfo struct. If the process is not finished, the parent will go to sleep until it is awoken by the global CV.

(When logged in, completion status appears here.)