As already stated in the previous article, the file system consists of two distinct parts: a collection of files, each storing related data, and a directory structure, which organises and provides information about all the files in the system.
Now, a disk or a partition containing a file system is generally known as a volume and each volume can be thought of as a virtual disk. Furthermore, each volume that contains a file system must also contain information about all the files in the system. This information is kept in the form of entries in a directory or folder. The directory, as stated above, records information—such as name, location, size, and type—for all files on that volume. Simply put, a directory is like a container for organising all the files in the file system by name or a file containing the information about all the other files on the system.
Operations on Directory
In order to organise the files in a more efficient manner, the user should be allowed a number of operations. Given below are the operations that can be performed on a directory:
- Search for a file: A directory structure can be searched to find the entry for a particular file.
- Create a file: New files can be created and added to the directory.
- Delete a file: When a file is no longer needed, it can be removed or deleted from the directory.
- List a directory: The list of all the files in a directory as well as the contents of the directory entry for each file in that list can be retrieved.
- Rename a file: Because the name of a file represents its contents to its users, it can be renamed when the contents or use of the file changes. Renaming a file may also allow its position within the directory structure to be changed.
- Traverse the file system: For reliability, it is a good idea to save the contents and structure of the entire file system at regular intervals. Often, this can be done by copying all the 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.
Types of Directory Structure
Given below are the most common schemes for defining the logical structure of a directory:
- Single-Level Directory
This structure is the simplest directory structure as all the files are contained in a single directory called the root directory, making it easy to support and understand.
However, a major disadvantage may occur when the number of files increases or when the system has more than one user due to the fact that all the files must have unique names since they are all in the same directory. For example, two users would not be able to name both their résumé files as ‘resume.pdf’.
2. Two-Level Directory
As a single-level directory often leads to confusion of file names among different users, two-level directory provides a solution to this problem by creating a separate directory for each user. In this structure, each user has its own directory known as a user file directory (UFD). Although the UFDs have similar structures, but each lists only the files of a single user.
When a user logs in, the system’s master file directory (MFD) or the root directory, which is indexed by user name or account number is searched. Following which, when a user refers to a particular file, only his own UFD is searched. Thus, different users may have files with the same name, as long as all the file names within each UFD are unique.
However, this structure effectively isolates one user from another and can be a disadvantage when the users want to cooperate on some task or access one another’s files. Moreover, a subdirectory cannot be further created under the UFDs.
3. Tree-Structured Directory
To better understand this structure, let us consider the two-level directory as an inverted tree, with the root of the tree being the master file directory (MFD). Its direct descendants being the user file directories (UFDs) and the descendants of the UFDs being the files which can further be considered as the leaves of the tree. Now, in order to access a particular file, we must specify the user name and the file name which will define a path in the tree, from the root (the MFD) to a leaf (the specified file).
The tree-structured directory thus simply extends the height of the two level directory tree arbitrarily. It is the most common directory structure, containing a root directory and a set of subdirectories or files, with unique path name to every file (leaves) in the system.
4. Acyclic-Graph Directories
An acyclic graph, that is, a graph with no cycles, allows directories to share subdirectories and files, for example, two users working on a project together can have a common subdirectory shared between them in addition to their own user directories. In other words, a shared directory or file exists in the file system in two (or more) places at once.
With a shared file, only one actual file exists, so any changes made by one person are immediately visible to the other; for example, a new file created by one person will automatically appear in all the shared subdirectories. Although an acyclic-graph directory structure is more flexible than a simple tree structure, yet it is also more complex. A major problem would be the possibility of files now having multiple path names.
Leave a Reply