Friday, August 3, 2007

Hard Disk Geometry Notes

Introduction and Road Map

All right, just to tell a little about myself, I'm a file system programmer (some call me a hacker, others call me a crack pot; the truth lies somewhere in between I suppose). I want to start a series of blog entries of "How to write a file system from scratch in the D Programming language", but I have to start small. Really small. So I will start with the geometry of the hard disk.

If all goes well, then the rough road map will be: introduction to Unix-like file systems, the Skelix file system, perhaps the Minix file system, the Fast File System (UFS), the ext2 file system, the ext3 file system, the ext4 file system, and the ZFS ("zeta byte file system"). Hopefully, I can pull off writing a ZFS clone or a file system superior to it. Ah, dare to dream!

Of course, perhaps I should be a little more specific: I will write a toy file system, then either hack it to make it better depending on the file system I just covered or I will write a completely new one from scratch. Of course, it will be in the D programming language ;)

Cylinder-Head-Sector Geometry

We need to begin with the fundamental part of the file system: the hardware. Without it, there is no need for a file system! It would be nice to discuss it first. The hardware, more specifically the hard disks, floppy disks, etc. that the file system keeps track of, has a sort of geometry to it.

The hard disks are actually a collection of magnetic plates, each plate has 2 sides called a head. Each head has grooves in it like a record, these grooves are called the track or the cylinders of the disk. The head is cut into pieces like a pie as well, each slice of the head is called a Sector.

That's the vocabulary lesson!

I'd hate to quote wikipedia, but I'm too lazy to discuss Cylinder-Head-Sector Addressing in detail:

The number of blocks on one side of a platter is:

blocksPerPlatterSide = (cylindersPerPlatter)*(SectorsPerPlatter)

The number of blocks per platter is:

blocksPerPlatter = (blocksPerPlatterSide)*(sidesUsedPerPlatter)

which is usually written in terms of the number of heads used:

blocksPerPlatter = (blocksPerPlatterSide)*(HeadsPerPlatter)

This is usually expanded to:

blocksPerPlatter =(cylindersPerPlatter)*(SectorsPerPlatter)*(HeadsPerPlatter)

and rearranged:

blocksPerPlatter =(cylindersPerPlatter)*(HeadsPerPlatter)*(SectorsPerPlatter)

Since all the platters are the same size and hard drives usually have more than one platter, the total number of blocks on the drive can be written as:

totalBlocks =(Cylinders)*(HeadsPerPlatter)*(Sectors)*(NumberOfPlatters)

If the number of platters is combined with the number of heads per platter to form the single parameter Heads, the equation can be written in its final form as:

totalBlocks = (Cylinders)*(Heads)*(Sectors)

The numbering for cylinders, heads, and sectors all begin at 0. There is a triple: (cylinder, head, sectors) that we use. Usually, it is given the number of sectors per track (A) and the number of heads per cylinder (B). The sectors component of the triple ranges from 0 to A-1. The head ranges from 0 to B-1. However the cylinder component is unbounded.

Logical Block Addressing ("LBA") Geometry

To contrast the cylinder-head-sector method, we can use a lazier approach: just count the 512 byte blocks from a given starting point (the so-called Boot Block)! So we would have block 0, block 1, ..., block N.

There is a reason this is called the Logical block addressing, and that's because it's completely logical rather than based on how the disks look, etc.

Vocabulary:

Block (aka Sector) is a 512 byte atom of disk space.

The hard disks are actually a collection of magnetic plates called a platter, each plate has 2 sides called a head. Each head has grooves in it like a record, these grooves are called the track or the cylinders of the disk. The head is cut into pieces like a pie as well, each slice of the head is called a Sector.

Note that: 1 byte = 8 bits,
1 kilobyte = 1024 bytes,
1 megabyte = 1024 kilobytes,
1 gigabyte = 1024 megabytes,
1 terabyte = 1024 gigabytes,
1 petabyte = 1024 terabytes,
1 exabyte = 1024 petabytes,
1 zettabyte = 1024 petabytes,
1 yottabyte = 1024 zettabyte.
And 1 bit is a "1-or-0" value!

1 comment:

Anonymous said...

good one