The purpose of this assignment is for you to explore the xv6 source code and find the appropriate things to modify to implement a system call collecting stats about open files.

After this assignment, you should be familiar with:

Before you start, make sure you are able to run xv6 on your machine. Follow the directions given in Lab 10.

Since familiarizing yourself with an unknown source code base might be a little daunting, we have generated an interlinked browsable version of xv6 for your convenience.

Note: The goal is for you to search around and find stuff. It would be best if you avoid posting exact function names or the line numbers that need to be changed to complete this assignment on Piazza or anywhere else.

Task

For this assignment you’ll be adding a system call which returns a struct containing the following information:

struct iostats {
    uint read_bytes;     // the total number of bytes read
    uint write_bytes;    // the total number of bytes written
};

The system call should have the following signature:

int getiostats(int fd, struct iostats* stats);

Given a file descriptor, getiostats gets the total number of bytes read and written on that file descriptor since it was opened. This information is returned in the user-supplied iostats structure. Returns 0 on success, or -1 on failure (e.g. bad file descriptor).

Plan

For this task, you will need to do the following:

  1. Modify the structure xv6 uses for open files to track the number of bytes read and written.
  2. Modify the implementations of the appropriate system calls to initialize and update these counters.
  3. Add the new getiostats system call to read these fields.
  4. Add the struct iostats definition to stat.h

Hint: Look at how the other system calls that use a file descriptor work.

Setting up for the tests

The three test programs included with the starter code—test1.c, test2.c and test3.c—are not built into the xv6 image by default, since they rely on a system call that doesn’t exist yet.

Make sure to add them to the appropriate list in the xv6 Makefile.

Manual Testing

Debugging

Deliverables

All Tasks ~ Implement your modification to the OS sources in the xv6 directory.

Commit the code to your repository. Do not include any executables, .o files, .img files, or other binary, temporary, or hidden files (unless they were part of the starter code).

Once you are done, remember to submit your solution to Gradescope and do not forget to include your partner.


Hints & Tips


Ben Weintraub © 2025
Site Last Updated June 27, 2025 at 13:20:40 UTC