Features


CUG Library

An Adaptable Disk Utility

Alex Cameron


Alex Cameron is currently an engineering Project Manager with a large Australian Telecommunications company. Like many others, he caught the 'C' bug from Ron Cain's small C compiler, and enjoys programming for embedded control systems. He is currently working on a hardware-assisted Disk Utility for the IBM PC.

Format Adaptable Disk Utility

For many programmers, the PC was not their first machine. Many of us started with CP/M and Apple IIs and had to find some way of porting that old data to the PC. There are two options:

If you still have the old computer, no problem, just load compatible file transfer programs on both machines and connect an RS-232 link between them.

If your old computer's disk format is supported by programs such as PC-Alien and Xenocopy, you can use them. But, if the transfer utilities don't support your format and you don't have access to your original computer, you're high and dry. My solution: Write my own truly versatile and adaptable disk utility.

ADU (Adaptable Disk Utility) can scan a disk, building a disk parameter table. Once the table is built, you can adjust any of the disk operating system dependencies, such as system track offsets, and so on, before reading and editing. The user interface includes a full screen editor so that patching and editing the disk is a simple task.

Adjusting The PC's Disk Format Tables

The current standard PC floppy disk format consists of 40 tracks, each containing nine sectors of 512 bytes per sector. Vary this in any way and the PC chokes.

Each time the BIOS is called to perform a disk function, through INT 13H, it calls the BIOS routine GET_PARM which indexes into a table called DISK_BASE. DISK_BASE is a collection of floppy disk controller (FDC) parameters which tells the BIOS in what manner the FDC chip must be programmed in order to correctly read the disk (see Figure 1) . Forcing C pointers to address specific locations is complicated by the PC's 8088/8086 memory segmentation and the high/low byte reversal, but it is doable.

Some of the parameters relating to the GAP lengths must be determined empirically and are important when attempting to read multiple sectors during a diskcopy or formatting process. These GAPs are basically buffers designed to allow the controller's data separator to "turn off" during splices or periods of unknown data. If the Phase Locked Loop (PLL) within the data separator is not instructed to "turn off", it may get out of synchronisation and so not be able to lock onto the identification (ID) marks. Thus, an incorrect GAP setting can "turn off" the data separator during an area of good data. Errors of this type normally manifest themselves as "Time out errors" (BIOS return code 80H). The BIOS's disk status area is maintained at address 0040:0041 (Figure 2) .

Determining The Disk Format

ADU finds the correct disk parameters by trial and error. If a call to BIOS function 13H returns an error, it adjusts a parameter and retries. For example, ADU continually varies the bytes per sector code from 00 to 05 on, say, track 0, sector 1 until no error is returned. Once the number of bytes per sector is determined, ADU determines the total number of sectors by incrementing the sector number and perform a seek/verify until an error occurs. Next it looks for a match on side one to determine the number of sides. Finally it steps off the number of tracks.

The number of sectors per block is user-definable, as are all the other parameters (default is eight sectors per block). The number of sectors per block is only important during the copying of CP/M type disks. As with other parameters, if you don't want to work in blocks then just set the sectors per block to one. Table 1 lists all the commands available with ADU.

An Adaptable Disk Utility (ADU) is available through the CUG Library as CUG volume #307. See the order form in the center of the magazine.