Master Boot Record Save and Restore--Error Messages and Algorithms (Color Versions)
Version 3.00
Introduction:
Saving a master boot record (MBR) to
a file and restoring an MBR file
to a hard disk are trivial operations. Each can be accomplished with a
100-byte-or-less .com program when the .com program is written in assembly. Getmbr.com and
restmbr.com were written in assembly, but you will notice that their sizes
are considerably greater than 100 bytes each. The difference (aside from the
additional code used for the user interface), relates to the amount
of checking these programs do.
For example, getmbr.com reads each MBR into memory twice, compares the two copies, and aborts
if are not identical. After writing the MBR to a file, it reads back the file
it has written and reads for a third time the chosen MBR from the hard disk and
compares it with the file. If the two copies are not identical, it deletes
the file (so you won't use it) and aborts.
Restmbr.com first makes sure that the file looks like an MBR (512 bytes,
correct signature word), then restores the file to the chosen hard disk.
If there are any errors in writing to the hard disk, restmbr.com retries
the operation up to 10 times with disk controller resets with each try.
Here are the error messages produced by
the color versions of getmbr.com and
restmbr.com. The algorithms of the programs are below.
Error messages in getmbr.com
Error messages in restmbr.com
Algorithm for getmbr.com
- See if being run from floppy. If not, print:
This program must be run from a floppy disk.
- See if ncget.com is on the floppy. If not, print:
ncget.com required to be on the disk.
- See if ncrest.com is on the floppy. If not, print:
ncrest.com required to be on the disk.
- See if being run from protected mode. If so, print
Do not run this program in protected mode.
See the README file, paragraph #3.
- Get command tail length. If 0:
Print instructions.
- Get filename; if it is not a legal filename or if the file cannot
be created print:
Bad filename.
Program aborted.
- See if MBR file already exists. If so, print:
(MBR filename) already exists!
Program aborted.
- See if .prm file already exists. If so, print:
(.prm filename) already exists!
Program aborted.
- See if hard drive 1 can be read. If not, print:
Cannot read Drive 1!
Program aborted.
- Read MBR of drive 1 into memory. If an error, print:
Error reading master boot record on drive ()
Program aborted.
Reread the MBR of drive 1 into another section of memory. If an error, print:
Error reading master boot record of drive ()
Program aborted.
- Compare the two copies of the MBR of drive 1. If they are not exactly
the same, print:
The two MBR copies read on drive () do not match!
Program aborted.
- Perform the above for any additional hard drives.
- If there is an error in the color display, print:
There is a color display error. Please run ncget.com.
- Display the MBR data to the screen and ask user to (s)ave or choose
another drive. If "s" is not input, print:
Program aborted.
- Try to create the file; if error (as i.e., floppy write-protected), print
Error creating file!
Program aborted.
- Try to write the file; if error (as i.e., floppy write-protected), print
Error writing file!
Program aborted.
- Read back the chosen MBR from disk; if error, print:
Error on re-reading master boot record.
Program aborted.
Delete the file so it cannot be used.
- Try to open the just-created file from disk. If error, print:
Error reopening file.
Program aborted.
Delete the file so it cannot be used.
- Try to read the just-opened file from disk. If error, print:
Error on re-reading file.
Program aborted.
Delete the file so it cannot be used.
- Re-read the chosen MBR from the hard disk a third time.
Compare the file just read into RAM with the re-read MBR. If not
a perfect match, print:
Bad double reread on drive ().
Program aborted.
The file and MBR re-read don't match!
Delete the file so it cannot be used.
- Success, so write out the MBR and .prm files and mark them as read-only.
Algorithm for restmbr.com
- See if being run from protected mode. If so, print
Do not run this program in protected mode.
See the README file, paragraph #3.
- Get command tail length. If 0:
Print instructions.
- Get filename; if it is not a legal filename print:
Bad filename.
- Try to open file. If error, print:
(filename) not found!
or
Path not found!
or
Error opening file.
- Make sure file size is 512 bytes; if not, print:
(filename) is wrong file size (MBR file must be 512 bytes).
- Try to read file; if an error, print:
Cannot read file.
- Check the MBR signature word. If not aa55 print:
(filename) is not an MBR! (Wrong signature word).
- See if file is marked read-only; if it is not, give user option of
so marking the file.
- Re-read the file into a second section of memory. Compare the two copies
of the file; if they are not exactly the same, print:
Bad file compare!
- See if hard drive 1 can be read. If not, print:
Cannot read Drive 1!
Program aborted.
- Read all MBR's into memory; if error, print:
Error reading MBR.
- See if parameter file (.prm) file exists. If not, print:
(Unable to display MBR data file. (prm filename) not found).
See if paramter file is 4 bytes and does not contain any 0's. If
not, print
(Unable to display MBR data file. Bad prm file.)
- If there is an error in the color display, print:
There is a color display error. Please run ncrest.com.
- Display the MBR data to the screen and ask user to "yes" to restore or choose
another drive. If "yes" is not input, print:
Program aborted.
- Write the MBR data from memory (the file data) to the hard disk. If
error, reset disk controller and try 9 more times (with controller
resets each time). If still error, print:
Error writing MBR!
- Read back the just-stored MBR into memory. If error, reset disk
disk controller and try 9 more times (with controller
resets each time). If still error, print:
Error re-reading MBR!.
- Compare the re-read MBR data with the file data that is in RAM. If
not exactly the same, repeat steps 14-15 three more times. If still
error, print:
Error comparing file with MBR!
- Otherwise, success.