[NTOS:FSTUB] Simplify xHalIoReadPartitionTable function

Use single IOCTL (IOCTL_DISK_GET_DRIVE_GEOMETRY_EX) for retrieving
disk basic geometry information along with disk size.
Previous implementation used to issue two requests for that.
This commit is contained in:
Victor Perevertkin 2020-07-15 03:20:13 +03:00
parent 64abd9fca8
commit 5201472be7
No known key found for this signature in database
GPG key ID: C750B7222E9C7830

View file

@ -1387,14 +1387,12 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
NTSTATUS NTSTATUS
NTAPI NTAPI
HalpGetFullGeometry(IN PDEVICE_OBJECT DeviceObject, HalpGetFullGeometry(IN PDEVICE_OBJECT DeviceObject,
IN PDISK_GEOMETRY Geometry, OUT PDISK_GEOMETRY_EX Geometry)
OUT PULONGLONG RealSectorCount)
{ {
PIRP Irp; PIRP Irp;
IO_STATUS_BLOCK IoStatusBlock; IO_STATUS_BLOCK IoStatusBlock;
PKEVENT Event; PKEVENT Event;
NTSTATUS Status; NTSTATUS Status;
PARTITION_INFORMATION PartitionInfo;
PAGED_CODE(); PAGED_CODE();
/* Allocate a non-paged event */ /* Allocate a non-paged event */
@ -1407,12 +1405,12 @@ HalpGetFullGeometry(IN PDEVICE_OBJECT DeviceObject,
KeInitializeEvent(Event, NotificationEvent, FALSE); KeInitializeEvent(Event, NotificationEvent, FALSE);
/* Build the IRP */ /* Build the IRP */
Irp = IoBuildDeviceIoControlRequest(IOCTL_DISK_GET_DRIVE_GEOMETRY, Irp = IoBuildDeviceIoControlRequest(IOCTL_DISK_GET_DRIVE_GEOMETRY_EX,
DeviceObject, DeviceObject,
NULL, NULL,
0UL, 0UL,
Geometry, Geometry,
sizeof(DISK_GEOMETRY), sizeof(DISK_GEOMETRY_EX),
FALSE, FALSE,
Event, Event,
&IoStatusBlock); &IoStatusBlock);
@ -1432,47 +1430,6 @@ HalpGetFullGeometry(IN PDEVICE_OBJECT DeviceObject,
Status = IoStatusBlock.Status; Status = IoStatusBlock.Status;
} }
/* Check if the driver returned success */
if(NT_SUCCESS(Status))
{
/* Build another IRP */
Irp = IoBuildDeviceIoControlRequest(IOCTL_DISK_GET_PARTITION_INFO,
DeviceObject,
NULL,
0UL,
&PartitionInfo,
sizeof(PARTITION_INFORMATION),
FALSE,
Event,
&IoStatusBlock);
if (!Irp)
{
/* Fail, free the event */
ExFreePoolWithTag(Event, TAG_FILE_SYSTEM);
return STATUS_INSUFFICIENT_RESOURCES;
}
/* Reset event */
KeClearEvent(Event);
/* Call the driver and check if it's pending */
Status = IoCallDriver(DeviceObject, Irp);
if (Status == STATUS_PENDING)
{
/* Wait on the driver */
KeWaitForSingleObject(Event, Executive, KernelMode, FALSE, NULL);
Status = IoStatusBlock.Status;
}
/* Check if the driver returned success */
if(NT_SUCCESS(Status))
{
/* Get the number of sectors */
*RealSectorCount = (PartitionInfo.PartitionLength.QuadPart /
Geometry->BytesPerSector);
}
}
/* Free the event and return the Status */ /* Free the event and return the Status */
ExFreePoolWithTag(Event, TAG_FILE_SYSTEM); ExFreePoolWithTag(Event, TAG_FILE_SYSTEM);
return Status; return Status;
@ -1823,9 +1780,8 @@ xHalIoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject,
ULONG BufferSize = 2048, InputSize; ULONG BufferSize = 2048, InputSize;
PDRIVE_LAYOUT_INFORMATION DriveLayoutInfo = NULL; PDRIVE_LAYOUT_INFORMATION DriveLayoutInfo = NULL;
LONG j = -1, i = -1, k; LONG j = -1, i = -1, k;
DISK_GEOMETRY DiskGeometry; DISK_GEOMETRY_EX DiskGeometryEx;
LONGLONG EndSector, MaxSector, StartOffset; LONGLONG EndSector, MaxSector, StartOffset;
ULONGLONG MaxOffset;
LARGE_INTEGER Offset, VolumeOffset; LARGE_INTEGER Offset, VolumeOffset;
BOOLEAN IsPrimary = TRUE, IsEzDrive = FALSE, MbrFound = FALSE; BOOLEAN IsPrimary = TRUE, IsEzDrive = FALSE, MbrFound = FALSE;
BOOLEAN IsValid, IsEmpty = TRUE; BOOLEAN IsValid, IsEmpty = TRUE;
@ -1856,7 +1812,7 @@ xHalIoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject,
} }
/* Get drive geometry */ /* Get drive geometry */
Status = HalpGetFullGeometry(DeviceObject, &DiskGeometry, &MaxOffset); Status = HalpGetFullGeometry(DeviceObject, &DiskGeometryEx);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
ExFreePoolWithTag(*PartitionBuffer, TAG_FILE_SYSTEM); ExFreePoolWithTag(*PartitionBuffer, TAG_FILE_SYSTEM);
@ -1865,10 +1821,10 @@ xHalIoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject,
} }
/* Get the end and maximum sector */ /* Get the end and maximum sector */
EndSector = MaxOffset; EndSector = DiskGeometryEx.DiskSize.QuadPart / DiskGeometryEx.Geometry.BytesPerSector;
MaxSector = MaxOffset << 1; MaxSector = EndSector << 1;
DPRINT("FSTUB: MaxOffset = %#I64x, MaxSector = %#I64x\n", DPRINT("FSTUB: DiskSize = %#I64x, MaxSector = %#I64x\n",
MaxOffset, MaxSector); DiskGeometryEx.DiskSize, MaxSector);
/* Allocate our buffer */ /* Allocate our buffer */
Buffer = ExAllocatePoolWithTag(NonPagedPool, InputSize, TAG_FILE_SYSTEM); Buffer = ExAllocatePoolWithTag(NonPagedPool, InputSize, TAG_FILE_SYSTEM);
@ -1970,13 +1926,12 @@ xHalIoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject,
if (PartitionType == EFI_PMBR_OSTYPE_EFI) if (PartitionType == EFI_PMBR_OSTYPE_EFI)
{ {
/* Partition length might be bigger than disk size */ /* Partition length might be bigger than disk size */
FstubFixupEfiPartition(PartitionDescriptor, FstubFixupEfiPartition(PartitionDescriptor, DiskGeometryEx.DiskSize.QuadPart);
MaxOffset);
} }
/* Make sure that the partition is valid, unless it's the first */ /* Make sure that the partition is valid, unless it's the first */
if (!(HalpIsValidPartitionEntry(PartitionDescriptor, if (!(HalpIsValidPartitionEntry(PartitionDescriptor,
MaxOffset, DiskGeometryEx.DiskSize.QuadPart,
MaxSector)) && (j == 0)) MaxSector)) && (j == 0))
{ {
/* It's invalid, so fail */ /* It's invalid, so fail */
@ -2158,7 +2113,7 @@ xHalIoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject,
} while (Offset.HighPart | Offset.LowPart); } while (Offset.HighPart | Offset.LowPart);
/* Check if this is a removable device that's probably a super-floppy */ /* Check if this is a removable device that's probably a super-floppy */
if ((DiskGeometry.MediaType == RemovableMedia) && if ((DiskGeometryEx.Geometry.MediaType == RemovableMedia) &&
(j == 0) && (MbrFound) && (IsEmpty)) (j == 0) && (MbrFound) && (IsEmpty))
{ {
PBOOT_SECTOR_INFO BootSectorInfo = (PBOOT_SECTOR_INFO)Buffer; PBOOT_SECTOR_INFO BootSectorInfo = (PBOOT_SECTOR_INFO)Buffer;
@ -2179,7 +2134,7 @@ xHalIoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject,
if (j == -1) if (j == -1)
{ {
/* The likely cause is the super floppy detection above */ /* The likely cause is the super floppy detection above */
if ((MbrFound) || (DiskGeometry.MediaType == RemovableMedia)) if ((MbrFound) || (DiskGeometryEx.Geometry.MediaType == RemovableMedia))
{ {
/* Print out debugging information */ /* Print out debugging information */
DPRINT1("FSTUB: Drive %#p has no valid MBR. Make it into a " DPRINT1("FSTUB: Drive %#p has no valid MBR. Make it into a "
@ -2187,7 +2142,7 @@ xHalIoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject,
DeviceObject); DeviceObject);
DPRINT1("FSTUB: Drive has %I64d sectors and is %#016I64x " DPRINT1("FSTUB: Drive has %I64d sectors and is %#016I64x "
"bytes large\n", "bytes large\n",
EndSector, EndSector * DiskGeometry.BytesPerSector); EndSector, DiskGeometryEx.DiskSize);
/* We should at least have some sectors */ /* We should at least have some sectors */
if (EndSector > 0) if (EndSector > 0)
@ -2202,9 +2157,7 @@ xHalIoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject,
PartitionInfo->BootIndicator = FALSE; PartitionInfo->BootIndicator = FALSE;
PartitionInfo->HiddenSectors = 0; PartitionInfo->HiddenSectors = 0;
PartitionInfo->StartingOffset.QuadPart = 0; PartitionInfo->StartingOffset.QuadPart = 0;
PartitionInfo->PartitionLength.QuadPart = (EndSector * PartitionInfo->PartitionLength = DiskGeometryEx.DiskSize;
DiskGeometry.
BytesPerSector);
/* FIXME: REACTOS HACK */ /* FIXME: REACTOS HACK */
PartitionInfo->PartitionNumber = 0; PartitionInfo->PartitionNumber = 0;