/* FIPS - the First nondestructive Interactive Partition Splitting program Module hdstruct.h RCS - Header: $Header: /afs/athena.mit.edu/user/g/h/ghudson/projects/fips/RCS/hdstruct.h,v 1.1 1995/05/06 03:42:33 ghudson Exp ghudson $ Copyright (C) 1993 Arno Schaefer This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Report problems and direct all questions to: schaefer@rbg.informatik.th-darmstadt.de */ #ifndef HDSTRUCT_H #define HDSTRUCT_H #include "types.h" #include "disk_io.h" #include "logdr_st.h" /* ----------------------------------------------------------------------- */ /* Class rootsector - derived from structure sector */ /* Must be initialized with a pointer to a physical_drive object */ /* Read() and Write() read/write sector 0 of physical drive */ /* ----------------------------------------------------------------------- */ class Rootsector:public Sector { Physical_drive *drive; public: int read (void) { return Sector::read (drive,0); } int write (void) { return Sector::write (drive,0); } Rootsector (Physical_drive *drive) { Rootsector::drive = drive; } Rootsector (Rootsector &rs); void operator= (Rootsector &rs); }; /* ----------------------------------------------------------------------- */ /* Partition Info Structure */ /* Each entry in the partition table contains this information */ /* ----------------------------------------------------------------------- */ struct Partition_info { byte bootable; // 80h or 0 byte start_head; // location of first sector (bootsector) word start_cylinder; byte start_sector; byte system; // 1 = 12-bit FAT // 4 = 16-bit FAT & 16-bit sector number // 6 = 16-bit FAT & 32-bit sector number (BIGDOS) byte end_head; // location of last sector word end_cylinder; byte end_sector; dword start_sector_abs; // = start_cylinder * heads * sectors // + start_head * sectors + start_sector - 1 dword no_of_sectors_abs; // = end_cylinder * heads * sectors + end_head * sectors // + end_sector - start_sector_abs }; /* ----------------------------------------------------------------------- */ /* Partition Table Structure */ /* The partition table consists of 4 entries for the 4 possible partitions */ /* Get() reads the partition table from the rootsector, put() writes the */ /* data back into the rootsector buffer */ /* ----------------------------------------------------------------------- */ struct Partition_table { Partition_info partition_info[4]; void get (Rootsector *rootsector); void put (Rootsector *rootsector); }; /* ----------------------------------------------------------------------- */ /* Harddrive Class, derived from physical_drive */ /* Represents one physical harddrive. Must be initialized with the drive */ /* number (0x80 for 1st HDD). Contains the rootsector and partition table. */ /* ----------------------------------------------------------------------- */ class Harddrive:public Physical_drive { Partition_table pr_partition_table; public: Rootsector *rootsector; virtual Partition_table &partition_table() { return pr_partition_table; } Harddrive (int number):Physical_drive (number) { rootsector = new Rootsector (this); } Harddrive (Harddrive &hd):Physical_drive (hd) { rootsector = new Rootsector (*(hd.rootsector)); partition_table () = hd.partition_table(); } void operator= (Harddrive &hd); ~Harddrive (void) { delete rootsector; } }; /* ----------------------------------------------------------------------- */ /* Raw Partition Class */ /* Represents one partition from the partition table (may be non-DOS) */ /* Initialization with the pointer to the harddrive object and the */ /* partition number (0-3) */ /* ----------------------------------------------------------------------- */ class Raw_partition { public: int number; Physical_drive *drive; Partition_info *partition_info; Raw_partition (Harddrive *drive,int number) { Raw_partition::number = number; Raw_partition::drive = drive; partition_info = &(drive->partition_table().partition_info[number]); } }; /* ----------------------------------------------------------------------- */ /* Partition Class, derived from logical_drive and raw_partition */ /* Represents one primary DOS partition. Read_sector() and write_sector() */ /* are instances of the virtual functions in the logical_drive class */ /* ----------------------------------------------------------------------- */ class Partition:public Logical_drive,public Raw_partition { public: int read_sector (dword number,Sector *sector) { return (sector->read (drive,partition_info->start_sector_abs + number)); } int write_sector (dword number,Sector *sector) { return (sector->write (drive,partition_info->start_sector_abs + number)); } Partition (Harddrive *drive,int number):Raw_partition(drive,number) { bootsector = new Bootsector (this); } ~Partition (void) { delete bootsector; } }; #endif