2 * Acess2 IDE Harddisk Driver
11 Uint64 ATA_MBR_int_ReadExt(int Disk, Uint64 Addr, Uint64 *Base, Uint64 *Length);
17 * \fn void ATA_ParseMBR(int Disk)
19 void ATA_ParseMBR(int Disk)
29 ATA_ReadDMA( Disk, 0, 1, &mbr );
32 gATA_Disks[Disk].NumPartitions = 0;
34 for( i = 0; i < 4; i ++ )
36 if( mbr.Parts[i].SystemID == 0 ) continue;
37 if( mbr.Parts[i].Boot == 0x0 || mbr.Parts[i].Boot == 0x80 // LBA 28
38 || mbr.Parts[i].Boot == 0x1 || mbr.Parts[i].Boot == 0x81 // LBA 48
41 if( mbr.Parts[i].SystemID == 0xF || mbr.Parts[i].SystemID == 5 ) {
42 LOG("Extended Partition");
43 if(extendedLBA != 0) {
44 Warning("Disk %i has multiple extended partitions, ignoring rest", Disk);
47 extendedLBA = mbr.Parts[i].LBAStart;
50 LOG("Primary Partition");
52 gATA_Disks[Disk].NumPartitions ++;
55 // Invalid Partition, so don't count it
57 while(extendedLBA != 0)
59 extendedLBA = ATA_MBR_int_ReadExt(Disk, extendedLBA, &base, &len);
60 if( extendedLBA == -1 ) return ;
61 gATA_Disks[Disk].NumPartitions ++;
63 LOG("gATA_Disks[Disk].NumPartitions = %i", gATA_Disks[Disk].NumPartitions);
65 // Create patition array
66 gATA_Disks[Disk].Partitions = malloc( gATA_Disks[Disk].NumPartitions * sizeof(tATA_Partition) );
68 // --- Fill Partition Info ---
70 for( j = 0, i = 0; i < 4; i ++ )
72 Log("mbr.Parts[%i].SystemID = 0x%02x", i, mbr.Parts[i].SystemID);
73 if( mbr.Parts[i].SystemID == 0 ) continue;
74 if( mbr.Parts[i].Boot == 0x0 || mbr.Parts[i].Boot == 0x80 ) // LBA 28
76 base = mbr.Parts[i].LBAStart;
77 len = mbr.Parts[i].LBALength;
79 else if( mbr.Parts[i].Boot == 0x1 || mbr.Parts[i].Boot == 0x81 ) // LBA 58
81 base = (mbr.Parts[i].StartHi << 16) | mbr.Parts[i].LBAStart;
82 len = (mbr.Parts[i].LengthHi << 16) | mbr.Parts[i].LBALength;
87 if( mbr.Parts[i].SystemID == 0xF || mbr.Parts[i].SystemID == 5 ) {
88 if(extendedLBA != 0) {
89 Warning("Disk %i has multiple extended partitions, ignoring rest", Disk);
96 ATA_int_MakePartition(
97 &gATA_Disks[Disk].Partitions[j], Disk, j,
103 // Scan extended partitions
104 while(extendedLBA != 0)
106 extendedLBA = ATA_MBR_int_ReadExt(Disk, extendedLBA, &base, &len);
107 ATA_int_MakePartition(
108 &gATA_Disks[Disk].Partitions[j], Disk, k, base, len
116 * \brief Reads an extended partition
117 * \return LBA of next Extended, -1 on error, 0 for last
119 Uint64 ATA_MBR_int_ReadExt(int Disk, Uint64 Addr, Uint64 *Base, Uint64 *Length)
127 if( ATA_ReadDMA( Disk, Addr, 1, &mbr ) != 0 )
128 return -1; // Stop on Errors
131 for( i = 0; i < 4; i ++ )
133 if( mbr.Parts[i].SystemID == 0 ) continue;
136 if( mbr.Parts[i].Boot == 0x0 || mbr.Parts[i].Boot == 0x80 ) {
137 base = mbr.Parts[i].LBAStart;
138 len = mbr.Parts[i].LBALength;
141 else if( mbr.Parts[i].Boot == 0x1 || mbr.Parts[i].Boot == 0x81 ) {
142 base = (mbr.Parts[i].StartHi << 16) | mbr.Parts[i].LBAStart;
143 len = (mbr.Parts[i].LengthHi << 16) | mbr.Parts[i].LBALength;
146 Warning("Unknown partition type, Disk %i 0x%llx Part %i",
151 switch(mbr.Parts[i].SystemID)
156 Warning("Disk %i has two forward links in the extended partition",
164 Warning("Disk %i has more than one partition in the extended partition at 0x%llx",
176 Warning("No partition in extended partiton, Disk %i 0x%llx",