disk: Always try to mount the first partition on a disk.

We've received multiple reports from users of 6th gen iPods where we
fail to find any mountable partition.  A user was able to supply an MBR
dump, which showed that the "type" listed for parition 0 was set to 0x00
(ie "unused"), leading us to (correctly) completely ignore that entry.
However, it looks like the stock firmware ignores the type and
unconditionally uses the first entry even if it's nominally "invalid"

So, to deal with this, always try to mount partition 0 if it is not one
of the two "extended partition table" types.  If that speculative mount
succeeds, we now treat it as type 0x0c (Fat32 w/LBA) internally.

Note that this will not allow the partition to be mountable over USB, as
the MBR is still incorrect, leading the host OS to ignore the partition.
Further complicating things, the stock Apple firmware always constructs
a fake MBR to hand to the host!

To prevent user confusion with these devices, we may consider faking the
MBR too; alternatively we could correct the MBR and write it back to
disk, perhaps via a debug menu option.

Change-Id: I1e9392d20401eb94ecc6d70263fb0e45392a9bd4
This commit is contained in:
Solomon Peachy 2025-08-31 13:20:15 -04:00
parent 063b0357c3
commit 4ad041e17a

View file

@ -228,6 +228,15 @@ bool disk_init(IF_MD_NONVOID(int drive))
if (pinfo[i].type == PARTITION_TYPE_GPT_GUARD) {
is_gpt = 1;
}
#if 0 // Currently done in disk_mount() upon successful mount only
/* Auto-correct partition entries */
if (i == 0 && pinfo[i].type == 0 &&
pinfo[i].start != 0 && pinfo[i].size != 0) {
pinfo[i].type = PARTITION_TYPE_FAT32_LBA;
// XXX consider correcting MBR and writing sector back?
}
#endif
}
while (is_gpt) {
@ -433,7 +442,9 @@ int disk_mount(int drive)
volume != -1 && i < MAX_PARTITIONS_PER_DRIVE && mounted < NUM_VOLUMES_PER_DRIVE;
i++)
{
if (pinfo[i].type == 0 || pinfo[i].type == 5)
if (pinfo[i].type == 0x05 ||
pinfo[i].type == 0x0f ||
(i != 0 && pinfo[i].type == 0))
continue; /* skip free/extended partitions */
DEBUGF("Trying to mount partition %d.\n", i);
@ -450,6 +461,10 @@ int disk_mount(int drive)
disk_sector_multiplier[drive] = j;
volume_onmount_internal(IF_MV(volume));
volume = get_free_volume(); /* prepare next entry */
if (pinfo[i].type == 0) {
pinfo[i].type = PARTITION_TYPE_FAT32_LBA;
// XXX write the sector back.?
}
break;
}
}
@ -460,6 +475,11 @@ int disk_mount(int drive)
init_volume(&volumes[volume], drive, i);
volume_onmount_internal(IF_MV(volume));
volume = get_free_volume(); /* prepare next entry */
if (pinfo[i].type == 0) {
pinfo[i].type = PARTITION_TYPE_FAT32_LBA;
// XXX write the sector back.?
}
}
#endif /* MAX_VIRT_SECTOR_SIZE */
}