mirror of
https://github.com/reactos/reactos.git
synced 2024-08-07 19:58:21 +00:00
Got xHalIoWritePartitionTable() working.
svn path=/trunk/; revision=5592
This commit is contained in:
parent
d4deb682ee
commit
ff28f462af
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: xhaldrv.c,v 1.35 2003/08/10 16:49:07 ekohl Exp $
|
/* $Id: xhaldrv.c,v 1.36 2003/08/15 19:37:32 ekohl Exp $
|
||||||
*
|
*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS kernel
|
* PROJECT: ReactOS kernel
|
||||||
|
@ -183,7 +183,7 @@ xHalpReadSector(IN PDEVICE_OBJECT DeviceObject,
|
||||||
PIRP Irp;
|
PIRP Irp;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
|
||||||
DPRINT("xHalReadMBR()\n");
|
DPRINT("xHalpReadSector()\n");
|
||||||
|
|
||||||
assert(DeviceObject);
|
assert(DeviceObject);
|
||||||
assert(Buffer);
|
assert(Buffer);
|
||||||
|
@ -204,7 +204,7 @@ xHalpReadSector(IN PDEVICE_OBJECT DeviceObject,
|
||||||
NotificationEvent,
|
NotificationEvent,
|
||||||
FALSE);
|
FALSE);
|
||||||
|
|
||||||
/* Read MBR (Master Boot Record) */
|
/* Read the sector */
|
||||||
Irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,
|
Irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,
|
||||||
DeviceObject,
|
DeviceObject,
|
||||||
Sector,
|
Sector,
|
||||||
|
@ -238,6 +238,58 @@ xHalpReadSector(IN PDEVICE_OBJECT DeviceObject,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static NTSTATUS
|
||||||
|
xHalpReadSector2 (IN PDEVICE_OBJECT DeviceObject,
|
||||||
|
IN ULONG SectorSize,
|
||||||
|
IN PLARGE_INTEGER SectorOffset,
|
||||||
|
IN PVOID Sector)
|
||||||
|
{
|
||||||
|
IO_STATUS_BLOCK StatusBlock;
|
||||||
|
KEVENT Event;
|
||||||
|
PIRP Irp;
|
||||||
|
NTSTATUS Status;
|
||||||
|
|
||||||
|
DPRINT("xHalpReadSector2() called\n");
|
||||||
|
|
||||||
|
assert(DeviceObject);
|
||||||
|
assert(Buffer);
|
||||||
|
|
||||||
|
KeInitializeEvent(&Event,
|
||||||
|
NotificationEvent,
|
||||||
|
FALSE);
|
||||||
|
|
||||||
|
/* Read the sector */
|
||||||
|
Irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,
|
||||||
|
DeviceObject,
|
||||||
|
Sector,
|
||||||
|
SectorSize,
|
||||||
|
SectorOffset,
|
||||||
|
&Event,
|
||||||
|
&StatusBlock);
|
||||||
|
|
||||||
|
Status = IoCallDriver(DeviceObject,
|
||||||
|
Irp);
|
||||||
|
if (Status == STATUS_PENDING)
|
||||||
|
{
|
||||||
|
KeWaitForSingleObject(&Event,
|
||||||
|
Executive,
|
||||||
|
KernelMode,
|
||||||
|
FALSE,
|
||||||
|
NULL);
|
||||||
|
Status = StatusBlock.Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
DPRINT("Reading sector failed (Status 0x%08lx)\n",
|
||||||
|
Status);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static NTSTATUS
|
static NTSTATUS
|
||||||
xHalpWriteSector(IN PDEVICE_OBJECT DeviceObject,
|
xHalpWriteSector(IN PDEVICE_OBJECT DeviceObject,
|
||||||
IN ULONG SectorSize,
|
IN ULONG SectorSize,
|
||||||
|
@ -249,7 +301,7 @@ xHalpWriteSector(IN PDEVICE_OBJECT DeviceObject,
|
||||||
PIRP Irp;
|
PIRP Irp;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
|
||||||
DPRINT("xHalWriteMBR()\n");
|
DPRINT("xHalpWriteSector() called\n");
|
||||||
|
|
||||||
if (SectorSize < 512)
|
if (SectorSize < 512)
|
||||||
SectorSize = 512;
|
SectorSize = 512;
|
||||||
|
@ -260,7 +312,7 @@ xHalpWriteSector(IN PDEVICE_OBJECT DeviceObject,
|
||||||
NotificationEvent,
|
NotificationEvent,
|
||||||
FALSE);
|
FALSE);
|
||||||
|
|
||||||
/* Write MBR (Master Boot Record) */
|
/* Write the sector */
|
||||||
Irp = IoBuildSynchronousFsdRequest(IRP_MJ_WRITE,
|
Irp = IoBuildSynchronousFsdRequest(IRP_MJ_WRITE,
|
||||||
DeviceObject,
|
DeviceObject,
|
||||||
Sector,
|
Sector,
|
||||||
|
@ -283,7 +335,7 @@ xHalpWriteSector(IN PDEVICE_OBJECT DeviceObject,
|
||||||
|
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
DPRINT("Writing MBR failed (Status 0x%08lx)\n",
|
DPRINT("Writing sector failed (Status 0x%08lx)\n",
|
||||||
Status);
|
Status);
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
@ -695,10 +747,10 @@ xHalIoReadPartitionTable(PDEVICE_OBJECT DeviceObject,
|
||||||
{
|
{
|
||||||
KEVENT Event;
|
KEVENT Event;
|
||||||
IO_STATUS_BLOCK StatusBlock;
|
IO_STATUS_BLOCK StatusBlock;
|
||||||
ULARGE_INTEGER PartitionOffset;
|
LARGE_INTEGER RealPartitionOffset;
|
||||||
ULARGE_INTEGER RealPartitionOffset;
|
ULONGLONG PartitionOffset;
|
||||||
ULARGE_INTEGER nextPartitionOffset;
|
ULONGLONG nextPartitionOffset;
|
||||||
ULARGE_INTEGER containerOffset;
|
ULONGLONG containerOffset;
|
||||||
PIRP Irp;
|
PIRP Irp;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
PPARTITION_SECTOR PartitionSector;
|
PPARTITION_SECTOR PartitionSector;
|
||||||
|
@ -760,8 +812,8 @@ xHalIoReadPartitionTable(PDEVICE_OBJECT DeviceObject,
|
||||||
RtlZeroMemory(LayoutBuffer,
|
RtlZeroMemory(LayoutBuffer,
|
||||||
0x1000);
|
0x1000);
|
||||||
|
|
||||||
PartitionOffset.QuadPart = (ULONGLONG)0;
|
PartitionOffset = 0ULL;
|
||||||
containerOffset.QuadPart = (ULONGLONG)0;
|
containerOffset = 0ULL;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
@ -769,11 +821,11 @@ xHalIoReadPartitionTable(PDEVICE_OBJECT DeviceObject,
|
||||||
|
|
||||||
if (DiskManager == OntrackDiskManager)
|
if (DiskManager == OntrackDiskManager)
|
||||||
{
|
{
|
||||||
RealPartitionOffset.QuadPart = PartitionOffset.QuadPart + (ULONGLONG)(63 * SectorSize);
|
RealPartitionOffset.QuadPart = PartitionOffset + (ULONGLONG)(63 * SectorSize);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
RealPartitionOffset.QuadPart = PartitionOffset.QuadPart;
|
RealPartitionOffset.QuadPart = PartitionOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
DPRINT("RealPartitionOffset: %I64u\n", RealPartitionOffset.QuadPart / SectorSize);
|
DPRINT("RealPartitionOffset: %I64u\n", RealPartitionOffset.QuadPart / SectorSize);
|
||||||
|
@ -784,7 +836,7 @@ xHalIoReadPartitionTable(PDEVICE_OBJECT DeviceObject,
|
||||||
|
|
||||||
Irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,
|
Irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,
|
||||||
DeviceObject,
|
DeviceObject,
|
||||||
PartitionSector, //SectorBuffer,
|
PartitionSector,
|
||||||
SectorSize,
|
SectorSize,
|
||||||
(PLARGE_INTEGER)&RealPartitionOffset,
|
(PLARGE_INTEGER)&RealPartitionOffset,
|
||||||
&Event,
|
&Event,
|
||||||
|
@ -840,7 +892,8 @@ xHalIoReadPartitionTable(PDEVICE_OBJECT DeviceObject,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (PartitionOffset.QuadPart == 0ULL)
|
// if (PartitionOffset.QuadPart == 0ULL)
|
||||||
|
if (PartitionOffset == 0ULL)
|
||||||
{
|
{
|
||||||
LayoutBuffer->Signature = PartitionSector->Signature;
|
LayoutBuffer->Signature = PartitionSector->Signature;
|
||||||
DPRINT("Disk signature: %lx\n", LayoutBuffer->Signature);
|
DPRINT("Disk signature: %lx\n", LayoutBuffer->Signature);
|
||||||
|
@ -853,11 +906,11 @@ xHalIoReadPartitionTable(PDEVICE_OBJECT DeviceObject,
|
||||||
if (IsContainerPartition(PartitionSector->Partition[i].PartitionType))
|
if (IsContainerPartition(PartitionSector->Partition[i].PartitionType))
|
||||||
{
|
{
|
||||||
ExtendedFound = TRUE;
|
ExtendedFound = TRUE;
|
||||||
if ((ULONGLONG) containerOffset.QuadPart == (ULONGLONG) 0)
|
if ((ULONGLONG) containerOffset == (ULONGLONG) 0)
|
||||||
{
|
{
|
||||||
containerOffset = PartitionOffset;
|
containerOffset = PartitionOffset;
|
||||||
}
|
}
|
||||||
nextPartitionOffset.QuadPart = (ULONGLONG) containerOffset.QuadPart +
|
nextPartitionOffset = (ULONGLONG) containerOffset +
|
||||||
(ULONGLONG) PartitionSector->Partition[i].StartingBlock *
|
(ULONGLONG) PartitionSector->Partition[i].StartingBlock *
|
||||||
(ULONGLONG) SectorSize;
|
(ULONGLONG) SectorSize;
|
||||||
}
|
}
|
||||||
|
@ -878,14 +931,14 @@ xHalIoReadPartitionTable(PDEVICE_OBJECT DeviceObject,
|
||||||
else if (IsContainerPartition(PartitionSector->Partition[i].PartitionType))
|
else if (IsContainerPartition(PartitionSector->Partition[i].PartitionType))
|
||||||
{
|
{
|
||||||
LayoutBuffer->PartitionEntry[Count].StartingOffset.QuadPart =
|
LayoutBuffer->PartitionEntry[Count].StartingOffset.QuadPart =
|
||||||
(ULONGLONG) containerOffset.QuadPart +
|
(ULONGLONG) containerOffset +
|
||||||
(ULONGLONG) PartitionSector->Partition[i].StartingBlock *
|
(ULONGLONG) PartitionSector->Partition[i].StartingBlock *
|
||||||
(ULONGLONG) SectorSize;
|
(ULONGLONG) SectorSize;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LayoutBuffer->PartitionEntry[Count].StartingOffset.QuadPart =
|
LayoutBuffer->PartitionEntry[Count].StartingOffset.QuadPart =
|
||||||
(ULONGLONG)PartitionOffset.QuadPart +
|
(ULONGLONG)PartitionOffset +
|
||||||
((ULONGLONG)PartitionSector->Partition[i].StartingBlock * (ULONGLONG)SectorSize);
|
((ULONGLONG)PartitionSector->Partition[i].StartingBlock * (ULONGLONG)SectorSize);
|
||||||
}
|
}
|
||||||
LayoutBuffer->PartitionEntry[Count].PartitionLength.QuadPart =
|
LayoutBuffer->PartitionEntry[Count].PartitionLength.QuadPart =
|
||||||
|
@ -951,10 +1004,13 @@ xHalIoWritePartitionTable(IN PDEVICE_OBJECT DeviceObject,
|
||||||
IN PDRIVE_LAYOUT_INFORMATION PartitionBuffer)
|
IN PDRIVE_LAYOUT_INFORMATION PartitionBuffer)
|
||||||
{
|
{
|
||||||
PPARTITION_SECTOR PartitionSector;
|
PPARTITION_SECTOR PartitionSector;
|
||||||
LARGE_INTEGER SectorOffset;
|
LARGE_INTEGER RealPartitionOffset;
|
||||||
NTSTATUS Status;
|
ULONGLONG PartitionOffset;
|
||||||
|
ULONGLONG NextPartitionOffset;
|
||||||
|
ULONGLONG ContainerOffset;
|
||||||
|
BOOLEAN ContainerEntry;
|
||||||
ULONG i;
|
ULONG i;
|
||||||
|
ULONG j;
|
||||||
ULONG StartBlock;
|
ULONG StartBlock;
|
||||||
ULONG SectorCount;
|
ULONG SectorCount;
|
||||||
ULONG StartCylinder;
|
ULONG StartCylinder;
|
||||||
|
@ -965,13 +1021,14 @@ xHalIoWritePartitionTable(IN PDEVICE_OBJECT DeviceObject,
|
||||||
ULONG EndHead;
|
ULONG EndHead;
|
||||||
ULONG lba;
|
ULONG lba;
|
||||||
ULONG x;
|
ULONG x;
|
||||||
|
NTSTATUS Status;
|
||||||
|
|
||||||
DPRINT("xHalIoWritePartitionTable(%p %lu %lu %lu %p)\n",
|
DPRINT1 ("xHalIoWritePartitionTable(%p %lu %lu %lu %p)\n",
|
||||||
DeviceObject,
|
DeviceObject,
|
||||||
SectorSize,
|
SectorSize,
|
||||||
SectorsPerTrack,
|
SectorsPerTrack,
|
||||||
NumberOfHeads,
|
NumberOfHeads,
|
||||||
PartitionBuffer);
|
PartitionBuffer);
|
||||||
|
|
||||||
assert(DeviceObject);
|
assert(DeviceObject);
|
||||||
assert(PartitionBuffer);
|
assert(PartitionBuffer);
|
||||||
|
@ -1000,136 +1057,180 @@ xHalIoWritePartitionTable(IN PDEVICE_OBJECT DeviceObject,
|
||||||
return STATUS_UNSUCCESSFUL;
|
return STATUS_UNSUCCESSFUL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocate partition sector */
|
||||||
for (i = 0; i < PartitionBuffer->PartitionCount; i++)
|
PartitionSector = (PPARTITION_SECTOR)ExAllocatePool(PagedPool,
|
||||||
|
SectorSize);
|
||||||
|
if (PartitionSector == NULL)
|
||||||
{
|
{
|
||||||
if (IsContainerPartition(PartitionBuffer->PartitionEntry[i].PartitionType))
|
return STATUS_INSUFFICIENT_RESOURCES;
|
||||||
{
|
|
||||||
/* FIXME: Implement */
|
|
||||||
DPRINT1("Writing MBRs with extended partitions is not implemented\n");
|
|
||||||
return STATUS_UNSUCCESSFUL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Status = STATUS_SUCCESS;
|
||||||
SectorOffset.QuadPart = 0ULL;
|
PartitionOffset = 0ULL;
|
||||||
Status = xHalpReadSector(DeviceObject,
|
ContainerOffset = 0ULL;
|
||||||
SectorSize,
|
for (i = 0; i < PartitionBuffer->PartitionCount; i += 4)
|
||||||
&SectorOffset,
|
|
||||||
(PVOID *) &PartitionSector);
|
|
||||||
if (!NT_SUCCESS(Status))
|
|
||||||
{
|
{
|
||||||
DPRINT1("xHalpReadSector() failed (Status %lx)\n", Status);
|
DPRINT1 ("PartitionOffset: %I64u\n", PartitionOffset);
|
||||||
return Status;
|
DPRINT1 ("ContainerOffset: %I64u\n", ContainerOffset);
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < PartitionBuffer->PartitionCount; i++)
|
/* FIXME: Handle partition managers */
|
||||||
{
|
RealPartitionOffset.QuadPart = PartitionOffset;
|
||||||
if (PartitionBuffer->PartitionEntry[i].PartitionType != PARTITION_ENTRY_UNUSED)
|
|
||||||
|
|
||||||
|
/* Write modified partition tables */
|
||||||
|
if (PartitionBuffer->PartitionEntry[i].RewritePartition == TRUE ||
|
||||||
|
PartitionBuffer->PartitionEntry[i + 1].RewritePartition == TRUE ||
|
||||||
|
PartitionBuffer->PartitionEntry[i + 2].RewritePartition == TRUE ||
|
||||||
|
PartitionBuffer->PartitionEntry[i + 3].RewritePartition == TRUE)
|
||||||
{
|
{
|
||||||
/*
|
/* Read partition sector */
|
||||||
* CHS formulas:
|
Status = xHalpReadSector2 (DeviceObject,
|
||||||
* x = LBA DIV SectorsPerTrack
|
SectorSize,
|
||||||
* cylinder = x DIV NumberOfHeads
|
&RealPartitionOffset,
|
||||||
* head = x MOD NumberOfHeads
|
PartitionSector);
|
||||||
* sector = (LBA MOD SectorsPerTrack) + 1
|
if (!NT_SUCCESS(Status))
|
||||||
*/
|
{
|
||||||
|
DPRINT1 ("xHalpReadSector2() failed (Status %lx)\n", Status);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (PartitionBuffer->PartitionEntry[i].BootIndicator)
|
/* Initialize a new partition sector */
|
||||||
{
|
if (PartitionSector->Magic != PARTITION_MAGIC)
|
||||||
PartitionSector->Partition[i].BootFlags |= 0x80;
|
{
|
||||||
}
|
/* Create empty partition sector */
|
||||||
else
|
RtlZeroMemory (PartitionSector,
|
||||||
{
|
SectorSize);
|
||||||
PartitionSector->Partition[i].BootFlags &= ~0x80;
|
PartitionSector->Magic = PARTITION_MAGIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
PartitionSector->Partition[i].PartitionType = PartitionBuffer->PartitionEntry[i].PartitionType;
|
/* Update partition sector entries */
|
||||||
|
for (j = 0; j < 4; j++)
|
||||||
|
{
|
||||||
|
if (PartitionBuffer->PartitionEntry[i + j].RewritePartition == TRUE)
|
||||||
|
{
|
||||||
|
/* Set partition boot flag */
|
||||||
|
if (PartitionBuffer->PartitionEntry[i + j].BootIndicator)
|
||||||
|
{
|
||||||
|
PartitionSector->Partition[j].BootFlags |= 0x80;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PartitionSector->Partition[j].BootFlags &= ~0x80;
|
||||||
|
}
|
||||||
|
|
||||||
/* Compute starting CHS values */
|
/* Set partition type */
|
||||||
lba = (PartitionBuffer->PartitionEntry[i].StartingOffset.QuadPart / SectorSize);
|
PartitionSector->Partition[j].PartitionType =
|
||||||
StartBlock = lba; /* Save this for later */
|
PartitionBuffer->PartitionEntry[i + j].PartitionType;
|
||||||
x = lba / SectorsPerTrack;
|
|
||||||
StartCylinder = x / NumberOfHeads;
|
|
||||||
StartHead = x % NumberOfHeads;
|
|
||||||
StartSector = (lba % SectorsPerTrack) + 1;
|
|
||||||
DPRINT("StartingOffset (LBA:%d C:%d H:%d S:%d)\n", lba, StartCylinder, StartHead, StartSector);
|
|
||||||
|
|
||||||
/* Compute ending CHS values */
|
/* Set partition data */
|
||||||
lba = (PartitionBuffer->PartitionEntry[i].StartingOffset.QuadPart
|
if (PartitionBuffer->PartitionEntry[i + j].StartingOffset.QuadPart == 0ULL &&
|
||||||
+ (PartitionBuffer->PartitionEntry[i].PartitionLength.QuadPart - 1)) / SectorSize;
|
PartitionBuffer->PartitionEntry[i + j].PartitionLength.QuadPart == 0ULL)
|
||||||
SectorCount = lba - StartBlock; /* Save this for later */
|
{
|
||||||
x = lba / SectorsPerTrack;
|
PartitionSector->Partition[j].StartingBlock = 0;
|
||||||
EndCylinder = x / NumberOfHeads;
|
PartitionSector->Partition[j].SectorCount = 0;
|
||||||
EndHead = x % NumberOfHeads;
|
PartitionSector->Partition[j].StartingCylinder = 0;
|
||||||
EndSector = (lba % SectorsPerTrack) + 1;
|
PartitionSector->Partition[j].StartingHead = 0;
|
||||||
DPRINT("EndingOffset (LBA:%d C:%d H:%d S:%d)\n", lba, EndCylinder, EndHead, EndSector);
|
PartitionSector->Partition[j].StartingSector = 0;
|
||||||
|
PartitionSector->Partition[j].EndingCylinder = 0;
|
||||||
|
PartitionSector->Partition[j].EndingHead = 0;
|
||||||
|
PartitionSector->Partition[j].EndingSector = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* CHS formulas:
|
||||||
|
* x = LBA DIV SectorsPerTrack
|
||||||
|
* cylinder = (x DIV NumberOfHeads) % 1024
|
||||||
|
* head = x MOD NumberOfHeads
|
||||||
|
* sector = (LBA MOD SectorsPerTrack) + 1
|
||||||
|
*/
|
||||||
|
|
||||||
/* Set startsector and sectorcount */
|
/* Compute starting CHS values */
|
||||||
PartitionSector->Partition[i].StartingBlock = StartBlock;
|
lba = (PartitionBuffer->PartitionEntry[i + j].StartingOffset.QuadPart) / SectorSize;
|
||||||
PartitionSector->Partition[i].SectorCount = SectorCount;
|
x = lba / SectorsPerTrack;
|
||||||
|
StartCylinder = (x / NumberOfHeads) %1024;
|
||||||
|
StartHead = x % NumberOfHeads;
|
||||||
|
StartSector = (lba % SectorsPerTrack) + 1;
|
||||||
|
DPRINT1 ("StartingOffset (LBA:%d C:%d H:%d S:%d)\n",
|
||||||
|
lba, StartCylinder, StartHead, StartSector);
|
||||||
|
|
||||||
/* Set starting CHS values */
|
/* Compute ending CHS values */
|
||||||
PartitionSector->Partition[i].StartingCylinder = StartCylinder & 0xff;
|
lba = (PartitionBuffer->PartitionEntry[i + j].StartingOffset.QuadPart +
|
||||||
PartitionSector->Partition[i].StartingHead = StartHead;
|
(PartitionBuffer->PartitionEntry[i + j].PartitionLength.QuadPart - 1)) / SectorSize;
|
||||||
PartitionSector->Partition[i].StartingSector = ((StartCylinder & 0x0300) >> 2) + (StartSector & 0x3f);
|
x = lba / SectorsPerTrack;
|
||||||
|
EndCylinder = (x / NumberOfHeads) % 1024;
|
||||||
|
EndHead = x % NumberOfHeads;
|
||||||
|
EndSector = (lba % SectorsPerTrack) + 1;
|
||||||
|
DPRINT1 ("EndingOffset (LBA:%d C:%d H:%d S:%d)\n",
|
||||||
|
lba, EndCylinder, EndHead, EndSector);
|
||||||
|
|
||||||
/* Set ending CHS values */
|
/* Set starting CHS values */
|
||||||
PartitionSector->Partition[i].EndingCylinder = EndCylinder & 0xff;
|
PartitionSector->Partition[j].StartingCylinder = StartCylinder & 0xff;
|
||||||
PartitionSector->Partition[i].EndingHead = EndHead;
|
PartitionSector->Partition[j].StartingHead = StartHead;
|
||||||
PartitionSector->Partition[i].EndingSector = ((EndCylinder & 0x0300) >> 2) + (EndSector & 0x3f);
|
PartitionSector->Partition[j].StartingSector =
|
||||||
|
((StartCylinder & 0x0300) >> 2) + (StartSector & 0x3f);
|
||||||
|
|
||||||
|
/* Set ending CHS values */
|
||||||
|
PartitionSector->Partition[j].EndingCylinder = EndCylinder & 0xff;
|
||||||
|
PartitionSector->Partition[j].EndingHead = EndHead;
|
||||||
|
PartitionSector->Partition[j].EndingSector =
|
||||||
|
((EndCylinder & 0x0300) >> 2) + (EndSector & 0x3f);
|
||||||
|
|
||||||
|
/* Calculate start sector and sector count */
|
||||||
|
StartBlock =
|
||||||
|
(PartitionBuffer->PartitionEntry[i + j].StartingOffset.QuadPart - ContainerOffset) / SectorSize;
|
||||||
|
SectorCount =
|
||||||
|
PartitionBuffer->PartitionEntry[i + j].PartitionLength.QuadPart / SectorSize;
|
||||||
|
DPRINT1 ("LBA (StartBlock:%lu SectorCount:%lu)\n",
|
||||||
|
StartBlock, SectorCount);
|
||||||
|
|
||||||
|
/* Set start sector and sector count */
|
||||||
|
PartitionSector->Partition[j].StartingBlock = StartBlock;
|
||||||
|
PartitionSector->Partition[j].SectorCount = SectorCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Write partition sector */
|
||||||
|
Status = xHalpWriteSector (DeviceObject,
|
||||||
|
SectorSize,
|
||||||
|
&RealPartitionOffset,
|
||||||
|
PartitionSector);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
DPRINT1("xHalpWriteSector() failed (Status %lx)\n", Status);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
ContainerEntry = FALSE;
|
||||||
|
for (j = 0; j < 4; j++)
|
||||||
{
|
{
|
||||||
PartitionSector->Partition[i].BootFlags = 0;
|
if (IsContainerPartition (PartitionBuffer->PartitionEntry[i + j].PartitionType))
|
||||||
PartitionSector->Partition[i].PartitionType = PARTITION_ENTRY_UNUSED;
|
{
|
||||||
PartitionSector->Partition[i].StartingHead = 0;
|
ContainerEntry = TRUE;
|
||||||
PartitionSector->Partition[i].StartingSector = 0;
|
NextPartitionOffset =
|
||||||
PartitionSector->Partition[i].StartingCylinder = 0;
|
PartitionBuffer->PartitionEntry[i + j].StartingOffset.QuadPart;
|
||||||
PartitionSector->Partition[i].EndingHead = 0;
|
|
||||||
PartitionSector->Partition[i].EndingSector = 0;
|
if (ContainerOffset == 0ULL)
|
||||||
PartitionSector->Partition[i].EndingCylinder = 0;
|
{
|
||||||
PartitionSector->Partition[i].StartingBlock = 0;
|
ContainerOffset = NextPartitionOffset;
|
||||||
PartitionSector->Partition[i].SectorCount = 0;
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ContainerEntry == FALSE)
|
||||||
|
{
|
||||||
|
DPRINT ("No container entry in partition sector!\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
PartitionOffset = NextPartitionOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ExFreePool (PartitionSector);
|
||||||
|
|
||||||
SectorOffset.QuadPart = 0ULL;
|
return Status;
|
||||||
Status = xHalpWriteSector(DeviceObject,
|
|
||||||
SectorSize,
|
|
||||||
&SectorOffset,
|
|
||||||
(PVOID) PartitionSector);
|
|
||||||
if (!NT_SUCCESS(Status))
|
|
||||||
{
|
|
||||||
DPRINT1("xHalpWriteSector() failed (Status %lx)\n", Status);
|
|
||||||
ExFreePool(PartitionSector);
|
|
||||||
return Status;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef NDEBUG
|
|
||||||
for (i = 0; i < PARTITION_TBL_SIZE; i++)
|
|
||||||
{
|
|
||||||
DPRINT1(" %d: flags:%2x type:%x start:%d:%d:%d end:%d:%d:%d stblk:%d count:%d\n",
|
|
||||||
i,
|
|
||||||
PartitionSector->Partition[i].BootFlags,
|
|
||||||
PartitionSector->Partition[i].PartitionType,
|
|
||||||
PartitionSector->Partition[i].StartingHead,
|
|
||||||
PartitionSector->Partition[i].StartingSector & 0x3f,
|
|
||||||
(((PartitionSector->Partition[i].StartingSector) & 0xc0) << 2) +
|
|
||||||
PartitionSector->Partition[i].StartingCylinder,
|
|
||||||
PartitionSector->Partition[i].EndingHead,
|
|
||||||
PartitionSector->Partition[i].EndingSector & 0x3f,
|
|
||||||
(((PartitionSector->Partition[i].EndingSector) & 0xc0) << 2) +
|
|
||||||
PartitionSector->Partition[i].EndingCylinder,
|
|
||||||
PartitionSector->Partition[i].StartingBlock,
|
|
||||||
PartitionSector->Partition[i].SectorCount);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ExFreePool(PartitionSector);
|
|
||||||
|
|
||||||
return(STATUS_SUCCESS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
Loading…
Reference in a new issue