Fixed a bug in the LBA extensions detection code.
[reactos.git] / freeldr / freeldr / disk.h
1 /*
2 * FreeLoader
3 * Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #ifndef __DISK_H
21 #define __DISK_H
22
23
24 typedef struct _GEOMETRY
25 {
26 ULONG Cylinders;
27 ULONG Heads;
28 ULONG Sectors;
29 ULONG BytesPerSector;
30
31 } GEOMETRY, *PGEOMETRY;
32
33 //
34 // Define the structure of a partition table entry
35 //
36 typedef struct _PARTITION_TABLE_ENTRY
37 {
38 BYTE BootIndicator; // 0x00 - non-bootable partition, 0x80 - bootable partition (one partition only)
39 BYTE StartHead; // Beginning head number
40 BYTE StartSector; // Beginning sector (2 high bits of cylinder #)
41 BYTE StartCylinder; // Beginning cylinder# (low order bits of cylinder #)
42 BYTE SystemIndicator; // System indicator
43 BYTE EndHead; // Ending head number
44 BYTE EndSector; // Ending sector (2 high bits of cylinder #)
45 BYTE EndCylinder; // Ending cylinder# (low order bits of cylinder #)
46 DWORD SectorCountBeforePartition; // Number of sectors preceding the partition
47 DWORD PartitionSectorCount; // Number of sectors in the partition
48
49 } PACKED PARTITION_TABLE_ENTRY, *PPARTITION_TABLE_ENTRY;
50
51 //
52 // Define the structure of the master boot record
53 //
54 typedef struct _MASTER_BOOT_RECORD
55 {
56 BYTE MasterBootRecordCodeAndData[0x1be];
57 PARTITION_TABLE_ENTRY PartitionTable[4];
58 WORD MasterBootRecordMagic;
59
60 } PACKED MASTER_BOOT_RECORD, *PMASTER_BOOT_RECORD;
61
62 //
63 // Partition type defines
64 //
65 #define PARTITION_ENTRY_UNUSED 0x00 // Entry unused
66 #define PARTITION_FAT_12 0x01 // 12-bit FAT entries
67 #define PARTITION_XENIX_1 0x02 // Xenix
68 #define PARTITION_XENIX_2 0x03 // Xenix
69 #define PARTITION_FAT_16 0x04 // 16-bit FAT entries
70 #define PARTITION_EXTENDED 0x05 // Extended partition entry
71 #define PARTITION_HUGE 0x06 // Huge partition MS-DOS V4
72 #define PARTITION_IFS 0x07 // IFS Partition
73 #define PARTITION_OS2BOOTMGR 0x0A // OS/2 Boot Manager/OPUS/Coherent swap
74 #define PARTITION_FAT32 0x0B // FAT32
75 #define PARTITION_FAT32_XINT13 0x0C // FAT32 using extended int13 services
76 #define PARTITION_XINT13 0x0E // Win95 partition using extended int13 services
77 #define PARTITION_XINT13_EXTENDED 0x0F // Same as type 5 but uses extended int13 services
78 #define PARTITION_PREP 0x41 // PowerPC Reference Platform (PReP) Boot Partition
79 #define PARTITION_LDM 0x42 // Logical Disk Manager partition
80 #define PARTITION_UNIX 0x63 // Unix
81
82 ///////////////////////////////////////////////////////////////////////////////////////
83 //
84 // BIOS Disk Functions
85 //
86 ///////////////////////////////////////////////////////////////////////////////////////
87 int biosdisk(int cmd, int drive, int head, int track, int sector, int nsects, void *buffer); // Implemented in asmcode.S
88
89 BOOL BiosInt13Read(ULONG Drive, ULONG Head, ULONG Track, ULONG Sector, ULONG SectorCount, PVOID Buffer); // Implemented in asmcode.S
90 BOOL BiosInt13ReadExtended(ULONG Drive, ULONG Sector, ULONG SectorCount, PVOID Buffer); // Implemented in asmcode.S
91 BOOL BiosInt13ExtensionsSupported(ULONG Drive);
92 ULONG BiosInt13GetLastErrorCode(VOID);
93
94 void stop_floppy(void); // Implemented in asmcode.S
95 int get_heads(int drive); // Implemented in asmcode.S
96 int get_cylinders(int drive); // Implemented in asmcode.S
97 int get_sectors(int drive); // Implemented in asmcode.S
98 BOOL BiosInt13GetDriveParameters(ULONG Drive, PGEOMETRY Geometry); // Implemented in disk.S
99
100 ///////////////////////////////////////////////////////////////////////////////////////
101 //
102 // FreeLoader Disk Functions
103 //
104 ///////////////////////////////////////////////////////////////////////////////////////
105 VOID DiskError(PUCHAR ErrorString);
106 BOOL DiskGetDriveGeometry(ULONG DriveNumber, PGEOMETRY DriveGeometry);
107 BOOL DiskReadLogicalSectors(ULONG DriveNumber, ULONG SectorNumber, ULONG SectorCount, PVOID Buffer);
108
109 ///////////////////////////////////////////////////////////////////////////////////////
110 //
111 // Fixed Disk Partition Management Functions
112 //
113 ///////////////////////////////////////////////////////////////////////////////////////
114 BOOL DiskIsDriveRemovable(ULONG DriveNumber);
115 BOOL DiskGetActivePartitionEntry(ULONG DriveNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry);
116 BOOL DiskGetPartitionEntry(ULONG DriveNumber, ULONG PartitionNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry);
117 BOOL DiskGetFirstPartitionEntry(PMASTER_BOOT_RECORD MasterBootRecord, PPARTITION_TABLE_ENTRY PartitionTableEntry);
118 BOOL DiskGetFirstExtendedPartitionEntry(PMASTER_BOOT_RECORD MasterBootRecord, PPARTITION_TABLE_ENTRY PartitionTableEntry);
119 BOOL DiskReadBootRecord(ULONG DriveNumber, ULONG LogicalSectorNumber, PMASTER_BOOT_RECORD BootRecord);
120
121 #endif // defined __DISK_H