[SETUP] Remove myself from the 1st stage setup code
[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 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;
91 // ULONG Checksum;
92
93 /* SCSI parameters */
94 ULONG DiskNumber;
95 USHORT Port;
96 USHORT Bus;
97 USHORT Id;
98
99 /* Has the partition list been modified? */
100 BOOLEAN Dirty;
101
102 BOOLEAN NewDisk;
103 BOOLEAN NoMbr; /* MBR is absent */ // See r40437
104
105 UNICODE_STRING DriverName;
106
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.
112
113 /* Pointer to the unique extended partition on this disk */
114 PPARTENTRY ExtendedPartition;
115
116 LIST_ENTRY PrimaryPartListHead;
117 LIST_ENTRY LogicalPartListHead;
118
119 } DISKENTRY, *PDISKENTRY;
120
121
122 typedef struct _PARTLIST
123 {
124 /*
125 * Disk & Partition iterators.
126 *
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.
131 */
132 PDISKENTRY CurrentDisk;
133 PPARTENTRY CurrentPartition;
134
135 /*
136 * The system partition where the boot manager resides.
137 * The corresponding system disk is obtained via:
138 * SystemPartition->DiskEntry.
139 */
140 PPARTENTRY SystemPartition;
141 /*
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.
149 */
150 PPARTENTRY OriginalSystemPartition;
151
152 LIST_ENTRY DiskListHead;
153 LIST_ENTRY BiosDiskListHead;
154
155 } PARTLIST, *PPARTLIST;
156
157 #define PARTITION_TBL_SIZE 4
158
159 #include <pshpack1.h>
160
161 typedef struct _PARTITION
162 {
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;
174
175 typedef struct _PARTITION_SECTOR
176 {
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;
183
184 #include <poppack.h>
185
186 typedef struct
187 {
188 LIST_ENTRY ListEntry;
189 ULONG DiskNumber;
190 ULONG Identifier;
191 ULONG Signature;
192 } BIOS_DISK, *PBIOS_DISK;
193
194
195
196 ULONGLONG
197 AlignDown(
198 IN ULONGLONG Value,
199 IN ULONG Alignment);
200
201 ULONGLONG
202 AlignUp(
203 IN ULONGLONG Value,
204 IN ULONG Alignment);
205
206 ULONGLONG
207 RoundingDivide(
208 IN ULONGLONG Dividend,
209 IN ULONGLONG Divisor);
210
211
212
213 PPARTLIST
214 CreatePartitionList(VOID);
215
216 VOID
217 DestroyPartitionList(
218 IN PPARTLIST List);
219
220 BOOLEAN
221 SelectPartition(
222 IN PPARTLIST List,
223 IN ULONG DiskNumber,
224 IN ULONG PartitionNumber);
225
226 PPARTENTRY
227 GetNextPartition(
228 IN PPARTLIST List);
229
230 PPARTENTRY
231 GetPrevPartition(
232 IN PPARTLIST List);
233
234 VOID
235 CreatePrimaryPartition(
236 IN PPARTLIST List,
237 IN ULONGLONG SectorCount,
238 IN BOOLEAN AutoCreate);
239
240 VOID
241 CreateExtendedPartition(
242 IN PPARTLIST List,
243 IN ULONGLONG SectorCount);
244
245 VOID
246 CreateLogicalPartition(
247 IN PPARTLIST List,
248 IN ULONGLONG SectorCount,
249 IN BOOLEAN AutoCreate);
250
251 VOID
252 DeleteCurrentPartition(
253 IN PPARTLIST List);
254
255 VOID
256 CheckActiveSystemPartition(
257 IN PPARTLIST List);
258
259 BOOLEAN
260 WritePartitionsToDisk(
261 IN PPARTLIST List);
262
263 BOOLEAN
264 SetMountedDeviceValue(
265 IN CHAR Letter,
266 IN ULONG Signature,
267 IN LARGE_INTEGER StartingOffset);
268
269 BOOLEAN
270 SetMountedDeviceValues(
271 IN PPARTLIST List);
272
273 VOID
274 SetPartitionType(
275 IN PPARTENTRY PartEntry,
276 IN UCHAR PartitionType);
277
278 ERROR_NUMBER
279 PrimaryPartitionCreationChecks(
280 IN PPARTLIST List);
281
282 ERROR_NUMBER
283 ExtendedPartitionCreationChecks(
284 IN PPARTLIST List);
285
286 ERROR_NUMBER
287 LogicalPartitionCreationChecks(
288 IN PPARTLIST List);
289
290 BOOLEAN
291 GetNextUnformattedPartition(
292 IN PPARTLIST List,
293 OUT PDISKENTRY *pDiskEntry OPTIONAL,
294 OUT PPARTENTRY *pPartEntry);
295
296 BOOLEAN
297 GetNextUncheckedPartition(
298 IN PPARTLIST List,
299 OUT PDISKENTRY *pDiskEntry OPTIONAL,
300 OUT PPARTENTRY *pPartEntry);
301
302 /* EOF */