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

  1. /*
  2.  
  3.     FIPS - the First nondestructive Interactive Partition Splitting program
  4.  
  5.  
  6.  
  7.     Module hdstruct.h
  8.  
  9.  
  10.  
  11.     RCS - Header:
  12.  
  13.     $Header: c:/daten/fips/source/main/RCS/hdstruct.h 1.4 1995/01/19 00:01:26 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. #ifndef HDSTRUCT_H
  62.  
  63. #define HDSTRUCT_H
  64.  
  65.  
  66.  
  67. #include "types.h"
  68.  
  69. #include "disk_io.h"
  70.  
  71.  
  72.  
  73.  
  74.  
  75. /* ----------------------------------------------------------------------- */
  76.  
  77. /* Class root_sector - derived from structure sector                        */
  78.  
  79. /* Must be initialized with a pointer to a physical_drive object           */
  80.  
  81. /* Read() and Write() read/write sector 0 of physical drive                */
  82.  
  83. /* ----------------------------------------------------------------------- */
  84.  
  85.  
  86.  
  87. class root_sector:public sector
  88.  
  89. {
  90.  
  91.     physical_drive *drive;
  92.  
  93. public:
  94.  
  95. // constructors and operators
  96.  
  97.  
  98.  
  99.     root_sector (physical_drive *drive) { root_sector::drive = drive; }
  100.  
  101.     root_sector (root_sector &rs);
  102.  
  103.     void operator= (root_sector &rs);
  104.  
  105.  
  106.  
  107.  
  108.  
  109. // functions
  110.  
  111.  
  112.  
  113.     int read (void) { return drive->read_sector (this, 0); }
  114.  
  115.     int write (void) { return drive->write_sector (this, 0); }
  116.  
  117. };
  118.  
  119.  
  120.  
  121.  
  122.  
  123. /* ----------------------------------------------------------------------- */
  124.  
  125. /* Partition Info Structure                                                */
  126.  
  127. /* Each entry in the partition table contains this information             */
  128.  
  129. /* ----------------------------------------------------------------------- */
  130.  
  131.  
  132.  
  133. struct partition_info
  134.  
  135. {
  136.  
  137.     byte bootable;                  // 80h or 0
  138.  
  139.     byte start_head;                // location of first sector (boot_sector)
  140.  
  141.     word start_cylinder;
  142.  
  143.     byte start_sector;
  144.  
  145.     byte system;            // 1 = 12-bit FAT
  146.  
  147.                     // 4 = 16-bit FAT & 16-bit sector number
  148.  
  149.                     // 6 = 16-bit FAT & 32-bit sector number (BIGDOS)
  150.  
  151.     byte end_head;                  // location of last sector
  152.  
  153.     word end_cylinder;
  154.  
  155.     byte end_sector;
  156.  
  157.     dword start_sector_abs;         // = start_cylinder * heads * sectors
  158.  
  159.                     // + start_head * sectors + start_sector - 1
  160.  
  161.     dword no_of_sectors_abs;        // = end_cylinder * heads * sectors + end_head * sectors
  162.  
  163.                     // + end_sector - start_sector_abs
  164.  
  165. };
  166.  
  167.  
  168.  
  169.  
  170.  
  171. /* ----------------------------------------------------------------------- */
  172.  
  173. /* Partition Table Structure                                               */
  174.  
  175. /* The partition table consists of 4 entries for the 4 possible partitions */
  176.  
  177. /* Get() reads the partition table from the root_sector, put() writes the   */
  178.  
  179. /* data back into the root_sector buffer                                    */
  180.  
  181. /* ----------------------------------------------------------------------- */
  182.  
  183.  
  184.  
  185. struct partition_table
  186.  
  187. {
  188.  
  189.     partition_info partition_info[4];
  190.  
  191.     void get (root_sector *root_sector);
  192.  
  193.     void put (root_sector *root_sector);
  194.  
  195. };
  196.  
  197.  
  198.  
  199.  
  200.  
  201. /* ----------------------------------------------------------------------- */
  202.  
  203. /* Harddrive Class, derived from physical_drive                            */
  204.  
  205. /* Represents one physical harddrive. Must be initialized with the drive   */
  206.  
  207. /* number (0x80 for 1st HDD). Contains the root_sector and partition table. */
  208.  
  209. /* ----------------------------------------------------------------------- */
  210.  
  211.  
  212.  
  213. class harddrive:public physical_drive
  214.  
  215. {
  216.  
  217.     partition_table pr_partition_table;
  218.  
  219.  
  220.  
  221. public:
  222.  
  223. // constructors, destructors, operators
  224.  
  225.  
  226.  
  227.     harddrive (int number):physical_drive (number)
  228.  
  229.     {
  230.  
  231.         root_sector = new class root_sector (this);
  232.  
  233.     }
  234.  
  235.     harddrive (harddrive &hd):physical_drive (hd)
  236.  
  237.     {
  238.  
  239.         root_sector = new class root_sector (*(hd.root_sector));
  240.  
  241.         partition_table () = hd.partition_table ();
  242.  
  243.     }
  244.  
  245.     void operator= (harddrive &hd);
  246.  
  247.     ~harddrive (void) { delete root_sector; }
  248.  
  249.  
  250.  
  251. // public data
  252.  
  253.  
  254.  
  255.     root_sector *root_sector;
  256.  
  257.  
  258.  
  259. // member access functions
  260.  
  261.  
  262.  
  263.     virtual partition_table &partition_table() { return pr_partition_table; }
  264.  
  265.  
  266.  
  267. // functions
  268.  
  269.  
  270.  
  271.     int read_root_sector (void) { return (root_sector->read ()); }
  272.  
  273.     int write_root_sector (void) { return (root_sector->write ()); }
  274.  
  275.  
  276.  
  277.     void get_partition_table (void);    // extract pt data from root sector
  278.  
  279.     void put_partition_table (void)        // put pt data into root sector
  280.  
  281.     {partition_table().put (root_sector);}
  282.  
  283. };
  284.  
  285.  
  286.  
  287. #endif
  288.  
  289.