Skip to content

Directory Management

Directory management is an important part of the file system. It is responsible for organizing and managing the structure of files so that users can access files conveniently and efficiently. The design of directory management directly affects file retrieval, sharing and system performance.

Specific requirements for directory management

  1. Achieve access by name:
  2. Users can access files by file name without worrying about the physical storage location of the file.

  3. Improve the speed of retrieving directories:

  4. The directory structure and the organization of files should help to find files quickly and reduce search time.

  5. Achieve file sharing:

  6. Allow multiple users or applications to share the same file and ensure the security of file access.

  7. Allow duplicate file names:

  8. Files in different directories can have the same name, but the file name must be unique in the same directory.

File directory

  • File control block (FCB):
  • The file control block is a data structure used in the file system to describe file attributes and storage information.
  • Each file corresponds to a file control block, which contains relevant information about the file, such as file name, attributes, physical storage location, etc.
  • The file directory is a list of multiple file control blocks.

  • MS-DOS file control block structure:

  • The file control block in MS-DOS contains the following fields:
  • File name: primary file name (up to 8 characters).
  • Extension: file extension (up to 3 characters).
  • Attribute: file attribute information (such as read-only, hidden, system file, etc.).
  • Backup: backup field, used internally by the system.
  • Time: time when the file was created or modified.
  • Date: date when the file was created or modified.
  • First block number: starting block number of file storage.
  • Total number of blocks: total number of blocks occupied by the file.

Directory structure type

Directory structure mainly includes the following types:

1. First-level directory structure

  • Features:
  • All files are registered in a global directory table, and each file occupies one of the directory entries.
  • Only simple access by name can be achieved, and complex directory management is not supported.

  • Schematic diagram:

    First-level directory structure:
    [Root directory]
    └── File 1
    └── File 2
    └── File 3
    

2. Second-level directory structure

  • Features:
  • Consists of a master file directory (MFD) and multiple user file directories (UFD).
  • The master file directory stores user account information and points to the user file directory of each user.
  • The user file directory contains the control blocks of all files of the user.

  • Schematic diagram:

    Secondary directory structure:
    [Master File Directory (MFD)]
    ├── User A's UFD
    │ └── File A1
    │ └── File A2
    ├── User B's UFD
    │ └── File B1
    │ └── File B2
    

3. Tree directory structure

  • Features:
  • The tree structure supports multi-level directory management, forming a hierarchy of root directories, subdirectories, and files.
  • The path of a file can be absolute path or relative path:
  • Absolute path: Starting from the root directory, all the way to the full path of the target file.
  • Relative path: The path based on the current working directory, excluding the root directory part.

  • Schematic diagram:

    Tree directory structure:
    [Root directory]
    ├── User A
    │ └── Document
    │ └── File A1
    │ └── File A2
    ├── User B
    │ └── Picture
    │ └── File B1
    │ └── File B2
    

Summary

Directory management plays a key role in the file system. Through reasonable directory structure design, file access efficiency and user experience can be improved. According to system requirements and application scenarios, it is crucial to choose a suitable directory structure:

  • First-level directory structure is suitable for simple single-user systems.

  • Second-level directory structure is suitable for multi-user systems and provides basic isolation and management functions.

  • Tree directory structure is suitable for complex file systems and multi-user environments. It is the most common directory management structure in modern operating systems.