1 Directory: First Part
1 Directory: First Part
1 DIRECTORY
1.1 Introduction
A directory is a location for storing files on your system. Directories are found in a hierarchical file
system, such as LINUX , MS-DOS, OS/2 and UNIX. Thus, a directory is a list of files. The file
systems store millions of files on disk. To manage all these files, we have to organize them. The
organization is done in two parts:
First part:
Disks are split into one or more partitions, known as mini disks or volumes.
Typically, each disk on a system contains at least one partition which is a low-level structure in
which files and directories reside.
Sometimes, partitions are used to provide several separate areas within one disk, each treated as
separate storage device.
Some systems allow to be larger than a disk to group disks into one logical structure. Therefore, the
user needs to be concerned with only the logical
directory and file structure and can ignore completely the problems of physically allocating space
for files. For this reason, partitions can be thought of virtual disks.
Second part:
Each partition contains information about files in a device directory. This information is kept in
entries in directory.
A typical directory entry may contain the information like:
● File name
● file type
● address
● current length
● maximum length
● date last accessed
● date last updated
● owner id
1
BHAVYA 21611827
1
BHAVYA 21611827
The simplest method of implementing a directory is to use a linear list of file names with pointers of
the data blocks. This method is simple to program but time-consuming to execute. To create a new
file, we must first search the directory to be sure that no existing file has the same name. Then, we
add new name at the end of the directory. To delete a file, we search the directory for the named file
and then release the space allocated to it. To reuse the directory entry, we can do one of several
things. We can mark the entry as unused (by assigning it a special name, such as an all-blank name,
or with a used-unused bit in each entry), or we can attach it to a list of free directory entries. A third
alternative is to copy the last entry in the directory into the freed location and to decrease the length
of the directory. A linked list can also be used to decrease the time required ti delete a file.
Main disadvantage of a linear list of directory entries is the linear search to find a file some
solutions of this problem are:
a) sorting the list makes searches faster by using binary search, at the expense of more complex
insertions and deletions.
b) A linked list makes insertions and deletions into a sorted list easier, with overhead for the
links.
c) More complex data structures, such as B-tress, could also be considered.
1.3.2 Hash table
Another data structure used for a file directory is a hash table. With this methid, a linear list stores
the directory entries,but a hash data structure is also used. The hash table takes a value computed
form the file name and returns a pointer to the file name in a linear list. Therefore, it can greatly
decrease the directory search time. Insertion and deletion are also fairly straightforward, althogh
some provision must be made for collisions-- situations in which two file names hash to the same
location.
Characteristics of hashing function:
• It should quickly compute the address
• It should avoid collision
• It should evenly distribute the records to the available space.
Main advantages of this method are:
• It can greatly decrease the directory search time.
1
BHAVYA 21611827
1.4 Recovery
Files and directories are kept both in main memory and on disk, and care must be taken to ensure
that a system failure does not result in loss of data or in data inconsistency. There are two
commonly used methods of this problem are:
i. Consistency checking
ii. Backup and restore
1.4.1 Consistency checking
A directory information is kept in main memory to speed up access. The directory
information in main memory is up to date as compare to the corresponding
information on disk, because the write of cached directory information to disk does
not occur necessarily as the updation of directory takes place.
Whwnever