File Structure - aryanjoshi0823/5143-Operating-System GitHub Wiki

In operating systems, the file system provides a structured way to store, organize, and manage files on storage devices. The file structure within a file system represents how files and directories are organized and accessed.


File Structure in File Systems

  1. Hierarchical Structure (Tree-Based Model)

    • The most common file structure resembles a tree, where directories (folders) act as nodes and files are the leaves.
    • The root directory (/ in Unix/Linux or C:\ in Windows) is the starting point.
    • Directories can contain other directories (subdirectories) and files.

    Example:

    /
    ├── home
    │   ├── user
    │   │   ├── documents
    │   │   │   └── resume.docx
    │   │   └── music
    │   │       └── song.mp3
    ├── etc
    │   └── config.conf
    └── var
        └── log
            └── system.log
    
  2. Flat Structure

    • All files exist at the same level, and there is no hierarchy.
    • This was common in older operating systems but is not scalable for modern systems.

    Example:

    file1.txt
    file2.txt
    file3.txt
    
  3. Relational Structure

    • Used in some databases where files are managed as relations (tables).
    • Each file can have metadata and attributes.
  4. Graph Structure

    • A more flexible structure where files or directories can have multiple parents, creating a Directed Acyclic Graph (DAG).
    • Common in systems that support symbolic links or shortcuts.
  5. Layered Structure

    • Layers abstract the file operations, ensuring consistent access regardless of the underlying file system type.
    • Example: Virtual File System (VFS) in Linux.

Key Components of File Structures

  1. Files: Contain data or information (text, images, programs, etc.).
  2. Directories: Containers that hold files and other directories.
  3. Root Directory: The top-most directory in the hierarchy.
  4. Metadata: Includes file name, type, size, permissions, creation/modification time, etc.
  5. Links:
    • Hard Links: Multiple directory entries that refer to the same file.
    • Soft Links (Symbolic Links): Pointers to another file or directory.

Common File Systems

  1. Windows: FAT32, NTFS
  2. Unix/Linux: EXT3/EXT4, Btrfs, XFS
  3. MacOS: APFS, HFS+
  4. Network File Systems: NFS, SMB/CIFS