You are on page 1of 15

1

• Content: Directory Structure in OS


• Overview of Directory Structure
Several users create thousands and millions of files in a file
system. To organize these files properly file system
uses directory structure
• Types of Directory Structures
1. Single-level directory
2. Two-level directory 
3. Tree-structured directory
4. Acyclic graph directory 
5. General graph directory
2

Overview of Directory Structure

• A File system contains thousands and millions of files, owned by several users.
The directory structure organizes these files by keeping entries of all the
related files. The file entries have information like file name, type, location, the
mode in which the file can be accessed by other users in the system.
• The two important features that must be taken care while maintaining a
directory are given below.
• 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.
• 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 search for the file’s entry in the
directory and when the match is found, it obtains the file’s location from there.
3

THE ABOVE FIELDS

 File name:- contains the name of the concerned file in the directory,


 Type field :- indicates the kind or category of the file,
 Location Info field:- indicates the location where the file is stored.
Protection Info field :- contains the information whether the file can be accessed by
the other user in the system or not.
  Flag field:- contains the kind of directory entry like value D in Flag field indicates
that the file is a directory, value L indicates that the file is a link, value M indicates that
the file is a mounted file system.
 Misc. info filed:- in the directory contains the miscellaneous information about the
owner of the file, the time of its creation, the time at which the file was modified last.
4

Types of Directory Structures

• In this section, we will be discussing the most


common types of directories, their benefits and
drawbacks.
1. 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.
5

• 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.
6

Advantages and Disadvantages of


Single-level directory structure
• Advantages: 
• Since it is a single directory, so its implementation is very easy.
• If the files are smaller in size, searching will become faster.
• The operations like file creation, searching, deletion, updating
are very easy in such a directory structure.
• Disadvantages:
• There may chance of name collision because two files can have
the same name.
• Searching will become time taking if the directory is large.
• This can not group the same type of files together.
7

2. Two-level directory structure


In Two-level directory structure, the users create
directory directly inside the root directory. But once a
user creates such 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. This two-level structure allows
each user to keep their files separately inside their own
directory. This structure allows to use the same name for
the files but under different user directories.
8

Advantages and Disadvantages of


Two-level directory structure
• Advantages: 
• We can give full path like /User-name/directory-name/.
• Different users can have the same directory as well as the
file name.
• Searching of files becomes easier due to pathname and
user-grouping.
• Disadvantages:
• A user is not allowed to share files with other users.
• Still, it not very scalable, two files of the same type
cannot be grouped together in the same user. 
9

3. Tree Directory Structure


• In a tree directory structure, except root directory, every
directory or file has only one parent directory. So,
there is a total separation between the users which
provide complete naming freedom. Here, if a user
wishes to access another users file, it has to go through
two or more directories.
10

Advantages and Disadvantages of


Tree Directory Structure

• Advantages: 
• Very general, since full pathname can be given.
• Very scalable, the probability of name collision is less.
• Searching becomes very easy, we can use both absolute
paths as well as relative.
• Disadvantages: 
• Every file does not fit into the hierarchical model, files
may be saved into multiple directories.
• We can not share files.
• It is inefficient, because accessing a file may go under
multiple directories. 
11

4. Acyclic-Graph Directory Structure

• An acyclic graph is a graph with no cycle and allows us to share


subdirectories and files. The same file or subdirectories may be
in two different directories. It is a natural generalization of the
tree-structured directory. 
• It is used in the situation like when two programmers are
working on a joint project and they need to access files.
• In the diagram below you can see that the directory having file
F7 and F8 have two parent directories
12

Advantages and Disadvantages of


Acyclic-Graph Directory Structure
• Advantages: 
• We can share files.
• Searching is easy due to different-different paths.
• Disadvantages:
• We share the files via linking, in case deleting it may
create the problem,
• If the link is a soft link then after deleting the file we
left with a dangling pointer.
• In the case of a hard link, to delete a file we have to
delete all the references associated with it. 
13

5. General graph directory structure

In general graph directory structure, cycles are allowed within a


directory structure where multiple directories can be derived from
more than one parent directory. 
The main problem with this kind of directory structure is to
calculate the total size or space that has been taken by the files and
directories. 
14

Advantages and Disadvantages of


Tree Directory Structure
• Advantages: 
• It allows cycles.
• It is more flexible than other directories structure.
• Disadvantages:
• It is more costly than others.
• It needs garbage collection
15

END OF SLIDE
Thanks for your time.

You might also like