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

  1. /*
  2.     FIPS - the First nondestructive Interactive Partition Splitting program
  3.  
  4.     Module logdr_st.h
  5.  
  6.     RCS - Header:
  7.     $Header: c:/daten/fips/source/main/RCS/logdr_st.h 1.4 1995/01/19 00:01:27 schaefer Exp $
  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 LOGDR_ST_H
  32. #define LOGDR_ST_H
  33.  
  34. #include "types.h"
  35. #include "disk_io.h"
  36.  
  37.  
  38. /* ----------------------------------------------------------------------- */
  39. /* Class boot_sector - derived from structure sector                       */
  40. /* Must be initialized with pointer to logical drive object                */
  41. /* Read() and write() read/write sector 0 of logical drive                 */
  42. /* ----------------------------------------------------------------------- */
  43.  
  44. class boot_sector:public sector
  45. {
  46.     class logical_drive *logical_drive;
  47. public:
  48. // constructor
  49.  
  50.     boot_sector (class logical_drive *logical_drive)
  51.     { boot_sector::logical_drive = logical_drive; }
  52.  
  53.  
  54. // functions
  55.  
  56.     int read (void);
  57.     int write (void);
  58. };
  59.  
  60.  
  61. /* ------------------------------------------------------------------------ */
  62. /* Bios Parameter Block structure                                           */
  63. /* This is not exactly the BPB as understood by DOS, because it contains    */
  64. /* the additional fields that are in the boot_sector like jump_instruction, */
  65. /* oem_name etc. Get() extracts info from the boot_sector, put() writes the */
  66. /* info back into the boot_sector buffer.                                   */
  67. /* ------------------------------------------------------------------------ */
  68.  
  69. struct bios_parameter_block
  70. {
  71.     byte jump_instruction[3];    // EB xx 90 or E9 xx xx
  72.     char oem_name[9];
  73.     word bytes_per_sector;          // usually 512
  74.     byte sectors_per_cluster;       // may differ
  75.     word reserved_sectors;          // usually 1 (boot_sector)
  76.     byte no_of_fats;                // usually 2
  77.     word no_of_rootdir_entries;     // usually 512 for HDs (?), 224 for
  78.                     // HD-Floppies, 112 for DD-Floppies
  79.     word no_of_sectors;             // 0 on BIGDOS partitions
  80.     byte media_descriptor;          // usually F8h
  81.     word sectors_per_fat;           // depends on partition size
  82.     word sectors_per_track;         // depends on drive
  83.     word drive_heads;               // dto.
  84.     dword hidden_sectors;           // first sector of partition or 0 for FDs
  85.     dword no_of_sectors_long;       // number of sectors on BIGDOS partitions
  86.     byte phys_drive_no;             // usually 80h
  87.     byte signature;                 // usually 29h
  88.     dword serial_number;            // random
  89.     char volume_label[12];
  90.     char file_system_id[9];
  91.  
  92.     void get (boot_sector *boot_sector);
  93.     void put (boot_sector *boot_sector);
  94. };
  95.  
  96.  
  97. /* ----------------------------------------------------------------------- */
  98. /* Some miscellaneous figures about the drive                              */
  99. /* Get() extracts this info from the BPB                                   */
  100. /* ----------------------------------------------------------------------- */
  101.  
  102. struct logical_drive_info
  103. {
  104.     dword start_fat1;
  105.     dword start_fat2;
  106.     dword start_rootdir;
  107.     dword start_data;
  108.     dword no_of_clusters;
  109.  
  110.     virtual void get (const bios_parameter_block &bpb);
  111. };
  112.  
  113.  
  114. /* ----------------------------------------------------------------------- */
  115. /* Abstract Class logical_drive. This can be any DOS drive that allows     */
  116. /* direct reading and writing of sectors, like Harddisk Partitions, Floppy */
  117. /* disks or Ramdisks                                                       */
  118. /* ----------------------------------------------------------------------- */
  119.  
  120. class logical_drive
  121. {
  122. // private data
  123.  
  124.     struct bios_parameter_block pr_bpb;
  125.     struct logical_drive_info pr_info;
  126.  
  127. public:
  128.  
  129. // public data
  130.  
  131.     class boot_sector *boot_sector;
  132.  
  133. // member access functions
  134.  
  135.     virtual bios_parameter_block &bpb() { return pr_bpb; }
  136.     virtual logical_drive_info &info() { return pr_info; }
  137.  
  138. // functions
  139.  
  140.     virtual int read_sector (dword number,sector *sector) = 0;
  141.     virtual int write_sector (dword number,sector *sector) = 0;
  142.     // pure virtual functions
  143.  
  144.     int read_boot_sector (void) { return (boot_sector->read ()); }
  145.     int write_boot_sector (void) { return (boot_sector->write ()); }
  146.  
  147.     void get_bpb (void) { bpb().get (boot_sector); }
  148.     void put_bpb (void) { bpb().put (boot_sector); }
  149.  
  150.     void get_info (void) { info().get (bpb ()); }
  151. };
  152.  
  153.  
  154. /* ----------------------------------------------------------------------- */
  155. /* Function to read boot_sector from logical drive                         */
  156. /* It must be in the header file because it is inline                      */
  157. /* ----------------------------------------------------------------------- */
  158.  
  159. inline int boot_sector::read (void)
  160. {
  161.     return logical_drive->read_sector (0,this);
  162. }
  163.  
  164.  
  165. /* ----------------------------------------------------------------------- */
  166. /* Function to write boot_sector to logical drive                          */
  167. /* ----------------------------------------------------------------------- */
  168.  
  169. inline int boot_sector::write (void)
  170. {
  171.     return logical_drive->write_sector (0,this);
  172. }
  173.  
  174. #endif
  175.