[SETUPLIB][USETUP] Remove CurrentDisk/Partition from the partlist lib code, and move...
[reactos.git] / base / setup / lib / utils / partlist.h
1 /*
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
7 */
8
9 #pragma once
10
11 /* HELPERS FOR PARTITION TYPES **********************************************/
12
13 typedef struct _PARTITION_TYPE
14 {
15 UCHAR Type;
16 PCHAR Description;
17 } PARTITION_TYPE, *PPARTITION_TYPE;
18
19 #define NUM_PARTITION_TYPE_ENTRIES 143
20 extern PARTITION_TYPE PartitionTypes[NUM_PARTITION_TYPE_ENTRIES];
21
22
23 /* PARTITION UTILITY FUNCTIONS **********************************************/
24
25 typedef enum _FORMATSTATE
26 {
27 Unformatted,
28 UnformattedOrDamaged,
29 UnknownFormat,
30 Preformatted,
31 Formatted
32 } FORMATSTATE, *PFORMATSTATE;
33
34 typedef struct _PARTENTRY
35 {
36 LIST_ENTRY ListEntry;
37
38 /* The disk this partition belongs to */
39 struct _DISKENTRY *DiskEntry;
40
41 /* Partition geometry */
42 ULARGE_INTEGER StartSector;
43 ULARGE_INTEGER SectorCount;
44
45 BOOLEAN BootIndicator;
46 UCHAR PartitionType;
47 ULONG HiddenSectors;
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 */
51
52 WCHAR DriveLetter;
53 WCHAR VolumeLabel[20];
54 WCHAR FileSystem[MAX_PATH+1];
55 FORMATSTATE FormatState;
56
57 BOOLEAN LogicalPartition;
58
59 /* Partition is partitioned disk space */
60 BOOLEAN IsPartitioned;
61
62 /** The following three properties may be replaced by flags **/
63
64 /* Partition is new, table does not exist on disk yet */
65 BOOLEAN New;
66
67 /* Partition was created automatically */
68 BOOLEAN AutoCreate;
69
70 /* Partition must be checked */
71 BOOLEAN NeedsCheck;
72
73 } PARTENTRY, *PPARTENTRY;
74
75
76 typedef struct _BIOSDISKENTRY
77 {
78 LIST_ENTRY ListEntry;
79 ULONG DiskNumber;
80 ULONG Signature;
81 ULONG Checksum;
82 BOOLEAN Recognized;
83 CM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry;
84 CM_INT13_DRIVE_PARAMETER Int13DiskData;
85 } BIOSDISKENTRY, *PBIOSDISKENTRY;
86
87
88 typedef struct _DISKENTRY
89 {
90 LIST_ENTRY ListEntry;
91
92 /* The list of disks/partitions this disk belongs to */
93 struct _PARTLIST *PartList;
94
95 /* Disk geometry */
96
97 ULONGLONG Cylinders;
98 ULONG TracksPerCylinder;
99 ULONG SectorsPerTrack;
100 ULONG BytesPerSector;
101
102 ULARGE_INTEGER SectorCount;
103 ULONG SectorAlignment;
104 ULONG CylinderAlignment;
105
106 /* BIOS parameters */
107 BOOLEAN BiosFound;
108 ULONG BiosDiskNumber;
109 // ULONG Signature; // Obtained from LayoutBuffer->Signature
110 // ULONG Checksum;
111
112 /* SCSI parameters */
113 ULONG DiskNumber;
114 // SCSI_ADDRESS;
115 USHORT Port;
116 USHORT Bus;
117 USHORT Id;
118
119 /* Has the partition list been modified? */
120 BOOLEAN Dirty;
121
122 BOOLEAN NewDisk; /* If TRUE, the disk is uninitialized */
123 PARTITION_STYLE DiskStyle; /* MBR/GPT-partitioned disk, or uninitialized disk (RAW) */
124
125 UNICODE_STRING DriverName;
126
127 PDRIVE_LAYOUT_INFORMATION LayoutBuffer;
128 // TODO: When adding support for GPT disks:
129 // Use PDRIVE_LAYOUT_INFORMATION_EX which indicates whether
130 // the disk is MBR, GPT, or unknown (uninitialized).
131 // Depending on the style, either use the MBR or GPT partition info.
132
133 LIST_ENTRY PrimaryPartListHead; /* List of primary partitions */
134 LIST_ENTRY LogicalPartListHead; /* List of logical partitions (Valid only for MBR-partitioned disks) */
135
136 /* Pointer to the unique extended partition on this disk (Valid only for MBR-partitioned disks) */
137 PPARTENTRY ExtendedPartition;
138
139 } DISKENTRY, *PDISKENTRY;
140
141
142 typedef struct _PARTLIST
143 {
144 /*
145 * The system partition where the boot manager resides.
146 * The corresponding system disk is obtained via:
147 * SystemPartition->DiskEntry.
148 */
149 PPARTENTRY SystemPartition;
150 /*
151 * The original system partition in case we are redefining it because
152 * we do not have write support on it.
153 * Please note that this is partly a HACK and MUST NEVER happen on
154 * architectures where real system partitions are mandatory (because then
155 * they are formatted in FAT FS and we support write operation on them).
156 * The corresponding original system disk is obtained via:
157 * OriginalSystemPartition->DiskEntry.
158 */
159 PPARTENTRY OriginalSystemPartition;
160
161 LIST_ENTRY DiskListHead;
162 LIST_ENTRY BiosDiskListHead;
163
164 } PARTLIST, *PPARTLIST;
165
166 #define PARTITION_TBL_SIZE 4
167
168 #define PARTITION_MAGIC 0xAA55
169
170 /* Defines system type for MBR showing that a GPT is following */
171 #define EFI_PMBR_OSTYPE_EFI 0xEE
172
173 #include <pshpack1.h>
174
175 typedef struct _PARTITION
176 {
177 unsigned char BootFlags; /* bootable? 0=no, 128=yes */
178 unsigned char StartingHead; /* beginning head number */
179 unsigned char StartingSector; /* beginning sector number */
180 unsigned char StartingCylinder; /* 10 bit nmbr, with high 2 bits put in begsect */
181 unsigned char PartitionType; /* Operating System type indicator code */
182 unsigned char EndingHead; /* ending head number */
183 unsigned char EndingSector; /* ending sector number */
184 unsigned char EndingCylinder; /* also a 10 bit nmbr, with same high 2 bit trick */
185 unsigned int StartingBlock; /* first sector relative to start of disk */
186 unsigned int SectorCount; /* number of sectors in partition */
187 } PARTITION, *PPARTITION;
188
189 typedef struct _PARTITION_SECTOR
190 {
191 UCHAR BootCode[440]; /* 0x000 */
192 ULONG Signature; /* 0x1B8 */
193 UCHAR Reserved[2]; /* 0x1BC */
194 PARTITION Partition[PARTITION_TBL_SIZE]; /* 0x1BE */
195 USHORT Magic; /* 0x1FE */
196 } PARTITION_SECTOR, *PPARTITION_SECTOR;
197
198 #include <poppack.h>
199
200 typedef struct
201 {
202 LIST_ENTRY ListEntry;
203 ULONG DiskNumber;
204 ULONG Identifier;
205 ULONG Signature;
206 } BIOS_DISK, *PBIOS_DISK;
207
208
209
210 ULONGLONG
211 AlignDown(
212 IN ULONGLONG Value,
213 IN ULONG Alignment);
214
215 ULONGLONG
216 AlignUp(
217 IN ULONGLONG Value,
218 IN ULONG Alignment);
219
220 ULONGLONG
221 RoundingDivide(
222 IN ULONGLONG Dividend,
223 IN ULONGLONG Divisor);
224
225
226
227 PPARTLIST
228 CreatePartitionList(VOID);
229
230 VOID
231 DestroyPartitionList(
232 IN PPARTLIST List);
233
234 PDISKENTRY
235 GetDiskByBiosNumber(
236 IN PPARTLIST List,
237 IN ULONG BiosDiskNumber);
238
239 PDISKENTRY
240 GetDiskByNumber(
241 IN PPARTLIST List,
242 IN ULONG DiskNumber);
243
244 PDISKENTRY
245 GetDiskBySCSI(
246 IN PPARTLIST List,
247 IN USHORT Port,
248 IN USHORT Bus,
249 IN USHORT Id);
250
251 PDISKENTRY
252 GetDiskBySignature(
253 IN PPARTLIST List,
254 IN ULONG Signature);
255
256 PPARTENTRY
257 GetPartition(
258 // IN PPARTLIST List,
259 IN PDISKENTRY DiskEntry,
260 IN ULONG PartitionNumber);
261
262 BOOLEAN
263 GetDiskOrPartition(
264 IN PPARTLIST List,
265 IN ULONG DiskNumber,
266 IN ULONG PartitionNumber OPTIONAL,
267 OUT PDISKENTRY* pDiskEntry,
268 OUT PPARTENTRY* pPartEntry OPTIONAL);
269
270 PPARTENTRY
271 SelectPartition(
272 IN PPARTLIST List,
273 IN ULONG DiskNumber,
274 IN ULONG PartitionNumber);
275
276 PPARTENTRY
277 GetNextPartition(
278 IN PPARTLIST List,
279 IN PPARTENTRY CurrentPart OPTIONAL);
280
281 PPARTENTRY
282 GetPrevPartition(
283 IN PPARTLIST List,
284 IN PPARTENTRY CurrentPart OPTIONAL);
285
286 BOOLEAN
287 CreatePrimaryPartition(
288 IN PPARTLIST List,
289 IN PPARTENTRY SelectedEntry,
290 IN ULONGLONG SectorCount,
291 IN BOOLEAN AutoCreate);
292
293 BOOLEAN
294 CreateExtendedPartition(
295 IN PPARTLIST List,
296 IN PPARTENTRY SelectedEntry,
297 IN ULONGLONG SectorCount);
298
299 BOOLEAN
300 CreateLogicalPartition(
301 IN PPARTLIST List,
302 IN PPARTENTRY SelectedEntry,
303 IN ULONGLONG SectorCount,
304 IN BOOLEAN AutoCreate);
305
306 BOOLEAN
307 DeletePartition(
308 IN PPARTLIST List,
309 IN PPARTENTRY PartEntry,
310 OUT PPARTENTRY* FreeRegion OPTIONAL);
311
312 VOID
313 CheckActiveSystemPartition(
314 IN PPARTLIST List,
315 IN BOOLEAN ForceSelect,
316 IN PDISKENTRY AlternateDisk OPTIONAL,
317 IN PPARTENTRY AlternatePart OPTIONAL);
318
319 NTSTATUS
320 WritePartitions(
321 IN PDISKENTRY DiskEntry);
322
323 BOOLEAN
324 WritePartitionsToDisk(
325 IN PPARTLIST List);
326
327 BOOLEAN
328 SetMountedDeviceValue(
329 IN WCHAR Letter,
330 IN ULONG Signature,
331 IN LARGE_INTEGER StartingOffset);
332
333 BOOLEAN
334 SetMountedDeviceValues(
335 IN PPARTLIST List);
336
337 VOID
338 SetPartitionType(
339 IN PPARTENTRY PartEntry,
340 IN UCHAR PartitionType);
341
342 ERROR_NUMBER
343 PrimaryPartitionCreationChecks(
344 IN PPARTENTRY PartEntry);
345
346 ERROR_NUMBER
347 ExtendedPartitionCreationChecks(
348 IN PPARTENTRY PartEntry);
349
350 ERROR_NUMBER
351 LogicalPartitionCreationChecks(
352 IN PPARTENTRY PartEntry);
353
354 BOOLEAN
355 GetNextUnformattedPartition(
356 IN PPARTLIST List,
357 OUT PDISKENTRY *pDiskEntry OPTIONAL,
358 OUT PPARTENTRY *pPartEntry);
359
360 BOOLEAN
361 GetNextUncheckedPartition(
362 IN PPARTLIST List,
363 OUT PDISKENTRY *pDiskEntry OPTIONAL,
364 OUT PPARTENTRY *pPartEntry);
365
366 /* EOF */