drivers/usbhost: Register the partitions on a mass storage device. - #19750
Merged
Conversation
A drive that has been anywhere near another operating system almost always carries a partition table rather than a filesystem starting at sector zero, so the single block device this driver registers is usually the one thing nobody can mount. A USB stick written with an installer image is a good example: sector zero holds a protective MBR, and what somebody wants is the EFI system partition several gigabytes in. Read the table and give each partition a block device of its own beside the whole drive, named the way every other system names them. The parsing is already in the tree and understands both MBR and GPT; this only calls it and registers what it finds. The whole-drive node stays exactly where it was, for anyone who wants the raw thing or whose drive really does hold a bare filesystem. Assisted-by: Claude:claude-opus-5 Signed-off-by: Justin Hammond <justin@dynam.ac>
Fishwaldo
requested review from
johannes-nivus and
xiaoxiang781216
as code owners
August 8, 2026 09:45
xiaoxiang781216
approved these changes
Aug 8, 2026
acassis
approved these changes
Aug 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A drive that has been anywhere near another operating system almost always carries a partition table rather than a filesystem starting at sector zero. The mass storage class driver registers only one block device for the whole drive, so on such a drive that node is the one thing nobody can mount: sector zero holds the partition table, not a filesystem.
This reads the table and registers a block device for each partition beside the whole drive,
/dev/sda1next to/dev/sda, named the way other systems name them. The parsing already exists in the tree and understands both MBR and GPT; this only calls it and registers what it finds.The whole-drive node stays exactly where it was, for anyone who wants the raw device or whose drive really does hold a bare filesystem.
Impact
/dev/sdaNnodes appear alongside the existing/dev/sda; nothing is removed or renamed.y, but gated onUSBHOST_MSC && !DISABLE_MOUNTPOINTand onMBR_PARTITION || GPT_PARTITION. It therefore only activates where partition parsing is already built in, which is a deliberate choice: a configuration that has gone to the trouble of enabling partition support and then attaches a partitioned drive almost certainly wants to reach the partitions. Set it tonto keep the previous behaviour.Testing
Host: macOS 15.5 (Apple Silicon). qemu: 10.1.5 with KVM on Fedora 43 x86_64.
A 32 MB image with an MBR and a single FAT32 partition at LBA 2048, holding one known file:
Booted on
qemu-intel64:jumbowithCONFIG_MBR_PARTITION=y, attached overqemu-xhciasusb-storage. The two runs are the same tree and the same image, differing only inCONFIG_USBHOST_MSC_PARTITIONS.Without the option:
With the option:
sda1appears, mounts, and the file inside the partition reads back correctly.sdais still present in both.A note on how this was tested
These runs were made with #19745 applied underneath, because
qemu-intel64:jumbois the only in-tree configuration with a USB host controller and on current master that controller does not initialise, so no USB device enumerates at all and there is nothing to partition.The problem this fixes is independent of that PR. It is in
usbhost_storage.c, the shared mass storage class driver, which knows nothing about any host controller: a partitioned drive on an EHCI or OHCI board is equally unmountable today. #19745 was needed only to obtain a working controller to test against, and anyone with USB host hardware that already works can reproduce this on its own.