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