mirror of
https://github.com/reactos/reactos.git
synced 2025-05-11 13:27:47 +00:00
- Fix multiple bugs in HalpCalculateChsValues.
- Fix lots of typecast warnings. - Fix potentially uninitialized variables. - This should fix the partitioning problems/regression. Thanks to hto for finding out the source of the bug. svn path=/trunk/; revision=25336
This commit is contained in:
parent
99e8c9a7c7
commit
8fe3cfc983
1 changed files with 60 additions and 47 deletions
|
@ -1009,24 +1009,23 @@ HalpIsValidPartitionEntry(IN PPARTITION_DESCRIPTOR Entry,
|
||||||
IN ULONGLONG MaxOffset,
|
IN ULONGLONG MaxOffset,
|
||||||
IN ULONGLONG MaxSector)
|
IN ULONGLONG MaxSector)
|
||||||
{
|
{
|
||||||
ULONGLONG endingSector;
|
ULONGLONG EndingSector;
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
|
|
||||||
/* Unused partitions are considered valid */
|
/* Unused partitions are considered valid */
|
||||||
if (Entry->PartitionType == PARTITION_ENTRY_UNUSED) return TRUE;
|
if (Entry->PartitionType == PARTITION_ENTRY_UNUSED) return TRUE;
|
||||||
|
|
||||||
/* Get the last sector of the partition */
|
/* Get the last sector of the partition */
|
||||||
endingSector = GET_STARTING_SECTOR(Entry) +
|
EndingSector = GET_STARTING_SECTOR(Entry) + GET_PARTITION_LENGTH(Entry);
|
||||||
GET_PARTITION_LENGTH(Entry);
|
|
||||||
|
|
||||||
/* Check if it's more then the maximum sector */
|
/* Check if it's more then the maximum sector */
|
||||||
if (endingSector > MaxSector)
|
if (EndingSector > MaxSector)
|
||||||
{
|
{
|
||||||
/* Invalid partition */
|
/* Invalid partition */
|
||||||
DPRINT1("FSTUB: entry is invalid\n");
|
DPRINT1("FSTUB: entry is invalid\n");
|
||||||
DPRINT1("FSTUB: offset %#08lx\n", GET_STARTING_SECTOR(Entry));
|
DPRINT1("FSTUB: offset %#08lx\n", GET_STARTING_SECTOR(Entry));
|
||||||
DPRINT1("FSTUB: length %#08lx\n", GET_PARTITION_LENGTH(Entry));
|
DPRINT1("FSTUB: length %#08lx\n", GET_PARTITION_LENGTH(Entry));
|
||||||
DPRINT1("FSTUB: end %#I64x\n", endingSector);
|
DPRINT1("FSTUB: end %#I64x\n", EndingSector);
|
||||||
DPRINT1("FSTUB: max %#I64x\n", MaxSector);
|
DPRINT1("FSTUB: max %#I64x\n", MaxSector);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -1036,7 +1035,7 @@ HalpIsValidPartitionEntry(IN PPARTITION_DESCRIPTOR Entry,
|
||||||
DPRINT1("FSTUB: entry is invalid\n");
|
DPRINT1("FSTUB: entry is invalid\n");
|
||||||
DPRINT1("FSTUB: offset %#08lx\n", GET_STARTING_SECTOR(Entry));
|
DPRINT1("FSTUB: offset %#08lx\n", GET_STARTING_SECTOR(Entry));
|
||||||
DPRINT1("FSTUB: length %#08lx\n", GET_PARTITION_LENGTH(Entry));
|
DPRINT1("FSTUB: length %#08lx\n", GET_PARTITION_LENGTH(Entry));
|
||||||
DPRINT1("FSTUB: end %#I64x\n", endingSector);
|
DPRINT1("FSTUB: end %#I64x\n", EndingSector);
|
||||||
DPRINT1("FSTUB: maxOffset %#I64x\n", MaxOffset);
|
DPRINT1("FSTUB: maxOffset %#I64x\n", MaxOffset);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -1055,59 +1054,69 @@ HalpCalculateChsValues(IN PLARGE_INTEGER PartitionOffset,
|
||||||
IN ULONG ConventionalCylinders,
|
IN ULONG ConventionalCylinders,
|
||||||
OUT PPARTITION_DESCRIPTOR PartitionDescriptor)
|
OUT PPARTITION_DESCRIPTOR PartitionDescriptor)
|
||||||
{
|
{
|
||||||
LARGE_INTEGER FirstSector, SectorCount, LastSector;
|
LARGE_INTEGER FirstSector, SectorCount;
|
||||||
ULONG SectorsPerCylinder, StartCluster, EndCluster;
|
ULONG LastSector, Remainder, SectorsPerCylinder;
|
||||||
ULONG StartHead, EndHead;
|
ULONG StartingCylinder, EndingCylinder;
|
||||||
ULONG StartSector, EndSector;
|
ULONG StartingTrack, EndingTrack;
|
||||||
ULONG Remainder;
|
ULONG StartingSector, EndingSector;
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
|
|
||||||
/* Calculate the number of sectors for each cylinder */
|
/* Calculate the number of sectors for each cylinder */
|
||||||
SectorsPerCylinder = SectorsPerTrack * NumberOfTracks;
|
SectorsPerCylinder = SectorsPerTrack * NumberOfTracks;
|
||||||
|
|
||||||
/* Calculate the start and end sector, as well as the count */
|
/* Calculate the first sector, and the sector count */
|
||||||
FirstSector.QuadPart = PartitionOffset->QuadPart >> ShiftCount;
|
FirstSector.QuadPart = PartitionOffset->QuadPart >> ShiftCount;
|
||||||
SectorCount.QuadPart = PartitionLength->QuadPart >> ShiftCount;
|
SectorCount.QuadPart = PartitionLength->QuadPart >> ShiftCount;
|
||||||
LastSector.QuadPart = FirstSector.QuadPart + SectorCount.QuadPart - 1;
|
|
||||||
|
|
||||||
/* Calculate the start and end clusters */
|
/* Now calculate the last sector */
|
||||||
StartCluster = FirstSector.LowPart / SectorsPerCylinder;
|
LastSector = FirstSector.LowPart + SectorCount.LowPart - 1;
|
||||||
EndCluster = LastSector.LowPart / SectorsPerCylinder;
|
|
||||||
|
/* Calculate the first and last cylinders */
|
||||||
|
StartingCylinder = FirstSector.LowPart / SectorsPerCylinder;
|
||||||
|
EndingCylinder = LastSector / SectorsPerCylinder;
|
||||||
|
|
||||||
/* Set the default number of cylinders */
|
/* Set the default number of cylinders */
|
||||||
if (!ConventionalCylinders) ConventionalCylinders = 1024;
|
if (!ConventionalCylinders) ConventionalCylinders = 1024;
|
||||||
|
|
||||||
/* Normalize the values */
|
/* Normalize the values */
|
||||||
if (StartCluster >= ConventionalCylinders)
|
if (StartingCylinder >= ConventionalCylinders)
|
||||||
{
|
{
|
||||||
/* Set the maximum to 1023 */
|
/* Set the maximum to 1023 */
|
||||||
StartCluster = ConventionalCylinders - 1;
|
StartingCylinder = ConventionalCylinders - 1;
|
||||||
}
|
}
|
||||||
if (EndCluster >= ConventionalCylinders)
|
if (EndingCylinder >= ConventionalCylinders)
|
||||||
{
|
{
|
||||||
/* Set the maximum to 1023 */
|
/* Set the maximum to 1023 */
|
||||||
EndCluster = ConventionalCylinders - 1;
|
EndingCylinder = ConventionalCylinders - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Calculate the starting head and sector that still remain */
|
/* Calculate the starting head and sector that still remain */
|
||||||
Remainder = StartCluster % SectorsPerCylinder;
|
Remainder = FirstSector.LowPart % SectorsPerCylinder;
|
||||||
StartHead = Remainder / SectorsPerTrack;
|
StartingTrack = Remainder / SectorsPerTrack;
|
||||||
StartSector = Remainder % SectorsPerTrack;
|
StartingSector = Remainder % SectorsPerTrack;
|
||||||
|
|
||||||
/* Calculate the ending head and sector that still remain */
|
/* Calculate the ending head and sector that still remain */
|
||||||
Remainder = EndCluster % SectorsPerCylinder;
|
Remainder = LastSector % SectorsPerCylinder;
|
||||||
EndHead = Remainder / SectorsPerTrack;
|
EndingTrack = Remainder / SectorsPerTrack;
|
||||||
EndSector = Remainder % SectorsPerTrack;
|
EndingSector = Remainder % SectorsPerTrack;
|
||||||
|
|
||||||
/* Write the values in the descriptor */
|
/* Set cylinder data for the MSB */
|
||||||
PartitionDescriptor->StartingCylinderMsb = StartCluster;
|
PartitionDescriptor->StartingCylinderMsb = (UCHAR)StartingCylinder;
|
||||||
PartitionDescriptor->EndingCylinderMsb = EndCluster;
|
PartitionDescriptor->EndingCylinderMsb = (UCHAR)EndingCylinder;
|
||||||
PartitionDescriptor->StartingTrack = StartHead;
|
|
||||||
PartitionDescriptor->EndingTrack = EndHead;
|
/* Set the track data */
|
||||||
PartitionDescriptor->StartingCylinderLsb = ((StartSector + 1) & 0x3F) |
|
PartitionDescriptor->StartingTrack = (UCHAR)StartingTrack;
|
||||||
((StartCluster >> 2) & 0xC0);
|
PartitionDescriptor->EndingTrack = (UCHAR)EndingTrack;
|
||||||
PartitionDescriptor->EndingCylinderLsb = ((EndSector + 1) & 0x3F) |
|
|
||||||
((EndCluster >> 2) & 0xC0);
|
/* Update cylinder data for the LSB */
|
||||||
|
StartingCylinder = ((StartingSector + 1) & 0x3F) |
|
||||||
|
((StartingCylinder >> 2) & 0xC0);
|
||||||
|
EndingCylinder = ((EndingSector + 1) & 0x3F) |
|
||||||
|
((EndingCylinder >> 2) & 0xC0);
|
||||||
|
|
||||||
|
/* Set the cylinder data for the LSB */
|
||||||
|
PartitionDescriptor->StartingCylinderLsb = (UCHAR)StartingCylinder;
|
||||||
|
PartitionDescriptor->EndingCylinderLsb = (UCHAR)EndingCylinder;
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
|
@ -1338,6 +1347,7 @@ IoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject,
|
||||||
PIO_STACK_LOCATION IoStackLocation;
|
PIO_STACK_LOCATION IoStackLocation;
|
||||||
PBOOT_SECTOR_INFO BootSectorInfo = (PBOOT_SECTOR_INFO)Buffer;
|
PBOOT_SECTOR_INFO BootSectorInfo = (PBOOT_SECTOR_INFO)Buffer;
|
||||||
UCHAR PartitionType;
|
UCHAR PartitionType;
|
||||||
|
LARGE_INTEGER HiddenSectors64;
|
||||||
VolumeOffset.QuadPart = Offset.QuadPart = 0;
|
VolumeOffset.QuadPart = Offset.QuadPart = 0;
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
|
|
||||||
|
@ -1584,18 +1594,19 @@ IoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject,
|
||||||
PartitionInfo->StartingOffset.QuadPart =
|
PartitionInfo->StartingOffset.QuadPart =
|
||||||
StartOffset +
|
StartOffset +
|
||||||
UInt32x32To64(GET_STARTING_SECTOR(PartitionDescriptor),
|
UInt32x32To64(GET_STARTING_SECTOR(PartitionDescriptor),
|
||||||
SectorSize);
|
SectorSize);
|
||||||
|
|
||||||
/* Calculate the number of hidden sectors */
|
/* Calculate the number of hidden sectors */
|
||||||
PartitionInfo->HiddenSectors = (PartitionInfo->
|
HiddenSectors64.QuadPart = (PartitionInfo->
|
||||||
StartingOffset.QuadPart -
|
StartingOffset.QuadPart -
|
||||||
StartOffset) /
|
StartOffset) /
|
||||||
SectorSize;
|
SectorSize;
|
||||||
|
PartitionInfo->HiddenSectors = HiddenSectors64.LowPart;
|
||||||
|
|
||||||
/* Get the partition length */
|
/* Get the partition length */
|
||||||
PartitionInfo->PartitionLength.QuadPart =
|
PartitionInfo->PartitionLength.QuadPart =
|
||||||
UInt32x32To64(GET_PARTITION_LENGTH(PartitionDescriptor),
|
UInt32x32To64(GET_PARTITION_LENGTH(PartitionDescriptor),
|
||||||
SectorSize);
|
SectorSize);
|
||||||
|
|
||||||
/* FIXME: REACTOS HACK */
|
/* FIXME: REACTOS HACK */
|
||||||
PartitionInfo->PartitionNumber = i + 1;
|
PartitionInfo->PartitionNumber = i + 1;
|
||||||
|
@ -1845,9 +1856,9 @@ IoSetPartitionInformation(IN PDEVICE_OBJECT DeviceObject,
|
||||||
if (++i == PartitionNumber)
|
if (++i == PartitionNumber)
|
||||||
{
|
{
|
||||||
/* We found a match, set the type */
|
/* We found a match, set the type */
|
||||||
PartitionDescriptor->PartitionType = PartitionType;
|
PartitionDescriptor->PartitionType = (UCHAR)PartitionType;
|
||||||
|
|
||||||
/* Reset the resusable event */
|
/* Reset the reusable event */
|
||||||
KeResetEvent(&Event);
|
KeResetEvent(&Event);
|
||||||
|
|
||||||
/* Build the write IRP */
|
/* Build the write IRP */
|
||||||
|
@ -1947,7 +1958,8 @@ IoWritePartitionTable(IN PDEVICE_OBJECT DeviceObject,
|
||||||
PPARTITION_TABLE PartitionTable;
|
PPARTITION_TABLE PartitionTable;
|
||||||
LARGE_INTEGER Offset, NextOffset, ExtendedOffset, SectorOffset;
|
LARGE_INTEGER Offset, NextOffset, ExtendedOffset, SectorOffset;
|
||||||
LARGE_INTEGER StartOffset, PartitionLength;
|
LARGE_INTEGER StartOffset, PartitionLength;
|
||||||
ULONG i, j, k;
|
ULONG i, j;
|
||||||
|
CCHAR k;
|
||||||
BOOLEAN IsEzDrive = FALSE, IsSuperFloppy = FALSE, DoRewrite = FALSE, IsMbr;
|
BOOLEAN IsEzDrive = FALSE, IsSuperFloppy = FALSE, DoRewrite = FALSE, IsMbr;
|
||||||
ULONG ConventionalCylinders;
|
ULONG ConventionalCylinders;
|
||||||
LONGLONG DiskSize;
|
LONGLONG DiskSize;
|
||||||
|
@ -1957,7 +1969,7 @@ IoWritePartitionTable(IN PDEVICE_OBJECT DeviceObject,
|
||||||
PIO_STACK_LOCATION IoStackLocation;
|
PIO_STACK_LOCATION IoStackLocation;
|
||||||
PPARTITION_INFORMATION PartitionInfo = PartitionBuffer->PartitionEntry;
|
PPARTITION_INFORMATION PartitionInfo = PartitionBuffer->PartitionEntry;
|
||||||
PPARTITION_INFORMATION TableEntry;
|
PPARTITION_INFORMATION TableEntry;
|
||||||
NextOffset.QuadPart = Offset.QuadPart = 0;
|
ExtendedOffset.QuadPart = NextOffset.QuadPart = Offset.QuadPart = 0;
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
|
|
||||||
/* Normalize the buffer size */
|
/* Normalize the buffer size */
|
||||||
|
@ -2011,14 +2023,15 @@ IoWritePartitionTable(IN PDEVICE_OBJECT DeviceObject,
|
||||||
Buffer = ExAllocatePoolWithTag(NonPagedPool, PAGE_SIZE, TAG_FILE_SYSTEM);
|
Buffer = ExAllocatePoolWithTag(NonPagedPool, PAGE_SIZE, TAG_FILE_SYSTEM);
|
||||||
if (!Buffer) return STATUS_INSUFFICIENT_RESOURCES;
|
if (!Buffer) return STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
|
||||||
|
/* Loop the entries */
|
||||||
Entry = (PPTE)&Buffer[PARTITION_TABLE_OFFSET];
|
Entry = (PPTE)&Buffer[PARTITION_TABLE_OFFSET];
|
||||||
for (i = 0; i < DiskLayout->TableCount; i++)
|
for (i = 0; i < DiskLayout->TableCount; i++)
|
||||||
{
|
{
|
||||||
/* Set if this is the MBR partition */
|
/* Set if this is the MBR partition */
|
||||||
IsMbr= !i;
|
IsMbr= (BOOLEAN)!i;
|
||||||
|
|
||||||
/* Initialize th event */
|
/* Initialize th event */
|
||||||
KeInitializeEvent( &Event, NotificationEvent, FALSE );
|
KeInitializeEvent(&Event, NotificationEvent, FALSE);
|
||||||
|
|
||||||
/* Build the read IRP */
|
/* Build the read IRP */
|
||||||
Irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,
|
Irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,
|
||||||
|
|
Loading…
Reference in a new issue