×

Directory Structure in Operating System

Directory Structure in Operating System

What is a Directory

A Directory is the collection of the correlated files on the disk. In simple words, a directory is like a container which contains file and folder. In a directory, we can store the complete file attributes or some attributes of the file. A directory can be comprised of various files. With the help of the directory, we can maintain the information related to the files.

Directory Structure in Operating System

To take the advantages of various file systems on the different operating systems, we can divide the hard disk into multiple partitions, which are of different sizes. Partitions are known as minidisks or volumes.

There should be at least one directory that must be present in each partition. Through it, we can list all the files of the partition. In the directory for each file, there is a directory entry, which is maintained, and in that directory entry, all the information related to the file is stored.

There are various types of information which are stored in a directory:

  1. Name
  2. Type
  3. Location
  4. Size
  5. Position
  6. Protection
  7. Usage
  8. Mounting
  1. Name: - Name is the name of the directory, which is visible to the user.
  2. Type: - Type of a directory means what type of directory is present such as single-level directory, two-level directory, tree-structured directory, and Acyclic graph directory.
  3. Location: - Location is the location of the device where the header of a file is located.
  4. Size: - Size means number of words/blocks/bytes in the file.
  5. Position: - Position means the position of the next-read pointer and the next-write pointer.
  6. Protection: - Protection means access control on the read/write/delete/execute.
  7. Usage: - Usage means the time of creation, modification, and access, etc.
  8. Mounting: - Mounting means if the root of a file system is grafted into the existing tree of other file systems.

Operations on Directory

The various types of operations on the directory are:

  1. Creating
  2. Deleting
  3. Searching
  4. List a directory
  5. Renaming
  6. Link
  7. Unlink
  1. Creating: - In this operation, a directory is created. The name of the directory should be unique.
  2. Deleting: - If there is a file that we don’t need, then we can delete that file from the directory. We can also remove the whole directory if the directory is not required. An empty directory can also be deleted. An empty directory is a directory that only consists of dot and dot-dot.
  3. Searching: - Searching operation means, for a specific file or another directory, we can search a directory.
  4. List a directory: - In this operation, we can retrieve all the files list in the directory. And we can also retrieve the content of the directory entry for every file present in the list.

If in the directory, we want to read the list of all files, then first, it should be opened, and afterwards we read the directory, it is a must to close the directory so that the internal tablespace can be free up.

Types of Directory Structure

There are various types of directory structure:

  1. Single-Level Directory
  2. Two-Level Directory
  3. Tree-Structured Directory
  4. Acyclic Graph Directory
  5. General-Graph Directory
  6. Single-Level Directory: - Single-Level Directory is the easiest directory structure. There is only one directory in a single-level directory, and that directory is called a root directory. In a single-level directory, all the files are present in one directory that makes it easy to understand. In this, under the root directory, the user cannot create the subdirectories.
Directory Structure in Operating System

Advantages of Single-Level Directory

The advantages of the single-level directory are:

  1. The implementation of a single-level directory is so easy.
  2. In a single-level directory, if all the files have a small size, then due to this, the searching of the files will be easy.
  3. In a single-Level directory, the operations such as searching, creation, deletion, and updating can be performed.

Disadvantages of Single-Level Directory

The disadvantages of Single-Level Directory are:

  1.  If the size of the directory is large in Single-Level Directory, then the searching will be tough.
  2. In a single-level directory, we cannot group the similar type of files.
  3.  Another disadvantage of a single-level directory is that there is a possibility of collision because the two files cannot have the same name.
  4. The task of choosing the unique file name is a little bit complex.
  5. Two-Level Directory

Two-Level Directory is another type of directory structure. In this, it is possible to create an individual directory for each of the users. There is one master node in the two-level directory that include an individual directory for every user. At the second level of the directory, there is a different directory present for each of the users. Without permission, no user can enter into the other user’s directory.

Directory Structure in Operating System

Characteristics of Two-Level Directory

The characteristics of the two-level directory are:

  1. In a two-level directory, there may be same file name of different users.
  2. There is a pathname of each file such as /User-name/directory-name/
  3. In a two-level directory, we cannot group the files which are having the same name into a single directory for a specific user.
  4. In a two-level directory, searching is more effective because there is only one user’s list, which is required to be traversed.

Advantages of Two-Level Directory

The advantages of the two-level directory are:

  1. In the two-level directory, various users have the same file name and also directory name.
  2. Because of using the  user-grouping and pathname, searching of files are quite easy.

Disadvantages of Two-Level Directory

The disadvantages of the two-level directory are:

  1. In a two-level directory, one user cannot share the file with another user.
  2. Another disadvantage with the two-level directory is it is not scalable.
  3. Tree-Structured Directory

A Tree-structured directory is another type of directory structure in which the directory entry may be a sub-directory or a file. The tree-structured directory reduces the limitations of the two-level directory. We can group the same type of files into one directory.

In a tree-structured directory, there is an own directory of each user, and any user is not allowed to enter into the directory of another user. Although the user can read the data of root, the user cannot modify or write it. The system administrator only has full access to the root directory. In this, searching is quite effective and we use the current working concept. We can access the file by using two kinds of paths, either absolute or relative.

Directory Structure in Operating System

Advantages of tree-structured directory

The advantages of the tree-structured directory are:

  1. The tree-structured directory is very scalable.
  2. In the tree-structures directory, the chances of collision are less.
  3. In the tree-structure directory, the searching is quite easy because, in this, we can use both types of paths, which are the absolute path and relative path.

Disadvantages of Tree-Structure Directory

The disadvantages of tree-structure directory are:

  1. In the tree-structure directory, the files cannot be shared.
  2. Tree-structure directory is not efficient because, in this, if we want to access a file, then it may go under multiple directories.
  3. Another disadvantage of the tree-structure directory is that each file does not fit into the hierarchal model. We have to save the files into various directories.
  • Acyclic-Graph Directory

In the tree-structure directory, the same files cannot exist in the multiple directories, so sharing the files is the main problem in the tree-structure directory. With the help of the acyclic-graph directory, we can provide the sharing of files. In the acyclic-graph directory, more than one directory can point to a similar file or subdirectory. We can share those files among the two directory entries.

With the help of aliases, and links, we can create this type of directory graph. We may also have a different path for the same file. Links may be of two kinds, which are hard link (physical) and symbolic (logical).

If we delete the files in acyclic graph structures, then

  1. In the hard link (physical) case, we can remove the actual files only if all the references to the file are deleted.
  2. In the symbolic link (logical) case, we just delete the file, and there is only a dangling point that is left.

Advantages of Acyclic-Graph Directory

The advantages of the acyclic-graph directory are:

  1. In the acyclic-graph directory, the sharing of files is possible.
  2. In the acyclic-graph directory, because of different-different paths, searching is easy.

Disadvantages of Acyclic-Graph Directory

The disadvantages of acyclic-graph directory are:

  1. If the files are shared through linking, there may be a problem in the case of deleting.
  2. If we are using softlink, then in this case, if the file is deleted then there is only a dangling pointer which is left.
  3. If we are using hardlink, in this case, when we delete a file, then we also have to remove all the reference connected with it.
  4. General-Graph Directory

The General-Graph directory is another vital type of directory structure. In this type of directory, within a directory we can create cycle of the directory where we can derive the various directory with the help of more than one parent directory.

The main issue in the general-graph directory is to calculate the total space or size, taken by the directories and the files.

Directory Structure in Operating System

Advantages of General-Graph directory

The advantages of general-graph directory are:

  1. The General-Graph directory is more flexible than the other directory structure.
  2. Cycles are allowed in the general-graph directory.

Disadvantages of General-Graph Directory

The disadvantages of general-graph directory are:

  1. In general-graph directory, garbage collection is required.
  2. General-graph directory is more costly, among other directory structures.

Directory Implementation

There are various types of algorithm which we use for directory implementation. The selection of a suitable algorithm for directory implementation is an essential task because it directly affects system performance.

We can classify the directory implementation algorithm based on the data structure.

Mostly, we use two types of algorithms:

  1. Linear List
  2. Hash Table
  1. Linear List: - The linear list is the most straightforward algorithm which is used for directory implementation. In this algorithm, we keep all the files in a directory like a singly linked list. Every file comprises of a pointer to the data blocks that are allocated to it and the next file in the directory.
Directory Structure in Operating System

Characteristics of Linear List

The characteristics of the linear list are:

2. Hash Table: - There are some disadvantages in singly linked implementation of directories. So, to remove this drawback, we use another method that is called a hash table. In this method, the hash table is used with the linked list.

In a directory, for every file, there is a key-value pair that is generated, and when the key-value pair is generated, then we store it into the hash table. With the help of the hash function on the file name, we can determine the key and key points to the respective file that are stored in a directory.

In a linear list, the task of searching is difficult because, in a linear list, we have to search the entire list, but in hash table approach, there is no requirement of searching the entire list. So, in hash table searching is quite efficient. With the help of the key, we only have to check the entries of the hash table, and when we get the entry, then by using the value, we will fetch the corresponding file.

Directory Structure in Operating System

Related Topics

Ubuntu Operating System

Ubuntu Operating System Ubuntu is an open-source and a Linux based operating system. Ubuntu is developed for the Network Servers, Computers, and Smartphones. The Ubuntu operating system was developed by Canonical...

3 minutes read.

Difference between C-SCAN and SSTF Disk Scheduling Algorithm

C-SCAN / Circular Elevator The circular SCAN (C-SCAN) scheduling method is a modified version of the SCAN disc scheduling technique that addresses the SCAN algorithm's inefficiency by more equitably serving requests....

3 minutes read.

Priority Scheduling in OS

Priority Scheduling is a type of CPU Scheduling algorithm which is used for process scheduling. In Priority Scheduling, we assign some priorities to each process. The process which has higher priority among all...

5 minutes read.

Free Space Management in Operating System

What is Free Space Management? The system always keeps the records of the free disks blocks for allocating space to files when they are created. To use the space free from...

4 minutes read.

Operating System Tutorial

What is an Operating System? An Operating System is a System Software that handles the resources of a computer such as computer hardware and software and offers frequent services to the...

7 minutes read.

Paging and Segmentation in OS

What is Paging in OS? Paging is a storage technique used for memory management. In paging, the (OS) Operating System retrieves the processes from the secondary memory into the main memory,...

6 minutes read.

Why is it critical for the Scheduler to distinguish between I/O-bound and CPU-bound programs

A CPU-bound process is one that spends most of its time executing instructions on the processor. A process that is I/O-bound spends most of its time waiting for input and...

2 minutes read.

Linux Operating System

What is Linux? The Linux operating system is used on various devices, including cellphones, automobiles, supercomputers, household gadgets, personal computers, and business servers. You can find Linux on your phones, thermostats, vehicles,...

8 minutes read.

Operating System Services

The Operating System provides various types of services:   I/O operationProgram executionFile system manipulationCommunicationError HandlingResource allocationAccountingProtection 1. I/O Operation: - To execute a program, needs I/O, which consists of a file, or I/O device. Due to the protection...

3 minutes read.

Difference between Seek Time and Disk Access Time in Disk Scheduling

Seek Time The time taken for the hard disk controller to detect a specific piece of recorded data is known as the seek time. The amount of time it takes to...

4 minutes read.

Resource Allocation Graph in Operating System

Resource Allocation Graph in OS We use the resource allocation graph for the pictographic representation of the state of a system. The resource allocation graph contains all the information related to the processes that...

5 minutes read.

Page Table in Operating System

What is a Page Table? A page table is a data structure used by an operating system (OS) to store information about the physical location of the pages in a computer's...

6 minutes read.

Non-Contiguous Memory Allocation in Operating System

Memory is nothing but a storage space where various data are stored. We can store data in temporary and permanent memory as per our future requirements for data. We can...

9 minutes read.

Difference between Process and Program in the Operating System

What is a process in the Operating System? A process is a program that is going through the execution. It also helps us to execute all the lines of code in...

4 minutes read.

Fixed Partitioning in Operating System

Fixed Partitioning in OS Fixed Partitioning is also known as Contiguous memory allocation. Fixed Partitioning is the easiest method, which is used to load more than one process into the main memory. In Fixed...

5 minutes read.

Directory Structure in Operating System

Directory Structure in Operating System What is a Directory A Directory is the collection of the correlated files on the disk. In simple words, a directory is like a container which contains...

8 minutes read.

Advantages of Operating System

What is an Operating System?   An operating system is an interface that helps to communicate with the user and the computer hardware. Operating systems are used for file management, memory...

3 minutes read.

Process Schedulers and Process Queue in OS

Process Schedulers There are various types of Process Schedulers: Long Term SchedulerShort Term SchedulerMedium Term Scheduler                                            Long Term Scheduler: - Long term scheduler is also referred to as Job Scheduler. The task of the Long-term...

3 minutes read.

Starvation in Operating System

Starvation is one of the major problems occurring when resource management is not done properly. This problem arises in the operating system when the resources are not being allocated for...

4 minutes read.

Single-User Operating System

An operating system designed and intended to be used on a computer or device with a single user at a time is known as a single-user operating system. Devices like...

8 minutes read.