FIle Access & Allocation Methods | Operating System - Computer Science Engineering (CSE) PDF Download

File Allocation Methods

The allocation methods define how the files are stored in the disk blocks.
There are three main disk space or file allocation methods:

  • Contiguous Allocation
  • Linked Allocation
  • Indexed Allocation

The main idea behind these methods is to provide:

  • Efficient disk space utilization.
  • Fast access to the file blocks.

All the three methods have their own advantages and disadvantages as discussed below:

1. Contiguous Allocation
In this scheme, each file occupies a contiguous set of blocks on the disk. For example, if a file requires n blocks and is given a block b as the starting location, then the blocks assigned to the file will be: b, b+1, b+2,……b+n-1. This means that given the starting block address and the length of the file (in terms of blocks required), we can determine the blocks occupied by the file.
The directory entry for a file with contiguous allocation contains:

  • Address of starting block
  • Length of the allocated portion.

The file ‘mail’ in the following figure starts from the block 19 with length = 6 blocks. Therefore, it occupies 19, 20, 21, 22, 23, 24 blocks.
FIle Access & Allocation Methods | Operating System - Computer Science Engineering (CSE)


Advantages:

  • Both the Sequential and Direct Accesses are supported by this. For direct access, the address of the kth block of the file which starts at block b can easily be obtained as (b+k).
  • This is extremely fast since the number of seeks are minimal because of contiguous allocation of file blocks.

Disadvantages:

  • This method suffers from both internal and external fragmentation. This makes it inefficient in terms of memory utilization.
  • Increasing file size is difficult because it depends on the availability of contiguous memory at a particular instance.

2. Linked List Allocation
In this scheme, each file is a linked list of disk blocks which need not be contiguous. The disk blocks can be scattered anywhere on the disk.
The directory entry contains a pointer to the starting and the ending file block. Each block contains a pointer to the next block occupied by the file.
The file ‘jeep’ in following image shows how the blocks are randomly distributed. The last block (25) contains -1 indicating a null pointer and does not point to any other block.
FIle Access & Allocation Methods | Operating System - Computer Science Engineering (CSE)


Advantages:

  • This is very flexible in terms of file size. File size can be increased easily since the system does not have to look for a contiguous chunk of memory.
  • This method does not suffer from external fragmentation. This makes it relatively better in terms of memory utilization.

Disadvantages:

  • Because the file blocks are distributed randomly on the disk, a large number of seeks are needed to access every block individually. This makes linked allocation slower.
  • It does not support random or direct access. We can not directly access the blocks of a file. A block k of a file can be accessed by traversing k blocks sequentially (sequential access ) from the starting block of the file via block pointers.
  • Pointers required in the linked allocation incur some extra overhead.

3. Indexed Allocation
In this scheme, a special block known as the Index block contains the pointers to all the blocks occupied by a file. Each file has its own index block. The ith entry in the index block contains the disk address of the ith file block. The directory entry contains the address of the index block as shown in the image:
FIle Access & Allocation Methods | Operating System - Computer Science Engineering (CSE)


Advantages:

  • This supports direct access to the blocks occupied by the file and therefore provides fast access to the file blocks.
  • It overcomes the problem of external fragmentation.

Disadvantages:

  • The pointer overhead for indexed allocation is greater than linked allocation.
  • For very small files, say files that expand only 2-3 blocks, the indexed allocation would keep one entire block (index block) for the pointers which is inefficient in terms of memory utilization. However, in linked allocation we lose the space of only 1 pointer per block.

For files that are very large, single index block may not be able to hold all the pointers.

Following mechanisms can be used to resolve this:

  1. Linked scheme: This scheme links two or more index blocks together for holding the pointers. Every index block would then contain a pointer or the address to the next index block.
  2. Multilevel index: In this policy, a first level index block is used to point to the second level index blocks which inturn points to the disk blocks occupied by the file. This can be extended to 3 or more levels depending on the maximum file size.
  3. Combined Scheme: In this scheme, a special block called the Inode (information Node) contains all the information about the file such as the name, size, authority, etc and the remaining space of Inode is used to store the Disk Block addresses which contain the actual file as shown in the image below. The first few of these pointers in Inode point to the direct blocks i.e the pointers contain the addresses of the disk blocks that contain data of the file. The next few pointers point to indirect blocks. Indirect blocks may be single indirect, double indirect or triple indirect. Single Indirect block is the disk block that does not contain the file data but the disk address of the blocks that contain the file data. Similarly, double indirect blocks do not contain the file data but the disk address of the blocks that contain the address of the blocks containing the file data.
    FIle Access & Allocation Methods | Operating System - Computer Science Engineering (CSE) 

File Access Methods in Operating System

When a file is used, information is read and accessed into computer memory and there are several ways to access this information of the file. Some systems provide only one access method for files. Other systems, such as those of IBM, support many access methods, and choosing the right one for a particular application is a major design problem.
There are three ways to access a file into a computer system: Sequential-Access, Direct Access, Index sequential Method. 

  1. Sequential Access
    It is the simplest access method. Information in the file is processed in order, one record after the other. This mode of access is by far the most common; for example, editor and compiler usually access the file in this fashion.
    Read and write make up the bulk of the operation on a file. A read operation -read next- read the next position of the file and automatically advance a file pointer, which keeps track I/O location. Similarly, for the writewrite next append to the end of the file and advance to the newly written material.
    Key points:
    • Data is accessed one record right after another record in an order.
    • When we use read command, it move ahead pointer by one
    • When we use write command, it will allocate memory and move the pointer to the end of the file
    • Such a method is reasonable for tape. 
  2. Direct Access
    Another method is direct access method also known as relative access method. A filed-length logical record that allows the program to read and write record rapidly. in no particular order. The direct access is based on the disk model of a file since disk allows random access to any file block. For direct access, the file is viewed as a numbered sequence of block or record. Thus, we may read block 14 then block 59 and then we can write block 17. There is no restriction on the order of reading and writing for a direct access file.
    A block number provided by the user to the operating system is normally a relative block number, the first relative block of the file is 0 and then 1 and so on.
  3. Index sequential method
    It is the other method of accessing a file which is built on the top of the sequential access method. These methods construct an index for the file. The index, like an index in the back of a book, contains the pointer to the various blocks. To find a record in the file, we first search the index and then by the help of pointer we access the file directly.
    Key points:
    • It is built on top of Sequential access.
    • It control the pointer by using index.
The document FIle Access & Allocation Methods | Operating System - Computer Science Engineering (CSE) is a part of the Computer Science Engineering (CSE) Course Operating System.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)
10 videos|99 docs|33 tests

Top Courses for Computer Science Engineering (CSE)

FAQs on FIle Access & Allocation Methods - Operating System - Computer Science Engineering (CSE)

1. What is file allocation in computer science engineering?
Ans. File allocation refers to the method of organizing and assigning storage space for files on a computer system. It involves determining how and where the files will be stored on the storage media.
2. What are the commonly used file allocation methods?
Ans. The commonly used file allocation methods are: 1. Contiguous Allocation: In this method, files are stored in consecutive blocks of memory. It provides fast access but suffers from fragmentation. 2. Linked Allocation: Each file is divided into blocks, and each block contains a pointer to the next block. It avoids fragmentation but can lead to slower access due to the need to follow pointers. 3. Indexed Allocation: A separate index block is created for each file, which contains pointers to the actual data blocks. It allows direct access to blocks but requires additional space for the index. 4. Multi-level Indexing: It is an extension of indexed allocation where multiple levels of index blocks are used to handle large files efficiently. 5. File Allocation Table (FAT): It uses a table to store information about the allocation of each block in a file. It is commonly used in FAT file systems.
3. What is fragmentation in file allocation?
Ans. Fragmentation refers to the phenomenon where free space in a storage medium becomes divided into small non-contiguous blocks over time. It can occur in both disk-based and memory-based file allocation methods. Fragmentation can be of two types: 1. External Fragmentation: It occurs when free space is scattered throughout the storage medium, making it difficult to allocate contiguous blocks of memory for large files. 2. Internal Fragmentation: It occurs when the allocated space for a file is larger than the actual size of the file. This wasted space within a block or cluster is not utilized efficiently.
4. What are the advantages and disadvantages of contiguous allocation?
Ans. The advantages of contiguous allocation are: - Fast access to files as they are stored in consecutive blocks. - Simple and efficient implementation. - Minimum overhead in terms of storage space. The disadvantages of contiguous allocation are: - External fragmentation can occur when files are deleted or modified, leading to inefficient space utilization. - It is not suitable for dynamic storage allocation as it requires contiguous free space. - It may not be able to handle files larger than the available contiguous space.
5. How does indexed allocation overcome the limitations of other methods?
Ans. Indexed allocation overcomes the limitations of other methods in the following ways: - It allows direct access to blocks of a file by using a separate index block, reducing the need to follow pointers like in linked allocation. - It avoids external fragmentation by using an index that points to the actual data blocks, rather than storing the data blocks themselves. - It can efficiently handle large files by using multi-level indexing, where multiple levels of index blocks are used to access data blocks. - It provides better performance compared to contiguous allocation for dynamic storage allocation, as it does not require contiguous free space.
10 videos|99 docs|33 tests
Download as PDF
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Objective type Questions

,

ppt

,

Free

,

Extra Questions

,

mock tests for examination

,

FIle Access & Allocation Methods | Operating System - Computer Science Engineering (CSE)

,

Important questions

,

pdf

,

Viva Questions

,

video lectures

,

Sample Paper

,

Exam

,

shortcuts and tricks

,

FIle Access & Allocation Methods | Operating System - Computer Science Engineering (CSE)

,

practice quizzes

,

FIle Access & Allocation Methods | Operating System - Computer Science Engineering (CSE)

,

Summary

,

Previous Year Questions with Solutions

,

study material

,

Semester Notes

,

MCQs

,

past year papers

;