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
;
76 typedef struct _BIOSDISKENTRY
83 CM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry
;
84 CM_INT13_DRIVE_PARAMETER Int13DiskData
;
85 } BIOSDISKENTRY
, *PBIOSDISKENTRY
;
88 typedef struct _DISKENTRY
95 ULONG TracksPerCylinder
;
96 ULONG SectorsPerTrack
;
99 ULARGE_INTEGER SectorCount
;
100 ULONG SectorAlignment
;
101 ULONG CylinderAlignment
;
103 /* BIOS parameters */
105 ULONG BiosDiskNumber
;
106 // ULONG Signature; // Obtained from LayoutBuffer->Signature
109 /* SCSI parameters */
116 /* Has the partition list been modified? */
119 BOOLEAN NewDisk
; /* If TRUE, the disk is uninitialized */
120 PARTITION_STYLE DiskStyle
; /* MBR/GPT-partitioned disk, or uninitialized disk (RAW) */
122 UNICODE_STRING DriverName
;
124 PDRIVE_LAYOUT_INFORMATION LayoutBuffer
;
125 // TODO: When adding support for GPT disks:
126 // Use PDRIVE_LAYOUT_INFORMATION_EX which indicates whether
127 // the disk is MBR, GPT, or unknown (uninitialized).
128 // Depending on the style, either use the MBR or GPT partition info.
130 LIST_ENTRY PrimaryPartListHead
; /* List of primary partitions */
131 LIST_ENTRY LogicalPartListHead
; /* List of logical partitions (Valid only for MBR-partitioned disks) */
133 /* Pointer to the unique extended partition on this disk (Valid only for MBR-partitioned disks) */
134 PPARTENTRY ExtendedPartition
;
136 } DISKENTRY
, *PDISKENTRY
;
139 typedef struct _PARTLIST
142 * Disk & Partition iterators.
144 * NOTE that when CurrentPartition != NULL, then CurrentPartition->DiskEntry
145 * must be the same as CurrentDisk. We should however keep the two members
146 * separated as we can have a current (selected) disk without any current
147 * partition, if the former does not contain any.
149 PDISKENTRY CurrentDisk
;
150 PPARTENTRY CurrentPartition
;
153 * The system partition where the boot manager resides.
154 * The corresponding system disk is obtained via:
155 * SystemPartition->DiskEntry.
157 PPARTENTRY SystemPartition
;
159 * The original system partition in case we are redefining it because
160 * we do not have write support on it.
161 * Please note that this is partly a HACK and MUST NEVER happen on
162 * architectures where real system partitions are mandatory (because then
163 * they are formatted in FAT FS and we support write operation on them).
164 * The corresponding original system disk is obtained via:
165 * OriginalSystemPartition->DiskEntry.
167 PPARTENTRY OriginalSystemPartition
;
169 LIST_ENTRY DiskListHead
;
170 LIST_ENTRY BiosDiskListHead
;
172 } PARTLIST
, *PPARTLIST
;
174 #define PARTITION_TBL_SIZE 4
176 #define PARTITION_MAGIC 0xAA55
178 /* Defines system type for MBR showing that a GPT is following */
179 #define EFI_PMBR_OSTYPE_EFI 0xEE
181 #include <pshpack1.h>
183 typedef struct _PARTITION
185 unsigned char BootFlags
; /* bootable? 0=no, 128=yes */
186 unsigned char StartingHead
; /* beginning head number */
187 unsigned char StartingSector
; /* beginning sector number */
188 unsigned char StartingCylinder
; /* 10 bit nmbr, with high 2 bits put in begsect */
189 unsigned char PartitionType
; /* Operating System type indicator code */
190 unsigned char EndingHead
; /* ending head number */
191 unsigned char EndingSector
; /* ending sector number */
192 unsigned char EndingCylinder
; /* also a 10 bit nmbr, with same high 2 bit trick */
193 unsigned int StartingBlock
; /* first sector relative to start of disk */
194 unsigned int SectorCount
; /* number of sectors in partition */
195 } PARTITION
, *PPARTITION
;
197 typedef struct _PARTITION_SECTOR
199 UCHAR BootCode
[440]; /* 0x000 */
200 ULONG Signature
; /* 0x1B8 */
201 UCHAR Reserved
[2]; /* 0x1BC */
202 PARTITION Partition
[PARTITION_TBL_SIZE
]; /* 0x1BE */
203 USHORT Magic
; /* 0x1FE */
204 } PARTITION_SECTOR
, *PPARTITION_SECTOR
;
210 LIST_ENTRY ListEntry
;
214 } BIOS_DISK
, *PBIOS_DISK
;
230 IN ULONGLONG Dividend
,
231 IN ULONGLONG Divisor
);
236 CreatePartitionList(VOID
);
239 DestroyPartitionList(
245 IN ULONG BiosDiskNumber
);
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
);
293 CreatePrimaryPartition(
295 IN ULONGLONG SectorCount
,
296 IN BOOLEAN AutoCreate
);
299 CreateExtendedPartition(
301 IN ULONGLONG SectorCount
);
304 CreateLogicalPartition(
306 IN ULONGLONG SectorCount
,
307 IN BOOLEAN AutoCreate
);
310 DeleteCurrentPartition(
314 CheckActiveSystemPartition(
318 WritePartitionsToDisk(
322 SetMountedDeviceValue(
325 IN LARGE_INTEGER StartingOffset
);
328 SetMountedDeviceValues(
333 IN PPARTENTRY PartEntry
,
334 IN UCHAR PartitionType
);
337 PrimaryPartitionCreationChecks(
341 ExtendedPartitionCreationChecks(
345 LogicalPartitionCreationChecks(
349 GetNextUnformattedPartition(
351 OUT PDISKENTRY
*pDiskEntry OPTIONAL
,
352 OUT PPARTENTRY
*pPartEntry
);
355 GetNextUncheckedPartition(
357 OUT PDISKENTRY
*pDiskEntry OPTIONAL
,
358 OUT PPARTENTRY
*pPartEntry
);