https://git.reactos.org/?p=reactos.git;a=commitdiff;h=29615feeb6120ccf2c593…
commit 29615feeb6120ccf2c593dc61ca812d769feb870
Author: Victor Perevertkin <victor.perevertkin(a)reactos.org>
AuthorDate: Mon Dec 7 19:50:51 2020 +0300
Commit: Victor Perevertkin <victor.perevertkin(a)reactos.org>
CommitDate: Mon Dec 7 19:50:51 2020 +0300
[FSTUB] Fix bugs from 8d2fe54188616fa5869468ecf108bf4af9a8624f
The buffer is now PUCHAR or PVOID everywhere
---
ntoskrnl/fstub/disksup.c | 14 +++++++-------
ntoskrnl/fstub/fstubex.c | 19 +++++++++----------
ntoskrnl/include/internal/hal.h | 2 +-
3 files changed, 17 insertions(+), 18 deletions(-)
diff --git a/ntoskrnl/fstub/disksup.c b/ntoskrnl/fstub/disksup.c
index a685393b143..a27b8c35b8d 100644
--- a/ntoskrnl/fstub/disksup.c
+++ b/ntoskrnl/fstub/disksup.c
@@ -1704,7 +1704,7 @@ xHalExamineMBR(IN PDEVICE_OBJECT DeviceObject,
if (NT_SUCCESS(Status))
{
/* Validate the MBR Signature */
- if (((PUSHORT)Buffer)[BOOT_SIGNATURE_OFFSET] != BOOT_RECORD_SIGNATURE)
+ if (*(PUINT16)&Buffer[BOOT_SIGNATURE_OFFSET] != BOOT_RECORD_SIGNATURE)
{
/* Failed */
ExFreePoolWithTag(Buffer, TAG_FILE_SYSTEM);
@@ -1885,7 +1885,7 @@ xHalIoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject,
if (IsEzDrive && (Offset.QuadPart == 512)) Offset.QuadPart = 0;
/* Make sure this is a valid MBR */
- if (((PUSHORT)Buffer)[BOOT_SIGNATURE_OFFSET] != BOOT_RECORD_SIGNATURE)
+ if (*(PUINT16)&Buffer[BOOT_SIGNATURE_OFFSET] != BOOT_RECORD_SIGNATURE)
{
/* It's not, fail */
DPRINT1("FSTUB: (IoReadPartitionTable) No 0xaa55 found in "
@@ -2279,7 +2279,7 @@ xHalIoSetPartitionInformation(IN PDEVICE_OBJECT DeviceObject,
if (IsEzDrive && (Offset.QuadPart == 512)) Offset.QuadPart = 0;
/* Make sure this is a valid MBR */
- if (((PUSHORT)Buffer)[BOOT_SIGNATURE_OFFSET] != BOOT_RECORD_SIGNATURE)
+ if (*(PUINT16)&Buffer[BOOT_SIGNATURE_OFFSET] != BOOT_RECORD_SIGNATURE)
{
/* It's not, fail */
Status = STATUS_BAD_MASTER_BOOT_RECORD;
@@ -2395,7 +2395,7 @@ xHalIoWritePartitionTable(IN PDEVICE_OBJECT DeviceObject,
PIRP Irp;
NTSTATUS Status = STATUS_SUCCESS;
ULONG BufferSize;
- PUSHORT Buffer;
+ PUCHAR Buffer;
PPTE Entry;
PPARTITION_TABLE PartitionTable;
LARGE_INTEGER Offset, NextOffset, ExtendedOffset, SectorOffset;
@@ -2515,7 +2515,7 @@ xHalIoWritePartitionTable(IN PDEVICE_OBJECT DeviceObject,
if (!IsSuperFloppy)
{
/* Set the boot record signature */
- ((PUSHORT)Buffer)[BOOT_SIGNATURE_OFFSET] = BOOT_RECORD_SIGNATURE;
+ *(PUINT16)&Buffer[BOOT_SIGNATURE_OFFSET] = BOOT_RECORD_SIGNATURE;
/* By default, don't require a rewrite */
DoRewrite = FALSE;
@@ -2524,10 +2524,10 @@ xHalIoWritePartitionTable(IN PDEVICE_OBJECT DeviceObject,
if (!Offset.QuadPart)
{
/* Check if the signature doesn't match */
- if (*(PUINT32)&Buffer[PARTITION_TABLE_OFFSET] !=
PartitionBuffer->Signature)
+ if (*(PUINT32)&Buffer[DISK_SIGNATURE_OFFSET] !=
PartitionBuffer->Signature)
{
/* Then write the signature and now we need a rewrite */
- *(PUINT32)&Buffer[PARTITION_TABLE_OFFSET] =
PartitionBuffer->Signature;
+ *(PUINT32)&Buffer[DISK_SIGNATURE_OFFSET] =
PartitionBuffer->Signature;
DoRewrite = TRUE;
}
}
diff --git a/ntoskrnl/fstub/fstubex.c b/ntoskrnl/fstub/fstubex.c
index 5e3a819ae7c..f0285301162 100644
--- a/ntoskrnl/fstub/fstubex.c
+++ b/ntoskrnl/fstub/fstubex.c
@@ -19,7 +19,7 @@ typedef struct _DISK_INFORMATION
PDEVICE_OBJECT DeviceObject;
ULONG SectorSize;
DISK_GEOMETRY_EX DiskGeometry;
- PUSHORT Buffer;
+ PUCHAR Buffer;
ULONGLONG SectorCount;
} DISK_INFORMATION, *PDISK_INFORMATION;
@@ -122,7 +122,7 @@ NTAPI
FstubReadSector(IN PDEVICE_OBJECT DeviceObject,
IN ULONG SectorSize,
IN ULONGLONG StartingSector OPTIONAL,
- OUT PUSHORT Buffer
+ OUT PVOID Buffer
);
NTSTATUS
@@ -158,7 +158,7 @@ NTAPI
FstubWriteSector(IN PDEVICE_OBJECT DeviceObject,
IN ULONG SectorSize,
IN ULONGLONG StartingSector OPTIONAL,
- IN PUSHORT Buffer
+ IN PVOID Buffer
);
VOID
@@ -673,10 +673,9 @@ FstubDetectPartitionStyle(IN PDISK_INFORMATION Disk,
}
/* Get the partition descriptor array */
- PartitionDescriptor = (PPARTITION_DESCRIPTOR)
- &(Disk->Buffer[PARTITION_TABLE_OFFSET /
sizeof(Disk->Buffer[0])]);
+ PartitionDescriptor =
(PPARTITION_DESCRIPTOR)&Disk->Buffer[PARTITION_TABLE_OFFSET];
/* If we have not the 0xAA55 then it's raw partition */
- if (Disk->Buffer[BOOT_SIGNATURE_OFFSET] != BOOT_RECORD_SIGNATURE)
+ if (*(PUINT16)&Disk->Buffer[BOOT_SIGNATURE_OFFSET] != BOOT_RECORD_SIGNATURE)
{
*PartitionStyle = PARTITION_STYLE_RAW;
}
@@ -865,7 +864,7 @@ FstubReadHeaderEFI(IN PDISK_INFORMATION Disk,
/* Then zero the one in EFI header. This is needed to compute header checksum */
EFIHeader->HeaderCRC32 = 0;
/* Compute header checksum and compare with the one present in partition table */
- if (RtlComputeCrc32(0, (PUCHAR)Disk->Buffer, sizeof(EFI_PARTITION_HEADER)) !=
HeaderCRC32)
+ if (RtlComputeCrc32(0, Disk->Buffer, sizeof(EFI_PARTITION_HEADER)) !=
HeaderCRC32)
{
DPRINT("EFI::Not matching header checksum!\n");
return STATUS_DISK_CORRUPT_ERROR;
@@ -1173,7 +1172,7 @@ NTAPI
FstubReadSector(IN PDEVICE_OBJECT DeviceObject,
IN ULONG SectorSize,
IN ULONGLONG StartingSector OPTIONAL,
- OUT PUSHORT Buffer)
+ OUT PVOID Buffer)
{
PIRP Irp;
KEVENT Event;
@@ -1721,7 +1720,7 @@ NTAPI
FstubWriteSector(IN PDEVICE_OBJECT DeviceObject,
IN ULONG SectorSize,
IN ULONGLONG StartingSector OPTIONAL,
- IN PUSHORT Buffer)
+ IN PVOID Buffer)
{
PIRP Irp;
KEVENT Event;
@@ -2220,7 +2219,7 @@ IoReadDiskSignature(IN PDEVICE_OBJECT DeviceObject,
else
{
/* Compute MBR checksum */
- for (i = 0, CheckSum = 0; i < BytesPerSector / sizeof(UINT32); i++)
+ for (i = 0, CheckSum = 0; i < 512; i += sizeof(INT32))
{
CheckSum += *(PUINT32)&Buffer[i];
}
diff --git a/ntoskrnl/include/internal/hal.h b/ntoskrnl/include/internal/hal.h
index b02b7575a60..d7e0e47b57d 100644
--- a/ntoskrnl/include/internal/hal.h
+++ b/ntoskrnl/include/internal/hal.h
@@ -242,7 +242,7 @@ xKdUnmapVirtualAddress(
//
#define DISK_SIGNATURE_OFFSET 0x1B8
#define PARTITION_TABLE_OFFSET 0x1BE
-#define BOOT_SIGNATURE_OFFSET ((0x200 / sizeof(INT16)) - 1)
+#define BOOT_SIGNATURE_OFFSET (0x200 - 2)
#define BOOT_RECORD_SIGNATURE 0xAA55
#define NUM_PARTITION_TABLE_ENTRIES 4