Skip to content

Commit 5201472

Browse files
committed
[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.
1 parent 64abd9f commit 5201472

File tree

1 file changed

+15
-62
lines changed

1 file changed

+15
-62
lines changed

ntoskrnl/fstub/disksup.c

Lines changed: 15 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,14 +1387,12 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
13871387
NTSTATUS
13881388
NTAPI
13891389
HalpGetFullGeometry(IN PDEVICE_OBJECT DeviceObject,
1390-
IN PDISK_GEOMETRY Geometry,
1391-
OUT PULONGLONG RealSectorCount)
1390+
OUT PDISK_GEOMETRY_EX Geometry)
13921391
{
13931392
PIRP Irp;
13941393
IO_STATUS_BLOCK IoStatusBlock;
13951394
PKEVENT Event;
13961395
NTSTATUS Status;
1397-
PARTITION_INFORMATION PartitionInfo;
13981396
PAGED_CODE();
13991397

14001398
/* Allocate a non-paged event */
@@ -1407,12 +1405,12 @@ HalpGetFullGeometry(IN PDEVICE_OBJECT DeviceObject,
14071405
KeInitializeEvent(Event, NotificationEvent, FALSE);
14081406

14091407
/* Build the IRP */
1410-
Irp = IoBuildDeviceIoControlRequest(IOCTL_DISK_GET_DRIVE_GEOMETRY,
1408+
Irp = IoBuildDeviceIoControlRequest(IOCTL_DISK_GET_DRIVE_GEOMETRY_EX,
14111409
DeviceObject,
14121410
NULL,
14131411
0UL,
14141412
Geometry,
1415-
sizeof(DISK_GEOMETRY),
1413+
sizeof(DISK_GEOMETRY_EX),
14161414
FALSE,
14171415
Event,
14181416
&IoStatusBlock);
@@ -1432,47 +1430,6 @@ HalpGetFullGeometry(IN PDEVICE_OBJECT DeviceObject,
14321430
Status = IoStatusBlock.Status;
14331431
}
14341432

1435-
/* Check if the driver returned success */
1436-
if(NT_SUCCESS(Status))
1437-
{
1438-
/* Build another IRP */
1439-
Irp = IoBuildDeviceIoControlRequest(IOCTL_DISK_GET_PARTITION_INFO,
1440-
DeviceObject,
1441-
NULL,
1442-
0UL,
1443-
&PartitionInfo,
1444-
sizeof(PARTITION_INFORMATION),
1445-
FALSE,
1446-
Event,
1447-
&IoStatusBlock);
1448-
if (!Irp)
1449-
{
1450-
/* Fail, free the event */
1451-
ExFreePoolWithTag(Event, TAG_FILE_SYSTEM);
1452-
return STATUS_INSUFFICIENT_RESOURCES;
1453-
}
1454-
1455-
/* Reset event */
1456-
KeClearEvent(Event);
1457-
1458-
/* Call the driver and check if it's pending */
1459-
Status = IoCallDriver(DeviceObject, Irp);
1460-
if (Status == STATUS_PENDING)
1461-
{
1462-
/* Wait on the driver */
1463-
KeWaitForSingleObject(Event, Executive, KernelMode, FALSE, NULL);
1464-
Status = IoStatusBlock.Status;
1465-
}
1466-
1467-
/* Check if the driver returned success */
1468-
if(NT_SUCCESS(Status))
1469-
{
1470-
/* Get the number of sectors */
1471-
*RealSectorCount = (PartitionInfo.PartitionLength.QuadPart /
1472-
Geometry->BytesPerSector);
1473-
}
1474-
}
1475-
14761433
/* Free the event and return the Status */
14771434
ExFreePoolWithTag(Event, TAG_FILE_SYSTEM);
14781435
return Status;
@@ -1823,9 +1780,8 @@ xHalIoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject,
18231780
ULONG BufferSize = 2048, InputSize;
18241781
PDRIVE_LAYOUT_INFORMATION DriveLayoutInfo = NULL;
18251782
LONG j = -1, i = -1, k;
1826-
DISK_GEOMETRY DiskGeometry;
1783+
DISK_GEOMETRY_EX DiskGeometryEx;
18271784
LONGLONG EndSector, MaxSector, StartOffset;
1828-
ULONGLONG MaxOffset;
18291785
LARGE_INTEGER Offset, VolumeOffset;
18301786
BOOLEAN IsPrimary = TRUE, IsEzDrive = FALSE, MbrFound = FALSE;
18311787
BOOLEAN IsValid, IsEmpty = TRUE;
@@ -1856,7 +1812,7 @@ xHalIoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject,
18561812
}
18571813

18581814
/* Get drive geometry */
1859-
Status = HalpGetFullGeometry(DeviceObject, &DiskGeometry, &MaxOffset);
1815+
Status = HalpGetFullGeometry(DeviceObject, &DiskGeometryEx);
18601816
if (!NT_SUCCESS(Status))
18611817
{
18621818
ExFreePoolWithTag(*PartitionBuffer, TAG_FILE_SYSTEM);
@@ -1865,10 +1821,10 @@ xHalIoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject,
18651821
}
18661822

18671823
/* Get the end and maximum sector */
1868-
EndSector = MaxOffset;
1869-
MaxSector = MaxOffset << 1;
1870-
DPRINT("FSTUB: MaxOffset = %#I64x, MaxSector = %#I64x\n",
1871-
MaxOffset, MaxSector);
1824+
EndSector = DiskGeometryEx.DiskSize.QuadPart / DiskGeometryEx.Geometry.BytesPerSector;
1825+
MaxSector = EndSector << 1;
1826+
DPRINT("FSTUB: DiskSize = %#I64x, MaxSector = %#I64x\n",
1827+
DiskGeometryEx.DiskSize, MaxSector);
18721828

18731829
/* Allocate our buffer */
18741830
Buffer = ExAllocatePoolWithTag(NonPagedPool, InputSize, TAG_FILE_SYSTEM);
@@ -1970,13 +1926,12 @@ xHalIoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject,
19701926
if (PartitionType == EFI_PMBR_OSTYPE_EFI)
19711927
{
19721928
/* Partition length might be bigger than disk size */
1973-
FstubFixupEfiPartition(PartitionDescriptor,
1974-
MaxOffset);
1929+
FstubFixupEfiPartition(PartitionDescriptor, DiskGeometryEx.DiskSize.QuadPart);
19751930
}
19761931

19771932
/* Make sure that the partition is valid, unless it's the first */
19781933
if (!(HalpIsValidPartitionEntry(PartitionDescriptor,
1979-
MaxOffset,
1934+
DiskGeometryEx.DiskSize.QuadPart,
19801935
MaxSector)) && (j == 0))
19811936
{
19821937
/* It's invalid, so fail */
@@ -2158,7 +2113,7 @@ xHalIoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject,
21582113
} while (Offset.HighPart | Offset.LowPart);
21592114

21602115
/* Check if this is a removable device that's probably a super-floppy */
2161-
if ((DiskGeometry.MediaType == RemovableMedia) &&
2116+
if ((DiskGeometryEx.Geometry.MediaType == RemovableMedia) &&
21622117
(j == 0) && (MbrFound) && (IsEmpty))
21632118
{
21642119
PBOOT_SECTOR_INFO BootSectorInfo = (PBOOT_SECTOR_INFO)Buffer;
@@ -2179,15 +2134,15 @@ xHalIoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject,
21792134
if (j == -1)
21802135
{
21812136
/* The likely cause is the super floppy detection above */
2182-
if ((MbrFound) || (DiskGeometry.MediaType == RemovableMedia))
2137+
if ((MbrFound) || (DiskGeometryEx.Geometry.MediaType == RemovableMedia))
21832138
{
21842139
/* Print out debugging information */
21852140
DPRINT1("FSTUB: Drive %#p has no valid MBR. Make it into a "
21862141
"super-floppy\n",
21872142
DeviceObject);
21882143
DPRINT1("FSTUB: Drive has %I64d sectors and is %#016I64x "
21892144
"bytes large\n",
2190-
EndSector, EndSector * DiskGeometry.BytesPerSector);
2145+
EndSector, DiskGeometryEx.DiskSize);
21912146

21922147
/* We should at least have some sectors */
21932148
if (EndSector > 0)
@@ -2202,9 +2157,7 @@ xHalIoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject,
22022157
PartitionInfo->BootIndicator = FALSE;
22032158
PartitionInfo->HiddenSectors = 0;
22042159
PartitionInfo->StartingOffset.QuadPart = 0;
2205-
PartitionInfo->PartitionLength.QuadPart = (EndSector *
2206-
DiskGeometry.
2207-
BytesPerSector);
2160+
PartitionInfo->PartitionLength = DiskGeometryEx.DiskSize;
22082161

22092162
/* FIXME: REACTOS HACK */
22102163
PartitionInfo->PartitionNumber = 0;

0 commit comments

Comments
 (0)