3 * Copyright (C) 2002, 2003, 2004, 2005 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 /* COPYRIGHT: See COPYING in the top level directory
20 * PROJECT: ReactOS text-mode setup
21 * FILE: subsys/system/usetup/partlist.c
22 * PURPOSE: Partition list functions
23 * PROGRAMMER: Eric Kohl
24 * Casper S. Hornstrup (chorns@users.sourceforge.net)
34 //#define DUMP_PARTITION_TABLE
36 /* FUNCTIONS ****************************************************************/
38 #ifdef DUMP_PARTITION_TABLE
44 PPARTITION_INFORMATION PartitionInfo
;
47 for (i
= 0; i
< DiskEntry
->LayoutBuffer
->PartitionCount
; i
++)
49 PartitionInfo
= &DiskEntry
->LayoutBuffer
->PartitionEntry
[i
];
50 DPRINT1("\n%lu: %12I64u %12I64u %10lu %2lu %2x %c %c\n",
52 PartitionInfo
->StartingOffset
.QuadPart
,
53 PartitionInfo
->PartitionLength
.QuadPart
,
54 PartitionInfo
->HiddenSectors
,
55 PartitionInfo
->PartitionNumber
,
56 PartitionInfo
->PartitionType
,
57 PartitionInfo
->BootIndicator
? '*': ' ',
58 PartitionInfo
->RewritePartition
? 'Y': 'N');
71 Temp
= Value
/ Alignment
;
73 return Temp
* Alignment
;
79 IN ULONGLONG Dividend
,
82 return (Dividend
+ Divisor
/ 2) / Divisor
;
91 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
95 RtlInitUnicodeString(&DiskEntry
->DriverName
,
99 L
"\\Scsi\\Scsi Port %lu",
102 RtlZeroMemory(&QueryTable
,
105 QueryTable
[0].Name
= L
"Driver";
106 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_DIRECT
;
107 QueryTable
[0].EntryContext
= &DiskEntry
->DriverName
;
109 Status
= RtlQueryRegistryValues(RTL_REGISTRY_DEVICEMAP
,
114 if (!NT_SUCCESS(Status
))
116 DPRINT1("RtlQueryRegistryValues() failed (Status %lx)\n", Status
);
126 PDISKENTRY DiskEntry
;
127 PPARTENTRY PartEntry
;
134 /* Assign drive letters to primary partitions */
135 Entry1
= List
->DiskListHead
.Flink
;
136 while (Entry1
!= &List
->DiskListHead
)
138 DiskEntry
= CONTAINING_RECORD(Entry1
, DISKENTRY
, ListEntry
);
140 Entry2
= DiskEntry
->PrimaryPartListHead
.Flink
;
141 while (Entry2
!= &DiskEntry
->PrimaryPartListHead
)
143 PartEntry
= CONTAINING_RECORD(Entry2
, PARTENTRY
, ListEntry
);
145 PartEntry
->DriveLetter
= 0;
147 if (PartEntry
->IsPartitioned
&&
148 !IsContainerPartition(PartEntry
->PartitionType
))
150 if (IsRecognizedPartition(PartEntry
->PartitionType
) ||
151 (PartEntry
->PartitionType
== PARTITION_ENTRY_UNUSED
&&
152 PartEntry
->SectorCount
.QuadPart
!= 0LL))
156 PartEntry
->DriveLetter
= Letter
;
162 Entry2
= Entry2
->Flink
;
165 Entry1
= Entry1
->Flink
;
168 /* Assign drive letters to logical drives */
170 Entry1
= List
->DiskListHead
.Flink
;
171 while (Entry1
!= &List
->DiskListHead
)
173 DiskEntry
= CONTAINING_RECORD(Entry1
, DISKENTRY
, ListEntry
);
175 Entry2
= DiskEntry
->PartListHead
.Flink
;
176 if (Entry2
!= &DiskEntry
->PartListHead
)
178 Entry2
= Entry2
->Flink
;
179 while (Entry2
!= &DiskEntry
->PartListHead
)
181 PartEntry
= CONTAINING_RECORD(Entry2
,
185 PartEntry
->DriveLetter
= 0;
187 if (PartEntry
->Unpartitioned
== FALSE
&&
188 !IsContainerPartition(PartEntry
->PartInfo
[0].PartitionType
))
190 if (IsRecognizedPartition(PartEntry
->PartInfo
[0].PartitionType
) ||
191 (PartEntry
->PartInfo
[0].PartitionType
== PARTITION_ENTRY_UNUSED
&&
192 PartEntry
->PartInfo
[0].PartitionLength
.QuadPart
!= 0LL))
196 PartEntry
->DriveLetter
= Letter
;
202 Entry2
= Entry2
->Flink
;
206 Entry1
= Entry1
->Flink
;
214 UpdatePartitionNumbers(
215 PDISKENTRY DiskEntry
)
217 PPARTENTRY PartEntry
;
219 // ULONG PartitionNumber = 1;
220 ULONG PartitionIndex
= 0;
222 Entry
= DiskEntry
->PrimaryPartListHead
.Flink
;
223 while (Entry
!= &DiskEntry
->PrimaryPartListHead
)
225 PartEntry
= CONTAINING_RECORD(Entry
,
229 if (PartEntry
->IsPartitioned
== FALSE
)
231 // PartEntry->PartitionNumber = 0;
232 PartEntry
->PartitionIndex
= (ULONG
)-1;
236 if (IsContainerPartition(PartEntry
->PartitionType
))
238 // PartEntry->PartitionNumber = 0;
240 else if (PartEntry
->PartitionType
== PARTITION_ENTRY_UNUSED
&&
241 PartEntry
->SectorCount
.QuadPart
== 0ULL)
243 // PartEntry->PartitionNumber = 0;
247 // PartEntry->PartitionNumber = PartitionNumber++;
250 PartEntry
->PartitionIndex
= PartitionIndex
++;
253 Entry
= Entry
->Flink
;
260 DiskIdentifierQueryRoutine(
268 PBIOSDISKENTRY BiosDiskEntry
= (PBIOSDISKENTRY
)Context
;
269 UNICODE_STRING NameU
;
271 if (ValueType
== REG_SZ
&&
272 ValueLength
== 20 * sizeof(WCHAR
))
274 NameU
.Buffer
= (PWCHAR
)ValueData
;
275 NameU
.Length
= NameU
.MaximumLength
= 8 * sizeof(WCHAR
);
276 RtlUnicodeStringToInteger(&NameU
, 16, &BiosDiskEntry
->Checksum
);
278 NameU
.Buffer
= (PWCHAR
)ValueData
+ 9;
279 RtlUnicodeStringToInteger(&NameU
, 16, &BiosDiskEntry
->Signature
);
281 return STATUS_SUCCESS
;
284 return STATUS_UNSUCCESSFUL
;
290 DiskConfigurationDataQueryRoutine(
298 PBIOSDISKENTRY BiosDiskEntry
= (PBIOSDISKENTRY
)Context
;
299 PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor
;
300 PCM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry
;
303 if (ValueType
!= REG_FULL_RESOURCE_DESCRIPTOR
||
304 ValueLength
< sizeof(CM_FULL_RESOURCE_DESCRIPTOR
))
305 return STATUS_UNSUCCESSFUL
;
307 FullResourceDescriptor
= (PCM_FULL_RESOURCE_DESCRIPTOR
)ValueData
;
309 /* Hm. Version and Revision are not set on Microsoft Windows XP... */
311 if (FullResourceDescriptor
->PartialResourceList
.Version
!= 1 ||
312 FullResourceDescriptor
->PartialResourceList
.Revision
!= 1)
313 return STATUS_UNSUCCESSFUL
;
316 for (i
= 0; i
< FullResourceDescriptor
->PartialResourceList
.Count
; i
++)
318 if (FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[i
].Type
!= CmResourceTypeDeviceSpecific
||
319 FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[i
].u
.DeviceSpecificData
.DataSize
!= sizeof(CM_DISK_GEOMETRY_DEVICE_DATA
))
322 DiskGeometry
= (PCM_DISK_GEOMETRY_DEVICE_DATA
)&FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[i
+ 1];
323 BiosDiskEntry
->DiskGeometry
= *DiskGeometry
;
325 return STATUS_SUCCESS
;
328 return STATUS_UNSUCCESSFUL
;
334 SystemConfigurationDataQueryRoutine(
342 PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor
;
343 PCM_INT13_DRIVE_PARAMETER
* Int13Drives
= (PCM_INT13_DRIVE_PARAMETER
*)Context
;
346 if (ValueType
!= REG_FULL_RESOURCE_DESCRIPTOR
||
347 ValueLength
< sizeof (CM_FULL_RESOURCE_DESCRIPTOR
))
348 return STATUS_UNSUCCESSFUL
;
350 FullResourceDescriptor
= (PCM_FULL_RESOURCE_DESCRIPTOR
)ValueData
;
352 /* Hm. Version and Revision are not set on Microsoft Windows XP... */
354 if (FullResourceDescriptor
->PartialResourceList
.Version
!= 1 ||
355 FullResourceDescriptor
->PartialResourceList
.Revision
!= 1)
356 return STATUS_UNSUCCESSFUL
;
359 for (i
= 0; i
< FullResourceDescriptor
->PartialResourceList
.Count
; i
++)
361 if (FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[i
].Type
!= CmResourceTypeDeviceSpecific
||
362 FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[i
].u
.DeviceSpecificData
.DataSize
% sizeof(CM_INT13_DRIVE_PARAMETER
) != 0)
365 *Int13Drives
= (CM_INT13_DRIVE_PARAMETER
*) RtlAllocateHeap(ProcessHeap
, 0, FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[i
].u
.DeviceSpecificData
.DataSize
);
366 if (*Int13Drives
== NULL
)
367 return STATUS_NO_MEMORY
;
370 &FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[i
+ 1],
371 FullResourceDescriptor
->PartialResourceList
.PartialDescriptors
[i
].u
.DeviceSpecificData
.DataSize
);
372 return STATUS_SUCCESS
;
375 return STATUS_UNSUCCESSFUL
;
379 #define ROOT_NAME L"\\Registry\\Machine\\HARDWARE\\DESCRIPTION\\System\\MultifunctionAdapter"
382 EnumerateBiosDiskEntries(
385 RTL_QUERY_REGISTRY_TABLE QueryTable
[3];
390 PCM_INT13_DRIVE_PARAMETER Int13Drives
;
391 PBIOSDISKENTRY BiosDiskEntry
;
393 memset(QueryTable
, 0, sizeof(QueryTable
));
395 QueryTable
[1].Name
= L
"Configuration Data";
396 QueryTable
[1].QueryRoutine
= SystemConfigurationDataQueryRoutine
;
398 Status
= RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE
,
399 L
"\\Registry\\Machine\\HARDWARE\\DESCRIPTION\\System",
403 if (!NT_SUCCESS(Status
))
405 DPRINT1("Unable to query the 'Configuration Data' key in '\\Registry\\Machine\\HARDWARE\\DESCRIPTION\\System', status=%lx\n", Status
);
412 swprintf(Name
, L
"%s\\%lu", ROOT_NAME
, AdapterCount
);
413 Status
= RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE
,
418 if (!NT_SUCCESS(Status
))
423 swprintf(Name
, L
"%s\\%lu\\DiskController", ROOT_NAME
, AdapterCount
);
424 Status
= RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE
,
429 if (NT_SUCCESS(Status
))
433 swprintf(Name
, L
"%s\\%lu\\DiskController\\0", ROOT_NAME
, AdapterCount
);
434 Status
= RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE
,
439 if (!NT_SUCCESS(Status
))
441 RtlFreeHeap(ProcessHeap
, 0, Int13Drives
);
445 swprintf(Name
, L
"%s\\%lu\\DiskController\\0\\DiskPeripheral", ROOT_NAME
, AdapterCount
);
446 Status
= RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE
,
451 if (NT_SUCCESS(Status
))
453 QueryTable
[0].Name
= L
"Identifier";
454 QueryTable
[0].QueryRoutine
= DiskIdentifierQueryRoutine
;
455 QueryTable
[1].Name
= L
"Configuration Data";
456 QueryTable
[1].QueryRoutine
= DiskConfigurationDataQueryRoutine
;
461 BiosDiskEntry
= (BIOSDISKENTRY
*) RtlAllocateHeap(ProcessHeap
, HEAP_ZERO_MEMORY
, sizeof(BIOSDISKENTRY
));
462 if (BiosDiskEntry
== NULL
)
467 swprintf(Name
, L
"%s\\%lu\\DiskController\\0\\DiskPeripheral\\%lu", ROOT_NAME
, AdapterCount
, DiskCount
);
468 Status
= RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE
,
471 (PVOID
)BiosDiskEntry
,
473 if (!NT_SUCCESS(Status
))
475 RtlFreeHeap(ProcessHeap
, 0, BiosDiskEntry
);
479 BiosDiskEntry
->DiskNumber
= DiskCount
;
480 BiosDiskEntry
->Recognized
= FALSE
;
482 if (DiskCount
< Int13Drives
[0].NumberDrives
)
484 BiosDiskEntry
->Int13DiskData
= Int13Drives
[DiskCount
];
488 DPRINT1("Didn't find int13 drive datas for disk %u\n", DiskCount
);
491 InsertTailList(&PartList
->BiosDiskListHead
, &BiosDiskEntry
->ListEntry
);
493 DPRINT("DiskNumber: %lu\n", BiosDiskEntry
->DiskNumber
);
494 DPRINT("Signature: %08lx\n", BiosDiskEntry
->Signature
);
495 DPRINT("Checksum: %08lx\n", BiosDiskEntry
->Checksum
);
496 DPRINT("BytesPerSector: %lu\n", BiosDiskEntry
->DiskGeometry
.BytesPerSector
);
497 DPRINT("NumberOfCylinders: %lu\n", BiosDiskEntry
->DiskGeometry
.NumberOfCylinders
);
498 DPRINT("NumberOfHeads: %lu\n", BiosDiskEntry
->DiskGeometry
.NumberOfHeads
);
499 DPRINT("DriveSelect: %02x\n", BiosDiskEntry
->Int13DiskData
.DriveSelect
);
500 DPRINT("MaxCylinders: %lu\n", BiosDiskEntry
->Int13DiskData
.MaxCylinders
);
501 DPRINT("SectorsPerTrack: %d\n", BiosDiskEntry
->Int13DiskData
.SectorsPerTrack
);
502 DPRINT("MaxHeads: %d\n", BiosDiskEntry
->Int13DiskData
.MaxHeads
);
503 DPRINT("NumberDrives: %d\n", BiosDiskEntry
->Int13DiskData
.NumberDrives
);
509 RtlFreeHeap(ProcessHeap
, 0, Int13Drives
);
517 RtlFreeHeap(ProcessHeap
, 0, Int13Drives
);
525 PDISKENTRY DiskEntry
,
526 ULONG PartitionIndex
,
527 BOOLEAN LogicalPartition
)
529 PPARTITION_INFORMATION PartitionInfo
;
530 PPARTENTRY PartEntry
;
532 PartitionInfo
= &DiskEntry
->LayoutBuffer
->PartitionEntry
[PartitionIndex
];
533 if (PartitionInfo
->PartitionType
== 0 ||
534 (LogicalPartition
== TRUE
&& IsContainerPartition(PartitionInfo
->PartitionType
)))
537 PartEntry
= RtlAllocateHeap(ProcessHeap
,
540 if (PartEntry
== NULL
)
545 PartEntry
->DiskEntry
= DiskEntry
;
547 PartEntry
->StartSector
.QuadPart
= (ULONGLONG
)PartitionInfo
->StartingOffset
.QuadPart
/ DiskEntry
->BytesPerSector
;
548 PartEntry
->SectorCount
.QuadPart
= (ULONGLONG
)PartitionInfo
->PartitionLength
.QuadPart
/ DiskEntry
->BytesPerSector
;
550 PartEntry
->BootIndicator
= PartitionInfo
->BootIndicator
;
551 PartEntry
->PartitionType
= PartitionInfo
->PartitionType
;
552 PartEntry
->HiddenSectors
= PartitionInfo
->HiddenSectors
;
554 PartEntry
->LogicalPartition
= LogicalPartition
;
555 PartEntry
->IsPartitioned
= TRUE
;
556 PartEntry
->PartitionNumber
= PartitionInfo
->PartitionNumber
;
557 PartEntry
->PartitionIndex
= PartitionIndex
;
559 if (IsContainerPartition(PartEntry
->PartitionType
))
561 PartEntry
->FormatState
= Unformatted
;
563 if (LogicalPartition
== FALSE
&& DiskEntry
->ExtendedPartition
== NULL
)
564 DiskEntry
->ExtendedPartition
= PartEntry
;
566 else if ((PartEntry
->PartitionType
== PARTITION_FAT_12
) ||
567 (PartEntry
->PartitionType
== PARTITION_FAT_16
) ||
568 (PartEntry
->PartitionType
== PARTITION_HUGE
) ||
569 (PartEntry
->PartitionType
== PARTITION_XINT13
) ||
570 (PartEntry
->PartitionType
== PARTITION_FAT32
) ||
571 (PartEntry
->PartitionType
== PARTITION_FAT32_XINT13
))
574 if (CheckFatFormat())
576 PartEntry
->FormatState
= Preformatted
;
580 PartEntry
->FormatState
= Unformatted
;
583 PartEntry
->FormatState
= Preformatted
;
585 else if (PartEntry
->PartitionType
== PARTITION_EXT2
)
588 if (CheckExt2Format())
590 PartEntry
->FormatState
= Preformatted
;
594 PartEntry
->FormatState
= Unformatted
;
597 PartEntry
->FormatState
= Preformatted
;
599 else if (PartEntry
->PartitionType
== PARTITION_IFS
)
602 if (CheckNtfsFormat())
604 PartEntry
->FormatState
= Preformatted
;
606 else if (CheckHpfsFormat())
608 PartEntry
->FormatState
= Preformatted
;
612 PartEntry
->FormatState
= Unformatted
;
615 PartEntry
->FormatState
= Preformatted
;
619 PartEntry
->FormatState
= UnknownFormat
;
622 if (LogicalPartition
)
623 InsertTailList(&DiskEntry
->LogicalPartListHead
,
624 &PartEntry
->ListEntry
);
626 InsertTailList(&DiskEntry
->PrimaryPartListHead
,
627 &PartEntry
->ListEntry
);
633 ScanForUnpartitionedDiskSpace(
634 PDISKENTRY DiskEntry
)
636 ULONGLONG LastStartSector
;
637 ULONGLONG LastSectorCount
;
638 ULONGLONG LastUnusedSectorCount
;
639 PPARTENTRY PartEntry
;
640 PPARTENTRY NewPartEntry
;
643 DPRINT("ScanForUnpartitionedDiskSpace()\n");
645 if (IsListEmpty(&DiskEntry
->PrimaryPartListHead
))
647 DPRINT1("No primary partition!\n");
649 /* Create a partition table that represents the empty disk */
650 NewPartEntry
= RtlAllocateHeap(ProcessHeap
,
653 if (NewPartEntry
== NULL
)
656 NewPartEntry
->DiskEntry
= DiskEntry
;
658 NewPartEntry
->IsPartitioned
= FALSE
;
659 NewPartEntry
->StartSector
.QuadPart
= (ULONGLONG
)DiskEntry
->SectorAlignment
;
660 NewPartEntry
->SectorCount
.QuadPart
= Align(DiskEntry
->SectorCount
.QuadPart
, DiskEntry
->SectorAlignment
) -
661 NewPartEntry
->StartSector
.QuadPart
;
663 DPRINT1("First Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
);
664 DPRINT1("Last Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
+ NewPartEntry
->SectorCount
.QuadPart
- 1);
665 DPRINT1("Total Sectors: %I64u\n", NewPartEntry
->SectorCount
.QuadPart
);
667 NewPartEntry
->FormatState
= Unformatted
;
669 InsertTailList(&DiskEntry
->PrimaryPartListHead
,
670 &NewPartEntry
->ListEntry
);
675 /* Start partition at head 1, cylinder 0 */
676 LastStartSector
= DiskEntry
->SectorAlignment
;
677 LastSectorCount
= 0ULL;
678 LastUnusedSectorCount
= 0ULL;
680 Entry
= DiskEntry
->PrimaryPartListHead
.Flink
;
681 while (Entry
!= &DiskEntry
->PrimaryPartListHead
)
683 PartEntry
= CONTAINING_RECORD(Entry
, PARTENTRY
, ListEntry
);
685 if (PartEntry
->PartitionType
!= PARTITION_ENTRY_UNUSED
||
686 PartEntry
->SectorCount
.QuadPart
!= 0ULL)
688 LastUnusedSectorCount
=
689 PartEntry
->StartSector
.QuadPart
- (LastStartSector
+ LastSectorCount
);
691 if (PartEntry
->StartSector
.QuadPart
> (LastStartSector
+ LastSectorCount
) &&
692 LastUnusedSectorCount
>= (ULONGLONG
)DiskEntry
->SectorAlignment
)
694 DPRINT("Unpartitioned disk space %I64u sectors\n", LastUnusedSectorCount
);
696 NewPartEntry
= RtlAllocateHeap(ProcessHeap
,
699 if (NewPartEntry
== NULL
)
702 NewPartEntry
->DiskEntry
= DiskEntry
;
704 NewPartEntry
->IsPartitioned
= FALSE
;
705 NewPartEntry
->StartSector
.QuadPart
= LastStartSector
+ LastSectorCount
;
706 NewPartEntry
->SectorCount
.QuadPart
= Align(NewPartEntry
->StartSector
.QuadPart
+ LastUnusedSectorCount
, DiskEntry
->SectorAlignment
) -
707 NewPartEntry
->StartSector
.QuadPart
;
709 DPRINT1("First Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
);
710 DPRINT1("Last Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
+ NewPartEntry
->SectorCount
.QuadPart
- 1);
711 DPRINT1("Total Sectors: %I64u\n", NewPartEntry
->SectorCount
.QuadPart
);
713 NewPartEntry
->FormatState
= Unformatted
;
715 /* Insert the table into the list */
716 InsertTailList(&PartEntry
->ListEntry
,
717 &NewPartEntry
->ListEntry
);
720 LastStartSector
= PartEntry
->StartSector
.QuadPart
;
721 LastSectorCount
= PartEntry
->SectorCount
.QuadPart
;
724 Entry
= Entry
->Flink
;
727 /* Check for trailing unpartitioned disk space */
728 if ((LastStartSector
+ LastSectorCount
) < DiskEntry
->SectorCount
.QuadPart
)
730 LastUnusedSectorCount
= Align(DiskEntry
->SectorCount
.QuadPart
- (LastStartSector
+ LastSectorCount
), DiskEntry
->SectorAlignment
);
732 if (LastUnusedSectorCount
>= (ULONGLONG
)DiskEntry
->SectorAlignment
)
734 DPRINT("Unpartitioned disk space: %I64u sectors\n", LastUnusedSectorCount
);
736 NewPartEntry
= RtlAllocateHeap(ProcessHeap
,
739 if (NewPartEntry
== NULL
)
742 NewPartEntry
->DiskEntry
= DiskEntry
;
744 NewPartEntry
->IsPartitioned
= FALSE
;
745 NewPartEntry
->StartSector
.QuadPart
= LastStartSector
+ LastSectorCount
;
746 NewPartEntry
->SectorCount
.QuadPart
= Align(NewPartEntry
->StartSector
.QuadPart
+ LastUnusedSectorCount
, DiskEntry
->SectorAlignment
) -
747 NewPartEntry
->StartSector
.QuadPart
;
749 DPRINT("First Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
);
750 DPRINT("Last Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
+ NewPartEntry
->SectorCount
.QuadPart
- 1);
751 DPRINT("Total Sectors: %I64u\n", NewPartEntry
->SectorCount
.QuadPart
);
753 NewPartEntry
->FormatState
= Unformatted
;
755 /* Append the table to the list */
756 InsertTailList(&DiskEntry
->PrimaryPartListHead
,
757 &NewPartEntry
->ListEntry
);
761 if (DiskEntry
->ExtendedPartition
!= NULL
)
763 if (IsListEmpty(&DiskEntry
->LogicalPartListHead
))
765 DPRINT1("No logical partition!\n");
767 /* Create a partition table entry that represents the empty extended partition */
768 NewPartEntry
= RtlAllocateHeap(ProcessHeap
,
771 if (NewPartEntry
== NULL
)
774 NewPartEntry
->DiskEntry
= DiskEntry
;
775 NewPartEntry
->LogicalPartition
= TRUE
;
777 NewPartEntry
->IsPartitioned
= FALSE
;
778 NewPartEntry
->StartSector
.QuadPart
= DiskEntry
->ExtendedPartition
->StartSector
.QuadPart
+ (ULONGLONG
)DiskEntry
->SectorAlignment
;
779 NewPartEntry
->SectorCount
.QuadPart
= DiskEntry
->ExtendedPartition
->SectorCount
.QuadPart
- (ULONGLONG
)DiskEntry
->SectorAlignment
;
781 DPRINT1("First Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
);
782 DPRINT1("Last Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
+ NewPartEntry
->SectorCount
.QuadPart
- 1);
783 DPRINT1("Total Sectors: %I64u\n", NewPartEntry
->SectorCount
.QuadPart
);
785 NewPartEntry
->FormatState
= Unformatted
;
787 InsertTailList(&DiskEntry
->LogicalPartListHead
,
788 &NewPartEntry
->ListEntry
);
793 /* Start partition at head 1, cylinder 0 */
794 LastStartSector
= DiskEntry
->ExtendedPartition
->StartSector
.QuadPart
+ (ULONGLONG
)DiskEntry
->SectorAlignment
;
795 LastSectorCount
= 0ULL;
796 LastUnusedSectorCount
= 0ULL;
798 Entry
= DiskEntry
->LogicalPartListHead
.Flink
;
799 while (Entry
!= &DiskEntry
->LogicalPartListHead
)
801 PartEntry
= CONTAINING_RECORD(Entry
, PARTENTRY
, ListEntry
);
803 if (PartEntry
->PartitionType
!= PARTITION_ENTRY_UNUSED
||
804 PartEntry
->SectorCount
.QuadPart
!= 0ULL)
806 LastUnusedSectorCount
=
807 PartEntry
->StartSector
.QuadPart
- (ULONGLONG
)DiskEntry
->SectorAlignment
- (LastStartSector
+ LastSectorCount
);
809 if ((PartEntry
->StartSector
.QuadPart
- (ULONGLONG
)DiskEntry
->SectorAlignment
) > (LastStartSector
+ LastSectorCount
) &&
810 LastUnusedSectorCount
>= (ULONGLONG
)DiskEntry
->SectorAlignment
)
812 DPRINT("Unpartitioned disk space %I64u sectors\n", LastUnusedSectorCount
);
814 NewPartEntry
= RtlAllocateHeap(ProcessHeap
,
817 if (NewPartEntry
== NULL
)
820 NewPartEntry
->DiskEntry
= DiskEntry
;
821 NewPartEntry
->LogicalPartition
= TRUE
;
823 NewPartEntry
->IsPartitioned
= FALSE
;
824 NewPartEntry
->StartSector
.QuadPart
= LastStartSector
+ LastSectorCount
;
825 NewPartEntry
->SectorCount
.QuadPart
= Align(NewPartEntry
->StartSector
.QuadPart
+ LastUnusedSectorCount
, DiskEntry
->SectorAlignment
) -
826 NewPartEntry
->StartSector
.QuadPart
;
828 DPRINT("First Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
);
829 DPRINT("Last Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
+ NewPartEntry
->SectorCount
.QuadPart
- 1);
830 DPRINT("Total Sectors: %I64u\n", NewPartEntry
->SectorCount
.QuadPart
);
832 NewPartEntry
->FormatState
= Unformatted
;
834 /* Insert the table into the list */
835 InsertTailList(&PartEntry
->ListEntry
,
836 &NewPartEntry
->ListEntry
);
839 LastStartSector
= PartEntry
->StartSector
.QuadPart
;
840 LastSectorCount
= PartEntry
->SectorCount
.QuadPart
;
843 Entry
= Entry
->Flink
;
846 /* Check for trailing unpartitioned disk space */
847 if ((LastStartSector
+ LastSectorCount
) < DiskEntry
->ExtendedPartition
->StartSector
.QuadPart
+ DiskEntry
->ExtendedPartition
->SectorCount
.QuadPart
)
849 LastUnusedSectorCount
= Align(DiskEntry
->ExtendedPartition
->StartSector
.QuadPart
+ DiskEntry
->ExtendedPartition
->SectorCount
.QuadPart
- (LastStartSector
+ LastSectorCount
), DiskEntry
->SectorAlignment
);
851 if (LastUnusedSectorCount
>= (ULONGLONG
)DiskEntry
->SectorAlignment
)
853 DPRINT("Unpartitioned disk space: %I64u sectors\n", LastUnusedSectorCount
);
855 NewPartEntry
= RtlAllocateHeap(ProcessHeap
,
858 if (NewPartEntry
== NULL
)
861 NewPartEntry
->DiskEntry
= DiskEntry
;
862 NewPartEntry
->LogicalPartition
= TRUE
;
864 NewPartEntry
->IsPartitioned
= FALSE
;
865 NewPartEntry
->StartSector
.QuadPart
= LastStartSector
+ LastSectorCount
;
866 NewPartEntry
->SectorCount
.QuadPart
= Align(NewPartEntry
->StartSector
.QuadPart
+ LastUnusedSectorCount
, DiskEntry
->SectorAlignment
) -
867 NewPartEntry
->StartSector
.QuadPart
;
869 DPRINT("First Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
);
870 DPRINT("Last Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
+ NewPartEntry
->SectorCount
.QuadPart
- 1);
871 DPRINT("Total Sectors: %I64u\n", NewPartEntry
->SectorCount
.QuadPart
);
873 NewPartEntry
->FormatState
= Unformatted
;
875 /* Append the table to the list */
876 InsertTailList(&DiskEntry
->LogicalPartListHead
,
877 &NewPartEntry
->ListEntry
);
882 DPRINT("ScanForUnpartitionedDiskSpace() done\n");
890 IN PDISKENTRY DiskEntry
)
892 LARGE_INTEGER SystemTime
;
893 TIME_FIELDS TimeFields
;
895 PDISKENTRY DiskEntry2
;
898 Buffer
= (PUCHAR
)&DiskEntry
->LayoutBuffer
->Signature
;
902 NtQuerySystemTime(&SystemTime
);
903 RtlTimeToTimeFields(&SystemTime
, &TimeFields
);
905 Buffer
[0] = (UCHAR
)(TimeFields
.Year
& 0xFF) + (UCHAR
)(TimeFields
.Hour
& 0xFF);
906 Buffer
[1] = (UCHAR
)(TimeFields
.Year
>> 8) + (UCHAR
)(TimeFields
.Minute
& 0xFF);
907 Buffer
[2] = (UCHAR
)(TimeFields
.Month
& 0xFF) + (UCHAR
)(TimeFields
.Second
& 0xFF);
908 Buffer
[3] = (UCHAR
)(TimeFields
.Day
& 0xFF) + (UCHAR
)(TimeFields
.Milliseconds
& 0xFF);
910 if (DiskEntry
->LayoutBuffer
->Signature
== 0)
915 /* check if the signature already exist */
917 * Check also signatures from disks, which are
918 * not visible (bootable) by the bios.
920 Entry2
= List
->DiskListHead
.Flink
;
921 while (Entry2
!= &List
->DiskListHead
)
923 DiskEntry2
= CONTAINING_RECORD(Entry2
, DISKENTRY
, ListEntry
);
925 if (DiskEntry
!= DiskEntry2
&&
926 DiskEntry
->LayoutBuffer
->Signature
== DiskEntry2
->LayoutBuffer
->Signature
)
929 Entry2
= Entry2
->Flink
;
932 if (Entry2
== &List
->DiskListHead
)
940 UpdateDiskSignatures(
944 PDISKENTRY DiskEntry
;
946 /* Print partition lines*/
947 Entry
= List
->DiskListHead
.Flink
;
948 while (Entry
!= &List
->DiskListHead
)
950 DiskEntry
= CONTAINING_RECORD(Entry
, DISKENTRY
, ListEntry
);
952 if (DiskEntry
->LayoutBuffer
&&
953 DiskEntry
->LayoutBuffer
->Signature
== 0)
955 SetDiskSignature(List
, DiskEntry
);
956 DiskEntry
->LayoutBuffer
->PartitionEntry
[0].RewritePartition
= TRUE
;
959 Entry
= Entry
->Flink
;
971 DISK_GEOMETRY DiskGeometry
;
972 SCSI_ADDRESS ScsiAddress
;
973 PDISKENTRY DiskEntry
;
974 IO_STATUS_BLOCK Iosb
;
976 PPARTITION_SECTOR Mbr
;
978 LARGE_INTEGER FileOffset
;
979 WCHAR Identifier
[20];
983 PLIST_ENTRY ListEntry
;
984 PBIOSDISKENTRY BiosDiskEntry
;
985 ULONG LayoutBufferSize
;
987 Status
= NtDeviceIoControlFile(FileHandle
,
992 IOCTL_DISK_GET_DRIVE_GEOMETRY
,
996 sizeof(DISK_GEOMETRY
));
997 if (!NT_SUCCESS(Status
))
1002 if (DiskGeometry
.MediaType
!= FixedMedia
&&
1003 DiskGeometry
.MediaType
!= RemovableMedia
)
1008 Status
= NtDeviceIoControlFile(FileHandle
,
1013 IOCTL_SCSI_GET_ADDRESS
,
1017 sizeof(SCSI_ADDRESS
));
1018 if (!NT_SUCCESS(Status
))
1023 Mbr
= (PARTITION_SECTOR
*)RtlAllocateHeap(ProcessHeap
,
1025 DiskGeometry
.BytesPerSector
);
1031 FileOffset
.QuadPart
= 0;
1032 Status
= NtReadFile(FileHandle
,
1038 DiskGeometry
.BytesPerSector
,
1041 if (!NT_SUCCESS(Status
))
1043 RtlFreeHeap(ProcessHeap
,
1046 DPRINT1("NtReadFile failed, status=%x\n", Status
);
1049 Signature
= Mbr
->Signature
;
1051 /* Calculate the MBR checksum */
1053 Buffer
= (PULONG
)Mbr
;
1054 for (i
= 0; i
< 128; i
++)
1056 Checksum
+= Buffer
[i
];
1058 Checksum
= ~Checksum
+ 1;
1060 swprintf(Identifier
, L
"%08x-%08x-A", Checksum
, Signature
);
1061 DPRINT("Identifier: %S\n", Identifier
);
1063 DiskEntry
= RtlAllocateHeap(ProcessHeap
,
1066 if (DiskEntry
== NULL
)
1071 // DiskEntry->Checksum = Checksum;
1072 // DiskEntry->Signature = Signature;
1073 DiskEntry
->BiosFound
= FALSE
;
1075 /* Check if this disk has a valid MBR */
1076 if (Mbr
->BootCode
[0] == 0 && Mbr
->BootCode
[1] == 0)
1077 DiskEntry
->NoMbr
= TRUE
;
1079 DiskEntry
->NoMbr
= FALSE
;
1081 /* Free Mbr sector buffer */
1082 RtlFreeHeap(ProcessHeap
,
1086 ListEntry
= List
->BiosDiskListHead
.Flink
;
1087 while(ListEntry
!= &List
->BiosDiskListHead
)
1089 BiosDiskEntry
= CONTAINING_RECORD(ListEntry
, BIOSDISKENTRY
, ListEntry
);
1091 * Compare the size from bios and the reported size from driver.
1092 * If we have more than one disk with a zero or with the same signatur
1093 * we must create new signatures and reboot. After the reboot,
1094 * it is possible to identify the disks.
1096 if (BiosDiskEntry
->Signature
== Signature
&&
1097 BiosDiskEntry
->Checksum
== Checksum
&&
1098 !BiosDiskEntry
->Recognized
)
1100 if (!DiskEntry
->BiosFound
)
1102 DiskEntry
->BiosDiskNumber
= BiosDiskEntry
->DiskNumber
;
1103 DiskEntry
->BiosFound
= TRUE
;
1104 BiosDiskEntry
->Recognized
= TRUE
;
1110 ListEntry
= ListEntry
->Flink
;
1113 if (!DiskEntry
->BiosFound
)
1116 RtlFreeHeap(ProcessHeap
, 0, DiskEntry
);
1119 DPRINT1("WARNING: Setup could not find a matching BIOS disk entry. Disk %d is not be bootable by the BIOS!\n", DiskNumber
);
1123 InitializeListHead(&DiskEntry
->PrimaryPartListHead
);
1124 InitializeListHead(&DiskEntry
->LogicalPartListHead
);
1126 DiskEntry
->Cylinders
= DiskGeometry
.Cylinders
.QuadPart
;
1127 DiskEntry
->TracksPerCylinder
= DiskGeometry
.TracksPerCylinder
;
1128 DiskEntry
->SectorsPerTrack
= DiskGeometry
.SectorsPerTrack
;
1129 DiskEntry
->BytesPerSector
= DiskGeometry
.BytesPerSector
;
1131 DPRINT("Cylinders %I64u\n", DiskEntry
->Cylinders
);
1132 DPRINT("TracksPerCylinder %I64u\n", DiskEntry
->TracksPerCylinder
);
1133 DPRINT("SectorsPerTrack %I64u\n", DiskEntry
->SectorsPerTrack
);
1134 DPRINT("BytesPerSector %I64u\n", DiskEntry
->BytesPerSector
);
1136 DiskEntry
->SectorCount
.QuadPart
= DiskGeometry
.Cylinders
.QuadPart
*
1137 (ULONGLONG
)DiskGeometry
.TracksPerCylinder
*
1138 (ULONGLONG
)DiskGeometry
.SectorsPerTrack
;
1140 DiskEntry
->SectorAlignment
= DiskGeometry
.SectorsPerTrack
;
1142 DPRINT("SectorCount %I64u\n", DiskEntry
->SectorCount
);
1143 DPRINT("SectorAlignment %lu\n", DiskEntry
->SectorAlignment
);
1145 DiskEntry
->DiskNumber
= DiskNumber
;
1146 DiskEntry
->Port
= ScsiAddress
.PortNumber
;
1147 DiskEntry
->Bus
= ScsiAddress
.PathId
;
1148 DiskEntry
->Id
= ScsiAddress
.TargetId
;
1150 GetDriverName(DiskEntry
);
1152 InsertAscendingList(&List
->DiskListHead
, DiskEntry
, DISKENTRY
, ListEntry
, DiskNumber
);
1154 /* Allocate a layout buffer for 4 partition entries first */
1155 LayoutBufferSize
= sizeof(DRIVE_LAYOUT_INFORMATION
) +
1156 ((4 - ANYSIZE_ARRAY
) * sizeof(PARTITION_INFORMATION
));
1157 DiskEntry
->LayoutBuffer
= RtlAllocateHeap(ProcessHeap
,
1160 if (DiskEntry
->LayoutBuffer
== NULL
)
1165 Status
= NtDeviceIoControlFile(FileHandle
,
1170 IOCTL_DISK_GET_DRIVE_LAYOUT
,
1173 DiskEntry
->LayoutBuffer
,
1175 DPRINT("Status: 0x%08lx\n", Status
);
1176 DPRINT("PartitionCount: %lu\n", DiskEntry
->LayoutBuffer
->PartitionCount
);
1178 /* If we need more than 4 partition entries, reallocte the buffer and
1179 retrieve the disk layout again */
1180 if (!NT_SUCCESS(Status
) && DiskEntry
->LayoutBuffer
->PartitionCount
> 4)
1182 LayoutBufferSize
= sizeof(DRIVE_LAYOUT_INFORMATION
) +
1183 ((DiskEntry
->LayoutBuffer
->PartitionCount
- ANYSIZE_ARRAY
) * sizeof(PARTITION_INFORMATION
));
1184 DiskEntry
->LayoutBuffer
= RtlReAllocateHeap(ProcessHeap
,
1186 DiskEntry
->LayoutBuffer
,
1188 if (DiskEntry
->LayoutBuffer
== NULL
)
1193 Status
= NtDeviceIoControlFile(FileHandle
,
1198 IOCTL_DISK_GET_DRIVE_LAYOUT
,
1201 DiskEntry
->LayoutBuffer
,
1205 if (NT_SUCCESS(Status
))
1207 #ifdef DUMP_PARTITION_TABLE
1208 DumpPartitionTable(DiskEntry
);
1211 if (DiskEntry
->LayoutBuffer
->PartitionEntry
[0].StartingOffset
.QuadPart
!= 0 &&
1212 DiskEntry
->LayoutBuffer
->PartitionEntry
[0].PartitionLength
.QuadPart
!= 0 &&
1213 DiskEntry
->LayoutBuffer
->PartitionEntry
[0].PartitionType
!= 0)
1215 if ((DiskEntry
->LayoutBuffer
->PartitionEntry
[0].StartingOffset
.QuadPart
/ DiskEntry
->BytesPerSector
) % DiskEntry
->SectorsPerTrack
== 0)
1217 DPRINT("Use %lu Sector alignment!\n", DiskEntry
->SectorsPerTrack
);
1219 else if (DiskEntry
->LayoutBuffer
->PartitionEntry
[0].StartingOffset
.QuadPart
% (1024 * 1024) == 0)
1221 DPRINT1("Use megabyte (%lu Sectors) alignment!\n", (1024 * 1024) / DiskEntry
->BytesPerSector
);
1225 DPRINT1("No matching aligment found! Partiton 1 starts at %I64u\n", DiskEntry
->LayoutBuffer
->PartitionEntry
[0].StartingOffset
.QuadPart
);
1230 DPRINT1("No valid partiton table found! Use megabyte (%lu Sectors) alignment!\n", (1024 * 1024) / DiskEntry
->BytesPerSector
);
1234 if (DiskEntry
->LayoutBuffer
->PartitionCount
== 0)
1236 DiskEntry
->NewDisk
= TRUE
;
1237 DiskEntry
->LayoutBuffer
->PartitionCount
= 4;
1239 for (i
= 0; i
< 4; i
++)
1240 DiskEntry
->LayoutBuffer
->PartitionEntry
[i
].RewritePartition
= TRUE
;
1244 for (i
= 0; i
< 4; i
++)
1246 AddPartitionToDisk(DiskNumber
,
1252 for (i
= 4; i
< DiskEntry
->LayoutBuffer
->PartitionCount
; i
+= 4)
1254 AddPartitionToDisk(DiskNumber
,
1262 ScanForUnpartitionedDiskSpace(DiskEntry
);
1267 CreatePartitionList(
1274 OBJECT_ATTRIBUTES ObjectAttributes
;
1275 SYSTEM_DEVICE_INFORMATION Sdi
;
1276 IO_STATUS_BLOCK Iosb
;
1280 WCHAR Buffer
[MAX_PATH
];
1281 UNICODE_STRING Name
;
1284 List
= (PPARTLIST
)RtlAllocateHeap(ProcessHeap
,
1292 List
->Right
= Right
;
1293 List
->Bottom
= Bottom
;
1298 List
->TopDisk
= (ULONG
)-1;
1299 List
->TopPartition
= (ULONG
)-1;
1301 List
->CurrentDisk
= NULL
;
1302 List
->CurrentPartition
= NULL
;
1304 List
->BootDisk
= NULL
;
1305 List
->BootPartition
= NULL
;
1307 List
->TempDisk
= NULL
;
1308 List
->TempPartition
= NULL
;
1309 List
->FormatState
= Start
;
1311 InitializeListHead(&List
->DiskListHead
);
1312 InitializeListHead(&List
->BiosDiskListHead
);
1314 EnumerateBiosDiskEntries(List
);
1316 Status
= NtQuerySystemInformation(SystemDeviceInformation
,
1318 sizeof(SYSTEM_DEVICE_INFORMATION
),
1320 if (!NT_SUCCESS(Status
))
1322 RtlFreeHeap(ProcessHeap
, 0, List
);
1326 for (DiskNumber
= 0; DiskNumber
< Sdi
.NumberOfDisks
; DiskNumber
++)
1329 L
"\\Device\\Harddisk%d\\Partition0",
1331 RtlInitUnicodeString(&Name
,
1334 InitializeObjectAttributes(&ObjectAttributes
,
1340 Status
= NtOpenFile(&FileHandle
,
1341 FILE_READ_DATA
| FILE_READ_ATTRIBUTES
| SYNCHRONIZE
,
1345 FILE_SYNCHRONOUS_IO_NONALERT
);
1346 if (NT_SUCCESS(Status
))
1348 AddDiskToList(FileHandle
,
1352 NtClose(FileHandle
);
1356 UpdateDiskSignatures(List
);
1358 AssignDriveLetters(List
);
1361 List
->TopPartition
= 0;
1363 /* Search for first usable disk and partition */
1364 if (IsListEmpty(&List
->DiskListHead
))
1366 List
->CurrentDisk
= NULL
;
1367 List
->CurrentPartition
= NULL
;
1371 List
->CurrentDisk
= CONTAINING_RECORD(List
->DiskListHead
.Flink
,
1375 if (IsListEmpty(&List
->CurrentDisk
->PrimaryPartListHead
))
1377 List
->CurrentPartition
= 0;
1381 List
->CurrentPartition
= CONTAINING_RECORD(List
->CurrentDisk
->PrimaryPartListHead
.Flink
,
1392 DestroyPartitionList(
1395 PDISKENTRY DiskEntry
;
1396 PBIOSDISKENTRY BiosDiskEntry
;
1397 PPARTENTRY PartEntry
;
1400 /* Release disk and partition info */
1401 while (!IsListEmpty(&List
->DiskListHead
))
1403 Entry
= RemoveHeadList(&List
->DiskListHead
);
1404 DiskEntry
= CONTAINING_RECORD(Entry
, DISKENTRY
, ListEntry
);
1406 /* Release driver name */
1407 RtlFreeUnicodeString(&DiskEntry
->DriverName
);
1409 /* Release primary partition list */
1410 while (!IsListEmpty(&DiskEntry
->PrimaryPartListHead
))
1412 Entry
= RemoveHeadList(&DiskEntry
->PrimaryPartListHead
);
1413 PartEntry
= CONTAINING_RECORD(Entry
, PARTENTRY
, ListEntry
);
1415 RtlFreeHeap(ProcessHeap
, 0, PartEntry
);
1418 /* Release logical partition list */
1419 while (!IsListEmpty(&DiskEntry
->LogicalPartListHead
))
1421 Entry
= RemoveHeadList(&DiskEntry
->LogicalPartListHead
);
1422 PartEntry
= CONTAINING_RECORD(Entry
, PARTENTRY
, ListEntry
);
1424 RtlFreeHeap(ProcessHeap
, 0, PartEntry
);
1427 /* Release layout buffer */
1428 if (DiskEntry
->LayoutBuffer
!= NULL
)
1429 RtlFreeHeap(ProcessHeap
, 0, DiskEntry
->LayoutBuffer
);
1432 /* Release disk entry */
1433 RtlFreeHeap(ProcessHeap
, 0, DiskEntry
);
1436 /* release the bios disk info */
1437 while(!IsListEmpty(&List
->BiosDiskListHead
))
1439 Entry
= RemoveHeadList(&List
->BiosDiskListHead
);
1440 BiosDiskEntry
= CONTAINING_RECORD(Entry
, BIOSDISKENTRY
, ListEntry
);
1442 RtlFreeHeap(ProcessHeap
, 0, BiosDiskEntry
);
1445 /* Release list head */
1446 RtlFreeHeap(ProcessHeap
, 0, List
);
1460 Width
= List
->Right
- List
->Left
- 1;
1461 Height
= List
->Bottom
- List
->Top
- 2;
1463 coPos
.X
= List
->Left
+ 1;
1464 coPos
.Y
= List
->Top
+ 1 + List
->Line
;
1466 if (List
->Line
>= 0 && List
->Line
<= Height
)
1468 FillConsoleOutputAttribute(StdOutput
,
1469 FOREGROUND_WHITE
| BACKGROUND_BLUE
,
1474 FillConsoleOutputCharacterA(StdOutput
,
1489 PDISKENTRY DiskEntry
,
1490 PPARTENTRY PartEntry
)
1492 CHAR LineBuffer
[128];
1497 LARGE_INTEGER PartSize
;
1502 Width
= List
->Right
- List
->Left
- 1;
1503 Height
= List
->Bottom
- List
->Top
- 2;
1505 coPos
.X
= List
->Left
+ 1;
1506 coPos
.Y
= List
->Top
+ 1 + List
->Line
;
1508 if (PartEntry
->IsPartitioned
== FALSE
)
1510 PartSize
.QuadPart
= PartEntry
->SectorCount
.QuadPart
* DiskEntry
->BytesPerSector
;
1512 if (PartSize
.QuadPart
>= 10737418240) /* 10 GB */
1514 PartSize
.QuadPart
= RoundingDivide(PartSize
.QuadPart
, 1073741824);
1515 Unit
= MUIGetString(STRING_GB
);
1519 if (PartSize
.QuadPart
>= 10485760) /* 10 MB */
1521 PartSize
.QuadPart
= RoundingDivide(PartSize
.QuadPart
, 1048576);
1522 Unit
= MUIGetString(STRING_MB
);
1526 PartSize
.QuadPart
= RoundingDivide(PartSize
.QuadPart
, 1024);
1527 Unit
= MUIGetString(STRING_KB
);
1531 MUIGetString(STRING_UNPSPACE
),
1532 PartEntry
->LogicalPartition
? " " : "",
1533 PartEntry
->LogicalPartition
? "" : " ",
1539 /* Determine partition type */
1541 if (PartEntry
->New
== TRUE
)
1543 PartType
= MUIGetString(STRING_UNFORMATTED
);
1545 else if (PartEntry
->IsPartitioned
== TRUE
)
1547 if ((PartEntry
->PartitionType
== PARTITION_FAT_12
) ||
1548 (PartEntry
->PartitionType
== PARTITION_FAT_16
) ||
1549 (PartEntry
->PartitionType
== PARTITION_HUGE
) ||
1550 (PartEntry
->PartitionType
== PARTITION_XINT13
))
1554 else if ((PartEntry
->PartitionType
== PARTITION_FAT32
) ||
1555 (PartEntry
->PartitionType
== PARTITION_FAT32_XINT13
))
1559 else if (PartEntry
->PartitionType
== PARTITION_EXT2
)
1563 else if (PartEntry
->PartitionType
== PARTITION_IFS
)
1565 PartType
= "NTFS"; /* FIXME: Not quite correct! */
1567 else if ((PartEntry
->PartitionType
== PARTITION_EXTENDED
) ||
1568 (PartEntry
->PartitionType
== PARTITION_XINT13_EXTENDED
))
1570 PartType
= MUIGetString(STRING_EXTENDED_PARTITION
);
1574 PartSize
.QuadPart
= PartEntry
->SectorCount
.QuadPart
* DiskEntry
->BytesPerSector
;
1576 if (PartSize
.QuadPart
>= 10737418240) /* 10 GB */
1578 PartSize
.QuadPart
= RoundingDivide(PartSize
.QuadPart
, 1073741824);
1579 Unit
= MUIGetString(STRING_GB
);
1583 if (PartSize
.QuadPart
>= 10485760) /* 10 MB */
1585 PartSize
.QuadPart
= RoundingDivide(PartSize
.QuadPart
, 1048576);
1586 Unit
= MUIGetString(STRING_MB
);
1590 PartSize
.QuadPart
= RoundingDivide(PartSize
.QuadPart
, 1024);
1591 Unit
= MUIGetString(STRING_KB
);
1594 if (PartType
== NULL
)
1597 MUIGetString(STRING_HDDINFOUNK5
),
1598 (PartEntry
->DriveLetter
== 0) ? '-' : PartEntry
->DriveLetter
,
1599 (PartEntry
->DriveLetter
== 0) ? '-' : ':',
1600 PartEntry
->BootIndicator
? '*' : ' ',
1601 PartEntry
->LogicalPartition
? " " : "",
1602 PartEntry
->PartitionType
,
1603 PartEntry
->LogicalPartition
? "" : " ",
1610 "%c%c %c %s%-24s%s %6lu %s",
1611 (PartEntry
->DriveLetter
== 0) ? '-' : PartEntry
->DriveLetter
,
1612 (PartEntry
->DriveLetter
== 0) ? '-' : ':',
1613 PartEntry
->BootIndicator
? '*' : ' ',
1614 PartEntry
->LogicalPartition
? " " : "",
1616 PartEntry
->LogicalPartition
? "" : " ",
1622 Attribute
= (List
->CurrentDisk
== DiskEntry
&&
1623 List
->CurrentPartition
== PartEntry
) ?
1624 FOREGROUND_BLUE
| BACKGROUND_WHITE
:
1625 FOREGROUND_WHITE
| BACKGROUND_BLUE
;
1627 if (List
->Line
>= 0 && List
->Line
<= Height
)
1629 FillConsoleOutputCharacterA(StdOutput
,
1637 if (List
->Line
>= 0 && List
->Line
<= Height
)
1639 FillConsoleOutputAttribute(StdOutput
,
1647 if (List
->Line
>= 0 && List
->Line
<= Height
)
1649 WriteConsoleOutputCharacterA(StdOutput
,
1651 min(strlen(LineBuffer
), Width
),
1664 PDISKENTRY DiskEntry
)
1666 PPARTENTRY PrimaryPartEntry
, LogicalPartEntry
;
1667 PLIST_ENTRY PrimaryEntry
, LogicalEntry
;
1668 CHAR LineBuffer
[128];
1673 ULARGE_INTEGER DiskSize
;
1676 Width
= List
->Right
- List
->Left
- 1;
1677 Height
= List
->Bottom
- List
->Top
- 2;
1679 coPos
.X
= List
->Left
+ 1;
1680 coPos
.Y
= List
->Top
+ 1 + List
->Line
;
1682 DiskSize
.QuadPart
= DiskEntry
->SectorCount
.QuadPart
* DiskEntry
->BytesPerSector
;
1683 if (DiskSize
.QuadPart
>= 10737418240) /* 10 GB */
1685 DiskSize
.QuadPart
= RoundingDivide(DiskSize
.QuadPart
, 1073741824);
1686 Unit
= MUIGetString(STRING_GB
);
1690 DiskSize
.QuadPart
= RoundingDivide(DiskSize
.QuadPart
, 1048576);
1691 if (DiskSize
.QuadPart
== 0)
1692 DiskSize
.QuadPart
= 1;
1693 Unit
= MUIGetString(STRING_MB
);
1696 if (DiskEntry
->DriverName
.Length
> 0)
1699 MUIGetString(STRING_HDINFOPARTSELECT
),
1702 DiskEntry
->DiskNumber
,
1706 DiskEntry
->DriverName
.Buffer
);
1711 MUIGetString(STRING_HDDINFOUNK6
),
1714 DiskEntry
->DiskNumber
,
1720 if (List
->Line
>= 0 && List
->Line
<= Height
)
1722 FillConsoleOutputAttribute(StdOutput
,
1723 FOREGROUND_WHITE
| BACKGROUND_BLUE
,
1728 FillConsoleOutputCharacterA(StdOutput
,
1736 if (List
->Line
>= 0 && List
->Line
<= Height
)
1738 WriteConsoleOutputCharacterA(StdOutput
,
1740 min((USHORT
)strlen(LineBuffer
), Width
- 2),
1747 /* Print separator line */
1748 PrintEmptyLine(List
);
1750 /* Print partition lines*/
1751 PrimaryEntry
= DiskEntry
->PrimaryPartListHead
.Flink
;
1752 while (PrimaryEntry
!= &DiskEntry
->PrimaryPartListHead
)
1754 PrimaryPartEntry
= CONTAINING_RECORD(PrimaryEntry
, PARTENTRY
, ListEntry
);
1756 PrintPartitionData(List
,
1760 if (IsContainerPartition(PrimaryPartEntry
->PartitionType
))
1762 LogicalEntry
= DiskEntry
->LogicalPartListHead
.Flink
;
1763 while (LogicalEntry
!= &DiskEntry
->LogicalPartListHead
)
1765 LogicalPartEntry
= CONTAINING_RECORD(LogicalEntry
, PARTENTRY
, ListEntry
);
1767 PrintPartitionData(List
,
1771 LogicalEntry
= LogicalEntry
->Flink
;
1775 PrimaryEntry
= PrimaryEntry
->Flink
;
1778 /* Print separator line */
1779 PrintEmptyLine(List
);
1787 PLIST_ENTRY Entry
, Entry2
;
1788 PDISKENTRY DiskEntry
;
1789 PPARTENTRY PartEntry
= NULL
;
1793 SHORT CurrentDiskLine
;
1794 SHORT CurrentPartLine
;
1796 BOOL CurrentPartLineFound
= FALSE
;
1797 BOOL CurrentDiskLineFound
= FALSE
;
1799 /* Calculate the line of the current disk and partition */
1800 CurrentDiskLine
= 0;
1801 CurrentPartLine
= 0;
1804 Entry
= List
->DiskListHead
.Flink
;
1805 while (Entry
!= &List
->DiskListHead
)
1807 DiskEntry
= CONTAINING_RECORD(Entry
, DISKENTRY
, ListEntry
);
1810 if (CurrentPartLineFound
== FALSE
)
1812 CurrentPartLine
+= 2;
1815 Entry2
= DiskEntry
->PrimaryPartListHead
.Flink
;
1816 while (Entry2
!= &DiskEntry
->PrimaryPartListHead
)
1818 PartEntry
= CONTAINING_RECORD(Entry2
, PARTENTRY
, ListEntry
);
1819 if (PartEntry
== List
->CurrentPartition
)
1821 CurrentPartLineFound
= TRUE
;
1824 Entry2
= Entry2
->Flink
;
1825 if (CurrentPartLineFound
== FALSE
)
1833 if (DiskEntry
== List
->CurrentDisk
)
1835 CurrentDiskLineFound
= TRUE
;
1838 Entry
= Entry
->Flink
;
1839 if (Entry
!= &List
->DiskListHead
)
1841 if (CurrentDiskLineFound
== FALSE
)
1844 CurrentDiskLine
= CurrentPartLine
;
1855 /* If it possible, make the disk name visible */
1856 if (CurrentPartLine
< List
->Offset
)
1858 List
->Offset
= CurrentPartLine
;
1860 else if (CurrentPartLine
- List
->Offset
> List
->Bottom
- List
->Top
- 2)
1862 List
->Offset
= CurrentPartLine
- (List
->Bottom
- List
->Top
- 2);
1865 if (CurrentDiskLine
< List
->Offset
&& CurrentPartLine
- CurrentDiskLine
< List
->Bottom
- List
->Top
- 2)
1867 List
->Offset
= CurrentDiskLine
;
1870 /* draw upper left corner */
1871 coPos
.X
= List
->Left
;
1872 coPos
.Y
= List
->Top
;
1873 FillConsoleOutputCharacterA(StdOutput
,
1879 /* draw upper edge */
1880 coPos
.X
= List
->Left
+ 1;
1881 coPos
.Y
= List
->Top
;
1882 if (List
->Offset
== 0)
1884 FillConsoleOutputCharacterA(StdOutput
,
1886 List
->Right
- List
->Left
- 1,
1892 FillConsoleOutputCharacterA(StdOutput
,
1894 List
->Right
- List
->Left
- 5,
1897 coPos
.X
= List
->Right
- 5;
1898 WriteConsoleOutputCharacterA(StdOutput
,
1903 coPos
.X
= List
->Right
- 2;
1904 FillConsoleOutputCharacterA(StdOutput
,
1911 /* draw upper right corner */
1912 coPos
.X
= List
->Right
;
1913 coPos
.Y
= List
->Top
;
1914 FillConsoleOutputCharacterA(StdOutput
,
1920 /* draw left and right edge */
1921 for (i
= List
->Top
+ 1; i
< List
->Bottom
; i
++)
1923 coPos
.X
= List
->Left
;
1925 FillConsoleOutputCharacterA(StdOutput
,
1931 coPos
.X
= List
->Right
;
1932 FillConsoleOutputCharacterA(StdOutput
,
1939 /* draw lower left corner */
1940 coPos
.X
= List
->Left
;
1941 coPos
.Y
= List
->Bottom
;
1942 FillConsoleOutputCharacterA(StdOutput
,
1948 /* draw lower edge */
1949 coPos
.X
= List
->Left
+ 1;
1950 coPos
.Y
= List
->Bottom
;
1951 if (LastLine
- List
->Offset
<= List
->Bottom
- List
->Top
- 2)
1953 FillConsoleOutputCharacterA(StdOutput
,
1955 List
->Right
- List
->Left
- 1,
1961 FillConsoleOutputCharacterA(StdOutput
,
1963 List
->Right
- List
->Left
- 5,
1966 coPos
.X
= List
->Right
- 5;
1967 WriteConsoleOutputCharacterA(StdOutput
,
1968 "(\x19)", // "(down)"
1972 coPos
.X
= List
->Right
- 2;
1973 FillConsoleOutputCharacterA(StdOutput
,
1980 /* draw lower right corner */
1981 coPos
.X
= List
->Right
;
1982 coPos
.Y
= List
->Bottom
;
1983 FillConsoleOutputCharacterA(StdOutput
,
1989 /* print list entries */
1990 List
->Line
= - List
->Offset
;
1992 Entry
= List
->DiskListHead
.Flink
;
1993 while (Entry
!= &List
->DiskListHead
)
1995 DiskEntry
= CONTAINING_RECORD(Entry
, DISKENTRY
, ListEntry
);
1997 /* Print disk entry */
2001 Entry
= Entry
->Flink
;
2010 ULONG PartitionNumber
)
2012 PDISKENTRY DiskEntry
;
2013 PPARTENTRY PartEntry
;
2017 /* Check for empty disks */
2018 if (IsListEmpty(&List
->DiskListHead
))
2021 /* Check for first usable entry on next disk */
2022 Entry1
= List
->CurrentDisk
->ListEntry
.Flink
;
2023 while (Entry1
!= &List
->DiskListHead
)
2025 DiskEntry
= CONTAINING_RECORD(Entry1
, DISKENTRY
, ListEntry
);
2027 if (DiskEntry
->DiskNumber
== DiskNumber
)
2029 Entry2
= DiskEntry
->PrimaryPartListHead
.Flink
;
2030 while (Entry2
!= &DiskEntry
->PrimaryPartListHead
)
2032 PartEntry
= CONTAINING_RECORD(Entry2
, PARTENTRY
, ListEntry
);
2034 if (PartEntry
->PartitionNumber
== PartitionNumber
)
2036 List
->CurrentDisk
= DiskEntry
;
2037 List
->CurrentPartition
= PartEntry
;
2038 DrawPartitionList(List
);
2042 Entry2
= Entry2
->Flink
;
2048 Entry1
= Entry1
->Flink
;
2056 ScrollDownPartitionList(
2059 PLIST_ENTRY DiskListEntry
;
2060 PLIST_ENTRY PartListEntry
;
2061 PDISKENTRY DiskEntry
;
2062 PPARTENTRY PartEntry
;
2064 /* Fail, if no disks are available */
2065 if (IsListEmpty(&List
->DiskListHead
))
2068 /* Check for next usable entry on current disk */
2069 if (List
->CurrentPartition
!= NULL
)
2071 if (List
->CurrentPartition
->LogicalPartition
)
2073 /* Logical partition */
2075 PartListEntry
= List
->CurrentPartition
->ListEntry
.Flink
;
2076 if (PartListEntry
!= &List
->CurrentDisk
->LogicalPartListHead
)
2078 /* Next logical partition */
2079 PartEntry
= CONTAINING_RECORD(PartListEntry
, PARTENTRY
, ListEntry
);
2081 List
->CurrentPartition
= PartEntry
;
2086 PartListEntry
= List
->CurrentDisk
->ExtendedPartition
->ListEntry
.Flink
;
2087 if (PartListEntry
!= &List
->CurrentDisk
->PrimaryPartListHead
)
2089 PartEntry
= CONTAINING_RECORD(PartListEntry
, PARTENTRY
, ListEntry
);
2091 List
->CurrentPartition
= PartEntry
;
2098 /* Primary or extended partition */
2100 if (List
->CurrentPartition
->IsPartitioned
== TRUE
&&
2101 IsContainerPartition(List
->CurrentPartition
->PartitionType
))
2103 /* First logical partition */
2104 PartListEntry
= List
->CurrentDisk
->LogicalPartListHead
.Flink
;
2105 if (PartListEntry
!= &List
->CurrentDisk
->LogicalPartListHead
)
2107 PartEntry
= CONTAINING_RECORD(PartListEntry
, PARTENTRY
, ListEntry
);
2109 List
->CurrentPartition
= PartEntry
;
2115 /* Next primary partition */
2116 PartListEntry
= List
->CurrentPartition
->ListEntry
.Flink
;
2117 if (PartListEntry
!= &List
->CurrentDisk
->PrimaryPartListHead
)
2119 PartEntry
= CONTAINING_RECORD(PartListEntry
, PARTENTRY
, ListEntry
);
2121 List
->CurrentPartition
= PartEntry
;
2128 /* Search for the first partition entry on the next disk */
2129 DiskListEntry
= List
->CurrentDisk
->ListEntry
.Flink
;
2130 while (DiskListEntry
!= &List
->DiskListHead
)
2132 DiskEntry
= CONTAINING_RECORD(DiskListEntry
, DISKENTRY
, ListEntry
);
2134 PartListEntry
= DiskEntry
->PrimaryPartListHead
.Flink
;
2135 if (PartListEntry
!= &DiskEntry
->PrimaryPartListHead
)
2137 PartEntry
= CONTAINING_RECORD(PartListEntry
, PARTENTRY
, ListEntry
);
2139 List
->CurrentDisk
= DiskEntry
;
2140 List
->CurrentPartition
= PartEntry
;
2144 DiskListEntry
= DiskListEntry
->Flink
;
2152 ScrollUpPartitionList(
2155 PLIST_ENTRY DiskListEntry
;
2156 PLIST_ENTRY PartListEntry
;
2157 PDISKENTRY DiskEntry
;
2158 PPARTENTRY PartEntry
;
2160 /* Fail, if no disks are available */
2161 if (IsListEmpty(&List
->DiskListHead
))
2164 /* Check for previous usable entry on current disk */
2165 if (List
->CurrentPartition
!= NULL
)
2167 if (List
->CurrentPartition
->LogicalPartition
)
2169 /* Logical partition */
2170 PartListEntry
= List
->CurrentPartition
->ListEntry
.Blink
;
2171 if (PartListEntry
!= &List
->CurrentDisk
->LogicalPartListHead
)
2173 /* Previous logical partition */
2174 PartEntry
= CONTAINING_RECORD(PartListEntry
, PARTENTRY
, ListEntry
);
2178 /* Extended partition*/
2179 PartEntry
= List
->CurrentDisk
->ExtendedPartition
;
2182 List
->CurrentPartition
= PartEntry
;
2187 /* Primary or extended partition */
2189 PartListEntry
= List
->CurrentPartition
->ListEntry
.Blink
;
2190 if (PartListEntry
!= &List
->CurrentDisk
->PrimaryPartListHead
)
2192 PartEntry
= CONTAINING_RECORD(PartListEntry
, PARTENTRY
, ListEntry
);
2194 if (PartEntry
->IsPartitioned
== TRUE
&&
2195 IsContainerPartition(PartEntry
->PartitionType
))
2197 PartListEntry
= List
->CurrentDisk
->LogicalPartListHead
.Blink
;
2198 PartEntry
= CONTAINING_RECORD(PartListEntry
, PARTENTRY
, ListEntry
);
2201 List
->CurrentPartition
= PartEntry
;
2208 /* Search for the last partition entry on the previous disk */
2209 DiskListEntry
= List
->CurrentDisk
->ListEntry
.Blink
;
2210 while (DiskListEntry
!= &List
->DiskListHead
)
2212 DiskEntry
= CONTAINING_RECORD(DiskListEntry
, DISKENTRY
, ListEntry
);
2214 PartListEntry
= DiskEntry
->PrimaryPartListHead
.Blink
;
2215 if (PartListEntry
!= &DiskEntry
->PrimaryPartListHead
)
2217 PartEntry
= CONTAINING_RECORD(PartListEntry
, PARTENTRY
, ListEntry
);
2219 if (PartEntry
->IsPartitioned
== TRUE
&&
2220 IsContainerPartition(PartEntry
->PartitionType
))
2222 PartListEntry
= DiskEntry
->LogicalPartListHead
.Blink
;
2223 if (PartListEntry
!= &DiskEntry
->LogicalPartListHead
)
2225 PartEntry
= CONTAINING_RECORD(PartListEntry
, PARTENTRY
, ListEntry
);
2227 List
->CurrentDisk
= DiskEntry
;
2228 List
->CurrentPartition
= PartEntry
;
2234 List
->CurrentDisk
= DiskEntry
;
2235 List
->CurrentPartition
= PartEntry
;
2240 DiskListEntry
= DiskListEntry
->Blink
;
2250 PPARTITION_INFORMATION PartitionInfo
)
2252 if (PartitionInfo
->StartingOffset
.QuadPart
== 0 &&
2253 PartitionInfo
->PartitionLength
.QuadPart
== 0)
2254 // PartitionInfo->PartitionType == 0)
2263 IsSamePrimaryLayoutEntry(
2264 IN PPARTITION_INFORMATION PartitionInfo
,
2265 IN PDISKENTRY DiskEntry
,
2266 IN PPARTENTRY PartEntry
)
2268 if (PartitionInfo
->StartingOffset
.QuadPart
== PartEntry
->StartSector
.QuadPart
* DiskEntry
->BytesPerSector
&&
2269 PartitionInfo
->PartitionLength
.QuadPart
== PartEntry
->SectorCount
.QuadPart
* DiskEntry
->BytesPerSector
)
2270 // PartitionInfo->PartitionNumber = PartEntry->PartitionNumber &&
2271 // PartitionInfo->PartitionType == PartEntry->PartitionType
2281 IN PDISKENTRY DiskEntry
)
2283 PPARTITION_INFORMATION PartitionInfo
;
2284 PLIST_ENTRY ListEntry
;
2285 PPARTENTRY PartEntry
;
2287 ULONG PartitionNumber
= 1;
2289 DPRINT1("UpdateDiskLayout()\n");
2291 ListEntry
= DiskEntry
->PrimaryPartListHead
.Flink
;
2292 while (ListEntry
!= &DiskEntry
->PrimaryPartListHead
)
2294 PartEntry
= CONTAINING_RECORD(ListEntry
, PARTENTRY
, ListEntry
);
2296 if (PartEntry
->IsPartitioned
== TRUE
)
2298 PartitionInfo
= &DiskEntry
->LayoutBuffer
->PartitionEntry
[Index
];
2300 if (!IsSamePrimaryLayoutEntry(PartitionInfo
, DiskEntry
, PartEntry
))
2302 DPRINT1("Updating partition entry %lu\n", Index
);
2304 PartitionInfo
->StartingOffset
.QuadPart
= PartEntry
->StartSector
.QuadPart
* DiskEntry
->BytesPerSector
;
2305 PartitionInfo
->PartitionLength
.QuadPart
= PartEntry
->SectorCount
.QuadPart
* DiskEntry
->BytesPerSector
;
2306 PartitionInfo
->HiddenSectors
= 0;
2307 PartitionInfo
->PartitionNumber
= (!IsContainerPartition(PartEntry
->PartitionType
)) ? PartitionNumber
: 0;
2308 PartitionInfo
->PartitionType
= PartEntry
->PartitionType
;
2309 PartitionInfo
->BootIndicator
= PartEntry
->BootIndicator
;
2310 PartitionInfo
->RecognizedPartition
= FALSE
;
2311 PartitionInfo
->RewritePartition
= TRUE
;
2313 PartEntry
->PartitionNumber
= PartitionNumber
;
2314 PartEntry
->PartitionIndex
= Index
;
2318 else if (!IsEmptyLayoutEntry(PartitionInfo
))
2326 ListEntry
= ListEntry
->Flink
;
2329 for (;Index
< 4; Index
++)
2331 PartitionInfo
= &DiskEntry
->LayoutBuffer
->PartitionEntry
[Index
];
2333 if (!IsEmptyLayoutEntry(PartitionInfo
))
2335 DPRINT1("Wiping partition entry %lu\n", Index
);
2337 PartitionInfo
->StartingOffset
.QuadPart
= 0;
2338 PartitionInfo
->PartitionLength
.QuadPart
= 0;
2339 PartitionInfo
->HiddenSectors
= 0;
2340 PartitionInfo
->PartitionNumber
= 0;
2341 PartitionInfo
->PartitionType
= 0;
2342 PartitionInfo
->BootIndicator
= FALSE
;
2343 PartitionInfo
->RecognizedPartition
= FALSE
;
2344 PartitionInfo
->RewritePartition
= TRUE
;
2348 #ifdef DUMP_PARTITION_TABLE
2349 DumpPartitionTable(DiskEntry
);
2356 GetPrevUnpartitionedEntry(
2357 PDISKENTRY DiskEntry
,
2358 PPARTENTRY PartEntry
)
2360 PPARTENTRY PrevPartEntry
;
2362 if (PartEntry
->ListEntry
.Blink
!= &DiskEntry
->PrimaryPartListHead
)
2364 PrevPartEntry
= CONTAINING_RECORD(PartEntry
->ListEntry
.Blink
,
2367 if (PrevPartEntry
->IsPartitioned
== FALSE
)
2368 return PrevPartEntry
;
2377 GetNextUnpartitionedEntry(
2378 PDISKENTRY DiskEntry
,
2379 PPARTENTRY PartEntry
)
2381 PPARTENTRY NextPartEntry
;
2383 if (PartEntry
->ListEntry
.Flink
!= &DiskEntry
->PrimaryPartListHead
)
2385 NextPartEntry
= CONTAINING_RECORD(PartEntry
->ListEntry
.Flink
,
2388 if (NextPartEntry
->IsPartitioned
== FALSE
)
2389 return NextPartEntry
;
2397 CreatePrimaryPartition(
2399 ULONGLONG SectorCount
,
2402 PDISKENTRY DiskEntry
;
2403 PPARTENTRY PartEntry
;
2404 PPARTENTRY NewPartEntry
;
2406 DPRINT1("CreatePrimaryPartition(%I64u)\n", SectorCount
);
2409 List
->CurrentDisk
== NULL
||
2410 List
->CurrentPartition
== NULL
||
2411 List
->CurrentPartition
->IsPartitioned
== TRUE
)
2416 DiskEntry
= List
->CurrentDisk
;
2417 PartEntry
= List
->CurrentPartition
;
2419 DPRINT1("Current partition sector count: %I64u\n", PartEntry
->SectorCount
.QuadPart
);
2421 if (AutoCreate
== TRUE
||
2422 Align(PartEntry
->StartSector
.QuadPart
+ SectorCount
, DiskEntry
->SectorAlignment
) - PartEntry
->StartSector
.QuadPart
== PartEntry
->SectorCount
.QuadPart
)
2424 DPRINT1("Convert existing partition entry\n");
2426 /* Convert current entry to 'new (unformatted)' */
2427 PartEntry
->IsPartitioned
= TRUE
;
2428 PartEntry
->PartitionType
= PARTITION_ENTRY_UNUSED
;
2429 PartEntry
->FormatState
= Unformatted
;
2430 PartEntry
->AutoCreate
= AutoCreate
;
2431 PartEntry
->New
= TRUE
;
2432 PartEntry
->BootIndicator
= FALSE
;
2434 DPRINT1("First Sector: %I64u\n", PartEntry
->StartSector
.QuadPart
);
2435 DPRINT1("Last Sector: %I64u\n", PartEntry
->StartSector
.QuadPart
+ PartEntry
->SectorCount
.QuadPart
- 1);
2436 DPRINT1("Total Sectors: %I64u\n", PartEntry
->SectorCount
.QuadPart
);
2440 DPRINT1("Add new partition entry\n");
2442 /* Insert and initialize a new partition entry */
2443 NewPartEntry
= RtlAllocateHeap(ProcessHeap
,
2446 if (NewPartEntry
== NULL
)
2449 /* Insert the new entry into the list */
2450 InsertTailList(&PartEntry
->ListEntry
,
2451 &NewPartEntry
->ListEntry
);
2453 NewPartEntry
->DiskEntry
= DiskEntry
;
2455 NewPartEntry
->IsPartitioned
= TRUE
;
2456 NewPartEntry
->StartSector
.QuadPart
= PartEntry
->StartSector
.QuadPart
;
2457 NewPartEntry
->SectorCount
.QuadPart
= Align(NewPartEntry
->StartSector
.QuadPart
+ SectorCount
, DiskEntry
->SectorAlignment
) -
2458 NewPartEntry
->StartSector
.QuadPart
;
2459 NewPartEntry
->PartitionType
= PARTITION_ENTRY_UNUSED
;
2461 DPRINT1("First Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
);
2462 DPRINT1("Last Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
+ NewPartEntry
->SectorCount
.QuadPart
- 1);
2463 DPRINT1("Total Sectors: %I64u\n", NewPartEntry
->SectorCount
.QuadPart
);
2465 NewPartEntry
->New
= TRUE
;
2466 NewPartEntry
->FormatState
= Unformatted
;
2467 NewPartEntry
->BootIndicator
= FALSE
;
2469 PartEntry
->StartSector
.QuadPart
= NewPartEntry
->StartSector
.QuadPart
+ NewPartEntry
->SectorCount
.QuadPart
;
2470 PartEntry
->SectorCount
.QuadPart
-= (PartEntry
->StartSector
.QuadPart
- NewPartEntry
->StartSector
.QuadPart
);
2473 UpdateDiskLayout(DiskEntry
);
2475 DiskEntry
->Dirty
= TRUE
;
2477 UpdatePartitionNumbers(DiskEntry
);
2479 AssignDriveLetters(List
);
2485 AddLogicalDiskSpace(
2486 PDISKENTRY DiskEntry
)
2488 PPARTENTRY NewPartEntry
;
2490 DPRINT1("AddLogicalDiskSpace()\n");
2492 /* Create a partition table entry that represents the empty space in the container partition */
2493 NewPartEntry
= RtlAllocateHeap(ProcessHeap
,
2496 if (NewPartEntry
== NULL
)
2499 NewPartEntry
->DiskEntry
= DiskEntry
;
2500 NewPartEntry
->LogicalPartition
= TRUE
;
2502 NewPartEntry
->IsPartitioned
= FALSE
;
2503 NewPartEntry
->StartSector
.QuadPart
= DiskEntry
->ExtendedPartition
->StartSector
.QuadPart
+ (ULONGLONG
)DiskEntry
->SectorAlignment
;
2504 NewPartEntry
->SectorCount
.QuadPart
= DiskEntry
->ExtendedPartition
->SectorCount
.QuadPart
- (ULONGLONG
)DiskEntry
->SectorAlignment
;
2506 DPRINT1("First Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
);
2507 DPRINT1("Last Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
+ NewPartEntry
->SectorCount
.QuadPart
- 1);
2508 DPRINT1("Total Sectors: %I64u\n", NewPartEntry
->SectorCount
.QuadPart
);
2510 NewPartEntry
->FormatState
= Unformatted
;
2512 InsertTailList(&DiskEntry
->LogicalPartListHead
,
2513 &NewPartEntry
->ListEntry
);
2518 CreateExtendedPartition(
2520 ULONGLONG SectorCount
)
2522 PDISKENTRY DiskEntry
;
2523 PPARTENTRY PartEntry
;
2524 PPARTENTRY NewPartEntry
;
2526 DPRINT1("CreateExtendedPartition(%I64u)\n", SectorCount
);
2529 List
->CurrentDisk
== NULL
||
2530 List
->CurrentPartition
== NULL
||
2531 List
->CurrentPartition
->IsPartitioned
== TRUE
)
2536 DiskEntry
= List
->CurrentDisk
;
2537 PartEntry
= List
->CurrentPartition
;
2539 DPRINT1("Current partition sector count: %I64u\n", PartEntry
->SectorCount
.QuadPart
);
2541 if (Align(PartEntry
->StartSector
.QuadPart
+ SectorCount
, DiskEntry
->SectorAlignment
) - PartEntry
->StartSector
.QuadPart
== PartEntry
->SectorCount
.QuadPart
)
2543 DPRINT1("Convert existing partition entry\n");
2545 /* Convert current entry to 'new (unformatted)' */
2546 PartEntry
->IsPartitioned
= TRUE
;
2547 PartEntry
->FormatState
= Formatted
;
2548 PartEntry
->AutoCreate
= FALSE
;
2549 PartEntry
->New
= FALSE
;
2550 PartEntry
->BootIndicator
= FALSE
;
2552 if (PartEntry
->StartSector
.QuadPart
< 1450560)
2554 /* Partition starts below the 8.4GB boundary ==> CHS partition */
2555 PartEntry
->PartitionType
= PARTITION_EXTENDED
;
2559 /* Partition starts above the 8.4GB boundary ==> LBA partition */
2560 PartEntry
->PartitionType
= PARTITION_XINT13_EXTENDED
;
2563 DiskEntry
->ExtendedPartition
= PartEntry
;
2565 DPRINT1("First Sector: %I64u\n", PartEntry
->StartSector
.QuadPart
);
2566 DPRINT1("Last Sector: %I64u\n", PartEntry
->StartSector
.QuadPart
+ PartEntry
->SectorCount
.QuadPart
- 1);
2567 DPRINT1("Total Sectors: %I64u\n", PartEntry
->SectorCount
.QuadPart
);
2571 DPRINT1("Add new partition entry\n");
2573 /* Insert and initialize a new partition entry */
2574 NewPartEntry
= RtlAllocateHeap(ProcessHeap
,
2577 if (NewPartEntry
== NULL
)
2580 /* Insert the new entry into the list */
2581 InsertTailList(&PartEntry
->ListEntry
,
2582 &NewPartEntry
->ListEntry
);
2584 NewPartEntry
->DiskEntry
= DiskEntry
;
2586 NewPartEntry
->IsPartitioned
= TRUE
;
2587 NewPartEntry
->StartSector
.QuadPart
= PartEntry
->StartSector
.QuadPart
;
2588 NewPartEntry
->SectorCount
.QuadPart
= Align(NewPartEntry
->StartSector
.QuadPart
+ SectorCount
, DiskEntry
->SectorAlignment
) -
2589 NewPartEntry
->StartSector
.QuadPart
;
2591 NewPartEntry
->New
= FALSE
;
2592 NewPartEntry
->FormatState
= Formatted
;
2593 NewPartEntry
->BootIndicator
= FALSE
;
2595 if (NewPartEntry
->StartSector
.QuadPart
< 1450560)
2597 /* Partition starts below the 8.4GB boundary ==> CHS partition */
2598 NewPartEntry
->PartitionType
= PARTITION_EXTENDED
;
2602 /* Partition starts above the 8.4GB boundary ==> LBA partition */
2603 NewPartEntry
->PartitionType
= PARTITION_XINT13_EXTENDED
;
2606 DiskEntry
->ExtendedPartition
= NewPartEntry
;
2608 PartEntry
->StartSector
.QuadPart
= NewPartEntry
->StartSector
.QuadPart
+ NewPartEntry
->SectorCount
.QuadPart
;
2609 PartEntry
->SectorCount
.QuadPart
-= (PartEntry
->StartSector
.QuadPart
- NewPartEntry
->StartSector
.QuadPart
);
2611 DPRINT1("First Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
);
2612 DPRINT1("Last Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
+ NewPartEntry
->SectorCount
.QuadPart
- 1);
2613 DPRINT1("Total Sectors: %I64u\n", NewPartEntry
->SectorCount
.QuadPart
);
2616 AddLogicalDiskSpace(DiskEntry
);
2618 UpdateDiskLayout(DiskEntry
);
2620 DiskEntry
->Dirty
= TRUE
;
2622 UpdatePartitionNumbers(DiskEntry
);
2624 AssignDriveLetters(List
);
2629 CreateLogicalPartition(
2631 ULONGLONG SectorCount
)
2633 // PDISKENTRY DiskEntry;
2634 PPARTENTRY PartEntry
;
2635 // PPARTENTRY NewPartEntry;
2637 DPRINT1("CreateLogicalPartition(%I64u)\n", SectorCount
);
2640 List
->CurrentDisk
== NULL
||
2641 List
->CurrentPartition
== NULL
||
2642 List
->CurrentPartition
->IsPartitioned
== TRUE
)
2647 // DiskEntry = List->CurrentDisk;
2648 PartEntry
= List
->CurrentPartition
;
2650 DPRINT1("Current partition sector count: %I64u\n", PartEntry
->SectorCount
.QuadPart
);
2655 DeleteCurrentPartition(
2658 PDISKENTRY DiskEntry
;
2659 PPARTENTRY PartEntry
;
2660 PPARTENTRY PrevPartEntry
;
2661 PPARTENTRY NextPartEntry
;
2662 PPARTENTRY LogicalPartEntry
;
2666 List
->CurrentDisk
== NULL
||
2667 List
->CurrentPartition
== NULL
||
2668 List
->CurrentPartition
->IsPartitioned
== FALSE
)
2673 DiskEntry
= List
->CurrentDisk
;
2674 PartEntry
= List
->CurrentPartition
;
2676 /* Delete all logical partiton entries if an extended partition will be deleted */
2677 if (DiskEntry
->ExtendedPartition
== PartEntry
)
2679 while (!IsListEmpty(&DiskEntry
->LogicalPartListHead
))
2681 Entry
= RemoveHeadList(&DiskEntry
->LogicalPartListHead
);
2682 LogicalPartEntry
= CONTAINING_RECORD(Entry
, PARTENTRY
, ListEntry
);
2684 RtlFreeHeap(ProcessHeap
, 0, LogicalPartEntry
);
2687 DiskEntry
->ExtendedPartition
= NULL
;
2690 /* Adjust unpartitioned disk space entries */
2692 /* Get pointer to previous and next unpartitioned entries */
2693 PrevPartEntry
= GetPrevUnpartitionedEntry(DiskEntry
,
2696 NextPartEntry
= GetNextUnpartitionedEntry(DiskEntry
,
2699 if (PrevPartEntry
!= NULL
&& NextPartEntry
!= NULL
)
2701 /* Merge previous, current and next unpartitioned entry */
2703 /* Adjust the previous entries length */
2704 PrevPartEntry
->SectorCount
.QuadPart
+= (PartEntry
->SectorCount
.QuadPart
+ NextPartEntry
->SectorCount
.QuadPart
);
2706 /* Remove the current entry */
2707 RemoveEntryList(&PartEntry
->ListEntry
);
2708 RtlFreeHeap(ProcessHeap
, 0, PartEntry
);
2710 /* Remove the next entry */
2711 RemoveEntryList (&NextPartEntry
->ListEntry
);
2712 RtlFreeHeap(ProcessHeap
, 0, NextPartEntry
);
2714 /* Update current partition */
2715 List
->CurrentPartition
= PrevPartEntry
;
2717 else if (PrevPartEntry
!= NULL
&& NextPartEntry
== NULL
)
2719 /* Merge current and previous unpartitioned entry */
2721 /* Adjust the previous entries length */
2722 PrevPartEntry
->SectorCount
.QuadPart
+= PartEntry
->SectorCount
.QuadPart
;
2724 /* Remove the current entry */
2725 RemoveEntryList(&PartEntry
->ListEntry
);
2726 RtlFreeHeap(ProcessHeap
, 0, PartEntry
);
2728 /* Update current partition */
2729 List
->CurrentPartition
= PrevPartEntry
;
2731 else if (PrevPartEntry
== NULL
&& NextPartEntry
!= NULL
)
2733 /* Merge current and next unpartitioned entry */
2735 /* Adjust the next entries offset and length */
2736 NextPartEntry
->StartSector
.QuadPart
= PartEntry
->StartSector
.QuadPart
;
2737 NextPartEntry
->SectorCount
.QuadPart
+= PartEntry
->SectorCount
.QuadPart
;
2739 /* Remove the current entry */
2740 RemoveEntryList(&PartEntry
->ListEntry
);
2741 RtlFreeHeap(ProcessHeap
, 0, PartEntry
);
2743 /* Update current partition */
2744 List
->CurrentPartition
= NextPartEntry
;
2748 /* Nothing to merge but change current entry */
2749 PartEntry
->IsPartitioned
= FALSE
;
2750 PartEntry
->PartitionType
= PARTITION_ENTRY_UNUSED
;
2751 PartEntry
->FormatState
= Unformatted
;
2752 PartEntry
->DriveLetter
= 0;
2755 UpdateDiskLayout(DiskEntry
);
2757 DiskEntry
->Dirty
= TRUE
;
2759 UpdatePartitionNumbers(DiskEntry
);
2761 AssignDriveLetters(List
);
2766 CheckActiveBootPartition(
2769 PDISKENTRY DiskEntry
;
2770 PPARTENTRY PartEntry
;
2771 PLIST_ENTRY ListEntry
;
2773 /* Check for empty disk list */
2774 if (IsListEmpty (&List
->DiskListHead
))
2776 List
->BootDisk
= NULL
;
2777 List
->BootPartition
= NULL
;
2782 if (List
->BootDisk
!= NULL
&&
2783 List
->BootPartition
!= NULL
)
2785 /* We already have an active boot partition */
2790 /* Choose the currently selected disk */
2791 DiskEntry
= List
->CurrentDisk
;
2793 /* Check for empty partition list */
2794 if (IsListEmpty (&DiskEntry
->PrimaryPartListHead
))
2796 List
->BootDisk
= NULL
;
2797 List
->BootPartition
= NULL
;
2801 PartEntry
= CONTAINING_RECORD(DiskEntry
->PrimaryPartListHead
.Flink
,
2805 /* Set active boot partition */
2806 if ((DiskEntry
->NewDisk
== TRUE
) ||
2807 (PartEntry
->BootIndicator
== FALSE
))
2809 PartEntry
->BootIndicator
= TRUE
;
2810 DiskEntry
->LayoutBuffer
->PartitionEntry
[PartEntry
->PartitionIndex
].BootIndicator
= TRUE
;
2811 DiskEntry
->LayoutBuffer
->PartitionEntry
[PartEntry
->PartitionIndex
].RewritePartition
= TRUE
;
2812 DiskEntry
->Dirty
= TRUE
;
2814 /* FIXME: Might be incorrect if partitions were created by Linux FDISK */
2815 List
->BootDisk
= DiskEntry
;
2816 List
->BootPartition
= PartEntry
;
2821 /* Disk is not new, scan all partitions to find a bootable one */
2822 List
->BootDisk
= NULL
;
2823 List
->BootPartition
= NULL
;
2825 ListEntry
= DiskEntry
->PrimaryPartListHead
.Flink
;
2826 while (ListEntry
!= &DiskEntry
->PrimaryPartListHead
)
2828 PartEntry
= CONTAINING_RECORD(ListEntry
,
2832 /* Check if it is partitioned */
2833 if (PartEntry
->IsPartitioned
)
2835 if (PartEntry
->PartitionType
!= PARTITION_ENTRY_UNUSED
&&
2836 PartEntry
->BootIndicator
)
2838 /* Yes, we found it */
2839 List
->BootDisk
= DiskEntry
;
2840 List
->BootPartition
= PartEntry
;
2842 DPRINT("Found bootable partition disk %d, drive letter %c\n",
2843 DiskEntry
->DiskNumber
, PartEntry
->DriveLetter
);
2848 /* Go to the next one */
2849 ListEntry
= ListEntry
->Flink
;
2858 IN PDISKENTRY DiskEntry
)
2860 WCHAR DstPath
[MAX_PATH
];
2861 OBJECT_ATTRIBUTES ObjectAttributes
;
2862 IO_STATUS_BLOCK Iosb
;
2863 UNICODE_STRING Name
;
2865 HANDLE FileHandle
= NULL
;
2868 DPRINT("WritePartitions() Disk: %lu\n", DiskEntry
->DiskNumber
);
2871 L
"\\Device\\Harddisk%d\\Partition0",
2872 DiskEntry
->DiskNumber
);
2873 RtlInitUnicodeString(&Name
,
2875 InitializeObjectAttributes(&ObjectAttributes
,
2881 Status
= NtOpenFile(&FileHandle
,
2882 GENERIC_READ
| GENERIC_WRITE
| SYNCHRONIZE
,
2886 FILE_SYNCHRONOUS_IO_NONALERT
);
2887 if (!NT_SUCCESS(Status
))
2889 DPRINT1("NtOpenFile() failed (Status %lx)\n", Status
);
2893 #ifdef DUMP_PARTITION_TABLE
2894 DumpPartitionTable(DiskEntry
);
2897 BufferSize
= sizeof(DRIVE_LAYOUT_INFORMATION
) +
2898 ((DiskEntry
->LayoutBuffer
->PartitionCount
- 1) * sizeof(PARTITION_INFORMATION
));
2899 Status
= NtDeviceIoControlFile(FileHandle
,
2904 IOCTL_DISK_SET_DRIVE_LAYOUT
,
2905 DiskEntry
->LayoutBuffer
,
2909 if (!NT_SUCCESS(Status
))
2911 DPRINT1("IOCTL_DISK_SET_DRIVE_LAYOUT failed (Status 0x%08lx)\n", Status
);
2914 if (FileHandle
!= NULL
)
2915 NtClose(FileHandle
);
2922 WritePartitionsToDisk(
2926 PDISKENTRY DiskEntry
;
2931 Entry
= List
->DiskListHead
.Flink
;
2932 while (Entry
!= &List
->DiskListHead
)
2934 DiskEntry
= CONTAINING_RECORD(Entry
, DISKENTRY
, ListEntry
);
2936 if (DiskEntry
->Dirty
== TRUE
)
2938 WritePartitions(List
, DiskEntry
);
2939 DiskEntry
->Dirty
= FALSE
;
2942 Entry
= Entry
->Flink
;
2950 SetMountedDeviceValues(
2953 PLIST_ENTRY Entry1
, Entry2
;
2954 PDISKENTRY DiskEntry
;
2955 PPARTENTRY PartEntry
;
2956 LARGE_INTEGER StartingOffset
;
2963 Entry1
= List
->DiskListHead
.Flink
;
2964 while (Entry1
!= &List
->DiskListHead
)
2966 DiskEntry
= CONTAINING_RECORD(Entry1
,
2970 Entry2
= DiskEntry
->PrimaryPartListHead
.Flink
;
2971 while (Entry2
!= &DiskEntry
->PrimaryPartListHead
)
2973 PartEntry
= CONTAINING_RECORD(Entry2
, PARTENTRY
, ListEntry
);
2974 if (PartEntry
->IsPartitioned
)
2976 if (PartEntry
->DriveLetter
)
2978 StartingOffset
.QuadPart
= PartEntry
->StartSector
.QuadPart
* DiskEntry
->BytesPerSector
;
2979 if (!SetMountedDeviceValue(PartEntry
->DriveLetter
,
2980 DiskEntry
->LayoutBuffer
->Signature
,
2988 Entry2
= Entry2
->Flink
;
2991 Entry1
= Entry1
->Flink
;
3000 GetPrimaryPartitionCount(
3001 IN PDISKENTRY DiskEntry
)
3004 PPARTENTRY PartEntry
;
3007 Entry
= DiskEntry
->PrimaryPartListHead
.Flink
;
3008 while (Entry
!= &DiskEntry
->PrimaryPartListHead
)
3010 PartEntry
= CONTAINING_RECORD(Entry
, PARTENTRY
, ListEntry
);
3011 if (PartEntry
->IsPartitioned
== TRUE
)
3014 Entry
= Entry
->Flink
;
3022 PrimaryPartitionCreationChecks(
3025 PDISKENTRY DiskEntry
;
3026 PPARTENTRY PartEntry
;
3028 DiskEntry
= List
->CurrentDisk
;
3029 PartEntry
= List
->CurrentPartition
;
3031 /* Fail if partition is already in use */
3032 if (PartEntry
->IsPartitioned
== TRUE
)
3033 return ERROR_NEW_PARTITION
;
3035 /* Fail if there are more than 4 partitions in the list */
3036 if (GetPrimaryPartitionCount(DiskEntry
) > 4)
3037 return ERROR_PARTITION_TABLE_FULL
;
3039 return ERROR_SUCCESS
;
3044 ExtendedPartitionCreationChecks(
3047 PDISKENTRY DiskEntry
;
3048 PPARTENTRY PartEntry
;
3050 DiskEntry
= List
->CurrentDisk
;
3051 PartEntry
= List
->CurrentPartition
;
3053 /* Fail if partition is already in use */
3054 if (PartEntry
->IsPartitioned
== TRUE
)
3055 return ERROR_NEW_PARTITION
;
3057 /* Fail if there are more than 4 partitions in the list */
3058 if (GetPrimaryPartitionCount(DiskEntry
) > 4)
3059 return ERROR_PARTITION_TABLE_FULL
;
3061 /* Fail if there is another extended partition in the list */
3062 if (DiskEntry
->ExtendedPartition
!= NULL
)
3063 return ERROR_ONLY_ONE_EXTENDED
;
3065 return ERROR_SUCCESS
;
3070 LogicalPartitionCreationChecks(
3073 // PDISKENTRY DiskEntry;
3074 PPARTENTRY PartEntry
;
3076 // DiskEntry = List->CurrentDisk;
3077 PartEntry
= List
->CurrentPartition
;
3079 /* Fail if partition is already in use */
3080 if (PartEntry
->IsPartitioned
== TRUE
)
3081 return ERROR_NEW_PARTITION
;
3083 return ERROR_SUCCESS
;
3088 GetNextUnformattedPartition(
3090 OUT PDISKENTRY
*pDiskEntry
,
3091 OUT PPARTENTRY
*pPartEntry
)
3093 PLIST_ENTRY Entry1
, Entry2
;
3094 PDISKENTRY DiskEntry
;
3095 PPARTENTRY PartEntry
;
3097 Entry1
= List
->DiskListHead
.Flink
;
3098 while (Entry1
!= &List
->DiskListHead
)
3100 DiskEntry
= CONTAINING_RECORD(Entry1
,
3104 Entry2
= DiskEntry
->PrimaryPartListHead
.Flink
;
3105 while (Entry2
!= &DiskEntry
->PrimaryPartListHead
)
3107 PartEntry
= CONTAINING_RECORD(Entry2
, PARTENTRY
, ListEntry
);
3108 if (PartEntry
->IsPartitioned
&& PartEntry
->New
)
3110 *pDiskEntry
= DiskEntry
;
3111 *pPartEntry
= PartEntry
;
3115 Entry2
= Entry2
->Flink
;
3118 Entry2
= DiskEntry
->LogicalPartListHead
.Flink
;
3119 while (Entry2
!= &DiskEntry
->LogicalPartListHead
)
3121 PartEntry
= CONTAINING_RECORD(Entry2
, PARTENTRY
, ListEntry
);
3122 if (PartEntry
->IsPartitioned
&& PartEntry
->New
)
3124 *pDiskEntry
= DiskEntry
;
3125 *pPartEntry
= PartEntry
;
3129 Entry2
= Entry2
->Flink
;
3132 Entry1
= Entry1
->Flink
;
3143 GetNextUncheckedPartition(
3145 OUT PDISKENTRY
*pDiskEntry
,
3146 OUT PPARTENTRY
*pPartEntry
)
3148 PLIST_ENTRY Entry1
, Entry2
;
3149 PDISKENTRY DiskEntry
;
3150 PPARTENTRY PartEntry
;
3152 Entry1
= List
->DiskListHead
.Flink
;
3153 while (Entry1
!= &List
->DiskListHead
)
3155 DiskEntry
= CONTAINING_RECORD(Entry1
,
3159 Entry2
= DiskEntry
->PrimaryPartListHead
.Flink
;
3160 while (Entry2
!= &DiskEntry
->PrimaryPartListHead
)
3162 PartEntry
= CONTAINING_RECORD(Entry2
, PARTENTRY
, ListEntry
);
3163 if (PartEntry
->NeedsCheck
== TRUE
)
3165 *pDiskEntry
= DiskEntry
;
3166 *pPartEntry
= PartEntry
;
3170 Entry2
= Entry2
->Flink
;
3173 Entry2
= DiskEntry
->LogicalPartListHead
.Flink
;
3174 while (Entry2
!= &DiskEntry
->LogicalPartListHead
)
3176 PartEntry
= CONTAINING_RECORD(Entry2
, PARTENTRY
, ListEntry
);
3177 if (PartEntry
->NeedsCheck
== TRUE
)
3179 *pDiskEntry
= DiskEntry
;
3180 *pPartEntry
= PartEntry
;
3184 Entry2
= Entry2
->Flink
;
3187 Entry1
= Entry1
->Flink
;