• Operating System Video Tutorials

Structures of Directory in Operating System



A directory in operating system is a special type of container/folder which is used to store multiple files and folder in an organized manner. Or we can say that it serves as a container that can hold both files and other directories (subdirectories), creating a hierarchical organization. Directories help users and programs efficiently access, store, and organize data on storage devices like hard drives or SSDs. The hierarchical structure of directories starts from a root directory, making it easier to locate files and maintain order in the file system.

What is Structure of Directory in Operating System?

The structure of a directory in an operating system refers to the way files and directories are organized within the file system. It defines how data is stored, accessed, and managed on a storage device. A well-designed directory structure ensures efficient file organization, easy navigation, and scalability for growing data. Common directory structures include single-level, two-level, hierarchical, and graph-based systems, each catering to different needs and complexity levels. The choice of structure directly impacts the performance and usability of the operating system.

Type of Directory Structure

Operating System provide various type of directory structures and they are:

  • Single-Level Directory

  • Two-Level Directory

  • Tree Structure or Hierarchical Structure

  • Acyclic Graph Structure

  • General-Graph Structure

Single-Level Directory

A single-level directory is the simplest type of directory structure in an operating system. In this structure, all files are stored in a single directory, and there are no subdirectories. Both users and the system share the same directory space.

Features of Single Level Directory

  • Every file is stored at the same level.

  • There is no hierarchy or grouping of files.

  • Files are identified by unique names.

Two-Level Directory

A two-level directory structure is a step up from the single-level directory and provides a basic separation of files for different users. In this structure, there is a master directory (or root directory) that contains separate user directories, and each user directory stores the files specific to that user. This approach resolves some of the issues of the single-level directory, such as name conflicts and lack of organization, by isolating files for each user.

Features of Two-Level Directory

  • Each user has their own directory, ensuring file organization and privacy.

  • File names only need to be unique within a user's directory, not across the entire system.

  • Permissions can be set at the directory level to restrict access to files between users.

  • Files are logically grouped under user directories, providing better scalability and management.

  • A single master directory keeps track of all user directories.

Tree Structure or Hierarchical Structure

A tree structure or hierarchical directory structure is a widely used directory organization system in modern operating systems. In this structure, directories are organized in a tree-like hierarchy, with a root directory at the top and subdirectories branching out beneath it. Each directory can contain files and other directories (subdirectories), allowing for efficient organization and scalable storage. This structure is particularly useful for multi-user systems or systems with a large number of files, as it supports logical grouping, ease of navigation, and modular organization.

Features of Tree Structure or Hierarchical Structure

  • All files and directories are organized under this root.

  • Directories within directories, allowing for a deeper level of organization.

  • Files and directories can be accessed using absolute paths (starting from the root) or relative paths (based on the current directory).

  • Related files are stored within the same directory or subdirectory, enabling better organization.

  • Permissions can be assigned to individual directories or files, controlling who can read, write, or execute them.

  • The structure can grow dynamically, allowing for efficient organization as the number of files increases.

Acyclic Graph Structure

The acyclic graph structure is an advanced directory organization system used in operating systems to allow files and directories to belong to multiple parent directories. It is an extension of the tree structure, but unlike a strict tree, it permits shared subdirectories or files by using links. This creates a directed acyclic graph (DAG), where there are no cycles, and each file or directory can be accessed from multiple paths. This structure is commonly used in systems where file sharing and efficient data organization are important. It enables multiple users or programs to share the same files without duplicating them.

Features of Acyclic Graph Structure

  • Files or directories can belong to more than one parent directory through links (e.g., symbolic links in Unix/Linux or shortcuts in Windows).

  • The structure ensures that there are no loops or circular references, which could lead to infinite navigation.

  • Allows users to share files and directories without duplication, saving storage space.

  • Enables logical grouping and reuse of files across different locations.

  • Files and directories can be accessed via multiple paths, offering flexibility for users and programs.

  • Avoids duplication of data by using links instead of creating separate copies of shared files.

General-Graph Structure

The general-graph directory structure is a more flexible and complex directory organization system that allows files and directories to be connected in any arbitrary manner. Unlike the acyclic graph structure, it does not restrict connections to being acyclic, meaning cycles (loops) are allowed in this structure. This flexibility enables files and directories to have multiple parent directories or relationships, providing powerful sharing and organization capabilities. However, this structure introduces challenges such as managing cycles and ensuring efficient navigation and access control. It is rarely used in practice due to these complexities and is more of a theoretical concept or used in specialized systems.

Features of General-Graph Structure

  • Files and directories can have multiple links (hard or symbolic), with no restriction on forming loops.

  • Files and subdirectories can be shared across multiple parent directories, allowing efficient reuse without duplication.

  • The system uses reference counting to track how many directories or files point to a given file or directory.

  • Multiple paths can lead to the same file or directory, enhancing access options.

  • The presence of cycles can complicate directory traversal, requiring algorithms to detect and handle loops to prevent infinite navigation.

  • Allows complex relationships between files and directories.

Advertisements