A disk driver interfaces with a disk, or disk partition, and presents the system with access to disk blocks 1 through N. The disk driver conceals the dirty details of accessing the underlying "device". Physical disks are accessed by Cylinder / Head / Sector (C/H/S) Changing Cylinders involved physical action, out in the Real World (sliding the arm carrying the read/write Heads in and out). The Heads "flew" over the disk platters. Changing Head took place at electronic speed, but Sector was a matter of waiting for the disk to revolve. Optimizations include sorting disk I/O by C/H/S, minimizing direction changes of the arm, chunking so you read/write ALL the Sectors under a single Head, buffering, ... Details differ among all disks and disk-like devices. Disk drivers make it possible for programs to ignore these details. All disk drives present Blocks 1 to N.
Disks are strictured by way of the GPT or older MBR. Each partition "looks" like a disk (Blocks 1 to N). Wikipedia explains more.
When a partition is "mounted", it is assigned a place in the Filesystem Hierarcy (man hier
), and it's filesystem consistency is checked, and if necessary, repaired.
A filesystem allocates these disk blocks(Blocks 1 to N), and keeps track in disk blocks it has allocated to itself (overhead blocks) using i-nodes
when one runs mkfs
to create the filesystem. Read man mkfs fsck
. The filesystem organizes blocks into "clusters" and "super clusters" for I/O optimization. All of the I/O (user data, fliesystem overhead) is buffered, and only periodically flushed to disk. The system can crash between the filesystem allocating blocks and the on-disk copy of the filesystem metadata, and become inconsistent. Filesystems use redundancy and journaling to avoid or. recover from inconsistency.
User programs can read/write files, in characters or blocks of (binary) data, according to access rules enforced by the system.
Every layer between the user and the hardware can be optimized (but do you want ALL the memory used for buffers?) without requiring changes in other layers. Blocks 1 to N.