CHS conversion

From Academic Kids

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 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.44 MB 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 refers 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. 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.


GetCHS proc
            mov         AX, LHA
            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
Navigation

Academic Kids Menu

  • Art and Cultures
    • Art (http://www.academickids.com/encyclopedia/index.php/Art)
    • Architecture (http://www.academickids.com/encyclopedia/index.php/Architecture)
    • Cultures (http://www.academickids.com/encyclopedia/index.php/Cultures)
    • Music (http://www.academickids.com/encyclopedia/index.php/Music)
    • Musical Instruments (http://academickids.com/encyclopedia/index.php/List_of_musical_instruments)
  • Biographies (http://www.academickids.com/encyclopedia/index.php/Biographies)
  • Clipart (http://www.academickids.com/encyclopedia/index.php/Clipart)
  • Geography (http://www.academickids.com/encyclopedia/index.php/Geography)
    • Countries of the World (http://www.academickids.com/encyclopedia/index.php/Countries)
    • Maps (http://www.academickids.com/encyclopedia/index.php/Maps)
    • Flags (http://www.academickids.com/encyclopedia/index.php/Flags)
    • Continents (http://www.academickids.com/encyclopedia/index.php/Continents)
  • History (http://www.academickids.com/encyclopedia/index.php/History)
    • Ancient Civilizations (http://www.academickids.com/encyclopedia/index.php/Ancient_Civilizations)
    • Industrial Revolution (http://www.academickids.com/encyclopedia/index.php/Industrial_Revolution)
    • Middle Ages (http://www.academickids.com/encyclopedia/index.php/Middle_Ages)
    • Prehistory (http://www.academickids.com/encyclopedia/index.php/Prehistory)
    • Renaissance (http://www.academickids.com/encyclopedia/index.php/Renaissance)
    • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
    • United States (http://www.academickids.com/encyclopedia/index.php/United_States)
    • Wars (http://www.academickids.com/encyclopedia/index.php/Wars)
    • World History (http://www.academickids.com/encyclopedia/index.php/History_of_the_world)
  • Human Body (http://www.academickids.com/encyclopedia/index.php/Human_Body)
  • Mathematics (http://www.academickids.com/encyclopedia/index.php/Mathematics)
  • Reference (http://www.academickids.com/encyclopedia/index.php/Reference)
  • Science (http://www.academickids.com/encyclopedia/index.php/Science)
    • Animals (http://www.academickids.com/encyclopedia/index.php/Animals)
    • Aviation (http://www.academickids.com/encyclopedia/index.php/Aviation)
    • Dinosaurs (http://www.academickids.com/encyclopedia/index.php/Dinosaurs)
    • Earth (http://www.academickids.com/encyclopedia/index.php/Earth)
    • Inventions (http://www.academickids.com/encyclopedia/index.php/Inventions)
    • Physical Science (http://www.academickids.com/encyclopedia/index.php/Physical_Science)
    • Plants (http://www.academickids.com/encyclopedia/index.php/Plants)
    • Scientists (http://www.academickids.com/encyclopedia/index.php/Scientists)
  • Social Studies (http://www.academickids.com/encyclopedia/index.php/Social_Studies)
    • Anthropology (http://www.academickids.com/encyclopedia/index.php/Anthropology)
    • Economics (http://www.academickids.com/encyclopedia/index.php/Economics)
    • Government (http://www.academickids.com/encyclopedia/index.php/Government)
    • Religion (http://www.academickids.com/encyclopedia/index.php/Religion)
    • Holidays (http://www.academickids.com/encyclopedia/index.php/Holidays)
  • Space and Astronomy
    • Solar System (http://www.academickids.com/encyclopedia/index.php/Solar_System)
    • Planets (http://www.academickids.com/encyclopedia/index.php/Planets)
  • Sports (http://www.academickids.com/encyclopedia/index.php/Sports)
  • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
  • Weather (http://www.academickids.com/encyclopedia/index.php/Weather)
  • US States (http://www.academickids.com/encyclopedia/index.php/US_States)

Information

  • Home Page (http://academickids.com/encyclopedia/index.php)
  • Contact Us (http://www.academickids.com/encyclopedia/index.php/Contactus)

  • Clip Art (http://classroomclipart.com)
Toolbox
Personal tools