MdeModulePkg/UsbMassStorageDxe: Report blank optical media as media absent

A blank (unwritten) optical disc reports a zero capacity through READ
CAPACITY (LastBlock == 0).  The driver currently exposes such a device
with BlockSize 2048 and LastBlock 0, so upper layers such as PartitionDxe
and the BDS removable-media boot probe keep reading LBA 0. The drive
rejects the read with "Illegal Request / LBA out of range" (sense 5/21/0)
and UsbMassReadBlocks enters its reset recovery loop. So each failed probe
can block for tens of seconds and boot appears to hang.

Treat an optical device with zero capacity as media absent so that the
media is skipped instead of being probed.

Signed-off-by: Haword <zhenghaowei@loongson.cn>
This commit is contained in:
haword 2026-08-24 15:43:21 +08:00
parent 7735ed4f8e
commit 4d02d548bc

View file

@ -722,6 +722,17 @@ UsbBootDetectMedia (
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "UsbBootDetectMedia: UsbBootReadCapacity (%r)\n", Status));
}
if (UsbMass->OpticalStorage && (Media->LastBlock == 0)) {
//
// A blank (unwritten) optical disc reports a zero capacity: there is no
// user data block that can be read. Report the media as absent so that
// upper layers (e.g. PartitionDxe and the BDS boot option probe) skip it
// instead of repeatedly reading LBA 0 and getting "LBA out of range".
//
Media->MediaPresent = FALSE;
Status = EFI_NO_MEDIA;
}
}
if (EFI_ERROR (Status) && (Status != EFI_NO_MEDIA)) {