0% found this document useful (0 votes)
92 views4 pages

1 Directory: First Part

Directories organize files in a hierarchical structure on disk partitions. A directory entry contains metadata about each file like its name, size, permissions. Directories can be implemented as linear lists or hash tables. Linear lists allow simple insertion and deletion but slow searches. Hash tables greatly speed up searches via a hash function but can have collisions. Backup and consistency checking ensure data integrity if the system fails.

Uploaded by

Ankit Garg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views4 pages

1 Directory: First Part

Directories organize files in a hierarchical structure on disk partitions. A directory entry contains metadata about each file like its name, size, permissions. Directories can be implemented as linear lists or hash tables. Linear lists allow simple insertion and deletion but slow searches. Hash tables greatly speed up searches via a hash function but can have collisions. Backup and consistency checking ensure data integrity if the system fails.

Uploaded by

Ankit Garg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 4

BHAVYA 21611827

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

● protection information etc..


The directory can be thought of as a symbol table that translates filenames into their directory
entries. The directory structure must be so designed so as to facilitate searching a file, creating a
file, deleting a file, listing of a directory, renaming a file, and traversing the file system.

1.2 Directory operations


A) Search for a file: we need to be able to search a directory structure to find the entry for a
particular file. Since files have symbolic names, and similar names may indicate a
relationship between files , we may want to be able to find all files whose names match a
particular pattern.
B) Create a file: this operation is used to create an empty directory. Note that an empty
directory is always containing .(dot) and ..(double dot). Which are put there automatically by
the system.
C) Delete a file: when a file is no longer needed, we want to be able to remove it from the
directory.
D) Rename a file: because the name of a file represents its contents or \to its users, we must be
able to change the name when the contents or use of the file changes. Renaming a file may
also allow its position within the directory structure to be changed.
E) Traverse the file system: we may wish to access every directory and every file within a
directory structure. For reliability, it is a good idea to save the contents and structure of the
entire file system at regular intervals. Often, we do this by copying all files to magnetic tape.
this technique provides a backup copy in case of system failure. In addition, if a file is no
longer in use, the file can be copied to tape and the disk space of that file released for reuse
by another file.

1.3 Directory implementation


The selection of directory-allocation and directory-management algorithms significantly affects the
efficiency, performance, and reliability of the file system. In this section we discuss the trade-off's
involved in choosing one if these algorithms.
1.3.1 Linear list

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

• Insertion and deletion are also fairly straight forward.


The major disadvantage of hash table is its fixed size and dependencies of hash function on the
size.
Alternatively, a chained-overflow hash table can be used. Each hash entry can be a linked list
instead of an individual value, and we can resolve collisions by adding the new entry to the linked
list. Lookups may be somewhat slowed, because searching for a name might require stepping
through a linked list of colliding table entries. Still, this method is likely to be much faster than a
linear search through the entire directory.

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

You might also like