- Ignore USB storage devices without an MBR or WBFS signature (fixes #338, reverts #343) thanks to wiidev/blackb0x for error handling and wbfs check

This commit is contained in:
kcpants 2023-04-29 14:57:23 -04:00
parent 1239b90751
commit e0bb6e936b
2 changed files with 20 additions and 40 deletions

View File

@ -151,7 +151,10 @@ bool PartitionHandle::Mount(int pos, const char *name, bool forceFAT)
}
}
if(!valid(pos))
{
gprintf("No valid partition position found! Failed to mount any partition.\n");
return false;
}
SetWbfsHandle(pos, NULL);
if(strncmp(GetFSName(pos), "FAT", 3) == 0 || strcmp(GetFSName(pos), "GUID-Entry") == 0)
@ -195,6 +198,7 @@ bool PartitionHandle::Mount(int pos, const char *name, bool forceFAT)
}
}
/* FAIL */
gprintf("Exhausted all supported filesystem types! Failed to mount any partition.\n");
MountNameList[pos].clear();
return false;
}

View File

@ -96,32 +96,9 @@ distribution.
#define DEVLIST_MAXSIZE 8
static inline const char *PartFromType(u8 type)
{
switch (type)
{
case 0x00: return "Unused";
case 0x01: return "FAT12";
case 0x04: return "FAT16";
case 0x05: return "Extended";
case 0x06: return "FAT16";
case 0x07: return "NTFS";
case 0x0b: return "FAT32";
case 0x0c: return "FAT32";
case 0x0e: return "FAT16";
case 0x0f: return "Extended";
case 0x82: return "LxSWP";
case 0x83: return "LINUX";
case 0x8e: return "LxLVM";
case 0xa8: return "OSX";
case 0xab: return "OSXBT";
case 0xaf: return "OSXHF";
case 0xbf: return "WBFS";
case 0xe8: return "LUKS";
default: return "Unknown";
}
}
#define MBR_SIGNATURE 0x55AA
#define MBR_SIGNATURE_MOD 0x55AB // UStealth modifies the mbr signature to 0x55AB so the WiiU will not attempt to format it; treat 0x55AB as a valid signature
#define WBFS_HEADER_MAGIC 0x57424653 // 0x57424653 is the characters "WBFS" in hex
static heap_cntrl __heap;
static bool __inited = false;
@ -848,6 +825,8 @@ static bool __usbstorage_ogc_IsInserted(void)
u8 device_count;
u8 i, j;
u16 vid, pid;
u16 mbrSignature;
u32 wbfsHeaderMagic;
s32 maxLun;
s32 retval;
u32 sectorsize, numSectors;
@ -928,22 +907,19 @@ static bool __usbstorage_ogc_IsInserted(void)
}
u8* mbr = (u8*)__lwp_heap_allocate(&__heap, 512);
USBStorage_OGC_Read(&__usbfd, j, 0, 1, mbr);
bool readablePartition = false;
for (u8 i = 0; i < 4; i++)
if (mbr)
{
u8 rawPartitionType = mbr[450 + i * 16];
const char* partitionType = PartFromType(rawPartitionType);
if (strcmp(partitionType, "Unknown") != 0) {
readablePartition = true;
}
}
__lwp_heap_free(&__heap, mbr);
USBStorage_OGC_Read(&__usbfd, j, 0, 1, mbr);
mbrSignature = ((u16*)mbr)[255];
wbfsHeaderMagic = *((u32*)mbr);
__lwp_heap_free(&__heap, mbr);
if (!readablePartition) {
gprintf("USB storage device with vid %lu pid %lu has no readable partitions. Skipping...\n", vid, pid);
__usbstorage_ogc_reset(&__usbfd);
continue;
if (mbrSignature != MBR_SIGNATURE && mbrSignature != MBR_SIGNATURE_MOD && wbfsHeaderMagic != WBFS_HEADER_MAGIC)
{
gprintf("USB storage device (vid %lu pid %lu) cannot be identified as MBR, GPT, or WBFS. Skipping...\n", vid, pid);
__usbstorage_ogc_reset(&__usbfd);
continue;
}
}
__mounted = true;