home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / fips15.zip / techinfo.txt < prev   
Text File  |  1995-08-22  |  9KB  |  227 lines

  1. Technical Info on FIPS
  2. ----------------------
  3.  
  4. FIPS was written in C++ V2.0 with the Turbo C++ 1.0 and Borland C++ 3.1
  5. compilers.
  6. It should compile with any newer C++ compiler (perhaps after minor changes
  7. to the BIOS calls).
  8.  
  9. If you're a C++ wizard, don't look too closely at the code, this is my first
  10. C++ program, so it is far from acceptable (too much public data, some ini-
  11. tializers and assignment operators are missing etc.). Constructive critizism
  12. is always welcome however.
  13.  
  14. How FIPS works:
  15.  
  16. FIPS uses the BIOS interrupts 13h 00h (reset disks), 13h 02h (read sector),
  17. 13h 08h (get drive parameters), 13h 03h (write sector) and 13h 04h (verify
  18. sector).
  19.  
  20. Here is the sequence of function calls in main:
  21.  
  22. evaluate_argument_vector
  23.   read the commandline arguments and set the global variables accordingly
  24. notice
  25.   display copyright notice and version number
  26. ask_for_drive_number
  27.   let the user choose the drive (if more than 1)
  28. harddrive.reset
  29.   reset harddrive
  30. harddrive.rootsector->read
  31.   read the sector 0,0,1 of the chosen drive into an array of unsigned char
  32. hd.partition_table().get
  33.   extract the necessary information from the root sector (see below - The
  34.   root sector)
  35. hd.print_partition_table
  36.   print the information
  37. hd.check
  38.   check if everything is ok (see below - The root sector)
  39. ask_for_partition_number
  40.   let the user choose the partition
  41. partition->bootsector->read
  42.   read the first sector of the chosen partition to another array
  43. partition->bpb().get
  44.   extract info from the boot sector (see below - The boot sector)
  45. partition->print_bpb
  46.   print the info
  47. partition->info().get
  48.   calculate no. of clusters, starting sector of FATs etc.
  49. partition->check
  50.   check boot sector (see below - The boot sector)
  51. fat1.check_against(fat2)
  52.   check if FAT 1 is identical to FAT 2 (see below - The FAT)
  53. save_root_and_boot
  54.   write root- and boot sector to floppy disk (optional)
  55. ask_for_new_start_cylinder
  56.   ask the user for the first cylinder of the new partition
  57. fat2.check_empty
  58.   check if chosen part of partition is empty (see below - The FAT)
  59. hd.calculate_new_root
  60.   from the chosen start cylinder calculate the new partition table
  61.   Note that the partition entries will be moved to the beginning of the par- 
  62.   tition table, so that the new partition will be the last one and the drive
  63.   names will not change.
  64. hd.partition_table.put
  65.   write the new partition table into the root sector buffer
  66. hd.partition_table.get,hd.print_partition_table,hd.check
  67.   check if new root sector is ok
  68. partition->calculate_new_boot
  69.   put new number of sectors in boot sector info
  70. partition->bpb()->put
  71.   write new boot sector info into boot sector buffer
  72. partition->bpb()->get,partition->print_bpb,partition->check
  73.   check if new boot sector is ok
  74. ask_for_write_permission
  75.   ask if user wants to proceed
  76. harddrive.rootsector->write
  77.   write the changed root sector to the disk
  78. partition->bootsector->write
  79.   write the changed boot sector to the disk
  80.  
  81.  
  82. The root sector
  83. ---------------
  84.  
  85. The root sector is the first sector on every hard disk. It contains the
  86. program that loads the boot sector of the bootable partition and the
  87. partition table. The last two bytes of the root sector must be 55 aa (hex).
  88. The partition table begins at 1be. It contains 4 * 16 Bytes for the four
  89. possible partitions.
  90. All numbers are zero based except the start/end-sector number (may be 1-63).
  91. One partition entry contains the following:
  92.  
  93. 1 Byte - Bootable Flag. Must be 0 (not bootable) or 80h (bootable).
  94.      At most one Partition may be bootable at a time.
  95.      (somewhere I read the bootable flag may also be 81h for the
  96.      second drive - does anybody know anything about that?)
  97.  
  98. 1 Byte - Start Head. The number of the head of the first sector of the
  99.      partition.
  100.  
  101. 2 Bytes - Start Sector + Cylinder. The Bits are as follows:
  102.  
  103.             CCSSSSSS CCCCCCCC
  104.  
  105.       where the first byte contains the sector number (1 - 63), and
  106.       the high two bits of the cylinder number. The second byte con-
  107.       tains the low eight bits of the cylinder number.
  108.  
  109. 1 Byte - System Indicator. For DOS this may be:
  110.  
  111.     1 - 12-bit FAT, 16-bit sector number
  112.     4 - 16-bit FAT, 16-bit sector number
  113.     5 - Extended Partition
  114.     6 - 16-bit FAT, 32-bit sector number
  115.  
  116. 1 Byte - End Head. Head Number of the last sector of the partition
  117.  
  118. 2 Bytes - End Sector + Cylinder. Same format as Start Sector + Cylinder
  119.  
  120. 4 Bytes - First Sector. Number of the first sector of the partition. This
  121.       corresponds to the Start Head, Sector + Cylinder. High Byte
  122.       comes first.
  123.  
  124. 4 Bytes - Total number of Sectors.
  125.  
  126. The function check_rootsector_validity checks the following:
  127.  
  128. - Signature Bytes (55 aa) in the last two bytes of the sector
  129. - not more than one bootable partition
  130. - Bootable flag is 0 or 80h
  131. - Start/End sector of a partition is not 0
  132. - Start/End sector & head are not greater than drive geometry allows
  133. - Start cylinder * sectors * heads + start head * sectors + start sector - 1
  134.   = first sector (where sectors is no. of sectors per track, heads is
  135.   no. of heads of the drive)
  136. - End cylinder * sectors * heads + end head * sector + end sector = first
  137.   sector + number of sectors
  138. - if System Indicator is 0, all other bytes of partition entry are 0
  139. - all partitions except the first begin on cylinder boundaries (head = 0,
  140.   sectors = 1)
  141. - all partition end on cylinder boundaries
  142. - partitions don't overlap
  143. - no free space between partitions
  144.  
  145.  
  146. The boot sector
  147. ---------------
  148.  
  149. The boot sector is the first sector of every partition. It contains the
  150. program that boots the operating system and the bios parameter block.
  151. The last two bytes must again contain 55 aa. The information in the
  152. boot sector is the following:
  153.  
  154. 00  3 bytes  jump instruction ('eb xx 90' or 'e9 xx xx')
  155. 03  8 bytes  OEM name and version - e.g. MSDOS5.0
  156. 0b  2 bytes  bytes per sector - should be 512
  157. 0d  1 byte   sectors per cluster - power of two
  158. 0e  2 bytes  reserved sectors - typically 1 (boot sector)
  159. 10  1 byte   number of FATs - must be 2
  160. 11  2 bytes  number of rootdirectory entries - typically 512
  161. 13  2 bytes  number of sectors (short) - 0, if BIGDOS partition
  162. 15  1 byte   media descriptor - typically f8h
  163. 16  2 bytes  sectors per FAT - varies
  164. 18  2 bytes  sectors per track
  165. 1a  2 bytes  number of heads
  166. 1c  2 bytes  number of hidden sectors (low)
  167.  
  168. - extended BPB since DOS 4.0 -
  169.  
  170. 1e  2 bytes  number of hidden sectors (high)
  171. 20  4 bytes  number of sectors (long)
  172. 24  1 byte   physical drive number - 80h or 81h
  173. 25  1 byte   reserved
  174. 26  1 byte   signature - 29h
  175.  
  176. The function check_bootsector_validity checks the following:
  177.  
  178. - correct jump instruction
  179. - signature bytes 55 aa in the last two bytes of the sector
  180. - bytes per sector = 512
  181. - sectors per cluster is power of two
  182. - reserved sectors = 1
  183. - number of FATs = 2
  184. - number of rootdirectory entries is multiple of 16
  185. - media descriptor = f8h
  186. - sectors per fat <= 256
  187. - sectors per fat big enough to hold complete FAT
  188. - sectors per track matches BIOS info
  189. - number of heads matches BIOS info
  190. - hidden sectors = start sector
  191. - signature = 29h, if BIGDOS
  192. - physical drive number = actual drive number
  193. - number of sectors matches partition info
  194. - system indicator byte in root sector matches partition type
  195.  
  196.  
  197. The FAT
  198. -------
  199.  
  200. The File Allocation Table contains the information how the clusters of the
  201. disk are linked to files. Every directory entry contains a pointer to the
  202. first cluster of the file. The corresponding cluster entry in the FAT con-
  203. tains a pointer to the next cluster, or an EOF marker (FFFF for 16-bit FATs,
  204. FFF for 12-bit FATs) if the cluster is the last one of the file.
  205. Bad clusters are marked with FFF7 or FF7. Empty clusters are marked with 0.
  206. The first cluster on the disk is cluster number 2, it begins at the first
  207. sector after the root directory. The FAT entries for the clusters 0 and 1
  208. contain the media descriptor byte (usually F8h for harddisk) and two or
  209. three FFh bytes.
  210. There exist two copies of the FAT on a normal DOS partition, these two
  211. copies must be identical. FAT 2 is the primary FAT.
  212.  
  213. The function check_fat_validity checks if the two FATs are identical and if
  214. the entries 0 and 1 contain what they are supposed to.
  215.  
  216. The function check_fat_empty checks if the cluster entries that cover the
  217. new partition contain either 0 (empty) or FFF7 (Bad cluster).
  218.  
  219.  
  220. ------------------------------------------------------------------------------
  221.  
  222. I hope you find this information useful. If you found anything not to be
  223. exact or if you have additions, please let me know asap.
  224.  
  225. Arno Schaefer
  226. schaefer@rbg.informatik.th-darmstadt.de
  227.