home *** CD-ROM | disk | FTP | other *** search
/ For Beginners & Professional Hackers / cd.iso / docum / hadware.doc / chapter.008 < prev    next >
Encoding:
Text File  |  1992-03-15  |  70.9 KB  |  1,555 lines

  1.                                     -200-
  2.  
  3.    **  Programmer's  Technical    Reference  for    MSDOS  and  the  IBM  PC **
  4. ─────────────────────────┤ Registered User Version ├───────────────────────────
  5.              not for public distribution
  6.          Copyright (c) 1987, 1988, 1989 Dave Williams
  7.  
  8.  
  9.                C H A P T E R   E I G H T
  10.  
  11.  
  12.                  DOS DISK INFORMATION
  13.  
  14.  
  15.                 C O N T E N T S
  16.  
  17. The DOS Area .......................................................... 8**1
  18. The Boot Record ....................................................... 8**2
  19. DOS File Allocation Table (FAT) ....................................... 8**3
  20.     Media Descriptor Byte ......................................... 8**4
  21.     12 Bit FATs ................................................... 8**5
  22.     16 Bit FATs ................................................... 8**6
  23.     32 Bit FATs ................................................... 8**7
  24. DOS Disk Directory .................................................... 8**8
  25. The Data Area ......................................................... 8**9
  26. Floppy Disk Types ..................................................... 8**10
  27. Hard Disk Layout ...................................................... 8**11
  28. System Initialization ................................................. 8**12
  29. Boot Record/Partition Table ........................................... 8**13
  30. Hard Disk Technical Information ....................................... 8**14
  31. Determining Hard Disk File Allocation ................................. 8**15
  32. BIOS Disk Functions ................................................... 8**16
  33.     00h  Reset
  34.     01h  Get Status
  35.     02h  Read Sectors
  36.     03h  Write Sectors
  37.     04h  Verify
  38.     05h  Format Track (floppy disk)
  39.     06h  Hard Disk - format track
  40.     07h  Hard Disk - format drive
  41.     08h  Read Drive Parameters
  42.     09h  Initialize Two Fixed Disk Base Tables
  43.     0Ah  Read Long (Hard disk)
  44.     0Bh  Write Long (Hard disk)
  45.     0Ch  Seek To Cylinder
  46.     0Dh  Alternate Hard Disk Reset
  47.     0Eh  Read Sector Buffer
  48.     0Fh  Write sector buffer
  49.     10h  Test For Drive Ready
  50.     11h  Recalibrate Drive
  51.     12h  Controller RAM Diagnostic
  52.     13h  Controller Drive Diagnostic
  53.     14h  Controller Internal Diagnostic
  54.     15h  Get Disk Type
  55.     16h  Get Disk Change Status (diskette)
  56.     17h  Set Disk Type for Format (diskette)
  57.     18h  Set Media Type For Format (diskette)
  58.     19h  Park Hard Disk Heads
  59.     1Ah  ESDI Hard Disk - Low Level Format
  60.     1Bh  ESDI Hard Disk - Get Manufacturing Header
  61.     1Ch  ESDI Hard Disk - Get Configuration
  62.  
  63.                                     -201-
  64.  
  65.  
  66. THE DOS AREA├────────────────────────────────────────────────────────── 8**1
  67.  
  68.  All disks and diskettes formatted by DOS are created with a sector size of 512
  69. bytes. The DOS area (entire area for a diskette, DOS partition for hard disks)
  70. is formatted as follows:
  71.  
  72.     ┌────────────────────────────────────────────────────────────┐
  73.     │            D O S    A R E A              │
  74.     ├────────────────────────────────────────────────────────────┤
  75.     │ partition table       - variable size (hard disk only)  │
  76.     │ boot record           - 1 sector                 │
  77.     │ first copy of the FAT    - variable size             │
  78.     │ second copy of the FAT   - same size as first copy         │
  79.     │ root directory       - variable size             │
  80.     │ data area           - variable depending on disk size │
  81.     └────────────────────────────────────────────────────────────┘
  82.  
  83. The following sections describe each of the allocated areas:
  84.  
  85.  
  86.  
  87. THE BOOT RECORD├─────────────────────────────────────────────────────── 8**2
  88.  
  89.  The boot record resides on track 0, sector 1, side 0 of every diskette
  90. formatted by the DOS FORMAT program. For hard disks the boot record resides on
  91. the first sector of the DOS partition. It is put on all disks to provide an
  92. error message if you try to start up with a nonsystem disk in drive A:. If the
  93. disk is a system disk, the boot record contains a JMP instruction pointing to
  94. the first byte of the operating system.
  95.  
  96.  If the device is IBM compatible, it must be true that the first sector of the
  97. first FAT is located at the same sector for all possible media. This is
  98. because the FAT sector is read before the media is actually determined.
  99.  The information relating to the BPB for a particular media is kept in the boot
  100. sector for the media. In particular, the format of the boot sector is:
  101.  
  102. ┌──────────────────────────────────────────────────────────────────────────────┐
  103. │             D O S     B O O T   R E C O R D                   │
  104. ├───┬───────┬──────────────────────────────────────────────────────────────────┤
  105. │00h│3 bytes│  JMP to executable code. For DOS 2.x, 3 byte near jump (0E9h).   │
  106. │   │        │  For DOS 3.x, 2 byte near jump (0EBh) followed by a NOP (90h)    │
  107. ├───┼───────┼──────────────────────────────────────────────────────────────────┤
  108. │03h│8 bytes│  optional OEM name and version  (such as IBM 2.1)            │
  109. ├───┼───────┼─────┬────────────────────────────────────────────────────────────┤
  110. │0Dh│ byte  │      │  sectors per allocation unit (must be a power of 2)        │
  111. ├───┼───────┤      ├────────────────────────────────────────────────────────────┤
  112. │0Eh│2 bytes│  B  │  reserved sectors (starting at logical sector 0)           │
  113. ├───┼───────┤      ├────────────────────────────────────────────────────────────┤
  114. │10h│ byte  │      │  number of FATs                           │
  115. ├───┼───────┤      ├────────────────────────────────────────────────────────────┤
  116. │11h│2 bytes│      │  maximum number of root directory entries               │
  117. ├───┼───────┤      ├────────────────────────────────────────────────────────────┤
  118. │13h│2 bytes│  P  │  number of sectors in logical image (total number of       │
  119. │   │        │      │  sectors in media, including boot sector directories, etc.)│
  120. │   │        │      │  If logical disk size is geater than 32Mb, this value is 0 │
  121. │   │        │      │  and the actual size is reported at offset 26h           │
  122. ├───┼───────┤      ├────────────────────────────────────────────────────────────┤
  123. │15h│ byte  │  B  │  media descriptor byte                       │
  124. ├───┼───────┤      ├────────────────────────────────────────────────────────────┤
  125. │16h│2 bytes│      │  number of sectors occupied by a single FAT            │
  126. └───┴───────┴─────┴────────────────────────────────────────────────────────────┘
  127.  
  128.                                     -202-
  129.  
  130. ┌───┬───────┬──────────────────────────────────────────────────────────────────┐
  131. │18h│2 bytes│  sectors per track                           │
  132. ├───┼───────┼──────────────────────────────────────────────────────────────────┤
  133. │1Ah│2 bytes│  number of heads                               │
  134. ├───┼───────┼──────────────────────────────────────────────────────────────────┤
  135. │1Ch│2 bytes│  number of hidden sectors                        │
  136. └───┴───────┼──────────────────────────────────────────────────────────────────┤
  137.         │             EXTENDED BOOT RECORD (DOS 4.0+)               │
  138. ┌───┬───────┼──────────────────────────────────────────────────────────────────┤
  139. │1Eh│2 bytes│  number of sectors per track                       │
  140. ├───┼───────┼──────────────────────────────────────────────────────────────────┤
  141. │20h│2 bytes│  number of heads                               │
  142. ├───┼───────┼──────────────────────────────────────────────────────────────────┤
  143. │22h│2 bytes│  number of hidden sectors                        │
  144. ├───┼───────┼──────────────────────────────────────────────────────────────────┤
  145. │26h│4 bytes│  total number of sectors in media (32MB or larger indicated here)│
  146. ├───┼───────┼──────────────────────────────────────────────────────────────────┤
  147. │27h│ byte  │  physical drive number                           │
  148. ├───┼───────┼──────────────────────────────────────────────────────────────────┤
  149. │28h│ byte  │  reserved                                │
  150. ├───┼───────┼──────────────────────────────────────────────────────────────────┤
  151. │29h│ byte  │  extended boot record signature                       │
  152. ├───┼───────┼──────────────────────────────────────────────────────────────────┤
  153. │30h│4 bytes│  volume serial number (assigned with a random function)           │
  154. ├───┼───────┼──────────────────────────────────────────────────────────────────┤
  155. │34h│11bytes│  volume label                               │
  156. ├───┼───────┼──────────────────────────────────────────────────────────────────┤
  157. │3Fh│8 bytes│  reserved                                │
  158. └───┴───────┴──────────────────────────────────────────────────────────────────┘
  159.  
  160.  The three words at the end return information about the media. The number of
  161. heads is useful for supporting different multihead drives that have the same
  162. storage capacity but a different number of surfaces. The number of hidden
  163. sectors is useful for drive partitioning schemes.
  164.  
  165.  DOS 3.2 uses a table called the BIOS Parameter Block (BPB) to determine if a
  166. disk has a valid File Allocation Table. The BPB is located in the first sector
  167. of a floppy disk. Although the BPB is supposed to be on every formatted floppy
  168. disk, some earlier versions of DOS did not create a BPB and instead assumed that
  169. the FAT begins at the second sector of the disk and that the first FAT byte
  170. (Media Descriptor Byte) describes the disk format.
  171.  DOS 3.2 reads in the whole of the BPB and tries to use it - although strangely
  172. enough, it seems as if DOS is prepared to cope with a BPB that is more or less
  173. totally blank (it seems to ignore the descriptor byte and treat it as a DSDD
  174. 9-sector disk).
  175.  DOS 3.2 determines if a disk has a valid boot sector by examining the first
  176. byte of logical sector 0. If that byte it a jump instruction 0E9h, DOS 3.2
  177. assumes the rest of the sector is a valid boot sector with a BPB. If the first
  178. byte is not 0E9h DOS 3.2 behaves like previous versions, assumes the boot sector
  179. is invalid and uses the first byte of the FAT to determine the media type.
  180.  If the first byte on the disk happens to be 0E9h, but the disk does not have a
  181. BPB, DOS 3.2 will return a disk error message.
  182.  The real problems occur if some of the BPB data is valid and some isn't.
  183. Apparently some OEMs have assumed that DOS would continue to ignore the
  184. formatting data on the disk, and have failed to write much there during FORMAT
  185. except the media descriptor byte (or, worse, have allowed random junk to be
  186. written there). While this error is understandable, and perhaps even
  187. forgiveable, it remains their problem, not IBMs, since the BPB area has always
  188. been documented as containing the format information that IBM DOS 3.2 now
  189. requires to be there.
  190.  
  191.                                     -203-
  192.  
  193. THE DOS FILE ALLOCATION TABLE (FAT)├─────────────────────────────────── 8**3
  194.  
  195.  The File Allocation Table, or FAT, has three main purposes:
  196.     1) to mark bad sectors on the media
  197.     2) to determine which sectors are free for use
  198.     3) to determine the physical location(s) of a file on the media.
  199.  DOS uses one of four different schemes for defining the File Allocation Table:
  200.     1) a 12-bit FAT, for DOS 1.x, 2.x, all floppies, and small hard disks
  201.     2) a 16-bit FAT, for DOS 3.x+ hard disks from 16.8 to 32Mb
  202.     3) a 32-bit FAT, for Compaq DOS 3.31 for over-32MB logical drives
  203.     4) a 32-bit FAT, for DOS 4.0 for over-32Mb logical drives
  204.  
  205.  This section explains how DOS uses the FAT to convert the clusters of a file
  206. into logical sector numbers. It is recommended that system utilities use the
  207. DOS handle calls rather than interpreting the FAT, particularly since
  208. aftermarket disk partitioning or formatting software may have been used.
  209.  
  210.  The FAT is used by DOS to allocate disk space for files, one cluster at a time.
  211. In DOS 4.0, clusters are referred to as "allocation units." It means the same
  212. things; the smallest logical portion of a drive.
  213.  
  214.  The FAT consists of a 12 bit entry (1.5 bytes) for each cluster on the disk or
  215. a 16 bit (2 bytes) entry when a hard disk has more than 20740 sectors as is the
  216. case with fixed disks larger than 10Mb.
  217.  
  218.  The first two FAT entries map a portion of the directory; these FAT entries
  219. contain indicators of the size and format of the disk. The FAT can be in a 12
  220. or 16 bit format. DOS determines whether a disk has a 12 or 16 bit FAT by
  221. looking at the total number of allocation units on a disk. For all diskettes
  222. and hard disks with DOS partitions less than 20,740 sectors, the FAT uses a 12
  223. bit value to map a cluster. For larger partitions, DOS uses a 16 bit value.
  224.  
  225.  The second, third, and fourth bit applicable for 16 bit FAT bytes always
  226. contains 0FFFFh. The first byte is used as follows:
  227.  
  228. Media Descriptor Byte ................................................. 8**4
  229.  
  230. ┌──────────────────────────────────────────────────────────────────────────────┐
  231. │          M E D I A    D E S C R I P T O R    B Y T E               │
  232. ├──────────┬──────────────────────────────────┬────────────────────────────────┤
  233. │hex value │          meaning          │     normally used           │
  234. ├──────────┼──────────────────────────────────┼────────────────────────────────┤
  235. │    00    │ hard disk                  │ 3.3+ extended DOS partition    │
  236. ├──────────┼──────────────────────────────────┼────────────────────────────────┤
  237. │    ED    │ double sided  9 sector 80 track  │ Tandy 2000 720k 5¼ floppy      │
  238. ├──────────┼──────────────────────────────────┼────────────────────────────────┤
  239. │    F0    │ double sided  18 sector diskette │ PS/2 1.44 meg DSHD           │
  240. ├──────────┼──────────────────────────────────┼────────────────────────────────┤
  241. │    F8    │ hard disk                  │ bootable hard disk at C:800    │
  242. ├──────────┼──────────────────────────────────┼────────────────────────────────┤
  243. │    F9    │ double sided  15 sector diskette │ AT 1.2 meg DSHD            │
  244. │       │ double sided  9  sector diskette │ Convertible 720k DSQD           │
  245. ├──────────┼──────────────────────────────────┼────────────────────────────────┤
  246. │    FA    │ IBM Displaywriter System disk    │ 287k                   │
  247. ├──────────┼──────────────────────────────────┼────────────────────────────────┤
  248. │    FB    │ IBM Displaywriter System disk    │ 1 meg                   │
  249. ├──────────┼──────────────────────────────────┼────────────────────────────────┤
  250. │    FC    │ single sided  9  sector diskette │ DOS 2.0, 180k SSDD           │
  251. ├──────────┼──────────────────────────────────┼────────────────────────────────┤
  252. │    FD    │ double sided  9  sector diskette │ DOS 2.0, 360k DSDD           │
  253. ├──────────┼──────────────────────────────────┼────────────────────────────────┤
  254. │    FE    │ single sided  8  sector diskette │ DOS 1.0, 160k SSDD           │
  255. ├──────────┼──────────────────────────────────┼────────────────────────────────┤
  256. │    FF    │ double sided  8  sector diskette │ DOS 1.1, 320k SSDD           │
  257. └──────────┴──────────────────────────────────┴────────────────────────────────┘
  258.  
  259.                                     -204-
  260.  
  261. ┌──────────────────────┐
  262. │for 8 inch diskettes: │
  263. ├──────────┬───────────┴──────────────────────┬────────────────────────────────┐
  264. │    FD    │ double sided  26 sector diskette │ IBM 3740 format DSSD           │
  265. ├──────────┼──────────────────────────────────┼────────────────────────────────┤
  266. │    FE    │ single sided  26 sector diskette │ IBM 3740 format SSSD           │
  267. │       ├──────────────────────────────────┼────────────────────────────────┤
  268. │       │ double sided  8  sector diskette │ IBM 3740 format DSDD           │
  269. └──────────┴──────────────────────────────────┴────────────────────────────────┘
  270.  
  271.  
  272. The third FAT entry begins mapping the data area (cluster 002).
  273.  
  274. NOTE: These values are provided as a reference. Therefore, programs should not
  275.       make use of these values.
  276.  
  277.  Each entry contains a hexadecimal character (or 4 for 16 bit FATs). ()
  278. indicates the high order four bit value in the case of 16 bit FAT entries.
  279. They can be:
  280.  
  281.         (0)000h  if the cluster is unused and availible
  282.  
  283. (0F)FF8h - (0F)FFFh  to indicate the last cluster of a file
  284.  
  285.         (X)XXXh  any other hexadecimal numbers that are the cluster number
  286.              of the next cluster in the file. The cluster number is the
  287.              first cluster in the file that is kept in the file's
  288.              directory entry.
  289.  
  290.  The values (0F)FF0h - (0F)FF7h are used to indicate reserved clusters.
  291. (0F)FF7h indicates a bad cluster if it is not part of the allocation chain.
  292. (0F)FF8h - (0F)FFFh are used as end of file markers.
  293.  
  294.  The file allocation table always occupies the sector or sectors immediately
  295. following the boot record. If the FAT is larger than 1 sector, the sectors
  296. occupy consecutive sector numbers. Two copies of the FAT are written, one
  297. following the other, for integrity. The FAT is read into one of the DOS buffers
  298. whenever needed (open, allocate more space, etc).
  299.  
  300.  
  301.  
  302. 12 Bit File Allocation Table .......................................... 8**5
  303.  
  304. Obtain the starting cluster of the file from the directory entry.
  305.  
  306. Now, to locate each subsequent sector of the file:
  307.  
  308. 1. Multiply the cluster number just used by 1.5 (each FAT entry is 1.5
  309.    bytes long).
  310. 2. The whole part of the product is offset into the FAT, pointing to the entry
  311.    that maps the cluster just used. That entry contains the cluster number of
  312.    the next cluster in the file.
  313. 3. Use a MOV instruction to move the word at the calculated FAT into a register.
  314. 4. If the last cluster used was an even number, keep the low order 12 bits of
  315.    the register, otherwise, keep the high order 12 bits.
  316. 5. If the resultant 12 bits are (0FF8h-0FFFh) no more clusters are in the file.
  317.    Otherwise, the next 12 bits contain the cluster number of the next cluster in
  318.    the file.
  319.  
  320.   To convert the cluster to a logical sector number (relative sector, such as
  321. that used by int 25h and 26h and DEBUG):
  322.  
  323. 1. Subtract 2 from the cluster number
  324. 2. Multiply the result by the number of sectors per cluster.
  325. 3. Add the logical sector number of the beginning of the data area.
  326.  
  327. 12-bit FAT if DOS partition is smaller than 32,680 sectors (16.340 MB).
  328.  
  329.                                     -205-
  330.  
  331.  
  332. 16 Bit File Allocation Table .......................................... 8**6
  333.  
  334.  Obtain the starting cluster of the file from the directory entry. Now to
  335. locate each subsequent cluster of the file:
  336.  
  337. 1.  Multiply the cluster number used by 2 (each FAT entry is 2 bytes long).
  338. 2.  Use the MOV word instruction to move the word at the calculated FAT offset
  339.     into a register.
  340. 3.  If the resultant 16 bits are (0FF8h-0FFFFh) no more clusters are in the
  341.     file. Otherwise, the 16 bits contain the cluster number of the next cluster
  342.     in the file.
  343.  
  344.  Compaq DOS makes availible a new disk type (6) with 32 bit partition values,
  345. allowing 512 megabytes per hard disk (Compaq DOS 3.3.1)
  346.  
  347.  
  348.  
  349. 32 Bit File Allocation Table .......................................... 8**7
  350.  
  351.  DOS 4.0's FORMAT program checks the size of the availible media. If the total
  352. number of 8 sector clusters is less than 4086 (not 4096) a 12 bit FAT is used.
  353.  
  354.  
  355.  
  356. DOS Disk Directory .................................................... 8**8
  357.  
  358.  The FORMAT command initially builds the root directory for all disks. Its
  359. location (logical sector number) and the maximum number of entries are
  360. availible through the device driver interfaces.
  361.  
  362.  Since directories other than the root directory are actually files, there is
  363. no limit to the number of entries that they may contain.
  364.  
  365.  All directory entries are 32 bytes long, and are in the following format:
  366. ┌───────┬─────────┬────────────────────────────────────────────────────────────
  367. │offset │  size   │             DISK DIRECTORY ENTRY
  368. ├───────┼─────────┼────────────────────────────────────────────────────────────
  369. │  00h    │ 8 bytes │ Filename
  370. │    ├─────────┴────────────────────────────────────────────────────────────
  371. │    │ The first byte of the filename indicates the file status.
  372. │    │ The file status byte may contain the following values:
  373. │    ├──────┬───────────────────────────────────────────────────────────────
  374. │    │  00h │ Directory entry has never been used. This is used to limit
  375. │    │      │ the length of directory searches, for performance reasons.
  376. │    │  05h │ Indicates that the first character of the filename actually
  377. │    │      │ has an 0EDh character.
  378. │    │ 0E5h │ Filename has been used but the file has been erased.
  379. │    │  2Eh │ This entry is for a directory. If the second byte is also
  380. │    │      │ 2Eh, the cluster field contains the cluster number of this
  381. │    │      │ directory's parent directory. (0000h if the parent directory
  382. │    │      │ is the root directory). Otherwise, bytes 00h-0Ah are all
  383. │    │      │ spaces and the cluster field contains the cluster number of
  384. │    │      │ the directory.
  385. │    ├──────┴───────────────────────────────────────────────────────────────
  386. │    │ Any other character is the first character of a filename. Filenames
  387. │    │ are left-aligned and if nescessary padded with blanks.
  388. ├───────┼─────────┬────────────────────────────────────────────────────────────
  389. │  08h    │ 3 bytes │ Filename extension if any
  390. │    ├─────────┴────────────────────────────────────────────────────────────
  391. │    │ Three characters, left-aligned and padded with blanks if necessary.
  392. │    │ If there is no file extension, this field contains all blanks
  393. └───────┴──────────────────────────────────────────────────────────────────────
  394.  
  395.                                     -206-
  396. ┌───────┬─────────┬────────────────────────────────────────────────────────────
  397. │  0Bh    │ 1 byte  │ File attributes
  398. │    ├─────────┴────────────────────────────────────────────────────────────
  399. │    │       The attribute byte is mapped as follows:
  400. │    ├─────┬───┬────────────────────────────────────────────────────────────
  401. │    │ hex │bit│               meaning
  402. │    ├─────┼───┼────────────────────────────────────────────────────────────
  403. │    │ 00h │   │ (no bits set) normal; can be read or written without
  404. │    │     │   │ restriction
  405. │    │ 01h │ 0 │ file is marked read-only. An attempt to open the file for
  406. │    │     │   │ output using int 21h/fn 3Dh will fail and an error code
  407. │    │     │   │ will be returned. This value can be used with other values
  408. │    │     │   │ below.
  409. │    │ 02h │ 1 │ indicates a hidden file. The file is excluded from normal
  410. │    │     │   │ directory searches.
  411. │    │ 04h │ 2 │ indicates a system file. The file is excluded from normal
  412. │    │     │   │ directory searches.
  413. │    │ 08h │ 3 │ indicates that the entry contains the volume label in the
  414. │    │     │   │ first 11 bytes. The entry has no other usable information
  415. │    │     │   │ and may exist only in the root directory.
  416. │    │ 10h │ 4 │ indicates that the file is a subdirectory
  417. │    │ 20h │ 5 │ indicates an archive bit. This bit is set to on whenever
  418. │    │     │   │ the file is written to and closed. Used by BACKUP and
  419. │    │     │   │ RESTORE.
  420. │    │     │ 6 │ reserved, set to 0
  421. │    │     │ 7 │ reserved, set to 0
  422. │    ├─────┴───┴────────────────────────────────────────────────────────────
  423. │    │ note 1) Bits 6 and 7 may be used in OS/2.
  424. │    │ note 2) Attributes 08h and 10h cannot be changed using int21/43h.
  425. │    │ note 3) The system files IBMBIO.COM and IBMDOS.COM (or customized
  426. │    │      equivalent) are marked as read-only, hidden, and system
  427. │    │      files. Files can be marked hidden when they are created.
  428. │    │ note 4) Read-only, hidden, system and archive attributes may be
  429. │    │      changed with int21h/fn43h.
  430. ├───────┼─────────┬────────────────────────────────────────────────────────────
  431. │  0Ch    │ 10 bytes│ Reserved by DOS; value unknown
  432. ├───────┼─────────┼────────────────────────────────────────────────────────────
  433. │  16h    │ 2 bytes │ File timestamp
  434. │    ├─────────┴────────────────────────────────────────────────────────────
  435. │    │ These bytes contain the time when the file was created or last
  436. │    │  updated. The time is mapped in the bits as follows:
  437. │    ├───────────────────────────────┬───────────────────────────────┐
  438. │    │      B Y T E   16h     │      B Y T E   17h     │
  439. │    ├───────────────────────────────┼───────────────────────────────┤
  440. │    │ F   E   D   C   B   A   9   8 │ 7   6   5   4   3   2   1   0 │
  441. │    ├───────────────────┬───────────┴───────────┬───────────────────┤
  442. │    │ H   H   H   H   H │ M   M   M   M   M   M │ D   D   D   D   D │
  443. │    ├───────────────────┼───────────────────────┼───────────────────┤
  444. │    │ binary # hrs 0-23 │ binary # minutes 0-59 │ bin. # 2-sec incr │
  445. │    ├───────────────────┴───────────────────────┴───────────────────┘
  446. │    │ note: The time is stored with the least significant byte first.
  447. ├───────┼─────────┬────────────────────────────────────────────────────────────
  448. │  18h    │ 2 bytes │ File datestamp
  449. │    ├─────────┴────────────────────────────────────────────────────────────
  450. │    │ This area contains the date when the file was created or last
  451. │    │ updated. The mm/dd/yy are mapped in the bits as follows:
  452. │    ├───────────────────────────────┬───────────────────────────────┐
  453. │    │      B Y T E   18h     │      B Y T E   19h     │
  454. │    ├───────────────────────────────┼───────────────────────────────┤
  455. │    │ F   E   D   C   B   A   9   8 │ 7   6   5   4   3   2   1   0 │
  456. │    ├───────────────────────────┬───┴───────────┬───────────────────┤
  457. │    │ Y   Y   Y   Y   Y   Y   Y │ M   M   M   M │ D   D   D   D   D │
  458. │    ├───────────────────────────┼───────────────┼───────────────────┤
  459. │    │     0-119 (1980-2099)     │      1-12        │        1-31    │
  460. │    ├───────────────────────────┴───────────────┴───────────────────┘
  461. │    │ note: The date is stored with the least significant byte first.
  462. └───────┴──────────────────────────────────────────────────────────────────────
  463.  
  464.                                     -207-
  465.  
  466. ┌───────┬─────────┬────────────────────────────────────────────────────────────
  467. │  1Ah    │ 2 bytes │ First file cluster number
  468. │    ├─────────┴────────────────────────────────────────────────────────────
  469. │    │ * (reserved in DOS 2, documented in DOS 3+)
  470. │    │ This area contains the starting cluster number of the first cluster
  471. │    │ in the file. The first cluster for data space on all fixed disks and
  472. │    │ floppy disks is always cluster 002. The cluster number is stored
  473. │    │ with the least significant byte first.
  474. ├───────┼─────────┬────────────────────────────────────────────────────────────
  475. │  1Ch    │ 4 bytes │ File size
  476. │    ├─────────┴────────────────────────────────────────────────────────────
  477. │    │ This area contains the file size in bytes. The first word contains
  478. │    │ the low order part of the size. Both words are stored with the least
  479. │    │ significant byte first.
  480. └───────┴──────────────────────────────────────────────────────────────────────
  481.  
  482.  
  483.  
  484. The Data Area ......................................................... 8**9
  485.  
  486.  Allocation of space for a file (in the data area) is done only when needed
  487. (it is not preallocated). The space is allocated one cluser (unit allocation)
  488. at a time. A cluster is always one or more consecutive sector numbers, and all
  489. of the clusters in a file are "chained" together in the FAT.
  490.  
  491.  The clusters are arranged on disk to minimize head movement for multisided
  492. media. All of the space on a track (or cylinder) is allocated before moving
  493. on to the next track. This is accomplished by using the sequential sector
  494. numbers on the lowest-numbered head, then all the sector numbers on the next
  495. head, and so on until all sectors of all heads of the track are used. Then the
  496. next sector used will be sector 1 of head 0 on the next track.
  497.  
  498.  An interesting innovation that was introduced in MS-DOS 3.0: disk space that
  499. is freed by erasing a file is not re-used immediately, unlike earlier versions
  500. of DOS. Instead, free space is obtained from the area not yet used during the
  501. current session, until all of it is used up. Only then will space that is freed
  502. during the current session be re-used.
  503.  
  504.  This feature minimizes fragmentation of files, since never-before-used space
  505. is always contiguous. However, once any space has been freed by deleting a file,
  506. that advantage vanishes at the next system boot. The feature also greatly
  507. simplifies un-erasing files, provided that the need to do an un-erase is found
  508. during the same session and also provided that the file occupies contiguous
  509. clusters.
  510.  
  511.  However, when one is using programs which make extensive use of temporary
  512. files, each of which may be created and erased many times during a session,
  513. the feature becomes a nuisance; it forces the permanent files to move farther
  514. and farther into the inner tracks of the disk, thus increasing rather than
  515. decreasing the amount of fragmentation which occurs.
  516.  
  517.  The feature is implemented in DOS by means of a single 16-bit "last cluster
  518. used" (LCU) pointer for each physical disk drive; this pointer is a part of
  519. the physical drive table maintained by DOS. At boot time, the LCU pointer is
  520. zeroed. Each time another cluster is obtained from the free-space pool (the
  521. FAT), its number is written into the LCU pointer. Each time a fresh cluster
  522. is required, the FAT is searched to locate a free one; in older versions of
  523. DOS this search always began at Cluster 0000, but in 3.x it begins at the
  524. cluster pointed to by the LCU pointer.
  525.  
  526.  For hard disks, the size of the file allocation table and directory are
  527. determined when FORMAT initializes it and are based on the size of the DOS
  528. partition.
  529.  
  530.                                     -208-
  531.  
  532.  
  533. Floppy Disk Types ..................................................... 8**10
  534.  
  535. The following tables give the specifications for floppy disk formats:
  536.  
  537. IBM PC-DOS disk formats:
  538.          # of       FAT size   DIR     total
  539.          sides      (sectors)(entries) sectors
  540.            │  sectors  │  DIR  │ sectors│
  541.            │  /track   │sectors│/cluster│
  542.            │     │     │   │   │   │    │
  543. ┌─────┬──┬───────┬─┴─┬───┴───┬─┴─┬─┴─┬─┴─┬─┴─┬──┴─┬────────────────────────────
  544. │ 160k│5¼│DOS 1.0│ 1 │ 8 (40)│ 1 │ 4 │ 64│ 1 │ 320│Original PC-0, 16k mbd
  545. │ 320k│5¼│DOS 1.1│ 2 │ 8 (40)│ 1 │ 7 │112│ 2 │ 360│PC-1, 64k mbd
  546. │ 180k│5¼│DOS 2.0│ 1 │ 9 (40)│ 2 │ 4 │ 64│ 1 │ 640│PC-2, 256k mbd
  547. │ 360k│5¼│DOS 2.0│ 2 │ 9 (40)│ 2 │ 7 │112│ 2 │ 720│PC/XT
  548. │ 1.2M│5¼│DOS 3.0│ 2 │15 (80)│ 7 │14 │224│ 1 │2400│PC/AT, PC/RT, XT/286
  549. │ 720k│3½│DOS 3.2│ 2 │ 9 (80)│ 3 │ 7 │112│ 2 │1440│Convertible, PS/2 25+
  550. │1.44M│3½│DOS 3.3│ 2 │18 (80)│ 9 │14 │224│ 1 │2880│PS/2 50+
  551. └─────┴──┴───────┴───┴───────┴───┴───┴───┴───┴────┴────────────────────────────
  552. various MS-DOS disk formats:
  553. ┌─────┬──┬───────┬─┴─┬───┴───┬─┴─┬─┴─┬─┴─┬─┴─┬──┴─┬────────────────────────────
  554. │ 200k│5¼│  *     │ 1 │10 (40)│     │   │     │   │      │
  555. │ 400k│5¼│  * ** │ 2 │10 (40)│     │   │     │   │      │
  556. │ 800k│5¼│  *     │ 2 │10 (80)│     │   │     │   │      │
  557. │ 720k│2 │     │   │         │     │   │     │   │      │Zenith SuperSport 2-inch
  558. │ 720k│5¼│DOS2.11│ 2 │ 9 (80)│ 3 │ 7 │112│ 2 │1440│Tandy 2000 (discontinued)
  559. └─────┴──┴───────┴───┴───────┴───┴───┴───┴───┴────┴────────────────────────────
  560. *  Michtron DS-DOS 2.11 Plus and one version of MS-DOS 3.11 (vendor unknown)
  561. ** TallTree JFormat program
  562. ┌─────┬──┬───────┬─┴─┬───┴───┬─┴─┬─┴─┬─┴─┬─┴─┬──┴─┬────────────────────────────
  563. │ 400k│5¼│DOS2.11│ 1 │10 (80)│     │   │     │   │ 800│DEC Rainbow    SS/HD    (disc.)
  564. │ 720k│5¼│DOS2.11│ 2 │variable number of sectors  │Victor 9000 PC   (discont'd)
  565. └─────┴──┴───────┴───┤per track, more sectors on  ├────────────────────────────
  566.              │outer tracks than inner      │
  567.              │tracks. Special DSDD drive. │
  568.              └────────────────────────────┘
  569.  
  570.  Some oddball DOS versions specify "zero" heads in their data area. HP's
  571. single-sided disk format (16 256-byte sectors/track, model unknown) uses a
  572. zero-based parameter for the number of heads. Without special device driver
  573. software to "fix" this, these disks are basically unusable by normal DOS.
  574.  
  575.  Files in the data area are not necessarily written sequentially. The data area
  576. space is allocated one cluster at a time, skipping over clusters already
  577. allocated. The first free cluster found is the next cluster allocated,
  578. regardless of its physical location on the disk. This permits the most efficient
  579. utilization of disk space because clusters freed by erasing files can be
  580. allocated for new files. Refer back to the description of the DOS FAT in this
  581. chapter for more information.
  582.  
  583.     SSDD    single sided, double density    (160-180k)     5¼
  584.     DSDD    double sided, double density    (320-360k)     5¼
  585.     DSQD    double sided, quad density    (720k)           5¼, 3½
  586.     DSHD    double sided, high density    (1.2-1.44M)    5¼, 3½
  587.  
  588.  Much of the trouble with AT 1.2 meg drives has been through the inadverdent
  589. use of quad density disks in the high density drives. The high density disks
  590. use a higher-coercivity media than the quads, and quads are not completely
  591. reliable as 1.2Mb. Make sure you have the correct disk for your application.
  592. Oddly, I have had no trouble punching an ID hole and using 720k microfloppies
  593. as 1.44 Mb microfloppies. Caveat emptor, however.
  594.  
  595.                                     -209-
  596.  
  597.  
  598. HARD DISK LAYOUT ...................................................... 8**11
  599.  
  600.  The DOS hard disk routines perform the following services:
  601.  
  602. 1) Allow multiple operating systems to be installed on the hard disk at the
  603.    same time.
  604.  
  605. 2) Allow a user-selected operating system to be started from the hard disk.
  606.  
  607.    I) In order to share the hard disk among operating systems, the disk may be
  608.       logically divided into 1 to 4 partitions. The space within a given
  609.       partition is contiguous, and can be dedicated to a specific operating
  610.       system. Each operating system may "own" only one partition in DOS versions
  611.       2.0 through 3.2. DOS 3.3 introduced the "Extended DOS Partition" which
  612.       allows multiple DOS partitions on the same hard disk. FDISK (or a
  613.       similar program from other DOS vendors) utility allows the user to select
  614.       the number, type, and size of each partition. The partition information is
  615.       kept in a partition table that is embedded in the master hard disk boot
  616.       record on the first sector of the disk. The format of this table varies
  617.       from version to version of DOS.
  618.  
  619.   II) An operating system must consider its partition to be the entire disk,
  620.       and must ensure that its functions and utilities do not access other
  621.       partitions on the disk.
  622.  
  623.  III) Each partition may contain a boot record on its first sector, and any
  624.       other programs or data that you choose, including a different operating
  625.       system. For example, the DOS FORMAT command may be used to format and
  626.       place a copy of DOS in the DOS partition in the same manner that a
  627.       diskette is formatted. You can use FDISK to designate a partition as
  628.       "active" (bootable). The master hard disk boot record causes that
  629.       partition's boot record to receive control when the system is
  630.       initialized. Additional disk partitions could be FORTH, UNIX, Pick,
  631.       CP/M-86, OS/2, or the UCSD p-System.
  632.  
  633.  
  634.  
  635. SYSTEM INITIALIZATION ................................................. 8**12
  636.  
  637. The boot sequence is as follows:
  638.  
  639. 1. System initialization first attempts to load an operating system from
  640.    diskette drive A. If the drive is not ready or a read error occurs, it then
  641.    attempts to read a master hard disk boot record on the first sector of the
  642.    first hard disk in the system. If unsuccessful, or if no hard disk is
  643.    present, it invokes ROM BASIC in an IBM PC or displays a disk error
  644.    message on most compatibles.
  645.  
  646. 2. If initialization is successful, the master hard disk boot record is given
  647.    control and it examines the partition table embedded within it. If one of
  648.    the entries indicates an active (bootable) partition, its boot record is
  649.    read from the partition's first sector and given control.
  650.  
  651. 3. If none of the partitions is bootable, ROM BASIC is invoked on an IBM PC or
  652.     a disk error on most compatibles.
  653.  
  654. 4. If any of the boot indicators are invalid, or if more than one indicator is
  655.    marked as bootable, the message "INVALID PARTITION TABLE "is displayed and
  656.    the system stops.
  657.  
  658. 5. If the partition's boot record cannot be successfully read within five
  659.    retries due to read errors, the message "ERROR LOADING OPERATING SYSTEM"
  660.    appears and the system stops.
  661.  
  662.                                     -210-
  663.  
  664. 6. If the partition's boot record does not contain a valid "signature", the
  665.    message "MISSING OPERATING SYSTEM" appears, and the system stops.
  666.  
  667. NOTE: When changing the size or location of any partition, you must ensure that
  668.       all existing data on the disk has been backed up. The partitioning program
  669.       will destroy the data on the disk.
  670.  
  671.  System programmers designing a utility to initialize/manage a hard disk must
  672. provide the following functions at a minimum:
  673.  
  674. 1. Write the master disk boot record/partition table to the disk's first
  675.    sector to initialize it.
  676.  
  677. 2. Perform partitioning of the disk - that is, create or update the partition
  678.    table information (all fields for the partition) when the user wishes
  679.    to create a partition. This may be limited to creating a partition for only
  680.    one type of operating systewm, but must allow repartitoning the entire disk,
  681.    or adding a partition without interfering with existing partitions (user's
  682.    choice).
  683.  
  684. 3. Provide a means for marking a user-specified partition as bootable and
  685.    resetting the bootable indicator bytes for all other partitions at the same
  686.    time.
  687.  
  688. 4. Such utilities should not change or move any partition information that
  689.    belongs to another operating system.
  690.  
  691.  
  692.  
  693.  
  694. BOOT RECORD/PARTITION TABLE ........................................... 8**13
  695.  
  696.  A boot record must be written on the first sector of all hard disks, and
  697. must contain the following:
  698.  
  699. 1. Code to load and give control to the boot record for one of four possible
  700.    operating systems.
  701.  
  702. 2. A partition table at the end of the boot record. Each table entry is 16
  703.    bytes long, and contains the starting and ending cylinder, sector, and head
  704.    for each of four possible partitions, as well as the number of sectors
  705.    preceding the partition and the number of sectors occupied by the partition.
  706.    The "boot indicator" byte is used by the boot record to determine if one of
  707.    the partitions contains a loadable operating system. FDISK initialization
  708.    utilities mark a user-selected partition as "bootable" by placing a value
  709.    of 80h in the corresponding partition's boot indicator (setting all other
  710.    partitions' indicators to 0 at the same time). The presence of the 80h tells
  711.    the standard boot routine to load the sector whose location is contained in
  712.    the following three bytes. That sector is the actual boot record for the
  713.    selected operating system, and it is responsible for the remainder of the
  714.    system's loading process (as it is from the diskette). All boot records are
  715.    loaded at absolute address 0:7C00.
  716.  
  717.                                     -211-
  718.  
  719. The partition table with its offsets into the boot record is:
  720. (except for Wyse DOS 3.2 with 32 bit allocation table, and DOS 3.3-up)
  721. ┌──────┬────────┬──────────────────┬──────────┬──────────┬──────────┬──────────┐
  722. │Offset│Partit'n│     Purpose       │          │   Head     │  Sector  │ Cylinder │
  723. ├──────┼────────┼──────────────────┼──────────┼──────────┼──────────┼──────────┤
  724. │ 1BEh │ part 1 │ begins       │ boot ind │    H     │    S     │    cyl    │
  725. ├──────┼────────┼──────────────────┼──────────┼──────────┼──────────┼──────────┤
  726. │ 1C2h │    │ ends           │ syst ind │    H     │    S     │    cyl    │
  727. ├──────┤    ├──────────────────┼──────────┴──────────┼──────────┴──────────┤
  728. │ 1C6h │    │ relative sector  │      low word     │    high word      │
  729. ├──────┤    ├──────────────────┼─────────────────────┼─────────────────────┤
  730. │ 1CAh │    │ # sectors       │      low word     │    high word      │
  731. ├──────┼────────┼──────────────────┼──────────┬──────────┼──────────┬──────────┤
  732. │ 1CEh │ part 2 │ begins       │ boot ind │    H     │    S     │    cyl    │
  733. ├──────┤    ├──────────────────┼──────────┼──────────┼──────────┼──────────┤
  734. │ 1D2h │    │ ends           │ syst ind │    H     │    S     │    cyl    │
  735. ├──────┤    ├──────────────────┼──────────┴──────────┼──────────┴──────────┤
  736. │ 1D6h │    │ relative sector  │      low word     │    high word      │
  737. ├──────┤    ├──────────────────┼─────────────────────┼─────────────────────┤
  738. │ 1DAh │    │ # sectors       │      low word     │    high word      │
  739. ├──────┼────────┼──────────────────┼──────────┬──────────┼──────────┬──────────┤
  740. │ 1DEh │ part 3 │ begins       │ boot ind │    H     │    S     │    cyl    │
  741. ├──────┤    ├──────────────────┼──────────┼──────────┼──────────┼──────────┤
  742. │ 1E2h │    │ ends           │ syst ind │    H     │    S     │    cyl    │
  743. ├──────┤    ├──────────────────┼──────────┴──────────┼──────────┴──────────┤
  744. │ 1E6h │    │ relative sector  │      low word     │    high word      │
  745. ├──────┤    ├──────────────────┼─────────────────────┼─────────────────────┤
  746. │ 1EAh │    │ # sectors       │      low word     │    high word      │
  747. ├──────┼────────┼──────────────────┼──────────┬──────────┼──────────┬──────────┤
  748. │ 1EEh │ part 4 │ begins       │ boot ind │    H     │    S     │    cyl    │
  749. ├──────┤    ├──────────────────┼──────────┼──────────┼──────────┼──────────┤
  750. │ 1F2h │    │ ends           │ syst ind │    H     │    S     │    cyl    │
  751. ├──────┤    ├──────────────────┼──────────┴──────────┼──────────┴──────────┤
  752. │ 1F6h │    │ relative sector  │      low word     │    high word      │
  753. ├──────┤    ├──────────────────┼─────────────────────┼─────────────────────┤
  754. │ 1FAh │    │ # sectors       │      low word     │    high word      │
  755. ├──────┼────────┴──────────────────┼──────────┬──────────┼─────────────────────┘
  756. │ 1FEh │     signature       │  hex 55  │  hex AA  │
  757. └──────┴───────────────────────────┴──────────┴──────────┘
  758.  
  759.  Boot indicator (boot ind): The boot indicator byte must contain 0 for a non-
  760. bootable partition or 80h for a bootable partition. Only one partition can be
  761. marked as bootable at a time.
  762.  
  763.  System Indicator (sys ind): The sys ind field contains an indicator of the
  764. operating system that "owns" the partition. IBM PC-DOS can only "own" one
  765. partition, though some versions of MSDOS allow all four partitions to be used
  766. by DOS.
  767.  
  768.                                     -212-
  769.  
  770.  The system indicators are:
  771.  
  772.     ┌─────────────────────────────────────────────────────────────┐
  773.     │          System Indicator  (sys ind)              │
  774.     ├───────┬─────────────────────────────────────────────────────┤
  775.     │  00h    │  unknown or unspecified                  │
  776.     ├───────┼─────────────────────────────────────────────────────┤
  777.     │  01h    │  DOS 12 bit FAT  (DOS 2.x all and 3.x under 10 Mb)  │
  778.     │    │           less than 4086 clusters          │
  779.     ├───────┼─────────────────────────────────────────────────────┤
  780.     │  04h    │  DOS 16 bit FAT  (DOS 3.0+. Not recognized by 2.x)  │
  781.     │    │           less than 65,536 sectors          │
  782.     ├───────┼─────────────────────────────────────────────────────┤
  783.     │  05h    │  extended DOS partition, some 3.2 and all 3.3+      │
  784.     ├───────┼─────────────────────────────────────────────────────┤
  785.     │  06h    │  Compaq and DRI DOS 3.31 partitions over 32 megs    │
  786.     ├───────┼─────────────────────────────────────────────────────┤
  787.     │  0DBh │  DRI Concurrent DOS                      │
  788.     ├───────┼─────────────────────────────────────────────────────┤
  789.     │  0F2h │  2nd DOS partition, some 3.2                  │
  790.     └───────┴─────────────────────────────────────────────────────┘
  791.  
  792.  There are bytes for XENIX, and other operating systems. Some manufacturers
  793. (such as Zenith, Wyse, and Tandon) diddle with these system bytes to implement
  794. more than one DOS partition per disk.
  795.  
  796.  
  797.  Cylinder (CYL) and Sector (S): The 1 byte fields labelled CYL contain the low
  798. order 8 bits of the cylinder number - the high order 2 bits are in the high
  799. order 2 bits of the sector (S) field. This corresponds with the ROM BIOS
  800. interrupt 13h (disk I/O) requirements, to allow for a 10 bit cylinder number.
  801.  
  802.  The fields are ordered in such a manner that only two MOV instructions are
  803. required to properly set up the DX and CX registers for a ROM BIOS call to
  804. load the appropriate boot record (hard disk booting is only possible from the
  805. first hard disk in the system, where a BIOS drive number of 80h corresponds
  806. to the boot indicator byte).
  807.  
  808.  All partitions are allocated in cylinder multiples and begin on sector 1,
  809. head 0, with the exception that the partition that is allocated at the beginning
  810. of the disk starts at sector 2, to account for the hard disk's master boot
  811. record.
  812.  
  813.  Relative Sector (rel sect): The number of sectors preceding each partition
  814. on the disk is kept in the 4 byte field labelled "rel sect". This value is
  815. obtained by counting the sectors beginning with cylinder 0, sector 1, head 0
  816. of the disk, and incrementing the sector, head, and then track values up to
  817. the beginning of the partition. This, if the disk has 17 sectors per track and
  818. 4 heads, and the second partition begins at cylinder 1, sector 1, head 0,and
  819. the partition's starting relative sector is 68 (decimal) - there were 17
  820. sectors on each of 4 heads on 1 track allocated ahead of it. The field is stored
  821. with the least significant word first.
  822.  
  823.  Number of sectors (#sects): The number of sectors allocated to the partition
  824. is kept in the "# of sects" field. This is a 4 byte field stored least
  825. significant word first.
  826.  
  827.  Signature: The last 2 bytes of the boot record (55AAh) are used as a signature
  828. to identify a valid boot record. Both this record and the partition boot record
  829. are required to contain the signature at offset 1FEh.
  830.  
  831.                                     -213-
  832.  
  833.  
  834. HARD DISK TECHNICAL INFORMATION ....................................... 8**14
  835.  
  836.  Western Digital's hard disk installation manuals make the claim that MSDOS
  837. can support only 2 hard drives. This is entirely false, and their purpose for
  838. making the claim is unclear. DOS merely performs a function call pointed at
  839. the hard disk driver, which is normally in one of three locations; a ROM at
  840. absolute address C:800, the main BIOS ROM if the machine is an AT, or a device
  841. driver installed through the CONFIG.SYS file. Two hard disk controller cards
  842. can normally not reside in the same machine due to lack of interrupt
  843. arbitration. Perstor's ARLL controller and some cards marketed by Novell can
  844. coexist with other controllers. Perstor's technical department has had four
  845. controllers and eight hard disks in the same IBM XT functioning concurrently.
  846.  
  847.  A valid hard disk has a boot record arranged in the following manner:
  848.  
  849.     db    drive        ; 0 or 80h  (80h marks a bootable, active
  850.                          partition)
  851.     db    head1        ; starting head
  852.     dw    trksec1     ; starting track/sector (CX value for INT 13)
  853.     db    system        ; SYS IND ID from table above
  854.     db    head2        ; ending head
  855.     dw    trksec2     ; ending track/sector
  856.     dd    sector1     ; absolute # of starting sector
  857.     dd    sector2     ; absolute # of last sector
  858.  
  859.  The master disk boot record invokes ROM BASIC if no indicator byte reflects a
  860. bootable system.
  861.  
  862.  When a partition's boot record is given control, it is passed its partition
  863. table entry address in the DS:SI registers.
  864.  
  865.  
  866.  
  867. DETERMINING HARD DISK ALLOCATION ...................................... 8**15
  868.  
  869. DOS determines disk allocation using the following formula:
  870.  
  871.                      D * BPD
  872.                 TS - RS -  ───────────
  873.                        BPS
  874.               SPF = ──────────────────────────────
  875.                     BPS * SPC
  876.                  CF + ──────────────
  877.                        BPC
  878. where:
  879.  
  880.      TS      Total number of sectors on the disk
  881.      RS      The number of sectors at the beginning of the disk that are
  882.          reserved for the boot record. DOS normally reserves 1 sector.
  883.      D         The number of directory entries in the root directory.
  884.      BPD     The number of bytes per directory entry. This is always 32.
  885.      BPS     The number of bytes per logical sector. Typically 512, but you can
  886.          specify a different number with VDISK.
  887.      CF      The number of FATS per disk. Usually 2. VDISK is 1.
  888.      SPF     The number of sectors per FAT. Maximum 64.
  889.      SPC     The number of sectors per allocation unit (cluster).
  890.      BPC     The number of bytes per FAT entry. BPC is 1.5 for 12 bit FATs.
  891.          2 for 16 bit FATS.
  892.  
  893.                                     -214-
  894.  
  895. To calculate the minimum partition size that will force a 16-bit FAT:
  896.  
  897.     CYL = (max clusters * 8)/(HEADS * SPT)
  898.  
  899. where:
  900.      CYL       number of cylinders on the disk
  901.      max clusters  4092 (maximum number of clusters for a 12 bit FAT)
  902.      HEADS       number of heads on the hard disk
  903.      SPT       sectors per track  (normally 17 on MFM)
  904.  
  905.  
  906.  DOS 2.0 uses a "first fit" algorithm when allocating file space on the hard
  907. disk. Each time an application requests disk space, it will scan from the
  908. beginning of the FAT until it finds a contiguous peice of storage large enough
  909. for the file.
  910.  
  911.  DOS 3.0 keeps a pointer into the disk space, and begins its search from the
  912. point it last left off. This pointer is lost when the system is rebooted.
  913. This is called the "next fit" algorithm. It is faster than the first fit and
  914. helps minimize fragmentation.
  915.  
  916.  In either case, if the FCB function calls are used instead of the handle
  917. function calls, the file will be broken into pieces starting with the first
  918. availible space on the disk.
  919.  
  920.  
  921. ┌─────────────────────────────────────────────────────────────────────────────┐
  922. │Interrupt 13h    Disk I/O - access the disk drives (floppy and hard disk)      │
  923. └─────────────────────────────────────────────────────────────────────────────┘
  924. (0:004Ch)    1) These calls do not try rereading disk if an error is returned
  925.          2) In the IBM OS/2 Tech Ref Volume 1, page 7-33, under "DOS
  926.         Environment Software Interrupt Support", it lists:
  927.         13h  disk/diskette     for non-removable media only, these
  928.                        functions are supported:
  929.                        01h     read status
  930.                        02h     read sectors
  931.                        0Ah     read long
  932.                        15h     read DASD (disk) type
  933.  
  934.  
  935. Function 00h    Reset - reset the disk controller chip
  936. entry    AH    00h
  937.     DL    drive (if bit 7 is set both hard disks and floppy disks reset)
  938.         00h-7Fh  floppy disk
  939.         80h-0FFh hard disk
  940. return    AH    status (see 01h below)
  941. note 1) Forces controller chip to recalibrate read/write heads.
  942.      2) Some systems (Sanyo 55x, Columbia MPC) this resets all drives.
  943.      3) This function should be called after a failed floppy disk Read, Write,
  944.     Verify, or Format request before retrying the operation.
  945.      4) If called with DL >= 80h (i.e., selecting a hard drive), the floppy
  946.     controller and then the hard disk controller are reset.
  947.      5) Function 0Dh allows the hard disk controller to be reset without
  948.     affecting the floppy controller.
  949.  
  950.                                     -215-
  951.  
  952. Function 01h    Get Status of Disk System
  953. entry    AH    01h
  954.     DL    drive (hard disk if bit 7 set)
  955.         00h-7Fh  floppy disk
  956.         80h-0FFh hard disk
  957. return    AH    00h
  958.     AL    status of most recent disk operation
  959.         00h    successful completion, no errors
  960.         01h    bad command
  961.         02h    address mark not found
  962.         03h    tried to write on write-protected disk      (floppy only)
  963.         04h    sector not found
  964.         05h    reset failed                    (hard disk)
  965.         06h    diskette removed or changed          (floppy only)
  966.         07h    bad parameter table                (hard disk)
  967.         08h    DMA overrun                  (floppy only)
  968.         09h    attempt to DMA across 64K boundary
  969.         0Ah    bad sector detected                (hard disk)
  970.         0Bh    bad track detected                (hard disk)
  971.         0Ch    unsupported track or media type not found (floppy disk)
  972.         0Dh    invalid number of sectors on format        (hard disk)
  973.         0Eh    control data address mark detected        (hard disk)
  974.         0Fh    DMA arbitration level out of range        (hard disk)
  975.         10h    uncorrectable CRC/EEC on read
  976.         11h    ECC corrected data error            (hard disk)
  977.         20h    controller failure
  978.         40h    seek failed
  979.         80h    timeout
  980.         0AAh    drive not ready                 (hard disk)
  981.         0BBh    undefined error                 (hard disk)
  982.         0CCh    write fault                    (hard disk)
  983.         0E0h    status error                    (hard disk)
  984.         0FFh    sense operation failed                (hard disk)
  985. note    For hard disks, error code 11h (ECC data error) indicates that a
  986.     recoverable error was detected during a preceding int 13h fn 02h
  987.     (Read Sector) call.
  988.  
  989.  
  990. Function 02h    Read Sectors - read one or more sectors from diskette
  991. entry    AH    02h
  992.     AL    number of sectors to read
  993.     BX    address of buffer (ES=segment)
  994.     CH    track (cylinder) number (0-39 or 0-79 for floppies)
  995.         (for hard disk, bits 8,9 in high bits of CL)
  996.     CL    sector number (1 to 18, not value checked)
  997.     DH    head number (0 or 1)
  998.     DL    drive (0=A, 1=B, etc.) (bit 7=0)  (drive 0-7)
  999.         00h-7Fh   floppy disk
  1000.         80h-FF0h  hard disk
  1001.     ES:BX    address to store/fetch data  (buffer to fill)
  1002.        [0000:0078]  dword pointer to diskette parameters
  1003. return    CF    0    successful
  1004.             AL    number of sectors transferred
  1005.         1    error
  1006.             AH    status    (00h, 02h, 03h, 04h, 08h, 09h, 10h,
  1007.                      0Ah, 20h, 40h, 80h)
  1008. note 1) Number of sectors begins with 1, not 0.
  1009.      2) Trying to read zero sectors is considered a programming error; results
  1010.     are not defined.
  1011.      3) For hard disks, the upper 2 bits of the 10-bit cylinder number are
  1012.     placed in the upper 2 bits of register CL.
  1013.      4) For hard disks, error code 11h indicates that a read error occurred
  1014.     that was corrected by the ECC algorithm; in this case, AL contains the
  1015.     burst length. The data read is good within the limits of the ECC code.
  1016.     If a multisector transfer was requested, the operation was terminated
  1017.     after the sector containing the read error.
  1018.  
  1019.                                     -216-
  1020.  
  1021.      5) For floppy drives, an error may result from the drive motor being off
  1022.     at the time of the request. The BIOS does not automatically wait for
  1023.     the drive to come up to speed before attempting the read operation. The
  1024.     calling program should reset the floppy disk system with function 00h
  1025.     and retry the operation three times before assuming that the error
  1026.     results from some other cause.
  1027.  
  1028.  
  1029. Function 03h    Write Sectors - write from memory to disk
  1030. entry    AH    03h
  1031.     AL    number of sectors to write (1-8)
  1032.     CH    track number (for hard disk, bits 8,9 in high bits of CL)
  1033.     CL    beginning sector number
  1034.         (if hard disk, high two bits are high bits of track #)
  1035.     DH    head number
  1036.     DL    drive number (0-7)
  1037.         00h-7Fh   floppy disk
  1038.         80h-FF0h  hard disk
  1039.     ES:BX    address of buffer for data
  1040. return    CF    0    success
  1041.         AL    number of sectors written
  1042.         1    error
  1043.         AH    status (see 01h above)
  1044. note 1) Number of sectors begins with 1, not 0.
  1045.      2) Trying to write zero sectors is considered a programming error; results
  1046.     are not defined.
  1047.      3) For hard disks, the upper 2 bits of the 10-bit cylinder number are
  1048.     placed in the upper 2 bits of register CL.
  1049.      4) For floppy drives, an error may result from the drive motor being off
  1050.     at the time of the request. The BIOS does not automatically wait for
  1051.     the drive to come up to speed before attempting the read operation. The
  1052.     calling program should reset the floppy disk system with function 00h
  1053.     and retry the operation three times before assuming that the error
  1054.     results from some other cause.
  1055.  
  1056.  
  1057. Function 04h    Verify - verify that a write operation was successful
  1058. entry    AH    04h
  1059.     AL    number of sectors to verify (1-8)
  1060.     CH    track number  (for hard disk, bits 8,9 in high bits of CL)
  1061.     CL    beginning sector number
  1062.     DH    head number
  1063.     DL    drive number (0-7)
  1064.     DL    drive number (0-7)
  1065.         00h-7Fh   floppy disk
  1066.         80h-FF0h  hard disk
  1067.     ES:BX    address of buffer for data
  1068. return    CF    set on error
  1069.         AH    status (see 01h above)
  1070.     AL    number of sectors verified
  1071. note 1) With IBM PC, XT, and AT with ROM BIOS earlier than 11/15/85, ES:BX
  1072.     should point to a valid buffer.
  1073.      2) For hard disks, the upper 2 bits of the 10-bit cylinder number are
  1074.     placed in the upper 2 bits of register CL.
  1075.      3) This function can be used to test whether a readable media is in a
  1076.     floppy drive. An error may result from the drive motor being off at the
  1077.     time of the request since the BIOS does not automatically wait for the
  1078.     drive to come up to speed before attempting the verify operation. The
  1079.     requesting program should reset the floppy disk system with function
  1080.     00h and retry the operation three times before assuming that a readable
  1081.     disk is not present.
  1082.  
  1083.                                     -217-
  1084.  
  1085. Function 05h    Format Track - write sector ID bytes for 1 track (floppy disk)
  1086. entry    AH    05h
  1087.     AL    number of sectors to create on this track
  1088.         interleave (for XT hard disk only)
  1089.     CH    track (or cylinder) number (bits 8,9 in high bits of CL)
  1090.     CL    sector number
  1091.     DH    head number (0, 1)
  1092.     DL    drive number (0-3)
  1093.         00h-7Fh   floppy disk
  1094.         80h-0FFh  hard disk
  1095.     ES:BX    pointer to 4-byte address field (C-H-R-N) (except XT hard disk)
  1096.         byte 1 = (C) cylinder or track
  1097.         byte 2 = (H) head
  1098.         byte 3 = (R) sector
  1099.         byte 4 = (N) bytes/sector (0 = 128, 1 = 256, 2 = 512, 3 = 1024)
  1100. return    CF    set if error occurred
  1101.         AH    status code (see 01h above)
  1102. note 1) Not valid for ESDI hard disks on PS/2.
  1103.      2) For floppy disks, the number of sectors per track is taken from the
  1104.     BIOS floppy disk parameter table whose address is stored in the vector
  1105.     for int 1Eh.
  1106.      3) When this function is used for floppies on ATs or the PS/2, it should
  1107.     be preceded by a call to int 13h/fn 17h to select the type of media to
  1108.     format.
  1109.      4) For hard disks, the upper 2 bits of the 10-bit cylinder number are
  1110.     placed in the upper 2 bits of CL.
  1111.      5) On the XT/286, AT, and PS/2 hard disks, ES:BX points to a 512-byte
  1112.     buffer containing byte pairs for each physical disk sector as follows:
  1113.     Byte  Contents
  1114.     0    00h    good sector
  1115.         80h    bad sector
  1116.     1    sector number
  1117.     For example, to format a track with 17 sectors and an interleave of
  1118.     two, ES:BX would point to the following 34-byte array at the beginning
  1119.     of a 512-byte buffer:
  1120.     db    00h, 01h, 00h, 0Ah, 00h, 02h, 00h, 0Bh, 00h, 03h, 00h, 0Ch
  1121.     db    00h, 04h, 00h, 0Dh, 00h, 05h, 00h, 0Eh, 00h, 06h, 00h, 0Fh
  1122.     db    00h, 07h, 00h, 10h, 00h, 08h, 00h, 11h, 00h, 09h
  1123.  
  1124.  
  1125. Function 06h    Hard Disk - format track and set bad sector flags
  1126.                              (PC2, PC-XT, and Portable)
  1127. entry    AH    06h
  1128.     AL    interleave value (XT only)
  1129.     CH    cylinder number (bits 8,9 in high bits of CL)
  1130.     CL    sector number
  1131.     DH    head
  1132.     DL    drive (80h-0FFh for hard disk)
  1133.     ES:BX    512 byte format buffer
  1134.         the first 2*(sectors/track) bytes contain f,n for each sector
  1135.         f    00h    good sector
  1136.             80h    bad sector
  1137.         n    sector number
  1138. return    CF    error
  1139.         AH    status code (see 01h above)
  1140.  
  1141.                                     -218-
  1142.  
  1143. Function 07h    Hard Disk - format the drive starting at the desired track
  1144.                               (PC2, PC-XT and Portable)
  1145. entry    AH    07h
  1146.     AL    interleave value (XT only) (01h-10h)
  1147.     CH    cylinder number (bits 8,9 in high bits of CL) (00h-03FFh)
  1148.     CL    sector number
  1149.     DH    head number (0-7)
  1150.     DL    drive number (80h-0FFh, 80h=C, 81h=D,...)
  1151.     ES:BX    format buffer, size = 512 bytes
  1152.         the first 2*(sectors/track) bytes contain f,n for each sector
  1153.         f    00h    good sector
  1154.             80h    bad sector
  1155.         n    sector number
  1156. return    CF    set on error
  1157.     AH    status code (see 01h above)
  1158. note    Award AT BIOS routines are extended to handle more than 1024 cylinders.
  1159.     AL    number of sectors
  1160.     CH    cylinder numberm low 8 bits
  1161.     CL    sector number bits 0-5, bits 6-7 are high 2 cylinder bits
  1162.     DH    head number (bits 0-5) bits 6-7 are extended high cyls (>1024)
  1163.     DL    drive number (0-1 for diskette, 80h-81h for hard disk)
  1164.     ES:BX    transfer address
  1165.  
  1166.  
  1167. Function 08h    Read Drive Parameters                   (except PC, Jr)
  1168. entry    AH    08h
  1169.     DL    drive number
  1170.         00h-7Fh   floppy disk
  1171.         80h-0FFh  hard disk
  1172. return    CF    set on error
  1173.         AH    status code (see above)
  1174.     BL    drive type  (AT/PS2 floppies only)
  1175.         01h    if 360 Kb, 40 track, 5¼"
  1176.         02h    if 1.2 Mb, 80 track, 5¼"
  1177.         03h    if 720 Kb, 80 track, 3½"
  1178.         04h    if 1.44 Mb, 80 track, 3½"
  1179.     CH    low 8 bits of maximum useable value for cylinder number
  1180.     CL bits 6-7    high-order 2 bits of maximum cylinder number
  1181.         0-5    maximum sector number
  1182.     DH    maximum usable value for head number
  1183.     DL    number of consecutive acknowledging drives (0-2)
  1184.     ES:DI    pointer to drive parameter table
  1185. note 1) On the PC and PC/XT, this function is supported on hard disks only.
  1186.      2) The Columbia MPC supports functions 6-14 for its hard disk. It returns
  1187.     drive information, same as int 13 function 8, except that the BL and
  1188.     ES:DI values are omitted and AL <- burst length.
  1189.  
  1190.  
  1191. Function 09h    Initialize Two Fixed Disk Base Tables     (XT, AT, XT/286, PS/2)
  1192.         (install nonstandard drive)
  1193. entry    AH    09h
  1194.     DL    80h-0FFh  hard disk number
  1195. return    CF    set on error
  1196.         AH    status code (see 01h above)
  1197.         For PC, XT hard disks, the disk parameter block format is:
  1198.         00h-01h maximum number of cylinders
  1199.         02h    maximum number of heads
  1200.         03h-04h starting reduced write current cylinder
  1201.         05h-06h starting write precompensation cylinder
  1202.         07h    maximum ECC burst length
  1203.         08h    drive options
  1204.            bits 7    1    disable disk access retries
  1205.             6    1    disable ECC retries
  1206.             3-5    set to 0
  1207.             0-2    drive option
  1208.  
  1209.                                     -219-
  1210.  
  1211.         09h    standard timeout value
  1212.         0Ah    timeout value for format drive
  1213.         0Bh    timeout value for check drive
  1214.         0Ch-0Fh reserved
  1215.  
  1216.         For AT and PS/2 hard disks:
  1217.         00h-01h maximum number of cylinders
  1218.         02h    maximum number of heads
  1219.         03h-04h reserved
  1220.         05h-06h starting write precompensation cylinder
  1221.         07h    maximum ECC burst length
  1222.         08h    drive options byte
  1223.            bits 6-7    nonzero (10, 01, or 11) if retries disabled
  1224.             5    1    if manufacturer's defect map present at
  1225.                     maximum cylinder + 1
  1226.             4    not used
  1227.             3    1    if more than 8 heads
  1228.             0-2    not used
  1229.         09h-0Bh reserved
  1230.         0Ch-0Dh landing zone cylinder
  1231.         0Eh    sectors per track
  1232.         0Fh    reserved
  1233. note 1) For the XT, int 41h must point to the Disk Parameter Block.
  1234.      2) For the AT and PS/2, int 41h points to table for drive 0 and int 46h
  1235.     points to table for drive 1.
  1236.      3) Initializes the hard disk controller for subsequent I/O operations
  1237.     using the values found in the BIOS disk parameter block(s).
  1238.      4) This function is supported on hard disks only.
  1239.  
  1240.  
  1241. Function 0Ah    Read Long   (Hard disk)         (XT, AT, XT/286, PS/2)
  1242. entry    AH    0Ah
  1243.     CH    cylinder number (bits 8,9 in high bits of CL)
  1244.     CL    sector number (upper 2 bits of cyl # in upper 2 bits of CL)
  1245.     DH    head number
  1246.     DL    drive ID  (80h-0FFh hard disk)
  1247.     ES:BX    pointer to buffer to fill
  1248. return    CF    set on error
  1249.         AH    status code (see 01h above)
  1250.     AL    number of sectors actually transferred
  1251. note 1) A "long" sector includes a 4 byte EEC (Extended Error Correction) code.
  1252.      2) Used for diagnostics only on PS/2 systems.
  1253.      3) This function is supported on fixed disks only.
  1254.      4) Unlike the normal Read Sector (02h) function, ECC errors are not
  1255.     automatically corrected. Multisector transfers are terminated after any
  1256.     sector with a read error.
  1257.  
  1258.  
  1259. Function 0Bh    Write Long                (XT, AT, XT/286, PS/2)
  1260. entry    AH    0Bh
  1261.     AL    number of sectors
  1262.     CH    cylinder (bits 8,9 in high bits of CL)
  1263.     CL    sector number
  1264.     DH    head number
  1265.     DL    drive ID  (80h-0FFh hard disk)
  1266.     ES:BX    pointer to buffer containing data
  1267. return    CF    set on error
  1268.         AH    status code (see 01h above)
  1269.     AL    number of sectors actually transferred
  1270. note 1) A "long" sector includes a 4 byte EEC (Extended Error Correction) code.
  1271.      2) Used for diagnostics only on PS/2 systems.
  1272.      3) Valid for hard disks only.
  1273.  
  1274.                                     -220-
  1275.  
  1276. Function 0Ch    Seek To Cylinder            (except PC, PCjr)
  1277. entry    AH    0Ch
  1278.     CH    lower 8 bits of cylinder
  1279.     CL    upper 2 bits of cylinder in bits 6-7
  1280.     DH    head number
  1281.     DL    drive number (0 or 1)  (80h-0FFh for hard disk)
  1282. return    CF    set on error
  1283.         AH    status code (see 01h above)
  1284. note 1) Positions heads over a particular cylinder, but does not move any data.
  1285.      2) This function is supported on hard disks only.
  1286.      3) The upper 2 bits of the 10-bit cylinder number are placed in the upper
  1287.     2 bits of CL.
  1288.      4) The Read Sector, Read Sector Long, Write Sector, and Write Sector Long
  1289.     functions include an implied seek operation and need not be preceded by
  1290.     an explicit call to this function.
  1291.  
  1292.  
  1293. Function 0Dh    Alternate Hard Disk Reset             (except PC, PCjr)
  1294. entry    AH    0Dh
  1295.     DL    hard drive number (80h-0FFh hard disk)
  1296. return    CF    set on error
  1297.         AH    status code (see 01h above)
  1298. note 1) Not for PS/2 ESDI hard disks.
  1299.      2) Resets the hard disk controller, recalibrates attached drives (moves
  1300.     the read/write arm to cylinder 0), and prepares for subsequent disk I/O.
  1301.      3) This function is for hard disks only. It differs from fn 00h by not
  1302.     resetting the floppy disk controller.
  1303.  
  1304.  
  1305. Function 0Eh    Read Sector Buffer               (XT, Portable, PS/2)
  1306. entry    AH    0Eh
  1307.     ES:BX    pointer to buffer
  1308. return    CF    set on error
  1309.         AH    status code (see 01h above)
  1310.     AL    number of sectors actually transferred
  1311. note 1) Transfers controller's sector buffer. No data is read from the drive.
  1312.      2) Used for diagnostics only on PS/2 systems.
  1313.      3) This fn is supported by the XT's hard disk adapter only. It is "not
  1314.     defined" for hard disk adapters on the AT or PS/2.
  1315.  
  1316.  
  1317. Function 0Fh    Write sector buffer                 (XT, Portable)
  1318. entry    AH    0Fh
  1319.     ES:BX    pointer to buffer
  1320. return    CF    set if error
  1321.         AH    status code (see 01h above)
  1322.     AL    number of sectors actually transferred
  1323. note 1) Should be called before formatting to initialize the controller's
  1324.     sector buffer.
  1325.      2) Used for diagnostics only on PS/2 systems.
  1326.      3) Transfers data from system RAM to the hard disk adapter's internal
  1327.     sector buffer.
  1328.      4) No data is written to the physical disk drive.
  1329.      5) This fn is for the XT hard disk controller only. It is "not defined"
  1330.     for AT or PS/2 controllers.
  1331.  
  1332.  
  1333. Function 10h    Test For Drive Ready              (XT, AT, XT/286, PS/2)
  1334. entry    AH    10h
  1335.     DL    hard drive number 0 or 1 (80h-0FFh)
  1336. return    CF    set on error
  1337.         AH    status code (see 01h above)
  1338. note 1) Tests whether the specified hard disk drive is operational and returns
  1339.     the drive's status.
  1340.  
  1341.                                     -221-
  1342.  
  1343.      2) This function is supported on hard disks only.
  1344.      3) Perstor and Novell controllers allow more than one hard drive.
  1345.  
  1346.  
  1347. Function 11h    Recalibrate Drive               (XT, AT, XT/286, PS/2)
  1348. entry    AH    11h
  1349.     DL    hard drive number (80h-0FFh hard disk)
  1350. return    CF    set on error
  1351.         AH    status code (see 01h above)
  1352. note 1) Causes the HD controller to recalibrate itself for the specified drive,
  1353.     positioning the read/arm to cylinder 0, and returns the drive's status.
  1354.      2) This function is for hard disks only.
  1355.  
  1356.  
  1357. Function 12h    Controller RAM Diagnostics          (XT, Portable, PS/2)
  1358. entry    AH    12h
  1359. return    CF    set on error
  1360.         AH    status code (see fn 01h above)
  1361. note 1) Used for diagnostics only on PS/2 systems.
  1362.      2) Makes the hard disk controller carry out a built-in diagnostic test on
  1363.     its internal sector buffer.
  1364.  
  1365.  
  1366. Function 13h    Controller Drive Diagnostic          (XT, Portable, PS/2)
  1367. entry    AH    13h
  1368. return    CF    set on error
  1369.         AH    status code (see 01h above)
  1370. note 1) Used for diagnostics only on PS/2 systems.
  1371.      2) Causes HD controller to run internal diagnostic tests of the attached
  1372.     drive, indicating whether the test was passed by the returned status.
  1373.      3) This function is supported on XT HDs only.
  1374.  
  1375.  
  1376. Function 14h    Controller Internal Diagnostic             (AT, XT/286)
  1377. entry    AH    14h
  1378. return    CF    set on error
  1379.     AH    status code (see 01h above)
  1380. note 1) OEM is Western Digital 1003-WA2 hard/floppy combination controller
  1381.     in AT and XT/286.
  1382.      2) Used for diagnostics only in PS/2 systems.
  1383.      3) Causes HD controller to do a built-in diagnostic self-test, indicating
  1384.     whether the test was passed by the returned status.
  1385.      4) This function is supported on hard disks only.
  1386.  
  1387.  
  1388. Function 15h    Get Disk Type                     (except PC and XT)
  1389. entry    AH    15h
  1390.     DL    drive ID
  1391.         00h-7Fh   floppy disk
  1392.         80h-0FFh  fixed disk
  1393. return    CF    set on error
  1394.         AH    error code (see 01h above)
  1395.     AH    disk type
  1396.         00h    no drive is present
  1397.         01h    diskette, no change detection present
  1398.         02h    diskette, change detection present
  1399.         03h    hard disk
  1400.             CX:DX    number of 512-byte sectors
  1401. note 1) Returns a code indicating the type of disk referenced by the specified
  1402.     drive code.
  1403.      2) This function is not supported on the PC or XT.
  1404.  
  1405.                                     -222-
  1406.  
  1407. Function 16h    Get Disk Change Status (diskette)      (except PC, XT, & Jr)
  1408. entry    AH    16h
  1409.     DL    drive to check
  1410. return    CF    set on error
  1411.     AH    disk change status
  1412.         00h    no disk change
  1413.         01h    disk changed
  1414.     DL    drive that had disk change (00h-07Fh floppy disk)
  1415. note    Returns the status of the change line, indicating whether the disk in
  1416.     the drive may have been replaced since the last disk access. If this
  1417.     function returns with CF set, the disk has not necessarily been
  1418.     changed; the change line can be activated by simply unlocking and
  1419.     relocking the disk drive door without removing the floppy disk.
  1420.  
  1421.  
  1422. Function 17h    Set Disk Type for Format (diskette)         (except PC and XT)
  1423. entry    AH    17h
  1424.     AL    00h    not used
  1425.         01h    160, 180, 320, or 360Kb diskette in 360kb drive
  1426.         02h    360Kb diskette in 1.2Mb drive
  1427.         03h    1.2Mb diskette in 1.2Mb drive
  1428.         04h    720Kb diskette in 720Kb drive
  1429.     DL    drive number (0-7)
  1430. return    CF    set on error
  1431.     AH    status of operation (see 01h above)
  1432. note 1) This function is probably enhanced for the PS/2 series to detect
  1433.     1.44 in 1.44 and 720k in 1.44.
  1434.      2) This function is not supported for floppy disks on the PC or XT.
  1435.      3) If the change line is active for the specified drive, it is reset.
  1436.      4) The BIOS sets the data rate for the specified drive and media type.
  1437.     The rate is 250k/sec for double-density media and 500k/sec for high
  1438.     density media. The proper hardware is required.
  1439.  
  1440.  
  1441. Function 18h    Set Media Type For Format  (diskette)    (AT, XT2, XT/286, PS/2)
  1442. entry    AH    18h
  1443.     CH    lower 8 bits of number of tracks
  1444.     CL    high 2 bits of number of tracks (6,7) sectors per track
  1445.         (bits 0-5)
  1446.     DL    drive number (0-7)
  1447. return    CF    clear    no errors
  1448.     AH    00h     if requested combination supported
  1449.         01h     if function not available
  1450.         0Ch     if not suppported or drive type unknown
  1451.         80h     if there is no media in the drive
  1452.     ES:DI    pointer to 11-byte disk parameter table for media type
  1453.     CF    set    error code (see 01h above)
  1454. note 1) A floppy disk must be present in the drive.
  1455.      2) This function should be called prior to formatting a disk with Int 13h
  1456.     Fn 05h so the BIOS can set the correct data rate for the media.
  1457.      3) If the change line is active for the specified drive, it is reset.
  1458.  
  1459.  
  1460. Function 19h    Park Hard Disk Heads                 (PS/2)
  1461. entry    AH    19h
  1462.     DL    drive number (80h-0FFh)
  1463. return    CF    set on error
  1464.         AH    error code (see fn 01h)
  1465. note    This function is defined for PS/2 fixed disks only.
  1466.  
  1467.                                     -223-
  1468.  
  1469. Function 1Ah    ESDI Hard Disk - Low Level Format               (PS/2)
  1470. entry    AH    1Ah
  1471.     AL    Relative Block Address (RBA) defect table count
  1472.         0    if no RBA table
  1473.         >0    if RBA table used
  1474.     CL    format modifiers byte
  1475.        bits 0    ignore primary defect map
  1476.         1    ignore secondary defect map
  1477.         2    update secondary defect map
  1478.         3    perform extended surface analysis
  1479.         4    generate periodic interrupt
  1480.         5    reserved - must be 0
  1481.         6    reserved - must be 0
  1482.         7    reserved - must be 0
  1483.     DL    drive  (80h-0FFh)
  1484.     ES:BX    pointer to RBA defect table
  1485. return    CF    set on error
  1486.         AH    error code (see fn 01h above)
  1487. note 1) Initializes disk sector and track address fields on a drive attached
  1488.     to the IBM "ESDI Fixed Disk Drive Adapter/A."
  1489.      2) If periodic interrupt selected, int 15h/fn 0Fh is called after each
  1490.     cylinder is formatted
  1491.      3) If bit 4 of CL is set, Int 15h, AH=0Fh, AL=phase code after each
  1492.     cylinder is formatted or analyzed. The phase code is defined as:
  1493.     0    reserved
  1494.     1    surface analysis
  1495.     2    formatting
  1496.      4) If bit 2 of CL is set, the drive's secondary defect map is updated to
  1497.     reflect errors found during surface analysis. If both bit 2 and bit 1
  1498.     are set, the secondary defect map is replaced.
  1499.      5) For an extended surface analysis, the disk should first be formatted by
  1500.     calling this function with bit 3 cleared and then analyzed by calling
  1501.     this function with bit 3 set.
  1502.  
  1503.  
  1504. Function 1Bh    ESDI Hard Disk - Get Manufacturing Header    (PS/2)
  1505. entry    AH    1Bh
  1506.     AL    number of record
  1507.     DL    drive
  1508.     ES:BX    pointer to buffer for manufacturing header (defect list)
  1509. return    CF    set on error
  1510.     AH    status
  1511. note    Manufacturing header format (Defect Map Record format) can be found
  1512.     in the "IBM 70Mb, 115Mb Fixed Disk Drives Technical Reference."
  1513.  
  1514.  
  1515. Function 1Ch    ESDI Hard Disk - Get Configuration            (PS/2)
  1516. entry    AH    1Ch
  1517.     AL    0Ah    Get Device Configuration
  1518.             DL    drive
  1519.             ES:BX    pointer to buffer for device configuration
  1520.                 (drive physical parameter)
  1521.         0Bh    Get Adapter Configuration
  1522.             ES:BX    pointer to buffer for adapter configuration
  1523.         0Ch    Get POS Information
  1524.             ES:BX    pointer to POS information
  1525.         0Eh    Translate RBA to ABA
  1526.             CH    low 8 bits of cylinder number
  1527.             CL    sector number, high two bits of cylinder number
  1528.                 in bits 6 and 7
  1529.             DH    head number
  1530.             DL    drive number
  1531.             ES:BX    pointer to ABA number
  1532.  
  1533.                                     -224-
  1534.  
  1535. return    CF    set on error
  1536.     AH    status (see 01h)
  1537. note 1) Device configuration format can be found in IBM ESDI Fixed Disk Drive
  1538.     Adapter/A Technical Reference.
  1539.      2) ABA (absolute block address) format can be found in IBM ESDI Adapter
  1540.     Technical Reference by using its Device Configuration Status Block.
  1541.  
  1542.  
  1543. Function 1Dh    IBMCACHE.SYS                    (PS/2 50+)
  1544. entry    AH    1Dh
  1545. other parameters unknown
  1546. note    IBMCACHE.SYS comes on the setup disk for MCA-bus PS/2 machines.
  1547.  
  1548.  
  1549. Function 20h    Western Digital HD SuperBIOS
  1550. entry    AH    20h
  1551. other parameters unknown
  1552. note    SuperBIOS may be purchased separately from Western Digital and added
  1553.     to standard HD controllers. SuperBIOS contains additional setup
  1554.     tables and parameters.
  1555.