home *** CD-ROM | disk | FTP | other *** search
/ James Briskly's Game Magazine 2 / JBGM002S.ZIP / SOURCE / CALCULAT.CPP next >
C/C++ Source or Header  |  1995-08-22  |  3KB  |  139 lines

  1. /*
  2.     FIPS - the First nondestructive Interactive Partition Splitting program
  3.  
  4.     Module calculat.cpp
  5.  
  6.     RCS - Header:
  7.     $Header: c:/daten/fips/source/main/RCS/calculat.cpp 1.4 1995/01/19 00:00:49 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 "fipsspec.h"
  33.  
  34. /* ----------------------------------------------------------------------- */
  35. /* Some calculations                                                       */
  36. /* ----------------------------------------------------------------------- */
  37.  
  38. void fips_partition_table::calculate_new_root
  39. (
  40.     dword new_start_cylinder,
  41.     partition *partition,
  42.     const drive_geometry &geometry
  43. )
  44. {
  45.     for (int i = 0; i < 3; i++) if (!partition_info[i].system)
  46.     // move DOS partitions to the beginning of the partition table
  47.     {
  48.         for (int j = i + 1; j < 4; j++) if
  49.         (
  50.             (partition_info[j].system == 1) ||
  51.             (partition_info[j].system == 4) ||
  52.             (partition_info[j].system == 6)
  53.         )
  54.         {
  55.             struct partition_info tmppart = partition_info[i];
  56.             partition_info[i] = partition_info[j];
  57.             partition_info[j] = tmppart;
  58.  
  59.             if (partition->number == j) partition->number = i;
  60.             break;
  61.         }
  62.     }
  63.  
  64.     int partition_no = partition->number;
  65.     partition->partition_info = &partition_info[partition_no];
  66.  
  67.     for (i=0;i<4;i++) if (!partition_info[i].system) break;
  68.     // search for first empty slot
  69.  
  70.     struct partition_info *newpart = &partition_info[i];
  71.     struct partition_info *oldpart = &partition_info[partition_no];
  72.  
  73.     newpart->bootable = 0;
  74.  
  75.     newpart->start_sector_abs =
  76.         new_start_cylinder *
  77.         geometry.heads *
  78.         geometry.sectors;
  79.  
  80.     newpart->no_of_sectors_abs =
  81.         oldpart->start_sector_abs +
  82.         oldpart->no_of_sectors_abs -
  83.         newpart->start_sector_abs;
  84.  
  85.     if
  86.     (
  87.         (newpart->no_of_sectors_abs > 0xffff) ||
  88.         (newpart->start_sector_abs > 0xffff)
  89.     )
  90.     {
  91.         newpart->system = 6;
  92.     }
  93.     else if
  94.     (
  95.         newpart->no_of_sectors_abs >= 20740
  96.     )
  97.     {
  98.         newpart->system = 4;
  99.     }
  100.     else
  101.     {
  102.         newpart->system = 1;
  103.     }
  104.  
  105.     oldpart->no_of_sectors_abs =
  106.         newpart->start_sector_abs -
  107.         oldpart->start_sector_abs;
  108.  
  109.     if
  110.     (
  111.         (oldpart->no_of_sectors_abs > 0xffff) ||
  112.         (oldpart->start_sector_abs > 0xffff)
  113.     )
  114.     {
  115.         oldpart->system = 6;
  116.     }
  117.     else
  118.     {
  119.         oldpart->system = 4;
  120.     }
  121.  
  122.     correct_physical (geometry);
  123. }
  124.  
  125.  
  126. void fips_bpb::calculate_new_boot (const partition_info &partition_info)
  127. {
  128.     if ((partition_info.no_of_sectors_abs > 0xffff) || (partition_info.start_sector_abs > 0xffff))
  129.     {
  130.         no_of_sectors = 0;
  131.         no_of_sectors_long = partition_info.no_of_sectors_abs;
  132.     }
  133.     else
  134.     {
  135.         no_of_sectors_long = 0;
  136.         no_of_sectors = partition_info.no_of_sectors_abs;
  137.     }
  138. }
  139.