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
;
48 ULONG OnDiskPartitionNumber
; /* Enumerated partition number (primary partitions first, excluding the extended partition container, then the logical partitions) */
49 ULONG PartitionNumber
; /* Current partition number, only valid for the currently running NTOS instance */
50 ULONG PartitionIndex
; /* Index in the LayoutBuffer->PartitionEntry[] cached array of the corresponding DiskEntry */
53 WCHAR VolumeLabel
[20];
54 WCHAR FileSystem
[MAX_PATH
+1];
55 FORMATSTATE FormatState
;
57 BOOLEAN LogicalPartition
;
59 /* Partition is partitioned disk space */
60 BOOLEAN IsPartitioned
;
62 /** The following three properties may be replaced by flags **/
64 /* Partition is new, table does not exist on disk yet */
67 /* Partition was created automatically */
70 /* Partition must be checked */
73 } PARTENTRY
, *PPARTENTRY
;
75 typedef struct _DISKENTRY
79 /* The list of disks/partitions this disk belongs to */
80 struct _PARTLIST
*PartList
;
82 MEDIA_TYPE MediaType
; /* FixedMedia or RemovableMedia */
87 ULONG TracksPerCylinder
;
88 ULONG SectorsPerTrack
;
91 ULARGE_INTEGER SectorCount
;
92 ULONG SectorAlignment
;
93 ULONG CylinderAlignment
;
95 /* BIOS Firmware parameters */
97 ULONG HwAdapterNumber
;
98 ULONG HwControllerNumber
;
99 ULONG HwDiskNumber
; /* Disk number currently assigned on the system */
100 ULONG HwFixedDiskNumber
; /* Disk number on the system when *ALL* removable disks are not connected */
101 // ULONG Signature; // Obtained from LayoutBuffer->Signature
104 /* SCSI parameters */
111 /* Has the partition list been modified? */
114 BOOLEAN NewDisk
; /* If TRUE, the disk is uninitialized */
115 PARTITION_STYLE DiskStyle
; /* MBR/GPT-partitioned disk, or uninitialized disk (RAW) */
117 UNICODE_STRING DriverName
;
119 PDRIVE_LAYOUT_INFORMATION LayoutBuffer
;
120 // TODO: When adding support for GPT disks:
121 // Use PDRIVE_LAYOUT_INFORMATION_EX which indicates whether
122 // the disk is MBR, GPT, or unknown (uninitialized).
123 // Depending on the style, either use the MBR or GPT partition info.
125 LIST_ENTRY PrimaryPartListHead
; /* List of primary partitions */
126 LIST_ENTRY LogicalPartListHead
; /* List of logical partitions (Valid only for MBR-partitioned disks) */
128 /* Pointer to the unique extended partition on this disk (Valid only for MBR-partitioned disks) */
129 PPARTENTRY ExtendedPartition
;
131 } DISKENTRY
, *PDISKENTRY
;
133 typedef struct _BIOSDISKENTRY
135 LIST_ENTRY ListEntry
;
137 ULONG ControllerNumber
;
141 PDISKENTRY DiskEntry
; /* Corresponding recognized disk; is NULL if the disk is not recognized */ // RecognizedDiskEntry;
142 CM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry
;
143 CM_INT13_DRIVE_PARAMETER Int13DiskData
;
144 } BIOSDISKENTRY
, *PBIOSDISKENTRY
;
146 typedef struct _PARTLIST
149 * The system partition where the boot manager resides.
150 * The corresponding system disk is obtained via:
151 * SystemPartition->DiskEntry.
153 PPARTENTRY SystemPartition
;
155 * The original system partition in case we are redefining it because
156 * we do not have write support on it.
157 * Please note that this is partly a HACK and MUST NEVER happen on
158 * architectures where real system partitions are mandatory (because then
159 * they are formatted in FAT FS and we support write operation on them).
160 * The corresponding original system disk is obtained via:
161 * OriginalSystemPartition->DiskEntry.
163 PPARTENTRY OriginalSystemPartition
;
165 LIST_ENTRY DiskListHead
;
166 LIST_ENTRY BiosDiskListHead
;
168 } PARTLIST
, *PPARTLIST
;
170 #define PARTITION_TBL_SIZE 4
172 #define PARTITION_MAGIC 0xAA55
174 /* Defines system type for MBR showing that a GPT is following */
175 #define EFI_PMBR_OSTYPE_EFI 0xEE
177 #include <pshpack1.h>
179 typedef struct _PARTITION
181 unsigned char BootFlags
; /* bootable? 0=no, 128=yes */
182 unsigned char StartingHead
; /* beginning head number */
183 unsigned char StartingSector
; /* beginning sector number */
184 unsigned char StartingCylinder
; /* 10 bit nmbr, with high 2 bits put in begsect */
185 unsigned char PartitionType
; /* Operating System type indicator code */
186 unsigned char EndingHead
; /* ending head number */
187 unsigned char EndingSector
; /* ending sector number */
188 unsigned char EndingCylinder
; /* also a 10 bit nmbr, with same high 2 bit trick */
189 unsigned int StartingBlock
; /* first sector relative to start of disk */
190 unsigned int SectorCount
; /* number of sectors in partition */
191 } PARTITION
, *PPARTITION
;
193 typedef struct _PARTITION_SECTOR
195 UCHAR BootCode
[440]; /* 0x000 */
196 ULONG Signature
; /* 0x1B8 */
197 UCHAR Reserved
[2]; /* 0x1BC */
198 PARTITION Partition
[PARTITION_TBL_SIZE
]; /* 0x1BE */
199 USHORT Magic
; /* 0x1FE */
200 } PARTITION_SECTOR
, *PPARTITION_SECTOR
;
206 LIST_ENTRY ListEntry
;
210 } BIOS_DISK
, *PBIOS_DISK
;
226 IN ULONGLONG Dividend
,
227 IN ULONGLONG Divisor
);
232 IN PDISKENTRY DiskEntry
);
236 CreatePartitionList(VOID
);
239 DestroyPartitionList(
245 IN ULONG HwDiskNumber
);
250 IN ULONG DiskNumber
);
266 // IN PPARTLIST List,
267 IN PDISKENTRY DiskEntry
,
268 IN ULONG PartitionNumber
);
274 IN ULONG PartitionNumber OPTIONAL
,
275 OUT PDISKENTRY
* pDiskEntry
,
276 OUT PPARTENTRY
* pPartEntry OPTIONAL
);
282 IN ULONG PartitionNumber
);
287 IN PPARTENTRY CurrentPart OPTIONAL
);
292 IN PPARTENTRY CurrentPart OPTIONAL
);
295 CreatePrimaryPartition(
297 IN PPARTENTRY SelectedEntry
,
298 IN ULONGLONG SectorCount
,
299 IN BOOLEAN AutoCreate
);
302 CreateExtendedPartition(
304 IN PPARTENTRY SelectedEntry
,
305 IN ULONGLONG SectorCount
);
308 CreateLogicalPartition(
310 IN PPARTENTRY SelectedEntry
,
311 IN ULONGLONG SectorCount
,
312 IN BOOLEAN AutoCreate
);
317 IN PPARTENTRY PartEntry
,
318 OUT PPARTENTRY
* FreeRegion OPTIONAL
);
321 CheckActiveSystemPartition(
323 IN BOOLEAN ForceSelect
,
324 IN PDISKENTRY AlternateDisk OPTIONAL
,
325 IN PPARTENTRY AlternatePart OPTIONAL
);
329 IN PDISKENTRY DiskEntry
);
332 WritePartitionsToDisk(
336 SetMountedDeviceValue(
339 IN LARGE_INTEGER StartingOffset
);
342 SetMountedDeviceValues(
347 IN PPARTENTRY PartEntry
,
348 IN UCHAR PartitionType
);
351 PrimaryPartitionCreationChecks(
352 IN PPARTENTRY PartEntry
);
355 ExtendedPartitionCreationChecks(
356 IN PPARTENTRY PartEntry
);
359 LogicalPartitionCreationChecks(
360 IN PPARTENTRY PartEntry
);
363 GetNextUnformattedPartition(
365 OUT PDISKENTRY
*pDiskEntry OPTIONAL
,
366 OUT PPARTENTRY
*pPartEntry
);
369 GetNextUncheckedPartition(
371 OUT PDISKENTRY
*pDiskEntry OPTIONAL
,
372 OUT PPARTENTRY
*pPartEntry
);