Operating System Tutorial

Operating System Tutorial Types of Operating System Evolution of Operating System Functions of Operating System Operating System Properties Operating System Services Components of Operating System Needs of the Operating System

Operating Systems

Linux Operating System Unix Operating System Ubuntu Operating System Chrome Operating Systems Fedora Operating System MAC Operating System MS Windows Operating System Solaris Operating System Cooperative Operating System CorelDRAW Operating System CentOS FreeBSD Operating Systems Batch Operating System MS-DOS Operating System Commercial Mobile Operating Systems

Differences

Difference Between Multi-programming and Multitasking Difference between C-LOOK and C-SCAN Difference between Rotational Latency and Disk Assess Time Trap vs Interrupt Difference between C-SCAN and SSTF Difference between SCAN and FCFS Difference between Seek Time and Disk Access Time Difference between SSTF and LOOK Difference between Process and Program in the Operating System Difference between Protection and Security in Operating System

How To

How to implement Monitors using Semaphores How to Install a Different Operating System on a PC

Questions

What is Kernel and Types of Kernel What is DOS Operating System What is Thread and Types of Thread What is Process Scheduler and Process Queue What is Context Switching What is CPU Scheduling What is Producer-Consumer Problem What is Semaphore in Operating System Monitors in Operating System What is Deadlock What is Paging and Segmentation What is Demand Paging What is Virtual Memory What is a Long term Scheduler What is Page Replacement in Operating System What is BSR Mode What is Convoy Effect What is Job Sequencing in Operating System Why is it critical for the Scheduler to distinguish between I/O-bound and CPU-bound programs Why is there a Need for an Operating System

Misc

Process Management Process State Scheduling Algorithm FCFS (First-come-First-Serve) Scheduling SJF (Shortest Job First) Scheduling Round-Robin CPU Scheduling Priority Based Scheduling HRRN (Highest Response Ratio Next) Scheduling Process Synchronization Lock Variable Mechanism TSL Mechanism Turn Variable Mechanism Interested Variable Mechanism Deadlock Avoidance Strategies for Handling Deadlock Deadlock Prevention Deadlock Detection and Recovery Resource Allocation Graph Banker’s Algorithm in Operating System Fixed Partitioning and Dynamic Partitioning Partitioning Algorithms Disk Scheduling Algorithms FCFS and SSTF Disk Scheduling Algorithm SCAN and C-SCAN Disk Scheduling Algorithm Look and C-Look Disk Scheduling Algorithm File in Operating System File Access Methods in Operating System File Allocation Method Directory Structure in Operating System N-Step-SCAN Disk Scheduling Feedback Queue in Operating System Contiguous Memory Allocation in Operating System Real-time Operating System Starvation in Operating System Thrashing in Operating System 5 Goals of Operating System Advantages of Operating System Advantages of UNIX Operating System Bit Vector in Operating System Booting Process in Operating System Can a Computer Run Without the Operating System Dining Philosophers Problem in Operating System Free Space Management in Operating System Inter Process Communication in Operating System Swapping in Operating System Memory Management in Operating System Multiprogramming Operating System Multitasking Operating Systems Multi-user Operating Systems Non-Contiguous Memory Allocation in Operating System Page Table in Operating System Process Scheduling in Operating System Segmentation in Operating System Simple Structure in Operating System Single-User Operating System Two Phase Locking Protocol Advantages and Disadvantages of Operating System Arithmetic operations in binary number system Assemblers in the operating system Bakery Algorithm in Operating System Benefits of Ubuntu Operating System CPU Scheduling Criteria in Operating System Critical Section in Operating System Device Management in Operating System Linux Scheduler in Operating System Long Term Scheduler in Operating System Mutex in Operating System Operating System Failure Peterson's Solution in Operating System Privileged and Non-Privileged Instructions in Operating System Swapping in Operating System Types of Operating System Zombie and Orphan Process in Operating System 62-bit operating system Advantages and Disadvantages of Batch Operating System Boot Block and Bad Block in Operating System Contiguous and Non - Contiguous Memory Allocation in Operating System Control and Distribution Systems in Operations Management Control Program in Operating System Convergent Technologies in Operating System Convoy Effect in Operating System Copy Operating Systems to SSD Core Components of Operating System Core of UNIX Operating System Correct Value to return to the Operating System Corrupted Operating System Cos is Smart Card Operating System Cosmos Operating Systems Examples Generation of Operating System Hardware Solution in Operating System Process Control Block in Operating System Function of Kernel in Operating System Operating System Layers History of Debian Operating Systems Branches and Architecture of Debian Operating Systems Features and Packages of Debian Operating Systems Installation of Operating System on a New PC Organizational Structure and Development in Debian Operating Systems User Interface in Operating System Types Of Memory in OS Operating System in Nokia Multilevel Paging in OS Memory Mapping Techniques in OS Memory Layout of a Process in Operating System Hardware Protection in Operating System Functions of File Management in Operating System Core of Linux Operating System Cache Replacement Policy in Operating System Cache Line and Cache Size in Operating System What is Memory Mapping? Difference Between Network Operating System And Distributed Operating System What is the difference between a Hard link and a Soft Link? Principles of Preemptive Scheduling Process Scheduling Algorithms What is NOS? What is the Interrupt I/O Process? What is Time Sharing OS What is process termination? What is Time-Sharing Operating System What is Batch File File system manipulation

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