[USETUP] Similarly to what was done for GenLists, factor out the UI code from the...
[reactos.git] / base / setup / usetup / partlist.h
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2002, 2003 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 /* COPYRIGHT: See COPYING in the top level directory
20 * PROJECT: ReactOS text-mode setup
21 * FILE: base/setup/usetup/partlist.h
22 * PURPOSE: Partition list functions
23 * PROGRAMMER: Eric Kohl
24 */
25
26 #pragma once
27
28 typedef enum _FORMATSTATE
29 {
30 Unformatted,
31 UnformattedOrDamaged,
32 UnknownFormat,
33 Preformatted,
34 Formatted
35 } FORMATSTATE, *PFORMATSTATE;
36
37 typedef enum _FORMATMACHINESTATE
38 {
39 Start,
40 FormatSystemPartition,
41 FormatInstallPartition,
42 FormatOtherPartition,
43 FormatDone,
44 CheckSystemPartition,
45 CheckInstallPartition,
46 CheckOtherPartition,
47 CheckDone
48 } FORMATMACHINESTATE, *PFORMATMACHINESTATE;
49
50 typedef struct _PARTENTRY
51 {
52 LIST_ENTRY ListEntry;
53
54 /* The disk this partition belongs to */
55 struct _DISKENTRY *DiskEntry;
56
57 /* Partition geometry */
58 ULARGE_INTEGER StartSector;
59 ULARGE_INTEGER SectorCount;
60
61 BOOLEAN BootIndicator;
62 UCHAR PartitionType;
63 ULONG HiddenSectors;
64 ULONG PartitionNumber; /* Enumerated partition number (primary partitions first -- excluding the extended partition container --, then the logical partitions) */
65 ULONG PartitionIndex; /* Index in the LayoutBuffer->PartitionEntry[] cached array of the corresponding DiskEntry */
66
67 CHAR DriveLetter;
68
69 BOOLEAN LogicalPartition;
70
71 /* Partition is partitioned disk space */
72 BOOLEAN IsPartitioned;
73
74 /* Partition is new, table does not exist on disk yet */
75 BOOLEAN New;
76
77 /* Partition was created automatically */
78 BOOLEAN AutoCreate;
79
80 /* Partition must be checked */
81 BOOLEAN NeedsCheck;
82
83 FORMATSTATE FormatState;
84 struct _FILE_SYSTEM_ITEM *FileSystem;
85
86 } PARTENTRY, *PPARTENTRY;
87
88
89 typedef struct _BIOSDISKENTRY
90 {
91 LIST_ENTRY ListEntry;
92 ULONG DiskNumber;
93 ULONG Signature;
94 ULONG Checksum;
95 BOOLEAN Recognized;
96 CM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry;
97 CM_INT13_DRIVE_PARAMETER Int13DiskData;
98 } BIOSDISKENTRY, *PBIOSDISKENTRY;
99
100
101 typedef struct _DISKENTRY
102 {
103 LIST_ENTRY ListEntry;
104
105 /* Disk geometry */
106
107 ULONGLONG Cylinders;
108 ULONG TracksPerCylinder;
109 ULONG SectorsPerTrack;
110 ULONG BytesPerSector;
111
112 ULARGE_INTEGER SectorCount;
113 ULONG SectorAlignment;
114 ULONG CylinderAlignment;
115
116 /* BIOS parameters */
117 BOOLEAN BiosFound;
118 ULONG BiosDiskNumber;
119 // ULONG Signature;
120 // ULONG Checksum;
121
122 /* SCSI parameters */
123 ULONG DiskNumber;
124 USHORT Port;
125 USHORT Bus;
126 USHORT Id;
127
128 /* Has the partition list been modified? */
129 BOOLEAN Dirty;
130
131 BOOLEAN NewDisk;
132 BOOLEAN NoMbr; /* MBR is absent */ // See r40437
133
134 UNICODE_STRING DriverName;
135
136 PDRIVE_LAYOUT_INFORMATION LayoutBuffer;
137 // TODO: When adding support for GPT disks:
138 // Use PDRIVE_LAYOUT_INFORMATION_EX which indicates whether
139 // the disk is MBR, GPT, or unknown (uninitialized).
140 // Depending on the style, either use the MBR or GPT partition info.
141
142 /* Pointer to the unique extended partition on this disk */
143 PPARTENTRY ExtendedPartition;
144
145 LIST_ENTRY PrimaryPartListHead;
146 LIST_ENTRY LogicalPartListHead;
147
148 } DISKENTRY, *PDISKENTRY;
149
150
151 typedef struct _PARTLIST
152 {
153 /*
154 * Disk & Partition iterators.
155 *
156 * NOTE that when CurrentPartition != NULL, then CurrentPartition->DiskEntry
157 * must be the same as CurrentDisk. We should however keep the two members
158 * separated as we can have a current (selected) disk without any current
159 * partition, if the former does not contain any.
160 */
161 PDISKENTRY CurrentDisk;
162 PPARTENTRY CurrentPartition;
163
164 /*
165 * The system partition where the boot manager resides.
166 * The corresponding system disk is obtained via:
167 * SystemPartition->DiskEntry.
168 */
169 PPARTENTRY SystemPartition;
170 /*
171 * The original system partition in case we are redefining it because
172 * we do not have write support on it.
173 * Please note that this is partly a HACK and MUST NEVER happen on
174 * architectures where real system partitions are mandatory (because then
175 * they are formatted in FAT FS and we support write operation on them).
176 * The corresponding original system disk is obtained via:
177 * OriginalSystemPartition->DiskEntry.
178 */
179 PPARTENTRY OriginalSystemPartition;
180
181 PPARTENTRY TempPartition;
182 FORMATMACHINESTATE FormatState;
183
184 LIST_ENTRY DiskListHead;
185 LIST_ENTRY BiosDiskListHead;
186
187 } PARTLIST, *PPARTLIST;
188
189 #define PARTITION_TBL_SIZE 4
190
191 #include <pshpack1.h>
192
193 typedef struct _PARTITION
194 {
195 unsigned char BootFlags; /* bootable? 0=no, 128=yes */
196 unsigned char StartingHead; /* beginning head number */
197 unsigned char StartingSector; /* beginning sector number */
198 unsigned char StartingCylinder; /* 10 bit nmbr, with high 2 bits put in begsect */
199 unsigned char PartitionType; /* Operating System type indicator code */
200 unsigned char EndingHead; /* ending head number */
201 unsigned char EndingSector; /* ending sector number */
202 unsigned char EndingCylinder; /* also a 10 bit nmbr, with same high 2 bit trick */
203 unsigned int StartingBlock; /* first sector relative to start of disk */
204 unsigned int SectorCount; /* number of sectors in partition */
205 } PARTITION, *PPARTITION;
206
207 typedef struct _PARTITION_SECTOR
208 {
209 UCHAR BootCode[440]; /* 0x000 */
210 ULONG Signature; /* 0x1B8 */
211 UCHAR Reserved[2]; /* 0x1BC */
212 PARTITION Partition[PARTITION_TBL_SIZE]; /* 0x1BE */
213 USHORT Magic; /* 0x1FE */
214 } PARTITION_SECTOR, *PPARTITION_SECTOR;
215
216 #include <poppack.h>
217
218 typedef struct
219 {
220 LIST_ENTRY ListEntry;
221 ULONG DiskNumber;
222 ULONG Identifier;
223 ULONG Signature;
224 } BIOS_DISK, *PBIOS_DISK;
225
226 VOID
227 GetPartTypeStringFromPartitionType(
228 IN UCHAR partitionType,
229 OUT PCHAR strPartType,
230 IN ULONG cchPartType);
231
232 PPARTLIST
233 CreatePartitionList(VOID);
234
235 VOID
236 DestroyPartitionList(
237 IN PPARTLIST List);
238
239 ULONG
240 SelectPartition(
241 IN PPARTLIST List,
242 IN ULONG DiskNumber,
243 IN ULONG PartitionNumber);
244
245 PPARTENTRY
246 GetNextPartition(
247 IN PPARTLIST List);
248
249 PPARTENTRY
250 GetPrevPartition(
251 IN PPARTLIST List);
252
253 VOID
254 CreatePrimaryPartition(
255 IN PPARTLIST List,
256 IN ULONGLONG SectorCount,
257 IN BOOLEAN AutoCreate);
258
259 VOID
260 CreateExtendedPartition(
261 IN PPARTLIST List,
262 IN ULONGLONG SectorCount);
263
264 VOID
265 CreateLogicalPartition(
266 IN PPARTLIST List,
267 IN ULONGLONG SectorCount,
268 IN BOOLEAN AutoCreate);
269
270 VOID
271 DeleteCurrentPartition(
272 IN PPARTLIST List);
273
274 VOID
275 CheckActiveSystemPartition(
276 IN PPARTLIST List,
277 IN PFILE_SYSTEM_LIST FileSystemList);
278
279 BOOLEAN
280 WritePartitionsToDisk(
281 IN PPARTLIST List);
282
283 BOOLEAN
284 SetMountedDeviceValues(
285 IN PPARTLIST List);
286
287 VOID
288 SetPartitionType(
289 IN PPARTENTRY PartEntry,
290 IN UCHAR PartitionType);
291
292 ULONG
293 PrimaryPartitionCreationChecks(
294 IN PPARTLIST List);
295
296 ULONG
297 ExtendedPartitionCreationChecks(
298 IN PPARTLIST List);
299
300 ULONG
301 LogicalPartitionCreationChecks(
302 IN PPARTLIST List);
303
304 BOOLEAN
305 GetNextUnformattedPartition(
306 IN PPARTLIST List,
307 OUT PDISKENTRY *pDiskEntry OPTIONAL,
308 OUT PPARTENTRY *pPartEntry);
309
310 BOOLEAN
311 GetNextUncheckedPartition(
312 IN PPARTLIST List,
313 OUT PDISKENTRY *pDiskEntry OPTIONAL,
314 OUT PPARTENTRY *pPartEntry);
315
316
317
318
319
320 typedef struct _PARTLIST_UI
321 {
322 PPARTLIST List;
323
324 // PLIST_ENTRY FirstShown;
325 // PLIST_ENTRY LastShown;
326
327 SHORT Left;
328 SHORT Top;
329 SHORT Right;
330 SHORT Bottom;
331
332 SHORT Line;
333 SHORT Offset;
334
335 // BOOL Redraw;
336 } PARTLIST_UI, *PPARTLIST_UI;
337
338 VOID
339 InitPartitionListUi(
340 IN OUT PPARTLIST_UI ListUi,
341 IN PPARTLIST List,
342 IN SHORT Left,
343 IN SHORT Top,
344 IN SHORT Right,
345 IN SHORT Bottom);
346
347 VOID
348 ScrollDownPartitionList(
349 IN PPARTLIST_UI ListUi);
350
351 VOID
352 ScrollUpPartitionList(
353 IN PPARTLIST_UI ListUi);
354
355 VOID
356 DrawPartitionList(
357 IN PPARTLIST_UI ListUi);
358
359 /* EOF */