File-System Implementation

an indirect block

Suppose your phone can only store a dozen contacts directly, but you keep a single card that says where to find a notebook full of more numbers. That card does not hold a phone number itself — it holds a pointer to a place that holds many numbers. An indirect block is exactly that kind of card inside a file's inode: a disk block that does not hold the file's data, but holds pointers to blocks that do.

When a file outgrows the inode's handful of direct pointers, the file system allocates an extra block and fills it entirely with block addresses, then stores the address of that block in the inode's single-indirect pointer. With 4 KB blocks and 4-byte pointers, one indirect block holds 1024 data-block addresses — about 4 MB of file. For larger files, a double-indirect block holds pointers to single-indirect blocks (a block of pointers to blocks of pointers to data), and a triple-indirect block adds yet another level. Each level you descend is one more disk read before you reach the data, because you must first fetch the pointer block, then maybe the next one, then finally the data block.

Indirect blocks are the gearing that lets a tiny fixed inode describe a vast file: you spend a little extra storage and a few extra reads only for the parts of the file that need them. The honest cost is real but usually well hidden: the operating system caches recently used indirect blocks in memory, so sequential reads through a big file fetch each indirect block once and then stream many data blocks behind it. The main misconception to avoid is thinking an indirect block contains file content — it contains addresses, the map, not the territory.

A 5 MB file with 4 KB blocks needs about 1280 data blocks. The first 12 are reached by the inode's direct pointers; the remaining ~1268 are listed inside one single-indirect block (capacity 1024) plus a few entries spilling into a double-indirect block. Reading block 500 means: read the single-indirect block, take entry 500-12 = 488, then read that data block.

An indirect block is a block full of addresses, not data — the map to where the file really sits.

An indirect block stores pointers, never file content. Each extra level of indirection adds one more disk read to reach the data — which is why direct pointers handle the small files that dominate real workloads.

Also called
pointer blocksingle/double/triple indirect block指標區塊