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
;
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 PPARTENTRY SystemPartition
;
154 * The original system partition in case we are redefining it because
155 * we do not have write support on it.
156 * Please note that this is partly a HACK and MUST NEVER happen on
157 * architectures where real system partitions are mandatory (because then
158 * they are formatted in FAT FS and we support write operation on them).
159 * The corresponding original system disk is obtained via:
160 * OriginalSystemPartition->DiskEntry.
162 PPARTENTRY OriginalSystemPartition
;
164 LIST_ENTRY DiskListHead
;
165 LIST_ENTRY BiosDiskListHead
;
167 } PARTLIST
, *PPARTLIST
;
169 #define PARTITION_TBL_SIZE 4
171 #define PARTITION_MAGIC 0xAA55
173 /* Defines system type for MBR showing that a GPT is following */
174 #define EFI_PMBR_OSTYPE_EFI 0xEE
176 #include <pshpack1.h>
178 typedef struct _PARTITION
180 unsigned char BootFlags
; /* bootable? 0=no, 128=yes */
181 unsigned char StartingHead
; /* beginning head number */
182 unsigned char StartingSector
; /* beginning sector number */
183 unsigned char StartingCylinder
; /* 10 bit nmbr, with high 2 bits put in begsect */
184 unsigned char PartitionType
; /* Operating System type indicator code */
185 unsigned char EndingHead
; /* ending head number */
186 unsigned char EndingSector
; /* ending sector number */
187 unsigned char EndingCylinder
; /* also a 10 bit nmbr, with same high 2 bit trick */
188 unsigned int StartingBlock
; /* first sector relative to start of disk */
189 unsigned int SectorCount
; /* number of sectors in partition */
190 } PARTITION
, *PPARTITION
;
192 typedef struct _PARTITION_SECTOR
194 UCHAR BootCode
[440]; /* 0x000 */
195 ULONG Signature
; /* 0x1B8 */
196 UCHAR Reserved
[2]; /* 0x1BC */
197 PARTITION Partition
[PARTITION_TBL_SIZE
]; /* 0x1BE */
198 USHORT Magic
; /* 0x1FE */
199 } PARTITION_SECTOR
, *PPARTITION_SECTOR
;
205 LIST_ENTRY ListEntry
;
209 } BIOS_DISK
, *PBIOS_DISK
;
225 IN ULONGLONG Dividend
,
226 IN ULONGLONG Divisor
);
231 IN PDISKENTRY DiskEntry
);
235 IN PPARTENTRY PartEntry
);
238 CreatePartitionList(VOID
);
241 DestroyPartitionList(
247 IN ULONG HwDiskNumber
);
252 IN ULONG DiskNumber
);
268 // IN PPARTLIST List,
269 IN PDISKENTRY DiskEntry
,
270 IN ULONG PartitionNumber
);
276 IN ULONG PartitionNumber OPTIONAL
,
277 OUT PDISKENTRY
* pDiskEntry
,
278 OUT PPARTENTRY
* pPartEntry OPTIONAL
);
284 IN ULONG PartitionNumber
);
289 IN PPARTENTRY CurrentPart OPTIONAL
);
294 IN PPARTENTRY CurrentPart OPTIONAL
);
297 CreatePrimaryPartition(
299 IN OUT PPARTENTRY PartEntry
,
300 IN ULONGLONG SectorCount
,
301 IN BOOLEAN AutoCreate
);
304 CreateExtendedPartition(
306 IN OUT PPARTENTRY PartEntry
,
307 IN ULONGLONG SectorCount
);
310 CreateLogicalPartition(
312 IN OUT PPARTENTRY PartEntry
,
313 IN ULONGLONG SectorCount
,
314 IN BOOLEAN AutoCreate
);
318 IN PPARTENTRY PartEntry
);
323 IN PPARTENTRY PartEntry
,
324 OUT PPARTENTRY
* FreeRegion OPTIONAL
);
327 CheckActiveSystemPartition(
329 IN BOOLEAN ForceSelect
,
330 IN PDISKENTRY AlternateDisk OPTIONAL
,
331 IN PPARTENTRY AlternatePart 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
);