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

  1. /*
  2.  
  3.     FIPS - the First nondestructive Interactive Partition Splitting program
  4.  
  5.  
  6.  
  7.     Module hdstruct.cpp
  8.  
  9.  
  10.  
  11.     RCS - Header:
  12.  
  13.     $Header: c:/daten/fips/source/main/RCS/hdstruct.cpp 1.4 1995/01/19 00:20:01 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 "types.h"
  62.  
  63. #include "hdstruct.h"
  64.  
  65.  
  66.  
  67. root_sector::root_sector (root_sector &rs)
  68.  
  69. {
  70.  
  71.     drive = rs.drive;
  72.  
  73.     for (int i=0; i<512; i++) data[i] = rs.data[i];
  74.  
  75. }
  76.  
  77.  
  78.  
  79. void root_sector::operator= (root_sector &rs)
  80.  
  81. {
  82.  
  83.     drive = rs.drive;
  84.  
  85.     for (int i=0; i<512; i++) data[i] = rs.data[i];
  86.  
  87. }
  88.  
  89.  
  90.  
  91. void harddrive::operator= (harddrive &hd)
  92.  
  93. {
  94.  
  95.     physical_drive::operator= (hd);
  96.  
  97.     *root_sector = *(hd.root_sector);
  98.  
  99.     partition_table () = hd.partition_table ();
  100.  
  101. }
  102.  
  103.  
  104.  
  105. void harddrive::get_partition_table (void)
  106.  
  107. {
  108.  
  109.     partition_table().get (root_sector);
  110.  
  111.  
  112.  
  113.     for (int i = 0; i < 4; i++)
  114.  
  115.     {
  116.  
  117.         class partition_info* p
  118.  
  119.             = &(partition_table().partition_info[i]);
  120.  
  121.  
  122.  
  123.         if (p->system == 0) continue;
  124.  
  125.  
  126.  
  127.         while
  128.  
  129.         (
  130.  
  131.             p->start_sector_abs
  132.  
  133.             > (
  134.  
  135.                 (p->start_cylinder + 1000UL)
  136.  
  137.                     * geometry.heads
  138.  
  139.                     * geometry.sectors
  140.  
  141.                 + p->start_head
  142.  
  143.                     * geometry.sectors
  144.  
  145.                 + p->start_sector
  146.  
  147.                 - 1
  148.  
  149.             )
  150.  
  151.         )
  152.  
  153.         {
  154.  
  155.             p->start_cylinder += 1024;    // more than 1024 cylinders
  156.  
  157.         }
  158.  
  159.  
  160.  
  161.         while
  162.  
  163.         (
  164.  
  165.             (p->start_sector_abs + p->no_of_sectors_abs - 1)
  166.  
  167.             > (
  168.  
  169.                 (p->end_cylinder + 1000UL)
  170.  
  171.                     * geometry.heads
  172.  
  173.                     * geometry.sectors
  174.  
  175.                 + p->end_head
  176.  
  177.                     * geometry.sectors
  178.  
  179.                 + p->end_sector
  180.  
  181.                 - 1
  182.  
  183.             )
  184.  
  185.         )
  186.  
  187.         {
  188.  
  189.             p->end_cylinder += 1024;    // more than 1024 cylinders
  190.  
  191.         }
  192.  
  193.     }
  194.  
  195. }
  196.  
  197.  
  198.  
  199.  
  200.  
  201. /* ----------------------------------------------------------------------- */
  202.  
  203. /* Extract Partition Table from root sector                                */
  204.  
  205. /* ----------------------------------------------------------------------- */
  206.  
  207.  
  208.  
  209. void partition_table::get (root_sector *root_sector)
  210.  
  211. {
  212.  
  213.     for (int i=0;i<4;i++)
  214.  
  215.     {
  216.  
  217.         class partition_info *p = &partition_info[i];
  218.  
  219.         byte *pi = &(root_sector->data[0x1be+16*i]);
  220.  
  221.  
  222.  
  223.         p->bootable = *pi;
  224.  
  225.         p->start_head = *(pi+1);
  226.  
  227.         p->start_cylinder = *(pi+3) | ((*(pi+2) << 2) & 0x300);
  228.  
  229.         p->start_sector = *(pi+2) & 0x3f;
  230.  
  231.         p->system = *(pi+4);
  232.  
  233.         p->end_head = *(pi+5);
  234.  
  235.         p->end_cylinder = *(pi+7) | ((*(pi+6) << 2) & 0x300);
  236.  
  237.         p->end_sector = *(pi+6) & 0x3f;
  238.  
  239.         p->start_sector_abs = (dword) *(pi+8) | ((dword) *(pi+9) << 8) | ((dword) *(pi+10) << 16) | ((dword) *(pi+11) << 24);
  240.  
  241.         p->no_of_sectors_abs = (dword) *(pi+12) | ((dword) *(pi+13) << 8) | ((dword) *(pi+14) << 16) | ((dword) *(pi+15) << 24);
  242.  
  243.     }
  244.  
  245. }
  246.  
  247.  
  248.  
  249.  
  250.  
  251. /* ----------------------------------------------------------------------- */
  252.  
  253. /* Write Partition Table back into root sector                             */
  254.  
  255. /* ----------------------------------------------------------------------- */
  256.  
  257.  
  258.  
  259. void partition_table::put (root_sector *root_sector)
  260.  
  261. {
  262.  
  263.     for (int i=0; i<4; i++)
  264.  
  265.     {
  266.  
  267.         class partition_info p = partition_info[i];
  268.  
  269.         byte *pi = &(root_sector->data[0x1be+16*i]);
  270.  
  271.  
  272.  
  273.         *pi = p.bootable;
  274.  
  275.         *(pi+1) = p.start_head;
  276.  
  277.         *(pi+2) = ((p.start_cylinder >> 2) & 0xc0) | (p.start_sector & 0x3f);
  278.  
  279.         *(pi+3) = p.start_cylinder & 0xff;
  280.  
  281.         *(pi+4) = p.system;
  282.  
  283.         *(pi+5) = p.end_head;
  284.  
  285.         *(pi+6) = ((p.end_cylinder >> 2) & 0xc0) | (p.end_sector & 0x3f);
  286.  
  287.         *(pi+7) = p.end_cylinder & 0xff;
  288.  
  289.         *(pi+8) = p.start_sector_abs & 0xff;
  290.  
  291.         *(pi+9) = (p.start_sector_abs >> 8) & 0xff;
  292.  
  293.         *(pi+10) = (p.start_sector_abs >> 16) & 0xff;
  294.  
  295.         *(pi+11) = (p.start_sector_abs >> 24) & 0xff;
  296.  
  297.         *(pi+12) = p.no_of_sectors_abs & 0xff;
  298.  
  299.         *(pi+13) = (p.no_of_sectors_abs >> 8) & 0xff;
  300.  
  301.         *(pi+14) = (p.no_of_sectors_abs >> 16) & 0xff;
  302.  
  303.         *(pi+15) = (p.no_of_sectors_abs >> 24) & 0xff;
  304.  
  305.     }
  306.  
  307. }
  308.  
  309.