- CHS conversion
CHS conversion is a conversion between the
geometric coordinate (cylinder/head/sector or CHS) of data on a disk's surface and the addressing system used by the disk's filesystem (linear base address or LBA). This conversion process is used withfloppy disk s as well ashard disk s but this article will focus on its use with floppy disks.When accessing data on a disk via the
IBM PC 's floppydisk controller , the driver must describe the location of that data in terms of its CHS coordinates. These coordinates are specified using three dimensions: cylinder number, head number and sector number.The addressing method used by almost all modern filesystems is called
logical block addressing (LBA). In logical block addressing, only one number is used to address data, rather than three. Each linear base address describes a single block. The reason for using LBA instead of CHS in the filesystem is because of its simplicity. Most modern floppy disks contain 2,880 blocks (numbered 0 to 2,879).From CHS to LBA
The equation to convert from CHS to LBA follows:
LBA = ( ( CYL * HPC + HEAD ) * SPT ) + SECT - 1
Where: LBA: linear base address of the block CYL: value of the cylinder CHS coordinate HPC: number of heads per cylinder for the disk HEAD: value of the head CHS coordinate SPT: number of sectors per track for the disk SECT: value of the sector CHS coordinate
This equation is not used very often. Usually the software already has the LBA value and needs to calculate the CHS value for it.
From LBA to CHS
The equations to convert from LBA to CHS follow:
CYL = LBA / (HPC * SPT) TEMP = LBA % (HPC * SPT) HEAD = TEMP / SPT SECT = TEMP % SPT + 1
Where: LBA: linear base address of the block CYL: value of the cylinder CHS coordinate HPC: number of heads per cylinder for the disk HEAD: value of the head CHS coordinate SPT: number of sectors per track for the disk SECT: value of the sector CHS coordinate TEMP: buffer to hold a temporary value
This equation is used very often by operating systems such as
DOS to calculate the CHS values it needs to send to the disk controller or INT13h in order to read or write data.Assembler code example
The following procedure calculates the geometric coordinate of a block of data based on an LBA address specified. Only works when AX is enough to hold LBA.
GetCHS proc mov AX, LBA xor DX, DX mov BX, SPT div BX inc DX mov SECT, DL xor DX, DX mov BX, HPC div BX mov CYL, AL mov HEAD, DL ret GetCHS endp
External Links
* [http://www.viralpatel.net/taj/tutorial/chs_translation.php CHS to LBA Translation Tutorial]
Wikimedia Foundation. 2010.