You are on page 1of 27

DIRECTORY

STRUCTURE

DIRECTORY STRUCTURE

A directory groups the files owned by a user.


It contains information like file attributes,its location and its
ownership
It can be viewed as a symbol table that translates the
filenames into their directory entries

Operations Performed on Directory

Search for a file


Create a file
Delete a file
List a directory
Rename a file:- name of the file represent the
content in it
Traverse the file system:-access every directory &
every file within a directory structure

Logical Directory Organization -Goals

Efficiency locating a file quickly

Naming convenient to users


Two users can have same name for different files
The same file can have several different names

Grouping logical grouping of files by properties, (Ex:all


Java programs, all games, )

Types Of Directory Structures

Single-level Directory

Two-level Directory

Tree-Structured Directories

Acyclic-Graph Directories

General-Graph Directory

Single-Level Directory(flat directories)


The simplest directory structure is the single-level directory.
All the files are contained in the same directory
A single flat directory can contain list of all files in the system
Flat directories are those directories in which root directory contains all
system files and there is no other subdirectories

Cat,bo,
are file names

<--Actual
data for files

Limitations
As the number of files increases, difficult to remember unique names

Even a single user on a single -level directory may find it difficult to


remem-ber the names of all the files, as the number of files increases

Two Level Directory

Introduced to remove naming problem between users


First Level contains list of user directories
Second Level contains user files
Need to specify Path name
Can have same file names for different users.
System files kept in separate directory or Level 1.
Efficient searching

Each user has his own user file directory(UFD).


When user logs in systems master file directory(MFD) is searched.
The MFD is indexed by user name, and each entry points to the UFD
for that user.

Advantage:

Isolation is an advantage when the


users are completely independent.

Disadvantage:

When the users want to cooperate


on some task and to access one
anothers files.

If a user has to access a file of another users directory,


then he has to specify the user name and file name.
A two-level directory can be thought of as a tree. The root
of the tree is MFD. Its direct descendants are the UFDs. The
descendants of the UFDs are the files themselves. The files
are the leaves of the tree.
Specifying a user name and a file name defines a path in
the tree from the root (the MFD) to a leaf (the specified
file).Thus user name and file name specifies a path name.
A user must know the path name of desired file.

Tree structured Directories(Hierarchial


directory structure)

When hierarchical directories are used, collection of directories and


subdirectory entries define the totality of system files

This allow the users to create their own subdirectories and


to organize their files accordingly.

directory

Root directory

file

D1
f1

D2
D21

D3
f21

d31

f8

f10

f7

When reference is made to a file, the current directory is searched.


If a file is needed that is not in the current directory, then the user
usually must either specify a path name or change the current
directory to be the directory holding that file.

To change directories, a system call is provided that takes a


directory name as a parameter and uses it to redefine the current
directory

Path names are of two types:

Absolute:
An absolute path name begins at the root and follows a
path down to the specified file, giving the directory names on the
path.

Relative:
a relative path name defines a path from the current
directory.

Deletion of a Directory:

If a directory is empty, it can be simply deleted. If a


directory is to be deleted which is not empty and it contain
several files or subdirectories, one of the two approaches
can be taken.

Some system will not delete directory unless it is empty.


Thus for deleting such directories the user has to delete all
files inside that directory. This can result in substantial
amount of work.

When request is given to delete a directory, all that


directorys file and subdirectories are also deleted.
Either approach is fairly easy to implement. The latter policy is
more convenient, but it is also more dangerous, because an entire
directory structure can be removed with one command. If that
command is issued in error, a large number of files and directories
will need to be restored.

Acyclic Graph Directories

A tree structure prohibits the sharing of files or directories.Acyclic


graphs allow sharing of subdirectories and files

An acyclic graph, that is, a graph with no cycles

Implementation by links
Links are pointers to other files or subdirectories
Symbolic links or relative path name
Directory entry is marked as a link and name of real
file/directory is given. Need to resolve link to locate file.

Implementation by shared files


Duplicate information in sharing directories
Original and copy indistinguishable
Need to maintain consistency if one of them is modified

Naming : File may have multiple absolute path names

Two different names for the same file


Traversal
ensure that shared data structures are traversed only once
Deletion
Removing file when someone deletes it may leave dangling
pointers.
Preserve file until all references to it are deleted
Keep a list of all references to a file or
Keep a count of the number of references - reference count.
When count = 0, file can be deleted.

Shared

files or directories are not 2


copies of the same , because with 2
copies each user can view and use
the copy but whenever a change is
made by a user it is not reflected in
the others copy
The method to implement shared
files is that create the file and create
a new directory entry called link ,
which effectively points to the

General Graph Directory

It allows cycles in directory structure

ie, one link

is pointing to the same file or directory


So whenever we traverse through the file system we must avoid

searching any component twice


For that complex algorithms are needed and if the algorithm is

poorly designed it causes an infinite search

The link count may not be zero when a cycle is present so we cant
delete a file

To avoid this problem use GARBAGE COLLECTION


It involves traversing the file system and mark all files that are

non accessible and remove them


It is a costly process because traversing is through a secondary

storage

General Graph Directories

You might also like