Open In App

Directory Implementation in Operating System

Last Updated : 07 Jan, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Directory implementation in the operating system can be done using Singly Linked List and Hash table. The efficiency, reliability, and performance of a file system are greatly affected by the selection of directory-allocation and directory-management algorithms. There are numerous ways in which the directories can be implemented. But we need to choose an appropriate directory implementation algorithm that enhances the performance of the system. 

Directory Implementation using Singly Linked List

The implementation of directories using a singly linked list is easy to program but is time-consuming to execute. Here we implement a directory by using a linear list of filenames with pointers to the data blocks.

Directory Implementation Using Singly Linked List

Directory Implementation Using Singly Linked List

  • To create a new file the entire list has to be checked such that the new directory does not exist previously.
  • The new directory then can be added to the end of the list or at the beginning of the list.
  • In order to delete a file, we first search the directory with the name of the file to be deleted. After searching we can delete that file by releasing the space allocated to it.
  • To reuse the directory entry we can mark that entry as unused or we can append it to the list of free directories.
  • To delete a file linked list is the best choice as it takes less time.

Disadvantage

The main disadvantage of using a linked list is that when the user needs to find a file the user has to do a linear search. In today’s world directory information is used quite frequently and linked list implementation results in slow access to a file. So the operating system maintains a cache to store the most recently used directory information.

Directory Implementation using Hash Table

An alternative data structure that can be used for directory implementation is a hash table. It overcomes the major drawbacks of directory implementation using a linked list. In this method, we use a hash table along with the linked list. Here the linked list stores the directory entries, but a hash data structure is used in combination with the linked list. 

In the hash table for each pair in the directory key-value pair is generated. The hash function on the file name determines the key and this key points to the corresponding file stored in the directory. This method efficiently decreases the directory search time as the entire list will not be searched on every operation. Using the keys the hash table entries are checked and when the file is found it is fetched. 

Directory Implementation Using Hash Table

Directory Implementation Using Hash Table

Disadvantage:

The major drawback of using the hash table is that generally, it has a fixed size and its dependency on size. But this method is usually faster than linear search through an entire directory using a linked list.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads