-
Notifications
You must be signed in to change notification settings - Fork 0
Hard Disk Geometry Notes
This is a draft of a post I am working on...so it's probably a bit rough and choppy.
A good, old fashioned hard disk consists of cylinders of magnetic plates. Each cylinder is like a wedding cake: they consist of stacks of plates.
Each plate has 2 sides called "heads".
Each head has grooves in it forming concentric circles. Each circle is called a "track" or "cylinder" of the disk.
The head is then cut into pieces like a pie, where each pie-slice is called a "sector".
A sector consists of a fixed amount of space. It is the "smallest storage unit" addressable by a hard drive. But the exact amount depends on the medium.
For example, hard drives and flash drives have 512-byte sectors, wherease CDs (and DVDs) have 2048-byte sectors.
Remark (Unix Terminology). It is not uncommon to run across the phrase "block" in Unix. The "block" refers to either a sector or a group of sectors. (End of Remark)
It is possible to address sectors using a triple (C, H, S)
which keeps
track of cylinder with index C
, and on that cylinder the head indexed
by H
, and then the slice S
.
These indices are numbered oddly. Both C
and H
begin at zero, but
S
begins with 1.
The sector (0, 0, 1)
is the master boot record (MBR). The MBR tells
the computer about the disk partitions, specifically how to boot up the
operating system.
Example (Brokenthorn). A 3.5-floppy disk has: 18 sectors per track, 80 tracks per head, 2 heads, and 1 cylinder. Hence there are a total of 160 tracks on a floppy disk. This gives us 2880 sectors. We get a grand total of: 1,474,560 bytes on the floppy disk (or 1440 kilobytes, or 1.40625 megabytes). Once upon a time, that was seen as all you'd ever need...
Puzzle. What's the smallest number of bits needed to address every sector of a floppy disk?
Solution. We need lg(2880)
bits, which is approximately 11.4918530963 bits;
so a 12-bit number would do it. (End of Example)
The structure for a classic generic MBR looks like:
Address | Description | Size in Bytes |
---|---|---|
0x000 |
Bootstrap code area | 446 |
0x1BE |
Partition Entry #1 | 16 |
0x1CE |
Partition Entry #2 | 16 |
0x1DE |
Partition Entry #3 | 16 |
0x1EE |
Partition Entry #4 | 16 |
0x1FE |
Magic Number | 2 |
What does a partition entry look like? Generically, it is:
Offset | Size | Description |
---|---|---|
0 | 1 byte | Boot indicator flag |
1 | 1 byte | Starting Head |
2 | 6 bits | Starting sector |
3 | 10 bits | Starting Cylinder |
4 | 1 byte | System ID |
5 | 1 byte | Ending Head |
6 | 6 bits | Ending Sector |
7 | 10 bits | Ending Cylinder |
8 | 4 bytes | Relative Sector (to start the partition) |
12 | 4 bytes | Total sectors in partition |
Rather than using an ordered triple to address a sector, it would be better to use a single number. As we saw, we needed 12 bits to label each sector on a floppy disk, but can we translate any given 12-bit number into a CHS tripe?
Fortunately, we can do it!
We have the formula, in pseudocode
LogicalAddress(c, h, s) = (c*NumberHeads + h)*NumberSector + (s - 1)
where NumberHeads
is the number of heads on the disk, NumberSector
is the number of sectors per track, and (c, h, s)
is the CHS address
for the sector we want to address.
- Andries Brouwer's "Large Disk HOWTO", section 4
- OSDev's Partition Table
- An Introduction to Hard-Disk Geometry