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

  1. /*
  2.  
  3.     FIPS - the First nondestructive Interactive Partition Splitting program
  4.  
  5.  
  6.  
  7.     Module calculat.cpp
  8.  
  9.  
  10.  
  11.     RCS - Header:
  12.  
  13.     $Header: c:/daten/fips/source/main/RCS/calculat.cpp 1.4 1995/01/19 00:00:49 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 "hdstruct.h"
  62.  
  63. #include "fipsspec.h"
  64.  
  65.  
  66.  
  67. /* ----------------------------------------------------------------------- */
  68.  
  69. /* Some calculations                                                       */
  70.  
  71. /* ----------------------------------------------------------------------- */
  72.  
  73.  
  74.  
  75. void fips_partition_table::calculate_new_root
  76.  
  77. (
  78.  
  79.     dword new_start_cylinder,
  80.  
  81.     partition *partition,
  82.  
  83.     const drive_geometry &geometry
  84.  
  85. )
  86.  
  87. {
  88.  
  89.     for (int i = 0; i < 3; i++) if (!partition_info[i].system)
  90.  
  91.     // move DOS partitions to the beginning of the partition table
  92.  
  93.     {
  94.  
  95.         for (int j = i + 1; j < 4; j++) if
  96.  
  97.         (
  98.  
  99.             (partition_info[j].system == 1) ||
  100.  
  101.             (partition_info[j].system == 4) ||
  102.  
  103.             (partition_info[j].system == 6)
  104.  
  105.         )
  106.  
  107.         {
  108.  
  109.             struct partition_info tmppart = partition_info[i];
  110.  
  111.             partition_info[i] = partition_info[j];
  112.  
  113.             partition_info[j] = tmppart;
  114.  
  115.  
  116.  
  117.             if (partition->number == j) partition->number = i;
  118.  
  119.             break;
  120.  
  121.         }
  122.  
  123.     }
  124.  
  125.  
  126.  
  127.     int partition_no = partition->number;
  128.  
  129.     partition->partition_info = &partition_info[partition_no];
  130.  
  131.  
  132.  
  133.     for (i=0;i<4;i++) if (!partition_info[i].system) break;
  134.  
  135.     // search for first empty slot
  136.  
  137.  
  138.  
  139.     struct partition_info *newpart = &partition_info[i];
  140.  
  141.     struct partition_info *oldpart = &partition_info[partition_no];
  142.  
  143.  
  144.  
  145.     newpart->bootable = 0;
  146.  
  147.  
  148.  
  149.     newpart->start_sector_abs =
  150.  
  151.         new_start_cylinder *
  152.  
  153.         geometry.heads *
  154.  
  155.         geometry.sectors;
  156.  
  157.  
  158.  
  159.     newpart->no_of_sectors_abs =
  160.  
  161.         oldpart->start_sector_abs +
  162.  
  163.         oldpart->no_of_sectors_abs -
  164.  
  165.         newpart->start_sector_abs;
  166.  
  167.  
  168.  
  169.     if
  170.  
  171.     (
  172.  
  173.         (newpart->no_of_sectors_abs > 0xffff) ||
  174.  
  175.         (newpart->start_sector_abs > 0xffff)
  176.  
  177.     )
  178.  
  179.     {
  180.  
  181.         newpart->system = 6;
  182.  
  183.     }
  184.  
  185.     else if
  186.  
  187.     (
  188.  
  189.         newpart->no_of_sectors_abs >= 20740
  190.  
  191.     )
  192.  
  193.     {
  194.  
  195.         newpart->system = 4;
  196.  
  197.     }
  198.  
  199.     else
  200.  
  201.     {
  202.  
  203.         newpart->system = 1;
  204.  
  205.     }
  206.  
  207.  
  208.  
  209.     oldpart->no_of_sectors_abs =
  210.  
  211.         newpart->start_sector_abs -
  212.  
  213.         oldpart->start_sector_abs;
  214.  
  215.  
  216.  
  217.     if
  218.  
  219.     (
  220.  
  221.         (oldpart->no_of_sectors_abs > 0xffff) ||
  222.  
  223.         (oldpart->start_sector_abs > 0xffff)
  224.  
  225.     )
  226.  
  227.     {
  228.  
  229.         oldpart->system = 6;
  230.  
  231.     }
  232.  
  233.     else
  234.  
  235.     {
  236.  
  237.         oldpart->system = 4;
  238.  
  239.     }
  240.  
  241.  
  242.  
  243.     correct_physical (geometry);
  244.  
  245. }
  246.  
  247.  
  248.  
  249.  
  250.  
  251. void fips_bpb::calculate_new_boot (const partition_info &partition_info)
  252.  
  253. {
  254.  
  255.     if ((partition_info.no_of_sectors_abs > 0xffff) || (partition_info.start_sector_abs > 0xffff))
  256.  
  257.     {
  258.  
  259.         no_of_sectors = 0;
  260.  
  261.         no_of_sectors_long = partition_info.no_of_sectors_abs;
  262.  
  263.     }
  264.  
  265.     else
  266.  
  267.     {
  268.  
  269.         no_of_sectors_long = 0;
  270.  
  271.         no_of_sectors = partition_info.no_of_sectors_abs;
  272.  
  273.     }
  274.  
  275. }
  276.  
  277.