From the user’s point of view, a file is an abstract data type. It can be created, opened, written, read, closed and deleted without any real concern for its implementation. The implementation of a file is a problem for the operating system.
The main problem is how to allocate space to these files so that disk space is effectively utilized and files can be quickly accessed. Three major methods of allocating disk space are in wide use:
Contiguous
Linked
Indexed
Contiguous Allocation
• The contiguous allocation method requires each file to occupy a set of contiguous addresses on the disk. Disk addresses define a linear ordering on the disk. Contiguous allocation of a file is defined by the disk address of the first block and its length. If the file is ‘n’ blocks long and starts at location ‘b’, then it occupies blocks b, b+1, b+2, - - - - - b+n-1. The directory entry for each file indicates the address of the starting block and the length of the area allocated for this file.
• Contiguous allocation supports both sequential and direct access.
• For direct access to block ‘i’ of a file, which starts at block ‘b’, we can immediately access block b+i. The difficulty with contiguous allocation is finding space for a new file.
• For direct access to block ‘i’ of a file, which starts at block ‘b’, we can immediately access block b+i.
• The difficulty with contiguous allocation is finding space for a new file.
• If file to be created are ‘n’ blocks long, we must search free space list for ‘n’ free contiguous blocks.
Advantages of Contiguous File Allocation Method:
1. Supports both sequential and direct access methods.
2. Contiguous allocation is the best form of allocation for sequential files. Multiple blocks can be brought in at a time to improve I/O performance for sequential processing.
3. It is also easy to retrieve a single block from a file. For example, if a file starts at block ‘n’ and the ith block of the file is wanted, its location on secondary storage is simply n + i.
4. Reading all blocks belonging to each file is very fast.
5. Provides good performance.
Disadvantages of Contiguous File Allocation Method:
1. Suffers from external fragmentation.
2. Very difficult to find contiguous blocks of space for new files.
3. Also with pre-allocation, it is necessary to declare the size of the file at the time of creation which many a times is difficult to estimate.
4. Compaction may be required and it can be very expensive.