How to use the new DOS 5.0 disk utilities. (MS-DOS Featuring DOS 5.0)
by Mark Minasi
In the article titled, "19 Top DOS 5.0 Tips," I discuss the small DOS 5.0 utilities, and there's a bunch of them. Let's take a more in-depth look here at how Microsoft has added a powerful troika of programs that make it tougher to lose data under 5.0.
These data-protection and -recovery tools are all adapted from the Central Point PC Tools collection. They go by the names of MIRROR, UNDELETE, and UNFORMAT.
The Right Tools
MIRROR is the preventive maintenance tool. It can back up three important areas: your disk's Partition Table, its File Allocation Table, and its root directory.
The Partition Table tells your system how much disk space to make available to DOS and lets you divide a single hard disk into multiple logical drives. It's only read at boot time, but if it's not present, DOS will refuse to recognize your disk. I've seen entire disk drives rendered unusable just because they had a damaged Partition Table.
Type MIRROR /PARTN, and you'll be prompted to put a floppy disk in drive A:. MIRROR will write a file containing a copy of the Partition Table to that disk. Put the disk away somewhere safe.
Then, if you ever experience a "cannot recognize drive C:" error, you can try to bring your hard disk back to life by typing UNFORMAT /PARTN. MIRROR will then attempt to restore your disk partition.
The File Allocation Table (FAT) is the part of your disk that tells DOS where each of your files resides on the disk. If there's any damage to the FAT, DOS won't be able to find some or all of your files. You cause DOS to modify the FAT every time you create or destroy a file, and anytime you modify a file.
The lion's share of the work needed to unerase a file involves work in the FAT. The root directory is the foundation of DOS's tree structured directory. It's hard-wired to the disk in that there can only be one root directory per drive and that root directory is a fixed size--512 entries on most hard disks.
All the other directories, the subdirectories, aren't stored on fixed locations on disk, but rather as special types of files that can be located anywhere on the disk.
Simply typing MIRROR backs up the FAT (and the root, as we'll see) to a file called MIRROR.FIL. Typing MIRROR followed by a drive letter, as in MIRROR D:, causes the FAT/root backup to occur on that drive.
As a start, you should put MIRROR in your AUTOEXEC.BAT. Include a line for each hard disk or hard disk partition on your drives. Then you'll get a fair amount of dataproofing.
Easy Way Out
How does MIRROR help? Well, let's take the case of a file erasure. When you type ERASE BANANA.COM, DOS doesn't go to the trouble of actually locating all of those areas where BANANA.COM resides on disk and overwriting them with 0s or 1s or whatever.
DOS takes a simpler (and faster) approach, only modifying the file system. First, it marks the file's directory entry as deleted and reusable by changing the first letter of the file's name to an ASCII 229, a lowercase sigma.
Then it marks all of the disk areas that the file is in--its clusters, in DOS terminology--as unused and available.
The data's still there, but DOS doesn't know that anymore and will overwrite it whenever it gets around to needing the disk space.
Unerasing a file, then, requires only restoring the first character of the directory entry and reminding the FAT that the file's clusters are indeed taken and shouldn't to be released to DOS when a program requires some free space.
The toughest problems faced by an unerase program, then, are (1) how to know which clusters the file formerly occupied in the FAT and (2) what to do if the file has already been overwritten.
MIRROR, by taking a snapshot of the FAT, simplifies the task of unerasing; all the UNDELETE program has to do is look at MIRROR.FIL to find out which clusters the file resided in when last MIRROR was run and go back and reallocate those clusters to BANANA.COM in the FAT. It's possible to reconstruct a FAT image for a file without a MIRROR backup, but MIRROR makes things easier.
But what about the other problem--keeping DOS from recycling the clusters that BANANA.COM resides in? Once a file has been erased, its clusters are fair game, so DOS can reuse any of them when creating a new file.
Once a file's clusters are overwritten, there's no way to bring the file back (short of backups, that is--you do back up your files regularly, don't you?).
MIRROR addresses that with a memory-resident mode: the tracking mode. You install that with the MIRROR /Td command, where d is the letter of the drive to track.
Having It Both Ways
Finally, there's UNFORMAT. You've seen that DOS doesn't really erase files, but rather erases their directory and FAT entries.
The FORMAT command, as it turns out, does roughly the same thing, although on a grand scale. It marks all clusters as available and clears out all root directory entries.
The data and the subdirectories are still on your disk drive, but they're no longer accessible, as the disk's table of contents has been erased.
You can see how simple unformatting is. Just find the recent FAT/root image file on the hard disk, copy the data to the root and FAT, and voila! You've unformatted the disk.
Someone always asks at this point, "How can you back up the FAT and root to a file on the hard disk, then format the hard disk, and then find the file?"
The answer is that the FORMAT command doesn't erase a single file; it only erases the information that tells DOS where that file is. The data's still there, if you can find it.
UNFORMAT starts out by searching the disk for the cluster that contains the MIRROR backup file--MIRROR gives it a distinctive look so it's easy to recognize. Then the unformatting process is a piece of cake.
"Ah," I hear you cry. "But what if I haven't done a MIRROR backup of the FAT/root recently? Doesn't that mean I'll get an incorrect unformat?" Nope. The FORMAT command protects you from yourself by doing an automatic MIRROR every time you format.
Back in the bad old DOS 2.0 days, you could just type FORMAT, and DOS would merrily zap your hard disk without a single Are you sure? Now, you'd be hard-pressed to lose your data.
It's kind of like driver's side air bags for cars, don't you think? I kinda like it.