Skip to content
CurriculumLesson 28 · Files
Intermediate~16 min

Linked Allocation & FAT

Linked allocation spreads a file across blocks and stores a next pointer in each block. FAT moves those pointers into a table so the chain can be followed without reading every data block.

In plain English

Linked allocation is a treasure hunt: each block holds a clue to the next. FAT keeps all the clues in one table.

By the end you will be able to

  • Trace a linked file chain.
  • Explain the File Allocation Table.
  • Compute the cost of direct access.
  • Know how free space is represented in FAT.
01

Linked allocation

Each block stores data plus a pointer to the next block. The directory entry stores only the first block. A file can grow by allocating any free block and linking it. There is no external fragmentation, but a random access to block i requires following i links, and each link may cost a disk read if the block is not cached.

lesson-28.osOS
directory: report.txt -> block 5
block 5  data + next 9
block 9  data + next 2
block 2  data + next 14
block 14 data + next EOF
02

The File Allocation Table

FAT removes the next pointer from the data block and stores it in a table indexed by block number. The directory entry still stores the first block. To follow the file, read FAT[5] = 9, FAT[9] = 2, and so on. The FAT is small enough to be cached in memory, so chain traversal is faster than reading each data block just to find the next pointer.

lesson-28.osOS
FAT[5]  = 9
FAT[9]  = 2
FAT[2]  = 14
FAT[14] = EOF
FAT[20] = FREE
03

Access cost

Sequential access is good: follow the chain and read each block once. Direct access to block i is O(i) because the chain must be walked. FAT is a linked-allocation variant, so it inherits this weakness. Indexed allocation solves direct access by storing all block pointers in one place.

Watch it happen

Step through the worked example. Play it, pause it, or move one step at a time.

step-by-step

Step 1 of 6

Directory entry points to block 5

The file starts at block 5. The FAT tells us where the rest of the file lives.

report.txt → block 5
0free
1free
2→14
3free
4free
5→9
6free
7free
8free
9→2
10free
11free
12free
13free
14→20
15free
16free
17free
18free
19free
20EOF
21free
22free
23free

Key takeaways

  • Linked allocation stores a next pointer per block.
  • FAT stores those pointers in a table indexed by block.
  • The directory entry stores the first block.
  • Sequential access is efficient; direct access is O(n).
  • FAT entries also represent free and end-of-file blocks.

Common pitfalls

  • Confusing the FAT with the data blocks.
  • Assuming direct access is O(1).
  • Forgetting to mark the last block as EOF.

Kernel notes

  • Walk a FAT chain and count the blocks.
  • Explain why FAT improves on in-block pointers.
  • Compare sequential and direct access cost.

Quick check

0 / 2 answered

1. In a FAT file system, what does a FAT entry contain?

2. What is the direct-access cost of block i in a FAT chain?