home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 8 / CDACTUAL8.iso / install / fips / source / hdstruct.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-11  |  6.0 KB  |  167 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.1 1994/05/25 22:20:25 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. #include "logdr_st.h" 
  37.  
  38. /* ----------------------------------------------------------------------- */ 
  39. /* Class rootsector - 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 rootsector:public sector 
  45.     physical_drive *drive; 
  46. public: 
  47.     int read (void) { return sector::read (drive,0); } 
  48.     int write (void) { return sector::write (drive,0); } 
  49.  
  50.     rootsector (physical_drive *drive) { rootsector::drive = drive; } 
  51.     rootsector (rootsector &rs); 
  52.     void operator= (rootsector &rs); 
  53. }; 
  54.  
  55. /* ----------------------------------------------------------------------- */ 
  56. /* Partition Info Structure                                                */ 
  57. /* Each entry in the partition table contains this information             */ 
  58. /* ----------------------------------------------------------------------- */ 
  59.  
  60. struct partition_info 
  61.     byte bootable;                  // 80h or 0 
  62.     byte start_head;                // location of first sector (bootsector) 
  63.     word start_cylinder; 
  64.     byte start_sector; 
  65.     byte system;            // 1 = 12-bit FAT 
  66.                     // 4 = 16-bit FAT & 16-bit sector number 
  67.                     // 6 = 16-bit FAT & 32-bit sector number (BIGDOS) 
  68.     byte end_head;                  // location of last sector 
  69.     word end_cylinder; 
  70.     byte end_sector; 
  71.     dword start_sector_abs;         // = start_cylinder * heads * sectors 
  72.                     // + start_head * sectors + start_sector - 1 
  73.     dword no_of_sectors_abs;        // = end_cylinder * heads * sectors + end_head * sectors 
  74.                     // + end_sector - start_sector_abs 
  75. }; 
  76.  
  77. /* ----------------------------------------------------------------------- */ 
  78. /* Partition Table Structure                                               */ 
  79. /* The partition table consists of 4 entries for the 4 possible partitions */ 
  80. /* Get() reads the partition table from the rootsector, put() writes the   */ 
  81. /* data back into the rootsector buffer                                    */ 
  82. /* ----------------------------------------------------------------------- */ 
  83.  
  84. struct partition_table 
  85.     partition_info partition_info[4]; 
  86.     void get (rootsector *rootsector); 
  87.     void put (rootsector *rootsector); 
  88. }; 
  89.  
  90. /* ----------------------------------------------------------------------- */ 
  91. /* Harddrive Class, derived from physical_drive                            */ 
  92. /* Represents one physical harddrive. Must be initialized with the drive   */ 
  93. /* number (0x80 for 1st HDD). Contains the rootsector and partition table. */ 
  94. /* ----------------------------------------------------------------------- */ 
  95.  
  96. class harddrive:public physical_drive 
  97.     partition_table pr_partition_table; 
  98. public: 
  99.     rootsector *rootsector; 
  100.     virtual partition_table &partition_table() { return pr_partition_table; } 
  101.  
  102.     harddrive (int number):physical_drive (number) 
  103.     { 
  104.         rootsector = new class rootsector (this); 
  105.     } 
  106.     harddrive (harddrive &hd):physical_drive (hd) 
  107.     { 
  108.         rootsector = new class rootsector (*(hd.rootsector)); 
  109.         partition_table () = hd.partition_table(); 
  110.     } 
  111.     void operator= (harddrive &hd); 
  112.     ~harddrive (void) { delete rootsector; } 
  113. }; 
  114.  
  115. /* ----------------------------------------------------------------------- */ 
  116. /* Raw Partition Class                                                     */ 
  117. /* Represents one partition from the partition table (may be non-DOS)      */ 
  118. /* Initialization with the pointer to the harddrive object and the         */ 
  119. /* partition number (0-3)                                                  */ 
  120. /* ----------------------------------------------------------------------- */ 
  121.  
  122. class raw_partition 
  123. public: 
  124.     int number; 
  125.     physical_drive *drive; 
  126.     partition_info *partition_info; 
  127.  
  128.     raw_partition (class harddrive *drive,int number) 
  129.     { 
  130.         raw_partition::number = number; 
  131.         raw_partition::drive = drive; 
  132.         partition_info = &(drive->partition_table().partition_info[number]); 
  133.     } 
  134. }; 
  135.      
  136. /* ----------------------------------------------------------------------- */ 
  137. /* Partition Class, derived from logical_drive and raw_partition           */ 
  138. /* Represents one primary DOS partition. Read_sector() and write_sector()  */ 
  139. /* are instances of the virtual functions in the logical_drive class       */ 
  140. /* ----------------------------------------------------------------------- */ 
  141.  
  142. class partition:public logical_drive,public raw_partition 
  143. public: 
  144.     int read_sector (dword number,sector *sector) 
  145.     { 
  146.         return (sector->read (drive,partition_info->start_sector_abs + number)); 
  147.     } 
  148.     int write_sector (dword number,sector *sector) 
  149.     { 
  150.         return (sector->write (drive,partition_info->start_sector_abs + number)); 
  151.     } 
  152.  
  153.     partition (class harddrive *drive,int number):raw_partition(drive,number) 
  154.     { 
  155.         bootsector = new class bootsector (this); 
  156.     } 
  157.     ~partition (void) { delete bootsector; } 
  158. }; 
  159.  
  160. #endif 
  161.