The object of the present invention is to provide a kind of can be to the method for disk (or disk cut section) quick formatting, simultaneously more can at disk behind low-level formatting, when cutting apart that the impaired situation in certain sector, district takes place in back and the disk again, still can carry out each format to disk.
The object of the present invention is achieved like this, a kind of method of formatting diskette promptly is provided, be applied to one and have a format manipulation that starts the disk cut section of record, a file configuration table and a file directory, in order to save the formative time, its step comprises:
A. obtain a disk parameter relevant with an arithmetic logic unit with this disk cut section;
B. produce a disk sequence number;
C. according to this disk parameter, obtain a sector number of this document allocation list with this arithmetic logic unit;
D. with this arithmetic logic unit sector number, this disk sequence number of this document allocation list write relevant position in this startup record; And
E. remove the content of a this document allocation list and a file directory.
The present invention also provides a kind of method of formatting diskette, and its step comprises:
A. obtain a disk parameter relevant with an arithmetic logic unit, and this disk have a startup record, a file configuration table and a file directory with this disk;
B. produce a disk sequence number;
C. according to this disk parameter, obtain a sector number of this document allocation list with this arithmetic logic unit;
D. with this arithmetic logic unit sector number, this disk sequence number of this document allocation list write relevant position in this startup record; And
E. remove the content of a this document allocation list and a file directory.
Technology of the present invention mainly is to format needed disk parameter by the INT 13h reading disk that BIOS interrupts, include: total sector number of disk (or disk cut section), start the position of record, the numbering of disk (or disk cut section) type and disk, with the sector of planning disk again by an arithmetic logic unit, and the result after will planning writes the interior corresponding position of startup record of former disk (or disk cut section).At first observing the structure of the startup record of a disk, is to be divided into five parts, as follows:
1.Jump Instructon (taking 3 hytes)
2.OEN Name (taking 8 hytes)
(3.DPB FAT16 and FAT32 have certain difference)
4.Bootstrap code (is one section start-up routine, can make disk after format, again
Can start after duplicating I0.dos and command.com two files, quite
In the effect of carrying out format/s)
5. finish in above structure with " 55aa ", disk parameter piece (DPB, Disc Properties Block) be different in FAT16 with structure in the FAT32 system, and other several parts are changeless basically, see also table one and table two, list the structure of the disk parameter piece of FAT16 and FAT32 system respectively, so technology emphasis of the present invention calculating of every content in the disk parameter piece just, by finding out in table one and the table two, the disk parameter piece has than big difference in FAT16 and FAT32 system, as: in the parameter block structure of FAT16 system, the maximal value of file directory item is 0x0002, but in the parameter block structure of FAT32 system, the maximal value of file directory item then is 0.So after the INT 13h reading disk of interrupting by BIOS formats needed disk parameter, calculate the sector number (sfat) of each file configuration table with arithmetic logic unit by formula (1) or formula (2), in the relevant position of write-enable record, and be clearly zero with the content of file configuration table and file directory, and write medianumber at the start-up portion of every file configuration table (FAT), so just finish the formative whole programs of disk (or disk cut section).This it should be noted that the disk of FAT32 system has three to start record again, first startup record that comprises DPB and FAT16 is approximate, second starts the size that records this disk cut section Free Space in the record, with bunch (Cluster) is unit, its computing formula is Free Space=(stotal-2 * sfat-0x20)/8-1, the 3rd startup record belongs to Bootstrap code, can not influence result of calculation.Sfat=(stotal-0x21)/((1) sfat=(stotal-0X23) of 1+s * 0x100)+1/(position of 1+8 * 0x080)+1 (2) tables one, disk parameter piece is in the 0B character place of first sector of disk cut section, the DPB structure of FAT16.
The position | Content |
0B-0C | Character number in each sector (herein be 0x0002, promptly 512) |
0D | Sector number in each bunch (number is determined in size by cut section) |
0E-0F | Reserve sector (0x0100) |
10 | The number of FAT (0x02) |
11-12 | The maximal value of file directory item (herein being 0x0002) |
13-14 | Sector sum (herein being 0 when greater than 65535) |
15 | Media descriptor handling (0xf8) |
16-17 | The sector number of each FAT (calculating) by formula (1) |
18-19 | The sector number of each track |
1A-1B | The magnetic head number |
1C-1D | Hide sector number (not influencing the result) |
20-23 | 13-14 character place is 0 o'clock a magnetic sum |
24 | Phisical drive number (first 0x80, second is 0x81 ...) |
25 | Keep |
26 | The feature character (being 0x29) of expansion leader record |
27-2A magnetic | Disk sequence number (producing at random) |
2B-35 | Label (totally 11 characters) |
36-3D | File system type (being FAT 16) |
The position of table two, disk parameter piece is in the 0B character place of first sector of disk cut section, the DPB structure of FAT32.
The position | Content |
0B-OC | Character number in each sector (herein be 0x0002, promptly 512) |
0D | Sector number in each bunch (number is by the decision of cut section size) |
0E-0F | Reserve sector (0x0100) |
10 | The number of FAT (0x02) |
11-12 | The maximal value of file directory item (herein being 0) |
13-14 | Sector sum (herein being 0) |
15 | Media descriptor handling (being 0xf8) |
16-17 | The sector number of each FAT (herein being 0) |
18-19 | The sector number of each track |
1A-1B | The magnetic head number |
1C-1F | Hide sector number (not influencing the result) |
20-23 | 13-14 character place is 0 o'clock a sector sum |
24-27 | Sector sum (calculating) by formula (2) |
28-29 | File System Ver (major) (be 0 get final product) |
2A-2B | File System Ver (minor) (be 0 get final product) |
2C-2D | File directory head bunch number (being 0x02000) |
2E-2F | The high bit of file directory head bunch number |
30-31 | FSINFO Sector number (, then being 0xffff) if do not have |
32-33 | Backup Boot Sector (, then being 0xffff) if do not have |
34-3F | Keep |
40 | Phisical drive number (first is 0x80, and second is 0x81...) |
41 | Keep |
42 | The feature character (being 0x29) of expansion leader record |
43-46 | Disk sequence number (producing at random) |
47-51 | Label (totally 11 characters) |
52-59 | File system type (being FAT32) |
Below in conjunction with accompanying drawing, describe embodiments of the invention in detail, wherein:
The present invention carries out the format work of disk by the INT 13h that BIOS interrupts, so in order to help following explanation, at first just code 02h, the 03h that INT 13h used in the present invention is interrupted, the function of 08h, and employed register, relevant program function are described as follows:
(1) function 02h: read the disk sector that specifies number
The register that uses: AH 02h (cmd)
The sector number that AL will transmit (nsectd)
The pointer (Buffer) of ES:BX directed towards user disk buffer
CH track number (Track)
CL sector number (Sector)
DH magnetic head number (Head)
DL drive letter (Drive)
After execution, the sector of needs is imported in the memory block.The function of the Borland C Plus Plus that it is corresponding is: and biosdisk (0x02, int drive, int head, int track, sector, int nsects, void * buffer);
(2) function 03h: the specified memory territory is write in the disk of setting
The register that uses: AH 03h (cmd)
The sector number that AL will transmit (nsectd)
The pointer (Buffer) of ES:BX directed towards user disk buffer
CH track number (Track)
CL sector number (Sector)
DH magnetic head number (Head)
DL drive letter (Drive)
The function of the Borland C Plus Plus that it is corresponding is: and biosdisk (0x03, int drive, int head, int track, sector, int nsects, void * buffer);
(3) function 08h: return the designated disk driver for information about
The register that uses: AH 08h
The DL drive letter
The sector number of the every track of return register: CL (low 6)
DH magnetic head number
The function of the Blorand C Plus Plus that it is corresponding is:
union?REGS?inreg,outreg;
unsigned?f,g;
inreg.h.ah=8;
Inreg.h.al=0x80; [annotate: disk number 0x80 represents first disk; 0x81 represents second disk, by that analogy]
int86(0x13,&inreg,&outreg);
f=(outreg.h.cl&63);
g=ooutreg.h.dh+1;
See also Fig. 3, be the disclosed technology of the present invention, its formative treatment step that carries out disk (or disk cut section) is as follows in regular turn:
Step 101, obtain the needed disk parameter of format with an arithmetic logic unit by INT 13h interrupt function 02h, include total sector number an of disk (or disk cut section), one starts the position of record, the type of a disk (or disk cut section) and the numbering of a disk;
Step 102 is called the function 08h that BIOS interrupts NIT 13h with arithmetic logic unit, obtains the sector number (f) and the magnetic head number (g) of every track;
Step 103, (Random) produces a disk sequence number (Volume Serial number) at random;
Step 104, type that judge to carry out the file system of object (as: disk or disk cut section) is FAT16 or FAT32, if FAT16 execution in step 105, if FAT32 execution in step 108 then; Because the disk parameter piece of FAT16 and FAT32 (DPB, Disc Properties Block) difference, so need to handle respectively;
Step 105, obtain the sector number of each bunch, this is when being FAT16 because of file system, sector number in each bunch can increase because of the power form that cut section increases with 2n, see also Fig. 2, be the corresponding situation of the contained sector number 17 of cut section size 16 and each bunch, as shown in FIG., if disk size is between 16MB~127MB, then the contained sector number of each bunch is 4.
Step 106 is according to formula (1), with the size of the sector number of arithmetic logic unit calculation document allocation list; Sfat=(stotal-0x21)/(1+s * 0x100)+1 (1)
Wherein sfat is the sector number of FAT, and stotal is total sector number, and s is every bunch a sector number.And the reckoning process of formula (1) is as follows:
At first, there are 512 characters each sector; Starting the record number is 1; The root directory sector number is 32; Sdata is the sector number of data field.Therefore the total sector number in the disk (or disk cut section) is:
stotal=1+sfat+32+sdata????????????(1-1)
Again, per 2 characters point to bunch of data field among the FAT, so equation is arranged:
sfat×512/2=sdata/s???????????????(1-2)
So (1-2) formula can be expressed as after rearranging:
sdata=sfat×s×256????????????????(1-3)
With formula (1-3) generation time formula (1-1), then can get then
stotal=1+sfat+32+sfat×s×256?????(1-4)
After after arrangement proposes sfat, promptly obtain
sfat=(statal-33)/(1+s×256)+1?????(1-5)
In formula (1-5) because sfat is integer type, so add 1 at last, remedying the fraction part of giving up, so with formulism (1-5) be behind the sexadecimal just calculating formula as shown in Equation (1):
Step 107 is called the function 03h of BIOS interrupt INT 13h with an arithmetic logic unit, and step 106 is calculated the content of the sector of gained, writes to start in the record behind the corresponding position, and skips to step 110;
Step 108 according to formula (2), is calculated the size of FAT sector number with arithmetic logic unit;
sfat=(stotal-0x23)/(1+8×0x080)+1????(2)
Wherein, sfat is the sector number of every FAT, and stotal is total sector number, and s is every bunch a sector number.And the formula of formula (2) calculates that process is as follows:
Because formative object is FAT32 at present, so per 4 characters point to one bunch, each bunch contains 8 sectors.There are 512 characters each sector; Starting record number FAT16 is 3; The sector number of file directory is 32; At first can obtain an equation according to aforementioned data:
sfat×512g=sdata/8?????????????(2-1)
After arrangement, can be expressed as in addition:
sdata=sfat×8×128?????????????(2-2)
With formula (2-2) substitution formula (1-1), then can get
stotal=3+sfat+32+sfat×8×128??(2-3)
Sfat in (2-3) formula of proposition, and rearrange and can get:
sfat=(stotal-35)/(1+8×128)+1??(2-4)
Similarly, in formula (2-4), because sfat is integer type, thus add that at last 1 is the fraction part of giving up in order to mend, so (2-4) formula turned to the calculating formula that just obtains formula (2) behind the sexadecimal.
Step 110, (stotal-2 * sfat-0x20)/8-1 calculates the size of Free Space with formula F ree Space=;
Step 110 is called the function 03h of BIOS interrupt INT 13h with arithmetic logic unit, and step 108 is calculated the content of the sector of gained, writes respectively in three relevant positions that start record;
Step 111 is the content of two file configuration table and file directory clearly zero specifically, for needing a clear t sector altogether, t=sfat * 2+32 wherein, and each file configuration table (FAT) begin to write meadia number, wherein FAT16 is f8ff; And FAT32 is f8ffff0f; And step 112, finish format.
The hard disk of an existing 2G after process " FDISK " instruction is cut apart again, is divided into two logic dividing, is respectively C and D, and wherein, the size of D dish is 1.2G, and when with above-mentioned treatment scheme the D dish being carried out quick formatting, its processing procedure is as follows:
(1) calling BIOS interrupt INT 13h function 02h with arithmetic logic unit obtains with disk and cuts apart
The information that the district is relevant;
With function biosdisk (2,0x80,0,0,1,1, buffer) can obtain following data;
(1) total sector number of disk cut section: 0x259afl
(2) initial head number: 0x01
(3) initial cylinder number: 0x96
(4) initial sector number: 0x01
(5) hard disk sequence number: 08x0 (i.e. first hard disk)
(6) FAT type: 0x0b (being FAT32)
(2) 08h that calls BIOS interrupt INT 13h function with arithmetic logic unit can obtain every track
Contained sector number (f) and magnetic head number (g).
union?REGS?inreg,outreg;
unsigned?f,g;
inreg.h.ah=8;
inreg.h.al=0x80;
in86(0x13,&inreg,&outreg);
f=(outreg.h.cl&63);
g=ooutreg.h.dh+1;
Obtain f=0x3F, G=0xF0;
(3) produce the disk sequence number at random with function random ()
(4) with the sector number of arithmetic logic unit calculation document allocation list:
sfat=(0x259af1-0x21)/(1+8×0x80)+1=0x965
(5) calculate Free Space:
Free?Spage=(0x259af1-2×0x965-0x20)/8-1=0x4b101
(6) call the startup recorded content (totally 3) that BIOS interrupt INT 13h function 03h will calculate with arithmetic logic unit and write 0x01 magnetic head, 0x96 cylinder, place, 0x01 sector.
(7) utilizing circulation is the content of 2 file configuration table and file directory clearly zero, and at each literary composition
Part allocation list section start writes f8ffff0f (media number).
Need a clear t sector, wherein t=sfat * 2+32=4842 altogether
The above only is the preferred embodiments of the present invention, be not limited to implement with the device of above-mentioned hardware, such as anyly be familiar with any modification that this technician is done in the field of the invention, have equal effect, all should contain and be placed in the claim scope of enclosing.