There are three main space allocation methods for storing files on disks: contiguous allocation, linked allocation, and indexed allocation. Each of these methods has its own advantages and disadvantages, and they each support different types of file access.
- Contiguous Allocation: In this method, each file occupies a contiguous address space on disk. This means that the blocks of a file are stored in a continuous sequence on the disk. This method supports both sequential and direct access. Sequential access is fast because the blocks are stored one after the other. Direct access is also fast because the disk head can quickly move to the desired block using the file's starting address and block size. However, contiguous allocation can lead to issues such as external fragmentation and inefficient disk space utilization.
- Linked Allocation: In this method, each file is a linked list of disk blocks. The blocks may be scattered anywhere on the disk. Each block contains a pointer to the next block in the file. This method supports sequential access but not direct access. Sequential access is straightforward because the blocks are linked together, but direct access is slow because the disk head has to follow the pointers to locate the desired block. Linked allocation is useful for storing large files that are accessed sequentially, such as video files.
- Indexed Allocation: In this method, each file has an index block that contains pointers to the file's disk blocks. The index block is a small block that is stored separately from the file's data blocks. This method supports both sequential and direct access. Direct access is fast because the disk head can quickly move to the desired block using the index block. However, indexed allocation can be inefficient for small files because the overhead of maintaining an index block may be larger than the file itself.
In addition to these three methods, there is a hybrid method called extent-based allocation. In this method, files are divided into large chunks called extents. Each extent is a contiguous sequence of blocks. The file system maintains a table that maps each extent to its physical location on the disk. This method supports both sequential and direct access. It is useful for large files that are accessed randomly because it minimizes the number of disk head movements required to access the file's blocks.
In summary, the choice of space allocation method depends on the type of file access required. Contiguous allocation is best for small files that are accessed randomly, linked allocation is best for large files that are accessed sequentially, and indexed allocation is best for small to medium-sized files that are accessed randomly. Extent-based allocation is a hybrid method that is useful for large files that are accessed randomly.