ReactOS 0.4.15-dev-7157-gb7dcc10
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/* EXTRA HANDFUL MACROS *****************************************************/
12
13// NOTE: They should be moved into some global header.
14
15/* OEM MBR partition types recognized by NT (see [MS-DMRP] Appendix B) */
16#define PARTITION_EISA 0x12 // EISA partition
17#define PARTITION_HIBERNATION 0x84 // Hibernation partition for laptops
18#define PARTITION_DIAGNOSTIC 0xA0 // Diagnostic partition on some Hewlett-Packard (HP) notebooks
19#define PARTITION_DELL 0xDE // Dell partition
20#define PARTITION_IBM 0xFE // IBM Initial Microprogram Load (IML) partition
21
22#define IsOEMPartition(PartitionType) \
23 ( ((PartitionType) == PARTITION_EISA) || \
24 ((PartitionType) == PARTITION_HIBERNATION) || \
25 ((PartitionType) == PARTITION_DIAGNOSTIC) || \
26 ((PartitionType) == PARTITION_DELL) || \
27 ((PartitionType) == PARTITION_IBM) )
28
29
30/* PARTITION UTILITY FUNCTIONS **********************************************/
31
32typedef enum _FORMATSTATE
33{
40
41typedef struct _PARTENTRY
42{
44
45 /* The disk this partition belongs to */
47
48 /* Partition geometry */
51
52 BOOLEAN BootIndicator; // NOTE: See comment for the PARTLIST::SystemPartition member.
54 ULONG OnDiskPartitionNumber; /* Enumerated partition number (primary partitions first, excluding the extended partition container, then the logical partitions) */
55 ULONG PartitionNumber; /* Current partition number, only valid for the currently running NTOS instance */
56 ULONG PartitionIndex; /* Index in the LayoutBuffer->PartitionEntry[] cached array of the corresponding DiskEntry */
57
62
64
65 /* Partition is partitioned disk space */
67
70 /* Partition is new, table does not exist on disk yet */
72
73 /* Partition was created automatically */
75
76 /* Partition must be checked */
78
80
81typedef struct _DISKENTRY
82{
84
85 /* The list of disks/partitions this disk belongs to */
87
88 MEDIA_TYPE MediaType; /* FixedMedia or RemovableMedia */
89
90 /* Disk geometry */
91
96
100
101 /* BIOS Firmware parameters */
105 ULONG HwDiskNumber; /* Disk number currently assigned on the system */
106 ULONG HwFixedDiskNumber; /* Disk number on the system when *ALL* removable disks are not connected */
107// ULONG Signature; // Obtained from LayoutBuffer->Signature
108// ULONG Checksum;
109
110 /* SCSI parameters */
112// SCSI_ADDRESS;
116
117 /* Has the partition list been modified? */
119
120 BOOLEAN NewDisk; /* If TRUE, the disk is uninitialized */
121 PARTITION_STYLE DiskStyle; /* MBR/GPT-partitioned disk, or uninitialized disk (RAW) */
122
124
126 // TODO: When adding support for GPT disks:
127 // Use PDRIVE_LAYOUT_INFORMATION_EX which indicates whether
128 // the disk is MBR, GPT, or unknown (uninitialized).
129 // Depending on the style, either use the MBR or GPT partition info.
130
131 LIST_ENTRY PrimaryPartListHead; /* List of primary partitions */
132 LIST_ENTRY LogicalPartListHead; /* List of logical partitions (Valid only for MBR-partitioned disks) */
133
134 /* Pointer to the unique extended partition on this disk (Valid only for MBR-partitioned disks) */
136
138
139typedef struct _BIOSDISKENTRY
140{
147 PDISKENTRY DiskEntry; /* Corresponding recognized disk; is NULL if the disk is not recognized */ // RecognizedDiskEntry;
151
152typedef struct _PARTLIST
153{
154 /*
155 * The system partition where the boot manager resides.
156 * The corresponding system disk is obtained via:
157 * SystemPartition->DiskEntry.
158 */
159 // NOTE: It seems to appear that the specifications of ARC and (u)EFI
160 // actually allow for multiple system partitions to exist on the system.
161 // If so we should instead rely on the BootIndicator bit of the PARTENTRY
162 // structure in order to find these.
164
167
169
170#define PARTITION_TBL_SIZE 4
171
172#define PARTITION_MAGIC 0xAA55
173
174/* Defines system type for MBR showing that a GPT is following */
175#define EFI_PMBR_OSTYPE_EFI 0xEE
176
177#include <pshpack1.h>
178
179typedef struct _PARTITION
180{
181 unsigned char BootFlags; /* bootable? 0=no, 128=yes */
182 unsigned char StartingHead; /* beginning head number */
183 unsigned char StartingSector; /* beginning sector number */
184 unsigned char StartingCylinder; /* 10 bit nmbr, with high 2 bits put in begsect */
185 unsigned char PartitionType; /* Operating System type indicator code */
186 unsigned char EndingHead; /* ending head number */
187 unsigned char EndingSector; /* ending sector number */
188 unsigned char EndingCylinder; /* also a 10 bit nmbr, with same high 2 bit trick */
189 unsigned int StartingBlock; /* first sector relative to start of disk */
190 unsigned int SectorCount; /* number of sectors in partition */
192
193typedef struct _PARTITION_SECTOR
194{
195 UCHAR BootCode[440]; /* 0x000 */
196 ULONG Signature; /* 0x1B8 */
197 UCHAR Reserved[2]; /* 0x1BC */
199 USHORT Magic; /* 0x1FE */
201
202#include <poppack.h>
203
204typedef struct
205{
211
212
213
218
220AlignUp(
223
226 IN ULONGLONG Dividend,
228
229
232 IN PDISKENTRY DiskEntry);
233
236 IN PPARTENTRY PartEntry);
237
240
241VOID
244
248 IN ULONG HwDiskNumber);
249
253 IN ULONG DiskNumber);
254
258 IN USHORT Port,
259 IN USHORT Bus,
260 IN USHORT Id);
261
266
269 // IN PPARTLIST List,
270 IN PDISKENTRY DiskEntry,
272
276 IN ULONG DiskNumber,
278 OUT PDISKENTRY* pDiskEntry,
279 OUT PPARTENTRY* pPartEntry OPTIONAL);
280
284 IN ULONG DiskNumber,
286
290 IN PPARTENTRY CurrentPart OPTIONAL);
291
295 IN PPARTENTRY CurrentPart OPTIONAL);
296
299 _In_ PPARTENTRY PartEntry);
300
303 _In_ PPARTENTRY PartEntry);
304
308 _Inout_ PPARTENTRY PartEntry,
310 _In_ BOOLEAN AutoCreate);
311
315 _Inout_ PPARTENTRY PartEntry,
317
320 IN PPARTENTRY PartEntry);
321
325 IN PPARTENTRY PartEntry,
326 OUT PPARTENTRY* FreeRegion OPTIONAL);
327
331 IN BOOLEAN ForceSelect,
332 IN PDISKENTRY AlternativeDisk OPTIONAL,
333 IN PPARTENTRY AlternativePart OPTIONAL);
334
338 IN PPARTENTRY PartEntry,
339 IN PPARTENTRY OldActivePart OPTIONAL);
340
343 IN PDISKENTRY DiskEntry);
344
348
354
358
359VOID
361 IN PPARTENTRY PartEntry,
363
367 OUT PDISKENTRY *pDiskEntry OPTIONAL,
368 OUT PPARTENTRY *pPartEntry);
369
373 OUT PDISKENTRY *pDiskEntry OPTIONAL,
374 OUT PPARTENTRY *pPartEntry);
375
376/* EOF */
DWORD Id
WCHAR Letter
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
_In_ PFCB _In_ LONGLONG StartingOffset
Definition: cdprocs.h:291
enum _FORMATSTATE FORMATSTATE
#define MAX_PATH
Definition: compat.h:34
static const WCHAR Signature[]
Definition: parser.c:141
enum _ERROR_NUMBER ERROR_NUMBER
CPPORT Port[4]
Definition: headless.c:35
ERROR_NUMBER ExtendedPartitionCreationChecks(_In_ PPARTENTRY PartEntry)
Definition: partlist.c:2831
VOID DestroyPartitionList(IN PPARTLIST List)
Definition: partlist.c:1931
struct _PARTITION * PPARTITION
ERROR_NUMBER PartitionCreationChecks(_In_ PPARTENTRY PartEntry)
Definition: partlist.c:2786
PPARTENTRY SelectPartition(IN PPARTLIST List, IN ULONG DiskNumber, IN ULONG PartitionNumber)
Definition: partlist.c:2183
BOOLEAN CreatePartition(_In_ PPARTLIST List, _Inout_ PPARTENTRY PartEntry, _In_ ULONGLONG SectorCount, _In_ BOOLEAN AutoCreate)
Definition: partlist.c:2862
BOOLEAN SetMountedDeviceValues(IN PPARTLIST List)
Definition: partlist.c:3899
BOOLEAN GetDiskOrPartition(IN PPARTLIST List, IN ULONG DiskNumber, IN ULONG PartitionNumber OPTIONAL, OUT PDISKENTRY *pDiskEntry, OUT PPARTENTRY *pPartEntry OPTIONAL)
Definition: partlist.c:2143
ULONGLONG AlignUp(IN ULONGLONG Value, IN ULONG Alignment)
Definition: partlist.c:79
enum _FORMATSTATE FORMATSTATE
BOOLEAN WritePartitionsToDisk(IN PPARTLIST List)
Definition: partlist.c:3801
PPARTENTRY GetPartition(IN PDISKENTRY DiskEntry, IN ULONG PartitionNumber)
Definition: partlist.c:2096
PDISKENTRY GetDiskByNumber(IN PPARTLIST List, IN ULONG DiskNumber)
Definition: partlist.c:2014
ULONGLONG RoundingDivide(IN ULONGLONG Dividend, IN ULONGLONG Divisor)
Definition: partlist.c:95
VOID SetMBRPartitionType(IN PPARTENTRY PartEntry, IN UCHAR PartitionType)
Definition: partlist.c:3975
enum _FORMATSTATE * PFORMATSTATE
struct BIOS_DISK * PBIOS_DISK
struct _PARTLIST * PPARTLIST
struct _PARTITION_SECTOR * PPARTITION_SECTOR
PPARTENTRY GetPrevPartition(IN PPARTLIST List, IN PPARTENTRY CurrentPart OPTIONAL)
Definition: partlist.c:2299
ULONGLONG AlignDown(IN ULONGLONG Value, IN ULONG Alignment)
Definition: partlist.c:67
BOOLEAN GetNextUncheckedPartition(IN PPARTLIST List, OUT PDISKENTRY *pDiskEntry OPTIONAL, OUT PPARTENTRY *pPartEntry)
Definition: partlist.c:4051
BOOLEAN DeletePartition(IN PPARTLIST List, IN PPARTENTRY PartEntry, OUT PPARTENTRY *FreeRegion OPTIONAL)
Definition: partlist.c:3085
BOOLEAN IsSuperFloppy(IN PDISKENTRY DiskEntry)
Definition: partlist.c:501
struct _PARTENTRY * PPARTENTRY
struct _BIOSDISKENTRY * PBIOSDISKENTRY
_FORMATSTATE
Definition: partlist.h:33
@ UnknownFormat
Definition: partlist.h:36
@ Preformatted
Definition: partlist.h:37
@ Formatted
Definition: partlist.h:38
@ Unformatted
Definition: partlist.h:34
@ UnformattedOrDamaged
Definition: partlist.h:35
PPARTLIST CreatePartitionList(VOID)
Definition: partlist.c:1847
PPARTENTRY GetNextPartition(IN PPARTLIST List, IN PPARTENTRY CurrentPart OPTIONAL)
Definition: partlist.c:2207
BOOLEAN IsPartitionActive(IN PPARTENTRY PartEntry)
Definition: partlist.c:1768
PDISKENTRY GetDiskByBiosNumber(IN PPARTLIST List, IN ULONG HwDiskNumber)
Definition: partlist.c:1988
struct _PARTITION_SECTOR PARTITION_SECTOR
BOOLEAN SetActivePartition(IN PPARTLIST List, IN PPARTENTRY PartEntry, IN PPARTENTRY OldActivePart OPTIONAL)
Definition: partlist.c:3593
struct _DISKENTRY DISKENTRY
struct _PARTLIST PARTLIST
BOOLEAN GetNextUnformattedPartition(IN PPARTLIST List, OUT PDISKENTRY *pDiskEntry OPTIONAL, OUT PPARTENTRY *pPartEntry)
Definition: partlist.c:3992
BOOLEAN CreateExtendedPartition(_In_ PPARTLIST List, _Inout_ PPARTENTRY PartEntry, _In_ ULONGLONG SectorCount)
Definition: partlist.c:2924
BOOLEAN SetMountedDeviceValue(IN WCHAR Letter, IN ULONG Signature, IN LARGE_INTEGER StartingOffset)
Definition: partlist.c:3838
PPARTENTRY FindSupportedSystemPartition(IN PPARTLIST List, IN BOOLEAN ForceSelect, IN PDISKENTRY AlternativeDisk OPTIONAL, IN PPARTENTRY AlternativePart OPTIONAL)
Definition: partlist.c:3298
PDISKENTRY GetDiskBySignature(IN PPARTLIST List, IN ULONG Signature)
Definition: partlist.c:2070
NTSTATUS DismountVolume(IN PPARTENTRY PartEntry)
Definition: partlist.c:2978
struct _BIOSDISKENTRY BIOSDISKENTRY
struct _DISKENTRY * PDISKENTRY
struct _PARTENTRY PARTENTRY
struct _PARTITION PARTITION
NTSTATUS WritePartitions(IN PDISKENTRY DiskEntry)
Definition: partlist.c:3657
PDISKENTRY GetDiskBySCSI(IN PPARTLIST List, IN USHORT Port, IN USHORT Bus, IN USHORT Id)
Definition: partlist.c:2040
enum _PARTITION_STYLE PARTITION_STYLE
#define _Inout_
Definition: ms_sal.h:378
#define _In_
Definition: ms_sal.h:308
enum _MEDIA_TYPE MEDIA_TYPE
ULONG SectorCount
Definition: part_xbox.c:31
CHAR PartitionType
Definition: part_xbox.c:32
unsigned short USHORT
Definition: pedump.c:61
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
ULONG DiskNumber
Definition: partlist.h:207
ULONG Signature
Definition: partlist.h:209
ULONG Identifier
Definition: partlist.h:208
LIST_ENTRY ListEntry
Definition: partlist.h:206
ULONG AdapterNumber
Definition: partlist.h:142
ULONG ControllerNumber
Definition: partlist.h:143
LIST_ENTRY ListEntry
Definition: partlist.h:141
ULONG DiskNumber
Definition: partlist.h:144
ULONG Checksum
Definition: partlist.h:146
ULONG Signature
Definition: partlist.h:145
PDISKENTRY DiskEntry
Definition: partlist.h:147
CM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry
Definition: partlist.h:148
CM_INT13_DRIVE_PARAMETER Int13DiskData
Definition: partlist.h:149
ULONG HwAdapterNumber
Definition: partlist.h:103
ULONG SectorAlignment
Definition: partlist.h:98
ULARGE_INTEGER SectorCount
Definition: partlist.h:97
UNICODE_STRING DriverName
Definition: partlist.h:123
ULONG HwControllerNumber
Definition: partlist.h:104
ULONG HwDiskNumber
Definition: partlist.h:105
ULONG SectorsPerTrack
Definition: partlist.h:94
PPARTENTRY ExtendedPartition
Definition: partlist.h:135
LIST_ENTRY LogicalPartListHead
Definition: partlist.h:132
struct _PARTLIST * PartList
Definition: partlist.h:86
BOOLEAN NewDisk
Definition: partlist.h:120
ULONG DiskNumber
Definition: partlist.h:111
ULONG BytesPerSector
Definition: partlist.h:95
BOOLEAN BiosFound
Definition: partlist.h:102
ULONGLONG Cylinders
Definition: partlist.h:92
USHORT Bus
Definition: partlist.h:114
USHORT Id
Definition: partlist.h:115
LIST_ENTRY ListEntry
Definition: partlist.h:83
BOOLEAN Dirty
Definition: partlist.h:118
USHORT Port
Definition: partlist.h:113
PARTITION_STYLE DiskStyle
Definition: partlist.h:121
ULONG TracksPerCylinder
Definition: partlist.h:93
LIST_ENTRY PrimaryPartListHead
Definition: partlist.h:131
MEDIA_TYPE MediaType
Definition: partlist.h:88
ULONG HwFixedDiskNumber
Definition: partlist.h:106
ULONG CylinderAlignment
Definition: partlist.h:99
PDRIVE_LAYOUT_INFORMATION LayoutBuffer
Definition: partlist.h:125
Definition: typedefs.h:120
BOOLEAN IsPartitioned
Definition: partlist.h:66
UCHAR PartitionType
Definition: partlist.h:53
BOOLEAN AutoCreate
Definition: partlist.h:74
BOOLEAN New
Definition: partlist.h:71
ULARGE_INTEGER SectorCount
Definition: partlist.h:50
BOOLEAN BootIndicator
Definition: partlist.h:52
WCHAR VolumeLabel[20]
Definition: partlist.h:59
WCHAR FileSystem[MAX_PATH+1]
Definition: partlist.h:60
struct _DISKENTRY * DiskEntry
Definition: partlist.h:46
BOOLEAN LogicalPartition
Definition: partlist.h:63
FORMATSTATE FormatState
Definition: partlist.h:61
WCHAR DriveLetter
Definition: partlist.h:58
ULONG OnDiskPartitionNumber
Definition: partlist.h:54
BOOLEAN NeedsCheck
Definition: partlist.h:77
LIST_ENTRY ListEntry
Definition: partlist.h:43
ULONG PartitionNumber
Definition: partlist.h:55
ULARGE_INTEGER StartSector
Definition: partlist.h:49
ULONG PartitionIndex
Definition: partlist.h:56
UCHAR BootCode[440]
Definition: partlist.h:195
PARTITION Partition[PARTITION_TBL_SIZE]
Definition: partlist.h:198
unsigned char PartitionType
Definition: partlist.h:185
unsigned char EndingSector
Definition: partlist.h:187
unsigned char BootFlags
Definition: partlist.h:181
unsigned char StartingHead
Definition: partlist.h:182
unsigned int StartingBlock
Definition: partlist.h:189
unsigned char EndingHead
Definition: partlist.h:186
unsigned char EndingCylinder
Definition: partlist.h:188
unsigned int SectorCount
Definition: partlist.h:190
unsigned char StartingSector
Definition: partlist.h:183
unsigned char StartingCylinder
Definition: partlist.h:184
PPARTENTRY SystemPartition
Definition: partlist.h:163
LIST_ENTRY DiskListHead
Definition: partlist.h:165
LIST_ENTRY BiosDiskListHead
Definition: partlist.h:166
#define PARTITION_TBL_SIZE
Definition: partlist.c:38
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
#define OUT
Definition: typedefs.h:40
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
_Reserved_ PVOID Reserved
Definition: winddi.h:3974
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2061
_In_ LARGE_INTEGER Divisor
Definition: rtlfuncs.h:3044
unsigned char UCHAR
Definition: xmlstorage.h:181
__wchar_t WCHAR
Definition: xmlstorage.h:180