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

  1. See if being run from floppy. If not, print:
    This program must be run from a floppy disk.

  2. See if ncget.com is on the floppy. If not, print:
    ncget.com required to be on the disk.

  3. See if ncrest.com is on the floppy. If not, print:
    ncrest.com required to be on the disk.

  4. See if being run from protected mode. If so, print
    Do not run this program in protected mode. See the README file, paragraph #3.

  5. Get command tail length. If 0:
    Print instructions.

  6. Get filename; if it is not a legal filename or if the file cannot be created print:
    Bad filename.
    Program aborted.

  7. See if MBR file already exists. If so, print:
    (MBR filename) already exists!
    Program aborted.

  8. See if .prm file already exists. If so, print:
    (.prm filename) already exists!
    Program aborted.

  9. See if hard drive 1 can be read. If not, print:
    Cannot read Drive 1!
    Program aborted.

  10. 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.

  11. 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.

  12. Perform the above for any additional hard drives.

  13. If there is an error in the color display, print:
    There is a color display error. Please run ncget.com.

  14. 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.

  15. Try to create the file; if error (as i.e., floppy write-protected), print
    Error creating file!
    Program aborted.

  16. Try to write the file; if error (as i.e., floppy write-protected), print
    Error writing file!
    Program aborted.

  17. 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.

  18. 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.

  19. 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.

  20. 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.

  21. Success, so write out the MBR and .prm files and mark them as read-only.

Algorithm for restmbr.com

  1. See if being run from protected mode. If so, print
    Do not run this program in protected mode.
    See the README file, paragraph #3.

  2. Get command tail length. If 0:
    Print instructions.

  3. Get filename; if it is not a legal filename print:
    Bad filename.

  4. Try to open file. If error, print:
    (filename) not found!

    or
    Path not found! or
    Error opening file.

  5. Make sure file size is 512 bytes; if not, print:
    (filename) is wrong file size (MBR file must be 512 bytes).

  6. Try to read file; if an error, print:
    Cannot read file.

  7. Check the MBR signature word. If not aa55 print:
    (filename) is not an MBR! (Wrong signature word).

  8. See if file is marked read-only; if it is not, give user option of so marking the file.

  9. 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!

  10. See if hard drive 1 can be read. If not, print:
    Cannot read Drive 1!
    Program aborted.

  11. Read all MBR's into memory; if error, print:
    Error reading MBR.

  12. 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.)

  13. If there is an error in the color display, print:
    There is a color display error. Please run ncrest.com.

  14. 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.

  15. 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!

  16. 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!.

  17. 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!

  18. Otherwise, success.