home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 8 / IOPROG_8.ISO / install / fips / techinfo.txt < prev   
Encoding:
Text File  |  1997-08-25  |  8.8 KB  |  227 lines

  1. Technical Info on FIPS
  2.  
  3. ----------------------
  4.  
  5.  
  6.  
  7. FIPS was written in C++ V2.0 with the Turbo C++ 1.0 and Borland C++ 3.1
  8.  
  9. compilers.
  10.  
  11. It should compile with any newer C++ compiler (perhaps after minor changes
  12.  
  13. to the BIOS calls).
  14.  
  15.  
  16.  
  17. If you're a C++ wizard, don't look too closely at the code, this is my first
  18.  
  19. C++ program, so it is far from acceptable (too much public data, some ini-
  20.  
  21. tializers and assignment operators are missing etc.). Constructive critizism
  22.  
  23. is always welcome however.
  24.  
  25.  
  26.  
  27. How FIPS works:
  28.  
  29.  
  30.  
  31. FIPS uses the BIOS interrupts 13h 00h (reset disks), 13h 02h (read sector),
  32.  
  33. 13h 08h (get drive parameters), 13h 03h (write sector) and 13h 04h (verify
  34.  
  35. sector).
  36.  
  37.  
  38.  
  39. Here is the sequence of function calls in main:
  40.  
  41.  
  42.  
  43. evaluate_argument_vector
  44.  
  45.   read the commandline arguments and set the global variables accordingly
  46.  
  47. notice
  48.  
  49.   display copyright notice and version number
  50.  
  51. ask_for_drive_number
  52.  
  53.   let the user choose the drive (if more than 1)
  54.  
  55. harddrive.reset
  56.  
  57.   reset harddrive
  58.  
  59. harddrive.rootsector->read
  60.  
  61.   read the sector 0,0,1 of the chosen drive into an array of unsigned char
  62.  
  63. hd.partition_table().get
  64.  
  65.   extract the necessary information from the root sector (see below - The
  66.  
  67.   root sector)
  68.  
  69. hd.print_partition_table
  70.  
  71.   print the information
  72.  
  73. hd.check
  74.  
  75.   check if everything is ok (see below - The root sector)
  76.  
  77. ask_for_partition_number
  78.  
  79.   let the user choose the partition
  80.  
  81. partition->bootsector->read
  82.  
  83.   read the first sector of the chosen partition to another array
  84.  
  85. partition->bpb().get
  86.  
  87.   extract info from the boot sector (see below - The boot sector)
  88.  
  89. partition->print_bpb
  90.  
  91.   print the info
  92.  
  93. partition->info().get
  94.  
  95.   calculate no. of clusters, starting sector of FATs etc.
  96.  
  97. partition->check
  98.  
  99.   check boot sector (see below - The boot sector)
  100.  
  101. fat1.check_against(fat2)
  102.  
  103.   check if FAT 1 is identical to FAT 2 (see below - The FAT)
  104.  
  105. save_root_and_boot
  106.  
  107.   write root- and boot sector to floppy disk (optional)
  108.  
  109. ask_for_new_start_cylinder
  110.  
  111.   ask the user for the first cylinder of the new partition
  112.  
  113. fat2.check_empty
  114.  
  115.   check if chosen part of partition is empty (see below - The FAT)
  116.  
  117. hd.calculate_new_root
  118.  
  119.   from the chosen start cylinder calculate the new partition table
  120.  
  121.   Note that the partition entries will be moved to the beginning of the par- 
  122.  
  123.   tition table, so that the new partition will be the last one and the drive
  124.  
  125.   names will not change.
  126.  
  127. hd.partition_table.put
  128.  
  129.   write the new partition table into the root sector buffer
  130.  
  131. hd.partition_table.get,hd.print_partition_table,hd.check
  132.  
  133.   check if new root sector is ok
  134.  
  135. partition->calculate_new_boot
  136.  
  137.   put new number of sectors in boot sector info
  138.  
  139. partition->bpb()->put
  140.  
  141.   write new boot sector info into boot sector buffer
  142.  
  143. partition->bpb()->get,partition->print_bpb,partition->check
  144.  
  145.   check if new boot sector is ok
  146.  
  147. ask_for_write_permission
  148.  
  149.   ask if user wants to proceed
  150.  
  151. harddrive.rootsector->write
  152.  
  153.   write the changed root sector to the disk
  154.  
  155. partition->bootsector->write
  156.  
  157.   write the changed boot sector to the disk
  158.  
  159.  
  160.  
  161.  
  162.  
  163. The root sector
  164.  
  165. ---------------
  166.  
  167.  
  168.  
  169. The root sector is the first sector on every hard disk. It contains the
  170.  
  171. program that loads the boot sector of the bootable partition and the
  172.  
  173. partition table. The last two bytes of the root sector must be 55 aa (hex).
  174.  
  175. The partition table begins at 1be. It contains 4 * 16 Bytes for the four
  176.  
  177. possible partitions.
  178.  
  179. All numbers are zero based except the start/end-sector number (may be 1-63).
  180.  
  181. One partition entry contains the following:
  182.  
  183.  
  184.  
  185. 1 Byte - Bootable Flag. Must be 0 (not bootable) or 80h (bootable).
  186.  
  187.      At most one Partition may be bootable at a time.
  188.  
  189.      (somewhere I read the bootable flag may also be 81h for the
  190.  
  191.      second drive - does anybody know anything about that?)
  192.  
  193.  
  194.  
  195. 1 Byte - Start Head. The number of the head of the first sector of the
  196.  
  197.      partition.
  198.  
  199.  
  200.  
  201. 2 Bytes - Start Sector + Cylinder. The Bits are as follows:
  202.  
  203.  
  204.  
  205.             CCSSSSSS CCCCCCCC
  206.  
  207.  
  208.  
  209.       where the first byte contains the sector number (1 - 63), and
  210.  
  211.       the high two bits of the cylinder number. The second byte con-
  212.  
  213.       tains the low eight bits of the cylinder number.
  214.  
  215.  
  216.  
  217. 1 Byte - System Indicator. For DOS this may be:
  218.  
  219.  
  220.  
  221.     1 - 12-bit FAT, 16-bit sector number
  222.  
  223.     4 - 16-bit FAT, 16-bit sector number
  224.  
  225.     5 - Extended Partition
  226.  
  227.     6 - 16-bit FAT, 32-bit sector number
  228.  
  229.  
  230.  
  231. 1 Byte - End Head. Head Number of the last sector of the partition
  232.  
  233.  
  234.  
  235. 2 Bytes - End Sector + Cylinder. Same format as Start Sector + Cylinder
  236.  
  237.  
  238.  
  239. 4 Bytes - First Sector. Number of the first sector of the partition. This
  240.  
  241.       corresponds to the Start Head, Sector + Cylinder. High Byte
  242.  
  243.       comes first.
  244.  
  245.  
  246.  
  247. 4 Bytes - Total number of Sectors.
  248.  
  249.  
  250.  
  251. The function check_rootsector_validity checks the following:
  252.  
  253.  
  254.  
  255. - Signature Bytes (55 aa) in the last two bytes of the sector
  256.  
  257. - not more than one bootable partition
  258.  
  259. - Bootable flag is 0 or 80h
  260.  
  261. - Start/End sector of a partition is not 0
  262.  
  263. - Start/End sector & head are not greater than drive geometry allows
  264.  
  265. - Start cylinder * sectors * heads + start head * sectors + start sector - 1
  266.  
  267.   = first sector (where sectors is no. of sectors per track, heads is
  268.  
  269.   no. of heads of the drive)
  270.  
  271. - End cylinder * sectors * heads + end head * sector + end sector = first
  272.  
  273.   sector + number of sectors
  274.  
  275. - if System Indicator is 0, all other bytes of partition entry are 0
  276.  
  277. - all partitions except the first begin on cylinder boundaries (head = 0,
  278.  
  279.   sectors = 1)
  280.  
  281. - all partition end on cylinder boundaries
  282.  
  283. - partitions don't overlap
  284.  
  285. - no free space between partitions
  286.  
  287.  
  288.  
  289.  
  290.  
  291. The boot sector
  292.  
  293. ---------------
  294.  
  295.  
  296.  
  297. The boot sector is the first sector of every partition. It contains the
  298.  
  299. program that boots the operating system and the bios parameter block.
  300.  
  301. The last two bytes must again contain 55 aa. The information in the
  302.  
  303. boot sector is the following:
  304.  
  305.  
  306.  
  307. 00  3 bytes  jump instruction ('eb xx 90' or 'e9 xx xx')
  308.  
  309. 03  8 bytes  OEM name and version - e.g. MSDOS5.0
  310.  
  311. 0b  2 bytes  bytes per sector - should be 512
  312.  
  313. 0d  1 byte   sectors per cluster - power of two
  314.  
  315. 0e  2 bytes  reserved sectors - typically 1 (boot sector)
  316.  
  317. 10  1 byte   number of FATs - must be 2
  318.  
  319. 11  2 bytes  number of rootdirectory entries - typically 512
  320.  
  321. 13  2 bytes  number of sectors (short) - 0, if BIGDOS partition
  322.  
  323. 15  1 byte   media descriptor - typically f8h
  324.  
  325. 16  2 bytes  sectors per FAT - varies
  326.  
  327. 18  2 bytes  sectors per track
  328.  
  329. 1a  2 bytes  number of heads
  330.  
  331. 1c  2 bytes  number of hidden sectors (low)
  332.  
  333.  
  334.  
  335. - extended BPB since DOS 4.0 -
  336.  
  337.  
  338.  
  339. 1e  2 bytes  number of hidden sectors (high)
  340.  
  341. 20  4 bytes  number of sectors (long)
  342.  
  343. 24  1 byte   physical drive number - 80h or 81h
  344.  
  345. 25  1 byte   reserved
  346.  
  347. 26  1 byte   signature - 29h
  348.  
  349.  
  350.  
  351. The function check_bootsector_validity checks the following:
  352.  
  353.  
  354.  
  355. - correct jump instruction
  356.  
  357. - signature bytes 55 aa in the last two bytes of the sector
  358.  
  359. - bytes per sector = 512
  360.  
  361. - sectors per cluster is power of two
  362.  
  363. - reserved sectors = 1
  364.  
  365. - number of FATs = 2
  366.  
  367. - number of rootdirectory entries is multiple of 16
  368.  
  369. - media descriptor = f8h
  370.  
  371. - sectors per fat <= 256
  372.  
  373. - sectors per fat big enough to hold complete FAT
  374.  
  375. - sectors per track matches BIOS info
  376.  
  377. - number of heads matches BIOS info
  378.  
  379. - hidden sectors = start sector
  380.  
  381. - signature = 29h, if BIGDOS
  382.  
  383. - physical drive number = actual drive number
  384.  
  385. - number of sectors matches partition info
  386.  
  387. - system indicator byte in root sector matches partition type
  388.  
  389.  
  390.  
  391.  
  392.  
  393. The FAT
  394.  
  395. -------
  396.  
  397.  
  398.  
  399. The File Allocation Table contains the information how the clusters of the
  400.  
  401. disk are linked to files. Every directory entry contains a pointer to the
  402.  
  403. first cluster of the file. The corresponding cluster entry in the FAT con-
  404.  
  405. tains a pointer to the next cluster, or an EOF marker (FFFF for 16-bit FATs,
  406.  
  407. FFF for 12-bit FATs) if the cluster is the last one of the file.
  408.  
  409. Bad clusters are marked with FFF7 or FF7. Empty clusters are marked with 0.
  410.  
  411. The first cluster on the disk is cluster number 2, it begins at the first
  412.  
  413. sector after the root directory. The FAT entries for the clusters 0 and 1
  414.  
  415. contain the media descriptor byte (usually F8h for harddisk) and two or
  416.  
  417. three FFh bytes.
  418.  
  419. There exist two copies of the FAT on a normal DOS partition, these two
  420.  
  421. copies must be identical. FAT 2 is the primary FAT.
  422.  
  423.  
  424.  
  425. The function check_fat_validity checks if the two FATs are identical and if
  426.  
  427. the entries 0 and 1 contain what they are supposed to.
  428.  
  429.  
  430.  
  431. The function check_fat_empty checks if the cluster entries that cover the
  432.  
  433. new partition contain either 0 (empty) or FFF7 (Bad cluster).
  434.  
  435.  
  436.  
  437.  
  438.  
  439. ------------------------------------------------------------------------------
  440.  
  441.  
  442.  
  443. I hope you find this information useful. If you found anything not to be
  444.  
  445. exact or if you have additions, please let me know asap.
  446.  
  447.  
  448.  
  449. Arno Schaefer
  450.  
  451. schaefer@rbg.informatik.th-darmstadt.de
  452.  
  453.