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;
35 if( MBR->Parts[i].Boot == 0x0 || MBR->Parts[i].Boot == 0x80 ) // LBA 28
37 base = MBR->Parts[i].LBAStart;
39 else if( MBR->Parts[i].Boot == 0x1 || MBR->Parts[i].Boot == 0x81 ) // LBA 48
41 base = (MBR->Parts[i].StartHi << 16) | MBR->Parts[i].LBAStart;
44 continue; // Invalid, don't count
46 if( MBR->Parts[i].SystemID == 0xF || MBR->Parts[i].SystemID == 5 ) {
47 LOG("Extended Partition at 0x%llx", base);
48 if(extendedLBA != 0) {
49 Warning("Disk %i has multiple extended partitions, ignoring rest", Disk);
55 LOG("Primary Partition at 0x%llx", base);
57 gATA_Disks[Disk].NumPartitions ++;
60 while(extendedLBA != 0)
62 extendedLBA = ATA_MBR_int_ReadExt(Disk, extendedLBA, &base, &len);
63 if( extendedLBA == -1 ) break;
64 gATA_Disks[Disk].NumPartitions ++;
66 LOG("gATA_Disks[Disk].NumPartitions = %i", gATA_Disks[Disk].NumPartitions);
68 // Create patition array
69 gATA_Disks[Disk].Partitions = malloc( gATA_Disks[Disk].NumPartitions * sizeof(tATA_Partition) );
71 // --- Fill Partition Info ---
73 for( j = 0, i = 0; i < 4; i ++ )
75 LOG("MBR->Parts[%i].SystemID = 0x%02x", i, MBR->Parts[i].SystemID);
76 if( MBR->Parts[i].SystemID == 0 ) continue;
77 if( MBR->Parts[i].Boot == 0x0 || MBR->Parts[i].Boot == 0x80 ) // LBA 28
79 base = MBR->Parts[i].LBAStart;
80 len = MBR->Parts[i].LBALength;
82 else if( MBR->Parts[i].Boot == 0x1 || MBR->Parts[i].Boot == 0x81 ) // LBA 48
84 base = (MBR->Parts[i].StartHi << 16) | MBR->Parts[i].LBAStart;
85 len = (MBR->Parts[i].LengthHi << 16) | MBR->Parts[i].LBALength;
90 if( MBR->Parts[i].SystemID == 0xF || MBR->Parts[i].SystemID == 5 ) {
91 if(extendedLBA != 0) {
92 Log_Warning("ATA", "Disk %i has multiple extended partitions, ignoring rest", Disk);
99 ATA_int_MakePartition(
100 &gATA_Disks[Disk].Partitions[j], Disk, j,
106 // Scan extended partitions
107 while(extendedLBA != 0)
109 extendedLBA = ATA_MBR_int_ReadExt(Disk, extendedLBA, &base, &len);
110 if(extendedLBA == -1) break;
111 ATA_int_MakePartition(
112 &gATA_Disks[Disk].Partitions[j], Disk, k, base, len
120 * \brief Reads an extended partition
121 * \return LBA of next Extended, -1 on error, 0 for last
123 Uint64 ATA_MBR_int_ReadExt(int Disk, Uint64 Addr, Uint64 *Base, Uint64 *Length)
131 if( ATA_ReadDMA( Disk, Addr, 1, &mbr ) != 0 )
132 return -1; // Stop on Errors
134 for( i = 0; i < 4; i ++ )
136 if( mbr.Parts[i].SystemID == 0 ) continue;
139 if( mbr.Parts[i].Boot == 0x0 || mbr.Parts[i].Boot == 0x80 ) {
140 base = mbr.Parts[i].LBAStart;
141 len = mbr.Parts[i].LBALength;
144 else if( mbr.Parts[i].Boot == 0x1 || mbr.Parts[i].Boot == 0x81 ) {
145 base = (mbr.Parts[i].StartHi << 16) | mbr.Parts[i].LBAStart;
146 len = (mbr.Parts[i].LengthHi << 16) | mbr.Parts[i].LBALength;
149 Log_Warning("ATA MBR",
150 "Unknown partition type 0x%x, Disk %i Ext 0x%llx Part %i",
151 mbr.Parts[i].Boot, Disk, Addr, i
155 base += Addr; // Addresses are relative
157 switch(mbr.Parts[i].SystemID)
162 Log_Warning("ATA MBR",
163 "Disk %i has two forward links in the extended partition",
173 "Disk %i has more than one partition in the extended partition at 0x%llx",
186 Log_Warning("ATA MBR",
187 "No partition in extended partiton, Disk %i 0x%llx",