Lab 3: Memory management and File Systems

Due: Dec 10, 2015, 5pm


This lab has two parts, one on memory management and one on file systems. There is also an extra credit question, which is optional. All parts must be written in C or C++.

Part I: Memory management - paging

This purpose of this component of the lab is to implement a portion of the virtual to physical address translation in a pure paging based scheme. You goal is to write a program that takes a sequence of virtual addresses and extract the page number and offset for each address using bit-wise operations.

Assume that virtual addresses are unsigned integers (i.e., unsigned int) and that we only look at 16 bits of the integer representing a virtual address. Thus, even if your machine represents integers as 32 or 64 bits, we are only concerned with the lower 16 bits of an integer to represent the virtual address. Your program should take the following inputs from an input file:

n   /* the n lowest significant bits that represent the offset */
m   /* the next m bits that represent the page number; assume that n+m is always 16 */
v1   /* first virtual address that needs to be mapped to a page number and offset */
v2   /* second virtual address */
...  /* a sequence of virtual addresses, one per line until the end of the file */

Your program should read the above input file, and in particular, read each virtual address as an unsigned integer and compute and print out the page number and offset for each address. Assume that the virtual addresses are correct and no error checks are needed. To compute the offset, use bit operations in C/C++ to extract the n least significant bits from v and print out the resulting integer. To compute the page number, extract the next m significant bits from v and print out the integer representing these bits.

You can check the result of your program by hand-computing the page number and offset as v DIV 2^n and v MOD 2^n However your program should not use division and mod operations to compute these values and should use bit-wise operations instead (just as a hardware implementation of paging would use).

The output of your program should look like:

virtual address v1 is in page number p and offset d
virtual address v2 is in page number p and offset d
...
Here is a tutorial on bit operations in C and C++: tutorial. Pay particular attention to the right shift operator as well as the using bit-masks and the bit-wise AND operation, which are concepts that will be helpful for this lab.

Part II: File Systems

The goal of part 2 of lab is to write a simple UNIX-like file system based on the topics covered in class. The file system you will write makes the following simplifying assumptions:


The layout of your 128 KB disk is as follows


You need to implement the following operations for your file system.


Getting Started for Part II