ReactOS  0.4.15-dev-1638-gc0caa5c
partlist.h
Go to the documentation of this file.
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-2019 Casper S. Hornstrup (chorns@users.sourceforge.net)
6  * Copyright 2018-2019 Hermes Belusca-Maito
7  */
8 
9 #pragma once
10 
11 /* HELPERS FOR PARTITION TYPES **********************************************/
12 
13 typedef struct _PARTITION_TYPE
14 {
18 
19 #define NUM_PARTITION_TYPE_ENTRIES 143
21 
22 
23 /* EXTRA HANDFUL MACROS *****************************************************/
24 
25 // NOTE: They should be moved into some global header.
26 
27 /* OEM MBR partition types recognized by NT (see [MS-DMRP] Appendix B) */
28 #define PARTITION_EISA 0x12 // EISA partition
29 #define PARTITION_HIBERNATION 0x84 // Hibernation partition for laptops
30 #define PARTITION_DIAGNOSTIC 0xA0 // Diagnostic partition on some Hewlett-Packard (HP) notebooks
31 #define PARTITION_DELL 0xDE // Dell partition
32 #define PARTITION_IBM 0xFE // IBM Initial Microprogram Load (IML) partition
33 
34 #define IsOEMPartition(PartitionType) \
35  ( ((PartitionType) == PARTITION_EISA) || \
36  ((PartitionType) == PARTITION_HIBERNATION) || \
37  ((PartitionType) == PARTITION_DIAGNOSTIC) || \
38  ((PartitionType) == PARTITION_DELL) || \
39  ((PartitionType) == PARTITION_IBM) )
40 
41 
42 /* PARTITION UTILITY FUNCTIONS **********************************************/
43 
44 typedef enum _FORMATSTATE
45 {
52 
53 typedef struct _PARTENTRY
54 {
56 
57  /* The disk this partition belongs to */
59 
60  /* Partition geometry */
63 
64  BOOLEAN BootIndicator; // NOTE: See comment for the PARTLIST::SystemPartition member.
66  ULONG OnDiskPartitionNumber; /* Enumerated partition number (primary partitions first, excluding the extended partition container, then the logical partitions) */
67  ULONG PartitionNumber; /* Current partition number, only valid for the currently running NTOS instance */
68  ULONG PartitionIndex; /* Index in the LayoutBuffer->PartitionEntry[] cached array of the corresponding DiskEntry */
69 
74 
76 
77  /* Partition is partitioned disk space */
79 
82  /* Partition is new, table does not exist on disk yet */
84 
85  /* Partition was created automatically */
87 
88  /* Partition must be checked */
90 
92 
93 typedef struct _DISKENTRY
94 {
96 
97  /* The list of disks/partitions this disk belongs to */
99 
100  MEDIA_TYPE MediaType; /* FixedMedia or RemovableMedia */
101 
102  /* Disk geometry */
103 
108 
112 
113  /* BIOS Firmware parameters */
117  ULONG HwDiskNumber; /* Disk number currently assigned on the system */
118  ULONG HwFixedDiskNumber; /* Disk number on the system when *ALL* removable disks are not connected */
119 // ULONG Signature; // Obtained from LayoutBuffer->Signature
120 // ULONG Checksum;
121 
122  /* SCSI parameters */
124 // SCSI_ADDRESS;
128 
129  /* Has the partition list been modified? */
131 
132  BOOLEAN NewDisk; /* If TRUE, the disk is uninitialized */
133  PARTITION_STYLE DiskStyle; /* MBR/GPT-partitioned disk, or uninitialized disk (RAW) */
134 
136 
138  // TODO: When adding support for GPT disks:
139  // Use PDRIVE_LAYOUT_INFORMATION_EX which indicates whether
140  // the disk is MBR, GPT, or unknown (uninitialized).
141  // Depending on the style, either use the MBR or GPT partition info.
142 
143  LIST_ENTRY PrimaryPartListHead; /* List of primary partitions */
144  LIST_ENTRY LogicalPartListHead; /* List of logical partitions (Valid only for MBR-partitioned disks) */
145 
146  /* Pointer to the unique extended partition on this disk (Valid only for MBR-partitioned disks) */
148 
150 
151 typedef struct _BIOSDISKENTRY
152 {
159  PDISKENTRY DiskEntry; /* Corresponding recognized disk; is NULL if the disk is not recognized */ // RecognizedDiskEntry;
163 
164 typedef struct _PARTLIST
165 {
166  /*
167  * The system partition where the boot manager resides.
168  * The corresponding system disk is obtained via:
169  * SystemPartition->DiskEntry.
170  */
171  // NOTE: It seems to appear that the specifications of ARC and (u)EFI
172  // actually allow for multiple system partitions to exist on the system.
173  // If so we should instead rely on the BootIndicator bit of the PARTENTRY
174  // structure in order to find these.
176 
179 
180 } PARTLIST, *PPARTLIST;
181 
182 #define PARTITION_TBL_SIZE 4
183 
184 #define PARTITION_MAGIC 0xAA55
185 
186 /* Defines system type for MBR showing that a GPT is following */
187 #define EFI_PMBR_OSTYPE_EFI 0xEE
188 
189 #include <pshpack1.h>
190 
191 typedef struct _PARTITION
192 {
193  unsigned char BootFlags; /* bootable? 0=no, 128=yes */
194  unsigned char StartingHead; /* beginning head number */
195  unsigned char StartingSector; /* beginning sector number */
196  unsigned char StartingCylinder; /* 10 bit nmbr, with high 2 bits put in begsect */
197  unsigned char PartitionType; /* Operating System type indicator code */
198  unsigned char EndingHead; /* ending head number */
199  unsigned char EndingSector; /* ending sector number */
200  unsigned char EndingCylinder; /* also a 10 bit nmbr, with same high 2 bit trick */
201  unsigned int StartingBlock; /* first sector relative to start of disk */
202  unsigned int SectorCount; /* number of sectors in partition */
204 
205 typedef struct _PARTITION_SECTOR
206 {
207  UCHAR BootCode[440]; /* 0x000 */
208  ULONG Signature; /* 0x1B8 */
209  UCHAR Reserved[2]; /* 0x1BC */
211  USHORT Magic; /* 0x1FE */
213 
214 #include <poppack.h>
215 
216 typedef struct
217 {
223 
224 
225 
226 ULONGLONG
227 AlignDown(
229  IN ULONG Alignment);
230 
231 ULONGLONG
232 AlignUp(
234  IN ULONG Alignment);
235 
236 ULONGLONG
238  IN ULONGLONG Dividend,
240 
241 
242 BOOLEAN
244  IN PDISKENTRY DiskEntry);
245 
246 BOOLEAN
248  IN PPARTENTRY PartEntry);
249 
250 PPARTLIST
252 
253 VOID
255  IN PPARTLIST List);
256 
259  IN PPARTLIST List,
260  IN ULONG HwDiskNumber);
261 
264  IN PPARTLIST List,
265  IN ULONG DiskNumber);
266 
269  IN PPARTLIST List,
270  IN USHORT Port,
271  IN USHORT Bus,
272  IN USHORT Id);
273 
276  IN PPARTLIST List,
277  IN ULONG Signature);
278 
281  // IN PPARTLIST List,
282  IN PDISKENTRY DiskEntry,
284 
285 BOOLEAN
287  IN PPARTLIST List,
288  IN ULONG DiskNumber,
290  OUT PDISKENTRY* pDiskEntry,
291  OUT PPARTENTRY* pPartEntry OPTIONAL);
292 
295  IN PPARTLIST List,
296  IN ULONG DiskNumber,
298 
301  IN PPARTLIST List,
302  IN PPARTENTRY CurrentPart OPTIONAL);
303 
306  IN PPARTLIST List,
307  IN PPARTENTRY CurrentPart OPTIONAL);
308 
309 BOOLEAN
311  IN PPARTLIST List,
312  IN OUT PPARTENTRY PartEntry,
314  IN BOOLEAN AutoCreate);
315 
316 BOOLEAN
318  IN PPARTLIST List,
319  IN OUT PPARTENTRY PartEntry,
321 
322 BOOLEAN
324  IN PPARTLIST List,
325  IN OUT PPARTENTRY PartEntry,
327  IN BOOLEAN AutoCreate);
328 
329 NTSTATUS
331  IN PPARTENTRY PartEntry);
332 
333 BOOLEAN
335  IN PPARTLIST List,
336  IN PPARTENTRY PartEntry,
337  OUT PPARTENTRY* FreeRegion OPTIONAL);
338 
341  IN PPARTLIST List,
342  IN BOOLEAN ForceSelect,
343  IN PDISKENTRY AlternativeDisk OPTIONAL,
344  IN PPARTENTRY AlternativePart OPTIONAL);
345 
346 BOOLEAN
348  IN PPARTLIST List,
349  IN PPARTENTRY PartEntry,
350  IN PPARTENTRY OldActivePart OPTIONAL);
351 
352 NTSTATUS
354  IN PDISKENTRY DiskEntry);
355 
356 BOOLEAN
358  IN PPARTLIST List);
359 
360 BOOLEAN
362  IN WCHAR Letter,
365 
366 BOOLEAN
368  IN PPARTLIST List);
369 
370 VOID
372  IN PPARTENTRY PartEntry,
374 
377  IN PPARTENTRY PartEntry);
378 
381  IN PPARTENTRY PartEntry);
382 
385  IN PPARTENTRY PartEntry);
386 
387 BOOLEAN
389  IN PPARTLIST List,
390  OUT PDISKENTRY *pDiskEntry OPTIONAL,
391  OUT PPARTENTRY *pPartEntry);
392 
393 BOOLEAN
395  IN PPARTLIST List,
396  OUT PDISKENTRY *pDiskEntry OPTIONAL,
397  OUT PPARTENTRY *pPartEntry);
398 
399 /* EOF */
ERROR_NUMBER PrimaryPartitionCreationChecks(IN PPARTENTRY PartEntry)
Definition: partlist.c:4133
LIST_ENTRY PrimaryPartListHead
Definition: partlist.h:143
signed char * PCHAR
Definition: retypes.h:7
struct _DISKENTRY DISKENTRY
struct _PARTLIST * PartList
Definition: partlist.h:98
WCHAR DriveLetter
Definition: partlist.h:70
CPPORT Port[4]
Definition: headless.c:35
#define IN
Definition: typedefs.h:39
struct _PARTLIST PARTLIST
ULONG PartitionNumber
Definition: partlist.h:67
ULARGE_INTEGER StartSector
Definition: partlist.h:61
USHORT Id
Definition: partlist.h:127
LIST_ENTRY BiosDiskListHead
Definition: partlist.h:178
WCHAR VolumeLabel[20]
Definition: partlist.h:71
ULONG HwControllerNumber
Definition: partlist.h:116
struct _PARTLIST * PPARTLIST
struct _PARTENTRY PARTENTRY
_In_ PFCB _In_ LONGLONG StartingOffset
Definition: cdprocs.h:290
BOOLEAN IsPartitionActive(IN PPARTENTRY PartEntry)
Definition: partlist.c:1947
ULONGLONG AlignDown(IN ULONGLONG Value, IN ULONG Alignment)
Definition: partlist.c:246
ULONG CylinderAlignment
Definition: partlist.h:111
PDISKENTRY GetDiskByBiosNumber(IN PPARTLIST List, IN ULONG HwDiskNumber)
Definition: partlist.c:2167
unsigned char EndingSector
Definition: partlist.h:199
PPARTENTRY GetPrevPartition(IN PPARTLIST List, IN PPARTENTRY CurrentPart OPTIONAL)
Definition: partlist.c:2478
NTSTATUS WritePartitions(IN PDISKENTRY DiskEntry)
Definition: partlist.c:3798
USHORT Bus
Definition: partlist.h:126
ULONG HwAdapterNumber
Definition: partlist.h:115
ULARGE_INTEGER SectorCount
Definition: partlist.h:62
ULONG DiskNumber
Definition: partlist.h:219
ULONG Signature
Definition: partlist.h:221
ULONG Checksum
Definition: partlist.h:158
LIST_ENTRY DiskListHead
Definition: partlist.h:177
ULONG Signature
Definition: partlist.h:157
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN GetDiskOrPartition(IN PPARTLIST List, IN ULONG DiskNumber, IN ULONG PartitionNumber OPTIONAL, OUT PDISKENTRY *pDiskEntry, OUT PPARTENTRY *pPartEntry OPTIONAL)
Definition: partlist.c:2322
ULONG ControllerNumber
Definition: partlist.h:155
ULONG DiskNumber
Definition: partlist.h:123
struct _PARTITION_TYPE PARTITION_TYPE
enum _MEDIA_TYPE MEDIA_TYPE
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2056
struct _BIOSDISKENTRY * PBIOSDISKENTRY
VOID DestroyPartitionList(IN PPARTLIST List)
Definition: partlist.c:2110
PDISKENTRY GetDiskBySCSI(IN PPARTLIST List, IN USHORT Port, IN USHORT Bus, IN USHORT Id)
Definition: partlist.c:2219
BOOLEAN DeletePartition(IN PPARTLIST List, IN PPARTENTRY PartEntry, OUT PPARTENTRY *FreeRegion OPTIONAL)
Definition: partlist.c:3226
LIST_ENTRY ListEntry
Definition: partlist.h:218
BOOLEAN SetMountedDeviceValue(IN WCHAR Letter, IN ULONG Signature, IN LARGE_INTEGER StartingOffset)
Definition: partlist.c:3979
unsigned char EndingCylinder
Definition: partlist.h:200
PPARTENTRY SystemPartition
Definition: partlist.h:175
DWORD Id
ULONGLONG AlignUp(IN ULONGLONG Value, IN ULONG Alignment)
Definition: partlist.c:258
PPARTENTRY ExtendedPartition
Definition: partlist.h:147
LIST_ENTRY ListEntry
Definition: partlist.h:55
BOOLEAN LogicalPartition
Definition: partlist.h:75
unsigned char BootFlags
Definition: partlist.h:193
struct _PARTITION_TYPE * PPARTITION_TYPE
PARTITION_STYLE DiskStyle
Definition: partlist.h:133
BOOLEAN SetMountedDeviceValues(IN PPARTLIST List)
Definition: partlist.c:4040
struct _BIOSDISKENTRY BIOSDISKENTRY
FORMATSTATE FormatState
Definition: partlist.h:73
#define PARTITION_TBL_SIZE
Definition: partlist.h:182
BOOLEAN Dirty
Definition: partlist.h:130
unsigned int SectorCount
Definition: partlist.h:202
unsigned char BOOLEAN
struct _PARTITION * PPARTITION
unsigned int StartingBlock
Definition: partlist.h:201
BOOLEAN GetNextUncheckedPartition(IN PPARTLIST List, OUT PDISKENTRY *pDiskEntry OPTIONAL, OUT PPARTENTRY *pPartEntry)
Definition: partlist.c:4273
_Reserved_ PVOID Reserved
Definition: winddi.h:3974
VOID SetMBRPartitionType(IN PPARTENTRY PartEntry, IN UCHAR PartitionType)
Definition: partlist.c:4116
BOOLEAN CreateLogicalPartition(IN PPARTLIST List, IN OUT PPARTENTRY PartEntry, IN ULONGLONG SectorCount, IN BOOLEAN AutoCreate)
Definition: partlist.c:3083
MEDIA_TYPE MediaType
Definition: partlist.h:100
PPARTENTRY SelectPartition(IN PPARTLIST List, IN ULONG DiskNumber, IN ULONG PartitionNumber)
Definition: partlist.c:2362
ULARGE_INTEGER SectorCount
Definition: partlist.h:109
PPARTENTRY GetNextPartition(IN PPARTLIST List, IN PPARTENTRY CurrentPart OPTIONAL)
Definition: partlist.c:2386
BOOLEAN AutoCreate
Definition: partlist.h:86
ULONG SectorAlignment
Definition: partlist.h:110
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:406
ULONG AdapterNumber
Definition: partlist.h:154
UCHAR PartitionType
Definition: partlist.h:65
BOOLEAN BiosFound
Definition: partlist.h:114
struct _DISKENTRY * DiskEntry
Definition: partlist.h:58
ULONG BytesPerSector
Definition: partlist.h:107
__wchar_t WCHAR
Definition: xmlstorage.h:180
UNICODE_STRING DriverName
Definition: partlist.h:135
uint64_t ULONGLONG
Definition: typedefs.h:67
ULONG OnDiskPartitionNumber
Definition: partlist.h:66
unsigned char StartingCylinder
Definition: partlist.h:196
#define MAX_PATH
Definition: compat.h:34
CM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry
Definition: partlist.h:160
LIST_ENTRY ListEntry
Definition: partlist.h:95
ULONG HwDiskNumber
Definition: partlist.h:117
WCHAR FileSystem[MAX_PATH+1]
Definition: partlist.h:72
unsigned char PartitionType
Definition: partlist.h:197
NTSTATUS DismountVolume(IN PPARTENTRY PartEntry)
Definition: partlist.c:3119
unsigned char UCHAR
Definition: xmlstorage.h:181
PDISKENTRY DiskEntry
Definition: partlist.h:159
struct BIOS_DISK * PBIOS_DISK
ULONG SectorsPerTrack
Definition: partlist.h:106
enum _ERROR_NUMBER ERROR_NUMBER
PARTITION_TYPE PartitionTypes[NUM_PARTITION_TYPE_ENTRIES]
Definition: partlist.c:63
ERROR_NUMBER ExtendedPartitionCreationChecks(IN PPARTENTRY PartEntry)
Definition: partlist.c:4160
WCHAR Letter
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
enum _PARTITION_STYLE PARTITION_STYLE
Definition: typedefs.h:119
ULONG SectorCount
Definition: part_xbox.c:31
ULONGLONG Cylinders
Definition: partlist.h:104
BOOLEAN New
Definition: partlist.h:83
BOOLEAN SetActivePartition(IN PPARTLIST List, IN PPARTENTRY PartEntry, IN PPARTENTRY OldActivePart OPTIONAL)
Definition: partlist.c:3734
BOOLEAN NeedsCheck
Definition: partlist.h:89
unsigned char EndingHead
Definition: partlist.h:198
enum _FORMATSTATE FORMATSTATE
struct _PARTENTRY * PPARTENTRY
PDISKENTRY GetDiskBySignature(IN PPARTLIST List, IN ULONG Signature)
Definition: partlist.c:2249
LIST_ENTRY ListEntry
Definition: partlist.h:153
unsigned char StartingHead
Definition: partlist.h:194
unsigned short USHORT
Definition: pedump.c:61
ULONG DiskNumber
Definition: partlist.h:156
BOOLEAN IsSuperFloppy(IN PDISKENTRY DiskEntry)
Definition: partlist.c:680
PARTITION Partition[PARTITION_TBL_SIZE]
Definition: partlist.h:210
PCHAR Description
Definition: partlist.h:16
UCHAR BootCode[440]
Definition: partlist.h:207
ULONG HwFixedDiskNumber
Definition: partlist.h:118
USHORT Port
Definition: partlist.h:125
struct _PARTITION PARTITION
ULONGLONG RoundingDivide(IN ULONGLONG Dividend, IN ULONGLONG Divisor)
Definition: partlist.c:274
ULONG TracksPerCylinder
Definition: partlist.h:105
struct _PARTITION_SECTOR * PPARTITION_SECTOR
LIST_ENTRY LogicalPartListHead
Definition: partlist.h:144
BOOLEAN BootIndicator
Definition: partlist.h:64
PDISKENTRY GetDiskByNumber(IN PPARTLIST List, IN ULONG DiskNumber)
Definition: partlist.c:2193
#define OUT
Definition: typedefs.h:40
CHAR PartitionType
Definition: part_xbox.c:32
_In_ LARGE_INTEGER Divisor
Definition: rtlfuncs.h:3046
unsigned int ULONG
Definition: retypes.h:1
struct _PARTITION_SECTOR PARTITION_SECTOR
_FORMATSTATE
Definition: partlist.h:44
CM_INT13_DRIVE_PARAMETER Int13DiskData
Definition: partlist.h:161
unsigned char StartingSector
Definition: partlist.h:195
static const WCHAR Signature[]
Definition: parser.c:141
ULONG Identifier
Definition: partlist.h:220
PDRIVE_LAYOUT_INFORMATION LayoutBuffer
Definition: partlist.h:137
struct _DISKENTRY * PDISKENTRY
enum _FORMATSTATE * PFORMATSTATE
BOOLEAN GetNextUnformattedPartition(IN PPARTLIST List, OUT PDISKENTRY *pDiskEntry OPTIONAL, OUT PPARTENTRY *pPartEntry)
Definition: partlist.c:4214
BOOLEAN CreateExtendedPartition(IN PPARTLIST List, IN OUT PPARTENTRY PartEntry, IN ULONGLONG SectorCount)
Definition: partlist.c:3029
ERROR_NUMBER LogicalPartitionCreationChecks(IN PPARTENTRY PartEntry)
Definition: partlist.c:4191
PPARTENTRY GetPartition(IN PDISKENTRY DiskEntry, IN ULONG PartitionNumber)
Definition: partlist.c:2275
BOOLEAN NewDisk
Definition: partlist.h:132
BOOLEAN CreatePrimaryPartition(IN PPARTLIST List, IN OUT PPARTENTRY PartEntry, IN ULONGLONG SectorCount, IN BOOLEAN AutoCreate)
Definition: partlist.c:2965
PPARTENTRY FindSupportedSystemPartition(IN PPARTLIST List, IN BOOLEAN ForceSelect, IN PDISKENTRY AlternativeDisk OPTIONAL, IN PPARTENTRY AlternativePart OPTIONAL)
Definition: partlist.c:3439
BOOLEAN WritePartitionsToDisk(IN PPARTLIST List)
Definition: partlist.c:3942
PPARTLIST CreatePartitionList(VOID)
Definition: partlist.c:2026
BOOLEAN IsPartitioned
Definition: partlist.h:78
ULONG PartitionIndex
Definition: partlist.h:68
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
#define NUM_PARTITION_TYPE_ENTRIES
Definition: partlist.h:19