File Storage and Access Methods in Operating Systems

Physical Storage of Information

Magnetic Tape

Early operating systems used magnetic tape for file management. Magnetic tape offers advantages in cost and storage capacity but only allows sequential access, resulting in increased access time. Currently, magnetic tapes are primarily used for backups and disk mirroring operations.

Physical Records and Blocks

The hardware storage device determines the size of the basic unit of information transferred during read/write operations. This unit, called a physical record or block, corresponds to a sector on a disk. Users manage information in logical units of varying sizes called logical records, depending on the application and archiving needs.

Disk Storage Management

When a user creates a file, the file subsystem allocates the necessary space. It tracks the total available space and reclaims space when files are deleted. This storage management aims to:

  1. Ensure efficient use of storage space.
  2. Enable fast access to stored information.

Linked Allocation

In this non-contiguous allocation method, each file is a linked list of disk blocks that can be scattered across the disk. The directory entry for each file contains a pointer to the first block in the chain. Each block then points to the next one in the sequence.

Advantages:

  • No external fragmentation.
  • Files can grow dynamically without pre-allocation.
  • Facilitates sequential access.

Disadvantages:

  • Inefficient for random access due to pointer traversal.
  • Vulnerable to data loss if a pointer is corrupted. Double chaining (forward and backward pointers) can improve reliability but increases overhead.

Indexed Allocation

This method addresses the drawbacks of linked allocation by using an index block for each file. The directory entry points to the index block, which contains pointers to the file’s data blocks.

Advantages:

  • No external fragmentation.
  • Faster random access compared to linked allocation.

Disadvantages:

  • Index block size can limit file size.
  • Requires two disk accesses for data retrieval (index block + data block).

Access Methods

An access method is a set of routines and tables that enable accessing file information according to a specific logical schema.

Sequential Access

Records are accessed in a fixed order, one after another. This method requires logical and physical order to match. It is simple to implement and efficient for processing records in a predetermined order but can be inefficient for updates and random access.

Direct Access

Allows accessing a specific record without traversing preceding ones. The access method calculates the physical address of the desired block. Methods for finding a block include:

  1. Block number.
  2. Key-based search.
  3. Hashing.

Indexed Direct Access

An index table maps keys to physical block addresses. To locate a record, the index is consulted to find the corresponding block. Large files can utilize a hierarchical index structure (master index pointing to secondary indexes) for efficient searching.