2 * Acess2 IDE Harddisk Driver
14 * \fn void ATA_ParseMBR(int Disk)
16 void ATA_ParseMBR(int Disk)
25 ATA_ReadDMA( Disk, 0, 1, &mbr );
28 gATA_Disks[Disk].NumPartitions = 0;
30 for( i = 0; i < 4; i ++ )
32 if( mbr.Parts[i].SystemID == 0 ) continue;
34 mbr.Parts[i].Boot == 0x0 || mbr.Parts[i].Boot == 0x80 // LBA 28
35 || mbr.Parts[i].Boot == 0x1 || mbr.Parts[i].Boot == 0x81 // LBA 48
38 if( mbr.Parts[i].SystemID == 0xF || mbr.Parts[i].SystemID == 5 ) {
39 LOG("Extended Partition");
40 if(extendedLBA != 0) {
41 Warning("Disk %i has multiple extended partitions, ignoring rest", Disk);
44 extendedLBA = mbr.Parts[i].LBAStart;
47 LOG("Primary Partition");
49 gATA_Disks[Disk].NumPartitions ++;
52 // Invalid Partition, so don't count it
54 while(extendedLBA != 0)
56 if( ATA_ReadDMA( Disk, extendedLBA, 1, &mbr ) != 0 )
57 break; // Stop on Errors
61 if( mbr.Parts[0].SystemID == 0 ) continue;
62 if( mbr.Parts[0].Boot == 0x0 || mbr.Parts[0].Boot == 0x80 // LBA 28
63 || mbr.Parts[0].Boot == 0x1 || mbr.Parts[0].Boot == 0x81 // LBA 48
66 if(mbr.Parts[0].SystemID == 0xF || mbr.Parts[0].SystemID == 0x7)
67 extendedLBA = mbr.Parts[0].LBAStart;
69 gATA_Disks[Disk].NumPartitions ++;
72 if( mbr.Parts[1].SystemID == 0 ) continue;
73 if( mbr.Parts[1].Boot == 0x0 || mbr.Parts[1].Boot == 0x80 // LBA 28
74 || mbr.Parts[1].Boot == 0x1 || mbr.Parts[1].Boot == 0x81 // LBA 48
77 if(mbr.Parts[1].SystemID == 0xF || mbr.Parts[1].SystemID == 0x7) {
78 if(extendedLBA == 0) {
79 Warning("Disk %i has twp forward link in the extended partition",
83 extendedLBA = mbr.Parts[1].LBAStart;
86 if(extendedLBA != 0) {
87 Warning("Disk %i lacks a forward link in the extended partition",
91 gATA_Disks[Disk].NumPartitions ++;
95 LOG("gATA_Disks[Disk].NumPartitions = %i", gATA_Disks[Disk].NumPartitions);
97 // Create patition array
98 gATA_Disks[Disk].Partitions = malloc( gATA_Disks[Disk].NumPartitions * sizeof(tATA_Partition) );
100 // --- Fill Partition Info ---
102 for( i = 0; i < 4; i ++ )
104 Log("mbr.Parts[%i].SystemID = 0x%02x", i, mbr.Parts[i].SystemID);
105 if( mbr.Parts[i].SystemID == 0 ) continue;
106 if( mbr.Parts[i].Boot == 0x0 || mbr.Parts[i].Boot == 0x80 ) // LBA 28
108 if( mbr.Parts[1].SystemID == 0xF || mbr.Parts[1].SystemID == 5 ) {
109 if(extendedLBA != 0) {
110 Warning("Disk %i has multiple extended partitions, ignoring rest", Disk);
113 extendedLBA = mbr.Parts[1].LBAStart;
117 ATA_int_MakePartition( &gATA_Disks[Disk].Partitions[j], Disk, i,
118 mbr.Parts[i].LBAStart, mbr.Parts[i].LBALength
123 if( mbr.Parts[i].Boot == 0x1 || mbr.Parts[i].Boot == 0x81 ) // LBA 48
125 if( mbr.Parts[i].SystemID == 0xF || mbr.Parts[i].SystemID == 5 ) {
126 if(extendedLBA != 0) {
127 Warning("Disk %i has multiple extended partitions, ignoring rest", Disk);
130 extendedLBA = (mbr.Parts[i].StartHi << 16) | mbr.Parts[i].LBAStart;
133 ATA_int_MakePartition( &gATA_Disks[Disk].Partitions[j], Disk, i,
134 (mbr.Parts[i].StartHi << 16) | mbr.Parts[i].LBAStart,
135 (mbr.Parts[i].LengthHi << 16) | mbr.Parts[i].LBALength
139 // Invalid Partition, so don't count it
141 // Scan extended partition
142 while(extendedLBA != 0)
144 if( ATA_ReadDMA( Disk, extendedLBA, 1, &mbr ) != 0 )
145 break; // Stop on Errors
149 // Check first entry (should be partition)
150 if( mbr.Parts[0].SystemID != 0)
152 if( mbr.Parts[0].Boot == 0x0 || mbr.Parts[0].Boot == 0x80 ) // LBA 28
154 // Forward Link to next Extended partition entry
155 if(mbr.Parts[0].SystemID == 0xF || mbr.Parts[0].SystemID == 0x7)
156 extendedLBA = mbr.Parts[0].LBAStart;
158 ATA_int_MakePartition( &gATA_Disks[Disk].Partitions[j], Disk, k,
159 mbr.Parts[0].LBAStart, mbr.Parts[0].LBALength
164 else if( mbr.Parts[0].Boot == 0x1 || mbr.Parts[0].Boot == 0x81 ) // LBA 48
166 if(mbr.Parts[0].SystemID == 0xF || mbr.Parts[0].SystemID == 0x7)
167 extendedLBA = (mbr.Parts[0].StartHi << 16) | mbr.Parts[0].LBAStart;
169 ATA_int_MakePartition( &gATA_Disks[Disk].Partitions[j], Disk, k,
170 (mbr.Parts[0].StartHi << 16) | mbr.Parts[0].LBAStart,
171 (mbr.Parts[0].LengthHi << 16) | mbr.Parts[0].LBALength
178 // Check second entry (should be forward link)
179 if( mbr.Parts[1].SystemID != 0)
181 if(mbr.Parts[1].Boot == 0x0 || mbr.Parts[1].Boot == 0x80 ) // LBA 28
183 if(mbr.Parts[1].SystemID == 0xF || mbr.Parts[1].SystemID == 0x7) {
184 if(extendedLBA == 0) {
185 Warning("Disk %i has twp forward link in the extended partition",
189 extendedLBA = mbr.Parts[1].LBAStart;
193 if(extendedLBA != 0) {
194 Warning("Disk %i lacks a forward link in the extended partition",
198 ATA_int_MakePartition( &gATA_Disks[Disk].Partitions[j], Disk, k,
199 mbr.Parts[1].LBAStart, mbr.Parts[1].LBALength
205 else if( mbr.Parts[1].Boot == 0x1 || mbr.Parts[1].Boot == 0x81 ) // LBA 48
207 if(mbr.Parts[1].SystemID == 0xF || mbr.Parts[1].SystemID == 0x7) {
208 if(extendedLBA == 0) {
209 Warning("Disk %i has twp forward link in the extended partition",
213 extendedLBA = (mbr.Parts[1].StartHi << 16) | mbr.Parts[1].LBAStart;
217 if(extendedLBA != 0) {
218 Warning("Disk %i lacks a forward link in the extended partition",
222 ATA_int_MakePartition( &gATA_Disks[Disk].Partitions[j], Disk, k,
223 (mbr.Parts[1].StartHi << 16) | mbr.Parts[1].LBAStart,
224 (mbr.Parts[1].LengthHi << 16) | mbr.Parts[1].LBALength