2 * PROJECT: ReactOS Setup Library
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Partition list functions
5 * COPYRIGHT: Copyright 2003-2019 Casper S. Hornstrup (chorns@users.sourceforge.net)
6 * Copyright 2018-2019 Hermes Belusca-Maito
11 /* HELPERS FOR PARTITION TYPES **********************************************/
13 typedef struct _PARTITION_TYPE
17 } PARTITION_TYPE
, *PPARTITION_TYPE
;
19 #define NUM_PARTITION_TYPE_ENTRIES 143
20 extern PARTITION_TYPE PartitionTypes
[NUM_PARTITION_TYPE_ENTRIES
];
23 /* PARTITION UTILITY FUNCTIONS **********************************************/
25 typedef enum _FORMATSTATE
32 } FORMATSTATE
, *PFORMATSTATE
;
34 typedef struct _PARTENTRY
38 /* The disk this partition belongs to */
39 struct _DISKENTRY
*DiskEntry
;
41 /* Partition geometry */
42 ULARGE_INTEGER StartSector
;
43 ULARGE_INTEGER SectorCount
;
45 BOOLEAN BootIndicator
; // NOTE: See comment for the PARTLIST::SystemPartition member.
47 ULONG OnDiskPartitionNumber
; /* Enumerated partition number (primary partitions first, excluding the extended partition container, then the logical partitions) */
48 ULONG PartitionNumber
; /* Current partition number, only valid for the currently running NTOS instance */
49 ULONG PartitionIndex
; /* Index in the LayoutBuffer->PartitionEntry[] cached array of the corresponding DiskEntry */
52 WCHAR VolumeLabel
[20];
53 WCHAR FileSystem
[MAX_PATH
+1];
54 FORMATSTATE FormatState
;
56 BOOLEAN LogicalPartition
;
58 /* Partition is partitioned disk space */
59 BOOLEAN IsPartitioned
;
61 /** The following three properties may be replaced by flags **/
63 /* Partition is new, table does not exist on disk yet */
66 /* Partition was created automatically */
69 /* Partition must be checked */
72 } PARTENTRY
, *PPARTENTRY
;
74 typedef struct _DISKENTRY
78 /* The list of disks/partitions this disk belongs to */
79 struct _PARTLIST
*PartList
;
81 MEDIA_TYPE MediaType
; /* FixedMedia or RemovableMedia */
86 ULONG TracksPerCylinder
;
87 ULONG SectorsPerTrack
;
90 ULARGE_INTEGER SectorCount
;
91 ULONG SectorAlignment
;
92 ULONG CylinderAlignment
;
94 /* BIOS Firmware parameters */
96 ULONG HwAdapterNumber
;
97 ULONG HwControllerNumber
;
98 ULONG HwDiskNumber
; /* Disk number currently assigned on the system */
99 ULONG HwFixedDiskNumber
; /* Disk number on the system when *ALL* removable disks are not connected */
100 // ULONG Signature; // Obtained from LayoutBuffer->Signature
103 /* SCSI parameters */
110 /* Has the partition list been modified? */
113 BOOLEAN NewDisk
; /* If TRUE, the disk is uninitialized */
114 PARTITION_STYLE DiskStyle
; /* MBR/GPT-partitioned disk, or uninitialized disk (RAW) */
116 UNICODE_STRING DriverName
;
118 PDRIVE_LAYOUT_INFORMATION LayoutBuffer
;
119 // TODO: When adding support for GPT disks:
120 // Use PDRIVE_LAYOUT_INFORMATION_EX which indicates whether
121 // the disk is MBR, GPT, or unknown (uninitialized).
122 // Depending on the style, either use the MBR or GPT partition info.
124 LIST_ENTRY PrimaryPartListHead
; /* List of primary partitions */
125 LIST_ENTRY LogicalPartListHead
; /* List of logical partitions (Valid only for MBR-partitioned disks) */
127 /* Pointer to the unique extended partition on this disk (Valid only for MBR-partitioned disks) */
128 PPARTENTRY ExtendedPartition
;
130 } DISKENTRY
, *PDISKENTRY
;
132 typedef struct _BIOSDISKENTRY
134 LIST_ENTRY ListEntry
;
136 ULONG ControllerNumber
;
140 PDISKENTRY DiskEntry
; /* Corresponding recognized disk; is NULL if the disk is not recognized */ // RecognizedDiskEntry;
141 CM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry
;
142 CM_INT13_DRIVE_PARAMETER Int13DiskData
;
143 } BIOSDISKENTRY
, *PBIOSDISKENTRY
;
145 typedef struct _PARTLIST
148 * The system partition where the boot manager resides.
149 * The corresponding system disk is obtained via:
150 * SystemPartition->DiskEntry.
152 // NOTE: It seems to appear that the specifications of ARC and (u)EFI
153 // actually allow for multiple system partitions to exist on the system.
154 // If so we should instead rely on the BootIndicator bit of the PARTENTRY
155 // structure in order to find these.
156 PPARTENTRY SystemPartition
;
158 LIST_ENTRY DiskListHead
;
159 LIST_ENTRY BiosDiskListHead
;
161 } PARTLIST
, *PPARTLIST
;
163 #define PARTITION_TBL_SIZE 4
165 #define PARTITION_MAGIC 0xAA55
167 /* Defines system type for MBR showing that a GPT is following */
168 #define EFI_PMBR_OSTYPE_EFI 0xEE
170 #include <pshpack1.h>
172 typedef struct _PARTITION
174 unsigned char BootFlags
; /* bootable? 0=no, 128=yes */
175 unsigned char StartingHead
; /* beginning head number */
176 unsigned char StartingSector
; /* beginning sector number */
177 unsigned char StartingCylinder
; /* 10 bit nmbr, with high 2 bits put in begsect */
178 unsigned char PartitionType
; /* Operating System type indicator code */
179 unsigned char EndingHead
; /* ending head number */
180 unsigned char EndingSector
; /* ending sector number */
181 unsigned char EndingCylinder
; /* also a 10 bit nmbr, with same high 2 bit trick */
182 unsigned int StartingBlock
; /* first sector relative to start of disk */
183 unsigned int SectorCount
; /* number of sectors in partition */
184 } PARTITION
, *PPARTITION
;
186 typedef struct _PARTITION_SECTOR
188 UCHAR BootCode
[440]; /* 0x000 */
189 ULONG Signature
; /* 0x1B8 */
190 UCHAR Reserved
[2]; /* 0x1BC */
191 PARTITION Partition
[PARTITION_TBL_SIZE
]; /* 0x1BE */
192 USHORT Magic
; /* 0x1FE */
193 } PARTITION_SECTOR
, *PPARTITION_SECTOR
;
199 LIST_ENTRY ListEntry
;
203 } BIOS_DISK
, *PBIOS_DISK
;
219 IN ULONGLONG Dividend
,
220 IN ULONGLONG Divisor
);
225 IN PDISKENTRY DiskEntry
);
229 IN PPARTENTRY PartEntry
);
232 CreatePartitionList(VOID
);
235 DestroyPartitionList(
241 IN ULONG HwDiskNumber
);
246 IN ULONG DiskNumber
);
262 // IN PPARTLIST List,
263 IN PDISKENTRY DiskEntry
,
264 IN ULONG PartitionNumber
);
270 IN ULONG PartitionNumber OPTIONAL
,
271 OUT PDISKENTRY
* pDiskEntry
,
272 OUT PPARTENTRY
* pPartEntry OPTIONAL
);
278 IN ULONG PartitionNumber
);
283 IN PPARTENTRY CurrentPart OPTIONAL
);
288 IN PPARTENTRY CurrentPart OPTIONAL
);
291 CreatePrimaryPartition(
293 IN OUT PPARTENTRY PartEntry
,
294 IN ULONGLONG SectorCount
,
295 IN BOOLEAN AutoCreate
);
298 CreateExtendedPartition(
300 IN OUT PPARTENTRY PartEntry
,
301 IN ULONGLONG SectorCount
);
304 CreateLogicalPartition(
306 IN OUT PPARTENTRY PartEntry
,
307 IN ULONGLONG SectorCount
,
308 IN BOOLEAN AutoCreate
);
312 IN PPARTENTRY PartEntry
);
317 IN PPARTENTRY PartEntry
,
318 OUT PPARTENTRY
* FreeRegion OPTIONAL
);
321 FindSupportedSystemPartition(
323 IN BOOLEAN ForceSelect
,
324 IN PDISKENTRY AlternativeDisk OPTIONAL
,
325 IN PPARTENTRY AlternativePart OPTIONAL
);
330 IN PPARTENTRY PartEntry
,
331 IN PPARTENTRY OldActivePart OPTIONAL
);
335 IN PDISKENTRY DiskEntry
);
338 WritePartitionsToDisk(
342 SetMountedDeviceValue(
345 IN LARGE_INTEGER StartingOffset
);
348 SetMountedDeviceValues(
353 IN PPARTENTRY PartEntry
,
354 IN UCHAR PartitionType
);
357 PrimaryPartitionCreationChecks(
358 IN PPARTENTRY PartEntry
);
361 ExtendedPartitionCreationChecks(
362 IN PPARTENTRY PartEntry
);
365 LogicalPartitionCreationChecks(
366 IN PPARTENTRY PartEntry
);
369 GetNextUnformattedPartition(
371 OUT PDISKENTRY
*pDiskEntry OPTIONAL
,
372 OUT PPARTENTRY
*pPartEntry
);
375 GetNextUncheckedPartition(
377 OUT PDISKENTRY
*pDiskEntry OPTIONAL
,
378 OUT PPARTENTRY
*pPartEntry
);