35c83b3f17acea0f2797df02c87518dc7ac6b468
[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 /* UI stuff */
154 SHORT Left;
155 SHORT Top;
156 SHORT Right;
157 SHORT Bottom;
158
159 SHORT Line;
160 SHORT Offset;
161
162 /*
163 * NOTE that when CurrentPartition != NULL, then CurrentPartition->DiskEntry
164 * must be the same as CurrentDisk. We should however keep the two members
165 * separated as we can have a current (selected) disk without any current
166 * partition, if the former does not contain any.
167 */
168 PDISKENTRY CurrentDisk;
169 PPARTENTRY CurrentPartition;
170
171 /*
172 * The system partition where the boot manager resides.
173 * The corresponding system disk is obtained via:
174 * SystemPartition->DiskEntry.
175 */
176 PPARTENTRY SystemPartition;
177 /*
178 * The original system partition in case we are redefining it because
179 * we do not have write support on it.
180 * Please note that this is partly a HACK and MUST NEVER happen on
181 * architectures where real system partitions are mandatory (because then
182 * they are formatted in FAT FS and we support write operation on them).
183 * The corresponding original system disk is obtained via:
184 * OriginalSystemPartition->DiskEntry.
185 */
186 PPARTENTRY OriginalSystemPartition;
187
188 PPARTENTRY TempPartition;
189 FORMATMACHINESTATE FormatState;
190
191 LIST_ENTRY DiskListHead;
192 LIST_ENTRY BiosDiskListHead;
193
194 } PARTLIST, *PPARTLIST;
195
196 #define PARTITION_TBL_SIZE 4
197
198 #include <pshpack1.h>
199
200 typedef struct _PARTITION
201 {
202 unsigned char BootFlags; /* bootable? 0=no, 128=yes */
203 unsigned char StartingHead; /* beginning head number */
204 unsigned char StartingSector; /* beginning sector number */
205 unsigned char StartingCylinder; /* 10 bit nmbr, with high 2 bits put in begsect */
206 unsigned char PartitionType; /* Operating System type indicator code */
207 unsigned char EndingHead; /* ending head number */
208 unsigned char EndingSector; /* ending sector number */
209 unsigned char EndingCylinder; /* also a 10 bit nmbr, with same high 2 bit trick */
210 unsigned int StartingBlock; /* first sector relative to start of disk */
211 unsigned int SectorCount; /* number of sectors in partition */
212 } PARTITION, *PPARTITION;
213
214 typedef struct _PARTITION_SECTOR
215 {
216 UCHAR BootCode[440]; /* 0x000 */
217 ULONG Signature; /* 0x1B8 */
218 UCHAR Reserved[2]; /* 0x1BC */
219 PARTITION Partition[PARTITION_TBL_SIZE]; /* 0x1BE */
220 USHORT Magic; /* 0x1FE */
221 } PARTITION_SECTOR, *PPARTITION_SECTOR;
222
223 #include <poppack.h>
224
225 typedef struct
226 {
227 LIST_ENTRY ListEntry;
228 ULONG DiskNumber;
229 ULONG Identifier;
230 ULONG Signature;
231 } BIOS_DISK, *PBIOS_DISK;
232
233 VOID
234 GetPartTypeStringFromPartitionType(
235 IN UCHAR partitionType,
236 OUT PCHAR strPartType,
237 IN ULONG cchPartType);
238
239 PPARTLIST
240 CreatePartitionList(
241 SHORT Left,
242 SHORT Top,
243 SHORT Right,
244 SHORT Bottom);
245
246 VOID
247 DestroyPartitionList(
248 IN PPARTLIST List);
249
250 VOID
251 DrawPartitionList(
252 IN PPARTLIST List);
253
254 ULONG
255 SelectPartition(
256 IN PPARTLIST List,
257 IN ULONG DiskNumber,
258 IN ULONG PartitionNumber);
259
260 BOOL
261 ScrollDownPartitionList(
262 IN PPARTLIST List);
263
264 BOOL
265 ScrollUpPartitionList(
266 IN PPARTLIST List);
267
268 VOID
269 CreatePrimaryPartition(
270 IN PPARTLIST List,
271 IN ULONGLONG SectorCount,
272 IN BOOLEAN AutoCreate);
273
274 VOID
275 CreateExtendedPartition(
276 IN PPARTLIST List,
277 IN ULONGLONG SectorCount);
278
279 VOID
280 CreateLogicalPartition(
281 IN PPARTLIST List,
282 IN ULONGLONG SectorCount,
283 IN BOOLEAN AutoCreate);
284
285 VOID
286 DeleteCurrentPartition(
287 IN PPARTLIST List);
288
289 VOID
290 CheckActiveSystemPartition(
291 IN PPARTLIST List,
292 IN PFILE_SYSTEM_LIST FileSystemList);
293
294 BOOLEAN
295 WritePartitionsToDisk(
296 IN PPARTLIST List);
297
298 BOOLEAN
299 SetMountedDeviceValues(
300 IN PPARTLIST List);
301
302 VOID
303 SetPartitionType(
304 IN PPARTENTRY PartEntry,
305 IN UCHAR PartitionType);
306
307 ULONG
308 PrimaryPartitionCreationChecks(
309 IN PPARTLIST List);
310
311 ULONG
312 ExtendedPartitionCreationChecks(
313 IN PPARTLIST List);
314
315 ULONG
316 LogicalPartitionCreationChecks(
317 IN PPARTLIST List);
318
319 BOOLEAN
320 GetNextUnformattedPartition(
321 IN PPARTLIST List,
322 OUT PDISKENTRY *pDiskEntry OPTIONAL,
323 OUT PPARTENTRY *pPartEntry);
324
325 BOOLEAN
326 GetNextUncheckedPartition(
327 IN PPARTLIST List,
328 OUT PDISKENTRY *pDiskEntry OPTIONAL,
329 OUT PPARTENTRY *pPartEntry);
330
331 /* EOF */