- 2074 Bhadra · 4+6 marks
File allocation and access methods
Short answer
File allocation methods include contiguous (fast sequential/direct access but external fragmentation and file-size knowledge needed), linked (no fragmentation but slow random access), FAT (pointers in memory for faster random access but scaling issues), and indexed (direct access via i-node, no fragmentation, overhead). Access methods are sequential, direct, and indexed sequential; allocation method affects access efficiency.
Discuss various file allocation and access methods. Compare their advantages and disadvantages.
File allocation methods
The file allocation method decides which disk blocks belong to a file. The main methods are:
1. Contiguous allocation - each file occupies a set of consecutive blocks. The directory stores the start block and length.
file A: blocks 0-3 file B: blocks 4-6 free 7-...
[A][A][A][A][B][B][B][ ][ ]
- Advantages: simple; very fast sequential and direct access (only one seek); only start and length are stored.
- Disadvantages: external fragmentation (needs compaction); file size must be known in advance; file growth is difficult.
2. Linked-list allocation - each block contains a pointer to the next block; the directory stores the first block.
[blk 9 |->2] [blk 2 |->14] [blk 14 |->nil]
- Advantages: no external fragmentation; files can grow easily; no need to know size.
- Disadvantages: random access is very slow (must follow the chain); the pointer takes space in each block (so the data size is no longer a power of 2); one lost pointer breaks the file (poor reliability).
3. Linked list with a table in memory (FAT) - the pointers are moved out of the data blocks into a File Allocation Table in memory; entry i gives the block after block i.
- Advantages: full block available for data; random access is faster (chain followed in memory).
- Disadvantages: the whole table must be in memory (a 1 TB disk with 1 KB blocks needs 10⁹ entries), so it does not scale.
4. Indexed allocation (i-node) - each file has an index block (i-node) that lists the addresses of all its blocks (UNIX adds indirect blocks for large files).
i-node: [b1][b2][b3]...[single indirect]-->[b..][b..]
- Advantages: supports direct access, no external fragmentation, only the i-nodes of open files need to be in memory.
- Disadvantages: index block overhead (even for a small file); very large files need multiple levels of indirection.
File access methods
| Method | Description | Advantages | Disadvantages |
|---|---|---|---|
| Sequential access | Records are read/written in order, one after another (read next, write next, rewind). Used with tapes and editors | Simple; efficient for whole-file processing | Slow to reach a particular record |
| Direct (random) access | The file is a numbered sequence of fixed-length blocks/records; any block can be read directly (read n, position to n) | Fast access to any record; good for databases | Needs fixed record structure; more complex |
| Indexed (index sequential) access | An index holds keys and pointers to blocks; first search the index, then access the record | Quick keyed lookup, supports both sequential and direct access | Index takes space and has to be maintained |
The allocation method affects which access is efficient: contiguous allows both sequential and direct access; linked allocation supports sequential access well but direct access poorly; indexed allocation supports direct access.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- File allocation methods; free space management · Operating System, chapter 5 · asked 2×
- File and attributes; allocation methods · Operating System, chapter 5
- File system vs virtual memory; contiguous allocation · Operating System, chapter 5
- Directory, file path, access methods · Operating System, chapter 5
- File system layers; linked list vs index · Operating System, chapter 5
- File system layout; i-node vs linked list · Operating System, chapter 5
- Random access file transaction processing · Object Oriented Programming, chapter 8
- File I/O operations, errors, random access · Computer Programming, chapter 10
- Spread spectrum multiple access; FDMA vs CDMA · Wireless Communication, chapter 7
- Multiple access; FDMA vs CDMA · Wireless Communication, chapter 7