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

  1. /* 
  2.     FIPS - the First nondestructive Interactive Partition Splitting program 
  3.  
  4.     Module main.cpp 
  5.  
  6.     RCS - Header: 
  7.     $Header: c:/daten/fips/source/main/RCS/main.cpp 1.1 1994/05/25 22:20:03 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 <stdlib.h> 
  32. #include "logdr_st.h" 
  33. #include "global.h" 
  34. #include "input.h" 
  35. #include "fat.h" 
  36. #include "fipsspec.h" 
  37. #include "host_os.h" 
  38.  
  39.  
  40. void main (int argc,char *argv[]) 
  41.     evaluate_argument_vector (argc,argv); 
  42.  
  43.     atexit (exit_function); 
  44.  
  45.     if (global.debug_mode) global.open_debugfile(argc,argv); 
  46.  
  47.     notice(); 
  48.  
  49.     int drive_number; 
  50.     if (global.drive_number_cmdline) drive_number = global.drive_number_cmdline; 
  51.     else drive_number = ask_for_drive_number (); 
  52.  
  53.     host_os os; 
  54.     char infostring[256]; 
  55.  
  56.     if (os.ok () != OK) 
  57.     { 
  58.         printx ("\nWARNING: FIPS has detected that it is running under %s\n" 
  59.             "FIPS should not be used under a multitasking OS. If possible, boot from a DOS\n" 
  60.             "disk and then run FIPS. Read FIPS.DOC for more information.\n\n", 
  61.             os.information (infostring)); 
  62.         ask_if_proceed (); 
  63.     } 
  64.  
  65.     fips_harddrive harddrive (drive_number); 
  66.  
  67.     if (harddrive.errorcode) 
  68.         error ("Error reading Drive Geometry: Errorcode %u",harddrive.errorcode); 
  69.  
  70.     harddrive.reset(); 
  71.  
  72.     if (harddrive.errorcode) 
  73.         error ("Drive Initialization Failure: Errorcode %u",harddrive.errorcode); 
  74.  
  75.     if (harddrive.rootsector->read ()) 
  76.         error ("Error reading Root Sector"); 
  77.  
  78.     if (global.debug_mode) 
  79.     { 
  80.         fprintf (global.debugfile,"\nRoot Sector Drive %02Xh:\n\n",drive_number); 
  81.         hexwrite (harddrive.rootsector->data,512,global.debugfile); 
  82.     } 
  83.  
  84.     fips_partition *partition; 
  85.  
  86.     while (true) 
  87.     { 
  88.         fips_harddrive hd = harddrive; 
  89.  
  90.         hd.partition_table().get (hd.rootsector); 
  91.  
  92.         printx ("\nPartition Table:\n\n"); 
  93.         hd.print_partition_table (); 
  94.  
  95.         hd.check(); 
  96.  
  97.         int partition_number; 
  98.         if (global.partition_number_cmdline) partition_number = global.partition_number_cmdline - 1; 
  99.         else partition_number = ask_for_partition_number (hd.partition_table().partition_info); 
  100.  
  101.         partition = new fips_partition (&hd,partition_number); 
  102.  
  103.         int system = partition->partition_info->system; 
  104.         if (system == 5) 
  105.             error ("Can't split extended Partitions"); 
  106.         if (system == 0) 
  107.             error ("Invalid Partition selected: %u",partition_number + 1); 
  108.         if ((system != 1) && (system != 4) && (system != 6)) 
  109.             error ("Unknown Filesystem: %02Xh",system); 
  110.  
  111.         if (partition->bootsector->read ()) 
  112.             error ("Error reading Boot Sector"); 
  113.  
  114.         if (global.debug_mode) 
  115.         { 
  116.             fprintf (global.debugfile,"\nBoot Sector Drive %02Xh, Partition %u:\n\n",hd.number,partition->number + 1); 
  117.             hexwrite (partition->bootsector->data,512,global.debugfile); 
  118.         } 
  119.  
  120.         partition->bpb().get (partition->bootsector); 
  121.  
  122.         printx ("\nBootsector:\n\n"); 
  123.         partition->print_bpb (); 
  124.  
  125.         partition->info().get (partition->bpb()); 
  126.         if (global.debug_mode) partition->write_info_debugfile (); 
  127.  
  128.         partition->check(); 
  129.  
  130.         fat16 fat1 (partition,1); 
  131.         fat16 fat2 (partition,2); 
  132.  
  133.         fat1.check_against (&fat2); 
  134.  
  135.         dword new_part_min_sector = partition->info().start_data + (dword) 4085 * partition->bpb().sectors_per_cluster; 
  136.         dword new_part_min_cylinder = (new_part_min_sector + partition->partition_info->start_sector_abs - 1) / (hd.geometry.heads * hd.geometry.sectors) + 1; 
  137.  
  138.         if (new_part_min_cylinder > partition->partition_info->end_cylinder) 
  139.             error ("Partition too small - can't split"); 
  140.  
  141.         dword min_free_cluster = fat1.min_cluster (); 
  142.         dword min_free_sector = partition->info().start_data + (min_free_cluster - 2) * (dword) partition->bpb().sectors_per_cluster; 
  143.         dword min_free_cylinder = (min_free_sector + partition->partition_info->start_sector_abs - 1) / (hd.geometry.heads * hd.geometry.sectors) + 1; 
  144.  
  145.         if (min_free_cylinder > partition->partition_info->end_cylinder) 
  146.             error ("Last Cylinder is not free"); 
  147.  
  148.         if (new_part_min_cylinder < min_free_cylinder) new_part_min_cylinder = min_free_cylinder; 
  149.  
  150.         if (ask_if_save()) save_root_and_boot(&hd,partition); 
  151.  
  152.         dword new_start_cylinder; 
  153.         if (global.new_start_cylinder_cmdline) 
  154.         { 
  155.             new_start_cylinder = global.new_start_cylinder_cmdline; 
  156.             if ((new_start_cylinder < new_part_min_cylinder) || (new_start_cylinder > partition->partition_info->end_cylinder)) 
  157.                 error ("Invalid new start cylinder: %lu",new_start_cylinder); 
  158.         } 
  159.         else new_start_cylinder = ask_for_new_start_cylinder (partition->partition_info->start_cylinder, new_part_min_cylinder,partition->partition_info->end_cylinder, hd.geometry.heads * hd.geometry.sectors); 
  160.  
  161.         fat2.check_empty (new_start_cylinder * hd.geometry.heads * hd.geometry.sectors - partition->partition_info->start_sector_abs); 
  162.  
  163.         hd.calculate_new_root (new_start_cylinder,partition); 
  164.  
  165.         hd.partition_table().put (hd.rootsector); 
  166.  
  167.         hd.partition_table().get (hd.rootsector); 
  168.  
  169.         printx ("\nNew Partition Table:\n\n"); 
  170.         hd.print_partition_table (); 
  171.  
  172.         hd.check(); 
  173.  
  174.         if (ask_if_continue ()) 
  175.         { 
  176.             harddrive = hd; 
  177.             break; 
  178.         } 
  179.     } 
  180.  
  181.     partition->calculate_new_boot (); 
  182.  
  183.     partition->bpb().put (partition->bootsector); 
  184.  
  185.     partition->bpb().get (partition->bootsector); 
  186.  
  187.     printx ("\nNew Bootsector:\n\n"); 
  188.     partition->print_bpb (); 
  189.  
  190.     partition->info().get (partition->bpb()); 
  191.     if (global.debug_mode) partition->write_info_debugfile (); 
  192.  
  193.     partition->check(); 
  194.  
  195.     if (!global.test_mode) 
  196.     { 
  197.         ask_for_write_permission(); 
  198.  
  199.         if (harddrive.rootsector->write()) 
  200.             error ("Error writing Root Sector"); 
  201.  
  202.         if (partition->bootsector->write ()) 
  203.             error ("Error writing Boot Sector"); 
  204.  
  205.         printx ("Repartitioning complete\n"); 
  206.     } 
  207.