/    /  OS – File access methods in Operating System

File access methods in Operating System

 

There are mainly three ways to access a file: Direct access, Indexed access, and Sequential access.

 

 

  • Direct access

 

Direct access or relative access method is mostly used in database systems. It is based on the disk model of a file since the disk allows access to any file block. 

In this method the files are viewed as a sequence of blocks, one can read block 1 and then write on block 20, there are no restrictions on the order in which the blocks are read or written on.

Let us assume that the storage stores 5 records and the record we need are stored in the 10th block. In this case, if we use sequential access, it will have to go through all of the blocks in order. Therefore, direct access is used in this situation. 

 

 

  • Indexed access

 

In the indexed access method, an index is created for the file. To access a file, we search for its index first, and then with the help of the pointer, we can access the file directly. 

This method is an extension of the sequential access method. 

 

 

  • Sequential  access

 

In the sequential access method, the data is accessed one after the other in a fixed order. When the user uses the ‘read’ command, the pointer moves ahead by one, and when the ‘write’ command is used, the pointer is allocated to the end of the file. 

Most of the files need to be accessed sequentially by the operating system, which means the operating system will read the file word by word. A pointer points to the base address of the file, so if the reader needs to read the first word of the file, then the pointer will point to that word and increase the value by 1 word. The process is repeated till the end of the file. 

Reference

File access methods in Operating System