Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions iop/fs/bdm/src/part_driver_mbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,37 @@

#include "module_debug.h"

int partitions_sanity_check_mbr(struct block_device *bd, master_boot_record* pMbrBlock) {
//All 4 MBR partitions should be considered valid ones to be mounted, even if some are unused.
//At least one of them must be active.
int valid = 0;
int active = 0;

for (int i = 0; i < 4; i++)
{

if (pMbrBlock->primary_partitions[i].partition_type != 0) {

if((pMbrBlock->primary_partitions[i].first_lba == 0) || (pMbrBlock->primary_partitions[i].first_lba >= bd->sectorCount))
return 0; //invalid

active++;
}

valid++; //Considered at least a valid partition.
}

return (valid == 4) && (active > 0);
}

int part_connect_mbr(struct block_device *bd)
{
master_boot_record* pMbrBlock = NULL;
int rval = -1;
int ret;
int mountCount = 0;
int partIndex;
int valid_partitions;

M_DEBUG("%s\n", __func__);

Expand Down Expand Up @@ -59,14 +83,29 @@ int part_connect_mbr(struct block_device *bd)
return rval;
}

// Loop and parse the primary partition entries in the MBR block.

valid_partitions = partitions_sanity_check_mbr(bd, pMbrBlock);

//Most likely a VBR
if(valid_partitions == 0) {
printf("MBR disk valid_partitions=%d \n", valid_partitions);
FreeSysMemory(pMbrBlock);
return -1;
}

printf("Found MBR disk\n");

// Loop and parse the primary partition entries in the MBR block.
for (int i = 0; i < 4; i++)
{
// Check if the partition is active, checking the status bit is not reliable so check if the sector_count is greater than zero instead.
if (pMbrBlock->primary_partitions[i].sector_count == 0)
continue;

//Ignore partitions that are not active. 0 is empty partition_type.
if (pMbrBlock->primary_partitions[i].partition_type == 0)
continue;

printf("Found partition type 0x%02x\n", pMbrBlock->primary_partitions[i].partition_type);

// TODO: Filter out unsupported partition types.
Expand Down Expand Up @@ -96,4 +135,4 @@ int part_connect_mbr(struct block_device *bd)

FreeSysMemory(pMbrBlock);
return rval;
}
}