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

  1. /*
  2.  
  3.     FIPS - the First nondestructive Interactive Partition Splitting program
  4.  
  5.  
  6.  
  7.     Module logdr_st.h
  8.  
  9.  
  10.  
  11.     RCS - Header:
  12.  
  13.     $Header: c:/daten/fips/source/main/RCS/logdr_st.h 1.4 1995/01/19 00:01:27 schaefer Exp $
  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 LOGDR_ST_H
  62.  
  63. #define LOGDR_ST_H
  64.  
  65.  
  66.  
  67. #include "types.h"
  68.  
  69. #include "disk_io.h"
  70.  
  71.  
  72.  
  73.  
  74.  
  75. /* ----------------------------------------------------------------------- */
  76.  
  77. /* Class boot_sector - derived from structure sector                       */
  78.  
  79. /* Must be initialized with pointer to logical drive object                */
  80.  
  81. /* Read() and write() read/write sector 0 of logical drive                 */
  82.  
  83. /* ----------------------------------------------------------------------- */
  84.  
  85.  
  86.  
  87. class boot_sector:public sector
  88.  
  89. {
  90.  
  91.     class logical_drive *logical_drive;
  92.  
  93. public:
  94.  
  95. // constructor
  96.  
  97.  
  98.  
  99.     boot_sector (class logical_drive *logical_drive)
  100.  
  101.     { boot_sector::logical_drive = logical_drive; }
  102.  
  103.  
  104.  
  105.  
  106.  
  107. // functions
  108.  
  109.  
  110.  
  111.     int read (void);
  112.  
  113.     int write (void);
  114.  
  115. };
  116.  
  117.  
  118.  
  119.  
  120.  
  121. /* ------------------------------------------------------------------------ */
  122.  
  123. /* Bios Parameter Block structure                                           */
  124.  
  125. /* This is not exactly the BPB as understood by DOS, because it contains    */
  126.  
  127. /* the additional fields that are in the boot_sector like jump_instruction, */
  128.  
  129. /* oem_name etc. Get() extracts info from the boot_sector, put() writes the */
  130.  
  131. /* info back into the boot_sector buffer.                                   */
  132.  
  133. /* ------------------------------------------------------------------------ */
  134.  
  135.  
  136.  
  137. struct bios_parameter_block
  138.  
  139. {
  140.  
  141.     byte jump_instruction[3];    // EB xx 90 or E9 xx xx
  142.  
  143.     char oem_name[9];
  144.  
  145.     word bytes_per_sector;          // usually 512
  146.  
  147.     byte sectors_per_cluster;       // may differ
  148.  
  149.     word reserved_sectors;          // usually 1 (boot_sector)
  150.  
  151.     byte no_of_fats;                // usually 2
  152.  
  153.     word no_of_rootdir_entries;     // usually 512 for HDs (?), 224 for
  154.  
  155.                     // HD-Floppies, 112 for DD-Floppies
  156.  
  157.     word no_of_sectors;             // 0 on BIGDOS partitions
  158.  
  159.     byte media_descriptor;          // usually F8h
  160.  
  161.     word sectors_per_fat;           // depends on partition size
  162.  
  163.     word sectors_per_track;         // depends on drive
  164.  
  165.     word drive_heads;               // dto.
  166.  
  167.     dword hidden_sectors;           // first sector of partition or 0 for FDs
  168.  
  169.     dword no_of_sectors_long;       // number of sectors on BIGDOS partitions
  170.  
  171.     byte phys_drive_no;             // usually 80h
  172.  
  173.     byte signature;                 // usually 29h
  174.  
  175.     dword serial_number;            // random
  176.  
  177.     char volume_label[12];
  178.  
  179.     char file_system_id[9];
  180.  
  181.  
  182.  
  183.     void get (boot_sector *boot_sector);
  184.  
  185.     void put (boot_sector *boot_sector);
  186.  
  187. };
  188.  
  189.  
  190.  
  191.  
  192.  
  193. /* ----------------------------------------------------------------------- */
  194.  
  195. /* Some miscellaneous figures about the drive                              */
  196.  
  197. /* Get() extracts this info from the BPB                                   */
  198.  
  199. /* ----------------------------------------------------------------------- */
  200.  
  201.  
  202.  
  203. struct logical_drive_info
  204.  
  205. {
  206.  
  207.     dword start_fat1;
  208.  
  209.     dword start_fat2;
  210.  
  211.     dword start_rootdir;
  212.  
  213.     dword start_data;
  214.  
  215.     dword no_of_clusters;
  216.  
  217.  
  218.  
  219.     virtual void get (const bios_parameter_block &bpb);
  220.  
  221. };
  222.  
  223.  
  224.  
  225.  
  226.  
  227. /* ----------------------------------------------------------------------- */
  228.  
  229. /* Abstract Class logical_drive. This can be any DOS drive that allows     */
  230.  
  231. /* direct reading and writing of sectors, like Harddisk Partitions, Floppy */
  232.  
  233. /* disks or Ramdisks                                                       */
  234.  
  235. /* ----------------------------------------------------------------------- */
  236.  
  237.  
  238.  
  239. class logical_drive
  240.  
  241. {
  242.  
  243. // private data
  244.  
  245.  
  246.  
  247.     struct bios_parameter_block pr_bpb;
  248.  
  249.     struct logical_drive_info pr_info;
  250.  
  251.  
  252.  
  253. public:
  254.  
  255.  
  256.  
  257. // public data
  258.  
  259.  
  260.  
  261.     class boot_sector *boot_sector;
  262.  
  263.  
  264.  
  265. // member access functions
  266.  
  267.  
  268.  
  269.     virtual bios_parameter_block &bpb() { return pr_bpb; }
  270.  
  271.     virtual logical_drive_info &info() { return pr_info; }
  272.  
  273.  
  274.  
  275. // functions
  276.  
  277.  
  278.  
  279.     virtual int read_sector (dword number,sector *sector) = 0;
  280.  
  281.     virtual int write_sector (dword number,sector *sector) = 0;
  282.  
  283.     // pure virtual functions
  284.  
  285.  
  286.  
  287.     int read_boot_sector (void) { return (boot_sector->read ()); }
  288.  
  289.     int write_boot_sector (void) { return (boot_sector->write ()); }
  290.  
  291.  
  292.  
  293.     void get_bpb (void) { bpb().get (boot_sector); }
  294.  
  295.     void put_bpb (void) { bpb().put (boot_sector); }
  296.  
  297.  
  298.  
  299.     void get_info (void) { info().get (bpb ()); }
  300.  
  301. };
  302.  
  303.  
  304.  
  305.  
  306.  
  307. /* ----------------------------------------------------------------------- */
  308.  
  309. /* Function to read boot_sector from logical drive                         */
  310.  
  311. /* It must be in the header file because it is inline                      */
  312.  
  313. /* ----------------------------------------------------------------------- */
  314.  
  315.  
  316.  
  317. inline int boot_sector::read (void)
  318.  
  319. {
  320.  
  321.     return logical_drive->read_sector (0,this);
  322.  
  323. }
  324.  
  325.  
  326.  
  327.  
  328.  
  329. /* ----------------------------------------------------------------------- */
  330.  
  331. /* Function to write boot_sector to logical drive                          */
  332.  
  333. /* ----------------------------------------------------------------------- */
  334.  
  335.  
  336.  
  337. inline int boot_sector::write (void)
  338.  
  339. {
  340.  
  341.     return logical_drive->write_sector (0,this);
  342.  
  343. }
  344.  
  345.  
  346.  
  347. #endif
  348.  
  349.