Sunday, 20 December 2020

OS Directory Structure: Single Level, Two Level and Tree Structured Directories

 

v DIRECTORY STRUCTURE:

 

o   The file systems of computers can be extensive. Some systems store millions of files on terabytes of disc.  To manage all this data we need to organize them.  This organization is usually done in two parts.

 

o   First disks are split into one or more partition also known as ‘minidisks’ in the IBM world, for ‘volumes’ in the PC and Macintosh arenas.  Typically each disk on a system contains at least one partition which is a low level structure in which files and directories reside.

 

o   Sometimes partitions are also used to provide several separate areas within one disc each treated as a separate storage device whereas other system allows partitions to be larger than a disk to group disk into one logical structure.

 

o   Partitions can also store multiple OS allowing a system to boot and run more than one.

 

o   Second, each partition contains information about files within it.  This information is kept in entries in a device directory or volume table of contents.  The device directory records information such as name, location, size and type for all files on that partition.

 

o   The directory can be viewed as a symbol table that translates filenames into their directory entries.

Typical file system organization

(Typical file system organization)


o   When considering a particular directory structure, we need to keep in mind the operations that are to be performed on a directory:

 

1.    Search for a file:  we need to be able to search a directory structure to find the entry for a particular file.

2.    Create a file:  new files need to be created and added to the directory.

3.    Delete a file:  when a file is no longer needed we want to remove it from the directory.

4.    List a directory:  we need to be able to list the files in a directory and the contents of the directory entry for each file in the list.

5.    Rename a file:  because the name of a file represents its contents to its users, the name must be changeable when the contents or use of file changes.

6.    Traverse the file system: to access every directory and every file within a directory structure.

 

 

A] Single Level Directory Structure:

 

o   The simplest directory structure is the single level directory.

 

o   All files are contained in the same directory which is easy to support and understand.


Single level directory structure


o   A single level directory has significant limitations however, when the number of files increases or when the system has more than one user.

 

o   Since all files are in the same directory, they must have unique names. If two users call their data file ‘test’ then the unique name rule is violated.

 

o   The MS Dos OS allows only 11 character file names; UNIX allows 255 characters.


 

o   Even a single user on a single level directory may find it difficult to remember the names of all the files as the number of files increases.

 

o   It is not uncommon for a user to have hundreds of files on one computer system and an equal number of additional files on another system.  In such an environment, keeping track of so many files is a daunting task.

 

 B] Two Level Directory Structure:

 

o   A single level directory often leads to confusion of filenames between different users.

 

o   The standard solution is to create a separate directory for each user.

 

o   In two level directory structure, each user has her own user file directory (UFD).

 

o   Each UFD has a similar structure, but list only the files of a single user.

 

o   When a user job starts for a user logs in, the systems master file directory (MFD) is searched.

 

o   The MFD is indexed by username or account number. Different users may have files with the same name, as long as all the file names within each UFD are unique.

  

o   To create a file for a user, the OS searches only that user’s UFD to ascertain whether another file of that name exist.  To delete a file, the OS confines its search to the local UFD. Thus it cannot accidentally delete another user’s file that has the same name.

 

o   Although two level directory structure solve the name collision problem, it still has disadvantages.  This structure effectively isolates one user from another.  This isolation is an advantage when the users are completely independent but it is a disadvantage when the users want to co-operate on some task and to access one another’s file.

 

o   If access is to be permitted, one user must have the ability to name a file in another user’s directory.  To name a particular file uniquely in a two level directory, we must give both the username and the file name.


o   If two level directory can be thought of as a tree,   or at least an inverted tree of height 2.

 

o   The root of the tree is the MFD.  It's direct descendants are the UFD. The descendants of the UFDs are the files themselves.  The files are the leaves of the tree.

 

o   Specifying a username and a filename defines a path in the tree from the root to a leaf.  Thus, a username and a filename define a path name.  Every file in the system has a path name.  To name a file uniquely, a user must know the name of the file desired.

 

o   Every system has its own syntax for naming files in directories other than the user’s own. Additional syntax is needed to specify the partition of a file.

 

Two level directory structure


C] Tree Structured Directories:

 

o   MS DOS system for instance is structured as tree. A tree is the most common directory structure

 

o   The tree has a root directory.  Every file in the system has a unique path name.  A path name is the path from the root to all the subdirectories to a specified file.

 

o   A directory or subdirectory contains a set of files or subdirectories.

 

o   A directory is simply another file but it is treated in a special way.

 

o   All directories have the same internal format.

 

o   One bit in each directory entry define the entry as a file (0) or as a subdirectory (1).

 

o   Special system calls are used to create and delete directories.

 

o   In normal use each user has a current directory.  The current directory should contain most of the files that are of current interest to the user.

 

o   When the 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 must either specify a path name or change the current directory to the directory holding that file.

 

o   Path names can be of two types:  absolute path names are relative path names.

 

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

 

o   A relative path defines a path from the current directory.

 

o   An interesting policy decision in a tree structured directory is how to handle the deletion of a directory.  If the directory is empty its entry in its containing directory can simply be deleted.

 

o   However suppose the directory to be deleted is not empty but contains several files or subdirectories:  one of two approaches can be taken.  Some systems such as MS DOS will not delete a directory unless it is empty.  To delete a directory the user must first delete all the files in the directory.  If any subdirectories exist this procedure must be applied recursively so that they can be deleted also.  This approach may result in a substantial amount of work.

 

o   An alternative approach such as that taken by the Unix ‘rm’ command is to provide the option that when a request is made to delete directory all the directories files and subdirectories are also to be deleted.  Though this policy is easy but it is more dangerous because an entire directory structure may be removed with one command.

 

o   With a tree structured directory system users can access in addition to their files, the files of other users. For example user B can access files of user A by specifying their path names.

 

o   User B can specify either an absolute or relative path name.  Alternatively user B could change his current directory to be user A’s directory and access the files by their file names.


Tree Structured directory

(Tree structure directory)


No comments:

Post a Comment