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 DPRINT("\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
);
1155 * Allocate a buffer for 26 logical drives (2 entries each == 52)
1156 * plus the main partiton table (4 entries). Total 56 entries.
1158 LayoutBufferSize
= sizeof(DRIVE_LAYOUT_INFORMATION
) +
1159 ((56 - ANYSIZE_ARRAY
) * sizeof(PARTITION_INFORMATION
));
1160 DiskEntry
->LayoutBuffer
= RtlAllocateHeap(ProcessHeap
,
1163 if (DiskEntry
->LayoutBuffer
== NULL
)
1168 Status
= NtDeviceIoControlFile(FileHandle
,
1173 IOCTL_DISK_GET_DRIVE_LAYOUT
,
1176 DiskEntry
->LayoutBuffer
,
1178 if (NT_SUCCESS(Status
))
1180 #ifdef DUMP_PARTITION_TABLE
1181 DumpPartitionTable(DiskEntry
);
1184 if (DiskEntry
->LayoutBuffer
->PartitionEntry
[0].StartingOffset
.QuadPart
!= 0 &&
1185 DiskEntry
->LayoutBuffer
->PartitionEntry
[0].PartitionLength
.QuadPart
!= 0 &&
1186 DiskEntry
->LayoutBuffer
->PartitionEntry
[0].PartitionType
!= 0)
1188 if ((DiskEntry
->LayoutBuffer
->PartitionEntry
[0].StartingOffset
.QuadPart
/ DiskEntry
->BytesPerSector
) % DiskEntry
->SectorsPerTrack
== 0)
1190 DPRINT("Use %lu Sector alignment!\n", DiskEntry
->SectorsPerTrack
);
1192 else if (DiskEntry
->LayoutBuffer
->PartitionEntry
[0].StartingOffset
.QuadPart
% (1024 * 1024) == 0)
1194 DPRINT1("Use megabyte (%lu Sectors) alignment!\n", (1024 * 1024) / DiskEntry
->BytesPerSector
);
1198 DPRINT1("No matching aligment found! Partiton 1 starts at %I64u\n", DiskEntry
->LayoutBuffer
->PartitionEntry
[0].StartingOffset
.QuadPart
);
1203 DPRINT1("No valid partiton table found! Use megabyte (%lu Sectors) alignment!\n", (1024 * 1024) / DiskEntry
->BytesPerSector
);
1207 if (DiskEntry
->LayoutBuffer
->PartitionCount
== 0)
1209 DiskEntry
->NewDisk
= TRUE
;
1210 DiskEntry
->LayoutBuffer
->PartitionCount
= 4;
1212 for (i
= 0; i
< 4; i
++)
1213 DiskEntry
->LayoutBuffer
->PartitionEntry
[i
].RewritePartition
= TRUE
;
1217 for (i
= 0; i
< 4; i
++)
1219 AddPartitionToDisk(DiskNumber
,
1225 for (i
= 4; i
< DiskEntry
->LayoutBuffer
->PartitionCount
; i
+= 4)
1227 AddPartitionToDisk(DiskNumber
,
1235 ScanForUnpartitionedDiskSpace(DiskEntry
);
1240 CreatePartitionList(
1247 OBJECT_ATTRIBUTES ObjectAttributes
;
1248 SYSTEM_DEVICE_INFORMATION Sdi
;
1249 IO_STATUS_BLOCK Iosb
;
1253 WCHAR Buffer
[MAX_PATH
];
1254 UNICODE_STRING Name
;
1257 List
= (PPARTLIST
)RtlAllocateHeap(ProcessHeap
,
1265 List
->Right
= Right
;
1266 List
->Bottom
= Bottom
;
1271 List
->TopDisk
= (ULONG
)-1;
1272 List
->TopPartition
= (ULONG
)-1;
1274 List
->CurrentDisk
= NULL
;
1275 List
->CurrentPartition
= NULL
;
1277 InitializeListHead(&List
->DiskListHead
);
1278 InitializeListHead(&List
->BiosDiskListHead
);
1280 EnumerateBiosDiskEntries(List
);
1282 Status
= NtQuerySystemInformation(SystemDeviceInformation
,
1284 sizeof(SYSTEM_DEVICE_INFORMATION
),
1286 if (!NT_SUCCESS(Status
))
1288 RtlFreeHeap(ProcessHeap
, 0, List
);
1292 for (DiskNumber
= 0; DiskNumber
< Sdi
.NumberOfDisks
; DiskNumber
++)
1295 L
"\\Device\\Harddisk%d\\Partition0",
1297 RtlInitUnicodeString(&Name
,
1300 InitializeObjectAttributes(&ObjectAttributes
,
1306 Status
= NtOpenFile(&FileHandle
,
1307 FILE_READ_DATA
| FILE_READ_ATTRIBUTES
| SYNCHRONIZE
,
1311 FILE_SYNCHRONOUS_IO_NONALERT
);
1312 if (NT_SUCCESS(Status
))
1314 AddDiskToList(FileHandle
,
1318 NtClose(FileHandle
);
1322 UpdateDiskSignatures(List
);
1324 AssignDriveLetters(List
);
1327 List
->TopPartition
= 0;
1329 /* Search for first usable disk and partition */
1330 if (IsListEmpty(&List
->DiskListHead
))
1332 List
->CurrentDisk
= NULL
;
1333 List
->CurrentPartition
= NULL
;
1337 List
->CurrentDisk
= CONTAINING_RECORD(List
->DiskListHead
.Flink
,
1341 if (IsListEmpty(&List
->CurrentDisk
->PrimaryPartListHead
))
1343 List
->CurrentPartition
= 0;
1347 List
->CurrentPartition
= CONTAINING_RECORD(List
->CurrentDisk
->PrimaryPartListHead
.Flink
,
1358 DestroyPartitionList(
1361 PDISKENTRY DiskEntry
;
1362 PBIOSDISKENTRY BiosDiskEntry
;
1363 PPARTENTRY PartEntry
;
1366 /* Release disk and partition info */
1367 while (!IsListEmpty(&List
->DiskListHead
))
1369 Entry
= RemoveHeadList(&List
->DiskListHead
);
1370 DiskEntry
= CONTAINING_RECORD(Entry
, DISKENTRY
, ListEntry
);
1372 /* Release driver name */
1373 RtlFreeUnicodeString(&DiskEntry
->DriverName
);
1375 /* Release primary partition list */
1376 while (!IsListEmpty(&DiskEntry
->PrimaryPartListHead
))
1378 Entry
= RemoveHeadList(&DiskEntry
->PrimaryPartListHead
);
1379 PartEntry
= CONTAINING_RECORD(Entry
, PARTENTRY
, ListEntry
);
1381 RtlFreeHeap(ProcessHeap
, 0, PartEntry
);
1384 /* Release logical partition list */
1385 while (!IsListEmpty(&DiskEntry
->LogicalPartListHead
))
1387 Entry
= RemoveHeadList(&DiskEntry
->LogicalPartListHead
);
1388 PartEntry
= CONTAINING_RECORD(Entry
, PARTENTRY
, ListEntry
);
1390 RtlFreeHeap(ProcessHeap
, 0, PartEntry
);
1393 /* Release layout buffer */
1394 if (DiskEntry
->LayoutBuffer
!= NULL
)
1395 RtlFreeHeap(ProcessHeap
, 0, DiskEntry
->LayoutBuffer
);
1398 /* Release disk entry */
1399 RtlFreeHeap(ProcessHeap
, 0, DiskEntry
);
1402 /* release the bios disk info */
1403 while(!IsListEmpty(&List
->BiosDiskListHead
))
1405 Entry
= RemoveHeadList(&List
->BiosDiskListHead
);
1406 BiosDiskEntry
= CONTAINING_RECORD(Entry
, BIOSDISKENTRY
, ListEntry
);
1408 RtlFreeHeap(ProcessHeap
, 0, BiosDiskEntry
);
1411 /* Release list head */
1412 RtlFreeHeap(ProcessHeap
, 0, List
);
1426 Width
= List
->Right
- List
->Left
- 1;
1427 Height
= List
->Bottom
- List
->Top
- 2;
1429 coPos
.X
= List
->Left
+ 1;
1430 coPos
.Y
= List
->Top
+ 1 + List
->Line
;
1432 if (List
->Line
>= 0 && List
->Line
<= Height
)
1434 FillConsoleOutputAttribute(StdOutput
,
1435 FOREGROUND_WHITE
| BACKGROUND_BLUE
,
1440 FillConsoleOutputCharacterA(StdOutput
,
1455 PDISKENTRY DiskEntry
,
1456 PPARTENTRY PartEntry
)
1458 CHAR LineBuffer
[128];
1463 LARGE_INTEGER PartSize
;
1468 Width
= List
->Right
- List
->Left
- 1;
1469 Height
= List
->Bottom
- List
->Top
- 2;
1471 coPos
.X
= List
->Left
+ 1;
1472 coPos
.Y
= List
->Top
+ 1 + List
->Line
;
1474 if (PartEntry
->IsPartitioned
== FALSE
)
1476 PartSize
.QuadPart
= PartEntry
->SectorCount
.QuadPart
* DiskEntry
->BytesPerSector
;
1478 if (PartSize
.QuadPart
>= 10737418240) /* 10 GB */
1480 PartSize
.QuadPart
= RoundingDivide(PartSize
.QuadPart
, 1073741824);
1481 Unit
= MUIGetString(STRING_GB
);
1485 if (PartSize
.QuadPart
>= 10485760) /* 10 MB */
1487 PartSize
.QuadPart
= RoundingDivide(PartSize
.QuadPart
, 1048576);
1488 Unit
= MUIGetString(STRING_MB
);
1492 PartSize
.QuadPart
= RoundingDivide(PartSize
.QuadPart
, 1024);
1493 Unit
= MUIGetString(STRING_KB
);
1497 MUIGetString(STRING_UNPSPACE
),
1498 PartEntry
->LogicalPartition
? " " : "",
1499 PartEntry
->LogicalPartition
? "" : " ",
1505 /* Determine partition type */
1507 if (PartEntry
->New
== TRUE
)
1509 PartType
= MUIGetString(STRING_UNFORMATTED
);
1511 else if (PartEntry
->IsPartitioned
== TRUE
)
1513 if ((PartEntry
->PartitionType
== PARTITION_FAT_12
) ||
1514 (PartEntry
->PartitionType
== PARTITION_FAT_16
) ||
1515 (PartEntry
->PartitionType
== PARTITION_HUGE
) ||
1516 (PartEntry
->PartitionType
== PARTITION_XINT13
))
1520 else if ((PartEntry
->PartitionType
== PARTITION_FAT32
) ||
1521 (PartEntry
->PartitionType
== PARTITION_FAT32_XINT13
))
1525 else if (PartEntry
->PartitionType
== PARTITION_EXT2
)
1529 else if (PartEntry
->PartitionType
== PARTITION_IFS
)
1531 PartType
= "NTFS"; /* FIXME: Not quite correct! */
1533 else if ((PartEntry
->PartitionType
== PARTITION_EXTENDED
) ||
1534 (PartEntry
->PartitionType
== PARTITION_XINT13_EXTENDED
))
1536 PartType
= MUIGetString(STRING_EXTENDED_PARTITION
);
1540 PartSize
.QuadPart
= PartEntry
->SectorCount
.QuadPart
* DiskEntry
->BytesPerSector
;
1542 if (PartSize
.QuadPart
>= 10737418240) /* 10 GB */
1544 PartSize
.QuadPart
= RoundingDivide(PartSize
.QuadPart
, 1073741824);
1545 Unit
= MUIGetString(STRING_GB
);
1549 if (PartSize
.QuadPart
>= 10485760) /* 10 MB */
1551 PartSize
.QuadPart
= RoundingDivide(PartSize
.QuadPart
, 1048576);
1552 Unit
= MUIGetString(STRING_MB
);
1556 PartSize
.QuadPart
= RoundingDivide(PartSize
.QuadPart
, 1024);
1557 Unit
= MUIGetString(STRING_KB
);
1560 if (PartType
== NULL
)
1563 MUIGetString(STRING_HDDINFOUNK5
),
1564 (PartEntry
->DriveLetter
== 0) ? '-' : PartEntry
->DriveLetter
,
1565 (PartEntry
->DriveLetter
== 0) ? '-' : ':',
1566 PartEntry
->BootIndicator
? '*' : ' ',
1567 PartEntry
->LogicalPartition
? " " : "",
1568 PartEntry
->PartitionType
,
1569 PartEntry
->LogicalPartition
? "" : " ",
1576 "%c%c %c %s%-24s%s %6lu %s",
1577 (PartEntry
->DriveLetter
== 0) ? '-' : PartEntry
->DriveLetter
,
1578 (PartEntry
->DriveLetter
== 0) ? '-' : ':',
1579 PartEntry
->BootIndicator
? '*' : ' ',
1580 PartEntry
->LogicalPartition
? " " : "",
1582 PartEntry
->LogicalPartition
? "" : " ",
1588 Attribute
= (List
->CurrentDisk
== DiskEntry
&&
1589 List
->CurrentPartition
== PartEntry
) ?
1590 FOREGROUND_BLUE
| BACKGROUND_WHITE
:
1591 FOREGROUND_WHITE
| BACKGROUND_BLUE
;
1593 if (List
->Line
>= 0 && List
->Line
<= Height
)
1595 FillConsoleOutputCharacterA(StdOutput
,
1603 if (List
->Line
>= 0 && List
->Line
<= Height
)
1605 FillConsoleOutputAttribute(StdOutput
,
1613 if (List
->Line
>= 0 && List
->Line
<= Height
)
1615 WriteConsoleOutputCharacterA(StdOutput
,
1617 min(strlen(LineBuffer
), Width
),
1630 PDISKENTRY DiskEntry
)
1632 PPARTENTRY PrimaryPartEntry
, LogicalPartEntry
;
1633 PLIST_ENTRY PrimaryEntry
, LogicalEntry
;
1634 CHAR LineBuffer
[128];
1639 ULARGE_INTEGER DiskSize
;
1642 Width
= List
->Right
- List
->Left
- 1;
1643 Height
= List
->Bottom
- List
->Top
- 2;
1645 coPos
.X
= List
->Left
+ 1;
1646 coPos
.Y
= List
->Top
+ 1 + List
->Line
;
1648 DiskSize
.QuadPart
= DiskEntry
->SectorCount
.QuadPart
* DiskEntry
->BytesPerSector
;
1649 if (DiskSize
.QuadPart
>= 10737418240) /* 10 GB */
1651 DiskSize
.QuadPart
= RoundingDivide(DiskSize
.QuadPart
, 1073741824);
1652 Unit
= MUIGetString(STRING_GB
);
1656 DiskSize
.QuadPart
= RoundingDivide(DiskSize
.QuadPart
, 1048576);
1657 if (DiskSize
.QuadPart
== 0)
1658 DiskSize
.QuadPart
= 1;
1659 Unit
= MUIGetString(STRING_MB
);
1662 if (DiskEntry
->DriverName
.Length
> 0)
1665 MUIGetString(STRING_HDINFOPARTSELECT
),
1668 DiskEntry
->DiskNumber
,
1672 DiskEntry
->DriverName
.Buffer
);
1677 MUIGetString(STRING_HDDINFOUNK6
),
1680 DiskEntry
->DiskNumber
,
1686 if (List
->Line
>= 0 && List
->Line
<= Height
)
1688 FillConsoleOutputAttribute(StdOutput
,
1689 FOREGROUND_WHITE
| BACKGROUND_BLUE
,
1694 FillConsoleOutputCharacterA(StdOutput
,
1702 if (List
->Line
>= 0 && List
->Line
<= Height
)
1704 WriteConsoleOutputCharacterA(StdOutput
,
1706 min((USHORT
)strlen(LineBuffer
), Width
- 2),
1713 /* Print separator line */
1714 PrintEmptyLine(List
);
1716 /* Print partition lines*/
1717 PrimaryEntry
= DiskEntry
->PrimaryPartListHead
.Flink
;
1718 while (PrimaryEntry
!= &DiskEntry
->PrimaryPartListHead
)
1720 PrimaryPartEntry
= CONTAINING_RECORD(PrimaryEntry
, PARTENTRY
, ListEntry
);
1722 PrintPartitionData(List
,
1726 if (IsContainerPartition(PrimaryPartEntry
->PartitionType
))
1728 LogicalEntry
= DiskEntry
->LogicalPartListHead
.Flink
;
1729 while (LogicalEntry
!= &DiskEntry
->LogicalPartListHead
)
1731 LogicalPartEntry
= CONTAINING_RECORD(LogicalEntry
, PARTENTRY
, ListEntry
);
1733 PrintPartitionData(List
,
1737 LogicalEntry
= LogicalEntry
->Flink
;
1741 PrimaryEntry
= PrimaryEntry
->Flink
;
1744 /* Print separator line */
1745 PrintEmptyLine(List
);
1753 PLIST_ENTRY Entry
, Entry2
;
1754 PDISKENTRY DiskEntry
;
1755 PPARTENTRY PartEntry
= NULL
;
1759 SHORT CurrentDiskLine
;
1760 SHORT CurrentPartLine
;
1762 BOOL CurrentPartLineFound
= FALSE
;
1763 BOOL CurrentDiskLineFound
= FALSE
;
1765 /* Calculate the line of the current disk and partition */
1766 CurrentDiskLine
= 0;
1767 CurrentPartLine
= 0;
1770 Entry
= List
->DiskListHead
.Flink
;
1771 while (Entry
!= &List
->DiskListHead
)
1773 DiskEntry
= CONTAINING_RECORD(Entry
, DISKENTRY
, ListEntry
);
1776 if (CurrentPartLineFound
== FALSE
)
1778 CurrentPartLine
+= 2;
1781 Entry2
= DiskEntry
->PrimaryPartListHead
.Flink
;
1782 while (Entry2
!= &DiskEntry
->PrimaryPartListHead
)
1784 PartEntry
= CONTAINING_RECORD(Entry2
, PARTENTRY
, ListEntry
);
1785 if (PartEntry
== List
->CurrentPartition
)
1787 CurrentPartLineFound
= TRUE
;
1790 Entry2
= Entry2
->Flink
;
1791 if (CurrentPartLineFound
== FALSE
)
1799 if (DiskEntry
== List
->CurrentDisk
)
1801 CurrentDiskLineFound
= TRUE
;
1804 Entry
= Entry
->Flink
;
1805 if (Entry
!= &List
->DiskListHead
)
1807 if (CurrentDiskLineFound
== FALSE
)
1810 CurrentDiskLine
= CurrentPartLine
;
1821 /* If it possible, make the disk name visible */
1822 if (CurrentPartLine
< List
->Offset
)
1824 List
->Offset
= CurrentPartLine
;
1826 else if (CurrentPartLine
- List
->Offset
> List
->Bottom
- List
->Top
- 2)
1828 List
->Offset
= CurrentPartLine
- (List
->Bottom
- List
->Top
- 2);
1831 if (CurrentDiskLine
< List
->Offset
&& CurrentPartLine
- CurrentDiskLine
< List
->Bottom
- List
->Top
- 2)
1833 List
->Offset
= CurrentDiskLine
;
1836 /* draw upper left corner */
1837 coPos
.X
= List
->Left
;
1838 coPos
.Y
= List
->Top
;
1839 FillConsoleOutputCharacterA(StdOutput
,
1845 /* draw upper edge */
1846 coPos
.X
= List
->Left
+ 1;
1847 coPos
.Y
= List
->Top
;
1848 if (List
->Offset
== 0)
1850 FillConsoleOutputCharacterA(StdOutput
,
1852 List
->Right
- List
->Left
- 1,
1858 FillConsoleOutputCharacterA(StdOutput
,
1860 List
->Right
- List
->Left
- 5,
1863 coPos
.X
= List
->Right
- 5;
1864 WriteConsoleOutputCharacterA(StdOutput
,
1869 coPos
.X
= List
->Right
- 2;
1870 FillConsoleOutputCharacterA(StdOutput
,
1877 /* draw upper right corner */
1878 coPos
.X
= List
->Right
;
1879 coPos
.Y
= List
->Top
;
1880 FillConsoleOutputCharacterA(StdOutput
,
1886 /* draw left and right edge */
1887 for (i
= List
->Top
+ 1; i
< List
->Bottom
; i
++)
1889 coPos
.X
= List
->Left
;
1891 FillConsoleOutputCharacterA(StdOutput
,
1897 coPos
.X
= List
->Right
;
1898 FillConsoleOutputCharacterA(StdOutput
,
1905 /* draw lower left corner */
1906 coPos
.X
= List
->Left
;
1907 coPos
.Y
= List
->Bottom
;
1908 FillConsoleOutputCharacterA(StdOutput
,
1914 /* draw lower edge */
1915 coPos
.X
= List
->Left
+ 1;
1916 coPos
.Y
= List
->Bottom
;
1917 if (LastLine
- List
->Offset
<= List
->Bottom
- List
->Top
- 2)
1919 FillConsoleOutputCharacterA(StdOutput
,
1921 List
->Right
- List
->Left
- 1,
1927 FillConsoleOutputCharacterA(StdOutput
,
1929 List
->Right
- List
->Left
- 5,
1932 coPos
.X
= List
->Right
- 5;
1933 WriteConsoleOutputCharacterA(StdOutput
,
1934 "(\x19)", // "(down)"
1938 coPos
.X
= List
->Right
- 2;
1939 FillConsoleOutputCharacterA(StdOutput
,
1946 /* draw lower right corner */
1947 coPos
.X
= List
->Right
;
1948 coPos
.Y
= List
->Bottom
;
1949 FillConsoleOutputCharacterA(StdOutput
,
1955 /* print list entries */
1956 List
->Line
= - List
->Offset
;
1958 Entry
= List
->DiskListHead
.Flink
;
1959 while (Entry
!= &List
->DiskListHead
)
1961 DiskEntry
= CONTAINING_RECORD(Entry
, DISKENTRY
, ListEntry
);
1963 /* Print disk entry */
1967 Entry
= Entry
->Flink
;
1976 ULONG PartitionNumber
)
1978 PDISKENTRY DiskEntry
;
1979 PPARTENTRY PartEntry
;
1983 /* Check for empty disks */
1984 if (IsListEmpty(&List
->DiskListHead
))
1987 /* Check for first usable entry on next disk */
1988 Entry1
= List
->CurrentDisk
->ListEntry
.Flink
;
1989 while (Entry1
!= &List
->DiskListHead
)
1991 DiskEntry
= CONTAINING_RECORD(Entry1
, DISKENTRY
, ListEntry
);
1993 if (DiskEntry
->DiskNumber
== DiskNumber
)
1995 Entry2
= DiskEntry
->PrimaryPartListHead
.Flink
;
1996 while (Entry2
!= &DiskEntry
->PrimaryPartListHead
)
1998 PartEntry
= CONTAINING_RECORD(Entry2
, PARTENTRY
, ListEntry
);
2000 if (PartEntry
->PartitionNumber
== PartitionNumber
)
2002 List
->CurrentDisk
= DiskEntry
;
2003 List
->CurrentPartition
= PartEntry
;
2004 DrawPartitionList(List
);
2008 Entry2
= Entry2
->Flink
;
2014 Entry1
= Entry1
->Flink
;
2022 ScrollDownPartitionList(
2025 PLIST_ENTRY DiskListEntry
;
2026 PLIST_ENTRY PartListEntry
;
2027 PDISKENTRY DiskEntry
;
2028 PPARTENTRY PartEntry
;
2030 /* Fail, if no disks are available */
2031 if (IsListEmpty(&List
->DiskListHead
))
2034 /* Check for next usable entry on current disk */
2035 if (List
->CurrentPartition
!= NULL
)
2037 if (List
->CurrentPartition
->LogicalPartition
)
2039 /* Logical partition */
2041 PartListEntry
= List
->CurrentPartition
->ListEntry
.Flink
;
2042 if (PartListEntry
!= &List
->CurrentDisk
->LogicalPartListHead
)
2044 /* Next logical partition */
2045 PartEntry
= CONTAINING_RECORD(PartListEntry
, PARTENTRY
, ListEntry
);
2047 List
->CurrentPartition
= PartEntry
;
2052 PartListEntry
= List
->CurrentDisk
->ExtendedPartition
->ListEntry
.Flink
;
2053 if (PartListEntry
!= &List
->CurrentDisk
->PrimaryPartListHead
)
2055 PartEntry
= CONTAINING_RECORD(PartListEntry
, PARTENTRY
, ListEntry
);
2057 List
->CurrentPartition
= PartEntry
;
2064 /* Primary or extended partition */
2066 if (List
->CurrentPartition
->IsPartitioned
== TRUE
&&
2067 IsContainerPartition(List
->CurrentPartition
->PartitionType
))
2069 /* First logical partition */
2070 PartListEntry
= List
->CurrentDisk
->LogicalPartListHead
.Flink
;
2071 if (PartListEntry
!= &List
->CurrentDisk
->LogicalPartListHead
)
2073 PartEntry
= CONTAINING_RECORD(PartListEntry
, PARTENTRY
, ListEntry
);
2075 List
->CurrentPartition
= PartEntry
;
2081 /* Next primary partition */
2082 PartListEntry
= List
->CurrentPartition
->ListEntry
.Flink
;
2083 if (PartListEntry
!= &List
->CurrentDisk
->PrimaryPartListHead
)
2085 PartEntry
= CONTAINING_RECORD(PartListEntry
, PARTENTRY
, ListEntry
);
2087 List
->CurrentPartition
= PartEntry
;
2094 /* Search for the first partition entry on the next disk */
2095 DiskListEntry
= List
->CurrentDisk
->ListEntry
.Flink
;
2096 while (DiskListEntry
!= &List
->DiskListHead
)
2098 DiskEntry
= CONTAINING_RECORD(DiskListEntry
, DISKENTRY
, ListEntry
);
2100 PartListEntry
= DiskEntry
->PrimaryPartListHead
.Flink
;
2101 if (PartListEntry
!= &DiskEntry
->PrimaryPartListHead
)
2103 PartEntry
= CONTAINING_RECORD(PartListEntry
, PARTENTRY
, ListEntry
);
2105 List
->CurrentDisk
= DiskEntry
;
2106 List
->CurrentPartition
= PartEntry
;
2110 DiskListEntry
= DiskListEntry
->Flink
;
2118 ScrollUpPartitionList(
2121 PLIST_ENTRY DiskListEntry
;
2122 PLIST_ENTRY PartListEntry
;
2123 PDISKENTRY DiskEntry
;
2124 PPARTENTRY PartEntry
;
2126 /* Fail, if no disks are available */
2127 if (IsListEmpty(&List
->DiskListHead
))
2130 /* Check for previous usable entry on current disk */
2131 if (List
->CurrentPartition
!= NULL
)
2133 if (List
->CurrentPartition
->LogicalPartition
)
2135 /* Logical partition */
2136 PartListEntry
= List
->CurrentPartition
->ListEntry
.Blink
;
2137 if (PartListEntry
!= &List
->CurrentDisk
->LogicalPartListHead
)
2139 /* Previous logical partition */
2140 PartEntry
= CONTAINING_RECORD(PartListEntry
, PARTENTRY
, ListEntry
);
2144 /* Extended partition*/
2145 PartEntry
= List
->CurrentDisk
->ExtendedPartition
;
2148 List
->CurrentPartition
= PartEntry
;
2153 /* Primary or extended partition */
2155 PartListEntry
= List
->CurrentPartition
->ListEntry
.Blink
;
2156 if (PartListEntry
!= &List
->CurrentDisk
->PrimaryPartListHead
)
2158 PartEntry
= CONTAINING_RECORD(PartListEntry
, PARTENTRY
, ListEntry
);
2160 if (PartEntry
->IsPartitioned
== TRUE
&&
2161 IsContainerPartition(PartEntry
->PartitionType
))
2163 PartListEntry
= List
->CurrentDisk
->LogicalPartListHead
.Blink
;
2164 PartEntry
= CONTAINING_RECORD(PartListEntry
, PARTENTRY
, ListEntry
);
2167 List
->CurrentPartition
= PartEntry
;
2174 /* Search for the last partition entry on the previous disk */
2175 DiskListEntry
= List
->CurrentDisk
->ListEntry
.Blink
;
2176 while (DiskListEntry
!= &List
->DiskListHead
)
2178 DiskEntry
= CONTAINING_RECORD(DiskListEntry
, DISKENTRY
, ListEntry
);
2180 PartListEntry
= DiskEntry
->PrimaryPartListHead
.Blink
;
2181 if (PartListEntry
!= &DiskEntry
->PrimaryPartListHead
)
2183 PartEntry
= CONTAINING_RECORD(PartListEntry
, PARTENTRY
, ListEntry
);
2185 if (PartEntry
->IsPartitioned
== TRUE
&&
2186 IsContainerPartition(PartEntry
->PartitionType
))
2188 PartListEntry
= DiskEntry
->LogicalPartListHead
.Blink
;
2189 if (PartListEntry
!= &DiskEntry
->LogicalPartListHead
)
2191 PartEntry
= CONTAINING_RECORD(PartListEntry
, PARTENTRY
, ListEntry
);
2193 List
->CurrentDisk
= DiskEntry
;
2194 List
->CurrentPartition
= PartEntry
;
2200 List
->CurrentDisk
= DiskEntry
;
2201 List
->CurrentPartition
= PartEntry
;
2206 DiskListEntry
= DiskListEntry
->Blink
;
2216 PPARTITION_INFORMATION PartitionInfo
)
2218 if (PartitionInfo
->StartingOffset
.QuadPart
== 0 &&
2219 PartitionInfo
->PartitionLength
.QuadPart
== 0)
2220 // PartitionInfo->PartitionType == 0)
2229 IsSamePrimaryLayoutEntry(
2230 IN PPARTITION_INFORMATION PartitionInfo
,
2231 IN PDISKENTRY DiskEntry
,
2232 IN PPARTENTRY PartEntry
)
2234 if (PartitionInfo
->StartingOffset
.QuadPart
== PartEntry
->StartSector
.QuadPart
* DiskEntry
->BytesPerSector
&&
2235 PartitionInfo
->PartitionLength
.QuadPart
== PartEntry
->SectorCount
.QuadPart
* DiskEntry
->BytesPerSector
)
2236 // PartitionInfo->PartitionNumber = PartEntry->PartitionNumber &&
2237 // PartitionInfo->PartitionType == PartEntry->PartitionType
2247 IN PDISKENTRY DiskEntry
)
2249 PPARTITION_INFORMATION PartitionInfo
;
2250 PLIST_ENTRY ListEntry
;
2251 PPARTENTRY PartEntry
;
2253 ULONG PartitionNumber
= 1;
2255 DPRINT1("UpdateDiskLayout()\n");
2257 ListEntry
= DiskEntry
->PrimaryPartListHead
.Flink
;
2258 while (ListEntry
!= &DiskEntry
->PrimaryPartListHead
)
2260 PartEntry
= CONTAINING_RECORD(ListEntry
, PARTENTRY
, ListEntry
);
2262 if (PartEntry
->IsPartitioned
== TRUE
)
2264 PartitionInfo
= &DiskEntry
->LayoutBuffer
->PartitionEntry
[Index
];
2266 if (!IsSamePrimaryLayoutEntry(PartitionInfo
, DiskEntry
, PartEntry
))
2268 DPRINT1("Updating partition entry %lu\n", Index
);
2270 PartitionInfo
->StartingOffset
.QuadPart
= PartEntry
->StartSector
.QuadPart
* DiskEntry
->BytesPerSector
;
2271 PartitionInfo
->PartitionLength
.QuadPart
= PartEntry
->SectorCount
.QuadPart
* DiskEntry
->BytesPerSector
;
2272 PartitionInfo
->HiddenSectors
= 0;
2273 PartitionInfo
->PartitionNumber
= (!IsContainerPartition(PartEntry
->PartitionType
)) ? PartitionNumber
: 0;
2274 PartitionInfo
->PartitionType
= PartEntry
->PartitionType
;
2275 PartitionInfo
->BootIndicator
= PartEntry
->BootIndicator
;
2276 PartitionInfo
->RecognizedPartition
= FALSE
;
2277 PartitionInfo
->RewritePartition
= TRUE
;
2279 PartEntry
->PartitionNumber
= PartitionNumber
;
2280 PartEntry
->PartitionIndex
= Index
;
2284 else if (!IsEmptyLayoutEntry(PartitionInfo
))
2292 ListEntry
= ListEntry
->Flink
;
2295 for (;Index
< 4; Index
++)
2297 PartitionInfo
= &DiskEntry
->LayoutBuffer
->PartitionEntry
[Index
];
2299 if (!IsEmptyLayoutEntry(PartitionInfo
))
2301 DPRINT1("Wiping partition entry %lu\n", Index
);
2303 PartitionInfo
->StartingOffset
.QuadPart
= 0;
2304 PartitionInfo
->PartitionLength
.QuadPart
= 0;
2305 PartitionInfo
->HiddenSectors
= 0;
2306 PartitionInfo
->PartitionNumber
= 0;
2307 PartitionInfo
->PartitionType
= 0;
2308 PartitionInfo
->BootIndicator
= FALSE
;
2309 PartitionInfo
->RecognizedPartition
= FALSE
;
2310 PartitionInfo
->RewritePartition
= TRUE
;
2314 #ifdef DUMP_PARTITION_TABLE
2315 DumpPartitionTable(DiskEntry
);
2322 GetPrevUnpartitionedEntry(
2323 PDISKENTRY DiskEntry
,
2324 PPARTENTRY PartEntry
)
2326 PPARTENTRY PrevPartEntry
;
2328 if (PartEntry
->ListEntry
.Blink
!= &DiskEntry
->PrimaryPartListHead
)
2330 PrevPartEntry
= CONTAINING_RECORD(PartEntry
->ListEntry
.Blink
,
2333 if (PrevPartEntry
->IsPartitioned
== FALSE
)
2334 return PrevPartEntry
;
2343 GetNextUnpartitionedEntry(
2344 PDISKENTRY DiskEntry
,
2345 PPARTENTRY PartEntry
)
2347 PPARTENTRY NextPartEntry
;
2349 if (PartEntry
->ListEntry
.Flink
!= &DiskEntry
->PrimaryPartListHead
)
2351 NextPartEntry
= CONTAINING_RECORD(PartEntry
->ListEntry
.Flink
,
2354 if (NextPartEntry
->IsPartitioned
== FALSE
)
2355 return NextPartEntry
;
2363 CreatePrimaryPartition(
2365 ULONGLONG SectorCount
,
2368 PDISKENTRY DiskEntry
;
2369 PPARTENTRY PartEntry
;
2370 PPARTENTRY NewPartEntry
;
2372 DPRINT1("CreatePrimaryPartition(%I64u)\n", SectorCount
);
2375 List
->CurrentDisk
== NULL
||
2376 List
->CurrentPartition
== NULL
||
2377 List
->CurrentPartition
->IsPartitioned
== TRUE
)
2382 DiskEntry
= List
->CurrentDisk
;
2383 PartEntry
= List
->CurrentPartition
;
2385 DPRINT1("Current partition sector count: %I64u\n", PartEntry
->SectorCount
.QuadPart
);
2387 if (AutoCreate
== TRUE
||
2388 Align(PartEntry
->StartSector
.QuadPart
+ SectorCount
, DiskEntry
->SectorAlignment
) - PartEntry
->StartSector
.QuadPart
== PartEntry
->SectorCount
.QuadPart
)
2390 DPRINT1("Convert existing partition entry\n");
2392 /* Convert current entry to 'new (unformatted)' */
2393 PartEntry
->IsPartitioned
= TRUE
;
2394 PartEntry
->PartitionType
= PARTITION_ENTRY_UNUSED
;
2395 PartEntry
->FormatState
= Unformatted
;
2396 PartEntry
->AutoCreate
= AutoCreate
;
2397 PartEntry
->New
= TRUE
;
2398 PartEntry
->BootIndicator
= FALSE
;
2400 DPRINT1("First Sector: %I64u\n", PartEntry
->StartSector
.QuadPart
);
2401 DPRINT1("Last Sector: %I64u\n", PartEntry
->StartSector
.QuadPart
+ PartEntry
->SectorCount
.QuadPart
- 1);
2402 DPRINT1("Total Sectors: %I64u\n", PartEntry
->SectorCount
.QuadPart
);
2406 DPRINT1("Add new partition entry\n");
2408 /* Insert and initialize a new partition entry */
2409 NewPartEntry
= RtlAllocateHeap(ProcessHeap
,
2412 if (NewPartEntry
== NULL
)
2415 /* Insert the new entry into the list */
2416 InsertTailList(&PartEntry
->ListEntry
,
2417 &NewPartEntry
->ListEntry
);
2419 NewPartEntry
->DiskEntry
= DiskEntry
;
2421 NewPartEntry
->IsPartitioned
= TRUE
;
2422 NewPartEntry
->StartSector
.QuadPart
= PartEntry
->StartSector
.QuadPart
;
2423 NewPartEntry
->SectorCount
.QuadPart
= Align(NewPartEntry
->StartSector
.QuadPart
+ SectorCount
, DiskEntry
->SectorAlignment
) -
2424 NewPartEntry
->StartSector
.QuadPart
;
2425 NewPartEntry
->PartitionType
= PARTITION_ENTRY_UNUSED
;
2427 DPRINT1("First Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
);
2428 DPRINT1("Last Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
+ NewPartEntry
->SectorCount
.QuadPart
- 1);
2429 DPRINT1("Total Sectors: %I64u\n", NewPartEntry
->SectorCount
.QuadPart
);
2431 NewPartEntry
->New
= TRUE
;
2432 NewPartEntry
->FormatState
= Unformatted
;
2433 NewPartEntry
->BootIndicator
= FALSE
;
2435 PartEntry
->StartSector
.QuadPart
= NewPartEntry
->StartSector
.QuadPart
+ NewPartEntry
->SectorCount
.QuadPart
;
2436 PartEntry
->SectorCount
.QuadPart
-= (PartEntry
->StartSector
.QuadPart
- NewPartEntry
->StartSector
.QuadPart
);
2439 UpdateDiskLayout(DiskEntry
);
2441 DiskEntry
->Dirty
= TRUE
;
2443 UpdatePartitionNumbers(DiskEntry
);
2445 AssignDriveLetters(List
);
2451 AddLogicalDiskSpace(
2452 PDISKENTRY DiskEntry
)
2454 PPARTENTRY NewPartEntry
;
2456 DPRINT1("AddLogicalDiskSpace()\n");
2458 /* Create a partition table entry that represents the empty space in the container partition */
2459 NewPartEntry
= RtlAllocateHeap(ProcessHeap
,
2462 if (NewPartEntry
== NULL
)
2465 NewPartEntry
->DiskEntry
= DiskEntry
;
2466 NewPartEntry
->LogicalPartition
= TRUE
;
2468 NewPartEntry
->IsPartitioned
= FALSE
;
2469 NewPartEntry
->StartSector
.QuadPart
= DiskEntry
->ExtendedPartition
->StartSector
.QuadPart
+ (ULONGLONG
)DiskEntry
->SectorAlignment
;
2470 NewPartEntry
->SectorCount
.QuadPart
= DiskEntry
->ExtendedPartition
->SectorCount
.QuadPart
- (ULONGLONG
)DiskEntry
->SectorAlignment
;
2472 DPRINT1("First Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
);
2473 DPRINT1("Last Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
+ NewPartEntry
->SectorCount
.QuadPart
- 1);
2474 DPRINT1("Total Sectors: %I64u\n", NewPartEntry
->SectorCount
.QuadPart
);
2476 NewPartEntry
->FormatState
= Unformatted
;
2478 InsertTailList(&DiskEntry
->LogicalPartListHead
,
2479 &NewPartEntry
->ListEntry
);
2484 CreateExtendedPartition(
2486 ULONGLONG SectorCount
)
2488 PDISKENTRY DiskEntry
;
2489 PPARTENTRY PartEntry
;
2490 PPARTENTRY NewPartEntry
;
2492 DPRINT1("CreateExtendedPartition(%I64u)\n", SectorCount
);
2495 List
->CurrentDisk
== NULL
||
2496 List
->CurrentPartition
== NULL
||
2497 List
->CurrentPartition
->IsPartitioned
== TRUE
)
2502 DiskEntry
= List
->CurrentDisk
;
2503 PartEntry
= List
->CurrentPartition
;
2505 DPRINT1("Current partition sector count: %I64u\n", PartEntry
->SectorCount
.QuadPart
);
2507 if (Align(PartEntry
->StartSector
.QuadPart
+ SectorCount
, DiskEntry
->SectorAlignment
) - PartEntry
->StartSector
.QuadPart
== PartEntry
->SectorCount
.QuadPart
)
2509 DPRINT1("Convert existing partition entry\n");
2511 /* Convert current entry to 'new (unformatted)' */
2512 PartEntry
->IsPartitioned
= TRUE
;
2513 PartEntry
->FormatState
= Formatted
;
2514 PartEntry
->AutoCreate
= FALSE
;
2515 PartEntry
->New
= FALSE
;
2516 PartEntry
->BootIndicator
= FALSE
;
2518 if (PartEntry
->StartSector
.QuadPart
< 1450560)
2520 /* Partition starts below the 8.4GB boundary ==> CHS partition */
2521 PartEntry
->PartitionType
= PARTITION_EXTENDED
;
2525 /* Partition starts above the 8.4GB boundary ==> LBA partition */
2526 PartEntry
->PartitionType
= PARTITION_XINT13_EXTENDED
;
2529 DiskEntry
->ExtendedPartition
= PartEntry
;
2531 DPRINT1("First Sector: %I64u\n", PartEntry
->StartSector
.QuadPart
);
2532 DPRINT1("Last Sector: %I64u\n", PartEntry
->StartSector
.QuadPart
+ PartEntry
->SectorCount
.QuadPart
- 1);
2533 DPRINT1("Total Sectors: %I64u\n", PartEntry
->SectorCount
.QuadPart
);
2537 DPRINT1("Add new partition entry\n");
2539 /* Insert and initialize a new partition entry */
2540 NewPartEntry
= RtlAllocateHeap(ProcessHeap
,
2543 if (NewPartEntry
== NULL
)
2546 /* Insert the new entry into the list */
2547 InsertTailList(&PartEntry
->ListEntry
,
2548 &NewPartEntry
->ListEntry
);
2550 NewPartEntry
->DiskEntry
= DiskEntry
;
2552 NewPartEntry
->IsPartitioned
= TRUE
;
2553 NewPartEntry
->StartSector
.QuadPart
= PartEntry
->StartSector
.QuadPart
;
2554 NewPartEntry
->SectorCount
.QuadPart
= Align(NewPartEntry
->StartSector
.QuadPart
+ SectorCount
, DiskEntry
->SectorAlignment
) -
2555 NewPartEntry
->StartSector
.QuadPart
;
2557 NewPartEntry
->New
= FALSE
;
2558 NewPartEntry
->FormatState
= Formatted
;
2559 NewPartEntry
->BootIndicator
= FALSE
;
2561 if (NewPartEntry
->StartSector
.QuadPart
< 1450560)
2563 /* Partition starts below the 8.4GB boundary ==> CHS partition */
2564 NewPartEntry
->PartitionType
= PARTITION_EXTENDED
;
2568 /* Partition starts above the 8.4GB boundary ==> LBA partition */
2569 NewPartEntry
->PartitionType
= PARTITION_XINT13_EXTENDED
;
2572 DiskEntry
->ExtendedPartition
= NewPartEntry
;
2574 PartEntry
->StartSector
.QuadPart
= NewPartEntry
->StartSector
.QuadPart
+ NewPartEntry
->SectorCount
.QuadPart
;
2575 PartEntry
->SectorCount
.QuadPart
-= (PartEntry
->StartSector
.QuadPart
- NewPartEntry
->StartSector
.QuadPart
);
2577 DPRINT1("First Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
);
2578 DPRINT1("Last Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
+ NewPartEntry
->SectorCount
.QuadPart
- 1);
2579 DPRINT1("Total Sectors: %I64u\n", NewPartEntry
->SectorCount
.QuadPart
);
2582 AddLogicalDiskSpace(DiskEntry
);
2584 UpdateDiskLayout(DiskEntry
);
2586 DiskEntry
->Dirty
= TRUE
;
2588 UpdatePartitionNumbers(DiskEntry
);
2590 AssignDriveLetters(List
);
2595 CreateLogicalPartition(
2597 ULONGLONG SectorCount
)
2599 // PDISKENTRY DiskEntry;
2600 PPARTENTRY PartEntry
;
2601 // PPARTENTRY NewPartEntry;
2603 DPRINT1("CreateLogicalPartition(%I64u)\n", SectorCount
);
2606 List
->CurrentDisk
== NULL
||
2607 List
->CurrentPartition
== NULL
||
2608 List
->CurrentPartition
->IsPartitioned
== TRUE
)
2613 // DiskEntry = List->CurrentDisk;
2614 PartEntry
= List
->CurrentPartition
;
2616 DPRINT1("Current partition sector count: %I64u\n", PartEntry
->SectorCount
.QuadPart
);
2621 DeleteCurrentPartition(
2624 PDISKENTRY DiskEntry
;
2625 PPARTENTRY PartEntry
;
2626 PPARTENTRY PrevPartEntry
;
2627 PPARTENTRY NextPartEntry
;
2628 PPARTENTRY LogicalPartEntry
;
2632 List
->CurrentDisk
== NULL
||
2633 List
->CurrentPartition
== NULL
||
2634 List
->CurrentPartition
->IsPartitioned
== FALSE
)
2639 DiskEntry
= List
->CurrentDisk
;
2640 PartEntry
= List
->CurrentPartition
;
2642 /* Delete all logical partiton entries if an extended partition will be deleted */
2643 if (DiskEntry
->ExtendedPartition
== PartEntry
)
2645 while (!IsListEmpty(&DiskEntry
->LogicalPartListHead
))
2647 Entry
= RemoveHeadList(&DiskEntry
->LogicalPartListHead
);
2648 LogicalPartEntry
= CONTAINING_RECORD(Entry
, PARTENTRY
, ListEntry
);
2650 RtlFreeHeap(ProcessHeap
, 0, LogicalPartEntry
);
2653 DiskEntry
->ExtendedPartition
= NULL
;
2656 /* Adjust unpartitioned disk space entries */
2658 /* Get pointer to previous and next unpartitioned entries */
2659 PrevPartEntry
= GetPrevUnpartitionedEntry(DiskEntry
,
2662 NextPartEntry
= GetNextUnpartitionedEntry(DiskEntry
,
2665 if (PrevPartEntry
!= NULL
&& NextPartEntry
!= NULL
)
2667 /* Merge previous, current and next unpartitioned entry */
2669 /* Adjust the previous entries length */
2670 PrevPartEntry
->SectorCount
.QuadPart
+= (PartEntry
->SectorCount
.QuadPart
+ NextPartEntry
->SectorCount
.QuadPart
);
2672 /* Remove the current entry */
2673 RemoveEntryList(&PartEntry
->ListEntry
);
2674 RtlFreeHeap(ProcessHeap
, 0, PartEntry
);
2676 /* Remove the next entry */
2677 RemoveEntryList (&NextPartEntry
->ListEntry
);
2678 RtlFreeHeap(ProcessHeap
, 0, NextPartEntry
);
2680 /* Update current partition */
2681 List
->CurrentPartition
= PrevPartEntry
;
2683 else if (PrevPartEntry
!= NULL
&& NextPartEntry
== NULL
)
2685 /* Merge current and previous unpartitioned entry */
2687 /* Adjust the previous entries length */
2688 PrevPartEntry
->SectorCount
.QuadPart
+= PartEntry
->SectorCount
.QuadPart
;
2690 /* Remove the current entry */
2691 RemoveEntryList(&PartEntry
->ListEntry
);
2692 RtlFreeHeap(ProcessHeap
, 0, PartEntry
);
2694 /* Update current partition */
2695 List
->CurrentPartition
= PrevPartEntry
;
2697 else if (PrevPartEntry
== NULL
&& NextPartEntry
!= NULL
)
2699 /* Merge current and next unpartitioned entry */
2701 /* Adjust the next entries offset and length */
2702 NextPartEntry
->StartSector
.QuadPart
= PartEntry
->StartSector
.QuadPart
;
2703 NextPartEntry
->SectorCount
.QuadPart
+= PartEntry
->SectorCount
.QuadPart
;
2705 /* Remove the current entry */
2706 RemoveEntryList(&PartEntry
->ListEntry
);
2707 RtlFreeHeap(ProcessHeap
, 0, PartEntry
);
2709 /* Update current partition */
2710 List
->CurrentPartition
= NextPartEntry
;
2714 /* Nothing to merge but change current entry */
2715 PartEntry
->IsPartitioned
= FALSE
;
2716 PartEntry
->PartitionType
= PARTITION_ENTRY_UNUSED
;
2717 PartEntry
->FormatState
= Unformatted
;
2718 PartEntry
->DriveLetter
= 0;
2721 UpdateDiskLayout(DiskEntry
);
2723 DiskEntry
->Dirty
= TRUE
;
2725 UpdatePartitionNumbers(DiskEntry
);
2727 AssignDriveLetters(List
);
2732 CheckActiveBootPartition(
2735 PDISKENTRY DiskEntry
;
2736 PPARTENTRY PartEntry
;
2737 PLIST_ENTRY ListEntry
;
2739 /* Check for empty disk list */
2740 if (IsListEmpty (&List
->DiskListHead
))
2742 List
->ActiveBootDisk
= NULL
;
2743 List
->ActiveBootPartition
= NULL
;
2748 if (List
->ActiveBootDisk
!= NULL
&&
2749 List
->ActiveBootPartition
!= NULL
)
2751 /* We already have an active boot partition */
2756 /* Choose the currently selected disk */
2757 DiskEntry
= List
->CurrentDisk
;
2759 /* Check for empty partition list */
2760 if (IsListEmpty (&DiskEntry
->PrimaryPartListHead
))
2762 List
->ActiveBootDisk
= NULL
;
2763 List
->ActiveBootPartition
= NULL
;
2767 PartEntry
= CONTAINING_RECORD(DiskEntry
->PrimaryPartListHead
.Flink
,
2771 /* Set active boot partition */
2772 if ((DiskEntry
->NewDisk
== TRUE
) ||
2773 (PartEntry
->BootIndicator
== FALSE
))
2775 PartEntry
->BootIndicator
= TRUE
;
2776 DiskEntry
->LayoutBuffer
->PartitionEntry
[PartEntry
->PartitionIndex
].BootIndicator
= TRUE
;
2777 DiskEntry
->LayoutBuffer
->PartitionEntry
[PartEntry
->PartitionIndex
].RewritePartition
= TRUE
;
2778 DiskEntry
->Dirty
= TRUE
;
2780 /* FIXME: Might be incorrect if partitions were created by Linux FDISK */
2781 List
->ActiveBootDisk
= DiskEntry
;
2782 List
->ActiveBootPartition
= PartEntry
;
2787 /* Disk is not new, scan all partitions to find a bootable one */
2788 List
->ActiveBootDisk
= NULL
;
2789 List
->ActiveBootPartition
= NULL
;
2791 ListEntry
= DiskEntry
->PrimaryPartListHead
.Flink
;
2792 while (ListEntry
!= &DiskEntry
->PrimaryPartListHead
)
2794 PartEntry
= CONTAINING_RECORD(ListEntry
,
2798 /* Check if it is partitioned */
2799 if (PartEntry
->IsPartitioned
)
2801 if (PartEntry
->PartitionType
!= PARTITION_ENTRY_UNUSED
&&
2802 PartEntry
->BootIndicator
)
2804 /* Yes, we found it */
2805 List
->ActiveBootDisk
= DiskEntry
;
2806 List
->ActiveBootPartition
= PartEntry
;
2808 DPRINT("Found bootable partition disk %d, drive letter %c\n",
2809 DiskEntry
->DiskNumber
, PartEntry
->DriveLetter
);
2814 /* Go to the next one */
2815 ListEntry
= ListEntry
->Flink
;
2821 CheckForLinuxFdiskPartitions(
2825 PDISKENTRY DiskEntry
;
2826 PPARTENTRY PartEntry
;
2829 ULONG PartitionCount
;
2832 Entry1
= List
->DiskListHead
.Flink
;
2833 while (Entry1
!= &List
->DiskListHead
)
2835 DiskEntry
= CONTAINING_RECORD(Entry1
,
2839 Entry2
= DiskEntry
->PartListHead
.Flink
;
2840 while (Entry2
!= &DiskEntry
->PartListHead
)
2842 PartEntry
= CONTAINING_RECORD(Entry2
,
2846 if (PartEntry
->Unpartitioned
== FALSE
)
2850 for (i
= 0; i
< 4; i
++)
2852 if (!IsContainerPartition(PartEntry
->PartInfo
[i
].PartitionType
) &&
2853 PartEntry
->PartInfo
[i
].PartitionLength
.QuadPart
!= 0ULL)
2859 if (PartitionCount
> 1)
2865 Entry2
= Entry2
->Flink
;
2868 Entry1
= Entry1
->Flink
;
2880 IN PDISKENTRY DiskEntry
)
2882 WCHAR DstPath
[MAX_PATH
];
2883 OBJECT_ATTRIBUTES ObjectAttributes
;
2884 IO_STATUS_BLOCK Iosb
;
2885 UNICODE_STRING Name
;
2887 HANDLE FileHandle
= NULL
;
2890 DPRINT("WritePartitions() Disk: %lu\n", DiskEntry
->DiskNumber
);
2893 L
"\\Device\\Harddisk%d\\Partition0",
2894 DiskEntry
->DiskNumber
);
2895 RtlInitUnicodeString(&Name
,
2897 InitializeObjectAttributes(&ObjectAttributes
,
2903 Status
= NtOpenFile(&FileHandle
,
2904 GENERIC_READ
| GENERIC_WRITE
| SYNCHRONIZE
,
2908 FILE_SYNCHRONOUS_IO_NONALERT
);
2909 if (!NT_SUCCESS(Status
))
2911 DPRINT1("NtOpenFile() failed (Status %lx)\n", Status
);
2915 #ifdef DUMP_PARTITION_TABLE
2916 DumpPartitionTable(DiskEntry
);
2919 BufferSize
= sizeof(DRIVE_LAYOUT_INFORMATION
) +
2920 ((DiskEntry
->LayoutBuffer
->PartitionCount
- 1) * sizeof(PARTITION_INFORMATION
));
2921 Status
= NtDeviceIoControlFile(FileHandle
,
2926 IOCTL_DISK_SET_DRIVE_LAYOUT
,
2927 DiskEntry
->LayoutBuffer
,
2931 if (!NT_SUCCESS(Status
))
2933 DPRINT1("IOCTL_DISK_SET_DRIVE_LAYOUT failed (Status 0x%08lx)\n", Status
);
2936 if (FileHandle
!= NULL
)
2937 NtClose(FileHandle
);
2944 WritePartitionsToDisk(
2948 PDISKENTRY DiskEntry
;
2953 Entry
= List
->DiskListHead
.Flink
;
2954 while (Entry
!= &List
->DiskListHead
)
2956 DiskEntry
= CONTAINING_RECORD(Entry
, DISKENTRY
, ListEntry
);
2958 if (DiskEntry
->Dirty
== TRUE
)
2960 WritePartitons(List
, DiskEntry
);
2963 Entry
= Entry
->Flink
;
2971 SetMountedDeviceValues(
2974 PLIST_ENTRY Entry1
, Entry2
;
2975 PDISKENTRY DiskEntry
;
2976 PPARTENTRY PartEntry
;
2977 LARGE_INTEGER StartingOffset
;
2984 Entry1
= List
->DiskListHead
.Flink
;
2985 while (Entry1
!= &List
->DiskListHead
)
2987 DiskEntry
= CONTAINING_RECORD(Entry1
,
2991 Entry2
= DiskEntry
->PrimaryPartListHead
.Flink
;
2992 while (Entry2
!= &DiskEntry
->PrimaryPartListHead
)
2994 PartEntry
= CONTAINING_RECORD(Entry2
, PARTENTRY
, ListEntry
);
2995 if (PartEntry
->IsPartitioned
)
2997 if (PartEntry
->DriveLetter
)
2999 StartingOffset
.QuadPart
= PartEntry
->StartSector
.QuadPart
* DiskEntry
->BytesPerSector
;
3000 if (!SetMountedDeviceValue(PartEntry
->DriveLetter
,
3001 DiskEntry
->LayoutBuffer
->Signature
,
3009 Entry2
= Entry2
->Flink
;
3012 Entry1
= Entry1
->Flink
;
3021 GetPrimaryPartitionCount(
3022 IN PDISKENTRY DiskEntry
)
3025 PPARTENTRY PartEntry
;
3028 Entry
= DiskEntry
->PrimaryPartListHead
.Flink
;
3029 while (Entry
!= &DiskEntry
->PrimaryPartListHead
)
3031 PartEntry
= CONTAINING_RECORD(Entry
, PARTENTRY
, ListEntry
);
3032 if (PartEntry
->IsPartitioned
== TRUE
)
3035 Entry
= Entry
->Flink
;
3043 PrimaryPartitionCreationChecks(
3046 PDISKENTRY DiskEntry
;
3047 PPARTENTRY PartEntry
;
3049 DiskEntry
= List
->CurrentDisk
;
3050 PartEntry
= List
->CurrentPartition
;
3052 /* Fail if partition is already in use */
3053 if (PartEntry
->IsPartitioned
== TRUE
)
3054 return ERROR_NEW_PARTITION
;
3056 /* Fail if there are more than 4 partitions in the list */
3057 if (GetPrimaryPartitionCount(DiskEntry
) > 4)
3058 return ERROR_PARTITION_TABLE_FULL
;
3060 return ERROR_SUCCESS
;
3065 ExtendedPartitionCreationChecks(
3068 PDISKENTRY DiskEntry
;
3069 PPARTENTRY PartEntry
;
3071 DiskEntry
= List
->CurrentDisk
;
3072 PartEntry
= List
->CurrentPartition
;
3074 /* Fail if partition is already in use */
3075 if (PartEntry
->IsPartitioned
== TRUE
)
3076 return ERROR_NEW_PARTITION
;
3078 /* Fail if there are more than 4 partitions in the list */
3079 if (GetPrimaryPartitionCount(DiskEntry
) > 4)
3080 return ERROR_PARTITION_TABLE_FULL
;
3082 /* Fail if there is another extended partition in the list */
3083 if (DiskEntry
->ExtendedPartition
!= NULL
)
3084 return ERROR_ONLY_ONE_EXTENDED
;
3086 return ERROR_SUCCESS
;
3091 LogicalPartitionCreationChecks(
3094 // PDISKENTRY DiskEntry;
3095 PPARTENTRY PartEntry
;
3097 // DiskEntry = List->CurrentDisk;
3098 PartEntry
= List
->CurrentPartition
;
3100 /* Fail if partition is already in use */
3101 if (PartEntry
->IsPartitioned
== TRUE
)
3102 return ERROR_NEW_PARTITION
;
3104 return ERROR_SUCCESS
;