2 * Acess2 IDE Harddisk Driver
14 * \fn void ATA_ParseMBR(int Disk)
16 void ATA_ParseMBR(int Disk)
26 ATA_ReadDMA( Disk, 0, 1, &mbr );
29 gATA_Disks[Disk].NumPartitions = 0;
31 for( i = 0; i < 4; i ++ )
33 if( mbr.Parts[i].SystemID == 0 ) continue;
35 mbr.Parts[i].Boot == 0x0 || mbr.Parts[i].Boot == 0x80 // LBA 28
36 || mbr.Parts[i].Boot == 0x1 || mbr.Parts[i].Boot == 0x81 // LBA 48
39 if( mbr.Parts[i].SystemID == 0xF || mbr.Parts[i].SystemID == 5 ) {
40 LOG("Extended Partition");
41 if(extendedLBA != 0) {
42 Warning("Disk %i has multiple extended partitions, ignoring rest", Disk);
45 extendedLBA = mbr.Parts[i].LBAStart;
48 LOG("Primary Partition");
50 gATA_Disks[Disk].NumPartitions ++;
53 // Invalid Partition, so don't count it
55 while(extendedLBA != 0)
57 extendedLBA = ATA_MBR_int_ReadExt(Disk, extendedLBA, &base, &len);
58 if( extendedLBA == -1 ) return ;
59 gATA_Disks[Disk].NumPartitions ++;
61 LOG("gATA_Disks[Disk].NumPartitions = %i", gATA_Disks[Disk].NumPartitions);
63 // Create patition array
64 gATA_Disks[Disk].Partitions = malloc( gATA_Disks[Disk].NumPartitions * sizeof(tATA_Partition) );
66 // --- Fill Partition Info ---
68 for( j = 0, i = 0; i < 4; i ++ )
70 Log("mbr.Parts[%i].SystemID = 0x%02x", i, mbr.Parts[i].SystemID);
71 if( mbr.Parts[i].SystemID == 0 ) continue;
72 if( mbr.Parts[i].Boot == 0x0 || mbr.Parts[i].Boot == 0x80 ) // LBA 28
74 base = mbr.Parts[i].LBAStart;
75 len = mbr.Parts[i].LBALength;
77 else if( mbr.Parts[i].Boot == 0x1 || mbr.Parts[i].Boot == 0x81 ) // LBA 58
79 base = (mbr.Parts[i].StartHi << 16) | mbr.Parts[i].LBAStart;
80 len = (mbr.Parts[i].LengthHi << 16) | mbr.Parts[i].LBALength;
85 if( mbr.Parts[i].SystemID == 0xF || mbr.Parts[i].SystemID == 5 ) {
86 if(extendedLBA != 0) {
87 Warning("Disk %i has multiple extended partitions, ignoring rest", Disk);
94 ATA_int_MakePartition(
95 &gATA_Disks[Disk].Partitions[j], Disk, j,
101 // Scan extended partitions
102 while(extendedLBA != 0)
104 extendedLBA = ATA_MBR_int_ReadExt(Disk, extendedLBA, &base, &len);
105 ATA_int_MakePartition(
106 &gATA_Disks[Disk].Partitions[j], Disk, k, base, len
114 * \brief Reads an extended partition
115 * \return LBA of next Extended, -1 on error, 0 for last
117 Uint64 ATA_MBR_int_ReadExt(int Disk, Uint64 Addr, Uint64 *Base, Uint64 *Length)
125 if( ATA_ReadDMA( Disk, Addr, 1, &mbr ) != 0 )
126 return -1; // Stop on Errors
129 for( i = 0; i < 4; i ++ )
131 if( mbr.Parts[i].SystemID == 0 ) continue;
134 if( mbr.Parts[i].Boot == 0x0 || mbr.Parts[i].Boot == 0x80 ) {
135 base = mbr.Parts[i].LBAStart;
136 len = mbr.Parts[i].LBALength;
139 else if( mbr.Parts[i].Boot == 0x1 || mbr.Parts[i].Boot == 0x81 ) {
140 base = (mbr.Parts[i].StartHi << 16) | mbr.Parts[i].LBAStart;
141 len = (mbr.Parts[i].LengthHi << 16) | mbr.Parts[i].LBALength;
144 Warning("Unknown partition type, Disk %i 0x%llx Part %i",
149 switch(mbr.Parts[i].SystemID)
154 Warning("Disk %i has two forward links in the extended partition",
162 Warning("Disk %i has more than one partition in the extended partition at 0x%llx",
174 Warning("No partition in extended partiton, Disk %i 0x%llx",