From 4ad041e17add81e62678d5e7d817ba2503db23c1 Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Sun, 31 Aug 2025 13:20:15 -0400 Subject: [PATCH] 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 --- firmware/common/disk.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/firmware/common/disk.c b/firmware/common/disk.c index 517d82febc..d42f74ce38 100644 --- a/firmware/common/disk.c +++ b/firmware/common/disk.c @@ -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 */ }