https://git.reactos.org/?p=reactos.git;a=commitdiff;h=bee8e81d5a7e70c4e71f9…
commit bee8e81d5a7e70c4e71f9b07d464544b672a19e1
Author: Timo Kreuzer <timo.kreuzer(a)reactos.org>
AuthorDate: Sat Oct 5 12:38:17 2024 +0200
Commit: Timo Kreuzer <timo.kreuzer(a)reactos.org>
CommitDate: Sat Nov 2 17:31:57 2024 +0200
[FREELDR] Move IoReadPartitionTable to ntoskrnl.c
---
boot/freeldr/freeldr/arch/i386/ntoskrnl.c | 163 ++++++++++++++++++++++++++++--
boot/freeldr/freeldr/disk/partition.c | 148 ---------------------------
2 files changed, 152 insertions(+), 159 deletions(-)
diff --git a/boot/freeldr/freeldr/arch/i386/ntoskrnl.c
b/boot/freeldr/freeldr/arch/i386/ntoskrnl.c
index d14d822c8e3..7695daee3b4 100644
--- a/boot/freeldr/freeldr/arch/i386/ntoskrnl.c
+++ b/boot/freeldr/freeldr/arch/i386/ntoskrnl.c
@@ -11,6 +11,10 @@
#include <freeldr.h>
#include <ntoskrnl.h>
+#ifndef UNIMPLEMENTED
+#define UNIMPLEMENTED ASSERT(FALSE)
+#endif
+
/* FUNCTIONS *****************************************************************/
VOID
@@ -52,17 +56,154 @@ IoSetPartitionInformation(
return STATUS_NOT_IMPLEMENTED;
}
-/*
- * NTSTATUS
- * FASTCALL
- * IoReadPartitionTable(
- * IN PDEVICE_OBJECT DeviceObject,
- * IN ULONG SectorSize,
- * IN BOOLEAN ReturnRecognizedPartitions,
- * OUT PDRIVE_LAYOUT_INFORMATION *PartitionBuffer);
- *
- * See boot/freeldr/freeldr/disk/partition.c
- */
+#ifndef _M_AMD64
+NTSTATUS
+NTAPI
+IopReadBootRecord(
+ IN PDEVICE_OBJECT DeviceObject,
+ IN ULONGLONG LogicalSectorNumber,
+ IN ULONG SectorSize,
+ OUT PMASTER_BOOT_RECORD BootRecord)
+{
+ ULONG_PTR FileId = (ULONG_PTR)DeviceObject;
+ LARGE_INTEGER Position;
+ ULONG BytesRead;
+ ARC_STATUS Status;
+
+ Position.QuadPart = LogicalSectorNumber * SectorSize;
+ Status = ArcSeek(FileId, &Position, SeekAbsolute);
+ if (Status != ESUCCESS)
+ return STATUS_IO_DEVICE_ERROR;
+
+ Status = ArcRead(FileId, BootRecord, SectorSize, &BytesRead);
+ if (Status != ESUCCESS || BytesRead != SectorSize)
+ return STATUS_IO_DEVICE_ERROR;
+
+ return STATUS_SUCCESS;
+}
+
+BOOLEAN
+NTAPI
+IopCopyPartitionRecord(
+ IN BOOLEAN ReturnRecognizedPartitions,
+ IN ULONG SectorSize,
+ IN PPARTITION_TABLE_ENTRY PartitionTableEntry,
+ OUT PARTITION_INFORMATION *PartitionEntry)
+{
+ BOOLEAN IsRecognized;
+
+ IsRecognized = TRUE; /* FIXME */
+ if (!IsRecognized && ReturnRecognizedPartitions)
+ return FALSE;
+
+ PartitionEntry->StartingOffset.QuadPart =
(ULONGLONG)PartitionTableEntry->SectorCountBeforePartition * SectorSize;
+ PartitionEntry->PartitionLength.QuadPart =
(ULONGLONG)PartitionTableEntry->PartitionSectorCount * SectorSize;
+ PartitionEntry->HiddenSectors = 0;
+ PartitionEntry->PartitionNumber = 0; /* Will be filled later */
+ PartitionEntry->PartitionType = PartitionTableEntry->SystemIndicator;
+ PartitionEntry->BootIndicator = (PartitionTableEntry->BootIndicator & 0x80)
? TRUE : FALSE;
+ PartitionEntry->RecognizedPartition = IsRecognized;
+ PartitionEntry->RewritePartition = FALSE;
+
+ return TRUE;
+}
+
+NTSTATUS
+FASTCALL
+IoReadPartitionTable(
+ IN PDEVICE_OBJECT DeviceObject,
+ IN ULONG SectorSize,
+ IN BOOLEAN ReturnRecognizedPartitions,
+ OUT PDRIVE_LAYOUT_INFORMATION *PartitionBuffer)
+{
+ NTSTATUS Status;
+ PMASTER_BOOT_RECORD MasterBootRecord;
+ PDRIVE_LAYOUT_INFORMATION Partitions;
+ ULONG NbPartitions, i, Size;
+
+ *PartitionBuffer = NULL;
+
+ if (SectorSize < sizeof(MASTER_BOOT_RECORD))
+ return STATUS_NOT_SUPPORTED;
+
+ MasterBootRecord = ExAllocatePool(NonPagedPool, SectorSize);
+ if (!MasterBootRecord)
+ return STATUS_NO_MEMORY;
+
+ /* Read disk MBR */
+ Status = IopReadBootRecord(DeviceObject, 0, SectorSize, MasterBootRecord);
+ if (!NT_SUCCESS(Status))
+ {
+ ExFreePool(MasterBootRecord);
+ return Status;
+ }
+
+ /* Check validity of boot record */
+ if (MasterBootRecord->MasterBootRecordMagic != 0xaa55)
+ {
+ ExFreePool(MasterBootRecord);
+ return STATUS_NOT_SUPPORTED;
+ }
+
+ /* Count number of partitions */
+ NbPartitions = 0;
+ for (i = 0; i < 4; i++)
+ {
+ NbPartitions++;
+
+ if (MasterBootRecord->PartitionTable[i].SystemIndicator == PARTITION_EXTENDED
||
+ MasterBootRecord->PartitionTable[i].SystemIndicator ==
PARTITION_XINT13_EXTENDED)
+ {
+ /* FIXME: unhandled case; count number of partitions */
+ UNIMPLEMENTED;
+ }
+ }
+
+ if (NbPartitions == 0)
+ {
+ ExFreePool(MasterBootRecord);
+ return STATUS_NOT_SUPPORTED;
+ }
+
+ /* Allocation space to store partitions */
+ Size = FIELD_OFFSET(DRIVE_LAYOUT_INFORMATION, PartitionEntry) +
+ NbPartitions * sizeof(PARTITION_INFORMATION);
+ Partitions = ExAllocatePool(NonPagedPool, Size);
+ if (!Partitions)
+ {
+ ExFreePool(MasterBootRecord);
+ return STATUS_NO_MEMORY;
+ }
+
+ /* Count number of partitions */
+ NbPartitions = 0;
+ for (i = 0; i < 4; i++)
+ {
+ if (IopCopyPartitionRecord(ReturnRecognizedPartitions,
+ SectorSize,
+ &MasterBootRecord->PartitionTable[i],
+ &Partitions->PartitionEntry[NbPartitions]))
+ {
+ Partitions->PartitionEntry[NbPartitions].PartitionNumber = NbPartitions +
1;
+ NbPartitions++;
+ }
+
+ if (MasterBootRecord->PartitionTable[i].SystemIndicator == PARTITION_EXTENDED
||
+ MasterBootRecord->PartitionTable[i].SystemIndicator ==
PARTITION_XINT13_EXTENDED)
+ {
+ /* FIXME: unhandled case; copy partitions */
+ UNIMPLEMENTED;
+ }
+ }
+
+ Partitions->PartitionCount = NbPartitions;
+ Partitions->Signature = MasterBootRecord->Signature;
+ ExFreePool(MasterBootRecord);
+
+ *PartitionBuffer = Partitions;
+ return STATUS_SUCCESS;
+}
+#endif // _M_AMD64
NTSTATUS
FASTCALL
diff --git a/boot/freeldr/freeldr/disk/partition.c
b/boot/freeldr/freeldr/disk/partition.c
index 7afb6e1edbc..6b3fe87c615 100644
--- a/boot/freeldr/freeldr/disk/partition.c
+++ b/boot/freeldr/freeldr/disk/partition.c
@@ -438,152 +438,4 @@ DiskGetPartitionEntry(
return FALSE;
}
-#ifndef _M_AMD64
-NTSTATUS
-NTAPI
-IopReadBootRecord(
- IN PDEVICE_OBJECT DeviceObject,
- IN ULONGLONG LogicalSectorNumber,
- IN ULONG SectorSize,
- OUT PMASTER_BOOT_RECORD BootRecord)
-{
- ULONG_PTR FileId = (ULONG_PTR)DeviceObject;
- LARGE_INTEGER Position;
- ULONG BytesRead;
- ARC_STATUS Status;
-
- Position.QuadPart = LogicalSectorNumber * SectorSize;
- Status = ArcSeek(FileId, &Position, SeekAbsolute);
- if (Status != ESUCCESS)
- return STATUS_IO_DEVICE_ERROR;
-
- Status = ArcRead(FileId, BootRecord, SectorSize, &BytesRead);
- if (Status != ESUCCESS || BytesRead != SectorSize)
- return STATUS_IO_DEVICE_ERROR;
-
- return STATUS_SUCCESS;
-}
-
-BOOLEAN
-NTAPI
-IopCopyPartitionRecord(
- IN BOOLEAN ReturnRecognizedPartitions,
- IN ULONG SectorSize,
- IN PPARTITION_TABLE_ENTRY PartitionTableEntry,
- OUT PARTITION_INFORMATION *PartitionEntry)
-{
- BOOLEAN IsRecognized;
-
- IsRecognized = TRUE; /* FIXME */
- if (!IsRecognized && ReturnRecognizedPartitions)
- return FALSE;
-
- PartitionEntry->StartingOffset.QuadPart =
(ULONGLONG)PartitionTableEntry->SectorCountBeforePartition * SectorSize;
- PartitionEntry->PartitionLength.QuadPart =
(ULONGLONG)PartitionTableEntry->PartitionSectorCount * SectorSize;
- PartitionEntry->HiddenSectors = 0;
- PartitionEntry->PartitionNumber = 0; /* Will be filled later */
- PartitionEntry->PartitionType = PartitionTableEntry->SystemIndicator;
- PartitionEntry->BootIndicator = (PartitionTableEntry->BootIndicator & 0x80)
? TRUE : FALSE;
- PartitionEntry->RecognizedPartition = IsRecognized;
- PartitionEntry->RewritePartition = FALSE;
-
- return TRUE;
-}
-
-NTSTATUS
-FASTCALL
-IoReadPartitionTable(
- IN PDEVICE_OBJECT DeviceObject,
- IN ULONG SectorSize,
- IN BOOLEAN ReturnRecognizedPartitions,
- OUT PDRIVE_LAYOUT_INFORMATION *PartitionBuffer)
-{
- NTSTATUS Status;
- PMASTER_BOOT_RECORD MasterBootRecord;
- PDRIVE_LAYOUT_INFORMATION Partitions;
- ULONG NbPartitions, i, Size;
-
- *PartitionBuffer = NULL;
-
- if (SectorSize < sizeof(MASTER_BOOT_RECORD))
- return STATUS_NOT_SUPPORTED;
-
- MasterBootRecord = ExAllocatePool(NonPagedPool, SectorSize);
- if (!MasterBootRecord)
- return STATUS_NO_MEMORY;
-
- /* Read disk MBR */
- Status = IopReadBootRecord(DeviceObject, 0, SectorSize, MasterBootRecord);
- if (!NT_SUCCESS(Status))
- {
- ExFreePool(MasterBootRecord);
- return Status;
- }
-
- /* Check validity of boot record */
- if (MasterBootRecord->MasterBootRecordMagic != 0xaa55)
- {
- ExFreePool(MasterBootRecord);
- return STATUS_NOT_SUPPORTED;
- }
-
- /* Count number of partitions */
- NbPartitions = 0;
- for (i = 0; i < 4; i++)
- {
- NbPartitions++;
-
- if (MasterBootRecord->PartitionTable[i].SystemIndicator == PARTITION_EXTENDED
||
- MasterBootRecord->PartitionTable[i].SystemIndicator ==
PARTITION_XINT13_EXTENDED)
- {
- /* FIXME: unhandled case; count number of partitions */
- UNIMPLEMENTED;
- }
- }
-
- if (NbPartitions == 0)
- {
- ExFreePool(MasterBootRecord);
- return STATUS_NOT_SUPPORTED;
- }
-
- /* Allocation space to store partitions */
- Size = FIELD_OFFSET(DRIVE_LAYOUT_INFORMATION, PartitionEntry) +
- NbPartitions * sizeof(PARTITION_INFORMATION);
- Partitions = ExAllocatePool(NonPagedPool, Size);
- if (!Partitions)
- {
- ExFreePool(MasterBootRecord);
- return STATUS_NO_MEMORY;
- }
-
- /* Count number of partitions */
- NbPartitions = 0;
- for (i = 0; i < 4; i++)
- {
- if (IopCopyPartitionRecord(ReturnRecognizedPartitions,
- SectorSize,
- &MasterBootRecord->PartitionTable[i],
- &Partitions->PartitionEntry[NbPartitions]))
- {
- Partitions->PartitionEntry[NbPartitions].PartitionNumber = NbPartitions +
1;
- NbPartitions++;
- }
-
- if (MasterBootRecord->PartitionTable[i].SystemIndicator == PARTITION_EXTENDED
||
- MasterBootRecord->PartitionTable[i].SystemIndicator ==
PARTITION_XINT13_EXTENDED)
- {
- /* FIXME: unhandled case; copy partitions */
- UNIMPLEMENTED;
- }
- }
-
- Partitions->PartitionCount = NbPartitions;
- Partitions->Signature = MasterBootRecord->Signature;
- ExFreePool(MasterBootRecord);
-
- *PartitionBuffer = Partitions;
- return STATUS_SUCCESS;
-}
-#endif // _M_AMD64
#endif