Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
Directory structures in an operating system provide a hierarchical organization for storing and managing files and directories. They typically start with a root directory and allow for efficient data access, organization, and navigation, simplifying file management and access control. Directory structures are essential for modern computing environments.
A directory can be thought of as a folder. It is a collection of files on the storage device. In our computers, we always store various files like songs, images, videos, etc. All these files are stored in some directory. In this article, we shall see directory structures in os. This is a very easy topic and simple to understand.
What is Directory Structure in OS?
On a computer, a directory is used to store, arrange, and segregate files and folders. It is similar to a telephone directory in that it just contains lists of names, phone numbers, and addresses rather than the real papers. It uses a hierarchical structure to organise files and directories. On many computers, directories are referred to as drawers or folders, much like a workbench or a standard filing cabinet in an office. You may, for instance, create a directory for images and another for all of your documents. You could easily access the type of file you wanted to see by saving particular file types in a folder.
There are several logical structures of a directory, these are given below.
Single level directory
Two-level directory
Tree structure or hierarchical directory
Acyclic graph directory
General graph directory structure and Data Structure
Single-Level Directory Structure
It is the simplest directory structure. In a single-level directory, there is only one directory in the system, meaning there is only one folder, and all the files are stored in that single directory. There is no way to segregate important files from non-important files.
Implementation of a single-level directory is the simplest. However, there are various disadvantages of it.
The pictorial representation of a single-level directory is given below. There is only one directory ( root directory), and all the files are stored in the same directory. Here f1, f2, f3, f4, f5 represent the five different files. Practically it can be thought of as a structure where all the files are stored in the same folder.
Advantages of single-level directory
The main advantage of a single-level directory is that it is very simple to implement.
Since all the files are present in the same directory, in case the number of files is less, then searching for a particular file is faster and easier.
Simple operations like file creation, search, deletion, and updating are possible with a single-level directory structure.
The single-level directory is easier to understand in practical life.
Disadvantages of single-level directory
In case we want to organise the files in some groups, it is not possible to do so since we cannot create subdirectories.
Two file names cannot be the same. In case two files are given the same name, the previous one is overridden.
If the number of files is very large, searching a particular file is very inefficient.
Segregation of important and unimportant files is not possible.
The single-level directory is not useful for multi-user systems.
Two-Level Directory Structure
We saw how the single-level directory proves to be inefficient if multiple users are accessing the system. If two different users wanted to create a file with the same name (say report.doc), it was not allowed in a single level directory.
In a two-level directory structure, there is a master node that has a separate directory for each user. Each user can store the files in that directory. It can be practically thought of as a folder that contains many folders, each for a particular user, and now each user can store files in the allocated directory just like a single level directory.
The pictorial representation of a two-level directory is shown below. For every user, there is a separate directory. At the next level, every directory stores the files just like a single-level directory. Although not very efficient, the two-level directory is better than a single-level directory structure.
Advantages of two-level directory
Searching is very easy.
There can be two files with the same name in two different user directories. Since they are not in the same directory, the same name can be used.
Grouping is easier.
A user cannot enter another user’s directory without permission.
Implementation is easy.
Disadvantages of two-level directory
One user cannot share a file with another user.
Even though it allows multiple users, still a user cannot keep two same type files in a user directory.
It does not allow users to create subdirectories.
Tree-Structured Directory Structure
This type of directory is used in our PCs. The biggest disadvantage of a two-level directory was that one could not create sub-directories in a directory. The tree-structured directory solved this problem. In a tree-structured directory, there is a root directory at the peak. The root directory contains directories for each user. The users can, however, create subdirectories inside their directory and also store the files.
This is how things work on our PCs. We can store some files inside a folder and also create multiple folders inside a folder.
The pictorial representation of a tree-structured directory is shown below. The root directory is highly secured, and only the system administrator can access it. We can see how there can be subdirectories inside the user directories. A user cannot modify the root directory data. Also, a user cannot access another user's directory.
Advantages of tree-structured directory
Highly scalable compared to the previous two types of directories.
Allows subdirectories inside a directory.
Searching is easy.
Allows grouping.
Segregation of important and unimportant files is easy.
Disadvantages of tree-structured directory
As one user cannot enter another user’s directory, this restricts sharing of files.
Too many subdirectories may make the search complicated.
Users cannot modify the root directory’s data.
Files might have to be saved in multiple directories in case all of them do not fit into one.
Acyclic Graph Directory Structure
Suppose there is a file abcd.txt. Out of the three types of directories we studied above, none of them provide the flexibility to access the file abcd.txt from multiple directories, i.e., we cannot access a particular file or subdirectory from two or more directories. The file or the subdirectory can be accessed only by the directory it is present inside.
The solution to this problem is presented by the acyclic-graph directory. In this type of directory, we can access a file or a subdirectory from multiple directories. Hence files can be shared between directories. It is designed in such a way that multiple directories point to a particular directory or file with the help of links.
A practical example of this is a doc file shared between two users. If any of the users makes a change in the file, the change is reflected for both the users.
Below is the pictorial representation of the acyclic-graph directory.
Advantages of acyclic- graph directory
Allows sharing of files or subdirectories from more than one directory.
Searching is very easy.
Provides more flexibility to the users.
Disadvantages of acyclic-graph directory
Harder to implement in comparison to the previous three.
Since the files are accessed from multiple directories, deleting a file may cause some errors if the user is not cautious.
If the files are linked by a hard link, then it is necessary to delete all the references to that file to permanently delete the file.
General-Graph Directory Structure
This is an extension to the acyclic-graph directory. In the general-graph directory, there can be a cycle inside a directory.
In the above image, we can see that a cycle is formed in the user 2 directory. Although it provides greater flexibility, it is complex to implement this structure.
Advantages of General-graph directory
Compared to the others, the General-Graph directory structure is more flexible.
Cycles are allowed in the directory for general-graphs.
What is directory structure in OS (operating system)?
The arrangement of files into a hierarchy of folders is known as the directory structure. It ought to be scalable and stable. The entries for all the files connected to a specific directory can be found in the Directory Structure. Many users have thousands of information-containing files and folders.
What are the 2 types of directories?
Single-level directories and two-level directories are the two types of directories. The single-level directory is the simplest directory structure. In a two-level directory structure, there is a master node that has a separate directory for each user. Each user can store the files in that directory.
What is the file structure?
A file structure refers to the organization and arrangement of data within a file or system of files. It determines how data is stored, accessed, and managed, enabling efficient retrieval and manipulation of information in computing environments.
Conclusion
In conclusion, directory structures in operating systems are fundamental for efficient file management, data organization, and access control. They create a hierarchical framework that simplifies the storage and retrieval of files, contributing to the seamless functioning of modern computing environments.
Single-level directory, two-level directory, tree-structured directory, acyclic-graph directory, and general-graph directory are various structures of a directory.
In a single-level directory, all the files are stored in a single directory.
In a two-level directory structure, there are user directories, and each user can store files in their own directory.
A tree-structured directory is used in real-life practice. It allows the creation of subdirectories.
General-graph directory allows a cycle within a directory, but the acyclic-graph directory does not.