Geometry problems
From Open Watcom
PC disk systems have many confusing limitations and complexities, brought about by the quest for backwards compatibility.
Contents |
The IBM PC/AT
Many modern disk systems are, at least optionally, compatible with the fixed disk interface introduced in the IBM PC/AT. Note that the PC/XT was also equipped with a hard disk, but used a very different disk controller which will not be discussed here.
The PC/AT came out at a time (1984) when hard disks (then often called Winchester disks, or Winchesters) were separate from disk controllers. One of the popular disk interfaces was Seagate ST-506/ST-412 used with MFM or RLL disks. For controlling the disk, IBM chose Western Digital WD1002-WA2, an adapter which could drive up to two fixed disks and two floppy drives. Later IBM models, such as the XT 286, used WD1003A-WA2, a cost-reduced version of the original WD1002-WA2.
Note that the AT controller interface is sometimes referred to as ST-506 compatible. That is somewhat misleading, because ST-506 was also a 5MB MFM disk (ST-412 was a 10MB model), and it was also the interface between a disk and a controller. A controller driving a ST-506 disk could present a simple AT compatible interface to the host system, but it could also use SCSI or yet another command set. At other times, the AT interface is called simply WD1003 compatible. That is not wrong, but it's also not entirely accurate. Western Digital produced several WD1003 models and some used very different command sets (WD1003-SCS was SCSI based). On top of that, the PC/AT actually used a WD1002, not a WD1003 controller...
Clones and IDE
The first attempt to combine a disk with its associated controller was the Quantum Hardcard, essentially a fixed disk bolted onto a ISA controller card. But both clone manufacturers (led by Compaq) and disk OEMs saw integration as a way to reduce cost and increase capabilities. By the late 1980s, IDE was becoming commonplace. IDE stood for Integrated Drive Electronics, and that's what it was. The controller card moved onto the drive itself. The 40-wire cable carried AT bus signals and was attached to the host system through very simple interface. Many people talked about "IDE controllers on the motherboard" but that was quite wrong. There was no controller on the motherboard, only a header and trivial logic. The controller was on the drive itself.
IDE brought great advances, but also some problems. The old discrete drive controllers could not hide many details of the attached drive. For instance, a low-level format of a disk required a table of bad sectors to be entered, and these sectors were visible to and had to be handled by the OS. The disk geometry was also visible to the OS and the user. Finally, separate controllers usually only supported a single recording technology (MFM, RLL). Once IDE arrived, these "details" were now hidden inside the disk/controller unit. An IDE drive could remap bad sectors and present a flawless disk to the host system. An IDE drive could also internally use any available recording technology, and it could internally organize data in whatever was the most convenient way. An IDE disk might present a geometry with X cylinders, Y heads, and Z sectors per track, but internally there could be for example variable sectors per track, with more sectors on the outer tracks. Or there might not be any cyliners, heads, and sectors at all, as was the case with CompactFlash cards and other flash-based media that used the IDE interface.
The biggest drawback, at least initially, was using two IDE disks attached to the same cable. In the old days, there were two drives but just one controller, and there was no problem. With IDE, there were two controllers which had to cooperate, and they often didn't.
ATA and LBA
ATA, or AT Attachment, was a standardization of the ST-506/WD1003/IDE interface. The ATA standard codified the software interface which had existed since the IBM PC/AT, as well as the connectors, signals, and timings used by IDE drives. The ATA standard was intended to be backwards compatible with the WD1002-WA2 controller, but it also brought an important advance: Logical Block Addressing, or LBA.
The SCSI standard never used cylinders, heads, and sector numbers (CHS) for addressing disk sectors. With IDE, using CHS addressing made less and less sense, because internally the drives used different organization anyway. With IDE, the controller register task file could specify either the old style CHS addresses, or the new LBA.
The BIOS and Software Compatibility
In an ideal world, PCs would switch to LBA disk addressing and CHS would fall by the wayside within a few years. But things weren't so simple. The IBM BIOS interface, originally designed for floppy drives (service INT 13h), turned out to be remarkably long-lived. The INT 13h BIOS service sub-functions for reading and writing accepted register parameters in the following simple format:
DH: head
CH: track
CL: sector
For floppy drives, this interface was (and remained) entirely adequate. For disks, the heads and sectors weren't a problem, because early fixed disks usually had 4-8 heads and 17 or 26 sectors per track. However, the 256 cylinder limit was a problem. IBM therefore slightly changed the interface for fixed disks:
DH: head
CH: cylinder low 8 bits
CL: cylinder high 2 bits in bits 7-6, sector in bits 5-0.
The interface could thus handle up to 1024 cylinders, 255 heads, and 63 sectors per track. Sector numbering started at one and zero was unused; head numbers started at zero so in theory 256 heads could be used, but the BIOS disk parameter tables (INT 41h vector) could only specify up to 255 heads.
The BIOS interface could thus address up to 1024 * 255 * 63 or 16,450,560 sectors. The sector size was more or less set in stone as 512 bytes, so the limit worked out to approximately 8.2 gigabytes (where 1GB equals 1,000,000,000 bytes).
But things weren't so simple. The WD1002-WA2 controller and compatibles had different limits:
1024 cylinders
16 heads
255 sectors per track
That works out to 1024 * 16 * 255 or 4,177,920 sectors. The sector size was fixed at 512 bytes with the IBM AT and compatible products, so the limit worked out to approximately 2.1 gigabytes.
But wait. It was even more complicated than that, because the lowest common denominator of the BIOS and IDE interfaces started causing problems first. The BIOS could specify up to 255 heads, but the disk interface was limited to 16. Similarly the disk could handle up to 255 sectors per track, but the BIOS was limited to 63. Thus the earliest limit was 1024 * 16 * 63 or 1,032,192 sectors. That worked out to approximately 528 megabytes (where one megabyte equals 1,000,000 bytes), a limit which started causing problems in the early 1990s.
Note: It should be kept in mind that the BIOS INT 13h interface is independent of the underlying drive technology. It is used for IDE drives as well as SCSI, or any other bus/controller interface. Other disk technologies had fewer or different limitations.
Geometry Translation to the Rescue
The ATA standard introduced several important changes from the original ST-506 or WD1002-WA2 interface. The cylinder limit was raised to 16,384 by defining the six previously unused cylinder high register. Thus an IDE drive could address up to 65,536 * 16 * 255 or 267,386,880 sectors using CHS addressing.
At the same time, the ATA standard provided an option of Logical Block Addressing, or LBA. Instead of using the old style CHS addressing that no longer reflected the organization of data on disks, sectors could be addressed by a single sequential number; it was up to the disk controller to translate the LBA into the internal cylinder/head/sector location. The SCSI interface never used CHS addressing at all and always specified logical sectors.
The original ATA standard specified 28 bits for the LBA. The maximum addressable capacity was thus 2^28 or 268,435,456 sectors - or in other words, approximately 137.4 gigabytes.
Using LBA addressing, a BIOS could translate from the INT 13h CHS addressing to linear sector numbers. Alternatively, a BIOS could use CHS addressing on the ATA interface, doing translation between the L-CHS and P-CHS using a bit-shift algorithm. Software written to the INT 13h interface could thus work with disks sized up to 8.2 gigabytes (and the infamous 1,024 cylinder limit).
The geometry translation created the disparity between "logical" and "physical" geometry. For disks under 528 MB, there was no need for the two geometries to differ as long as the geometry was within the limits of both the BIOS and ATA CHS interfaces. For larger disks, some translation was always required.
Master Boot Record
The logical geometry has a very important place in the Master Boot Record (MBR) and the partition table contained within. If the information in the MBR does not match the logical geometry, the system will be often unable to boot. This is especially problematic when a disk is moved from one system to another. If the new host system does not use the same logical geometry, the disk may be unusable (though the data stored on it is not necessarily damaged).
Ironically, the MBR contains logical sector numbers as well as CHS addresses. Sadly, the logical numbers aren't properly updated by all operating systems and the CHS information is considered more reliable. That is especially unfortunate in light of the fact that most file systems (including FAT) internally use linear sector numbering anyway, and aren't dependent on CHS geometry. That doesn't help when the partitions cannot be located properly.
BIOS vs. Direct Access
TBW - BIOS translation vs. direct ATA register interface access
Extended INT 13h Interface
TBW - LBA in the BIOS

