home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 8 / CDACTUAL8.iso / install / fips / source / check.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-11  |  8.2 KB  |  213 lines

  1. /* 
  2.     FIPS - the First nondestructive Interactive Partition Splitting program 
  3.  
  4.     Module check.cpp 
  5.  
  6.     RCS - Header: 
  7.     $Header: c:/daten/fips/source/main/RCS/check.cpp 1.1 1994/05/25 22:19:37 schaefer Exp schaefer $ 
  8.  
  9.     Copyright (C) 1993 Arno Schaefer 
  10.  
  11.     This program is free software; you can redistribute it and/or modify 
  12.     it under the terms of the GNU General Public License as published by 
  13.     the Free Software Foundation; either version 2 of the License, or 
  14.     (at your option) any later version. 
  15.  
  16.     This program is distributed in the hope that it will be useful, 
  17.     but WITHOUT ANY WARRANTY; without even the implied warranty of 
  18.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  19.     GNU General Public License for more details. 
  20.  
  21.     You should have received a copy of the GNU General Public License 
  22.     along with this program; if not, write to the Free Software 
  23.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
  24.  
  25.  
  26.     Report problems and direct all questions to: 
  27.  
  28.     schaefer@rbg.informatik.th-darmstadt.de 
  29. */ 
  30.  
  31. #include "hdstruct.h" 
  32. #include "global.h" 
  33. #include "fipsspec.h" 
  34.  
  35. void fips_harddrive::check (void) 
  36.     int i,j,k; 
  37.     boolean bootable = false; 
  38.  
  39.     byte *rootsector = harddrive::rootsector->data; 
  40.     partition_info *parts = partition_table().partition_info; 
  41.  
  42.     int order[4] = {-1,-1,-1,-1}; 
  43.  
  44.     printx ("\nChecking Rootsector ... "); 
  45.  
  46.     if ((*(rootsector+510) != 0x55) || (*(rootsector+511) != 0xaa)) 
  47.         error ("Invalid Rootsector Signature: %02X %02X",*(rootsector+510),*(rootsector+511)); 
  48.  
  49.     for (i=0;i<4;i++) 
  50.     { 
  51.         if (parts[i].bootable == 0x80) 
  52.         { 
  53.             if (bootable) 
  54.             { 
  55.                 if (!global.override_multiple_boot) 
  56.                     error ("More than one bootable Partition"); 
  57.             } 
  58.             else bootable = true; 
  59.         } 
  60.         else if (parts[i].bootable != 0) 
  61.             if (!global.override_bootable_flag) 
  62.                 error ("Invalid bootable-flag: partition %u: %02Xh",i+1,parts[i].bootable); 
  63.             // must be 0 or 80h 
  64.  
  65.         if (parts[i].system) 
  66.         { 
  67.             if ((parts[i].start_sector == 0) || (parts[i].start_sector > geometry.sectors)) 
  68.                 error ("Invalid Start Sector: partition %u: %u",i+1,parts[i].start_sector); 
  69.             if ((parts[i].end_sector == 0) || (parts[i].end_sector > geometry.sectors)) 
  70.                 error ("Invalid End Sector: partition %u: %u",i+1,parts[i].end_sector); 
  71.             if (parts[i].start_head > (geometry.heads - 1)) 
  72.                 error ("Invalid Start Head: partition %u: %u",i+1,parts[i].start_head); 
  73.             if (parts[i].end_head > (geometry.heads - 1)) 
  74.                 error ("Invalid End Head: partition %u: %u",i+1,parts[i].end_head); 
  75.  
  76.             if (parts[i].start_sector_abs != (parts[i].start_cylinder * geometry.heads * geometry.sectors + 
  77.                 parts[i].start_head * geometry.sectors + parts[i].start_sector - 1)) 
  78.                 error ("Partition Table Corrupt - start: partition %u",i+1); 
  79.                 // physical start sector does not match logical start sector 
  80.  
  81.             if ((parts[i].start_sector_abs + parts[i].no_of_sectors_abs - 1) != 
  82.                 (parts[i].end_cylinder * geometry.heads * geometry.sectors + 
  83.                 parts[i].end_head * geometry.sectors + parts[i].end_sector - 1)) 
  84.                 error ("Partition Table Corrupt - end: partition %u",i+1); 
  85.                 // physical end sector does not match logical end sector 
  86.  
  87.             for (j=0;j<4;j++)       // insert partition in ordered table 
  88.             { 
  89.                 if (order[j] == -1) 
  90.                 { 
  91.                     order[j] = i; 
  92.                     break; 
  93.                 } 
  94.                 else if (parts[i].start_sector_abs < parts[order[j]].start_sector_abs) 
  95.                 { 
  96.                     for (k=3;k>j;k--) order[k] = order[k-1]; 
  97.                     order[j] = i; 
  98.                     break; 
  99.                 } 
  100.             } 
  101.         } 
  102.         else            // system = 0 
  103.         { 
  104.             for (j=0;j<16;j++) 
  105.             { 
  106.                 if (*(rootsector + 0x1be + 16*i + j)) 
  107.                 { 
  108.                     warning ("Invalid Partition entry: partition %u",i+1); 
  109.                     break; 
  110.                 } 
  111.             } 
  112.         } 
  113.     } 
  114.     for (i=0;i<4;i++) 
  115.     { 
  116.         if ((k=order[i]) != -1)         // valid partition 
  117.         { 
  118.             if ((parts[k].end_sector != geometry.sectors) || (parts[k].end_head != (geometry.heads - 1))) 
  119.                 warning ("Partition does not end on Cylinder boundary: partition %u",k+1); 
  120.             if (i != 0) if ((parts[k].start_sector != 1) || (parts[k].start_head != 0)) 
  121.                 warning ("Partition does not begin on Cylinder boundary: partition %u",k+1); 
  122.  
  123.             if (i<3) if ((j=order[i+1]) != -1)       // following valid partition 
  124.             { 
  125.                 if ((parts[k].start_sector_abs + parts[k].no_of_sectors_abs) > parts[j].start_sector_abs) 
  126.                     error ("Overlapping Partitions: %u and %u",k+1,j+1); 
  127.                 if ((parts[k].start_sector_abs + parts[k].no_of_sectors_abs) < parts[j].start_sector_abs) 
  128.                     warning ("Free Space between Partitions: %u and %u",k+1,j+1); 
  129.             } 
  130.         } 
  131.     } 
  132.     printx ("OK\n"); 
  133.  
  134. void fips_partition::check (void) 
  135.     printx ("Checking Bootsector ... "); 
  136.  
  137.     byte *bootsector = partition::bootsector->data; 
  138.  
  139.     if (*(bootsector) == 0xeb) 
  140.     { 
  141.         if (*(bootsector + 2) != 0x90) 
  142.             error ("Invalid Jump Instruction in Bootsector: %02X %02X %02X",*(bootsector),*(bootsector+1),*(bootsector+2)); 
  143.     } 
  144.     else if (*(bootsector) != 0xe9) 
  145.         error ("Invalid Jump Instruction in Bootsector: %02X %02X %02X",*(bootsector),*(bootsector+1),*(bootsector+2)); 
  146.  
  147.     if ((*(bootsector+510) != 0x55) || (*(bootsector+511) != 0xaa)) 
  148.         error ("Invalid Bootsector: %02X %02X",*(bootsector+510),*(bootsector+511)); 
  149.     if (bpb().bytes_per_sector != 512) 
  150.         error ("Can't handle number of Bytes per Sector: %u",bpb().bytes_per_sector); 
  151.     switch (bpb().sectors_per_cluster) 
  152.     { 
  153.         case 1:case 2:case 4:case 8:case 16:case 32:case 64:case 128: break; 
  154.         default: 
  155.             error ("Number of Sectors per Cluster must be a power of 2: actually it is %u",bpb().sectors_per_cluster); 
  156.     } 
  157.     if (bpb().reserved_sectors != 1) 
  158.         warning ("Number of reserved sectors should be 1: actually it is %u",bpb().reserved_sectors); 
  159.     if (bpb().no_of_fats != 2) 
  160.         error ("Partition must have 2 FATs: actually it is %u",bpb().no_of_fats); 
  161.     if (bpb().no_of_rootdir_entries % 16) 
  162.         if (!global.override_rootdir_entries) 
  163.             error ("Number of Rootdir entries must be multiple of 16: actually it is %u",bpb().no_of_rootdir_entries); 
  164.     if (bpb().no_of_rootdir_entries == 0) 
  165.         error ("Number of Rootdir entries must not be zero"); 
  166.     if (bpb().media_descriptor != 0xf8) 
  167.         if (!global.override_media_descriptor) 
  168.             error ("Wrong Media Descriptor Byte in Bootsector: %02X",bpb().media_descriptor); 
  169.     if (bpb().sectors_per_fat > 256) 
  170.         if (!global.override_large_fat) 
  171.             error ("FAT too large: %u sectors",bpb().sectors_per_fat); 
  172.     if (bpb().sectors_per_fat < (info().no_of_clusters + 1) / 256 + 1) 
  173.         if (!global.override_small_fat) 
  174.             error ("FAT too small: %u sectors (should be %u)",bpb().sectors_per_fat, (unsigned int) ((info().no_of_clusters + 1) / 256 + 1)); 
  175.     if (bpb().sectors_per_track != drive->geometry.sectors) 
  176.         warning ("Sectors per track incorrect: %u instead of %u",bpb().sectors_per_track,(int) drive->geometry.sectors); 
  177.     if (bpb().drive_heads != drive->geometry.heads) 
  178.         warning ("Number of drive heads incorrect: %u instead of %u",bpb().drive_heads,(int) drive->geometry.heads); 
  179.     if (bpb().hidden_sectors != partition_info->start_sector_abs) 
  180.         error ("Number of hidden sectors incorrect: %lu instead of %lu",bpb().hidden_sectors,partition_info->start_sector_abs); 
  181.  
  182.     if (info().no_of_clusters <= 4084) 
  183.         error ("12-bit FAT not supported: number of clusters is %u",(int) info().no_of_clusters); 
  184.  
  185.     if (bpb().no_of_sectors) 
  186.     { 
  187.         if (partition_info->no_of_sectors_abs > 0xffff) 
  188.             error ("Number of sectors (short) must be zero"); 
  189.         if (bpb().no_of_sectors != partition_info->no_of_sectors_abs) 
  190.             error ("Number of sectors (short) does not match Partition Info:\n%u instead of %lu",bpb().no_of_sectors,partition_info->no_of_sectors_abs); 
  191.         if (partition_info->system != 4) 
  192.             warning ("Wrong System Indicator Byte: %u instead of 4",partition_info->system); 
  193.     } 
  194.     else 
  195.     { 
  196.         if (bpb().no_of_sectors_long != partition_info->no_of_sectors_abs) 
  197.             error ("Number of Sectors (long) does not match Partition Info:\n%lu instead of %lu",bpb().no_of_sectors_long,partition_info->no_of_sectors_abs); 
  198.         if (bpb().signature != 0x29) 
  199.             warning ("Wrong Signature: %02Xh",bpb().signature); 
  200.         if (bpb().phys_drive_no != drive->number) 
  201.             warning ("Drive number in bootsector does not match actual drivenumber:\n%02Xh instead of %02Xh" 
  202.             ,bpb().phys_drive_no,drive->number); 
  203.         if (partition_info->system != 6) 
  204.             warning ("Wrong System Indicator Byte: %u instead of 6",partition_info->system); 
  205.     } 
  206.  
  207.     printx ("OK\n"); 
  208.  
  209.