[NTOS:FSTUB] Improve output of the FstubDbg* helpers + fix a bug

- Compile their contents only when NDEBUG is _NOT_ defined.

- Only keep the first DPRINT in these functions in order to keep the
  file path and line number, but replace the others with DbgPrint in
  order to have a clearer printout.

- Fix a bug in FstubDbgPrintSetPartitionEx(), where PartitionNumber has
  to be used as an indicator parameter but MUST NOT be used to index the
  PartitionEntry pointer. (PartitionEntry already points to the data for
  setting the partition specified by PartitionNumber.)
  The bug certainly came from a copy-pasting error from FstubDbgPrintPartitionEx().
This commit is contained in:
Hermès Bélusca-Maïto 2024-07-14 19:33:39 +02:00
parent 8c04fdd1af
commit 1827e4e776
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0

View file

@ -100,12 +100,6 @@ C_ASSERT(sizeof(MASTER_BOOT_RECORD) == 512);
((Disk)->Buffer) && \ ((Disk)->Buffer) && \
((Disk)->SectorCount)) ((Disk)->SectorCount))
VOID
NTAPI
FstubDbgPrintPartitionEx(IN PPARTITION_INFORMATION_EX PartitionEntry,
IN ULONG PartitionNumber
);
NTSTATUS NTSTATUS
NTAPI NTAPI
FstubDetectPartitionStyle(IN PDISK_INFORMATION Disk, FstubDetectPartitionStyle(IN PDISK_INFORMATION Disk,
@ -529,34 +523,32 @@ FstubCreateDiskRaw(IN PDEVICE_OBJECT DeviceObject)
return Status; return Status;
} }
PCHAR #ifndef NDEBUG
NTAPI static __inline
FstubDbgGuidToString(IN PGUID Guid, VOID
OUT PCHAR String) FstubDbgGuidToString(
_In_ PGUID Guid,
_Out_ PCHAR String)
{ {
sprintf(String, sprintf(String,
"{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
Guid->Data1, Guid->Data1, Guid->Data2, Guid->Data3,
Guid->Data2, Guid->Data4[0], Guid->Data4[1], Guid->Data4[2], Guid->Data4[3],
Guid->Data3, Guid->Data4[4], Guid->Data4[5], Guid->Data4[6], Guid->Data4[7]);
Guid->Data4[0],
Guid->Data4[1],
Guid->Data4[2],
Guid->Data4[3],
Guid->Data4[4],
Guid->Data4[5],
Guid->Data4[6],
Guid->Data4[7]);
return String;
} }
VOID static VOID
NTAPI FstubDbgPrintPartitionEx(
FstubDbgPrintDriveLayoutEx(IN PDRIVE_LAYOUT_INFORMATION_EX DriveLayout) _In_ PPARTITION_INFORMATION_EX PartitionEntry,
_In_ ULONG PartitionNumber);
#endif // !NDEBUG
static VOID
FstubDbgPrintDriveLayoutEx(
_In_ PDRIVE_LAYOUT_INFORMATION_EX DriveLayout)
{ {
#ifndef NDEBUG
ULONG i; ULONG i;
CHAR Guid[EFI_GUID_STRING_SIZE];
PAGED_CODE(); PAGED_CODE();
@ -564,104 +556,116 @@ FstubDbgPrintDriveLayoutEx(IN PDRIVE_LAYOUT_INFORMATION_EX DriveLayout)
switch (DriveLayout->PartitionStyle) switch (DriveLayout->PartitionStyle)
{ {
case PARTITION_STYLE_MBR: case PARTITION_STYLE_MBR:
{
if (DriveLayout->PartitionCount % NUM_PARTITION_TABLE_ENTRIES != 0) if (DriveLayout->PartitionCount % NUM_PARTITION_TABLE_ENTRIES != 0)
{ {
DPRINT("Warning: Partition count isn't a 4-factor: %lu!\n", DriveLayout->PartitionCount); DbgPrint(" Warning: Partition count isn't a 4-factor: %lu!\n", DriveLayout->PartitionCount);
} }
DbgPrint(" Signature: %8.8x\n", DriveLayout->Mbr.Signature);
DPRINT("Signature: %8.8x\n", DriveLayout->Mbr.Signature);
for (i = 0; i < DriveLayout->PartitionCount; i++) for (i = 0; i < DriveLayout->PartitionCount; i++)
{ {
FstubDbgPrintPartitionEx(DriveLayout->PartitionEntry, i); FstubDbgPrintPartitionEx(DriveLayout->PartitionEntry, i);
} }
break; break;
}
case PARTITION_STYLE_GPT: case PARTITION_STYLE_GPT:
{
CHAR Guid[EFI_GUID_STRING_SIZE];
FstubDbgGuidToString(&(DriveLayout->Gpt.DiskId), Guid); FstubDbgGuidToString(&(DriveLayout->Gpt.DiskId), Guid);
DPRINT("DiskId: %s\n", Guid); DbgPrint(" DiskId: %s\n", Guid);
DPRINT("StartingUsableOffset: %I64x\n", DriveLayout->Gpt.StartingUsableOffset.QuadPart); DbgPrint(" StartingUsableOffset: %I64x\n", DriveLayout->Gpt.StartingUsableOffset.QuadPart);
DPRINT("UsableLength: %I64x\n", DriveLayout->Gpt.UsableLength.QuadPart); DbgPrint(" UsableLength: %I64x\n", DriveLayout->Gpt.UsableLength.QuadPart);
DPRINT("MaxPartitionCount: %lu\n", DriveLayout->Gpt.MaxPartitionCount); DbgPrint(" MaxPartitionCount: %lu\n", DriveLayout->Gpt.MaxPartitionCount);
for (i = 0; i < DriveLayout->PartitionCount; i++) for (i = 0; i < DriveLayout->PartitionCount; i++)
{ {
FstubDbgPrintPartitionEx(DriveLayout->PartitionEntry, i); FstubDbgPrintPartitionEx(DriveLayout->PartitionEntry, i);
} }
break; break;
}
default: default:
DPRINT("Unsupported partition style: %lu\n", DriveLayout->PartitionStyle); DbgPrint(" Unsupported partition style: %lu\n", DriveLayout->PartitionStyle);
} }
#endif // !NDEBUG
} }
VOID #ifndef NDEBUG
NTAPI static VOID
FstubDbgPrintPartitionEx(IN PPARTITION_INFORMATION_EX PartitionEntry, FstubDbgPrintPartitionEx(
IN ULONG PartitionNumber) _In_ PPARTITION_INFORMATION_EX PartitionEntry,
_In_ ULONG PartitionNumber)
{ {
CHAR Guid[EFI_GUID_STRING_SIZE];
PAGED_CODE(); PAGED_CODE();
DPRINT("Printing partition %lu\n", PartitionNumber); DPRINT("Printing partition %lu\n", PartitionNumber);
switch (PartitionEntry[PartitionNumber].PartitionStyle) switch (PartitionEntry[PartitionNumber].PartitionStyle)
{ {
case PARTITION_STYLE_MBR: case PARTITION_STYLE_MBR:
DPRINT(" StartingOffset: %I64x\n", PartitionEntry[PartitionNumber].StartingOffset.QuadPart); {
DPRINT(" PartitionLength: %I64x\n", PartitionEntry[PartitionNumber].PartitionLength.QuadPart); DbgPrint(" StartingOffset: %I64x\n", PartitionEntry[PartitionNumber].StartingOffset.QuadPart);
DPRINT(" RewritePartition: %u\n", PartitionEntry[PartitionNumber].RewritePartition); DbgPrint(" PartitionLength: %I64x\n", PartitionEntry[PartitionNumber].PartitionLength.QuadPart);
DPRINT(" PartitionType: %02x\n", PartitionEntry[PartitionNumber].Mbr.PartitionType); DbgPrint(" RewritePartition: %u\n", PartitionEntry[PartitionNumber].RewritePartition);
DPRINT(" BootIndicator: %u\n", PartitionEntry[PartitionNumber].Mbr.BootIndicator); DbgPrint(" PartitionType: %02x\n", PartitionEntry[PartitionNumber].Mbr.PartitionType);
DPRINT(" RecognizedPartition: %u\n", PartitionEntry[PartitionNumber].Mbr.RecognizedPartition); DbgPrint(" BootIndicator: %u\n", PartitionEntry[PartitionNumber].Mbr.BootIndicator);
DPRINT(" HiddenSectors: %lu\n", PartitionEntry[PartitionNumber].Mbr.HiddenSectors); DbgPrint(" RecognizedPartition: %u\n", PartitionEntry[PartitionNumber].Mbr.RecognizedPartition);
DbgPrint(" HiddenSectors: %lu\n", PartitionEntry[PartitionNumber].Mbr.HiddenSectors);
break; break;
}
case PARTITION_STYLE_GPT: case PARTITION_STYLE_GPT:
DPRINT(" StartingOffset: %I64x\n", PartitionEntry[PartitionNumber].StartingOffset.QuadPart); {
DPRINT(" PartitionLength: %I64x\n", PartitionEntry[PartitionNumber].PartitionLength.QuadPart); CHAR Guid[EFI_GUID_STRING_SIZE];
DPRINT(" RewritePartition: %u\n", PartitionEntry[PartitionNumber].RewritePartition); DbgPrint(" StartingOffset: %I64x\n", PartitionEntry[PartitionNumber].StartingOffset.QuadPart);
DbgPrint(" PartitionLength: %I64x\n", PartitionEntry[PartitionNumber].PartitionLength.QuadPart);
DbgPrint(" RewritePartition: %u\n", PartitionEntry[PartitionNumber].RewritePartition);
FstubDbgGuidToString(&(PartitionEntry[PartitionNumber].Gpt.PartitionType), Guid); FstubDbgGuidToString(&(PartitionEntry[PartitionNumber].Gpt.PartitionType), Guid);
DPRINT(" PartitionType: %s\n", Guid); DbgPrint(" PartitionType: %s\n", Guid);
FstubDbgGuidToString(&(PartitionEntry[PartitionNumber].Gpt.PartitionId), Guid); FstubDbgGuidToString(&(PartitionEntry[PartitionNumber].Gpt.PartitionId), Guid);
DPRINT(" PartitionId: %s\n", Guid); DbgPrint(" PartitionId: %s\n", Guid);
DPRINT(" Attributes: %I64x\n", PartitionEntry[PartitionNumber].Gpt.Attributes); DbgPrint(" Attributes: %I64x\n", PartitionEntry[PartitionNumber].Gpt.Attributes);
DPRINT(" Name: %ws\n", PartitionEntry[PartitionNumber].Gpt.Name); DbgPrint(" Name: %ws\n", PartitionEntry[PartitionNumber].Gpt.Name);
break; break;
}
default: default:
DPRINT(" Unsupported partition style: %ld\n", PartitionEntry[PartitionNumber].PartitionStyle); DbgPrint(" Unsupported partition style: %ld\n", PartitionEntry[PartitionNumber].PartitionStyle);
} }
} }
#endif // !NDEBUG
VOID static VOID
NTAPI FstubDbgPrintSetPartitionEx(
FstubDbgPrintSetPartitionEx(IN PSET_PARTITION_INFORMATION_EX PartitionEntry, _In_ PSET_PARTITION_INFORMATION_EX PartitionEntry,
IN ULONG PartitionNumber) _In_ ULONG PartitionNumber)
{ {
CHAR Guid[EFI_GUID_STRING_SIZE]; #ifndef NDEBUG
PAGED_CODE(); PAGED_CODE();
DPRINT("FSTUB: SET_PARTITION_INFORMATION_EX: %p\n", PartitionEntry); DPRINT("FSTUB: SET_PARTITION_INFORMATION_EX: %p\n", PartitionEntry);
DPRINT("Modifying partition %lu\n", PartitionNumber); DbgPrint("Modifying partition %lu\n", PartitionNumber);
switch (PartitionEntry->PartitionStyle) switch (PartitionEntry->PartitionStyle)
{ {
case PARTITION_STYLE_MBR: case PARTITION_STYLE_MBR:
DPRINT(" PartitionType: %02x\n", PartitionEntry->Mbr.PartitionType); DbgPrint(" PartitionType: %02x\n", PartitionEntry->Mbr.PartitionType);
break; break;
case PARTITION_STYLE_GPT: case PARTITION_STYLE_GPT:
{
CHAR Guid[EFI_GUID_STRING_SIZE];
FstubDbgGuidToString(&(PartitionEntry->Gpt.PartitionType), Guid); FstubDbgGuidToString(&(PartitionEntry->Gpt.PartitionType), Guid);
DPRINT(" PartitionType: %s\n", Guid); DbgPrint(" PartitionType: %s\n", Guid);
FstubDbgGuidToString(&(PartitionEntry->Gpt.PartitionId), Guid); FstubDbgGuidToString(&(PartitionEntry->Gpt.PartitionId), Guid);
DPRINT(" PartitionId: %s\n", Guid); DbgPrint(" PartitionId: %s\n", Guid);
DPRINT(" Attributes: %I64x\n", PartitionEntry->Gpt.Attributes); DbgPrint(" Attributes: %I64x\n", PartitionEntry->Gpt.Attributes);
DPRINT(" Name: %ws\n", PartitionEntry->Gpt.Name); DbgPrint(" Name: %ws\n", PartitionEntry->Gpt.Name);
break; break;
}
default: default:
DPRINT(" Unsupported partition style: %ld\n", PartitionEntry[PartitionNumber].PartitionStyle); DbgPrint(" Unsupported partition style: %ld\n", PartitionEntry->PartitionStyle);
} }
#endif // !NDEBUG
} }
NTSTATUS NTSTATUS