Skip to main content

10.3 File Allocation Methods: Contiguous, Linked & Indexed Allocation

📚Module 10: File Systems & InodesTopic 10.3⏱️22 min read
🎯High-Yield For:Computer Science Foundations • Systems Engineering • Storage Performance

💡 Core Intuition​

🍳 The Everyday Analogy: The City Warehouse Storage Strategies​

Imagine managing a massive municipal warehouse where cargo shipments of varying sizes arrive daily:

Architecture Flow

The Warehouse Allocation Paradigms

Contrasting physical storage strategies with operating system disk allocation

📦Contiguous

Reserved Adjacent Aisles

Contiguous Allocation

Shipment A occupies consecutive bays 10 through 14. A forklift can zip down the aisle in one continuous straight line, but if bay 15 is occupied, shipment A cannot expand.

→
Decouple Placement
🔗Linked List

Scattered Bays with Clue Slips

Linked Allocation

Crates are placed in any empty bay. Inside crate 1 is a note with the address of crate 2. No empty space is wasted, but finding crate 10 requires visiting crates 1 through 9.

→
Centralize Pointers
📑Indexed

Master Control Ledger

Indexed Allocation

A single master clipboard at the manager's desk lists the exact bay coordinates of every crate in the shipment. Any crate can be located immediately with zero searching.

In an operating system, the file allocation problem fundamentally addresses two competing engineering goals:

  1. Effective Disk Space Utilization: Minimizing fragmentation and eliminating wasted storage capacity.
  2. Fast File Access Performance: Minimizing mechanical disk seek times and rotational delays when performing both sequential and random file I/O operations.

The three primary file allocation methods employed across operating systems are:

  • Contiguous Allocation
  • Linked Allocation (including the File Allocation Table / FAT optimization)
  • Indexed Allocation (including multi-level and hybrid indexing)

🏛️ Method 1: Contiguous Allocation​

Structural Architecture​

Under contiguous allocation, each file is required to occupy a set of linearly consecutive disk blocks. Because disk block addresses define a linear ordering on the storage media, accessing block b+1b + 1 immediately after block bb requires zero actuator head seek movement (assuming the blocks reside on the same cylinder/track).

File NameStarting Block (bb)Length (LL)Physical Disk Blocks Allocated
count02Blocks 0, 1
f62Blocks 6, 7
tr143Blocks 14, 15, 16
mail196Blocks 19, 20, 21, 22, 23, 24
list284Blocks 28, 29, 30, 31

The directory entry for a contiguously allocated file is exceptionally compact, requiring only two fields:

  • Starting Block Address (bb)
  • Length (LL) (number of consecutive blocks allocated)

Access Mechanics & Formulas​


Advantages and Engineering Drawbacks​


⏱️ Mathematical Case Study: Contiguous vs. Non-Contiguous Read Latency​

Consider a disk subsystem with the following parameters:

  • Geometry: 8 sectors per track, 512 bytes per sector
  • Rotational Speed: 3000 RPM3000\text{ RPM}
  • Average Seek Time (ST\text{ST}): 15 ms15\text{ ms}
  • Workload: Read an entire file consisting of 8 sectors.

1. Fundamental Timing Derivations:​

  • Time for one full rotation (TrotT_{\text{rot}}): 3000 RPM=300060 rev/s=50 rev/s3000\text{ RPM} = \frac{3000}{60}\text{ rev/s} = 50\text{ rev/s} Trot=150 s=0.02 s=20 msT_{\text{rot}} = \frac{1}{50}\text{ s} = 0.02\text{ s} = 20\text{ ms}
  • Average Rotational Latency (RL\text{RL}): RL=Trot2=20 ms2=10 ms\text{RL} = \frac{T_{\text{rot}}}{2} = \frac{20\text{ ms}}{2} = 10\text{ ms}
  • Track Transfer Time (TT\text{TT}): TT=Sectors to ReadSectors per Track×Trot=88×20 ms=20 ms\text{TT} = \frac{\text{Sectors to Read}}{\text{Sectors per Track}} \times T_{\text{rot}} = \frac{8}{8} \times 20\text{ ms} = 20\text{ ms}

2. Case I: Contiguous Allocation​

All 8 sectors are stored sequentially on the same track. The disk head seeks to the target cylinder once, waits for the initial sector to arrive underneath the head, and then streams all 8 sectors in one continuous revolution:

Total Transfer Time (TTT)=ST+RL+TT\text{Total Transfer Time (TTT)} = \text{ST} + \text{RL} + \text{TT}

TTT=15 ms+10 ms+20 ms=45 ms\text{TTT} = 15\text{ ms} + 10\text{ ms} + 20\text{ ms} = 45\text{ ms}


3. Case II: Non-Contiguous Allocation (Scattered Blocks)​

The 8 sectors are scattered randomly across different tracks across the disk platters. For every individual sector, the actuator arm must perform a separate seek and rotational wait:

TTTnon-contiguous=8×[ST+RL]+TT\text{TTT}_{\text{non-contiguous}} = 8 \times \big[\text{ST} + \text{RL}\big] + \text{TT}

TTTnon-contiguous=8×[15 ms+10 ms]+20 ms\text{TTT}_{\text{non-contiguous}} = 8 \times \big[15\text{ ms} + 10\text{ ms}\big] + 20\text{ ms}

TTTnon-contiguous=8×25 ms+20 ms=200 ms+20 ms=220 ms\text{TTT}_{\text{non-contiguous}} = 8 \times 25\text{ ms} + 20\text{ ms} = 200\text{ ms} + 20\text{ ms} = 220\text{ ms}

Mechanical Penalty of Non-Contiguous Allocation

Non-contiguous allocation takes 220 ms220\text{ ms} versus 45 ms45\text{ ms} for contiguous allocation—nearly a 5×5\times performance penalty purely due to mechanical seek and rotational overhead!


🌀 Sector Interleaving​

In early disk systems, disk controllers required a brief processing delay after reading a sector into the controller's internal SRAM buffer before it could accept the next sector. If sectors were numbered sequentially (0,1,2,3…0, 1, 2, 3\dots), by the time the controller finished processing sector 00, sector 11 had already rotated past the read head, forcing the head to wait an entire revolution (20 ms20\text{ ms}) to read sector 11!

To solve this, hardware engineers introduced Sector Interleaving:

  • Single Interleaving: Requires 2 complete rotations to read all sectors of 1 track. Transfer Time=2×Trot\text{Transfer Time} = 2 \times T_{\text{rot}}.
  • Double Interleaving: Requires 2.75 to 3 rotations to read 1 track. Transfer Time≈2.75×Trot\text{Transfer Time} \approx 2.75 \times T_{\text{rot}}.

🔗 Method 2: Linked Allocation​

Structural Architecture​

Linked allocation eliminates external fragmentation entirely. Each file is represented as a linked list of disk blocks. Disk blocks may be scattered arbitrarily across the entire storage volume.

File NameStart BlockEnd Block
jeep925
Architecture Flow

Linked File Block Pointer Chain

Dynamic allocation chain for file 'jeep' (Start: Block 9, End: Block 25)

📦Block 9

Initial Block (Head)

Start Block = 9

Stores first 508 bytes of file data; tail pointer addresses Block 16.

→
Next Block
📦Block 16

Second Block

Logical Block 1

Stores next payload bytes; tail pointer addresses Block 1.

→
Next Block
📦Block 1

Third Block

Logical Block 2

Stores next payload bytes; tail pointer addresses Block 10.

→
Next Block
📦Block 10

Fourth Block

Logical Block 3

Stores next payload bytes; tail pointer addresses Block 25.

→
Next Block
🏁Block 25

Terminal Block (Tail)

End Block = 25

Stores final payload bytes; tail pointer stores -1 (EOF / Nil).

The directory entry stores only two block pointers:

  • Start Block
  • End Block

Each physical disk block dedicates a small portion of its internal storage (e.g., 4 or 8 bytes) to store a pointer to the next allocated block.


Usable Data Capacity per Block​

If disk block size is BB bytes and a disk block pointer requires PP bytes:

Usable Payload per Block=B−P\text{Usable Payload per Block} = B - P

For example, with B=512 bytesB = 512\text{ bytes} and P=4 bytesP = 4\text{ bytes}:

  • Data payload =512−4=508 bytes= 512 - 4 = 508\text{ bytes}.
  • Pointer space overhead =4512≈0.78%= \frac{4}{512} \approx 0.78\%.

Advantages and Engineering Vulnerabilities​


💾 The File Allocation Table (FAT) Solution​

To solve the slow random access and reliability hazards of linked allocation without reintroducing external fragmentation, MS-DOS and early Windows designed the File Allocation Table (FAT):

Disk Block NumberValue (Next Block Entry)Status / Meaning
00 (Free)Unallocated disk block
.........
916Start block of jeep →\to points to Block 16
1025Part of jeep chain →\to points to Block 25
161Part of jeep chain →\to points to Block 1
110Part of jeep chain →\to points to Block 10
25-1 (0xFFFF)End-of-File (EOF) marker for jeep

FAT Acceleration Architecture

Decoupling pointer navigation from physical disk head travel

1
→
1. Table Placement

The FAT table is stored at the beginning of the volume and cached entirely in RAM during system boot.

2
→
2. Pointer Chasing in RAM

To find logical block k, the kernel chases pointers inside the RAM-cached FAT table at nanosecond CPU speeds.

3
→
3. Direct Disk Seek

Once the physical target block address is discovered in RAM, the disk head seeks directly to that exact target block.


📑 Method 3: Indexed Allocation​

Structural Architecture​

Indexed allocation completely resolves the limitations of both contiguous allocation (fragmentation, expansion limits) and linked allocation (slow random access, pointer corruption).

Instead of scattering pointers across individual data blocks, indexed allocation brings all block pointers together into a single dedicated block: the Index Block.

File NameIndex Block Address
jeepBlock 19
Index Block EntryTarget Physical Disk BlockFile Logical Block Mapping
Entry 0Block 9Logical Block 0 (Bytes 0 – 511)
Entry 1Block 16Logical Block 1 (Bytes 512 – 1023)
Entry 2Block 1Logical Block 2 (Bytes 1024 – 1535)
Entry 3Block 10Logical Block 3 (Bytes 1536 – 2047)
Entry 4Block 25Logical Block 4 (Bytes 2048 – 2559)
Entry 5 .. N-1 (Nil)Unallocated pointer slots
  • Each file has its own private Index Block.
  • The ii-th entry in the index block points to the ii-th physical data block of the file.
  • The directory entry contains only one pointer: the physical address of the file's index block.

Operational Characteristics​


Scaling to Very Large Files​

If a disk block is 4 KB4\text{ KB} and a block address is 4 bytes4\text{ bytes}, one index block holds:

Pointers per Block=40964=1024 pointers\text{Pointers per Block} = \frac{4096}{4} = 1024\text{ pointers}

Maximum File Size=1024×4 KB=4 MB\text{Maximum File Size} = 1024 \times 4\text{ KB} = 4\text{ MB}

A 4 MB4\text{ MB} file size ceiling is unacceptably small for modern workloads. Operating systems resolve this limitation through three indexing architectures:

Large File Indexing Architectures

Strategies to scale index block capacity beyond a single physical block

Linked Indexing Scheme

↓

Multilevel Indexing Scheme

↓

Combined Scheme (UNIX Inode)


📊 Comprehensive Allocation Methods Comparison Matrix​

Architectural FeatureContiguous AllocationLinked AllocationFAT (Linked in RAM)Indexed Allocation
Directory Entry[Start Block, Length][Start, End][Start Block][Index Block]
Sequential Access SpeedFastest (Zero seek between adjacent blocks)Slow (Seeks between scattered blocks)Moderate (Head seeks between blocks)Moderate (Index lookup + seek)
Direct / Random AccessInstant (b+kb + k)Impossible (O(k)O(k) seeks)Fast (RAM pointer chase + 1 seek)Fast (1 index read + 1 seek)
External FragmentationSevereZeroZeroZero
Internal FragmentationOnly in the final allocated blockOnly in the final allocated blockOnly in the final allocated blockFinal block + Index block waste
File Expansion EaseDifficult (Requires relocation)Trivial (Append to tail)Trivial (Link new FAT entry)Trivial (Add pointer to index block)
Metadata Space OverheadLowest (2 integers)PP bytes per block (Payload misaligned)Table size ∝\propto total disk capacity1 entire block per file
Reliability / Fault ToleranceHighLow (Broken link corrupts file)High (FAT duplicated on disk)High (Pointers centralized)

🧮 Numerical & Conceptual Exam Problems​

Problem 1: Linked Allocation Pointer Capacity Calculation​

Question:
A storage system has a disk block size of 1 KB1\text{ KB} (1024 bytes1024\text{ bytes}). It employs linked allocation where each block devotes 4 bytes4\text{ bytes} for the next-block pointer.

  1. What is the usable payload of each disk block?
  2. If a file has an exact size of 35 KB35\text{ KB} (35×1024=35,840 bytes35 \times 1024 = 35,840\text{ bytes}), how many total disk blocks must be allocated to store this file?
  3. How many bytes of internal fragmentation occur in the final block?

Step-by-Step Solution:​

  1. Usable Payload per Block: Payload=1024 bytes−4 bytes=1020 bytes\text{Payload} = 1024\text{ bytes} - 4\text{ bytes} = 1020\text{ bytes}

  2. Total Blocks Required: Blocks=⌈File SizePayload per Block⌉=⌈358401020⌉=⌈35.137⌉=36 blocks\text{Blocks} = \left\lceil \frac{\text{File Size}}{\text{Payload per Block}} \right\rceil = \left\lceil \frac{35840}{1020} \right\rceil = \left\lceil 35.137 \right\rceil = 36\text{ blocks}

  3. Internal Fragmentation in Block 36:

    • The first 35 blocks store: 35×1020=35,700 bytes35 \times 1020 = 35,700\text{ bytes}.
    • Remaining bytes to store in the 36th block: Remaining Bytes=35,840−35,700=140 bytes\text{Remaining Bytes} = 35,840 - 35,700 = 140\text{ bytes}
    • Internal fragmentation in the 36th block: Internal Fragmentation=1020−140=880 bytes\text{Internal Fragmentation} = 1020 - 140 = 880\text{ bytes}

Problem 2: Two-Level Indexed Allocation Maximum File Size​

Question:
A file system uses a two-level indexed allocation scheme. The disk block size is 2 KB2\text{ KB} (2048 bytes2048\text{ bytes}) and disk block addresses are 32 bits32\text{ bits} (4 bytes4\text{ bytes}) long.
The directory entry points to a Master Index Block. Each entry in the Master Index Block points to a Second-Level Index Block, and each entry in the Second-Level Index Block points to a Data Block.
Calculate:

  1. The number of pointers per index block.
  2. The maximum possible file size supported by this two-level scheme.
  3. How many disk block reads are required to read the first byte of data from logical block 500 (assuming cold cache)?

Step-by-Step Solution:​

  1. Number of Pointers per Block (EE): E=Block SizePointer Size=2048 bytes4 bytes=512 pointers=29E = \frac{\text{Block Size}}{\text{Pointer Size}} = \frac{2048\text{ bytes}}{4\text{ bytes}} = 512\text{ pointers} = 2^9

  2. Maximum File Size:

    • The Master Index Block holds 512 pointers to second-level index blocks.
    • Each second-level index block holds 512 pointers to data blocks.
    • Total addressable data blocks: Total Data Blocks=E×E=512×512=262,144 blocks=218 blocks\text{Total Data Blocks} = E \times E = 512 \times 512 = 262,144\text{ blocks} = 2^{18}\text{ blocks}
    • Maximum File Size: Max File Size=218×2 KB=218×211 bytes=229 bytes=512 MB\text{Max File Size} = 2^{18} \times 2\text{ KB} = 2^{18} \times 2^{11}\text{ bytes} = 2^{29}\text{ bytes} = 512\text{ MB}
  3. Disk I/O Operations for Cold Read: To access any byte in data block 500:

    • Read 1: Read the Master Index Block from disk into RAM.
    • Read 2: Read the appropriate Second-Level Index Block (⌊500/512⌋=Entry 0\lfloor 500 / 512 \rfloor = \text{Entry 0}) from disk.
    • Read 3: Read the physical data block (500(mod512)=Entry 500500 \pmod{512} = \text{Entry 500}) from disk.

Total Disk Reads=3 Disk I/Os\text{Total Disk Reads} = 3\text{ Disk I/Os}


🏁 Summary & Mental Model​


💬

Discussion & Doubts