Disk Access: Inode Traversal Arithmetic
The problem
The Tripos asks: how many disk accesses are needed to read a specific byte of a file, given the inode and block-pointer structure? The answer depends on the size and position of the byte, because larger files require traversing indirect blocks.
The inode structure (standard model)
Assume the Tripos-standard inode:
- 10 direct block pointers
- 1 single-indirect pointer
- 1 double-indirect pointer
- 1 triple-indirect pointer
- Block size = bytes
- Pointers are bytes (typically 4 or 8)
- Pointers per block =
Counting disk accesses
To read the -th byte of a file:
-
Read the inode: 1 disk access (unless cached). For the purposes of exam arithmetic, we usually count accesses from the inode in memory — i.e., we assume the inode has already been read. Check the question wording carefully.
-
Determine which pointer tier to use:
- Bytes : use a direct pointer → 1 access (the data block).
- Bytes where : single indirect → 2 accesses (read the indirect block, then the data block).
- For double indirect: 3 accesses (double-indirect block, single-indirect block, data block).
- For triple indirect: 4 accesses.
Worked example (2021 Paper 2 Q3(b))
A file system with 4 KB blocks and 4-byte block pointers. Inode has 10 direct pointers, 1 single, 1 double, 1 triple indirect. How many disk accesses to read byte 10,000,000?
-
Pointers per block: .
-
Direct range: bytes (approximately 41 KB). Byte 10,000,000 is far beyond this.
-
Single-indirect range: bytes (4 MB). bytes. Still below 10,000,000.
-
Double-indirect range: . . So the byte is in the double-indirect range.
-
Disk accesses:
- 1: read the double-indirect block.
- 1: read the single-indirect block (indexed by the double-indirect entry).
- 1: read the data block.
- Total: 3 disk accesses (plus the inode itself if not cached — typically 4 with the inode).
The general formula
For a byte at offset :
- Let = direct pointers, = pointers per block, = block size.
- Direct range: .
- Single-indirect range: .
- Double-indirect range: .
- Triple-indirect range: beyond that.
The number of accesses is , where level is 0 (direct), 1 (single indirect), 2 (double), 3 (triple). Add 1 for the inode itself if the question specifies it must be read.
Summary
- The inode stores direct, single-indirect, double-indirect, and triple-indirect block pointers.
- For small files (under ~48 KB), 1 disk access reaches the data.
- For medium files (up to ~4 MB), 2 accesses (single indirect + data).
- For large files (up to ~4 GB), 3 accesses (double indirect + single indirect + data).
- The arithmetic is mechanical: compute the byte range for each tier and count the levels of indirection.