# Homework 8

Due 3/23/2012 [start of section]

## Problem 1

Suppose that I implement a FFS-like file system that stores data in 4KB blocks on disk and that uses 4-byte block IDs in its inodes and triple/double/single-indirect blocks. What is the largest disk this file system can support?

## Problem 2

1. An engineer has designed a FAT-like system and he has used 24 bits for each entry. For a 32-GB disk, what is the minimum size of a file allocation in this system? Justify your answer.

2. Consider an index-based file system with the inode containing 64 indexes, 1 indirect index pointing to a disk block containing an array of direct indexes, and 1 2-level index in the usual way. Assume that each index takes 4 bytes.
1. What is the maximum file size under this arrangement, if a disk block is 1024 bytes? Explain how do you compute this maximum size.
2. How many disk accesses does it take to read one disk block at location 3000321 within a file, assuming no caching. Justify your answer.

## Problem 3

Consider a very simple file system for a tiny disk. Each sector on the disk holds 2 integers, and all data blocks, indirect blocks, and inodes are 1 disk sector in size (each contains 2 integers). All files stored on disk are interpreted as directories by the file system (there are no "data files"). The file system defines the layout for the following data types on disk:
inode = 1 pointer to a data block + 1 pointer to indirect block

indirect block = 2 pointers to data blocks

directory = a regular file containing zero or more pairs of integers; the first integer of each pair is a file name and the second is the file's inumber

The value "99" signifies a null pointer when referring to a disk block address or directory name. An empty directory has one disk block with the contents "99   99". The inumber for root directory is "/" is 0.

The following data are stored on disk:

inode array:
 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 106 799 899 399

disk blocks:
 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 323 961 199 9999 9999 576

1. How many entries can appear in a maximum-sized directory? (Each entry is a pair of integers)

2. List all directories stored on this disk (full path names) along with the names of the files stored in each directory.

 directory path name inumber indirect blocks data blocks contents (subdirectories) / 0

3. Modify the above data structures to add an empty directory called "87" to directory "/"

 directory path name inumber indirect blocks data blocks contents (subdirectories) /87

## Problem 4

Consider the (tiny) disk with 64 sectors shown below, which stores a FFS-like file system. The disk reserves the first 16 sectors for its inode array. Each sector stores four 4-byte words. An inode fills a sector and contains 2 direct pointers, 1 indirect pointer, and 1 double-indirect pointer. An inumber is a 4-byte integer. In a directory, a file name is a 4-byte array of 1-byte characters. A block ID is a 4-byte integer. The root directory's inumber is 0.
• (a) What is the largest file size (in sectors) this file system can support?
• (b) For the file system on this disk how large (in sectors) is the file with inumber 6?
• (c) For th file system on this disk, what is the inumber of file /FOO/BAR?
• (d) For the file system on the disk in Figure~\ref{tinyFS} on page \pageref{tinyFS}, what do I get if I read 1 word from file /APT/ZED'' starting from 16 bytes (4 words) into the file?
• (e) For the file system on this disk what do I get if I read the last word from file /APT/ZED?
• (f) The file system on this disk cannot support hard links. Why?
• ## Problem 5

You are implementing a file server that contains 25 16GB disks and uses the UNIX file system to implement the network file server (NFS). A engineer in the lab gives you a 1GB disk that she no longer needs. What would you do with this disk?

## Problem 6

Suppose you have a file system with multi-level indexing (with 14 direct pointers, 1 indirect inode, 1 doubly indirect pointer, and 1 triple indirect pointer in the inode), directories, inodes statically allocated in an array 0..MAX_INUM to a known location on disk. Also assume there is an on-disk bitmap of free inodes and free sectors. Assume that the file containing the root directory is stored in a well-known inode with inumber ROOT_INUM.

Assume each file fits in one sector. Assume each inode consumes exactly one sector.

Consider creating a new file "/foo/bar" in the existing directory "foo" and writing one sector of data to that file.

Assume no in-memory cache.

1. List the reads and writes that must be executed to accomplish this task (and explain how each disk address is determined.)

2. Suppose we want to ensure that these actions occur reliably (e.g., if a crash occurs, the file ends up either created and full with the bitmaps and directories updated accordingly or not created with none of these updates having occurred). Using ordered synchronous metadata writes and FSCK (File System ChecK program --e.g., file system recovery on reboot), explain how to meet this guarantee. In particular,
1. Write down the writes in order they should occur.
2. List the actions that the fsck program must take to ensure the disk is brought to a correct state on recovery and show that these actions guarantee file systems consistency.

3. Suppose we want to ensure reliable updates using logging (e.g., as per a journaling file system). List the series of writes (to the disk and log) in the order they should occur. Also describe what actions (if any) must be taken on recovery after a crash.

## Problem 7

In some operating systems, IO from/to disk is done directly to/from a buffer in the user program's memory. The user program does a system call specifying the address and length of the buffer (the length must be a multiple of the disk record size).

The disk controller needs a physical memory address, not a virtual address. Ben Bitdiddle proposes that when the user does a write system call, the operating system should check that the user's virtual address is valid, translate it into a physical address, and pass that address and the length (also checked for validity) to the disk hardware.

This won't quite work. In no more than two sentences, what did Ben forget?

## Problem 8

Suppose you have a file system with multi-level indexing (with 14 direct pointers, 1 indirect inode, 1 doubly indirect pointer, and 1 triple indirect pointer in the inode), directories, inodes statically allocated in an array 0..MAX_INUM to a known location on disk. Also assume there is an on-disk bitmap of free inodes and free sectors. Assume that the file containing the root directory is stored in a well-known inode with inumber ROOT_INUM.

Assume each file fits in one sector. Assume each inode consumes exactly one sector.

Consider creating a new file "/foo/bar" in the existing directory "foo" and writing one sector of data to that file.

Assume no in-memory cache.

1. List the reads and writes that must be executed to accomplish this task (and explain how each disk address is determined.)

2. Suppose we want to ensure that these actions occur reliably (e.g., if a crash occurs, the file ends up either created and full with the bitmaps and directories updated accordingly or not created with none of these updates having occurred). Using ordered synchronous metadata writes and FSCK (File System ChecK program --e.g., file system recovery on reboot), explain how to meet this guarantee. In particular,
1. Write down the writes in order they should occur.
2. List the actions that the fsck program must take to ensure the disk is brought to a correct state on recovery and show that these actions guarantee file systems consistency.

3. Suppose we want to ensure reliable updates using logging (e.g., as per a journaling file system). List the series of writes (to the disk and log) in the order they should occur. Also describe what actions (if any) must be taken on recovery after a crash.