Open In App

Structures of Directory in Operating System

A directory is a container that is used to contain folders and files. It organizes files and folders in a hierarchical manner. 



Following are the logical structures of a directory, each providing a solution to the problem faced in previous type of directory structure.  

1) Single-level directory:

 
The single-level directory is the simplest directory structure. In it, all files are contained in the same directory which makes it easy to support and understand. 



A single level directory has a significant limitation, however, when the number of files increases or when the system has more than one user. Since all the files are in the same directory, they must have a unique name. If two users call their dataset test, then the unique name rule violated.

Advantages: 

Disadvantages:

2) Two-level directory:

As we have seen, a single level directory often leads to confusion of files names among different users. The solution to this problem is to create a separate directory for each user

In the two-level directory structure, each user has their own user files directory (UFD). The UFDs have similar structures, but each lists only the files of a single user. System’s master file directory (MFD) is searched whenever a new user id is created.

Two-Levels Directory Structure

Advantages: 

Disadvantages:

3) Tree Structure/ Hierarchical Structure: 

Tree directory structure of operating system is most commonly used in our personal computers. User can create files and subdirectories too, which was a disadvantage in the previous directory structures. 

This directory structure resembles a real tree upside down, where the root directory is at the peak. This root contains all the directories for each user. The users can create subdirectories and even store files in their directory. 

A user do not have access to the root directory data and cannot modify it. And, even in this directory the user do not have access to other user’s directories.  The structure of tree directory is given below which shows how there are files and subdirectories in each user’s directory. 

Tree/Hierarchical Directory Structure

Advantages:

Disadvantages:

4) Acyclic Graph Structure: 

As we have seen the above three directory structures, where none of them have the capability to access one file from multiple directories. The file or the subdirectory could be accessed through the directory it was present in, but not from the other directory. 

This problem is solved in acyclic graph directory structure, where a file in one directory can be accessed from multiple directories. In this way, the files could be shared in between the users. It is designed in a way that multiple directories point to a particular directory or file with the help of links. 

In the below figure, this explanation can be nicely observed, where a file is shared between multiple users. If any user makes a change, it would be reflected to both the users. 

Acyclic Graph Structure

Advantages:

Disadvantages:

FAQs on Directory Structure

Q1. What is a root Directory?

Answer:

A root directory is a fundamental concept in directory structure of OS. It is a parent directory that is a top-level directory organised in a hierarchical manner and is represented by a forward slash “/” in a unix like systems & a backslash in windows “\”.

Q2. What is a purpose of a directory structure?

Answer:

The sole purpose of a directory structure is to provide a way to store and oragnised files & data in an efficient manner so that access and management of all the files can be done by the user in the simplest and productive manner.

Q3. What is a sub-directory ?

Answer:

A sub-directory is a directory inside another directory. Inside a directory structure, a user can create many directories inside a directory. These are called sub-directories.

Q4. What are some common directory structures used in Operating System?

Answer:

Most common directory structures used to store and organise files are – Single-Level, Two-Level, tree-like directory structures. Tree structure is generally used in modern personal computers.

Q5. What are most common system calls made while managing files through a directory structure?

Answer:

Following system calls are majorly used :

  • mkdir() : this system call is made when creating a new file through GUI or through command line.
  • open() : This call is made when opening a file inside a directory structure
  • close() : This call is made when we close a file in a directory structure
  • unlink() : This call is made to unlike a file from other directories before deleting it
  • rmdir : This call is made to remove a directory from a file system.


Article Tags :