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.
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:
- File Creation
- Search for the file
- File deletion
- Renaming the file
- Traversing Files
- 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.
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.
- Implementation is very simple.
- If the sizes of the files are very small then the searching becomes faster.
- File creation, searching, deletion is very simple since we have only one directory.
- We cannot have two files with the same name.
- The directory may be very big therefore searching for a file may take so much time.
- Protection cannot be implemented for multiple users.
- There are no ways to group same kind of files.
- 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.
Characteristics of two level directory system
- Each files has a path name as /User-name/directory-name/
- Different users can have the same file name.
- Searching becomes more efficient as only one user’s list needs to be traversed.
- 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.
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
Here, the path for the desired file is described by considering the root directory as the base directory.
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.
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.
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.
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.
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.
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.
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.
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.
SOME USE FULL LINK
What is Cache Memory Organization What is Program Design Explain File Allocation Methods USFULL PRODUCT