OvmfPkg/XenPvBlkDxe: Update disk size calculation

The specification wasn't clear and even contradict itself regarding
the calculation of the disk size. This have been clarified by Xen
commit 221f2748e8da ("blkif: reconcile protocol specification with
in-use implementations").

https://xenbits.xenproject.org/gitweb/?p=xen.git;a=commit;h=221f2748e8dabe8361b8cdfcffbeab9102c4c899

The value from the xenstore node "sectors" must be multiplied by 512
to have the size of the disk.

Calculation of LastBlock is now the same for both CD-ROM case and
generic case.

Signed-off-by: Anthony PERARD <anthony.perard@vates.tech>
This commit is contained in:
Anthony PERARD 2024-09-23 15:59:24 +02:00 committed by mergify[bot]
parent 3cf7a644eb
commit 8c1e786e50
2 changed files with 10 additions and 6 deletions

View File

@ -356,7 +356,7 @@ Again:
DEBUG ((
DEBUG_INFO,
"XenPvBlk: New disk with %ld sectors of %d bytes\n",
"XenPvBlk: New disk with %ld 512B-sectors and logical sector size of %d bytes\n",
Dev->MediaInfo.Sectors,
Dev->MediaInfo.SectorSize
));

View File

@ -295,15 +295,19 @@ XenPvBlkDxeDriverBindingStart (
// MdeModulePkg/Universal/Disk/PartitionDxe/ElTorito.c
//
Media->BlockSize = 2048;
Media->LastBlock = DivU64x32 (
Dev->MediaInfo.Sectors,
Media->BlockSize / Dev->MediaInfo.SectorSize
) - 1;
} else {
Media->BlockSize = Dev->MediaInfo.SectorSize;
Media->LastBlock = Dev->MediaInfo.Sectors - 1;
}
//
// Sectors is express as 512B unit, size of disk is "Sectors * 512",
// independently from SectorSize.
//
Media->LastBlock = DivU64x32 (
Dev->MediaInfo.Sectors,
Media->BlockSize / 512
) - 1;
ASSERT (Media->BlockSize % 512 == 0);
Dev->BlockIo.Media = Media;