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:
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:
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:
error, data was corrupted
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:
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.
|Physical Number of Cylinders||Physical Heads Per Cyl||Physical Sectors Per Head||Power of Two for Translation|
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.