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

  1. /*
  2.  
  3.     FIPS - the First nondestructive Interactive Partition Splitting program
  4.  
  5.  
  6.  
  7.     Module disk_io.h
  8.  
  9.  
  10.  
  11.     RCS - Header:
  12.  
  13.     $Header: c:/daten/fips/source/main/RCS/disk_io.h 1.4 1995/01/19 00:01:25 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 DISK_IO_H
  62.  
  63. #define DISK_IO_H
  64.  
  65.  
  66.  
  67. #include "types.h"
  68.  
  69.  
  70.  
  71.  
  72.  
  73. /* ----------------------------------------------------------------------- */
  74.  
  75. /* Structure to hold information about the drive geometry                  */
  76.  
  77. /* ----------------------------------------------------------------------- */
  78.  
  79.  
  80.  
  81. struct drive_geometry
  82.  
  83. {
  84.  
  85.     dword heads;
  86.  
  87.     dword cylinders;
  88.  
  89.     dword sectors;
  90.  
  91. };
  92.  
  93.  
  94.  
  95.  
  96.  
  97. /* ----------------------------------------------------------------------- */
  98.  
  99. /* Low level structure physical_drive, contains drive number and geometry, */
  100.  
  101. /* as well as low level sector read and write routines                     */
  102.  
  103. /* Geometry is determined on initialization, errorcode contains error      */
  104.  
  105. /* number after call to get_geometry() and reset().                        */
  106.  
  107. /* Initialization requires number (e.g. physical_drive drive1 (0x80);).    */
  108.  
  109. /*                                                                         */
  110.  
  111. /* Read and write are called max. 3 times in case of failure, return code  */
  112.  
  113. /* contains 0 if successful. Sector CRC is verified after write.           */
  114.  
  115. /* sector_number is absolute logical sector number (0 = master boot record)*/
  116.  
  117. /* ----------------------------------------------------------------------- */
  118.  
  119.  
  120.  
  121. class physical_drive
  122.  
  123. {
  124.  
  125. protected:
  126.  
  127.     virtual void get_geometry (void);
  128.  
  129.  
  130.  
  131. public:
  132.  
  133. // constructors & operators
  134.  
  135.  
  136.  
  137.     physical_drive (int number);
  138.  
  139.     physical_drive (physical_drive &pd);
  140.  
  141.     void operator= (physical_drive &pd);
  142.  
  143.  
  144.  
  145. // public data
  146.  
  147.  
  148.  
  149.     int number;
  150.  
  151.     int errorcode;
  152.  
  153.     drive_geometry geometry;
  154.  
  155.  
  156.  
  157. // functions
  158.  
  159.  
  160.  
  161.     virtual void reset (void);
  162.  
  163.  
  164.  
  165.     int read_sector (struct sector* sector, dword sector_number);
  166.  
  167.     int write_sector (struct sector* sector, dword sector_number);
  168.  
  169. };
  170.  
  171.  
  172.  
  173.  
  174.  
  175. /* ----------------------------------------------------------------------- */
  176.  
  177. /* Physical_sector_no holds and calculates physical sector number (Head,   */
  178.  
  179. /* Cylinder, Sector). Number is calculated on initialization. Log_sector   */
  180.  
  181. /* is absolute logical sector number (0 = master boot record). Usage:      */
  182.  
  183. /* physical_sector_no mbr (0,geometry);                                    */
  184.  
  185. /* physical_sector_no mbr (0,0,1);                                         */
  186.  
  187. /* ----------------------------------------------------------------------- */
  188.  
  189.  
  190.  
  191. struct physical_sector_no
  192.  
  193. {
  194.  
  195. // public data
  196.  
  197.  
  198.  
  199.     dword head;
  200.  
  201.     dword cylinder;
  202.  
  203.     dword sector;
  204.  
  205.  
  206.  
  207. // constructors
  208.  
  209.  
  210.  
  211.     physical_sector_no (dword logical_sector, const drive_geometry &geometry);
  212.  
  213.     physical_sector_no (dword head, dword cylinder, dword sector)
  214.  
  215.     {
  216.  
  217.         physical_sector_no::head = head;
  218.  
  219.         physical_sector_no::cylinder = cylinder;
  220.  
  221.         physical_sector_no::sector = sector;
  222.  
  223.     }
  224.  
  225. };
  226.  
  227.  
  228.  
  229.  
  230.  
  231. /* ----------------------------------------------------------------------- */
  232.  
  233. /* Structure sector - contains only sector data                            */
  234.  
  235. /* ----------------------------------------------------------------------- */
  236.  
  237.  
  238.  
  239. struct sector
  240.  
  241. {
  242.  
  243.     byte data[512];
  244.  
  245. };
  246.  
  247.  
  248.  
  249.  
  250.  
  251. /* ----------------------------------------------------------------------- */
  252.  
  253. /* Prototype for bios call get_disk_type - returns 0 if drive not present. */
  254.  
  255. /* Valid drive numbers: 0 - 255, result: 1 - floppy without disk change    */
  256.  
  257. /* detection, 2 - floppy with disk change detection, 3 - harddisk          */
  258.  
  259. /* ----------------------------------------------------------------------- */
  260.  
  261.  
  262.  
  263. int get_disk_type (int drive_number);
  264.  
  265.  
  266.  
  267. /* Bios call get_no_of_drives */
  268.  
  269.  
  270.  
  271. int get_no_of_drives (void);
  272.  
  273.  
  274.  
  275. #endif
  276.  
  277.