7a6cec9487fd430028e837db6ad1f2ce57afd723
[reactos.git] / base / setup / lib / 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 2002-2018 Eric Kohl
6 * Copyright 2003-2018 Casper S. Hornstrup (chorns@users.sourceforge.net)
7 */
8
9 #pragma once
10
11 typedef enum _FORMATSTATE
12 {
13 Unformatted,
14 UnformattedOrDamaged,
15 UnknownFormat,
16 Preformatted,
17 Formatted
18 } FORMATSTATE, *PFORMATSTATE;
19
20 struct _FILE_SYSTEM;
21
22 typedef struct _PARTENTRY
23 {
24 LIST_ENTRY ListEntry;
25
26 /* The disk this partition belongs to */
27 struct _DISKENTRY *DiskEntry;
28
29 /* Partition geometry */
30 ULARGE_INTEGER StartSector;
31 ULARGE_INTEGER SectorCount;
32
33 BOOLEAN BootIndicator;
34 UCHAR PartitionType;
35 ULONG HiddenSectors;
36 ULONG PartitionNumber; /* Enumerated partition number (primary partitions first -- excluding the extended partition container --, then the logical partitions) */
37 ULONG PartitionIndex; /* Index in the LayoutBuffer->PartitionEntry[] cached array of the corresponding DiskEntry */
38
39 CHAR DriveLetter;
40
41 BOOLEAN LogicalPartition;
42
43 /* Partition is partitioned disk space */
44 BOOLEAN IsPartitioned;
45
46 /* Partition is new, table does not exist on disk yet */
47 BOOLEAN New;
48
49 /* Partition was created automatically */
50 BOOLEAN AutoCreate;
51
52 /* Partition must be checked */
53 BOOLEAN NeedsCheck;
54
55 FORMATSTATE FormatState;
56 struct _FILE_SYSTEM* FileSystem;
57
58 } PARTENTRY, *PPARTENTRY;
59
60
61 typedef struct _BIOSDISKENTRY
62 {
63 LIST_ENTRY ListEntry;
64 ULONG DiskNumber;
65 ULONG Signature;
66 ULONG Checksum;
67 BOOLEAN Recognized;
68 CM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry;
69 CM_INT13_DRIVE_PARAMETER Int13DiskData;
70 } BIOSDISKENTRY, *PBIOSDISKENTRY;
71
72
73 typedef struct _DISKENTRY
74 {
75 LIST_ENTRY ListEntry;
76
77 /* Disk geometry */
78
79 ULONGLONG Cylinders;
80 ULONG TracksPerCylinder;
81 ULONG SectorsPerTrack;
82 ULONG BytesPerSector;
83
84 ULARGE_INTEGER SectorCount;
85 ULONG SectorAlignment;
86 ULONG CylinderAlignment;
87
88 /* BIOS parameters */
89 BOOLEAN BiosFound;
90 ULONG BiosDiskNumber;
91 // ULONG Signature;
92 // ULONG Checksum;
93
94 /* SCSI parameters */
95 ULONG DiskNumber;
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 BOOLEAN
222 SelectPartition(
223 IN PPARTLIST List,
224 IN ULONG DiskNumber,
225 IN ULONG PartitionNumber);
226
227 PPARTENTRY
228 GetNextPartition(
229 IN PPARTLIST List);
230
231 PPARTENTRY
232 GetPrevPartition(
233 IN PPARTLIST List);
234
235 VOID
236 CreatePrimaryPartition(
237 IN PPARTLIST List,
238 IN ULONGLONG SectorCount,
239 IN BOOLEAN AutoCreate);
240
241 VOID
242 CreateExtendedPartition(
243 IN PPARTLIST List,
244 IN ULONGLONG SectorCount);
245
246 VOID
247 CreateLogicalPartition(
248 IN PPARTLIST List,
249 IN ULONGLONG SectorCount,
250 IN BOOLEAN AutoCreate);
251
252 VOID
253 DeleteCurrentPartition(
254 IN PPARTLIST List);
255
256 VOID
257 CheckActiveSystemPartition(
258 IN PPARTLIST List);
259
260 BOOLEAN
261 WritePartitionsToDisk(
262 IN PPARTLIST List);
263
264 BOOLEAN
265 SetMountedDeviceValue(
266 IN CHAR Letter,
267 IN ULONG Signature,
268 IN LARGE_INTEGER StartingOffset);
269
270 BOOLEAN
271 SetMountedDeviceValues(
272 IN PPARTLIST List);
273
274 VOID
275 SetPartitionType(
276 IN PPARTENTRY PartEntry,
277 IN UCHAR PartitionType);
278
279 ERROR_NUMBER
280 PrimaryPartitionCreationChecks(
281 IN PPARTLIST List);
282
283 ERROR_NUMBER
284 ExtendedPartitionCreationChecks(
285 IN PPARTLIST List);
286
287 ERROR_NUMBER
288 LogicalPartitionCreationChecks(
289 IN PPARTLIST List);
290
291 BOOLEAN
292 GetNextUnformattedPartition(
293 IN PPARTLIST List,
294 OUT PDISKENTRY *pDiskEntry OPTIONAL,
295 OUT PPARTENTRY *pPartEntry);
296
297 BOOLEAN
298 GetNextUncheckedPartition(
299 IN PPARTLIST List,
300 OUT PDISKENTRY *pDiskEntry OPTIONAL,
301 OUT PPARTENTRY *pPartEntry);
302
303 /* EOF */