File Storage
Contiguous Allocation
File data is stored on disk. Like programs in memory, it can occupy contiguous or noncontiguous space. Storage methods differ in efficiency and read/write performance.
Contiguous storage places file data in consecutive physical disk locations. Data is tightly packed, making sequential reading efficient by reducing disk seeks.
Contiguous storage requires knowing the file size in advance so the file system can allocate a sufficiently large consecutive region. The file header therefore records the starting block and length, which describe the file's contiguous disk space.
Although efficient to read and write, contiguous storage suffers from fragmentation and difficulty extending a file. For example, files A, B and C occupy these disk blocks:
If B is deleted, the largest contiguous free region contains six blocks. A new file needing at most six blocks can be stored, but a larger file cannot be stored contiguously on this disk.
Fit a file into a continuous gap
Unlock the complete interactive lab, deeper explanations, and curated reference answers.
Linked Allocation
Linked storage uses scattered blocks, eliminating external fragmentation and improving space utilization while allowing files to grow dynamically. It can be implemented with implicit or explicit links.
Implicit links use a file header containing the first and last block locations. Each data block reserves space for a pointer to the next block, so all blocks can be found by following pointers from the head, without requiring contiguous storage.
Implicit linked storage cannot directly access a data block: pointers must be followed sequentially, and they consume storage space. It is vulnerable to pointer loss or corruption caused by software or hardware errors, which can make file data inaccessible.
Moving pointers out of data blocks into an in-memory table reduces pointer overhead inside data blocks and avoids reading each data block merely to follow its pointer. Explicit links store the next-block pointers in one table for the disk. This table is called the File Allocation Table (FAT).
| Block / FAT entry | Next block |
|---|---|
| 0 | — |
| 1 | — |
| 2 | — |
| 3 | 11 |
| 4 | 7 |
| 5 | — |
| 6 | 3 |
| 7 | 10 |
| 8 | — |
| 9 | — |
| 10 | 12 |
| 11 | -1 |
| 12 | -1 |
| 13 | — |
Follow a file across scattered blocks
Unlock the complete interactive lab, deeper explanations, and curated reference answers.
Indexed Allocation
Linked storage addresses external fragmentation and dynamic growth but does not efficiently support direct access. Indexed storage solves this by creating an index block for each file, containing a list of pointers to data blocks, like a book's contents page. The file header points to the index block, whose entries locate the data blocks.
Index block 1
Indexed storage has these advantages:
- Files are easy to create, grow and shrink
- It avoids external fragmentation
- It supports sequential and random reading and writing
If a file is too large for one index block to hold its index entries, linked and indexed storage can be combined into chained index blocks. Each index block reserves a pointer to the next index block; once its entries are exhausted, that pointer locates the next index block's information.
Index block 1
Index block 8
Jump from a file offset to its indexed block
Unlock the complete interactive lab, deeper explanations, and curated reference answers.
KNOWLEDGE QUIZ
KNOWLEDGE QUIZ
Contiguous, linked or indexed: locate the file
Disk blocks 0–15 are shown below. Delete B and allocate an 8-block D with contiguous first fit. State the free regions, total free space, largest region and D's header. Could a 9-block D fit?
Each block is 512 bytes. Locate file byte offset 1570 in D. Separately, a four-block file is stored as 3 → 11 → 6 → 14 → END, or as index [3, 11, 6, 14]. Locate the same offset and compare disk reads for implicit links, a cold single index block and a cached FAT. File headers are already known; count the target data read.