C/H/S Encoding

File format documentation

C/H/S encoding of data, which stands for Cylinder/Head/Sector, is the standard interleaved method for storing the actual disk contents. It is utilized in most of the file formats processed by FIVEC, and generally follows whichever header is used in a uniform fashion. Some formats do embedded other data within these data areas (NFD, specifically) but otherwise, the data block will form one big "chunk" after the header.

Data is sequenced in the following manner:

Cylinder 0, Head 0, Sector 1 - X bytes of data, where X is the byte in the sector.
Cylinder 0, Head 0, Sector 2
Cylinder 0, Head 0, Sector 3
...
Cylinder 0, Head 0, Sector 16 - Assuming there are 16 sectors per track (cylinder/head pair) in this format
Cylinder 0, Head 1, Sector 1
Cylinder 0, Head 1, Sector 2
...
Cylinder 0, Head 1, Sector 16 - Assuming there are two heads, as with all floppy formats
Cylinder 1, Head 0, Sector 1
Cylinder 1, Head 0, Sector 2
...

In generalized C# code:

for (c = 0; c < cylinders; c++)
    {
     for (h = 0; h < heads; h++)
     	 {
         for (s = 0; s < sectors; s++)
             {
             ReadSectorFromFile(DiskSector[h, c, s]);
             } //sectors
         } //heads
} //cylinders

For an illustration within a HexEditor, click here

Because you need to know the disk geometry to properly parse out each block, you need to either be provided this information by the header in the file format, or you need to assume a geometry based on the size of the headerless image (BKDSK/BIN-type images)

Back to the main page