/    /  OS – Directory structure in Operating System

Directory structure in Operating System

 

What is a directory?

A directory is a listing of all folders and files. A hard disk can be divided into a number of partitions of different sizes called volumes or mini disks. Each partition has at least one directory in which all the files of the partition is listed. It can also be defined as the file that contains the metadata of a bunch of files.

Several logical structures of the directory are as follows:

 

  • Single-level directory

 

In a single-level directory, all files are stored in the same directory which makes it easier to understand. However, it has a single drawback. When the number of files is large or there is more than one user, then all the files must have unique names, but if the two users call their dataset test, then the unique name rule is violated.

 

Advantages:

The advantages of a single-level directory are as follows:

  1. Implementation is easier.
  2. If the size of the files is smaller, searching becomes faster.
  3. File operations like file creation, searching, deletion becomes easier.

Disadvantages:

The disadvantages of a single-level directory are as follows:

  1. Cannot group the same file type together.
  2. Two files cannot have the same name.
  3. If the directory is larger, searching becomes time taking.

 

  1. Two level directory

In two level directory, every user has their own user files directory or UFD. The structures of the UFDs are similar, but each one of them is used by a single user. The master file directory or MFD is indexed by the username whenever a new account is entered into the system and each entry points to that user. 

 

Advantages:

The advantages of a two-level directory are as follows:

  1. Users can have the same file name.
  2. Searching is easier as there is user-grouping. 

 

Disadvantages:

The disadvantages of a two-level directory are as follows:

  1. Two files of the same type cannot be grouped together.
  2. Users cannot share the files with each other.

 

Tree-structured directory:

In a tee-structured directory, there is a root directory and every file in the system has a unique path. It is the most common directory structure.

 

Advantages:

The advantages of a tree-structured directory are as follows:

  1. Full pathname can be given.
  2. Almost no name collision.

 

Disadvantages:

The disadvantages of tree-structured directory are as follows:

  1. File may get saved into multiple directories.
  2. Files cannot be shared.
  3. Accessing a file may lead to different directories.

 

Acyclic graph directory:

In acyclic graph directories, more than one directory can point to the same file. It is mostly used in a project where two users need to work jointly. The needed files are stored in a subdirectory separate from other files so that they can be accessed by any of the users. 

 

Advantages:

The advantages of acyclic graph directories are as follows:

  1. Files can be shared.
  2. It makes searching easier as there are different paths.

 

Disadvantages:

The disadvantages of acyclic graph directories are as follows:

  1. In the case of softlink, if the file is deleted, then only a dangling pointer is left.
  2. In the case of hardlink, if we delete a file, then we also need to remove the reference connected to it.
  3. If the files are shared using a link, then deleting them might cause problems.

 

General-graph directory:

In a general-graph directory, multiple directories can be derived from more than one parent directory. The major problem with this directory is calculating the total space or size taken by the directories.

 

Advantages:

The advantages of general-graph directories are as follows:

  1. Cycles are allowed.
  2. It is more flexible.

 

Disadvantages:

The disadvantages of general-graph directories are as follows:

  1. Garbage collection is required.
  2. It is costlier than other directories. 

 

Reference

Directory structure in Operating System