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 /* HELPERS FOR PARTITION TYPES **********************************************/
12 typedef struct _PARTITION_TYPE
16 } PARTITION_TYPE
, *PPARTITION_TYPE
;
18 #define NUM_PARTITION_TYPE_ENTRIES 143
19 extern PARTITION_TYPE PartitionTypes
[NUM_PARTITION_TYPE_ENTRIES
];
22 /* PARTITION UTILITY FUNCTIONS **********************************************/
24 typedef enum _FORMATSTATE
31 } FORMATSTATE
, *PFORMATSTATE
;
35 typedef struct _PARTENTRY
39 /* The disk this partition belongs to */
40 struct _DISKENTRY
*DiskEntry
;
42 /* Partition geometry */
43 ULARGE_INTEGER StartSector
;
44 ULARGE_INTEGER SectorCount
;
46 BOOLEAN BootIndicator
;
49 ULONG PartitionNumber
; /* Enumerated partition number (primary partitions first -- excluding the extended partition container --, then the logical partitions) */
50 ULONG PartitionIndex
; /* Index in the LayoutBuffer->PartitionEntry[] cached array of the corresponding DiskEntry */
53 WCHAR VolumeLabel
[20];
54 // CHAR FileSystemName[9]; // NOTE: Superseded by the FileSystem member
56 BOOLEAN LogicalPartition
;
58 /* Partition is partitioned disk space */
59 BOOLEAN IsPartitioned
;
61 /* Partition is new, table does not exist on disk yet */
64 /* Partition was created automatically */
67 /* Partition must be checked */
70 FORMATSTATE FormatState
;
71 struct _FILE_SYSTEM
* FileSystem
;
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? */
120 BOOLEAN NoMbr
; /* MBR is absent */ // See r40437
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 /* Pointer to the unique extended partition on this disk */
131 PPARTENTRY ExtendedPartition
;
133 LIST_ENTRY PrimaryPartListHead
;
134 LIST_ENTRY LogicalPartListHead
;
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 #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 CreatePartitionList(VOID
);
234 DestroyPartitionList(
240 IN ULONG BiosDiskNumber
);
245 IN ULONG DiskNumber
);
261 // IN PPARTLIST List,
262 IN PDISKENTRY DiskEntry
,
263 IN ULONG PartitionNumber
);
269 IN ULONG PartitionNumber OPTIONAL
,
270 OUT PDISKENTRY
* pDiskEntry
,
271 OUT PPARTENTRY
* pPartEntry OPTIONAL
);
277 IN ULONG PartitionNumber
);
288 CreatePrimaryPartition(
290 IN ULONGLONG SectorCount
,
291 IN BOOLEAN AutoCreate
);
294 CreateExtendedPartition(
296 IN ULONGLONG SectorCount
);
299 CreateLogicalPartition(
301 IN ULONGLONG SectorCount
,
302 IN BOOLEAN AutoCreate
);
305 DeleteCurrentPartition(
309 CheckActiveSystemPartition(
313 WritePartitionsToDisk(
317 SetMountedDeviceValue(
320 IN LARGE_INTEGER StartingOffset
);
323 SetMountedDeviceValues(
328 IN PPARTENTRY PartEntry
,
329 IN UCHAR PartitionType
);
332 PrimaryPartitionCreationChecks(
336 ExtendedPartitionCreationChecks(
340 LogicalPartitionCreationChecks(
344 GetNextUnformattedPartition(
346 OUT PDISKENTRY
*pDiskEntry OPTIONAL
,
347 OUT PPARTENTRY
*pPartEntry
);
350 GetNextUncheckedPartition(
352 OUT PDISKENTRY
*pDiskEntry OPTIONAL
,
353 OUT PPARTENTRY
*pPartEntry
);