Directory Structure in os

What is a directory?

Directory can be defined as the listing of the related files on the disk. The directory may store some or the entire file attributes.

To get the benefit of different file systems on the different operating systems, A hard disk can be divided into the number of partitions of different sizes. The partitions are also called volumes or mini disks.

Each partition must have at least one directory in which, all the files of the partition can be listed. A directory entry is maintained for each file in the directory which stores all the information related to that file.

os Directory Structure

A directory can be viewed as a file which contains the Meta data of the bunch of files.

Every Directory supports a number of common operations on the file:

  1. File Creation
  2. Search for the file
  3. File deletion
  4. Renaming the file
  5. Traversing Files
  6. Listing of files

Types of Directory Structures

In this section, we will be discussing the most common types of directories, their benefits and drawbacks



Single-level directory structure

Single level directory structure has only one directory which is called the root directory. The users are not allowed to create subdirectories under the root directory. All the files created by the several users are present in the root directory only.

As you can see in the diagram below all the file F1, F2, F3, F4 created by the different users are present at the root directory.

Single-level Directory

There is one drawback of Single-level directory structure, a user cannot use the same file name used by another user in the system. Even if the file with the same name is created the old file will get destroyed first and replaced by the new file having the same name.

  1. Implementation is very simple.
  2. If the sizes of the files are very small then the searching becomes faster.
  3. File creation, searching, deletion is very simple since we have only one directory.
  1. We cannot have two files with the same name.
  2. The directory may be very big therefore searching for a file may take so much time.
  3. Protection cannot be implemented for multiple users.
  4. There are no ways to group same kind of files.
  5. Choosing the unique name for every file is a bit complex and limits the number of files in the system because most of the Operating System limits the number of characters used to construct the file name.

Two-level directory structure

In a Two-level directory structure, the users create a directory directly inside the root directory. But once a user creates such a directory, further he cannot create any subdirectory inside that directory. Observe the figure below, 4 users have created their separate directory inside the root directory. But further, no subdirectory is created by the users.

Two-level Directory Structure

This two-level structure allows each user to keep their files separately inside their own directory. This structure allows to use of the same name for the files but under different user directories.

The 72 Sigils of Power: Magic, Insight, BOOK BUY 

Characteristics of two level directory system
  1. Each files has a path name as /User-name/directory-name/
  2. Different users can have the same file name.
  3. Searching becomes more efficient as only one user’s list needs to be traversed.
  4. The same kind of files cannot be grouped into a single directory for a particular user.

Every Operating System maintains a variable as PWD which contains the present directory name (present user name) so that the searching can be done appropriately.

Hierarchical Directory Structure

In Hierarchical directory structure, the users can create directories under the root directory and can also create sub-directories under this structure. As the user is free to create many sub-directories, it can create different sub-directories for different file types.

Hierarchical Directory

Here, the files are accessed by their location using the path. There are two types of paths to locate the file in this directory structure

Absolute Path

Here, the path for the desired file is described by considering the root directory as the base directory.

Relative Path

Here, either the user’s directory is considered as the base directory or the desired file directory is considered as the base directory.

Tree Directory Structure

In a tree directory structure, except the root directory, every directory or file has only one parent directory. So, there is a total separation between the users which provides complete naming freedom. Here, if a user wishes to access another user’s file, it has to go through two or more directories.

Tree Directory Structure

The tree directory structure provides an asymmetric way for the user to access the shared files of a different user. For example, a user can access a file of its own user directory with a shorter path than the other user.

Acyclic-Graph Directory Structure

This problem can be solved by the acyclic-graph directory structure. As this directory structure allows a directory or a file to have many parent directories. So, a shared file in a directory can be pointed by the other user directories who have access to that shared file using the links.

In the diagram below you can see that the directory having file F7 and F8 have two-parent directories

Operations on Directory

As discussed above, a directory contains the entries of all the related files. For organizing the directory in the better way the user must be able to insert, delete, search, list the entries in the directory. Below we will be discussing the operation that can be performed on the directory.

1.  Searching 

A directory can be searched for a particular file or for another directory. It can also be searched to list all the files with the same name.

2. Creating

A new file can be created and inserted to the directory or new directory can be created keeping in mind that its name must be unique under that particular directory.

3. Deleting

If a file is no longer needed by the user, it can be deleted from the directory. The entire directory can also be deleted if it is not needed. An empty directory can also be deleted. When a directory is empty it is resembled by dot and dotdot.

4. List a directory

List of all the files in the directory can be retrieved and also the contents of the directory entry, for each file in a list. To read the list of all the files in the directory, it must be opened and after reading the directory must be closed to free up the internal tablespace.

5. Renaming

The name of the file or a directory represents the content it holds and its use. The file or directory can be renamed in case, the content inside or the use of file get changed. Renaming the file or directory also changes its position inside the directory.

6. Link

The file can be allowed to appear in more than one directory. Here, the system call creates a link between the file and the name specified by the path where the file is to appear.

7. Unlink

If the file is unlinked and is only present in one directory its directory entry is removed. If the file appears in multiple directories, only the link is removed.


What is Cache Memory Organization   

What is Program Design
Explain File Allocation Methods


Tygot Adjustable Aluminium Alloy Tripod Stand Holder for Mobile Phones & Camera, 360 mm -1050 mm, 1/4 inch Screw + Mobile Holde


Open chat