Homework #4 Disk and Storage Systems

Due: 12/1/06 in class

Part A

The block is the minimum unit of file system allocation and I/O. A typical block size if 4 KB. Given this, how is it possible for the read() system call to return a single byte?

char buffer[1]; // one byte buffer
read (fileDescriptor,buffer,1);

Part B

What is the largest possible file given a UNIX-like file system with the following characteristics. The i-node contains 12 direct pointers, 1 indirect block pointer, 1 doubly indirect block pointer, and 1 triply indirect block pointer. Block are 1 KB, and each block pointer is 4 bytes.

Part C

In class, we looked at two ways to read file information from disk: the read() system call and memory-mapped files (using the mmap() system call). Your task in this problem is to design a "smart read" function, which chooses the appropriate read implementation in order to optimize performance. The prototype for smartRead is as follows:

void smartRead(int fileDescriptor, void* buffer, int size,int fileOffset);

For this problem, you should assume that the read() system call always performs a memory-to-memory copy (from the file cache to the page cache). The mmap() system call is faster because it avoids this copy. So, we want to memory map the file whenever possible.

You should assume that the block size and the page size are 4 KB. Also, all OS buffers (for file blocks and virtual memory pages) are page aligned --- this means that the last 12 bits are zeroes. The user-provided pointer/buffer is valid, but contains just enough space for the file (in other words, there is pre-existing data on both sides of the buffer).

Answer the following three questions: