A directory is a container that is used to contain folders and files. It organizes files and folders in a hierarchical manner.
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:
Disadvantages:
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.
Advantages:
Disadvantages:
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.
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:
Disadvantages:
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.
Advantages:
Disadvantages:
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.
Advantages:
Disadvantages:
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:
When the file system is organized as a directory tree, some way is needed for specifying file names.
Two different methods are commonly used:
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.
10 videos|99 docs|33 tests
|
1. What is the purpose of directory structures in an operating system? |
2. What are the advantages of using directory structures in an operating system? |
3. Can directory structures be nested within each other? |
4. How does a directory path represent the location of a file? |
5. What happens if a file is moved within a directory structure? |
|
Explore Courses for Computer Science Engineering (CSE) exam
|