Document from 🤌🏽

11.2 File-System Implementation

Overview of File-System Operations

File systems utilize both on-disk and in-memory structures that vary with the OS and file system. General principles apply, covering:

  • Location of free blocks

  • Total number of blocks

  • Directory structure

  • Information about individual files

Key File-System Structures

  • Boot Control Block (BCB): Contains info to boot the OS, usually in the first block (boot block in UFS; first sector in NTFS).

  • Volume Control Block (VCB): Holds details like number of blocks, block size, free block count, etc. In UFS, called a superblock; in NTFS, it is in the master file table.

  • Directory Structure: Organizes files in the system; in UFS, includes file names and inode numbers; in NTFS, within the master file table.

  • File Control Block (FCB): Details about each file like permissions, ownership, size, and data blocks location. In UFS, it's called an inode; in NTFS, part of the master file table.

In-Memory Structures for Performance

File system management and performance improvement through caching occurs at mount and dismount times. Key in-memory structures include:

  • Mount Table: Info about each mounted volume.

  • Directory Structure Cache: Holds recent directory data and pointers.

  • System-Wide Open-File Table: Copies of PCB for open files.

  • Per-Process Open-File Table: Points to the system-wide table and includes file location and access mode.

Creating and Managing Files

To create a file, an application calls the logical file system which allocates or uses a pre-allocated FCB, updates the directory in memory, and writes it to disk. Typical FCB includes:

  • Permissions

  • Data (creation/access/write times)

  • File size

  • Data block pointers

Some OSs, like UNIX, treat directories as files, allowing for similar operations.

Opening Files

The open() system call searches the system-wide open-file table. If found, a per-process entry points to this table, copying the relevant FCB. Upon closing a file, the per-process entry is removed, and if all processes close it, metadata is updated, removing the system-wide entry.

Caching in File Systems

Most systems cache information about open files (excluding data blocks) to optimize operations. For instance, the BSD UNIX system has a cache hit rate of 85%, illustrating efficiency.

Summary of File-System Structures

Figure 11.3 illustrates the relationship and flow between opened files, caches, and directory structures in file management operations.