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;
38 mbr.Parts[i].Boot == 0x0 || mbr.Parts[i].Boot == 0x80 // LBA 28
39 || mbr.Parts[i].Boot == 0x1 || mbr.Parts[i].Boot == 0x81 // LBA 48
42 if( mbr.Parts[i].SystemID == 0xF || mbr.Parts[i].SystemID == 5 ) {
43 LOG("Extended Partition");
44 if(extendedLBA != 0) {
45 Warning("Disk %i has multiple extended partitions, ignoring rest", Disk);
48 extendedLBA = mbr.Parts[i].LBAStart;
51 LOG("Primary Partition");
53 gATA_Disks[Disk].NumPartitions ++;
56 // Invalid Partition, so don't count it
58 while(extendedLBA != 0)
60 extendedLBA = ATA_MBR_int_ReadExt(Disk, extendedLBA, &base, &len);
61 if( extendedLBA == -1 ) return ;
62 gATA_Disks[Disk].NumPartitions ++;
64 LOG("gATA_Disks[Disk].NumPartitions = %i", gATA_Disks[Disk].NumPartitions);
66 // Create patition array
67 gATA_Disks[Disk].Partitions = malloc( gATA_Disks[Disk].NumPartitions * sizeof(tATA_Partition) );
69 // --- Fill Partition Info ---
71 for( j = 0, i = 0; i < 4; i ++ )
73 Log("mbr.Parts[%i].SystemID = 0x%02x", i, mbr.Parts[i].SystemID);
74 if( mbr.Parts[i].SystemID == 0 ) continue;
75 if( mbr.Parts[i].Boot == 0x0 || mbr.Parts[i].Boot == 0x80 ) // LBA 28
77 base = mbr.Parts[i].LBAStart;
78 len = mbr.Parts[i].LBALength;
80 else if( mbr.Parts[i].Boot == 0x1 || mbr.Parts[i].Boot == 0x81 ) // LBA 58
82 base = (mbr.Parts[i].StartHi << 16) | mbr.Parts[i].LBAStart;
83 len = (mbr.Parts[i].LengthHi << 16) | mbr.Parts[i].LBALength;
88 if( mbr.Parts[i].SystemID == 0xF || mbr.Parts[i].SystemID == 5 ) {
89 if(extendedLBA != 0) {
90 Warning("Disk %i has multiple extended partitions, ignoring rest", Disk);
97 ATA_int_MakePartition(
98 &gATA_Disks[Disk].Partitions[j], Disk, j,
104 // Scan extended partitions
105 while(extendedLBA != 0)
107 extendedLBA = ATA_MBR_int_ReadExt(Disk, extendedLBA, &base, &len);
108 ATA_int_MakePartition(
109 &gATA_Disks[Disk].Partitions[j], Disk, k, base, len
117 * \brief Reads an extended partition
118 * \return LBA of next Extended, -1 on error, 0 for last
120 Uint64 ATA_MBR_int_ReadExt(int Disk, Uint64 Addr, Uint64 *Base, Uint64 *Length)
128 if( ATA_ReadDMA( Disk, Addr, 1, &mbr ) != 0 )
129 return -1; // Stop on Errors
132 for( i = 0; i < 4; i ++ )
134 if( mbr.Parts[i].SystemID == 0 ) continue;
137 if( mbr.Parts[i].Boot == 0x0 || mbr.Parts[i].Boot == 0x80 ) {
138 base = mbr.Parts[i].LBAStart;
139 len = mbr.Parts[i].LBALength;
142 else if( mbr.Parts[i].Boot == 0x1 || mbr.Parts[i].Boot == 0x81 ) {
143 base = (mbr.Parts[i].StartHi << 16) | mbr.Parts[i].LBAStart;
144 len = (mbr.Parts[i].LengthHi << 16) | mbr.Parts[i].LBALength;
147 Warning("Unknown partition type, Disk %i 0x%llx Part %i",
152 switch(mbr.Parts[i].SystemID)
157 Warning("Disk %i has two forward links in the extended partition",
165 Warning("Disk %i has more than one partition in the extended partition at 0x%llx",
177 Warning("No partition in extended partiton, Disk %i 0x%llx",