home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 8 / IOPROG_8.ISO / install / fips / source / main.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-25  |  4.0 KB  |  172 lines

  1. /*
  2.  
  3.     FIPS - the First nondestructive Interactive Partition Splitting program
  4.  
  5.  
  6.  
  7.     Module main.cpp
  8.  
  9.  
  10.  
  11.     RCS - Header:
  12.  
  13.     $Header: c:/daten/fips/source/main/RCS/main.cpp 1.4 1995/01/19 00:00:55 schaefer Exp schaefer $
  14.  
  15.  
  16.  
  17.     Copyright (C) 1993 Arno Schaefer
  18.  
  19.  
  20.  
  21.     This program is free software; you can redistribute it and/or modify
  22.  
  23.     it under the terms of the GNU General Public License as published by
  24.  
  25.     the Free Software Foundation; either version 2 of the License, or
  26.  
  27.     (at your option) any later version.
  28.  
  29.  
  30.  
  31.     This program is distributed in the hope that it will be useful,
  32.  
  33.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  34.  
  35.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  36.  
  37.     GNU General Public License for more details.
  38.  
  39.  
  40.  
  41.     You should have received a copy of the GNU General Public License
  42.  
  43.     along with this program; if not, write to the Free Software
  44.  
  45.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  46.  
  47.  
  48.  
  49.  
  50.  
  51.     Report problems and direct all questions to:
  52.  
  53.  
  54.  
  55.     schaefer@rbg.informatik.th-darmstadt.de
  56.  
  57. */
  58.  
  59.  
  60.  
  61. #include <stdlib.h>
  62.  
  63. #include "logdr_st.h"
  64.  
  65. #include "global.h"
  66.  
  67. #include "input.h"
  68.  
  69. #include "fat.h"
  70.  
  71. #include "fipsspec.h"
  72.  
  73. #include "host_os.h"
  74.  
  75.  
  76.  
  77.  
  78.  
  79. #define FIRST_CHECK false
  80.  
  81. #define FINAL_CHECK true
  82.  
  83.  
  84.  
  85.  
  86.  
  87. extern unsigned _stklen = 20000U;
  88.  
  89.  
  90.  
  91.  
  92.  
  93. int main (int argc, char *argv[])
  94.  
  95. {
  96.  
  97.     // *********************************************************
  98.  
  99.     // Initialize Program
  100.  
  101.     // *********************************************************
  102.  
  103.  
  104.  
  105.     evaluate_argument_vector (argc, argv);
  106.  
  107.  
  108.  
  109.     atexit (exit_function);
  110.  
  111.  
  112.  
  113.     if (global.debug_mode)
  114.  
  115.         global.open_debugfile (argc,argv);
  116.  
  117.  
  118.  
  119.     notice ();
  120.  
  121.  
  122.  
  123.     host_os os;
  124.  
  125.     char infostring[256];
  126.  
  127.  
  128.  
  129.     if (os.ok () != OK)
  130.  
  131.     {
  132.  
  133.         printx ("\nWARNING: FIPS has detected that it is running under %s\n"
  134.  
  135.             "FIPS should not be used under a multitasking OS. If possible, boot from a DOS\n"
  136.  
  137.             "disk and then run FIPS. Read FIPS.DOC for more information.\n\n",
  138.  
  139.             os.information (infostring));
  140.  
  141.  
  142.  
  143.         ask_if_proceed ();
  144.  
  145.     }
  146.  
  147.  
  148.  
  149.  
  150.  
  151.     // *********************************************************
  152.  
  153.     // Select Drive
  154.  
  155.     // *********************************************************
  156.  
  157.  
  158.  
  159.     int drive_number;
  160.  
  161.  
  162.  
  163.     if (global.drive_number_cmdline != 0)
  164.  
  165.         drive_number = global.drive_number_cmdline;
  166.  
  167.     else
  168.  
  169.         drive_number = ask_for_drive_number ();
  170.  
  171.  
  172.  
  173.     fips_harddrive harddrive (drive_number);    // reads geometry
  174.  
  175.  
  176.  
  177.     if (harddrive.errorcode)
  178.  
  179.         error
  180.  
  181.         (
  182.  
  183.             "Error reading drive geometry: Errorcode %u",
  184.  
  185.             harddrive.errorcode
  186.  
  187.         );
  188.  
  189.  
  190.  
  191.     harddrive.reset ();
  192.  
  193.  
  194.  
  195.     if (harddrive.errorcode)
  196.  
  197.     {
  198.  
  199.         warning
  200.  
  201.         (
  202.  
  203.             false,
  204.  
  205.             "Drive initialization failure: Errorcode %u",
  206.  
  207.             harddrive.errorcode
  208.  
  209.         );
  210.  
  211.  
  212.  
  213.         ask_if_proceed ();
  214.  
  215.     }
  216.  
  217.  
  218.  
  219.  
  220.  
  221.     // *********************************************************
  222.  
  223.     // Select partition
  224.  
  225.     // *********************************************************
  226.  
  227.  
  228.  
  229.     if (harddrive.read_root_sector () != 0)
  230.  
  231.         error ("Error reading root sector");
  232.  
  233.  
  234.  
  235.     if (global.debug_mode)
  236.  
  237.     {
  238.  
  239.         fprintf
  240.  
  241.         (
  242.  
  243.             global.debugfile,
  244.  
  245.             "\nRoot sector drive %02Xh:\n\n",
  246.  
  247.             drive_number
  248.  
  249.         );
  250.  
  251.  
  252.  
  253.         hexwrite (harddrive.root_sector->data, 512, global.debugfile);
  254.  
  255.     }
  256.  
  257.  
  258.  
  259.     while (true)
  260.  
  261.     {
  262.  
  263.         fips_harddrive hd = harddrive;
  264.  
  265.  
  266.  
  267.         hd.get_partition_table();
  268.  
  269.  
  270.  
  271.         printx ("\nPartition table:\n\n");
  272.  
  273.         hd.print_partition_table ();
  274.  
  275.  
  276.  
  277.         hd.check (FIRST_CHECK);
  278.  
  279.  
  280.  
  281.         int partition_number =
  282.  
  283.             ask_for_partition_number
  284.  
  285.             (
  286.  
  287.                 hd.partition_table().partition_info
  288.  
  289.             );
  290.  
  291.  
  292.  
  293.         int system = hd.partition_table()
  294.  
  295.             .partition_info[partition_number].system;
  296.  
  297.  
  298.  
  299.         switch (system)
  300.  
  301.         {
  302.  
  303.             case 5:
  304.  
  305.                 error ("Can't split extended partitions");
  306.  
  307.                 break;
  308.  
  309.             case 1: case 4: case 6:
  310.  
  311.             {
  312.  
  313.                 fips_partition* partition =
  314.  
  315.                     new fips_partition (&hd, partition_number);
  316.  
  317.  
  318.  
  319.                 if (partition->split (hd) == true)
  320.  
  321.                     return (0);
  322.  
  323.  
  324.  
  325.                 delete partition;
  326.  
  327.             }
  328.  
  329.                 break;
  330.  
  331.             default:
  332.  
  333.                 error ("Unknown file system: %02Xh", system);
  334.  
  335.                 break;
  336.  
  337.         }
  338.  
  339.     }
  340.  
  341. }
  342.  
  343.