How to get the partition type of a FAT32 formatted USB drive

I have LWext4 working on the GIGA. The only issue is that you never know which instance of USBHostMSD (there are two one for FAT32 type and another for ext4 type) is going to claim which drive at any one time. With the ext4 driver I can scan the MBR and get each partition type and then set a private variable in my EXT4Filesystem.
How can you scan the MBR of a FAT32 formatted USB drive or access it from the FATFilesystem or even from FatFS?
I can work around it but it's going to be more invasive than I like...

EDIT: Solved - Found this post:
https://forum.arduino.cc/t/giga-r1-usb-mass-storage-does-not-seem-to-support-partitioned-drives/1179397

2 Likes

@wwatson
Sorry didn't get back sooner on this - been a bit distracted last couple of days.

Never did get any answer from the arduino team or anyone else for that matter.

As you said, can read the MBR but thats about it. Not sure if its me or its OS - probably the os.

1 Like

When I first read this thread, I was going to mention that @Merlin513 was experimenting with something similar, but then by the time I found it, I saw your EDIT...

Yes Probably the OS!

I finally wound up using the ext4_mbr_scan() function of LWext4. I just had to comment out:

// Commented out for use with Mbed-os for GIGA R1
//		if (pe->type != 0x83)
//			continue; /*Unsupported entry. 0x83 - linux native*/

That allowed me to detect which USBHostMSD instance claimed which USB stick by checking the partition type. USBHost seems to start trying to claim devices on a hub starting at port #0 so the position of the USB sticks was affecting my results. Right now you won't be able to use mixed FAT32/EXT4 partitions on a single USB stick but that is possible later on. I tried accessing f_getlabel() in FatFS but it is not seen so I am assuming that it has not been enabled in the json. I really don't want have to modify the core os.

I am getting closer to finishing the EXT4Filesystem. When it is in a reasonable state I'll start a new GitHub and post.

Thanks for the info @Merlin513 and @KurtE :grin:

1 Like