Structures of Directory | Operating System - Computer Science Engineering (CSE) PDF Download

Structures of Directory in Operating System

A directory is a container that is used to contain folders and files. It organizes files and folders in a hierarchical manner.
Structures of Directory | Operating System - Computer Science Engineering (CSE)

There are several logical structures of a directory, these are given below: 

1. Single-level directory
The single-level directory is the simplest directory structure. In it, all files are contained in the same directory which makes it easy to support and understand.
A single level directory has a significant limitation, however, when the number of files increases or when the system has more than one user. Since all the files are in the same directory, they must have a unique name. if two users call their dataset test, then the unique name rule violated.

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 not have the same name. 
  • Searching will become time taking if the directory is large. 
  • This can not group the same type of files together. 

2. Two-level directory
As we have seen, a single level directory often leads to confusion of files names among different users. the solution to this problem is to create a separate directory for each user.
In the two-level directory structure, each user has their own user files directory (UFD). The UFDs have similar structures, but each lists only the files of a single user. system’s master file directory (MFD) is searches whenever a new user id=s logged in. The MFD is indexed by username or account number, and each entry points to the UFD for that user.
Structures of Directory | Operating System - Computer Science Engineering (CSE)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. 

3. Tree-structured directory  
Once we have seen a two-level directory as a tree of height 2, the natural generalization is to extend the directory structure to a tree of arbitrary height.
This generalization allows the user to create their own subdirectories and to organize their files accordingly.
Structures of Directory | Operating System - Computer Science Engineering (CSE)

A tree structure is the most common directory structure. The tree has a root directory, and every file in the system has a unique path. 

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. 

4. Acyclic graph directory
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. The associated files are stored in a subdirectory, separating them from other projects and files of other programmers since they are working on a joint project so they want the subdirectories to be into their own directories. The common subdirectories should be shared. So here we use Acyclic directories.
It is the point to note that the shared file is not the same as the copy file. If any programmer makes some changes in the subdirectory it will reflect in both subdirectories.
Structures of Directory | Operating System - Computer Science Engineering (CSE)

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. 

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.
Structures of Directory | Operating System - Computer Science Engineering (CSE)Advantages: 

  • It allows cycles. 
  • It is more flexible than other directories structure. 

Disadvantages:

  • It is more costly than others. 
  • It needs garbage collection. 

Path Name in File Directory

Hierarchical Directory Systems: Directory is maintained in the form of a tree. Each user can have as many directories as are needed so, that files can be grouped together in a natural way.

Advantages of this structure:

  • Searching is efficient
  • Groping capability of files increase

When the file system is organized as a directory tree, some way is needed for specifying file names.

Two different methods are commonly used:

  1. Absolute Path name: In this method, each file is given an absolute path name consisting of the path from the root directory to the file. As an example, the path /usr/ast/mailbox means that the root directory contains a subdirectory usr, which in turn contains a subdirectory ast, which contains the file mailbox.
    Absolute path names always start at the root directory and are unique.
    In UNIX the components of the path are separated by ‘/’. In Windows, the separator is ‘\’.
    Windows \usr\ast\mailbox
    UNIX /usr/ast/mailbox
  2. Relative Path name: This is used in conjunction with the concept of the working directory (also called the current directory).A user can designate one directory as the current working directory, in which case all path names not beginning at the root directory are taken relative to the working directory.
    For example, if the current working directory is /usr/ast, then the file whose absolute path is /usr/ast/mailbox can be referenced simply as mailbox.
    In other words, the UNIX
    command : cp /usr/ast/mailbox /usr/ast/mailbox.bak
    and the command : cp mailbox mailbox.bak
    do exactly the same thing if the working directory is /usr/ast.

When to use which approach?
Some programs need to access a specific file without regard to what the working directory is. In that case, they should always use absolute path names. For example, a spelling checker might need to read /usr/lib/dictionary to do its work. It should use the full, absolute path name in this case because it does not know what the working directory will be when it is called. The absolute path name will always work, no matter what the working directory is.
Of course, if the spelling checker needs a large number of files from /usr/lib, an alternative approach is for it to issue a system call to change its working directory to /usr/lib, and then use just dictionary as the first parameter to open. By explicitly changing the working directory, it knows for sure where it is in the directory tree, so it can then use relative paths.

The document Structures of Directory | Operating System - Computer Science Engineering (CSE) is a part of the Computer Science Engineering (CSE) Course Operating System.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)
10 videos|99 docs|33 tests

Top Courses for Computer Science Engineering (CSE)

FAQs on Structures of Directory - Operating System - Computer Science Engineering (CSE)

1. What is the purpose of directory structures in an operating system?
Ans. Directory structures in an operating system are used to organize and manage files and folders. They provide a hierarchical structure that allows users to easily navigate and locate specific files or directories. Additionally, directory structures help to ensure efficient storage allocation and file access.
2. What are the advantages of using directory structures in an operating system?
Ans. There are several advantages of using directory structures in an operating system. Firstly, they help to organize and categorize files, making it easier for users to locate and manage them. Secondly, directory structures provide a logical and hierarchical representation of the file system, which aids in efficient file storage and retrieval. Lastly, directory structures allow for the implementation of access controls and permissions, ensuring data security and privacy.
3. Can directory structures be nested within each other?
Ans. Yes, directory structures can be nested within each other. This means that a directory can contain subdirectories, and these subdirectories can further contain additional subdirectories and files. This nesting capability allows for the creation of complex and organized file systems, where files are grouped together based on their relationships or similarities.
4. How does a directory path represent the location of a file?
Ans. A directory path represents the location of a file within a directory structure. It consists of a sequence of directory names separated by a delimiter (such as a forward slash or backslash). The path starts from the root directory and includes all the directories and subdirectories that need to be traversed in order to reach the desired file. By following the directory path, the operating system can locate and retrieve the file accurately.
5. What happens if a file is moved within a directory structure?
Ans. When a file is moved within a directory structure, its location or path is updated accordingly. The operating system updates the file's metadata to reflect the new directory path. This ensures that the file remains accessible and can be located using the updated path. If any programs or processes were referencing the file using its old path, they would need to be updated to use the new path in order to access the file correctly.
10 videos|99 docs|33 tests
Download as PDF
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

shortcuts and tricks

,

Previous Year Questions with Solutions

,

Objective type Questions

,

Exam

,

past year papers

,

ppt

,

mock tests for examination

,

Sample Paper

,

Extra Questions

,

video lectures

,

pdf

,

Structures of Directory | Operating System - Computer Science Engineering (CSE)

,

Important questions

,

practice quizzes

,

Structures of Directory | Operating System - Computer Science Engineering (CSE)

,

Free

,

Summary

,

Semester Notes

,

MCQs

,

study material

,

Structures of Directory | Operating System - Computer Science Engineering (CSE)

,

Viva Questions

;