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

  1. /*
  2.     FIPS - the First nondestructive Interactive Partition Splitting program
  3.  
  4.     Module disk_io.h
  5.  
  6.     RCS - Header:
  7.     $Header: c:/daten/fips/source/main/RCS/disk_io.h 1.4 1995/01/19 00:01: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 DISK_IO_H
  32. #define DISK_IO_H
  33.  
  34. #include "types.h"
  35.  
  36.  
  37. /* ----------------------------------------------------------------------- */
  38. /* Structure to hold information about the drive geometry                  */
  39. /* ----------------------------------------------------------------------- */
  40.  
  41. struct drive_geometry
  42. {
  43.     dword heads;
  44.     dword cylinders;
  45.     dword sectors;
  46. };
  47.  
  48.  
  49. /* ----------------------------------------------------------------------- */
  50. /* Low level structure physical_drive, contains drive number and geometry, */
  51. /* as well as low level sector read and write routines                     */
  52. /* Geometry is determined on initialization, errorcode contains error      */
  53. /* number after call to get_geometry() and reset().                        */
  54. /* Initialization requires number (e.g. physical_drive drive1 (0x80);).    */
  55. /*                                                                         */
  56. /* Read and write are called max. 3 times in case of failure, return code  */
  57. /* contains 0 if successful. Sector CRC is verified after write.           */
  58. /* sector_number is absolute logical sector number (0 = master boot record)*/
  59. /* ----------------------------------------------------------------------- */
  60.  
  61. class physical_drive
  62. {
  63. protected:
  64.     virtual void get_geometry (void);
  65.  
  66. public:
  67. // constructors & operators
  68.  
  69.     physical_drive (int number);
  70.     physical_drive (physical_drive &pd);
  71.     void operator= (physical_drive &pd);
  72.  
  73. // public data
  74.  
  75.     int number;
  76.     int errorcode;
  77.     drive_geometry geometry;
  78.  
  79. // functions
  80.  
  81.     virtual void reset (void);
  82.  
  83.     int read_sector (struct sector* sector, dword sector_number);
  84.     int write_sector (struct sector* sector, dword sector_number);
  85. };
  86.  
  87.  
  88. /* ----------------------------------------------------------------------- */
  89. /* Physical_sector_no holds and calculates physical sector number (Head,   */
  90. /* Cylinder, Sector). Number is calculated on initialization. Log_sector   */
  91. /* is absolute logical sector number (0 = master boot record). Usage:      */
  92. /* physical_sector_no mbr (0,geometry);                                    */
  93. /* physical_sector_no mbr (0,0,1);                                         */
  94. /* ----------------------------------------------------------------------- */
  95.  
  96. struct physical_sector_no
  97. {
  98. // public data
  99.  
  100.     dword head;
  101.     dword cylinder;
  102.     dword sector;
  103.  
  104. // constructors
  105.  
  106.     physical_sector_no (dword logical_sector, const drive_geometry &geometry);
  107.     physical_sector_no (dword head, dword cylinder, dword sector)
  108.     {
  109.         physical_sector_no::head = head;
  110.         physical_sector_no::cylinder = cylinder;
  111.         physical_sector_no::sector = sector;
  112.     }
  113. };
  114.  
  115.  
  116. /* ----------------------------------------------------------------------- */
  117. /* Structure sector - contains only sector data                            */
  118. /* ----------------------------------------------------------------------- */
  119.  
  120. struct sector
  121. {
  122.     byte data[512];
  123. };
  124.  
  125.  
  126. /* ----------------------------------------------------------------------- */
  127. /* Prototype for bios call get_disk_type - returns 0 if drive not present. */
  128. /* Valid drive numbers: 0 - 255, result: 1 - floppy without disk change    */
  129. /* detection, 2 - floppy with disk change detection, 3 - harddisk          */
  130. /* ----------------------------------------------------------------------- */
  131.  
  132. int get_disk_type (int drive_number);
  133.  
  134. /* Bios call get_no_of_drives */
  135.  
  136. int get_no_of_drives (void);
  137.  
  138. #endif
  139.