1#include "part_driver.h"
10#include "module_debug.h"
14 master_boot_record* pMbrBlock = NULL;
20 M_DEBUG(
"%s\n", __func__);
24 if (bd->sectorOffset != 0)
28 pMbrBlock = AllocSysMemory(ALLOC_FIRST,
sizeof(master_boot_record), NULL);
29 if (pMbrBlock == NULL)
32 M_DEBUG(
"Failed to allocate memory for MBR block\n");
37 ret = bd->read(bd, 0, pMbrBlock, 1);
41 M_DEBUG(
"Failed to read MBR sector from block device %d\n", ret);
46 if (pMbrBlock->boot_signature != MBR_BOOT_SIGNATURE)
49 M_DEBUG(
"MBR boot signature is invalid, device is not MBR\n");
50 FreeSysMemory(pMbrBlock);
55 if (pMbrBlock->primary_partitions[0].partition_type == MBR_PART_TYPE_GPT_PROTECTIVE_MBR)
58 FreeSysMemory(pMbrBlock);
63 printf(
"Found MBR disk\n");
64 for (
int i = 0; i < 4; i++)
67 if (pMbrBlock->primary_partitions[i].sector_count == 0)
70 printf(
"Found partition type 0x%02x\n", pMbrBlock->primary_partitions[i].partition_type);
74 if ((partIndex = GetNextFreePartitionIndex()) == -1)
77 printf(
"Can't mount partition, no more free partition slots!\n");
82 g_part[partIndex].bd = bd;
83 g_part_bd[partIndex].name = bd->name;
84 g_part_bd[partIndex].devNr = bd->devNr;
85 g_part_bd[partIndex].parNr = i + 1;
86 g_part_bd[partIndex].parId = pMbrBlock->primary_partitions[i].partition_type;
87 g_part_bd[partIndex].sectorSize = bd->sectorSize;
88 g_part_bd[partIndex].sectorOffset = bd->sectorOffset + (u64)pMbrBlock->primary_partitions[i].first_lba;
89 g_part_bd[partIndex].sectorCount = pMbrBlock->primary_partitions[i].sector_count;
90 bdm_connect_bd(&g_part_bd[partIndex]);
95 rval = mountCount > 0 ? 0 : -1;
97 FreeSysMemory(pMbrBlock);