Professional Documents
Culture Documents
Introduction
Several users create thousands and millions of files in a file system.
The Directory structure is used by the file system to correctly organize these
files. The directory structure has the entries of the all the files related to that
directory. A directory is considered as a file, that contains information about
the other files.
Data or applications can be stored in files. There are two types of files:
simple and complex. Both the operating system and the software that
creates the file decide the structure of the file. Files are kept in a file system,
which can be found on a disc, tape, or main memory.
The two important features that must be taken care of while maintaining a
directory are:
1. A user must have freedom of giving the desired name to the file,
without taking into consideration that the same file names are used by
other users on the system.
2. A user must be able to share the files he creates and he must also be
able to access the files, created by other users.
Overview of Directory Structure
A Directory structure provides both the above-discussed features. A
directory always has information about the group of related
files. Whenever a user or a process request for a file, the file system
searches for the file’s entry in the directory and when the match is
found, it obtains the file’s location.
Overview of Directory Structure
File name: The name of the concerned file in the directory
Type: The kind or category of the file
Location Info: The location where the file is stored.
Protection Info: Information whether the file can be accessed by the
other users in the system or not.
Flag: The kind of directory entry
o D indicates that the file is a directory
o L indicates that the file is a link
o M indicates that the file is a mounted file system.
Improved Security: Directory structures can provide better security for files
by allowing access to be restricted at the directory level. This helps to
prevent unauthorized access to sensitive data and ensures that important
files are protected.
Advantages of Directory Structure
Facilitates Backup and Recovery: Directory structures make it easier
to backup and recover files in the event of a system failure or data loss.
By storing related files in the same directory, it is easier to locate and
backup all the files that need to be protected.
2. Two-Level Directory
3. Tree-Structured Directory
5. General-Graph Directory
Single-Level Directory
There is only one directory called the Root directory. There is one big list of
all the files on the disk. All the files created by several users are in one
directory. The users are not allowed to create subdirectories under the root
directory. The directory contains one entry per each file present on the file
system.
Single-Level Directory
Advantages of Single-Level Directory
1. Implementation of a single-level directory is easy.
2. If all the files have a small size, then the searching of the files will be
easy.
3. The operations such as searching, creation, deletion, is very simple
since we have only one directory.
Single-Level Directory
Disadvantages of Single-Level Directory
1. We cannot have two files with the same name
2. If the size of the directory is large the searching will take so much
time.
3. Similar type of files cannot be grouped together.
4. There is a possibility of collision because the two files cannot have the
same name.
5. The task of choosing the unique file name is a little bit complex and it
limits the number of files in the system because most of the Operating
Systems limit the number of characters used to construct the file
name.
6. Protection cannot be implemented for multiple users.
7. The single-level directory is not useful for multi-user systems.
Two-Level Directory
There is a master node that has a separate directory for each user. For
each user, there is a different directory present at the second level,
containing group of user's file. The system doesn't let a user to enter in
the other user's directory without permission. 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.
For every user, there is a separate directory. Each user has their
own user files directory (UFD). No user can enter into the other user’s
directory without permission. 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.
Two-Level Directory
The UFDs have similar structures, but each lists only the files of a
single user. system’s master file directory (MFD) is searched whenever
a new user id is Correct.
We cannot group files having the same name into a single directory for a specific
user.
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.
Two-Level Directory
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.
Two-Level Directory
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.
It is not scalable.
Tree-Structured / Hierarchical 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.
In Tree structured directory system, any directory entry can either be a file or sub
directory. Tree structured directory system overcomes the drawbacks of two level
directory system. The similar kind of files can now be grouped in one directory.
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 root directory is highly secured, and only the system administrator can access it.
There can be subdirectories inside the user directories. Although the user can read the
data of root, he cannot however modify or write it and he cannot also access another
user's directory.
Tree-Structured Directory
Tree-Structured Directory
Tree-Structured / Hierarchical Directory
It’s only the System Administrator who has full access to the root directory.
Absolute Path
Here, the path for the desired file is described by considering the root
directory as the base directory.
Relative Path
Here, the path depends on the current working directory of the system; either
the user’s directory is considered as the base directory or the desired file
directory is considered as the base directory.
Tree-Structured / Hierarchical Directory
In tree structured directory systems, the user is given the privilege to
create the files as well as directories.
In a tree directory structure, every directory or file has only one parent
directory except the Root Directory. So, there is a total separation
between the users which provide complete naming freedom. If a user
wishes to access another users file, it has to go through two or more
directories.
Tree-Structured Directory
Advantages of tree-structured directory
Highly scalable compared to the previous two types of directories.
Allows subdirectories inside a directory.
Searching is easy because we may utilize both absolute and relative
paths.
Allows grouping.
Segregation of important and unimportant files is easy.
Collisions are less likely in the tree-structures directory
Tree-Structured Directory
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.
Each file does not fit into the hierarchal model. We have to save the
files into various directories.
Because a file might be found in several folders, it is inefficient
Tree-Structured Directory
Permissions on the file and directory
A tree structured directory system may consist of various levels
therefore there is a set of permissions assigned to each file and
directory.
o (i) symbolic link or soft link (specify a file path: logical) and
o (ii) hard link (actual link to the same file on the disc from multiple
directories: physical).
2. In the case of hard link, the actual file will be deleted only if all the
references to it gets deleted.
Acyclic Graph Directory
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.
The biggest issue with this type of directory layout is figuring out how
much space the files and folders have used up.
General-Graph Directory
General-Graph Directory
General-Graph Directory
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.
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 represented by dots.
Operations on Directory
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 table space.
5. Renaming
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.
Directory Implementation
There are various types of algorithms which can be used for directory
implementation. The selection of a suitable algorithm for directory
implementation is an essential task because it directly affects system
performance. The directory implementation algorithm depends upon
the data structure.
o Hash Table
Directory Implementation
Linear List:
It is the most straightforward algorithm used for directory
implementation. All the files in a directory are kept 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. It requires a costly
search on large directories
Directory Implementation
Hash Table
There are some disadvantages in singly linked implementation of
directories. To remove this drawback, another method called a hash table is
used. In this method, the hash table is used with the linked list.
In a linear list, we have to search the entire list, but in hash table the
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 Implementation
Summary
A Directory is considered as a file that contains information about the
other files and directories. It keeps the entry of a group of all the related
files and also the information like file names, types, location, etc.
The single-level directory has only one root directory and no user is
allowed to create subdirectories inside the root directory.
The two-level directory allows the user to create a directory inside the
root directory but do not allow creating further subdirectories.