diff options
Diffstat (limited to 'v2.0/bin/FORMAT.DOC')
| -rw-r--r-- | v2.0/bin/FORMAT.DOC | 393 |
1 files changed, 393 insertions, 0 deletions
diff --git a/v2.0/bin/FORMAT.DOC b/v2.0/bin/FORMAT.DOC new file mode 100644 index 0000000..ab47f54 --- /dev/null +++ b/v2.0/bin/FORMAT.DOC | |||
| @@ -0,0 +1,393 @@ | |||
| 1 | FORMAT - formats a new disk, clears the FAT and DIRECTORY | ||
| 2 | and optionally copies the SYSTEM and COMMAND.COM to this | ||
| 3 | new disk. | ||
| 4 | |||
| 5 | Command syntax: | ||
| 6 | |||
| 7 | FORMAT [drive:][/switch1][/switch2]...[/switch16] | ||
| 8 | |||
| 9 | Where "drive:" is a legal drive specification and if | ||
| 10 | omitted indicates that the default drive will be used. | ||
| 11 | There may be up to 16 legal switches included in the | ||
| 12 | command line. | ||
| 13 | |||
| 14 | |||
| 15 | The OEM must supply five (NEAR) routines to the program | ||
| 16 | along with 6 data items. The names of the routines are INIT, | ||
| 17 | DISKFORMAT, BADSECTOR, WRTFAT and DONE, and their flow of | ||
| 18 | control (by the Microsoft module) is like this: | ||
| 19 | |||
| 20 | | | ||
| 21 | +---------+ | ||
| 22 | | INIT | | ||
| 23 | +---------+ | ||
| 24 | | | ||
| 25 | |<------------------------------+ | ||
| 26 | +------------+ | | ||
| 27 | | DISKFORMAT | | | ||
| 28 | +------------+ | | ||
| 29 | |<-------+ | | ||
| 30 | +-----------+ |-This loop is done |- This loop done | ||
| 31 | | BADSECTOR | | for each group of | once for each disk | ||
| 32 | +-----------+ | bad sectors | to be formatted. | ||
| 33 | |----->--+ | If variable HARDFLAG | ||
| 34 | | | is set then the loop | ||
| 35 | +----------+ | is only performed | ||
| 36 | | | | once. | ||
| 37 | | WRTFAT | | | ||
| 38 | +----------+ | | ||
| 39 | | | | ||
| 40 | +------+ | | ||
| 41 | | DONE | | | ||
| 42 | +------+ | | ||
| 43 | +---->--------------------------+ | ||
| 44 | |||
| 45 | The INIT, DISKFORMAT, and BADSECTOR routines are free | ||
| 46 | to use any MS-DOS system calls, except for calls that cause | ||
| 47 | disk accesses on the disk being formatted. DONE may use | ||
| 48 | ANY calls, since by the time it is called the new disk has | ||
| 49 | been formatted. | ||
| 50 | |||
| 51 | The following data must be declared PUBLIC in a module | ||
| 52 | provided by the OEM: | ||
| 53 | |||
| 54 | SWITCHLIST - A string of bytes. The first byte is count | ||
| 55 | N, followed by N characters which are the switches to | ||
| 56 | be accepted by the command line scanner. Alphabetic | ||
| 57 | characters must be in upper case (the numeric | ||
| 58 | characters 0-9 are allowed). The last three switches, | ||
| 59 | normally "O", "V" and "S", have pre-defined meanings. | ||
| 60 | |||
| 61 | The "S" switch is the switch which causes the | ||
| 62 | system files IO.SYS, MSDOS.SYS, and COMMAND.COM to be | ||
| 63 | transfered to the disk after it is formatted thus | ||
| 64 | making a "S"ystem disk. The switch can be some letter | ||
| 65 | other than "S", but the last switch in the list is | ||
| 66 | assumed to have the meaning "transfer system", | ||
| 67 | regardles of what the particular letter is. | ||
| 68 | |||
| 69 | The second to the last switch, "V", causes FORMAT | ||
| 70 | to prompt the user for a volume label after the disk | ||
| 71 | is formatted. Again, as with "S", the particular | ||
| 72 | letter is not important but rather the position in the | ||
| 73 | list. | ||
| 74 | |||
| 75 | The third to the last switch, "O", causes FORMAT to | ||
| 76 | produce an IBM Personal Computer DOS version 1.X | ||
| 77 | compatible disk. Normally FORMAT causes a 0 byte to | ||
| 78 | be placed in the first byte of each directory entry | ||
| 79 | instead of the 0E5 Hex free entry designator. This | ||
| 80 | results in a very marked directory search performance | ||
| 81 | increase due to an optimization in the DOS. Disks | ||
| 82 | made this way cause trouble on IBM PC DOS 1.X | ||
| 83 | versions, however, which did not have this | ||
| 84 | optimization. The 0 byte fools IBM 1.X versions into | ||
| 85 | thinking these entries are allocated instead of free, | ||
| 86 | NOTE that IBM Personnal Computer DOS version 2.00 and | ||
| 87 | MS-DOS version 1.25 will have no trouble with these | ||
| 88 | disks, since they have the same optimization. The "O" | ||
| 89 | switch causes FORMAT to re-do the directory with a 0E5 | ||
| 90 | Hex byte at the start of each entry so that the disk | ||
| 91 | may be used with 1.X versions of IBM PC DOS, as well | ||
| 92 | as MS-DOS 1.25/2.00 and IBM PC DOS 2.00. This switch | ||
| 93 | should only be given when needed because it takes a | ||
| 94 | fair amount of time for FORMAT to perform the | ||
| 95 | conversion, and it noticably decreases 1.25 and 2.00 | ||
| 96 | performance on disks with few directory entries. | ||
| 97 | |||
| 98 | Up to 16 switches are permitted. Normally a "C" | ||
| 99 | switch is specified for "Clear". This switch should | ||
| 100 | cause the formatting operation to be bypassed (within | ||
| 101 | DISKFORMAT or BADSECTOR). This is provided as a | ||
| 102 | time-saving convenience to the user, who may wish | ||
| 103 | to "start fresh" on a previosly formatted and used | ||
| 104 | disk. | ||
| 105 | |||
| 106 | HARDFLAG - BYTE location which specifies whether the | ||
| 107 | OEM routine is formatting a fixed disk or a a drive | ||
| 108 | with removable media. A zero indicates removable | ||
| 109 | media, any other value indicates a fixed disk. The | ||
| 110 | status of this byte only effect the messages printed | ||
| 111 | by the main format module. This value should be | ||
| 112 | set or reset by the OEM supplied INIT routine. | ||
| 113 | |||
| 114 | FATID - BYTE location containing the value to be used | ||
| 115 | in the first byte of the FAT. Must be in the range | ||
| 116 | F8 hex to FF hex. | ||
| 117 | |||
| 118 | STARTSECTOR - WORD location containing the sector number | ||
| 119 | of the first sector of the data area. | ||
| 120 | |||
| 121 | FATSPACE - WORD location containing the address of the | ||
| 122 | start of the FAT area. A FAT built in this area | ||
| 123 | will be written to disk using the OEM supplied WRTFAT | ||
| 124 | subroutine. 6k is sufficient to store any FAT. This | ||
| 125 | area must not overlap the FREESPACE area. | ||
| 126 | |||
| 127 | FREESPACE - WORD location which contains the address | ||
| 128 | of the start of free memory space. This is where | ||
| 129 | the system will be loaded, by the Microsoft module, | ||
| 130 | for transferring to the newly formatted disk. Memory | ||
| 131 | should be available from this address to the end | ||
| 132 | of memory, so it is typically the address of the | ||
| 133 | end of the OEM module. | ||
| 134 | |||
| 135 | The following routines must be declared PUBLIC in the | ||
| 136 | OEM-supplied module: | ||
| 137 | |||
| 138 | INIT - An initialization routine. This routine is called | ||
| 139 | once at the start of the FORMAT run after the switches | ||
| 140 | have been processed. This routine should perform | ||
| 141 | any functions that only need to be done once per | ||
| 142 | FORMAT run. An example of what this routine might | ||
| 143 | do is read the boot sector into a buffer so that | ||
| 144 | it can be transferred to the new disks by DISKFORMAT. | ||
| 145 | If this routine returns with the CARRY flag set it | ||
| 146 | indicates an error, and FORMAT will print "Format | ||
| 147 | failure" and quit. This feature can be used to detect | ||
| 148 | conflicting switches (like specifying both single | ||
| 149 | and double density) and cause FORMAT to quit without | ||
| 150 | doing anything. | ||
| 151 | |||
| 152 | DISKFORMAT - Formats the disk according to the options | ||
| 153 | indicated by the switches and the value of FATID | ||
| 154 | must be defined when it returns (although INIT may | ||
| 155 | have already done it). This routine is called once | ||
| 156 | for EACH disk to be formatted. If neccessary it | ||
| 157 | must transfer the Bootstrap loader. If any error | ||
| 158 | conditions are detected, set the CARRY flag and return | ||
| 159 | to FORMAT. FORMAT will report a 'Format failure' | ||
| 160 | and prompt for another disk. (If you only require | ||
| 161 | a clear directory and FAT then simply setting the | ||
| 162 | appropriate FATID, if not done by INIT, will be all | ||
| 163 | that DISKFORMAT must do.) | ||
| 164 | |||
| 165 | BADSECTOR - Reports the sector number of any bad sectors | ||
| 166 | that may have been found during the formatting of | ||
| 167 | the disk. This routine is called at least once for | ||
| 168 | EACH disk to be formatted, and is called repeatedly | ||
| 169 | until AX is zero or the carry flag is set. The carry | ||
| 170 | flag is used just as in DISKFORMAT to indicate an | ||
| 171 | error, and FORMAT handles it in the same way. The | ||
| 172 | first sector in the data area must be in STARTSECTOR | ||
| 173 | for the returns from this routine to be interpreted | ||
| 174 | correctly. If there are bad sectors, BADSECTOR must | ||
| 175 | return a sector number in in register BX, the number | ||
| 176 | of consecutive bad sectors in register AX, and carry | ||
| 177 | clear. FORMAT will then process the bad sectors | ||
| 178 | and call BADSECTOR again. When BADSECTOR returns | ||
| 179 | with AX = 0 this means there are no more bad sectors; | ||
| 180 | FORMAT clears the directory and goes on to DONE, | ||
| 181 | so for this last return BX need not contain anything | ||
| 182 | meaningful. | ||
| 183 | |||
| 184 | FORMAT processes bad sectors by determining their | ||
| 185 | corresponding allocation unit and marking that unit | ||
| 186 | with an FF7 hex in the File Allocation Table. CHKDSK | ||
| 187 | understands the FF7 mark as a flag for bad sectors | ||
| 188 | and accordingly reports the number of bytes marked | ||
| 189 | in this way. | ||
| 190 | |||
| 191 | NOTE: Actual formatting of the disk can be done in | ||
| 192 | BADSECTOR instead of DISKFORMAT on a "report as you | ||
| 193 | go" basis. Formatting goes until a group of bad | ||
| 194 | sectors is encountered, BADSECTOR then reports them | ||
| 195 | by returning with AX and BX set. FORMAT will then | ||
| 196 | call BADSECTOR again and formatting can continue. | ||
| 197 | |||
| 198 | WRTFAT - This routine is called after the disk is | ||
| 199 | formatted and bad sectors have been reported. Its | ||
| 200 | purpose is to write all copies of the FAT from the | ||
| 201 | area of memory referenced by FATSPACE to the drive | ||
| 202 | just formatted. It may be possible to use INT 26H | ||
| 203 | to perform the write, or a direct BIOS call. Whether | ||
| 204 | this is possible depends on whether the FAT ID byte | ||
| 205 | is used by the BIOS to determine the media in the | ||
| 206 | drive. If it is, these methods will probably fail | ||
| 207 | because there is no FAT ID byte on the disk yet (in | ||
| 208 | this case WRTFATs primary job is to get the FAT ID | ||
| 209 | byte out on the disk and thus solve the chicken and | ||
| 210 | egg problem). | ||
| 211 | |||
| 212 | DONE - This routine is called after the formatting is | ||
| 213 | complete, the disk directory has been initialized, | ||
| 214 | and the system has been transferred. It is called | ||
| 215 | once for EACH disk to be formatted. This gives the | ||
| 216 | chance for any finishing-up operations, if needed. | ||
| 217 | If the OEM desires certain extra files to be put | ||
| 218 | on the diskette by default, or according to a switch, | ||
| 219 | this could be done in DONE. Again, as in BADSECTOR | ||
| 220 | and DISKFORMAT, carry flag set on return means an | ||
| 221 | error has occurred: 'Format failure' will be printed | ||
| 222 | and FORMAT will prompt for another disk. | ||
| 223 | |||
| 224 | |||
| 225 | The following data is declared PUBLIC in Microsoft's FORMAT | ||
| 226 | module: | ||
| 227 | |||
| 228 | SWITCHMAP - A word with a bit vector indicating what | ||
| 229 | switches have been included in the command line. The | ||
| 230 | correspondence of the bits to the switches is | ||
| 231 | determined by SWITCHLIST. The right-most | ||
| 232 | (highest-addressed) switch in SWITCHLIST (which must | ||
| 233 | be the system transfer switch, normally "S") | ||
| 234 | corresponds to bit 0, the second from the right, | ||
| 235 | normally "V" to bit 1, etc. For example, if | ||
| 236 | SWITCHLIST is the string "7,'AGI2OVS'", and the user | ||
| 237 | specifies "/G/S" on the command line, then bit 6 will | ||
| 238 | be 0 (A not specified), bit 5 will be 1 (G specified), | ||
| 239 | bits 4,3,2 and 1 will be 0 (neither I,2,O or V | ||
| 240 | specified), and bit 0 will be 1 (S specified). | ||
| 241 | |||
| 242 | Bits 0,1 and 2 are the only switches used in | ||
| 243 | Microsoft's FORMAT module. These switches are used 1) | ||
| 244 | after INIT has been called, to determine if it is | ||
| 245 | necessary to load the system; 2) after the last | ||
| 246 | BADSECTOR call, to determine if the system is to be | ||
| 247 | written, E5 directory conversion is to be done, and/or | ||
| 248 | a volume label is to be asked for. INIT may force | ||
| 249 | these bits set or reset if desired (for example, some | ||
| 250 | drives may never be used as system disk, such as hard | ||
| 251 | disks). After INIT, the "S" bit may be turned off | ||
| 252 | (but not on, since the system was never read) if | ||
| 253 | something happens that means the system should not be | ||
| 254 | transferred. | ||
| 255 | |||
| 256 | After INIT, a second copy of SWITCHMAP is made | ||
| 257 | internally which is used to restore SWITCHMAP for | ||
| 258 | each disk to be formatted. FORMAT itself will turn | ||
| 259 | off the system bit if bad sectors are reported in | ||
| 260 | the system area; DISKFORMAT and BADSECTOR are also | ||
| 261 | allowed to change the map. However, these changes | ||
| 262 | affect only the current disk being formatted, since | ||
| 263 | SWITCHMAP is restored after each disk. (Changes | ||
| 264 | made to SWITCHMAP by INIT do affect ALL disks.) | ||
| 265 | |||
| 266 | DRIVE - A byte containing the drive specified in the | ||
| 267 | command line. 0=A, 1=B, etc. | ||
| 268 | |||
| 269 | Once the OEM-supplied module has been prepared, it must linked | ||
| 270 | with Microsoft's FORMAT.OBJ module and the FORMES.OBJ module. | ||
| 271 | If the OEM-supplied module is called OEMFOR.OBJ, then the | ||
| 272 | following linker command will do: | ||
| 273 | |||
| 274 | LINK FORMAT FORMES OEMFOR; | ||
| 275 | |||
| 276 | This command will produce a file called FORMAT.EXE. FORMAT | ||
| 277 | has been designed to run under MS-DOS as a simple binary | ||
| 278 | .COM file. This conversion is performed by LOCATE (EXE2BIN) | ||
| 279 | with the command | ||
| 280 | |||
| 281 | LOCATE FORMAT.EXE FORMAT.COM | ||
| 282 | |||
| 283 | which will produce the file FORMAT.COM. | ||
| 284 | |||
| 285 | ;***************************************** | ||
| 286 | ; | ||
| 287 | ; A Sample OEM module | ||
| 288 | ; | ||
| 289 | ;***************************************** | ||
| 290 | |||
| 291 | CODE SEGMENT BYTE PUBLIC 'CODE' | ||
| 292 | ; This segment must be | ||
| 293 | ; named CODE, it must be | ||
| 294 | ; PUBLIC, and it's | ||
| 295 | ; classname must be 'CODE' | ||
| 296 | |||
| 297 | |||
| 298 | ASSUME CS:CODE,DS:CODE,ES:CODE | ||
| 299 | |||
| 300 | ; Must declare data and routines PUBLIC | ||
| 301 | |||
| 302 | PUBLIC FATID,STARTSECTOR,SWITCHLIST,FREESPACE | ||
| 303 | PUBLIC INIT,DISKFORMAT,BADSECTOR,DONE,WRTFAT | ||
| 304 | PUBLIC FATSPACE,HARDFLAG | ||
| 305 | |||
| 306 | ; This data defined in Microsoft-supplied module | ||
| 307 | |||
| 308 | EXTRN SWITCHMAP:WORD,DRIVE:BYTE | ||
| 309 | |||
| 310 | INIT: | ||
| 311 | |||
| 312 | ; Read the boot sector into memory | ||
| 313 | CALL READBOOT | ||
| 314 | ... | ||
| 315 | ; Set FATID to double sided if "D" switch specified | ||
| 316 | TEST SWITCHMAP,10H | ||
| 317 | JNZ SETDBLSIDE | ||
| 318 | ... | ||
| 319 | RET | ||
| 320 | |||
| 321 | DISKFORMAT: | ||
| 322 | ... | ||
| 323 | |||
| 324 | ; Use the bit map in SWITCHMAP to determine | ||
| 325 | ; what switches are set | ||
| 326 | |||
| 327 | TEST SWITCHMAP,8 ;Is there a "/C"? | ||
| 328 | JNZ CLEAR ; Yes -- clear operation | ||
| 329 | ; requested jump around the | ||
| 330 | ; format code | ||
| 331 | < format the disk > | ||
| 332 | CLEAR: | ||
| 333 | ... | ||
| 334 | ; Transfer the boot from memory to the new disk | ||
| 335 | CALL TRANSBOOT | ||
| 336 | ... | ||
| 337 | RET | ||
| 338 | |||
| 339 | ; Error return - set carry | ||
| 340 | |||
| 341 | ERRET: | ||
| 342 | STC | ||
| 343 | RET | ||
| 344 | |||
| 345 | BADSECTOR: | ||
| 346 | ... | ||
| 347 | RET | ||
| 348 | |||
| 349 | |||
| 350 | WRTFAT: | ||
| 351 | ... | ||
| 352 | |||
| 353 | WRTFATLOOP: | ||
| 354 | < Set up call to write out a fat to disk> | ||
| 355 | ... | ||
| 356 | MOV BX,[FATSPACE] | ||
| 357 | |||
| 358 | < Write out one fat to disk> | ||
| 359 | JC ERRET | ||
| 360 | ... | ||
| 361 | < Decrement fat counter > | ||
| 362 | JNZ WRTFATLOOP | ||
| 363 | CLC ;Good return | ||
| 364 | RET | ||
| 365 | |||
| 366 | |||
| 367 | DONE: | ||
| 368 | ... | ||
| 369 | RET | ||
| 370 | |||
| 371 | ; Default Single sided | ||
| 372 | FATID DB 0FEH | ||
| 373 | |||
| 374 | HARDFLAG DB 0 | ||
| 375 | |||
| 376 | STARTSECTOR DW 9 | ||
| 377 | |||
| 378 | SWITCHLIST DB 5,"DCOVS" ; "OVS" must be the last | ||
| 379 | ; switches in the list | ||
| 380 | |||
| 381 | FATSPACE DW FATBUF | ||
| 382 | |||
| 383 | FREESPACE DW ENDBOOT | ||
| 384 | |||
| 385 | BOOT DB BOOTSIZE DUP(?) ; Buffer for the | ||
| 386 | ; boot sector | ||
| 387 | |||
| 388 | FATBUF DB 6 * 1024 DUP(?) ; Fat buffer | ||
| 389 | ENDBOOT LABEL BYTE | ||
| 390 | |||
| 391 | CODE ENDS | ||
| 392 | END | ||
| 393 | |||