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
= Formatted
;
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
->SectorsPerTrack
;
660 NewPartEntry
->SectorCount
.QuadPart
= Align(DiskEntry
->SectorCount
.QuadPart
, DiskEntry
->SectorAlignment
) -
661 DiskEntry
->SectorsPerTrack
;
662 DPRINT1("First Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
);
663 DPRINT1("Last Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
+ NewPartEntry
->SectorCount
.QuadPart
- 1);
664 DPRINT1("Total Sectors: %I64u\n", NewPartEntry
->SectorCount
.QuadPart
);
666 NewPartEntry
->FormatState
= Unformatted
;
668 InsertTailList(&DiskEntry
->PrimaryPartListHead
,
669 &NewPartEntry
->ListEntry
);
674 /* Start partition at head 1, cylinder 0 */
675 LastStartSector
= DiskEntry
->SectorsPerTrack
;
676 LastSectorCount
= 0ULL;
677 LastUnusedSectorCount
= 0ULL;
679 Entry
= DiskEntry
->PrimaryPartListHead
.Flink
;
680 while (Entry
!= &DiskEntry
->PrimaryPartListHead
)
682 PartEntry
= CONTAINING_RECORD(Entry
, PARTENTRY
, ListEntry
);
684 if (PartEntry
->PartitionType
!= PARTITION_ENTRY_UNUSED
||
685 PartEntry
->SectorCount
.QuadPart
!= 0ULL)
687 LastUnusedSectorCount
=
688 PartEntry
->StartSector
.QuadPart
- (LastStartSector
+ LastSectorCount
);
690 if (PartEntry
->StartSector
.QuadPart
> (LastStartSector
+ LastSectorCount
) &&
691 LastUnusedSectorCount
>= (ULONGLONG
)DiskEntry
->SectorAlignment
)
693 DPRINT("Unpartitioned disk space %I64u sectors\n", LastUnusedSectorCount
);
695 NewPartEntry
= RtlAllocateHeap(ProcessHeap
,
698 if (NewPartEntry
== NULL
)
701 NewPartEntry
->DiskEntry
= DiskEntry
;
703 NewPartEntry
->IsPartitioned
= FALSE
;
704 NewPartEntry
->StartSector
.QuadPart
= LastStartSector
+ LastSectorCount
;
705 NewPartEntry
->SectorCount
.QuadPart
= Align(NewPartEntry
->StartSector
.QuadPart
+ LastUnusedSectorCount
, DiskEntry
->SectorAlignment
) -
706 NewPartEntry
->StartSector
.QuadPart
;
707 DPRINT1("First Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
);
708 DPRINT1("Last Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
+ NewPartEntry
->SectorCount
.QuadPart
- 1);
709 DPRINT1("Total Sectors: %I64u\n", NewPartEntry
->SectorCount
.QuadPart
);
711 NewPartEntry
->FormatState
= Unformatted
;
713 /* Insert the table into the list */
714 InsertTailList(&PartEntry
->ListEntry
,
715 &NewPartEntry
->ListEntry
);
718 LastStartSector
= PartEntry
->StartSector
.QuadPart
;
719 LastSectorCount
= PartEntry
->SectorCount
.QuadPart
;
722 Entry
= Entry
->Flink
;
725 /* Check for trailing unpartitioned disk space */
726 if ((LastStartSector
+ LastSectorCount
) < DiskEntry
->SectorCount
.QuadPart
)
728 LastUnusedSectorCount
= Align(DiskEntry
->SectorCount
.QuadPart
- (LastStartSector
+ LastSectorCount
), DiskEntry
->SectorAlignment
);
730 if (LastUnusedSectorCount
>= (ULONGLONG
)DiskEntry
->SectorAlignment
)
732 DPRINT("Unpartitioned disk space: %I64u sectors\n", LastUnusedSectorCount
);
734 NewPartEntry
= RtlAllocateHeap(ProcessHeap
,
737 if (NewPartEntry
== NULL
)
740 NewPartEntry
->DiskEntry
= DiskEntry
;
742 NewPartEntry
->IsPartitioned
= FALSE
;
743 NewPartEntry
->StartSector
.QuadPart
= LastStartSector
+ LastSectorCount
;
744 NewPartEntry
->SectorCount
.QuadPart
= Align(NewPartEntry
->StartSector
.QuadPart
+ LastUnusedSectorCount
, DiskEntry
->SectorAlignment
) -
745 NewPartEntry
->StartSector
.QuadPart
;
746 DPRINT("First Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
);
747 DPRINT("Last Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
+ NewPartEntry
->SectorCount
.QuadPart
- 1);
748 DPRINT("Total Sectors: %I64u\n", NewPartEntry
->SectorCount
.QuadPart
);
750 NewPartEntry
->FormatState
= Unformatted
;
752 /* Append the table to the list */
753 InsertTailList(&DiskEntry
->PrimaryPartListHead
,
754 &NewPartEntry
->ListEntry
);
758 if (DiskEntry
->ExtendedPartition
!= NULL
)
760 if (IsListEmpty(&DiskEntry
->LogicalPartListHead
))
762 DPRINT1("No logical partition!\n");
764 /* Create a partition table entry that represents the empty extended partition */
765 NewPartEntry
= RtlAllocateHeap(ProcessHeap
,
768 if (NewPartEntry
== NULL
)
771 NewPartEntry
->DiskEntry
= DiskEntry
;
772 NewPartEntry
->LogicalPartition
= TRUE
;
774 NewPartEntry
->IsPartitioned
= FALSE
;
775 NewPartEntry
->StartSector
.QuadPart
= DiskEntry
->ExtendedPartition
->StartSector
.QuadPart
+ (ULONGLONG
)DiskEntry
->SectorsPerTrack
;
776 NewPartEntry
->SectorCount
.QuadPart
= DiskEntry
->ExtendedPartition
->SectorCount
.QuadPart
- (ULONGLONG
)DiskEntry
->SectorsPerTrack
;
778 DPRINT1("First Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
);
779 DPRINT1("Last Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
+ NewPartEntry
->SectorCount
.QuadPart
- 1);
780 DPRINT1("Total Sectors: %I64u\n", NewPartEntry
->SectorCount
.QuadPart
);
782 NewPartEntry
->FormatState
= Unformatted
;
784 InsertTailList(&DiskEntry
->LogicalPartListHead
,
785 &NewPartEntry
->ListEntry
);
790 /* Start partition at head 1, cylinder 0 */
791 LastStartSector
= DiskEntry
->ExtendedPartition
->StartSector
.QuadPart
+ (ULONGLONG
)DiskEntry
->SectorsPerTrack
;
792 LastSectorCount
= 0ULL;
793 LastUnusedSectorCount
= 0ULL;
795 Entry
= DiskEntry
->LogicalPartListHead
.Flink
;
796 while (Entry
!= &DiskEntry
->LogicalPartListHead
)
798 PartEntry
= CONTAINING_RECORD(Entry
, PARTENTRY
, ListEntry
);
800 if (PartEntry
->PartitionType
!= PARTITION_ENTRY_UNUSED
||
801 PartEntry
->SectorCount
.QuadPart
!= 0ULL)
803 LastUnusedSectorCount
=
804 PartEntry
->StartSector
.QuadPart
- (ULONGLONG
)DiskEntry
->SectorsPerTrack
- (LastStartSector
+ LastSectorCount
);
806 if ((PartEntry
->StartSector
.QuadPart
- (ULONGLONG
)DiskEntry
->SectorsPerTrack
) > (LastStartSector
+ LastSectorCount
) &&
807 LastUnusedSectorCount
>= (ULONGLONG
)DiskEntry
->SectorAlignment
)
809 DPRINT("Unpartitioned disk space %I64u sectors\n", LastUnusedSectorCount
);
811 NewPartEntry
= RtlAllocateHeap(ProcessHeap
,
814 if (NewPartEntry
== NULL
)
817 NewPartEntry
->DiskEntry
= DiskEntry
;
818 NewPartEntry
->LogicalPartition
= TRUE
;
820 NewPartEntry
->IsPartitioned
= FALSE
;
821 NewPartEntry
->StartSector
.QuadPart
= LastStartSector
+ LastSectorCount
;
822 NewPartEntry
->SectorCount
.QuadPart
= Align(NewPartEntry
->StartSector
.QuadPart
+ LastUnusedSectorCount
, DiskEntry
->SectorAlignment
) -
823 NewPartEntry
->StartSector
.QuadPart
;
824 DPRINT("First Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
);
825 DPRINT("Last Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
+ NewPartEntry
->SectorCount
.QuadPart
- 1);
826 DPRINT("Total Sectors: %I64u\n", NewPartEntry
->SectorCount
.QuadPart
);
828 NewPartEntry
->FormatState
= Unformatted
;
830 /* Insert the table into the list */
831 InsertTailList(&PartEntry
->ListEntry
,
832 &NewPartEntry
->ListEntry
);
835 LastStartSector
= PartEntry
->StartSector
.QuadPart
;
836 LastSectorCount
= PartEntry
->SectorCount
.QuadPart
;
839 Entry
= Entry
->Flink
;
842 /* Check for trailing unpartitioned disk space */
843 if ((LastStartSector
+ LastSectorCount
) < DiskEntry
->ExtendedPartition
->StartSector
.QuadPart
+ DiskEntry
->ExtendedPartition
->SectorCount
.QuadPart
)
845 LastUnusedSectorCount
= Align(DiskEntry
->ExtendedPartition
->StartSector
.QuadPart
+ DiskEntry
->ExtendedPartition
->SectorCount
.QuadPart
- (LastStartSector
+ LastSectorCount
), DiskEntry
->SectorAlignment
);
847 if (LastUnusedSectorCount
>= (ULONGLONG
)DiskEntry
->SectorAlignment
)
849 DPRINT("Unpartitioned disk space: %I64u sectors\n", LastUnusedSectorCount
);
851 NewPartEntry
= RtlAllocateHeap(ProcessHeap
,
854 if (NewPartEntry
== NULL
)
857 NewPartEntry
->DiskEntry
= DiskEntry
;
858 NewPartEntry
->LogicalPartition
= TRUE
;
860 NewPartEntry
->IsPartitioned
= FALSE
;
861 NewPartEntry
->StartSector
.QuadPart
= LastStartSector
+ LastSectorCount
;
862 NewPartEntry
->SectorCount
.QuadPart
= Align(NewPartEntry
->StartSector
.QuadPart
+ LastUnusedSectorCount
, DiskEntry
->SectorAlignment
) -
863 NewPartEntry
->StartSector
.QuadPart
;
864 DPRINT("First Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
);
865 DPRINT("Last Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
+ NewPartEntry
->SectorCount
.QuadPart
- 1);
866 DPRINT("Total Sectors: %I64u\n", NewPartEntry
->SectorCount
.QuadPart
);
868 NewPartEntry
->FormatState
= Unformatted
;
870 /* Append the table to the list */
871 InsertTailList(&DiskEntry
->LogicalPartListHead
,
872 &NewPartEntry
->ListEntry
);
877 DPRINT("ScanForUnpartitionedDiskSpace() done\n");
885 IN PDISKENTRY DiskEntry
)
887 LARGE_INTEGER SystemTime
;
888 TIME_FIELDS TimeFields
;
890 PDISKENTRY DiskEntry2
;
893 Buffer
= (PUCHAR
)&DiskEntry
->LayoutBuffer
->Signature
;
897 NtQuerySystemTime(&SystemTime
);
898 RtlTimeToTimeFields(&SystemTime
, &TimeFields
);
900 Buffer
[0] = (UCHAR
)(TimeFields
.Year
& 0xFF) + (UCHAR
)(TimeFields
.Hour
& 0xFF);
901 Buffer
[1] = (UCHAR
)(TimeFields
.Year
>> 8) + (UCHAR
)(TimeFields
.Minute
& 0xFF);
902 Buffer
[2] = (UCHAR
)(TimeFields
.Month
& 0xFF) + (UCHAR
)(TimeFields
.Second
& 0xFF);
903 Buffer
[3] = (UCHAR
)(TimeFields
.Day
& 0xFF) + (UCHAR
)(TimeFields
.Milliseconds
& 0xFF);
905 if (DiskEntry
->LayoutBuffer
->Signature
== 0)
910 /* check if the signature already exist */
912 * Check also signatures from disks, which are
913 * not visible (bootable) by the bios.
915 Entry2
= List
->DiskListHead
.Flink
;
916 while (Entry2
!= &List
->DiskListHead
)
918 DiskEntry2
= CONTAINING_RECORD(Entry2
, DISKENTRY
, ListEntry
);
920 if (DiskEntry
!= DiskEntry2
&&
921 DiskEntry
->LayoutBuffer
->Signature
== DiskEntry2
->LayoutBuffer
->Signature
)
924 Entry2
= Entry2
->Flink
;
927 if (Entry2
== &List
->DiskListHead
)
935 UpdateDiskSignatures(
939 PDISKENTRY DiskEntry
;
941 /* Print partition lines*/
942 Entry
= List
->DiskListHead
.Flink
;
943 while (Entry
!= &List
->DiskListHead
)
945 DiskEntry
= CONTAINING_RECORD(Entry
, DISKENTRY
, ListEntry
);
947 if (DiskEntry
->LayoutBuffer
&&
948 DiskEntry
->LayoutBuffer
->Signature
== 0)
950 SetDiskSignature(List
, DiskEntry
);
951 DiskEntry
->LayoutBuffer
->PartitionEntry
[0].RewritePartition
= TRUE
;
954 Entry
= Entry
->Flink
;
966 DISK_GEOMETRY DiskGeometry
;
967 SCSI_ADDRESS ScsiAddress
;
968 PDISKENTRY DiskEntry
;
969 IO_STATUS_BLOCK Iosb
;
971 PPARTITION_SECTOR Mbr
;
973 LARGE_INTEGER FileOffset
;
974 WCHAR Identifier
[20];
978 PLIST_ENTRY ListEntry
;
979 PBIOSDISKENTRY BiosDiskEntry
;
980 ULONG LayoutBufferSize
;
982 Status
= NtDeviceIoControlFile(FileHandle
,
987 IOCTL_DISK_GET_DRIVE_GEOMETRY
,
991 sizeof(DISK_GEOMETRY
));
992 if (!NT_SUCCESS(Status
))
997 if (DiskGeometry
.MediaType
!= FixedMedia
&&
998 DiskGeometry
.MediaType
!= RemovableMedia
)
1003 Status
= NtDeviceIoControlFile(FileHandle
,
1008 IOCTL_SCSI_GET_ADDRESS
,
1012 sizeof(SCSI_ADDRESS
));
1013 if (!NT_SUCCESS(Status
))
1018 Mbr
= (PARTITION_SECTOR
*)RtlAllocateHeap(ProcessHeap
,
1020 DiskGeometry
.BytesPerSector
);
1026 FileOffset
.QuadPart
= 0;
1027 Status
= NtReadFile(FileHandle
,
1033 DiskGeometry
.BytesPerSector
,
1036 if (!NT_SUCCESS(Status
))
1038 RtlFreeHeap(ProcessHeap
,
1041 DPRINT1("NtReadFile failed, status=%x\n", Status
);
1044 Signature
= Mbr
->Signature
;
1046 /* Calculate the MBR checksum */
1048 Buffer
= (PULONG
)Mbr
;
1049 for (i
= 0; i
< 128; i
++)
1051 Checksum
+= Buffer
[i
];
1053 Checksum
= ~Checksum
+ 1;
1055 swprintf(Identifier
, L
"%08x-%08x-A", Checksum
, Signature
);
1056 DPRINT("Identifier: %S\n", Identifier
);
1058 DiskEntry
= RtlAllocateHeap(ProcessHeap
,
1061 if (DiskEntry
== NULL
)
1066 // DiskEntry->Checksum = Checksum;
1067 // DiskEntry->Signature = Signature;
1068 DiskEntry
->BiosFound
= FALSE
;
1070 /* Check if this disk has a valid MBR */
1071 if (Mbr
->BootCode
[0] == 0 && Mbr
->BootCode
[1] == 0)
1072 DiskEntry
->NoMbr
= TRUE
;
1074 DiskEntry
->NoMbr
= FALSE
;
1076 /* Free Mbr sector buffer */
1077 RtlFreeHeap(ProcessHeap
,
1081 ListEntry
= List
->BiosDiskListHead
.Flink
;
1082 while(ListEntry
!= &List
->BiosDiskListHead
)
1084 BiosDiskEntry
= CONTAINING_RECORD(ListEntry
, BIOSDISKENTRY
, ListEntry
);
1086 * Compare the size from bios and the reported size from driver.
1087 * If we have more than one disk with a zero or with the same signatur
1088 * we must create new signatures and reboot. After the reboot,
1089 * it is possible to identify the disks.
1091 if (BiosDiskEntry
->Signature
== Signature
&&
1092 BiosDiskEntry
->Checksum
== Checksum
&&
1093 !BiosDiskEntry
->Recognized
)
1095 if (!DiskEntry
->BiosFound
)
1097 DiskEntry
->BiosDiskNumber
= BiosDiskEntry
->DiskNumber
;
1098 DiskEntry
->BiosFound
= TRUE
;
1099 BiosDiskEntry
->Recognized
= TRUE
;
1105 ListEntry
= ListEntry
->Flink
;
1108 if (!DiskEntry
->BiosFound
)
1111 RtlFreeHeap(ProcessHeap
, 0, DiskEntry
);
1114 DPRINT1("WARNING: Setup could not find a matching BIOS disk entry. Disk %d is not be bootable by the BIOS!\n", DiskNumber
);
1118 InitializeListHead(&DiskEntry
->PrimaryPartListHead
);
1119 InitializeListHead(&DiskEntry
->LogicalPartListHead
);
1121 DiskEntry
->Cylinders
= DiskGeometry
.Cylinders
.QuadPart
;
1122 DiskEntry
->TracksPerCylinder
= DiskGeometry
.TracksPerCylinder
;
1123 DiskEntry
->SectorsPerTrack
= DiskGeometry
.SectorsPerTrack
;
1124 DiskEntry
->BytesPerSector
= DiskGeometry
.BytesPerSector
;
1126 DPRINT("Cylinders %I64u\n", DiskEntry
->Cylinders
);
1127 DPRINT("TracksPerCylinder %I64u\n", DiskEntry
->TracksPerCylinder
);
1128 DPRINT("SectorsPerTrack %I64u\n", DiskEntry
->SectorsPerTrack
);
1129 DPRINT("BytesPerSector %I64u\n", DiskEntry
->BytesPerSector
);
1131 DiskEntry
->SectorCount
.QuadPart
= DiskGeometry
.Cylinders
.QuadPart
*
1132 (ULONGLONG
)DiskGeometry
.TracksPerCylinder
*
1133 (ULONGLONG
)DiskGeometry
.SectorsPerTrack
;
1135 DiskEntry
->SectorAlignment
= DiskGeometry
.SectorsPerTrack
;
1137 DPRINT("SectorCount %I64u\n", DiskEntry
->SectorCount
);
1138 DPRINT("SectorAlignment %lu\n", DiskEntry
->SectorAlignment
);
1140 DiskEntry
->DiskNumber
= DiskNumber
;
1141 DiskEntry
->Port
= ScsiAddress
.PortNumber
;
1142 DiskEntry
->Bus
= ScsiAddress
.PathId
;
1143 DiskEntry
->Id
= ScsiAddress
.TargetId
;
1145 GetDriverName(DiskEntry
);
1147 InsertAscendingList(&List
->DiskListHead
, DiskEntry
, DISKENTRY
, ListEntry
, DiskNumber
);
1150 * Allocate a buffer for 26 logical drives (2 entries each == 52)
1151 * plus the main partiton table (4 entries). Total 56 entries.
1153 LayoutBufferSize
= sizeof(DRIVE_LAYOUT_INFORMATION
) +
1154 ((56 - ANYSIZE_ARRAY
) * sizeof(PARTITION_INFORMATION
));
1155 DiskEntry
->LayoutBuffer
= RtlAllocateHeap(ProcessHeap
,
1158 if (DiskEntry
->LayoutBuffer
== NULL
)
1163 Status
= NtDeviceIoControlFile(FileHandle
,
1168 IOCTL_DISK_GET_DRIVE_LAYOUT
,
1171 DiskEntry
->LayoutBuffer
,
1173 if (NT_SUCCESS(Status
))
1175 #ifdef DUMP_PARTITION_TABLE
1176 DumpPartitionTable(DiskEntry
);
1179 if (DiskEntry
->LayoutBuffer
->PartitionEntry
[0].StartingOffset
.QuadPart
!= 0 &&
1180 DiskEntry
->LayoutBuffer
->PartitionEntry
[0].PartitionLength
.QuadPart
!= 0 &&
1181 DiskEntry
->LayoutBuffer
->PartitionEntry
[0].PartitionType
!= 0)
1183 if ((DiskEntry
->LayoutBuffer
->PartitionEntry
[0].StartingOffset
.QuadPart
/ DiskEntry
->BytesPerSector
) % DiskEntry
->SectorsPerTrack
== 0)
1185 DPRINT("Use %lu Sector alignment!\n", DiskEntry
->SectorsPerTrack
);
1187 else if (DiskEntry
->LayoutBuffer
->PartitionEntry
[0].StartingOffset
.QuadPart
% 1048756 == 0)
1189 DPRINT1("Use megabyte (%lu Sectors) alignment!\n", 1048756 / DiskEntry
->BytesPerSector
);
1193 DPRINT1("No matching aligment found! Partiton 1 starts at %I64u\n", DiskEntry
->LayoutBuffer
->PartitionEntry
[0].StartingOffset
.QuadPart
);
1198 DPRINT1("No valid partiton table found! Use megabyte (%lu Sectors) alignment!\n", 1048756 / DiskEntry
->BytesPerSector
);
1202 if (DiskEntry
->LayoutBuffer
->PartitionCount
== 0)
1204 DiskEntry
->NewDisk
= TRUE
;
1205 DiskEntry
->LayoutBuffer
->PartitionCount
= 4;
1207 for (i
= 0; i
< 4; i
++)
1208 DiskEntry
->LayoutBuffer
->PartitionEntry
[i
].RewritePartition
= TRUE
;
1212 for (i
= 0; i
< 4; i
++)
1214 AddPartitionToDisk(DiskNumber
,
1220 for (i
= 4; i
< DiskEntry
->LayoutBuffer
->PartitionCount
; i
+= 4)
1222 AddPartitionToDisk(DiskNumber
,
1230 ScanForUnpartitionedDiskSpace(DiskEntry
);
1235 CreatePartitionList(
1242 OBJECT_ATTRIBUTES ObjectAttributes
;
1243 SYSTEM_DEVICE_INFORMATION Sdi
;
1244 IO_STATUS_BLOCK Iosb
;
1248 WCHAR Buffer
[MAX_PATH
];
1249 UNICODE_STRING Name
;
1252 List
= (PPARTLIST
)RtlAllocateHeap(ProcessHeap
,
1260 List
->Right
= Right
;
1261 List
->Bottom
= Bottom
;
1266 List
->TopDisk
= (ULONG
)-1;
1267 List
->TopPartition
= (ULONG
)-1;
1269 List
->CurrentDisk
= NULL
;
1270 List
->CurrentPartition
= NULL
;
1272 InitializeListHead(&List
->DiskListHead
);
1273 InitializeListHead(&List
->BiosDiskListHead
);
1275 EnumerateBiosDiskEntries(List
);
1277 Status
= NtQuerySystemInformation(SystemDeviceInformation
,
1279 sizeof(SYSTEM_DEVICE_INFORMATION
),
1281 if (!NT_SUCCESS(Status
))
1283 RtlFreeHeap(ProcessHeap
, 0, List
);
1287 for (DiskNumber
= 0; DiskNumber
< Sdi
.NumberOfDisks
; DiskNumber
++)
1290 L
"\\Device\\Harddisk%d\\Partition0",
1292 RtlInitUnicodeString(&Name
,
1295 InitializeObjectAttributes(&ObjectAttributes
,
1301 Status
= NtOpenFile(&FileHandle
,
1302 FILE_READ_DATA
| FILE_READ_ATTRIBUTES
| SYNCHRONIZE
,
1306 FILE_SYNCHRONOUS_IO_NONALERT
);
1307 if (NT_SUCCESS(Status
))
1309 AddDiskToList(FileHandle
,
1313 NtClose(FileHandle
);
1317 UpdateDiskSignatures(List
);
1319 AssignDriveLetters(List
);
1322 List
->TopPartition
= 0;
1324 /* Search for first usable disk and partition */
1325 if (IsListEmpty(&List
->DiskListHead
))
1327 List
->CurrentDisk
= NULL
;
1328 List
->CurrentPartition
= NULL
;
1332 List
->CurrentDisk
= CONTAINING_RECORD(List
->DiskListHead
.Flink
,
1336 if (IsListEmpty(&List
->CurrentDisk
->PrimaryPartListHead
))
1338 List
->CurrentPartition
= 0;
1342 List
->CurrentPartition
= CONTAINING_RECORD(List
->CurrentDisk
->PrimaryPartListHead
.Flink
,
1353 DestroyPartitionList(
1356 PDISKENTRY DiskEntry
;
1357 PBIOSDISKENTRY BiosDiskEntry
;
1358 PPARTENTRY PartEntry
;
1361 /* Release disk and partition info */
1362 while (!IsListEmpty(&List
->DiskListHead
))
1364 Entry
= RemoveHeadList(&List
->DiskListHead
);
1365 DiskEntry
= CONTAINING_RECORD(Entry
, DISKENTRY
, ListEntry
);
1367 /* Release driver name */
1368 RtlFreeUnicodeString(&DiskEntry
->DriverName
);
1370 /* Release primary partition list */
1371 while (!IsListEmpty(&DiskEntry
->PrimaryPartListHead
))
1373 Entry
= RemoveHeadList(&DiskEntry
->PrimaryPartListHead
);
1374 PartEntry
= CONTAINING_RECORD(Entry
, PARTENTRY
, ListEntry
);
1376 RtlFreeHeap(ProcessHeap
, 0, PartEntry
);
1379 /* Release logical partition list */
1380 while (!IsListEmpty(&DiskEntry
->LogicalPartListHead
))
1382 Entry
= RemoveHeadList(&DiskEntry
->LogicalPartListHead
);
1383 PartEntry
= CONTAINING_RECORD(Entry
, PARTENTRY
, ListEntry
);
1385 RtlFreeHeap(ProcessHeap
, 0, PartEntry
);
1388 /* Release layout buffer */
1389 if (DiskEntry
->LayoutBuffer
!= NULL
)
1390 RtlFreeHeap(ProcessHeap
, 0, DiskEntry
->LayoutBuffer
);
1393 /* Release disk entry */
1394 RtlFreeHeap(ProcessHeap
, 0, DiskEntry
);
1397 /* release the bios disk info */
1398 while(!IsListEmpty(&List
->BiosDiskListHead
))
1400 Entry
= RemoveHeadList(&List
->BiosDiskListHead
);
1401 BiosDiskEntry
= CONTAINING_RECORD(Entry
, BIOSDISKENTRY
, ListEntry
);
1403 RtlFreeHeap(ProcessHeap
, 0, BiosDiskEntry
);
1406 /* Release list head */
1407 RtlFreeHeap(ProcessHeap
, 0, List
);
1421 Width
= List
->Right
- List
->Left
- 1;
1422 Height
= List
->Bottom
- List
->Top
- 2;
1424 coPos
.X
= List
->Left
+ 1;
1425 coPos
.Y
= List
->Top
+ 1 + List
->Line
;
1427 if (List
->Line
>= 0 && List
->Line
<= Height
)
1429 FillConsoleOutputAttribute(StdOutput
,
1430 FOREGROUND_WHITE
| BACKGROUND_BLUE
,
1435 FillConsoleOutputCharacterA(StdOutput
,
1450 PDISKENTRY DiskEntry
,
1451 PPARTENTRY PartEntry
)
1453 CHAR LineBuffer
[128];
1458 LARGE_INTEGER PartSize
;
1463 Width
= List
->Right
- List
->Left
- 1;
1464 Height
= List
->Bottom
- List
->Top
- 2;
1466 coPos
.X
= List
->Left
+ 1;
1467 coPos
.Y
= List
->Top
+ 1 + List
->Line
;
1469 if (PartEntry
->IsPartitioned
== FALSE
)
1471 PartSize
.QuadPart
= PartEntry
->SectorCount
.QuadPart
* DiskEntry
->BytesPerSector
;
1473 if (PartSize
.QuadPart
>= 10737418240) /* 10 GB */
1475 PartSize
.QuadPart
= RoundingDivide(PartSize
.QuadPart
, 1073741824);
1476 Unit
= MUIGetString(STRING_GB
);
1480 if (PartSize
.QuadPart
>= 10485760) /* 10 MB */
1482 PartSize
.QuadPart
= RoundingDivide(PartSize
.QuadPart
, 1048576);
1483 Unit
= MUIGetString(STRING_MB
);
1487 PartSize
.QuadPart
= RoundingDivide(PartSize
.QuadPart
, 1024);
1488 Unit
= MUIGetString(STRING_KB
);
1492 MUIGetString(STRING_UNPSPACE
),
1493 PartEntry
->LogicalPartition
? " " : "",
1494 PartEntry
->LogicalPartition
? "" : " ",
1500 /* Determine partition type */
1502 if (PartEntry
->IsPartitioned
== TRUE
)
1504 if ((PartEntry
->PartitionType
== PARTITION_FAT_12
) ||
1505 (PartEntry
->PartitionType
== PARTITION_FAT_16
) ||
1506 (PartEntry
->PartitionType
== PARTITION_HUGE
) ||
1507 (PartEntry
->PartitionType
== PARTITION_XINT13
))
1511 else if ((PartEntry
->PartitionType
== PARTITION_FAT32
) ||
1512 (PartEntry
->PartitionType
== PARTITION_FAT32_XINT13
))
1516 else if (PartEntry
->PartitionType
== PARTITION_EXT2
)
1520 else if (PartEntry
->PartitionType
== PARTITION_IFS
)
1522 PartType
= "NTFS"; /* FIXME: Not quite correct! */
1524 else if ((PartEntry
->PartitionType
== PARTITION_EXTENDED
) ||
1525 (PartEntry
->PartitionType
== PARTITION_XINT13_EXTENDED
))
1527 PartType
= MUIGetString(STRING_EXTENDED_PARTITION
);
1531 PartSize
.QuadPart
= PartEntry
->SectorCount
.QuadPart
* DiskEntry
->BytesPerSector
;
1533 if (PartSize
.QuadPart
>= 10737418240) /* 10 GB */
1535 PartSize
.QuadPart
= RoundingDivide(PartSize
.QuadPart
, 1073741824);
1536 Unit
= MUIGetString(STRING_GB
);
1540 if (PartSize
.QuadPart
>= 10485760) /* 10 MB */
1542 PartSize
.QuadPart
= RoundingDivide(PartSize
.QuadPart
, 1048576);
1543 Unit
= MUIGetString(STRING_MB
);
1547 PartSize
.QuadPart
= RoundingDivide(PartSize
.QuadPart
, 1024);
1548 Unit
= MUIGetString(STRING_KB
);
1551 if (PartType
== NULL
)
1554 MUIGetString(STRING_HDDINFOUNK5
),
1555 (PartEntry
->DriveLetter
== 0) ? '-' : PartEntry
->DriveLetter
,
1556 (PartEntry
->DriveLetter
== 0) ? '-' : ':',
1557 PartEntry
->BootIndicator
? '*' : ' ',
1558 PartEntry
->LogicalPartition
? " " : "",
1559 PartEntry
->PartitionType
,
1560 PartEntry
->LogicalPartition
? "" : " ",
1567 "%c%c %c %s%-24s%s %6lu %s",
1568 (PartEntry
->DriveLetter
== 0) ? '-' : PartEntry
->DriveLetter
,
1569 (PartEntry
->DriveLetter
== 0) ? '-' : ':',
1570 PartEntry
->BootIndicator
? '*' : ' ',
1571 PartEntry
->LogicalPartition
? " " : "",
1573 PartEntry
->LogicalPartition
? "" : " ",
1579 Attribute
= (List
->CurrentDisk
== DiskEntry
&&
1580 List
->CurrentPartition
== PartEntry
) ?
1581 FOREGROUND_BLUE
| BACKGROUND_WHITE
:
1582 FOREGROUND_WHITE
| BACKGROUND_BLUE
;
1584 if (List
->Line
>= 0 && List
->Line
<= Height
)
1586 FillConsoleOutputCharacterA(StdOutput
,
1594 if (List
->Line
>= 0 && List
->Line
<= Height
)
1596 FillConsoleOutputAttribute(StdOutput
,
1604 if (List
->Line
>= 0 && List
->Line
<= Height
)
1606 WriteConsoleOutputCharacterA(StdOutput
,
1608 min(strlen(LineBuffer
), Width
),
1621 PDISKENTRY DiskEntry
)
1623 PPARTENTRY PrimaryPartEntry
, LogicalPartEntry
;
1624 PLIST_ENTRY PrimaryEntry
, LogicalEntry
;
1625 CHAR LineBuffer
[128];
1630 ULARGE_INTEGER DiskSize
;
1633 Width
= List
->Right
- List
->Left
- 1;
1634 Height
= List
->Bottom
- List
->Top
- 2;
1636 coPos
.X
= List
->Left
+ 1;
1637 coPos
.Y
= List
->Top
+ 1 + List
->Line
;
1639 DiskSize
.QuadPart
= DiskEntry
->SectorCount
.QuadPart
* DiskEntry
->BytesPerSector
;
1640 if (DiskSize
.QuadPart
>= 10737418240) /* 10 GB */
1642 DiskSize
.QuadPart
= RoundingDivide(DiskSize
.QuadPart
, 1073741824);
1643 Unit
= MUIGetString(STRING_GB
);
1647 DiskSize
.QuadPart
= RoundingDivide(DiskSize
.QuadPart
, 1048576);
1648 if (DiskSize
.QuadPart
== 0)
1649 DiskSize
.QuadPart
= 1;
1650 Unit
= MUIGetString(STRING_MB
);
1653 if (DiskEntry
->DriverName
.Length
> 0)
1656 MUIGetString(STRING_HDINFOPARTSELECT
),
1659 DiskEntry
->DiskNumber
,
1663 DiskEntry
->DriverName
.Buffer
);
1668 MUIGetString(STRING_HDDINFOUNK6
),
1671 DiskEntry
->DiskNumber
,
1677 if (List
->Line
>= 0 && List
->Line
<= Height
)
1679 FillConsoleOutputAttribute(StdOutput
,
1680 FOREGROUND_WHITE
| BACKGROUND_BLUE
,
1685 FillConsoleOutputCharacterA(StdOutput
,
1693 if (List
->Line
>= 0 && List
->Line
<= Height
)
1695 WriteConsoleOutputCharacterA(StdOutput
,
1697 min((USHORT
)strlen(LineBuffer
), Width
- 2),
1704 /* Print separator line */
1705 PrintEmptyLine(List
);
1707 /* Print partition lines*/
1708 PrimaryEntry
= DiskEntry
->PrimaryPartListHead
.Flink
;
1709 while (PrimaryEntry
!= &DiskEntry
->PrimaryPartListHead
)
1711 PrimaryPartEntry
= CONTAINING_RECORD(PrimaryEntry
, PARTENTRY
, ListEntry
);
1713 PrintPartitionData(List
,
1717 if (IsContainerPartition(PrimaryPartEntry
->PartitionType
))
1719 LogicalEntry
= DiskEntry
->LogicalPartListHead
.Flink
;
1720 while (LogicalEntry
!= &DiskEntry
->LogicalPartListHead
)
1722 LogicalPartEntry
= CONTAINING_RECORD(LogicalEntry
, PARTENTRY
, ListEntry
);
1724 PrintPartitionData(List
,
1728 LogicalEntry
= LogicalEntry
->Flink
;
1732 PrimaryEntry
= PrimaryEntry
->Flink
;
1735 /* Print separator line */
1736 PrintEmptyLine(List
);
1744 PLIST_ENTRY Entry
, Entry2
;
1745 PDISKENTRY DiskEntry
;
1746 PPARTENTRY PartEntry
= NULL
;
1750 SHORT CurrentDiskLine
;
1751 SHORT CurrentPartLine
;
1753 BOOL CurrentPartLineFound
= FALSE
;
1754 BOOL CurrentDiskLineFound
= FALSE
;
1756 /* Calculate the line of the current disk and partition */
1757 CurrentDiskLine
= 0;
1758 CurrentPartLine
= 0;
1761 Entry
= List
->DiskListHead
.Flink
;
1762 while (Entry
!= &List
->DiskListHead
)
1764 DiskEntry
= CONTAINING_RECORD(Entry
, DISKENTRY
, ListEntry
);
1767 if (CurrentPartLineFound
== FALSE
)
1769 CurrentPartLine
+= 2;
1772 Entry2
= DiskEntry
->PrimaryPartListHead
.Flink
;
1773 while (Entry2
!= &DiskEntry
->PrimaryPartListHead
)
1775 PartEntry
= CONTAINING_RECORD(Entry2
, PARTENTRY
, ListEntry
);
1776 if (PartEntry
== List
->CurrentPartition
)
1778 CurrentPartLineFound
= TRUE
;
1781 Entry2
= Entry2
->Flink
;
1782 if (CurrentPartLineFound
== FALSE
)
1790 if (DiskEntry
== List
->CurrentDisk
)
1792 CurrentDiskLineFound
= TRUE
;
1795 Entry
= Entry
->Flink
;
1796 if (Entry
!= &List
->DiskListHead
)
1798 if (CurrentDiskLineFound
== FALSE
)
1801 CurrentDiskLine
= CurrentPartLine
;
1812 /* If it possible, make the disk name visible */
1813 if (CurrentPartLine
< List
->Offset
)
1815 List
->Offset
= CurrentPartLine
;
1817 else if (CurrentPartLine
- List
->Offset
> List
->Bottom
- List
->Top
- 2)
1819 List
->Offset
= CurrentPartLine
- (List
->Bottom
- List
->Top
- 2);
1822 if (CurrentDiskLine
< List
->Offset
&& CurrentPartLine
- CurrentDiskLine
< List
->Bottom
- List
->Top
- 2)
1824 List
->Offset
= CurrentDiskLine
;
1827 /* draw upper left corner */
1828 coPos
.X
= List
->Left
;
1829 coPos
.Y
= List
->Top
;
1830 FillConsoleOutputCharacterA(StdOutput
,
1836 /* draw upper edge */
1837 coPos
.X
= List
->Left
+ 1;
1838 coPos
.Y
= List
->Top
;
1839 if (List
->Offset
== 0)
1841 FillConsoleOutputCharacterA(StdOutput
,
1843 List
->Right
- List
->Left
- 1,
1849 FillConsoleOutputCharacterA(StdOutput
,
1851 List
->Right
- List
->Left
- 5,
1854 coPos
.X
= List
->Right
- 5;
1855 WriteConsoleOutputCharacterA(StdOutput
,
1860 coPos
.X
= List
->Right
- 2;
1861 FillConsoleOutputCharacterA(StdOutput
,
1868 /* draw upper right corner */
1869 coPos
.X
= List
->Right
;
1870 coPos
.Y
= List
->Top
;
1871 FillConsoleOutputCharacterA(StdOutput
,
1877 /* draw left and right edge */
1878 for (i
= List
->Top
+ 1; i
< List
->Bottom
; i
++)
1880 coPos
.X
= List
->Left
;
1882 FillConsoleOutputCharacterA(StdOutput
,
1888 coPos
.X
= List
->Right
;
1889 FillConsoleOutputCharacterA(StdOutput
,
1896 /* draw lower left corner */
1897 coPos
.X
= List
->Left
;
1898 coPos
.Y
= List
->Bottom
;
1899 FillConsoleOutputCharacterA(StdOutput
,
1905 /* draw lower edge */
1906 coPos
.X
= List
->Left
+ 1;
1907 coPos
.Y
= List
->Bottom
;
1908 if (LastLine
- List
->Offset
<= List
->Bottom
- List
->Top
- 2)
1910 FillConsoleOutputCharacterA(StdOutput
,
1912 List
->Right
- List
->Left
- 1,
1918 FillConsoleOutputCharacterA(StdOutput
,
1920 List
->Right
- List
->Left
- 5,
1923 coPos
.X
= List
->Right
- 5;
1924 WriteConsoleOutputCharacterA(StdOutput
,
1925 "(\x19)", // "(down)"
1929 coPos
.X
= List
->Right
- 2;
1930 FillConsoleOutputCharacterA(StdOutput
,
1937 /* draw lower right corner */
1938 coPos
.X
= List
->Right
;
1939 coPos
.Y
= List
->Bottom
;
1940 FillConsoleOutputCharacterA(StdOutput
,
1946 /* print list entries */
1947 List
->Line
= - List
->Offset
;
1949 Entry
= List
->DiskListHead
.Flink
;
1950 while (Entry
!= &List
->DiskListHead
)
1952 DiskEntry
= CONTAINING_RECORD(Entry
, DISKENTRY
, ListEntry
);
1954 /* Print disk entry */
1958 Entry
= Entry
->Flink
;
1967 ULONG PartitionNumber
)
1969 PDISKENTRY DiskEntry
;
1970 PPARTENTRY PartEntry
;
1974 /* Check for empty disks */
1975 if (IsListEmpty(&List
->DiskListHead
))
1978 /* Check for first usable entry on next disk */
1979 Entry1
= List
->CurrentDisk
->ListEntry
.Flink
;
1980 while (Entry1
!= &List
->DiskListHead
)
1982 DiskEntry
= CONTAINING_RECORD(Entry1
, DISKENTRY
, ListEntry
);
1984 if (DiskEntry
->DiskNumber
== DiskNumber
)
1986 Entry2
= DiskEntry
->PrimaryPartListHead
.Flink
;
1987 while (Entry2
!= &DiskEntry
->PrimaryPartListHead
)
1989 PartEntry
= CONTAINING_RECORD(Entry2
, PARTENTRY
, ListEntry
);
1991 if (PartEntry
->PartitionNumber
== PartitionNumber
)
1993 List
->CurrentDisk
= DiskEntry
;
1994 List
->CurrentPartition
= PartEntry
;
1995 DrawPartitionList(List
);
1999 Entry2
= Entry2
->Flink
;
2005 Entry1
= Entry1
->Flink
;
2013 ScrollDownPartitionList(
2016 PLIST_ENTRY DiskListEntry
;
2017 PLIST_ENTRY PartListEntry
;
2018 PDISKENTRY DiskEntry
;
2019 PPARTENTRY PartEntry
;
2021 /* Fail, if no disks are available */
2022 if (IsListEmpty(&List
->DiskListHead
))
2025 /* Check for next usable entry on current disk */
2026 if (List
->CurrentPartition
!= NULL
)
2028 if (List
->CurrentPartition
->LogicalPartition
)
2030 /* Logical partition */
2032 PartListEntry
= List
->CurrentPartition
->ListEntry
.Flink
;
2033 if (PartListEntry
!= &List
->CurrentDisk
->LogicalPartListHead
)
2035 /* Next logical partition */
2036 PartEntry
= CONTAINING_RECORD(PartListEntry
, PARTENTRY
, ListEntry
);
2038 List
->CurrentPartition
= PartEntry
;
2043 PartListEntry
= List
->CurrentDisk
->ExtendedPartition
->ListEntry
.Flink
;
2044 if (PartListEntry
!= &List
->CurrentDisk
->PrimaryPartListHead
)
2046 PartEntry
= CONTAINING_RECORD(PartListEntry
, PARTENTRY
, ListEntry
);
2048 List
->CurrentPartition
= PartEntry
;
2055 /* Primary or extended partition */
2057 if (List
->CurrentPartition
->IsPartitioned
== TRUE
&&
2058 IsContainerPartition(List
->CurrentPartition
->PartitionType
))
2060 /* First logical partition */
2061 PartListEntry
= List
->CurrentDisk
->LogicalPartListHead
.Flink
;
2062 if (PartListEntry
!= &List
->CurrentDisk
->LogicalPartListHead
)
2064 PartEntry
= CONTAINING_RECORD(PartListEntry
, PARTENTRY
, ListEntry
);
2066 List
->CurrentPartition
= PartEntry
;
2072 /* Next primary partition */
2073 PartListEntry
= List
->CurrentPartition
->ListEntry
.Flink
;
2074 if (PartListEntry
!= &List
->CurrentDisk
->PrimaryPartListHead
)
2076 PartEntry
= CONTAINING_RECORD(PartListEntry
, PARTENTRY
, ListEntry
);
2078 List
->CurrentPartition
= PartEntry
;
2085 /* Search for the first partition entry on the next disk */
2086 DiskListEntry
= List
->CurrentDisk
->ListEntry
.Flink
;
2087 while (DiskListEntry
!= &List
->DiskListHead
)
2089 DiskEntry
= CONTAINING_RECORD(DiskListEntry
, DISKENTRY
, ListEntry
);
2091 PartListEntry
= DiskEntry
->PrimaryPartListHead
.Flink
;
2092 if (PartListEntry
!= &DiskEntry
->PrimaryPartListHead
)
2094 PartEntry
= CONTAINING_RECORD(PartListEntry
, PARTENTRY
, ListEntry
);
2096 List
->CurrentDisk
= DiskEntry
;
2097 List
->CurrentPartition
= PartEntry
;
2101 DiskListEntry
= DiskListEntry
->Flink
;
2109 ScrollUpPartitionList(
2112 PLIST_ENTRY DiskListEntry
;
2113 PLIST_ENTRY PartListEntry
;
2114 PDISKENTRY DiskEntry
;
2115 PPARTENTRY PartEntry
;
2117 /* Fail, if no disks are available */
2118 if (IsListEmpty(&List
->DiskListHead
))
2121 /* Check for previous usable entry on current disk */
2122 if (List
->CurrentPartition
!= NULL
)
2124 if (List
->CurrentPartition
->LogicalPartition
)
2126 /* Logical partition */
2127 PartListEntry
= List
->CurrentPartition
->ListEntry
.Blink
;
2128 if (PartListEntry
!= &List
->CurrentDisk
->LogicalPartListHead
)
2130 /* Previous logical partition */
2131 PartEntry
= CONTAINING_RECORD(PartListEntry
, PARTENTRY
, ListEntry
);
2135 /* Extended partition*/
2136 PartEntry
= List
->CurrentDisk
->ExtendedPartition
;
2139 List
->CurrentPartition
= PartEntry
;
2144 /* Primary or extended partition */
2146 PartListEntry
= List
->CurrentPartition
->ListEntry
.Blink
;
2147 if (PartListEntry
!= &List
->CurrentDisk
->PrimaryPartListHead
)
2149 PartEntry
= CONTAINING_RECORD(PartListEntry
, PARTENTRY
, ListEntry
);
2151 if (PartEntry
->IsPartitioned
== TRUE
&&
2152 IsContainerPartition(PartEntry
->PartitionType
))
2154 PartListEntry
= List
->CurrentDisk
->LogicalPartListHead
.Blink
;
2155 PartEntry
= CONTAINING_RECORD(PartListEntry
, PARTENTRY
, ListEntry
);
2158 List
->CurrentPartition
= PartEntry
;
2165 /* Search for the last partition entry on the previous disk */
2166 DiskListEntry
= List
->CurrentDisk
->ListEntry
.Blink
;
2167 while (DiskListEntry
!= &List
->DiskListHead
)
2169 DiskEntry
= CONTAINING_RECORD(DiskListEntry
, DISKENTRY
, ListEntry
);
2171 PartListEntry
= DiskEntry
->PrimaryPartListHead
.Blink
;
2172 if (PartListEntry
!= &DiskEntry
->PrimaryPartListHead
)
2174 PartEntry
= CONTAINING_RECORD(PartListEntry
, PARTENTRY
, ListEntry
);
2176 if (PartEntry
->IsPartitioned
== TRUE
&&
2177 IsContainerPartition(PartEntry
->PartitionType
))
2179 PartListEntry
= DiskEntry
->LogicalPartListHead
.Blink
;
2180 if (PartListEntry
!= &DiskEntry
->LogicalPartListHead
)
2182 PartEntry
= CONTAINING_RECORD(PartListEntry
, PARTENTRY
, ListEntry
);
2184 List
->CurrentDisk
= DiskEntry
;
2185 List
->CurrentPartition
= PartEntry
;
2191 List
->CurrentDisk
= DiskEntry
;
2192 List
->CurrentPartition
= PartEntry
;
2197 DiskListEntry
= DiskListEntry
->Blink
;
2207 PPARTITION_INFORMATION PartitionInfo
)
2209 if (PartitionInfo
->StartingOffset
.QuadPart
== 0 &&
2210 PartitionInfo
->PartitionLength
.QuadPart
== 0)
2211 // PartitionInfo->PartitionType == 0)
2220 IsSamePrimaryLayoutEntry(
2221 IN PPARTITION_INFORMATION PartitionInfo
,
2222 IN PDISKENTRY DiskEntry
,
2223 IN PPARTENTRY PartEntry
)
2225 if (PartitionInfo
->StartingOffset
.QuadPart
== PartEntry
->StartSector
.QuadPart
* DiskEntry
->BytesPerSector
&&
2226 PartitionInfo
->PartitionLength
.QuadPart
== PartEntry
->SectorCount
.QuadPart
* DiskEntry
->BytesPerSector
)
2227 // PartitionInfo->PartitionNumber = PartEntry->PartitionNumber &&
2228 // PartitionInfo->PartitionType == PartEntry->PartitionType
2238 IN PDISKENTRY DiskEntry
)
2240 PPARTITION_INFORMATION PartitionInfo
;
2241 PLIST_ENTRY ListEntry
;
2242 PPARTENTRY PartEntry
;
2244 ULONG PartitionNumber
= 1;
2246 DPRINT1("UpdateDiskLayout()\n");
2248 ListEntry
= DiskEntry
->PrimaryPartListHead
.Flink
;
2249 while (ListEntry
!= &DiskEntry
->PrimaryPartListHead
)
2251 PartEntry
= CONTAINING_RECORD(ListEntry
, PARTENTRY
, ListEntry
);
2253 if (PartEntry
->IsPartitioned
== TRUE
)
2255 PartitionInfo
= &DiskEntry
->LayoutBuffer
->PartitionEntry
[Index
];
2257 if (!IsSamePrimaryLayoutEntry(PartitionInfo
, DiskEntry
, PartEntry
))
2259 DPRINT1("Updating partition entry %lu\n", Index
);
2260 PartitionInfo
->StartingOffset
.QuadPart
= PartEntry
->StartSector
.QuadPart
* DiskEntry
->BytesPerSector
;
2261 PartitionInfo
->PartitionLength
.QuadPart
= PartEntry
->SectorCount
.QuadPart
* DiskEntry
->BytesPerSector
;
2262 PartitionInfo
->HiddenSectors
= 0;
2263 PartitionInfo
->PartitionNumber
= (!IsContainerPartition(PartEntry
->PartitionType
)) ? PartitionNumber
: 0;
2264 PartitionInfo
->PartitionType
= PartEntry
->PartitionType
;
2265 PartitionInfo
->BootIndicator
= PartEntry
->BootIndicator
;
2266 PartitionInfo
->RecognizedPartition
= FALSE
;
2267 PartitionInfo
->RewritePartition
= TRUE
;
2269 PartEntry
->PartitionNumber
= PartitionNumber
;
2270 PartEntry
->PartitionIndex
= Index
;
2274 else if (!IsEmptyLayoutEntry(PartitionInfo
))
2282 ListEntry
= ListEntry
->Flink
;
2285 for (;Index
< 4; Index
++)
2287 PartitionInfo
= &DiskEntry
->LayoutBuffer
->PartitionEntry
[Index
];
2289 if (!IsEmptyLayoutEntry(PartitionInfo
))
2291 DPRINT1("Wiping partition entry %lu\n", Index
);
2292 PartitionInfo
->StartingOffset
.QuadPart
= 0;
2293 PartitionInfo
->PartitionLength
.QuadPart
= 0;
2294 PartitionInfo
->HiddenSectors
= 0;
2295 PartitionInfo
->PartitionNumber
= 0;
2296 PartitionInfo
->PartitionType
= 0;
2297 PartitionInfo
->BootIndicator
= FALSE
;
2298 PartitionInfo
->RecognizedPartition
= FALSE
;
2299 PartitionInfo
->RewritePartition
= TRUE
;
2303 #ifdef DUMP_PARTITION_TABLE
2304 DumpPartitionTable(DiskEntry
);
2311 GetPrevUnpartitionedEntry(
2312 PDISKENTRY DiskEntry
,
2313 PPARTENTRY PartEntry
)
2315 PPARTENTRY PrevPartEntry
;
2317 if (PartEntry
->ListEntry
.Blink
!= &DiskEntry
->PrimaryPartListHead
)
2319 PrevPartEntry
= CONTAINING_RECORD(PartEntry
->ListEntry
.Blink
,
2322 if (PrevPartEntry
->IsPartitioned
== FALSE
)
2323 return PrevPartEntry
;
2332 GetNextUnpartitionedEntry(
2333 PDISKENTRY DiskEntry
,
2334 PPARTENTRY PartEntry
)
2336 PPARTENTRY NextPartEntry
;
2338 if (PartEntry
->ListEntry
.Flink
!= &DiskEntry
->PrimaryPartListHead
)
2340 NextPartEntry
= CONTAINING_RECORD(PartEntry
->ListEntry
.Flink
,
2343 if (NextPartEntry
->IsPartitioned
== FALSE
)
2344 return NextPartEntry
;
2352 CreatePrimaryPartition(
2354 ULONGLONG SectorCount
,
2357 PDISKENTRY DiskEntry
;
2358 PPARTENTRY PartEntry
;
2359 PPARTENTRY NewPartEntry
;
2361 DPRINT1("CreatePrimaryPartition(%I64u)\n", SectorCount
);
2364 List
->CurrentDisk
== NULL
||
2365 List
->CurrentPartition
== NULL
||
2366 List
->CurrentPartition
->IsPartitioned
== TRUE
)
2371 DiskEntry
= List
->CurrentDisk
;
2372 PartEntry
= List
->CurrentPartition
;
2374 DPRINT1("Current partition sector count: %I64u\n", PartEntry
->SectorCount
.QuadPart
);
2376 if (AutoCreate
== TRUE
||
2377 Align(PartEntry
->StartSector
.QuadPart
+ SectorCount
, DiskEntry
->SectorAlignment
) - PartEntry
->StartSector
.QuadPart
== PartEntry
->SectorCount
.QuadPart
)
2379 DPRINT1("Convert existing partition entry\n");
2380 /* Convert current entry to 'new (unformatted)' */
2381 PartEntry
->IsPartitioned
= TRUE
;
2382 PartEntry
->PartitionType
= PARTITION_ENTRY_UNUSED
;
2383 PartEntry
->FormatState
= Unformatted
;
2384 PartEntry
->AutoCreate
= AutoCreate
;
2385 PartEntry
->BootIndicator
= FALSE
;
2387 DPRINT1("First Sector: %I64u\n", PartEntry
->StartSector
.QuadPart
);
2388 DPRINT1("Last Sector: %I64u\n", PartEntry
->StartSector
.QuadPart
+ PartEntry
->SectorCount
.QuadPart
- 1);
2389 DPRINT1("Total Sectors: %I64u\n", PartEntry
->SectorCount
.QuadPart
);
2393 DPRINT1("Add new partition entry\n");
2395 /* Insert and initialize a new partition entry */
2396 NewPartEntry
= RtlAllocateHeap(ProcessHeap
,
2399 if (NewPartEntry
== NULL
)
2402 /* Insert the new entry into the list */
2403 InsertTailList(&PartEntry
->ListEntry
,
2404 &NewPartEntry
->ListEntry
);
2406 NewPartEntry
->DiskEntry
= DiskEntry
;
2408 NewPartEntry
->IsPartitioned
= TRUE
;
2409 NewPartEntry
->StartSector
.QuadPart
= PartEntry
->StartSector
.QuadPart
;
2410 NewPartEntry
->SectorCount
.QuadPart
= Align(NewPartEntry
->StartSector
.QuadPart
+ SectorCount
, DiskEntry
->SectorAlignment
) -
2411 NewPartEntry
->StartSector
.QuadPart
;
2412 NewPartEntry
->PartitionType
= PARTITION_ENTRY_UNUSED
;
2414 DPRINT1("First Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
);
2415 DPRINT1("Last Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
+ NewPartEntry
->SectorCount
.QuadPart
- 1);
2416 DPRINT1("Total Sectors: %I64u\n", NewPartEntry
->SectorCount
.QuadPart
);
2418 NewPartEntry
->FormatState
= Unformatted
;
2419 NewPartEntry
->BootIndicator
= FALSE
;
2421 PartEntry
->StartSector
.QuadPart
= NewPartEntry
->StartSector
.QuadPart
+ NewPartEntry
->SectorCount
.QuadPart
;
2422 PartEntry
->SectorCount
.QuadPart
-= (PartEntry
->StartSector
.QuadPart
- NewPartEntry
->StartSector
.QuadPart
);
2424 List
->CurrentPartition
= NewPartEntry
;
2427 UpdateDiskLayout(DiskEntry
);
2429 DiskEntry
->Dirty
= TRUE
;
2431 UpdatePartitionNumbers(DiskEntry
);
2433 AssignDriveLetters(List
);
2439 AddLogicalDiskSpace(
2440 PDISKENTRY DiskEntry
)
2442 PPARTENTRY NewPartEntry
;
2444 DPRINT1("AddLogicalDiskSpace()\n");
2446 /* Create a partition table entry that represents the empty space in the container partition */
2447 NewPartEntry
= RtlAllocateHeap(ProcessHeap
,
2450 if (NewPartEntry
== NULL
)
2453 NewPartEntry
->DiskEntry
= DiskEntry
;
2454 NewPartEntry
->LogicalPartition
= TRUE
;
2456 NewPartEntry
->IsPartitioned
= FALSE
;
2457 NewPartEntry
->StartSector
.QuadPart
= DiskEntry
->ExtendedPartition
->StartSector
.QuadPart
+ (ULONGLONG
)DiskEntry
->SectorsPerTrack
;
2458 NewPartEntry
->SectorCount
.QuadPart
= DiskEntry
->ExtendedPartition
->SectorCount
.QuadPart
- (ULONGLONG
)DiskEntry
->SectorsPerTrack
;
2460 DPRINT1("First Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
);
2461 DPRINT1("Last Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
+ NewPartEntry
->SectorCount
.QuadPart
- 1);
2462 DPRINT1("Total Sectors: %I64u\n", NewPartEntry
->SectorCount
.QuadPart
);
2464 NewPartEntry
->FormatState
= Unformatted
;
2466 InsertTailList(&DiskEntry
->LogicalPartListHead
,
2467 &NewPartEntry
->ListEntry
);
2472 CreateExtendedPartition(
2474 ULONGLONG SectorCount
)
2476 PDISKENTRY DiskEntry
;
2477 PPARTENTRY PartEntry
;
2478 PPARTENTRY NewPartEntry
;
2480 DPRINT1("CreateExtendedPartition(%I64u)\n", SectorCount
);
2483 List
->CurrentDisk
== NULL
||
2484 List
->CurrentPartition
== NULL
||
2485 List
->CurrentPartition
->IsPartitioned
== TRUE
)
2490 DiskEntry
= List
->CurrentDisk
;
2491 PartEntry
= List
->CurrentPartition
;
2493 DPRINT1("Current partition sector count: %I64u\n", PartEntry
->SectorCount
.QuadPart
);
2495 if (Align(PartEntry
->StartSector
.QuadPart
+ SectorCount
, DiskEntry
->SectorAlignment
) - PartEntry
->StartSector
.QuadPart
== PartEntry
->SectorCount
.QuadPart
)
2497 DPRINT1("Convert existing partition entry\n");
2498 /* Convert current entry to 'new (unformatted)' */
2499 PartEntry
->IsPartitioned
= TRUE
;
2500 PartEntry
->FormatState
= Formatted
;
2501 PartEntry
->AutoCreate
= FALSE
;
2502 PartEntry
->BootIndicator
= FALSE
;
2504 if (PartEntry
->StartSector
.QuadPart
< 1450560)
2506 /* Partition starts below the 8.4GB boundary ==> CHS partition */
2507 PartEntry
->PartitionType
= PARTITION_EXTENDED
;
2511 /* Partition starts above the 8.4GB boundary ==> LBA partition */
2512 PartEntry
->PartitionType
= PARTITION_XINT13_EXTENDED
;
2515 DiskEntry
->ExtendedPartition
= PartEntry
;
2517 DPRINT1("First Sector: %I64u\n", PartEntry
->StartSector
.QuadPart
);
2518 DPRINT1("Last Sector: %I64u\n", PartEntry
->StartSector
.QuadPart
+ PartEntry
->SectorCount
.QuadPart
- 1);
2519 DPRINT1("Total Sectors: %I64u\n", PartEntry
->SectorCount
.QuadPart
);
2523 DPRINT1("Add new partition entry\n");
2525 /* Insert and initialize a new partition entry */
2526 NewPartEntry
= RtlAllocateHeap(ProcessHeap
,
2529 if (NewPartEntry
== NULL
)
2532 /* Insert the new entry into the list */
2533 InsertTailList(&PartEntry
->ListEntry
,
2534 &NewPartEntry
->ListEntry
);
2536 NewPartEntry
->DiskEntry
= DiskEntry
;
2538 NewPartEntry
->IsPartitioned
= TRUE
;
2539 NewPartEntry
->StartSector
.QuadPart
= PartEntry
->StartSector
.QuadPart
;
2540 NewPartEntry
->SectorCount
.QuadPart
= Align(NewPartEntry
->StartSector
.QuadPart
+ SectorCount
, DiskEntry
->SectorAlignment
) -
2541 NewPartEntry
->StartSector
.QuadPart
;
2543 NewPartEntry
->FormatState
= Formatted
;
2544 NewPartEntry
->BootIndicator
= FALSE
;
2546 if (NewPartEntry
->StartSector
.QuadPart
< 1450560)
2548 /* Partition starts below the 8.4GB boundary ==> CHS partition */
2549 NewPartEntry
->PartitionType
= PARTITION_EXTENDED
;
2553 /* Partition starts above the 8.4GB boundary ==> LBA partition */
2554 NewPartEntry
->PartitionType
= PARTITION_XINT13_EXTENDED
;
2557 DiskEntry
->ExtendedPartition
= NewPartEntry
;
2559 PartEntry
->StartSector
.QuadPart
= NewPartEntry
->StartSector
.QuadPart
+ NewPartEntry
->SectorCount
.QuadPart
;
2560 PartEntry
->SectorCount
.QuadPart
-= (PartEntry
->StartSector
.QuadPart
- NewPartEntry
->StartSector
.QuadPart
);
2562 DPRINT1("First Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
);
2563 DPRINT1("Last Sector: %I64u\n", NewPartEntry
->StartSector
.QuadPart
+ NewPartEntry
->SectorCount
.QuadPart
- 1);
2564 DPRINT1("Total Sectors: %I64u\n", NewPartEntry
->SectorCount
.QuadPart
);
2566 List
->CurrentPartition
= NewPartEntry
;
2569 AddLogicalDiskSpace(DiskEntry
);
2571 UpdateDiskLayout(DiskEntry
);
2573 DiskEntry
->Dirty
= TRUE
;
2575 UpdatePartitionNumbers(DiskEntry
);
2577 AssignDriveLetters(List
);
2582 CreateLogicalPartition(
2584 ULONGLONG SectorCount
)
2586 // PDISKENTRY DiskEntry;
2587 PPARTENTRY PartEntry
;
2588 // PPARTENTRY NewPartEntry;
2590 DPRINT1("CreateLogicalPartition(%I64u)\n", SectorCount
);
2593 List
->CurrentDisk
== NULL
||
2594 List
->CurrentPartition
== NULL
||
2595 List
->CurrentPartition
->IsPartitioned
== TRUE
)
2600 // DiskEntry = List->CurrentDisk;
2601 PartEntry
= List
->CurrentPartition
;
2603 DPRINT1("Current partition sector count: %I64u\n", PartEntry
->SectorCount
.QuadPart
);
2608 DeleteCurrentPartition(
2611 PDISKENTRY DiskEntry
;
2612 PPARTENTRY PartEntry
;
2613 PPARTENTRY PrevPartEntry
;
2614 PPARTENTRY NextPartEntry
;
2615 PPARTENTRY LogicalPartEntry
;
2619 List
->CurrentDisk
== NULL
||
2620 List
->CurrentPartition
== NULL
||
2621 List
->CurrentPartition
->IsPartitioned
== FALSE
)
2626 DiskEntry
= List
->CurrentDisk
;
2627 PartEntry
= List
->CurrentPartition
;
2629 /* Delete all logical partiton entries if an extended partition will be deleted */
2630 if (DiskEntry
->ExtendedPartition
== PartEntry
)
2632 while (!IsListEmpty(&DiskEntry
->LogicalPartListHead
))
2634 Entry
= RemoveHeadList(&DiskEntry
->LogicalPartListHead
);
2635 LogicalPartEntry
= CONTAINING_RECORD(Entry
, PARTENTRY
, ListEntry
);
2637 RtlFreeHeap(ProcessHeap
, 0, LogicalPartEntry
);
2640 DiskEntry
->ExtendedPartition
= NULL
;
2643 /* Adjust unpartitioned disk space entries */
2645 /* Get pointer to previous and next unpartitioned entries */
2646 PrevPartEntry
= GetPrevUnpartitionedEntry(DiskEntry
,
2649 NextPartEntry
= GetNextUnpartitionedEntry(DiskEntry
,
2652 if (PrevPartEntry
!= NULL
&& NextPartEntry
!= NULL
)
2654 /* Merge previous, current and next unpartitioned entry */
2656 /* Adjust the previous entries length */
2657 PrevPartEntry
->SectorCount
.QuadPart
+= (PartEntry
->SectorCount
.QuadPart
+ NextPartEntry
->SectorCount
.QuadPart
);
2659 /* Remove the current entry */
2660 RemoveEntryList(&PartEntry
->ListEntry
);
2661 RtlFreeHeap(ProcessHeap
, 0, PartEntry
);
2663 /* Remove the next entry */
2664 RemoveEntryList (&NextPartEntry
->ListEntry
);
2665 RtlFreeHeap(ProcessHeap
, 0, NextPartEntry
);
2667 /* Update current partition */
2668 List
->CurrentPartition
= PrevPartEntry
;
2670 else if (PrevPartEntry
!= NULL
&& NextPartEntry
== NULL
)
2672 /* Merge current and previous unpartitioned entry */
2674 /* Adjust the previous entries length */
2675 PrevPartEntry
->SectorCount
.QuadPart
+= PartEntry
->SectorCount
.QuadPart
;
2677 /* Remove the current entry */
2678 RemoveEntryList(&PartEntry
->ListEntry
);
2679 RtlFreeHeap(ProcessHeap
, 0, PartEntry
);
2681 /* Update current partition */
2682 List
->CurrentPartition
= PrevPartEntry
;
2684 else if (PrevPartEntry
== NULL
&& NextPartEntry
!= NULL
)
2686 /* Merge current and next unpartitioned entry */
2688 /* Adjust the next entries offset and length */
2689 NextPartEntry
->StartSector
.QuadPart
= PartEntry
->StartSector
.QuadPart
;
2690 NextPartEntry
->SectorCount
.QuadPart
+= PartEntry
->SectorCount
.QuadPart
;
2692 /* Remove the current entry */
2693 RemoveEntryList(&PartEntry
->ListEntry
);
2694 RtlFreeHeap(ProcessHeap
, 0, PartEntry
);
2696 /* Update current partition */
2697 List
->CurrentPartition
= NextPartEntry
;
2701 /* Nothing to merge but change current entry */
2702 PartEntry
->IsPartitioned
= FALSE
;
2703 PartEntry
->PartitionType
= PARTITION_ENTRY_UNUSED
;
2704 PartEntry
->FormatState
= Unformatted
;
2705 PartEntry
->DriveLetter
= 0;
2708 UpdateDiskLayout(DiskEntry
);
2710 DiskEntry
->Dirty
= TRUE
;
2712 UpdatePartitionNumbers(DiskEntry
);
2714 AssignDriveLetters(List
);
2719 CheckActiveBootPartition(
2722 PDISKENTRY DiskEntry
;
2723 PPARTENTRY PartEntry
;
2724 PLIST_ENTRY ListEntry
;
2726 /* Check for empty disk list */
2727 if (IsListEmpty (&List
->DiskListHead
))
2729 List
->ActiveBootDisk
= NULL
;
2730 List
->ActiveBootPartition
= NULL
;
2735 if (List
->ActiveBootDisk
!= NULL
&&
2736 List
->ActiveBootPartition
!= NULL
)
2738 /* We already have an active boot partition */
2743 /* Choose the currently selected disk */
2744 DiskEntry
= List
->CurrentDisk
;
2746 /* Check for empty partition list */
2747 if (IsListEmpty (&DiskEntry
->PrimaryPartListHead
))
2749 List
->ActiveBootDisk
= NULL
;
2750 List
->ActiveBootPartition
= NULL
;
2754 PartEntry
= CONTAINING_RECORD(DiskEntry
->PrimaryPartListHead
.Flink
,
2758 /* Set active boot partition */
2759 if ((DiskEntry
->NewDisk
== TRUE
) ||
2760 (PartEntry
->BootIndicator
== FALSE
))
2762 PartEntry
->BootIndicator
= TRUE
;
2763 DiskEntry
->LayoutBuffer
->PartitionEntry
[PartEntry
->PartitionIndex
].BootIndicator
= TRUE
;
2764 DiskEntry
->LayoutBuffer
->PartitionEntry
[PartEntry
->PartitionIndex
].RewritePartition
= TRUE
;
2765 DiskEntry
->Dirty
= TRUE
;
2767 /* FIXME: Might be incorrect if partitions were created by Linux FDISK */
2768 List
->ActiveBootDisk
= DiskEntry
;
2769 List
->ActiveBootPartition
= PartEntry
;
2774 /* Disk is not new, scan all partitions to find a bootable one */
2775 List
->ActiveBootDisk
= NULL
;
2776 List
->ActiveBootPartition
= NULL
;
2778 ListEntry
= DiskEntry
->PrimaryPartListHead
.Flink
;
2779 while (ListEntry
!= &DiskEntry
->PrimaryPartListHead
)
2781 PartEntry
= CONTAINING_RECORD(ListEntry
,
2785 /* Check if it is partitioned */
2786 if (PartEntry
->IsPartitioned
)
2788 if (PartEntry
->PartitionType
!= PARTITION_ENTRY_UNUSED
&&
2789 PartEntry
->BootIndicator
)
2791 /* Yes, we found it */
2792 List
->ActiveBootDisk
= DiskEntry
;
2793 List
->ActiveBootPartition
= PartEntry
;
2795 DPRINT("Found bootable partition disk %d, drive letter %c\n",
2796 DiskEntry
->DiskNumber
, PartEntry
->DriveLetter
);
2801 /* Go to the next one */
2802 ListEntry
= ListEntry
->Flink
;
2808 CheckForLinuxFdiskPartitions(
2812 PDISKENTRY DiskEntry
;
2813 PPARTENTRY PartEntry
;
2816 ULONG PartitionCount
;
2819 Entry1
= List
->DiskListHead
.Flink
;
2820 while (Entry1
!= &List
->DiskListHead
)
2822 DiskEntry
= CONTAINING_RECORD(Entry1
,
2826 Entry2
= DiskEntry
->PartListHead
.Flink
;
2827 while (Entry2
!= &DiskEntry
->PartListHead
)
2829 PartEntry
= CONTAINING_RECORD(Entry2
,
2833 if (PartEntry
->Unpartitioned
== FALSE
)
2837 for (i
= 0; i
< 4; i
++)
2839 if (!IsContainerPartition(PartEntry
->PartInfo
[i
].PartitionType
) &&
2840 PartEntry
->PartInfo
[i
].PartitionLength
.QuadPart
!= 0ULL)
2846 if (PartitionCount
> 1)
2852 Entry2
= Entry2
->Flink
;
2855 Entry1
= Entry1
->Flink
;
2867 IN PDISKENTRY DiskEntry
)
2869 WCHAR DstPath
[MAX_PATH
];
2870 OBJECT_ATTRIBUTES ObjectAttributes
;
2871 IO_STATUS_BLOCK Iosb
;
2872 UNICODE_STRING Name
;
2874 HANDLE FileHandle
= NULL
;
2877 DPRINT("WritePartitions() Disk: %lu\n", DiskEntry
->DiskNumber
);
2880 L
"\\Device\\Harddisk%d\\Partition0",
2881 DiskEntry
->DiskNumber
);
2882 RtlInitUnicodeString(&Name
,
2884 InitializeObjectAttributes(&ObjectAttributes
,
2890 Status
= NtOpenFile(&FileHandle
,
2891 GENERIC_READ
| GENERIC_WRITE
| SYNCHRONIZE
,
2895 FILE_SYNCHRONOUS_IO_NONALERT
);
2896 if (!NT_SUCCESS(Status
))
2898 DPRINT1("NtOpenFile() failed (Status %lx)\n", Status
);
2902 #ifdef DUMP_PARTITION_TABLE
2903 DumpPartitionTable(DiskEntry
);
2906 BufferSize
= sizeof(DRIVE_LAYOUT_INFORMATION
) +
2907 ((DiskEntry
->LayoutBuffer
->PartitionCount
- 1) * sizeof(PARTITION_INFORMATION
));
2908 Status
= NtDeviceIoControlFile(FileHandle
,
2913 IOCTL_DISK_SET_DRIVE_LAYOUT
,
2914 DiskEntry
->LayoutBuffer
,
2918 if (!NT_SUCCESS(Status
))
2920 DPRINT1("IOCTL_DISK_SET_DRIVE_LAYOUT failed (Status 0x%08lx)\n", Status
);
2923 if (FileHandle
!= NULL
)
2924 NtClose(FileHandle
);
2931 WriteDirtyPartitions(
2935 PDISKENTRY DiskEntry
;
2939 return STATUS_SUCCESS
;
2941 Entry
= List
->DiskListHead
.Flink
;
2942 while (Entry
!= &List
->DiskListHead
)
2944 DiskEntry
= CONTAINING_RECORD(Entry
, DISKENTRY
, ListEntry
);
2946 if (DiskEntry
->Dirty
== TRUE
)
2948 Status
= WritePartitons(List
, DiskEntry
);
2949 if (!NT_SUCCESS(Status
))
2952 DiskEntry
->Dirty
= FALSE
;
2955 Entry
= Entry
->Flink
;
2958 return STATUS_SUCCESS
;
2963 SetMountedDeviceValues(
2966 PLIST_ENTRY Entry1
, Entry2
;
2967 PDISKENTRY DiskEntry
;
2968 PPARTENTRY PartEntry
;
2969 LARGE_INTEGER StartingOffset
;
2976 Entry1
= List
->DiskListHead
.Flink
;
2977 while (Entry1
!= &List
->DiskListHead
)
2979 DiskEntry
= CONTAINING_RECORD(Entry1
,
2983 Entry2
= DiskEntry
->PrimaryPartListHead
.Flink
;
2984 while (Entry2
!= &DiskEntry
->PrimaryPartListHead
)
2986 PartEntry
= CONTAINING_RECORD(Entry2
, PARTENTRY
, ListEntry
);
2987 if (PartEntry
->IsPartitioned
)
2989 if (PartEntry
->DriveLetter
)
2991 StartingOffset
.QuadPart
= PartEntry
->StartSector
.QuadPart
* DiskEntry
->BytesPerSector
;
2992 if (!SetMountedDeviceValue(PartEntry
->DriveLetter
,
2993 DiskEntry
->LayoutBuffer
->Signature
,
3001 Entry2
= Entry2
->Flink
;
3004 Entry1
= Entry1
->Flink
;
3013 GetPrimaryPartitionCount(
3014 IN PDISKENTRY DiskEntry
)
3017 PPARTENTRY PartEntry
;
3020 Entry
= DiskEntry
->PrimaryPartListHead
.Flink
;
3021 while (Entry
!= &DiskEntry
->PrimaryPartListHead
)
3023 PartEntry
= CONTAINING_RECORD(Entry
, PARTENTRY
, ListEntry
);
3024 if (PartEntry
->IsPartitioned
== TRUE
)
3027 Entry
= Entry
->Flink
;
3035 PrimaryPartitionCreationChecks(
3038 PDISKENTRY DiskEntry
;
3039 PPARTENTRY PartEntry
;
3041 DiskEntry
= List
->CurrentDisk
;
3042 PartEntry
= List
->CurrentPartition
;
3044 /* Fail if partition is already in use */
3045 if (PartEntry
->IsPartitioned
== TRUE
)
3046 return ERROR_NEW_PARTITION
;
3048 /* Fail if there are more than 4 partitions in the list */
3049 if (GetPrimaryPartitionCount(DiskEntry
) > 4)
3050 return ERROR_PARTITION_TABLE_FULL
;
3052 return ERROR_SUCCESS
;
3057 ExtendedPartitionCreationChecks(
3060 PDISKENTRY DiskEntry
;
3061 PPARTENTRY PartEntry
;
3063 DiskEntry
= List
->CurrentDisk
;
3064 PartEntry
= List
->CurrentPartition
;
3066 /* Fail if partition is already in use */
3067 if (PartEntry
->IsPartitioned
== TRUE
)
3068 return ERROR_NEW_PARTITION
;
3070 /* Fail if there are more than 4 partitions in the list */
3071 if (GetPrimaryPartitionCount(DiskEntry
) > 4)
3072 return ERROR_PARTITION_TABLE_FULL
;
3074 /* Fail if there is another extended partition in the list */
3075 if (DiskEntry
->ExtendedPartition
!= NULL
)
3076 return ERROR_ONLY_ONE_EXTENDED
;
3078 return ERROR_SUCCESS
;
3083 LogicalPartitionCreationChecks(
3086 // PDISKENTRY DiskEntry;
3087 PPARTENTRY PartEntry
;
3089 // DiskEntry = List->CurrentDisk;
3090 PartEntry
= List
->CurrentPartition
;
3092 /* Fail if partition is already in use */
3093 if (PartEntry
->IsPartitioned
== TRUE
)
3094 return ERROR_NEW_PARTITION
;
3096 return ERROR_SUCCESS
;