Misc - Cleaning up logging output
[tpg/acess2.git] / Modules / Storage / ATA / mbr.c
index 45ade88..a294ca8 100644 (file)
@@ -8,46 +8,43 @@
 #include "common.h"
 
 // === PROTOTYPES ===
+void   ATA_ParseMBR(int Disk, tMBR *MBR);
 Uint64 ATA_MBR_int_ReadExt(int Disk, Uint64 Addr, Uint64 *Base, Uint64 *Length);
 
 // === GLOBALS ===
 
 // === CODE ===
 /**
- * \fn void ATA_ParseMBR(int Disk)
+ * \fn void ATA_ParseMBR(int Disk, tMBR *MBR)
  */
-void ATA_ParseMBR(int Disk)
+void ATA_ParseMBR(int Disk, tMBR *MBR)
 {
         int    i, j = 0, k = 4;
-       tMBR    mbr;
        Uint64  extendedLBA;
        Uint64  base, len;
        
        ENTER("iDisk", Disk);
        
-       // Read Boot Sector
-       ATA_ReadDMA( Disk, 0, 1, &mbr );
-       
        // Count Partitions
        gATA_Disks[Disk].NumPartitions = 0;
        extendedLBA = 0;
        for( i = 0; i < 4; i ++ )
        {
-               if( mbr.Parts[i].SystemID == 0 )        continue;
-               if(     mbr.Parts[i].Boot == 0x0 || mbr.Parts[i].Boot == 0x80   // LBA 28
-               ||      mbr.Parts[i].Boot == 0x1 || mbr.Parts[i].Boot == 0x81   // LBA 48
+               if( MBR->Parts[i].SystemID == 0 )       continue;
+               if(     MBR->Parts[i].Boot == 0x0 || MBR->Parts[i].Boot == 0x80 // LBA 28
+               ||      MBR->Parts[i].Boot == 0x1 || MBR->Parts[i].Boot == 0x81 // LBA 48
                        )
                {
-                       if( mbr.Parts[i].SystemID == 0xF || mbr.Parts[i].SystemID == 5 ) {
-                               LOG("Extended Partition");
+                       if( MBR->Parts[i].SystemID == 0xF || MBR->Parts[i].SystemID == 5 ) {
+                               LOG("Extended Partition at 0x%llx", MBR->Parts[i].LBAStart);
                                if(extendedLBA != 0) {
                                        Warning("Disk %i has multiple extended partitions, ignoring rest", Disk);
                                        continue;
                                }
-                               extendedLBA = mbr.Parts[i].LBAStart;
+                               extendedLBA = MBR->Parts[i].LBAStart;
                                continue;
                        }
-                       LOG("Primary Partition");
+                       LOG("Primary Partition at 0x%llx", MBR->Parts[i].LBAStart);
                        
                        gATA_Disks[Disk].NumPartitions ++;
                        continue;
@@ -57,7 +54,7 @@ void ATA_ParseMBR(int Disk)
        while(extendedLBA != 0)
        {
                extendedLBA = ATA_MBR_int_ReadExt(Disk, extendedLBA, &base, &len);
-               if( extendedLBA == -1 ) return ;
+               if( extendedLBA == -1 ) break;
                gATA_Disks[Disk].NumPartitions ++;
        }
        LOG("gATA_Disks[Disk].NumPartitions = %i", gATA_Disks[Disk].NumPartitions);
@@ -69,24 +66,24 @@ void ATA_ParseMBR(int Disk)
        extendedLBA = 0;
        for( j = 0, i = 0; i < 4; i ++ )
        {
-               Log("mbr.Parts[%i].SystemID = 0x%02x", i, mbr.Parts[i].SystemID);
-               if( mbr.Parts[i].SystemID == 0 )        continue;
-               if( mbr.Parts[i].Boot == 0x0 || mbr.Parts[i].Boot == 0x80 )     // LBA 28
+               LOG("MBR->Parts[%i].SystemID = 0x%02x", i, MBR->Parts[i].SystemID);
+               if( MBR->Parts[i].SystemID == 0 )       continue;
+               if( MBR->Parts[i].Boot == 0x0 || MBR->Parts[i].Boot == 0x80 )   // LBA 28
                {
-                       base = mbr.Parts[i].LBAStart;
-                       len = mbr.Parts[i].LBALength;
+                       base = MBR->Parts[i].LBAStart;
+                       len = MBR->Parts[i].LBALength;
                }
-               else if( mbr.Parts[i].Boot == 0x1 || mbr.Parts[i].Boot == 0x81 )        // LBA 58
+               else if( MBR->Parts[i].Boot == 0x1 || MBR->Parts[i].Boot == 0x81 )      // LBA 58
                {
-                       base = (mbr.Parts[i].StartHi << 16) | mbr.Parts[i].LBAStart;
-                       len = (mbr.Parts[i].LengthHi << 16) | mbr.Parts[i].LBALength;
+                       base = (MBR->Parts[i].StartHi << 16) | MBR->Parts[i].LBAStart;
+                       len = (MBR->Parts[i].LengthHi << 16) | MBR->Parts[i].LBALength;
                }
                else
                        continue;
                
-               if( mbr.Parts[i].SystemID == 0xF || mbr.Parts[i].SystemID == 5 ) {
+               if( MBR->Parts[i].SystemID == 0xF || MBR->Parts[i].SystemID == 5 ) {
                        if(extendedLBA != 0) {
-                               Warning("Disk %i has multiple extended partitions, ignoring rest", Disk);
+                               Log_Warning("ATA", "Disk %i has multiple extended partitions, ignoring rest", Disk);
                                continue;
                        }
                        extendedLBA = base;
@@ -104,6 +101,7 @@ void ATA_ParseMBR(int Disk)
        while(extendedLBA != 0)
        {
                extendedLBA = ATA_MBR_int_ReadExt(Disk, extendedLBA, &base, &len);
+               if(extendedLBA == -1)   break;
                ATA_int_MakePartition(
                        &gATA_Disks[Disk].Partitions[j], Disk, k, base, len
                        );
@@ -127,7 +125,6 @@ Uint64 ATA_MBR_int_ReadExt(int Disk, Uint64 Addr, Uint64 *Base, Uint64 *Length)
        if( ATA_ReadDMA( Disk, Addr, 1, &mbr ) != 0 )
                return -1;      // Stop on Errors
        
-       
        for( i = 0; i < 4; i ++ )
        {
                if( mbr.Parts[i].SystemID == 0 )        continue;
@@ -143,8 +140,10 @@ Uint64 ATA_MBR_int_ReadExt(int Disk, Uint64 Addr, Uint64 *Base, Uint64 *Length)
                        len = (mbr.Parts[i].LengthHi << 16) | mbr.Parts[i].LBALength;
                }
                else {
-                       Warning("Unknown partition type, Disk %i 0x%llx Part %i",
-                               Disk, Addr, i);
+                       Log_Warning("ATA MBR",
+                               "Unknown partition type 0x%x, Disk %i Ext 0x%llx Part %i",
+                               mbr.Parts[i].Boot, Disk, Addr, i
+                               );
                        return -1;
                }
                
@@ -153,16 +152,20 @@ Uint64 ATA_MBR_int_ReadExt(int Disk, Uint64 Addr, Uint64 *Base, Uint64 *Length)
                case 0xF:
                case 0x5:
                        if(link != 0) {
-                               Warning("Disk %i has two forward links in the extended partition",
-                                       Disk);
+                               Log_Warning("ATA MBR",
+                                       "Disk %i has two forward links in the extended partition",
+                                       Disk
+                                       );
                                return -1;
                        }
                        link = base;
                        break;
                default:
                        if(bFoundPart) {
-                               Warning("Disk %i has more than one partition in the extended partition at 0x%llx",
-                                       Disk, Addr);
+                               Warning("ATA MBR",
+                                       "Disk %i has more than one partition in the extended partition at 0x%llx",
+                                       Disk, Addr
+                                       );
                                return -1;
                        }
                        bFoundPart = 1;
@@ -173,7 +176,8 @@ Uint64 ATA_MBR_int_ReadExt(int Disk, Uint64 Addr, Uint64 *Base, Uint64 *Length)
        }
        
        if(!bFoundPart) {
-               Warning("No partition in extended partiton, Disk %i 0x%llx",
+               Log_Warning("ATA MBR",
+                       "No partition in extended partiton, Disk %i 0x%llx",
                        Disk, Addr);
                return -1;
        }

UCC git Repository :: git.ucc.asn.au