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

  1. /*
  2.     FIPS - the First nondestructive Interactive Partition Splitting program
  3.  
  4.     Module hdstruct.cpp
  5.  
  6.     RCS - Header:
  7.     $Header: c:/daten/fips/source/main/RCS/hdstruct.cpp 1.4 1995/01/19 00:20:01 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 "types.h"
  32. #include "hdstruct.h"
  33.  
  34. root_sector::root_sector (root_sector &rs)
  35. {
  36.     drive = rs.drive;
  37.     for (int i=0; i<512; i++) data[i] = rs.data[i];
  38. }
  39.  
  40. void root_sector::operator= (root_sector &rs)
  41. {
  42.     drive = rs.drive;
  43.     for (int i=0; i<512; i++) data[i] = rs.data[i];
  44. }
  45.  
  46. void harddrive::operator= (harddrive &hd)
  47. {
  48.     physical_drive::operator= (hd);
  49.     *root_sector = *(hd.root_sector);
  50.     partition_table () = hd.partition_table ();
  51. }
  52.  
  53. void harddrive::get_partition_table (void)
  54. {
  55.     partition_table().get (root_sector);
  56.  
  57.     for (int i = 0; i < 4; i++)
  58.     {
  59.         class partition_info* p
  60.             = &(partition_table().partition_info[i]);
  61.  
  62.         if (p->system == 0) continue;
  63.  
  64.         while
  65.         (
  66.             p->start_sector_abs
  67.             > (
  68.                 (p->start_cylinder + 1000UL)
  69.                     * geometry.heads
  70.                     * geometry.sectors
  71.                 + p->start_head
  72.                     * geometry.sectors
  73.                 + p->start_sector
  74.                 - 1
  75.             )
  76.         )
  77.         {
  78.             p->start_cylinder += 1024;    // more than 1024 cylinders
  79.         }
  80.  
  81.         while
  82.         (
  83.             (p->start_sector_abs + p->no_of_sectors_abs - 1)
  84.             > (
  85.                 (p->end_cylinder + 1000UL)
  86.                     * geometry.heads
  87.                     * geometry.sectors
  88.                 + p->end_head
  89.                     * geometry.sectors
  90.                 + p->end_sector
  91.                 - 1
  92.             )
  93.         )
  94.         {
  95.             p->end_cylinder += 1024;    // more than 1024 cylinders
  96.         }
  97.     }
  98. }
  99.  
  100.  
  101. /* ----------------------------------------------------------------------- */
  102. /* Extract Partition Table from root sector                                */
  103. /* ----------------------------------------------------------------------- */
  104.  
  105. void partition_table::get (root_sector *root_sector)
  106. {
  107.     for (int i=0;i<4;i++)
  108.     {
  109.         class partition_info *p = &partition_info[i];
  110.         byte *pi = &(root_sector->data[0x1be+16*i]);
  111.  
  112.         p->bootable = *pi;
  113.         p->start_head = *(pi+1);
  114.         p->start_cylinder = *(pi+3) | ((*(pi+2) << 2) & 0x300);
  115.         p->start_sector = *(pi+2) & 0x3f;
  116.         p->system = *(pi+4);
  117.         p->end_head = *(pi+5);
  118.         p->end_cylinder = *(pi+7) | ((*(pi+6) << 2) & 0x300);
  119.         p->end_sector = *(pi+6) & 0x3f;
  120.         p->start_sector_abs = (dword) *(pi+8) | ((dword) *(pi+9) << 8) | ((dword) *(pi+10) << 16) | ((dword) *(pi+11) << 24);
  121.         p->no_of_sectors_abs = (dword) *(pi+12) | ((dword) *(pi+13) << 8) | ((dword) *(pi+14) << 16) | ((dword) *(pi+15) << 24);
  122.     }
  123. }
  124.  
  125.  
  126. /* ----------------------------------------------------------------------- */
  127. /* Write Partition Table back into root sector                             */
  128. /* ----------------------------------------------------------------------- */
  129.  
  130. void partition_table::put (root_sector *root_sector)
  131. {
  132.     for (int i=0; i<4; i++)
  133.     {
  134.         class partition_info p = partition_info[i];
  135.         byte *pi = &(root_sector->data[0x1be+16*i]);
  136.  
  137.         *pi = p.bootable;
  138.         *(pi+1) = p.start_head;
  139.         *(pi+2) = ((p.start_cylinder >> 2) & 0xc0) | (p.start_sector & 0x3f);
  140.         *(pi+3) = p.start_cylinder & 0xff;
  141.         *(pi+4) = p.system;
  142.         *(pi+5) = p.end_head;
  143.         *(pi+6) = ((p.end_cylinder >> 2) & 0xc0) | (p.end_sector & 0x3f);
  144.         *(pi+7) = p.end_cylinder & 0xff;
  145.         *(pi+8) = p.start_sector_abs & 0xff;
  146.         *(pi+9) = (p.start_sector_abs >> 8) & 0xff;
  147.         *(pi+10) = (p.start_sector_abs >> 16) & 0xff;
  148.         *(pi+11) = (p.start_sector_abs >> 24) & 0xff;
  149.         *(pi+12) = p.no_of_sectors_abs & 0xff;
  150.         *(pi+13) = (p.no_of_sectors_abs >> 8) & 0xff;
  151.         *(pi+14) = (p.no_of_sectors_abs >> 16) & 0xff;
  152.         *(pi+15) = (p.no_of_sectors_abs >> 24) & 0xff;
  153.     }
  154. }
  155.