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

  1. /*
  2.     FIPS - the First nondestructive Interactive Partition Splitting program
  3.  
  4.     Module hdstruct.h
  5.  
  6.     RCS - Header:
  7.     $Header: c:/daten/fips/source/main/RCS/hdstruct.h 1.4 1995/01/19 00:01:26 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. #ifndef HDSTRUCT_H
  32. #define HDSTRUCT_H
  33.  
  34. #include "types.h"
  35. #include "disk_io.h"
  36.  
  37.  
  38. /* ----------------------------------------------------------------------- */
  39. /* Class root_sector - derived from structure sector                        */
  40. /* Must be initialized with a pointer to a physical_drive object           */
  41. /* Read() and Write() read/write sector 0 of physical drive                */
  42. /* ----------------------------------------------------------------------- */
  43.  
  44. class root_sector:public sector
  45. {
  46.     physical_drive *drive;
  47. public:
  48. // constructors and operators
  49.  
  50.     root_sector (physical_drive *drive) { root_sector::drive = drive; }
  51.     root_sector (root_sector &rs);
  52.     void operator= (root_sector &rs);
  53.  
  54.  
  55. // functions
  56.  
  57.     int read (void) { return drive->read_sector (this, 0); }
  58.     int write (void) { return drive->write_sector (this, 0); }
  59. };
  60.  
  61.  
  62. /* ----------------------------------------------------------------------- */
  63. /* Partition Info Structure                                                */
  64. /* Each entry in the partition table contains this information             */
  65. /* ----------------------------------------------------------------------- */
  66.  
  67. struct partition_info
  68. {
  69.     byte bootable;                  // 80h or 0
  70.     byte start_head;                // location of first sector (boot_sector)
  71.     word start_cylinder;
  72.     byte start_sector;
  73.     byte system;            // 1 = 12-bit FAT
  74.                     // 4 = 16-bit FAT & 16-bit sector number
  75.                     // 6 = 16-bit FAT & 32-bit sector number (BIGDOS)
  76.     byte end_head;                  // location of last sector
  77.     word end_cylinder;
  78.     byte end_sector;
  79.     dword start_sector_abs;         // = start_cylinder * heads * sectors
  80.                     // + start_head * sectors + start_sector - 1
  81.     dword no_of_sectors_abs;        // = end_cylinder * heads * sectors + end_head * sectors
  82.                     // + end_sector - start_sector_abs
  83. };
  84.  
  85.  
  86. /* ----------------------------------------------------------------------- */
  87. /* Partition Table Structure                                               */
  88. /* The partition table consists of 4 entries for the 4 possible partitions */
  89. /* Get() reads the partition table from the root_sector, put() writes the   */
  90. /* data back into the root_sector buffer                                    */
  91. /* ----------------------------------------------------------------------- */
  92.  
  93. struct partition_table
  94. {
  95.     partition_info partition_info[4];
  96.     void get (root_sector *root_sector);
  97.     void put (root_sector *root_sector);
  98. };
  99.  
  100.  
  101. /* ----------------------------------------------------------------------- */
  102. /* Harddrive Class, derived from physical_drive                            */
  103. /* Represents one physical harddrive. Must be initialized with the drive   */
  104. /* number (0x80 for 1st HDD). Contains the root_sector and partition table. */
  105. /* ----------------------------------------------------------------------- */
  106.  
  107. class harddrive:public physical_drive
  108. {
  109.     partition_table pr_partition_table;
  110.  
  111. public:
  112. // constructors, destructors, operators
  113.  
  114.     harddrive (int number):physical_drive (number)
  115.     {
  116.         root_sector = new class root_sector (this);
  117.     }
  118.     harddrive (harddrive &hd):physical_drive (hd)
  119.     {
  120.         root_sector = new class root_sector (*(hd.root_sector));
  121.         partition_table () = hd.partition_table ();
  122.     }
  123.     void operator= (harddrive &hd);
  124.     ~harddrive (void) { delete root_sector; }
  125.  
  126. // public data
  127.  
  128.     root_sector *root_sector;
  129.  
  130. // member access functions
  131.  
  132.     virtual partition_table &partition_table() { return pr_partition_table; }
  133.  
  134. // functions
  135.  
  136.     int read_root_sector (void) { return (root_sector->read ()); }
  137.     int write_root_sector (void) { return (root_sector->write ()); }
  138.  
  139.     void get_partition_table (void);    // extract pt data from root sector
  140.     void put_partition_table (void)        // put pt data into root sector
  141.     {partition_table().put (root_sector);}
  142. };
  143.  
  144. #endif
  145.