Make your own free website on Tripod.com

Physical Interfaces


Introduction

I assume that you are already familiar with what disks are as physical devices. The purpose of these documents is to describe disk logical structures, but not disk interfaces. To understand the material better, I recommend that you familiarize yourself with EIDE or SCSI disk controllers. Only the things that are absolutely necessary for understanding further material are explained here.

Links

The general FAQ on EIDE can be found at:
 http://www.paranoia.com/~filipg/LINK/F_IDE-tech.html
More technical ATA drafts are at:
 http://fission.dt.wdc.com/ata/
Certainly, all links are subject to change without notice.

CHS and LBA

In a nutshell, disk consists of sectors. Sector is a group of bytes (octets), the minimal unit of transaction between the disk and the system. Although sector size can theoretically be pretty anything, it is safe to assume that one sector is 512 bytes long.

There are two major modes for addressing sectors on disk. One is called CHS mode. Sectors in this mode are grouped under heads. How many sectors are under one head is determined by the device parameter called SectorsPerHead. Further, heads are grouped under cylinders. How many heads are under one cylinder is determined by another device parameter, HeadsPerCylinder. The remaining disk parameter is NumberOfCylinders, which, together with HeadsPerCylinder and SectorsPerHead unambiguously determines disk capacity in CHS mode:

CHSCapacity=NumberOfCylinders*HeadsPerCylinder*SectorsPerHead*512

Needless to say, neither of disk parameters should be equal to zero. If any of them is equal to zero, such disk should be considered invalid

You need Cylinder, Head, and Sector to identify the sector in CHS mode. Identification is unique as long as you stay in the same CHS translation mode. However, it is not unique across different translation modes. Devices, in conjunction with BIOS, may translate Cylinder and Head values to make it possible for BIOS to access large amounts of data. The mechanism of this translation is discussed below. Head and cylinder numbers always start from zero, sector numbers start from one. You will likely perform some arithmetic operations on CHS values. The formulas below will help you. Note that you can use them only if you know disk parameters.

To add S sectors to some CHS address follow these steps:

Sector=Sector+S;
Head=Head+(Sector div SectorsPerHead);
Sector=Sector mod SectorsPerHead;
Cylinder=Cylinder+(Head div HeadsPerCylinder);
Head=Head mod HeadsPerCylinder;

You should always check if the resulting Cylinder is less than NumberOfCylinders. If this is not the case, the data on disk that made you do this calculation was corrupted.

To subtract one sector from the given CHS address follow these steps:

if Sector=0
  Sector=SectorsPerHead-1;
  if Head=0
    Head=HeadsPerCylinder-1;
    if Cylinder=0
      error, data was corrupted
    else
      Cylinder=Cylinder-1;
  else
    Head=Head-1;
else
  Sector=Sector-1;

The second mode for addressing sectors is called LBA. It stands for Linear Block Addressing, which means exactly that. You need only sector number to address the sector. Linear sector numbers start from zero. Disk capacity in LBA mode is determined by NumberOfSectors, which is certainly device parameter. The following equality must always hold:

LBA=(Cylinder*HeadsPerCylinder+Head)*SectorsPerHead+Sector-1

Thus, CHS (0, 0, 1) corresponds to LBA (0). One might think that CHS (NumberOfCylinders-1, HeadsPerCylinder-1, SectorsPerHead) corresponds to LBA (NumberOfSectors-1), but this is not the case. In practice, one can usually address slightly more sectors in LBA mode than he does in CHS mode. According to my rules described earlier, you should ignore extra LBA sectors that might exist in CHS partitions. Refer to EIDE or SCSI documentation for the ways of determining physical disk parameters. Refer to your BIOS manual for the way of determining logical disk parameters.

There are two key operations that can be performed on sectors in any mode: read and write. Refer to the manuals described above for the ways of performing these operations. From now on, you must be able to read and write sectors given their LBA or CHS address.

Limitations

As you might have noticed reading documentation, there are some limitations on how much space is addressable in LBA and CHS modes. For example, ATA standard reserves two 16 bit words for NumberOfSectors, which means that the highest possible disk capacity in LBA mode is 2 TB. ATA standard also reserves 16 bit word for each of the disk parameters in CHS mode, thus the highest disk capacity in CHS mode is 131072 TB. In reality, HeadsPerCylinder is usually limited to 16 and SectorsPerHead is limited to 64, so the real highest disk capacity for CHS mode is only 32 GB. As will be shown later, BIOS imposes its own limitations: NumberOfCylinders cannot exceed 1024, SectorsPerHead is limited to 64, and HeadsPerCylinder is limited to 256. While BIOS itself can support up to 8G disks, comparing BIOS and EIDE limitations yields the unpleasant 512 MB barrier in CHS mode (BIOS barrier in LBA mode is 2 TB). How this problem is dealt with is the subject of the next section.

CHS Translation

Since many current EIDE drives still have 16 or less heads and more than 1024 cylinders, and far not all drives support the necessary hardware CHS translation modes, BIOS provides software CHS translation. It does some arithmetic on HeadsPerCylinder and NumberOfCylinders to make more than 512 MB accessible. BIOS maps logical CHS address to physical CHS address by multiplying logical Cylinder by the power of two and dividing logical Head by the same power of two. Conversely, one can translate physical CHS address to logical CHS address by dividing physical Cylinder by the power of two and multiplying physical Head by the same power of two. Certainly, the same arithmetic is performed on NumberOfCylinders and HeadsPerCylinder. Sector and SectorsPerHead remain untouched by the translation. The corresponding power of two is the minimal power of two that makes logical NumberOfCylinders less than or equal to 1024. You can pick it from the table:
 
Physical Number of Cylinders Physical Heads Per Cyl Physical Sectors Per Head Power of Two for Translation
1..1024 1..256 1..64 1
1025..2048 1..128 1..64 2
2049..4096 1..64 1..64 4
4097..8192 1..32 1..64 8
8193..16384 1..16 1..64 16
16385..32768 1..8 1..64 32
32769..65536 1..4 1..64 64
 

It is obvious that with some values of NumberOfCylinders disk may have different capacity in different CHS modes. However, I have never seen this in practice. The situation when physical disk parameters do not fit in this table is only possible if disk capacity is more than 8 GB or when disk has more than 64 sectors per head. Such disks are not yet handled by BIOS correctly. That is why I cannot provide any guidelines for these cases.

LARGE, NORMAL, and LBA

Finally, I would like to say some words about BIOS settings for EIDE drives. BIOS routines can use different addressing modes for accessing drives. NORMAL BIOS mode uses CHS addressing mode with no software translation. LARGE mode uses software CHS translation as described above. It is identical to NORMAL mode for the drives that have 1024 or less cylinders. LBA mode uses LBA addressing. In my experience, this mode also provides software CHS translation for the requests that are made in CHS notation. AUTO selects the best mode automatically.



Author:  Alex Verstak  3/10/1998