2 * Acess2 IDE Harddisk Driver
11 void ATA_ParseMBR(int Disk, tMBR *MBR);
12 Uint64 ATA_MBR_int_ReadExt(int Disk, Uint64 Addr, Uint64 *Base, Uint64 *Length);
18 * \fn void ATA_ParseMBR(int Disk, tMBR *MBR)
20 void ATA_ParseMBR(int Disk, tMBR *MBR)
29 gATA_Disks[Disk].NumPartitions = 0;
31 for( i = 0; i < 4; i ++ )
33 if( MBR->Parts[i].SystemID == 0 ) continue;
34 if( 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 extendedLBA = ATA_MBR_int_ReadExt(Disk, extendedLBA, &base, &len);
57 if( extendedLBA == 0xFFFFFFFF ) return ;
58 gATA_Disks[Disk].NumPartitions ++;
60 LOG("gATA_Disks[Disk].NumPartitions = %i", gATA_Disks[Disk].NumPartitions);
62 // Create patition array
63 gATA_Disks[Disk].Partitions = malloc( gATA_Disks[Disk].NumPartitions * sizeof(tATA_Partition) );
65 // --- Fill Partition Info ---
67 for( j = 0, i = 0; i < 4; i ++ )
69 LOG("MBR->Parts[%i].SystemID = 0x%02x", i, MBR->Parts[i].SystemID);
70 if( MBR->Parts[i].SystemID == 0 ) continue;
71 if( MBR->Parts[i].Boot == 0x0 || MBR->Parts[i].Boot == 0x80 ) // LBA 28
73 base = MBR->Parts[i].LBAStart;
74 len = MBR->Parts[i].LBALength;
76 else if( MBR->Parts[i].Boot == 0x1 || MBR->Parts[i].Boot == 0x81 ) // LBA 58
78 base = (MBR->Parts[i].StartHi << 16) | MBR->Parts[i].LBAStart;
79 len = (MBR->Parts[i].LengthHi << 16) | MBR->Parts[i].LBALength;
84 if( MBR->Parts[i].SystemID == 0xF || MBR->Parts[i].SystemID == 5 ) {
85 if(extendedLBA != 0) {
86 Log_Warning("ATA", "Disk %i has multiple extended partitions, ignoring rest", Disk);
93 ATA_int_MakePartition(
94 &gATA_Disks[Disk].Partitions[j], Disk, j,
100 // Scan extended partitions
101 while(extendedLBA != 0)
103 extendedLBA = ATA_MBR_int_ReadExt(Disk, extendedLBA, &base, &len);
104 ATA_int_MakePartition(
105 &gATA_Disks[Disk].Partitions[j], Disk, k, base, len
113 * \brief Reads an extended partition
114 * \return LBA of next Extended, -1 on error, 0 for last
116 Uint64 ATA_MBR_int_ReadExt(int Disk, Uint64 Addr, Uint64 *Base, Uint64 *Length)
124 if( ATA_ReadDMA( Disk, Addr, 1, &mbr ) != 0 )
125 return -1; // Stop on Errors
128 for( i = 0; i < 4; i ++ )
130 if( mbr.Parts[i].SystemID == 0 ) continue;
133 if( mbr.Parts[i].Boot == 0x0 || mbr.Parts[i].Boot == 0x80 ) {
134 base = mbr.Parts[i].LBAStart;
135 len = mbr.Parts[i].LBALength;
138 else if( mbr.Parts[i].Boot == 0x1 || mbr.Parts[i].Boot == 0x81 ) {
139 base = (mbr.Parts[i].StartHi << 16) | mbr.Parts[i].LBAStart;
140 len = (mbr.Parts[i].LengthHi << 16) | mbr.Parts[i].LBALength;
143 Warning("Unknown partition type, Disk %i 0x%llx Part %i",
148 switch(mbr.Parts[i].SystemID)
153 Warning("Disk %i has two forward links in the extended partition",
161 Warning("Disk %i has more than one partition in the extended partition at 0x%llx",
173 Warning("No partition in extended partiton, Disk %i 0x%llx",