## Solution Set 6

### Problem 1

Suppose that a block is 1K Byte and that a disk address is 4 bytes. Suppose that files are implemented using i-nodes, and that an i-node has the following structure: Bytes 0-127 of the i-node are file attributes. Bytes 128-1011 are addresses of data blocks. Bytes 1012-1015 are the address of an indirect block. Bytes 1016-1019 are the address of an second-level indirect block. Bytes 1020-1023 are the address of a third-level indirect block.
• A. File F has 1 MByte of data. How many data blocks, indirect blocks, second-level indirect blocks, and third-level indirect blocks are used?

Answer: Each indirect block holds 1024/4=256 addresses. The inode holds the addresses of (1012-128)/4= 221 data blocks.

In a 1 MByte file, there are 1024 data blocks. The first 221 of these are indexed directly by the inode, so there must be ceiling((1024 - 221)/256) = 4 indirect blocks. The first of these is indexed by the inode; the other 3 are indexed by a single doubly-indirect block.

• B. Answer the same question for a file with 100 MBytes of data. (Note: 1MByte = 220 bytes. 100 MBytes = 100*220 bytes.)

Answer: In a 100 MByte file, there are 102,400 data blocks. The first 221 of these are indexed directly by the inode, so there must be ceiling((102400 - 221)/256) = 400 indirect blocks. The first of these is indexed by the inode; the remaining 399 are indexed by two doubly-indirect blocks. The first of these is indexed by the inode, the second is indexed in a single triply-indirect block.