[SETUPLIB] Partitioning code fixes and improvements.

CORE-7749

- Correctly insert discovered partitions in sorted order of StartSector,
  and verify that they do not overlap (-> check for broken partitioning).

May help for CORE-10898.

- Use the correct reported partition numbers that may be modified after
  partitioning changes, and that need to be used when opening
  \Device\Harddisk'M'\Partition'N' files. This is achieving by
  retrieving the returned value of the IOCTL_DISK_SET_DRIVE_LAYOUT call.

  Distinguish them from the "on-disk" partition numbers that are the ones
  that enumerate the partition in partition-table order (and is the order
  known by e.g. the BIOS), and that should be used to construct the
  destination ARC path.

May help for CORE-4870, CORE-13205.

- Simplify a lot of duplicated code by using helper functions.
This commit is contained in:
Hermès Bélusca-Maïto 2018-11-22 03:26:47 +01:00
parent 958ae44599
commit 7df9296692
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
3 changed files with 417 additions and 386 deletions

View file

@ -642,7 +642,7 @@ InitDestinationPaths(
RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer),
L"multi(0)disk(0)rdisk(%lu)partition(%lu)\\", L"multi(0)disk(0)rdisk(%lu)partition(%lu)\\",
DiskEntry->BiosDiskNumber, DiskEntry->BiosDiskNumber,
PartEntry->PartitionNumber); PartEntry->OnDiskPartitionNumber);
ConcatPaths(PathBuffer, ARRAYSIZE(PathBuffer), 1, InstallationDir); ConcatPaths(PathBuffer, ARRAYSIZE(PathBuffer), 1, InstallationDir);
RtlCreateUnicodeString(&pSetupData->DestinationArcPath, PathBuffer); RtlCreateUnicodeString(&pSetupData->DestinationArcPath, PathBuffer);

File diff suppressed because it is too large Load diff

View file

@ -46,8 +46,9 @@ typedef struct _PARTENTRY
BOOLEAN BootIndicator; BOOLEAN BootIndicator;
UCHAR PartitionType; UCHAR PartitionType;
ULONG HiddenSectors; ULONG HiddenSectors;
ULONG PartitionNumber; /* Enumerated partition number (primary partitions first -- excluding the extended partition container --, then the logical partitions) */ ULONG OnDiskPartitionNumber; /* Enumerated partition number (primary partitions first, excluding the extended partition container, then the logical partitions) */
ULONG PartitionIndex; /* Index in the LayoutBuffer->PartitionEntry[] cached array of the corresponding DiskEntry */ ULONG PartitionNumber; /* Current partition number, only valid for the currently running NTOS instance */
ULONG PartitionIndex; /* Index in the LayoutBuffer->PartitionEntry[] cached array of the corresponding DiskEntry */
WCHAR DriveLetter; WCHAR DriveLetter;
WCHAR VolumeLabel[20]; WCHAR VolumeLabel[20];
@ -116,8 +117,8 @@ typedef struct _DISKENTRY
/* Has the partition list been modified? */ /* Has the partition list been modified? */
BOOLEAN Dirty; BOOLEAN Dirty;
BOOLEAN NewDisk; BOOLEAN NewDisk; /* If TRUE, the disk is uninitialized */
BOOLEAN NoMbr; /* MBR is absent */ // See r40437 BOOLEAN NoMbr; /* If TRUE, the MBR is absent */ // See r40437
UNICODE_STRING DriverName; UNICODE_STRING DriverName;
@ -127,11 +128,11 @@ typedef struct _DISKENTRY
// the disk is MBR, GPT, or unknown (uninitialized). // the disk is MBR, GPT, or unknown (uninitialized).
// Depending on the style, either use the MBR or GPT partition info. // Depending on the style, either use the MBR or GPT partition info.
/* Pointer to the unique extended partition on this disk */ LIST_ENTRY PrimaryPartListHead; /* List of primary partitions */
PPARTENTRY ExtendedPartition; LIST_ENTRY LogicalPartListHead; /* List of logical partitions (Valid only for MBR-partitioned disks) */
LIST_ENTRY PrimaryPartListHead; /* Pointer to the unique extended partition on this disk (Valid only for MBR-partitioned disks) */
LIST_ENTRY LogicalPartListHead; PPARTENTRY ExtendedPartition;
} DISKENTRY, *PDISKENTRY; } DISKENTRY, *PDISKENTRY;