Revert "misc cleanup"
[rpi-open-firmware.git] / arm_chainloader / drivers / mbr_disk.cc
index ff24b1f..fced100 100644 (file)
@@ -37,6 +37,12 @@ struct MbrPartition {
        uint8_t         part_ehd;               /* end head */\r
        uint8_t         part_esect;             /* end sector */\r
        uint8_t         part_ecyl;              /* end cylinder */\r
+#if 0\r
+       uint16_t        part_start_lo;          /* absolute starting ... */\r
+       uint16_t        part_start_hi;          /* ... sector number */\r
+       uint16_t        part_size_lo;           /* partition size ... */\r
+       uint16_t        part_size_hi;           /* ... in sectors */\r
+#endif\r
        uint32_t part_start;\r
        uint32_t part_size;\r
 } __attribute__((packed));\r
@@ -49,6 +55,8 @@ struct Mbr {
        uint16_t         mbr_sig;\r
 } __attribute__((packed));\r
 \r
+static_assert(sizeof(Mbr) >= 512, "What the fuck");\r
+\r
 #define MBR_FAT16 0x04\r
 #define MBR_FAT32 0x0B\r
 #define MBR_FAT32_INT13 0x0C\r
@@ -56,6 +64,25 @@ struct Mbr {
 #define MBR_LINUX 0x83\r
 #define MBR_NTFS 0x07\r
 \r
+static const char* mbr_fs_to_string(int fs) {\r
+       switch (fs) {\r
+       case MBR_FAT32:\r
+               return "FAT32";\r
+       case MBR_FAT32_INT13:\r
+               return "FAT32-INT13";\r
+       case MBR_FAT16_INT13:\r
+               return "FAT16-INT13";\r
+       case MBR_FAT16:\r
+               return "FAT16";\r
+       case MBR_LINUX:\r
+               return "Linux (ext2/ext3)";\r
+       case MBR_NTFS:\r
+               return "NTFS";\r
+       default:\r
+               return "<Unknown>";\r
+       }\r
+}\r
+\r
 struct MbrImpl {\r
        Mbr* mbr;\r
        BlockDevice* mmc;\r
@@ -94,19 +121,28 @@ struct MbrImpl {
        void read_mbr() {\r
                logf("Reading master boot record ...\n");\r
 \r
-               if (!mmc->read_block(0, mbr))\r
+               if (!mmc->read_block(0, mbr)) {\r
                        panic("unable to read master boot record from the SD card");\r
+               }\r
 \r
-               if (!validate_signature())\r
+               if (!validate_signature()) {\r
                        panic("invalid master boot record signature (got 0x%x)", mbr->mbr_sig);\r
+               }\r
+\r
+               logf("MBR contents:\n");\r
+\r
+               for (int i = 0; i < 4; i++) {\r
+                       MbrPartition& p = mbr->mbr_part[i];\r
+                       printf("    %d: %s at:%d size:%d\n", i, mbr_fs_to_string(p.part_typ), p.part_start, p.part_size);\r
+               }\r
        }\r
 \r
        MbrImpl() {\r
                mbr = new Mbr;\r
                mmc = get_sdhost_device();\r
-               if (!mmc)\r
+               if (!mmc) {\r
                        panic("parent block device not initilalized!");\r
-\r
+               }\r
                read_mbr();\r
                logf("Disk ready!\n");\r
        }\r
This page took 0.028129 seconds and 4 git commands to generate.