Encyclopedia > CHS conversion

  Article Content

CHS conversion

CHS conversion is a conversion between the geometric coordinate of data on a disk's surface (these coordinates are referred to as CHS coodinates) and the addressing system used by the disk's filesystem (referred to as the LBA). This conversion process is used with floppy disks as well as hard disks but this article will focus on its use with floppy disks.

When accessing data on a disk via the IBM-PC's floppy disk 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.

A cylinder is an imaginary circle running around the disk. Each disk has a fixed number of cylinders running from the inner edge of the disk and the outer edge of the disk. A head is a device which actually reads the data from the disk. The modern IBM-PC's floppy disk has a head on each side of the disk for a total of two. These heads are also numbered. A track is a strip of data running around the disk on a specific side. That is, each cylinder and head combination addresses a specific track. The word sector has two meanings. In terms of a CHS coordinate, a sector is a division of a track. Multiple sectors run around the disk in a circular pattern.

The number of cylinders, heads and sectors that a disk has depends on the type of disk. Most modern 1.44MB floppy disks have 80 cylinders (numbered 0 to 79), 2 heads (numbered 0 to 1) and 18 sectors per track (numbered 1 to 18). Each CHS coordinate points to a specific block on the disk. Each of these blocks contains a certain number of bytes. Most modern disks use 512-byte blocks.

(NOTE: A block is more commonly called a sector. This is not to be confused with the "sector" dimension described above which is a division of a track. For the purpose of this article, a "disk-wide sector" will be referred to as a "block".)

The addressing method used by almost all modern filesystems is called linear base addressing (LBA). In linear base 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 1 to 2,880).

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. Ussually 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



All Wikipedia text is available under the terms of the GNU Free Documentation License

 
  Search Encyclopedia

Search over one million articles, find something about almost anything!
 
 
  
  Featured Article
French resistance

... (BOA) - Service for arranging clandestine air operations in northern France. Ceux de la Resistance[?] Ceux de la Liberation[?] Chantiers de la Jeunesse[?] ...

 
 
 
This page was created in 27 ms