Open In App

File Access Methods in Operating System

Last Updated : 05 May, 2023
Like Article

Prerequisite – File Systems 
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 -write 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. 

Advantages of Sequential Access Method :

  • It is simple to implement this file access mechanism.
  • It uses lexicographic order to quickly access the next entry. 
  • It is suitable for applications that require access to all records in a file, in a specific order.
  • It is less prone to data corruption as the data is written sequentially and not randomly.
  • It is a more efficient method for reading large files, as it only reads the required data and does not waste time reading unnecessary data.
  • It is a reliable method for backup and restore operations, as the data is stored sequentially and can be easily restored if required.

Disadvantages of Sequential Access Method :

  • If the file record that needs to be accessed next is not present next to the current record, this type of file access method is slow.
  • Moving a sizable chunk of the file may be necessary to insert a new record.
  • It does not allow for quick access to specific records in the file. The entire file must be searched sequentially to find a specific record, which can be time-consuming.
  • It is not well-suited for applications that require frequent updates or modifications to the file. Updating or inserting a record in the middle of a large file can be a slow and cumbersome process.
  • Sequential access can also result in wasted storage space if records are of varying lengths. The space between records cannot be used by other records, which can result in inefficient use of storage.

2.Direct Access – 
Another method is direct access method also known as relative access method. A fixed-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. 

Advantages of Direct Access Method :

  • The files can be immediately accessed decreasing the average access time.
  • In the direct access method, in order to access a block, there is no need of traversing all the blocks present before it.

3.Index sequential method – 
It is the other method of accessing a file that 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. 

4.Relative Record Access –

Relative record access is a file access method used in operating systems where records are accessed relative to the current position of the file pointer. In this method, records are located based on their position relative to the current record, rather than by a specific address or key value.

Key Points of Relative Record Access:

Relative record access is a random access method that allows records to be accessed based on their position relative to the current record.

This method is efficient for accessing individual records but may not be suitable for files that require frequent updates or random access to specific records.

Relative record access requires fixed-length records and may not be flexible enough for some applications.

This method is useful for processing records in a specific order or for files that are accessed sequentially.

Advantages of Relative Record Access:

Random Access: Relative record access allows random access to records in a file. The system can access any record at a specific offset from the current position of the file pointer.

Efficient Retrieval: Since the system only needs to read the current record and any records that need to be skipped, relative record access is more efficient than sequential access for accessing individual records.

Useful for Sequential Processing: Relative record access is useful for processing records in a specific order. For example, if the records are sorted in a specific order, the system can access the next or previous record relative to the current position of the file pointer.

Disadvantages of Relative Record Access:

Fixed Record Length: Relative record access requires fixed-length records. If the records are of varying length, it may be necessary to use padding to ensure that each record is the same length.

Limited Flexibility: Relative record access is not very flexible. It is difficult to insert or delete records in the middle of a file without disrupting the relative positions of other records.

Limited Application: Relative record access is best suited for files that are accessed sequentially or with some regularity, but it may not be appropriate for files that are frequently updated or require random access to specific records.

5.Content Addressable Access-

Content-addressable access (CAA) is a file access method used in operating systems that allows records or blocks to be accessed based on their content rather than their address. In this method, a hash function is used to calculate a unique key for each record or block, and the system can access any record or block by specifying its key.

Keys in Content-Addressable Access:

Unique: Each record or block has a unique key that is generated using a hash function.

Calculated based on content: The key is calculated based on the content of the record or block, rather than its location or address.

Advantages of Content-Addressable Access:

Efficient Search: CAA is ideal for searching large databases or file systems because it allows for efficient searching based on the content of the records or blocks.

Flexibility: CAA is more flexible than other access methods because it allows for easy insertion and deletion of records or blocks.

Data Integrity: CAA ensures data integrity because each record or block has a unique key that is generated based on its content.

Disadvantages of Content-Addressable Access:

Overhead: CAA requires additional overhead because the hash function must be calculated for each record or block.

Collision: There is a possibility of collision where two records or blocks can have the same key. This can be minimized by using a good hash function, but it cannot be completely eliminated.

Limited Key Space: The key space is limited by the size of the hash function used, which can lead to collisions and other issues.

Key Points of Content-Addressable Access:

Content-addressable access is a file access method that allows records or blocks to be accessed based on their content rather than their address.

CAA uses a hash function to generate a unique key for each record or block.

CAA is efficient for searching large databases or file systems and is more flexible than other access methods.

CAA requires additional overhead for calculating the hash function and may have collisions or limited key space.

Similar Reads

File System Implementation in Operating System
Prerequisite - File Systems in Operating Systems A file is a collection of related information. The file system resides on secondary storage and provides efficient and convenient access to the disk by allowing data to be stored, located, and retrieved. File system implementation in an operating system refers to how the file system manages the stora
11 min read
Access matrix in Operating System
Access Matrix is a security model of protection state in computer system. It is represented as a matrix. Access matrix is used to define the rights of each process executing in the domain with respect to each object. The rows of matrix represent domains and columns represent objects. Each cell of matrix represents set of access rights which are giv
3 min read
Difference between Local File System (LFS) and Distributed File System (DFS)
1. Local File System (LFS) : The basic file system of Linux operating system is termed as Local file system. It stores any data file as it is in single copy. It stores data files in Tree format. Here, any user can access data files directly. LFS does not Replicate the data blocks. It always used for storing and processing personal data(small data).
3 min read
File Systems in Operating System
A computer file is defined as a medium used for saving and managing data in the computer system. The data stored in the computer system is completely in digital format, although there can be various types of files that help us to store the data. What is a File System?A file system is a method an operating system uses to store, organize, and manage
9 min read
System Protection in Operating System
Introduction: System protection in an operating system refers to the mechanisms implemented by the operating system to ensure the security and integrity of the system. System protection involves various techniques to prevent unauthorized access, misuse, or modification of the operating system and its resources. There are several ways in which an op
3 min read
User View Vs Hardware View Vs System View of Operating System
User View of Operating System: The Operating System is an interface, hides the details which must be performed and present a virtual machine to the user that makes it easier to use. Operating System provides the following services to the user. Execution of a programAccess to I/O devicesControlled access to filesError detection (Hardware failures, a
1 min read
Xv6 Operating System -adding a new system call
Prerequisite - Xv6 Operating System -add a user program In last post we got to know how to add user program in Xv6 Operating System. Now here you will see how to add new system call in Xv6 Operating System. A dding new system call to xv6: A system call is way for programs to interact with operating system. A computer program makes system call when
6 min read
Traps and System Calls in Operating System (OS)
Traps and system calls are two mechanisms used by an operating system (OS) to perform privileged operations and interact with user-level programs. Here is an overview of each mechanism: Traps: A trap is an interrupt generated by the CPU when a user-level program attempts to execute a privileged instruction or encounters an error. When a trap occurs
3 min read
Difference between System Software and Operating System
1. System Software: System software is a type of computer program that is designed to run a computer's hardware and application programs it controls a computer's internal functioning, chiefly through an operating system. It also controls peripherals devices such as monitors, printers, and storage devices. 2. Operating System: An operating system or
3 min read
Fork System Call in Operating System
In many operating systems, the fork system call is an essential operation. The fork system call allows the creation of a new process. When a process calls the fork(), it duplicates itself, resulting in two processes running at the same time. The new process that is created is called a child process. It is a copy of the parent process. The fork syst
5 min read