home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / misc / hdstruct.cpp < prev    next >
C/C++ Source or Header  |  1993-11-17  |  4KB  |  106 lines

  1. /*
  2.     FIPS - the First nondestructive Interactive Partition Splitting program
  3.  
  4.     Module hdstruct.cpp
  5.  
  6.     RCS - Header:
  7.     $Header: c:/daten/c/fips/source/cpp/RCS/hdstruct.cpp 0.9.1.1 1993/11/17 17:51:06 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. rootsector::rootsector (rootsector &rs)
  35. {
  36.     drive = rs.drive;
  37.     for (int i=0;i<512;i++) data[i] = rs.data[i];
  38. }
  39.  
  40. void rootsector::operator= (rootsector &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.     *rootsector = *(hd.rootsector);
  50.     pr_partition_table = hd.partition_table();
  51. }
  52.  
  53. /* ----------------------------------------------------------------------- */
  54. /* Extract Partition Table from rootsector                                 */
  55. /* ----------------------------------------------------------------------- */
  56.  
  57. void partition_table::get (rootsector *rootsector)
  58. {
  59.     for (int i=0;i<4;i++)
  60.     {
  61.         class partition_info *p = &partition_info[i];
  62.         byte *pi = &(rootsector->data[0x1be+16*i]);
  63.  
  64.         p->bootable = *pi;
  65.         p->start_head = *(pi+1);
  66.         p->start_cylinder = *(pi+3) | ((*(pi+2) << 2) & 0x300);
  67.         p->start_sector = *(pi+2) & 0x3f;
  68.         p->system = *(pi+4);
  69.         p->end_head = *(pi+5);
  70.         p->end_cylinder = *(pi+7) | ((*(pi+6) << 2) & 0x300);
  71.         p->end_sector = *(pi+6) & 0x3f;
  72.         p->start_sector_abs = (dword) *(pi+8) | (dword) *(pi+9) << 8 | (dword) *(pi+10) << 16 | (dword) *(pi+11) << 24;
  73.         p->no_of_sectors_abs = (dword) *(pi+12) | (dword) *(pi+13) << 8 | (dword) *(pi+14) << 16 | (dword) *(pi+15) << 24;
  74.     }
  75. }
  76.  
  77. /* ----------------------------------------------------------------------- */
  78. /* Write Partition Table back into rootsector                              */
  79. /* ----------------------------------------------------------------------- */
  80.  
  81. void partition_table::put (rootsector *rootsector)
  82. {
  83.     for (int i=0;i<4;i++)
  84.     {
  85.         class partition_info p = partition_info[i];
  86.         byte *pi = &(rootsector->data[0x1be+16*i]);
  87.  
  88.         *pi = p.bootable;
  89.         *(pi+1) = p.start_head;
  90.         *(pi+2) = ((p.start_cylinder >> 2) & 0xc0) | (p.start_sector & 0x3f);
  91.         *(pi+3) = p.start_cylinder & 0xff;
  92.         *(pi+4) = p.system;
  93.         *(pi+5) = p.end_head;
  94.         *(pi+6) = ((p.end_cylinder >> 2) & 0xc0) | (p.end_sector & 0x3f);
  95.         *(pi+7) = p.end_cylinder & 0xff;
  96.         *(pi+8) = p.start_sector_abs & 0xff;
  97.         *(pi+9) = (p.start_sector_abs >> 8) & 0xff;
  98.         *(pi+10) = (p.start_sector_abs >> 16) & 0xff;
  99.         *(pi+11) = (p.start_sector_abs >> 24) & 0xff;
  100.         *(pi+12) = p.no_of_sectors_abs & 0xff;
  101.         *(pi+13) = (p.no_of_sectors_abs >> 8) & 0xff;
  102.         *(pi+14) = (p.no_of_sectors_abs >> 16) & 0xff;
  103.         *(pi+15) = (p.no_of_sectors_abs >> 24) & 0xff;
  104.     }
  105. }
  106.