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-2018 Casper S. Hornstrup (chorns@users.sourceforge.net)
10 typedef enum _FORMATSTATE
17 } FORMATSTATE
, *PFORMATSTATE
;
21 typedef struct _PARTENTRY
25 /* The disk this partition belongs to */
26 struct _DISKENTRY
*DiskEntry
;
28 /* Partition geometry */
29 ULARGE_INTEGER StartSector
;
30 ULARGE_INTEGER SectorCount
;
32 BOOLEAN BootIndicator
;
35 ULONG PartitionNumber
; /* Enumerated partition number (primary partitions first -- excluding the extended partition container --, then the logical partitions) */
36 ULONG PartitionIndex
; /* Index in the LayoutBuffer->PartitionEntry[] cached array of the corresponding DiskEntry */
40 BOOLEAN LogicalPartition
;
42 /* Partition is partitioned disk space */
43 BOOLEAN IsPartitioned
;
45 /* Partition is new, table does not exist on disk yet */
48 /* Partition was created automatically */
51 /* Partition must be checked */
54 FORMATSTATE FormatState
;
55 struct _FILE_SYSTEM
* FileSystem
;
57 } PARTENTRY
, *PPARTENTRY
;
60 typedef struct _BIOSDISKENTRY
67 CM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry
;
68 CM_INT13_DRIVE_PARAMETER Int13DiskData
;
69 } BIOSDISKENTRY
, *PBIOSDISKENTRY
;
72 typedef struct _DISKENTRY
79 ULONG TracksPerCylinder
;
80 ULONG SectorsPerTrack
;
83 ULARGE_INTEGER SectorCount
;
84 ULONG SectorAlignment
;
85 ULONG CylinderAlignment
;
99 /* Has the partition list been modified? */
103 BOOLEAN NoMbr
; /* MBR is absent */ // See r40437
105 UNICODE_STRING DriverName
;
107 PDRIVE_LAYOUT_INFORMATION LayoutBuffer
;
108 // TODO: When adding support for GPT disks:
109 // Use PDRIVE_LAYOUT_INFORMATION_EX which indicates whether
110 // the disk is MBR, GPT, or unknown (uninitialized).
111 // Depending on the style, either use the MBR or GPT partition info.
113 /* Pointer to the unique extended partition on this disk */
114 PPARTENTRY ExtendedPartition
;
116 LIST_ENTRY PrimaryPartListHead
;
117 LIST_ENTRY LogicalPartListHead
;
119 } DISKENTRY
, *PDISKENTRY
;
122 typedef struct _PARTLIST
125 * Disk & Partition iterators.
127 * NOTE that when CurrentPartition != NULL, then CurrentPartition->DiskEntry
128 * must be the same as CurrentDisk. We should however keep the two members
129 * separated as we can have a current (selected) disk without any current
130 * partition, if the former does not contain any.
132 PDISKENTRY CurrentDisk
;
133 PPARTENTRY CurrentPartition
;
136 * The system partition where the boot manager resides.
137 * The corresponding system disk is obtained via:
138 * SystemPartition->DiskEntry.
140 PPARTENTRY SystemPartition
;
142 * The original system partition in case we are redefining it because
143 * we do not have write support on it.
144 * Please note that this is partly a HACK and MUST NEVER happen on
145 * architectures where real system partitions are mandatory (because then
146 * they are formatted in FAT FS and we support write operation on them).
147 * The corresponding original system disk is obtained via:
148 * OriginalSystemPartition->DiskEntry.
150 PPARTENTRY OriginalSystemPartition
;
152 LIST_ENTRY DiskListHead
;
153 LIST_ENTRY BiosDiskListHead
;
155 } PARTLIST
, *PPARTLIST
;
157 #define PARTITION_TBL_SIZE 4
159 #include <pshpack1.h>
161 typedef struct _PARTITION
163 unsigned char BootFlags
; /* bootable? 0=no, 128=yes */
164 unsigned char StartingHead
; /* beginning head number */
165 unsigned char StartingSector
; /* beginning sector number */
166 unsigned char StartingCylinder
; /* 10 bit nmbr, with high 2 bits put in begsect */
167 unsigned char PartitionType
; /* Operating System type indicator code */
168 unsigned char EndingHead
; /* ending head number */
169 unsigned char EndingSector
; /* ending sector number */
170 unsigned char EndingCylinder
; /* also a 10 bit nmbr, with same high 2 bit trick */
171 unsigned int StartingBlock
; /* first sector relative to start of disk */
172 unsigned int SectorCount
; /* number of sectors in partition */
173 } PARTITION
, *PPARTITION
;
175 typedef struct _PARTITION_SECTOR
177 UCHAR BootCode
[440]; /* 0x000 */
178 ULONG Signature
; /* 0x1B8 */
179 UCHAR Reserved
[2]; /* 0x1BC */
180 PARTITION Partition
[PARTITION_TBL_SIZE
]; /* 0x1BE */
181 USHORT Magic
; /* 0x1FE */
182 } PARTITION_SECTOR
, *PPARTITION_SECTOR
;
188 LIST_ENTRY ListEntry
;
192 } BIOS_DISK
, *PBIOS_DISK
;
208 IN ULONGLONG Dividend
,
209 IN ULONGLONG Divisor
);
214 CreatePartitionList(VOID
);
217 DestroyPartitionList(
224 IN ULONG PartitionNumber
);
235 CreatePrimaryPartition(
237 IN ULONGLONG SectorCount
,
238 IN BOOLEAN AutoCreate
);
241 CreateExtendedPartition(
243 IN ULONGLONG SectorCount
);
246 CreateLogicalPartition(
248 IN ULONGLONG SectorCount
,
249 IN BOOLEAN AutoCreate
);
252 DeleteCurrentPartition(
256 CheckActiveSystemPartition(
260 WritePartitionsToDisk(
264 SetMountedDeviceValue(
267 IN LARGE_INTEGER StartingOffset
);
270 SetMountedDeviceValues(
275 IN PPARTENTRY PartEntry
,
276 IN UCHAR PartitionType
);
279 PrimaryPartitionCreationChecks(
283 ExtendedPartitionCreationChecks(
287 LogicalPartitionCreationChecks(
291 GetNextUnformattedPartition(
293 OUT PDISKENTRY
*pDiskEntry OPTIONAL
,
294 OUT PPARTENTRY
*pPartEntry
);
297 GetNextUncheckedPartition(
299 OUT PDISKENTRY
*pDiskEntry OPTIONAL
,
300 OUT PPARTENTRY
*pPartEntry
);