DISKBUG - The Disk Debugger

Latest version is 0.3.2 (0.3.3 for Linux). The archives contain source code ONLY. (If anyone asks we will provide binaries.)

DISKBUG for MS-DOS is a program that uses the BIOS Interrupt 13h to interface with IDE hard drives and with floppy drives.

DISKBUG for Linux is a program that uses standard file I/O on IDE devices. (Browsers that are not told about .gz files may not transfer properly - here is an InfoZIP'd version: diskbugl.zip) Latest version fixes a few really stupid errors.

DISKBUG sources are currently only compatible with the 16-bit Microsoft and Watcom compilers, and with DJGPP for MS_DOS.

DISKBUG for Linux has only been (briefly) tested with Linux 2.0.36 as "root" and has sector writing disabled. I will be updating the Linux version to handle drives > ULONG_MAX in capacity and to write sectors to the disk (and update the read cache) RSNtm.
 

Contents

  1. Introduction
  2. Command Summary
  3. Command Line
  4. Partition Information
  5. The Future
  6. Modification & Distribution
  7. BUGS

1. Introduction

DISKBUG is for debugging hard disk drives via BIOS calls (or standard filr I/O for Linux). It is very simple and should be easy to use. With it you can edit sectors, save sectors to a file, write a file to sectors, etc.

DISKBUG is not for the faint of heart -- it can fill an entire HDD with zeros -- it can write a file over several tracks -- it can do really bad things.

DISKBUG can save your ass -- use it to save and restore partition and boot tracks -- use it to recover from idiot programs that can ruin a drive -- use it to do really cool things.
 

UNDERSTAND DISKBUG BEFORE USING ITS SECTOR WRITING COMMANDS 
TEST DISKBUG CAREFULLY BEFORE USING ITS SECTOR WRITING COMMANDS 
I CAN NOT OFFER ANY WARRANTY or GUARANTEE FOR DISKBUG 

DISKBUG sources are currently only compatible with the 16-bit Microsoft and Watcom compilers, and with DJGPP for MS_DOS.
DISKBUG has only been (briefly) tested with Linux 2.0.36 as "root".
 

2. Command Summary

bios <ax cx dx> perform BIOS INT 13h call (MS-DOS only)
drive <n> drive to use; 0 1st, 1 2nd, etc.
set <d,c,h,s> set drive, cylinders, heads and sectors
size <n> set sector size to `n' if not 512
read [file] read sector; or read (secsiz bytes of) `file'
save <file> [n] save sector (or `n' sectors) to `file'
write [enable] write sector ("enable" to allow writes)
Write <n file> write `file' over `n' sectors
dump dump sector
disp display drive geometry
seek <c,h,s> seek to cylinder,head,sector
tell tell current position
edit edit sector data
zero zero fill sector buffer
Zero <n> [b] zero fill & write `n' sectors (fill byte `b')
part display drive partition info
next read & dump next sector
prev read & dump previous sector
quit [n] quit (return `n' to system)
help display command summary
! [command] exec shell or command
? [command] command help

Multiple commands may be separated by ';'.

Things to remember:

Read about the -trace command line option in the COMMAND LINE section below for how to test DISKBUG.

DISKBUG is in read-only mode until you type "write enable".

Use the "bios" command very, very carefully.

The "drive" command can access FDDs as drives -2 and -1 (for A: and  B:).

Commands are case sensitive. Commands which write raw sectors will always ask for confirmation.

All commands that write to the disk will always ask for confirmation.

Look for unused sectors on HDDs and experiment there first before editing used sectors. (If you have a spare HDD then you can mess around all you want.) Of course you can always mess around with floppies first.
 
 

EXPERIMENT
BE CAREFUL
MAKE BACKUPS
CHECK THE SOURCE CODE

3. Command Line

The command line option "-trace" will cause DISKBUG to display a parameter dump write before a BIOS function is called. And only when you issue the command "write enable" will DISKBUG allow any writes to the drive -- otherwise you will just see the parameter dump. This way you can test all write commands to see what the BIOS call parameters will be.

DISKBUG commands can be given on the command line; for example:

DISKBUG drive 0; save track.0 63; quit
will save track 0 of drive 0 to the file track.0 (assuming that there are 63 sectors per cylinder).
 

3. Partition Information

There are two things I will discuss here: the "part" command, and partition information in general.

The "part" command will recursively display all partitions on the drive. Here is the output from the command

DISKBUG drive 0; part; quit >part.txt
on my system:
                     start            end          start        number of
entry   type       C   H   S       C   H   S       sector         sectors

Cyl: 0, Head: 0, Sec: 1

0       06 *       0   1   1     519 127  63           63         4193217
1       05       520   0   1     779 127  63      4193280         2096640
2       00         0   0   0       0   0   0            0               0
3       00         0   0   0       0   0   0            0               0

Cyl: 520, Head: 0, Sec: 1

0       06       520   1   1     779 127  63           63         2096577
1       00         0   0   0       0   0   0            0               0
2       00         0   0   0       0   0   0            0               0
3       00         0   0   0       0   0   0            0               0

There are two partitions; it's a Seagate 3.2GB with a 2GB primary partition and a 1GB extended partition.

Note that the partition display may be non-sensical for non-FDISKed partitions.

For more information about partitions get allhiw.zip, all of Hale Landis' How It Works articles.

About Partitions in General:

The terminology used in various books and texts on partitions and boot records can be, and many times are, confusing, and sometimes are just plain wrong.

Do not confuse the BOOT RECORD with the BOOT SECTOR.

The BOOT RECORD is really the MASTER BOOT RECORD (MBR) of a HDD that resides on the first sector of the first track of a HDD, and is loaded by the BIOS during the boot process.

The BOOT SECTOR is on the first sector of the second track of a HDD, and is loaded by the BOOT RECORD code to boot the Operating System on the HDD.

A program like FDISK creates a BOOT RECORD. A program like FORMAT creates a BOOT SECTOR.

BE CAREFUL! Spend the time to really understand BOOT RECORDS and  BOOT SECTORS before you run programs that modify these sectors.

4. The Future

Since I created DISKBUG as a tool for my own use (and because I will be re-installing Linux several more times (the first three times resulted in disaster), I will be using DISKBUG, and therefore will be upgrading DISKBUG; i.e. adding features and making modifications (and perhaps fixing bugs).

5. Modification & Distribution

This software is covered by the DPU Software License.

I hope that DISKBUG will be of use to you and to others. I ask nothing in return for its "being", and that no others ask for anything for its "being" either.

6. BUGS

If DISKBUG is compiled to use a color prompt (the defualt), the prompt can get out of synch with the rest of the text. I do not know why. Just keep pressing CR until the screen scrolls.

Also, if DISKBUG is compiled to use a color prompt and is running in a Windows DOS-BOX, the text can sometimes get "stuck" in the prompt color. I do not know why.

See DISKBUG.TXT in the archive for a more up to date BUG LIST.