Disk formatting can be divided into low-level formatting and advanced formatting. Low-level formatting is applicable to hard disks. It can clear all data in the hard disk, including the master boot records, DOS boot records, and partition table information of the hard disk, of course, it can also eliminate all viruses that use disks as hiding places. Earlier versions of CMOS include low-level hard disk formatting programs. You can perform low-level hard disk formatting in CMOS, or use some low-level software such as DM. There are several advanced formatting methods for disks. Quick formatting is one of them. The basic format program published with DOS allows you to quickly format the disk (optional parameter/Q ). Before introducing quick formatting, we will first give a brief introduction to the disk structure, and then compare the quick formatting with General advanced formatting.
A successfully formatted hard disk can be divided into the following parts: Master Boot Record and partition table information, DOS Boot Record, File Allocation Table (FAT) information, root directory (Root) information and data zone. The Master Boot Record and partition table information are stored in the first sector of the hard disk. The Master Boot Record can be written randomly based on the operating system, it is not difficult to realize coexistence of multiple operating systems. The partition table is the last 64 bytes in the first sector of the hard disk. the start and end signs are 80 h and 55aah respectively. It records the number of logical partitions, the start and end fan ID, and other information. "80 h" and "55aah" are two key codes of the hard disk, after the disk is lost, it will not be self-initiated. The dos Boot Record stores the description of the three files in the boot system. It also contains information about a partition table. The file allocation table and root directory information record the file name, attributes, and storage address. When locating a file, you can easily find the file by combining the allocation table information and root directory information. The data zone is the most occupied part of the hard disk and is used to save file data.
Let's take a look at the file deletion process: Modify the corresponding information of the file allocation table, change the first character of the file name, and release the disk space. Note that the content of the files stored in the data zone is not deleted, so the deleted files can be restored. In contrast, the advanced formatting of a disk mainly involves the following tasks: divide the disk into channels and sectors, write boot information to the primary boot area and DOS boot area, clear the File Allocation Table and root directory area, and scan the track. However, fast formatting is different because it does not perform Track Scanning. Therefore, the effect of fast formatting and completely deleting disk files is the same.
Compared with the hard disk structure, there is no primary boot area in the floppy disk. Advanced formatting also requires four tasks for a floppy disk, but for the format command, before executing the operation, the contents of the file allocation table and root directory are saved to the last several slices of the disk as an image, the disk data can be restored by the "unformatted" Operation (as long as the content in the data area is not overwritten ).
Given that the number of sectors occupied by the fat and root directories of a 1.44 MB 3.5 inch floppy disk remains unchanged (fat1: Sector 1-9; fat2: Sector 10-18; root: Sector 19-32 ), we can practice it on the machine and write a quick formatting program to quickly format a 1.44 MB 3.5 inch floppy disk. Because the program is relatively simple and the unformat information is not saved, the data cannot be restored after the formatting is completed. Therefore, you should be careful when performing the experiment. We can use the C language library function abswrite to achieve rapid formatting, because it is defined in the DOS. h header file, so the program should start:
# Include <dos. h>
Below is the prototype of this function, which is easy to learn:
Int abswrite (INT drive, int nsects, int lsect, void * buffer );
The original form of the corresponding absread function:
Int absread (INT drive, int nsects, int lsect, void * buffer );
Program Design Idea: Because the rapid formatting is to clear the fat and root areas, we can use the abswrite function to write zero to these two areas to clear the data. The program code is as follows:
# Include <dos. h>
# Include <stdio. h>
Unsigned char buff [512];
Main ()
{
Int I; char C;
Printf ("/nquick format 1.44 MB/N ");
Printf ("Program by chenqingyang./N ");
Printf ("All data in the floppy disk will be lost !! /N ");
Printf ("/ninsert a diskette for drive a:/N ");
Printf ("and press Enter when ready..."); C = getchar ();
Printf ("/n/ncleaning fat area ...");
Buff [0] = 0xf0; buff [1] = buff [2] = 0xff;
For (I = 3; I <512; I ++) buff [I] = 0;
Abswrite (0, 1, buff );
Abswrite (0, 1, 10, buff );
For (I = 0; I <512; I ++) buff [I] = 0;
For (I = 2; I <10; I ++) abswrite (0, 1, I, buff );
For (I = 11; I <19; I ++) abswrite (0, 1, I, buff );
Printf ("/ncleaning root area ...");
For (I = 19; I <33; I ++) abswrite (0, 1, I, buff );
Printf ("/n/nquickformat completed! /N ");
}