ReactOS 0.4.15-dev-8135-g1bc6c90
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 must be checked */
75
77
78typedef struct _DISKENTRY
79{
81
82 /* The list of disks/partitions this disk belongs to */
84
85 MEDIA_TYPE MediaType; /* FixedMedia or RemovableMedia */
86
87 /* Disk geometry */
88
93
97
98 /* BIOS Firmware parameters */
102 ULONG HwDiskNumber; /* Disk number currently assigned on the system */
103 ULONG HwFixedDiskNumber; /* Disk number on the system when *ALL* removable disks are not connected */
104// ULONG Signature; // Obtained from LayoutBuffer->Signature
105// ULONG Checksum;
106
107 /* SCSI parameters */
109// SCSI_ADDRESS;
113
114 /* Has the partition list been modified? */
116
117 BOOLEAN NewDisk; /* If TRUE, the disk is uninitialized */
118 PARTITION_STYLE DiskStyle; /* MBR/GPT-partitioned disk, or uninitialized disk (RAW) */
119
121
123 // TODO: When adding support for GPT disks:
124 // Use PDRIVE_LAYOUT_INFORMATION_EX which indicates whether
125 // the disk is MBR, GPT, or unknown (uninitialized).
126 // Depending on the style, either use the MBR or GPT partition info.
127
128 LIST_ENTRY PrimaryPartListHead; /* List of primary partitions */
129 LIST_ENTRY LogicalPartListHead; /* List of logical partitions (Valid only for MBR-partitioned disks) */
130
131 /* Pointer to the unique extended partition on this disk (Valid only for MBR-partitioned disks) */
133
135
136typedef struct _BIOSDISKENTRY
137{
144 PDISKENTRY DiskEntry; /* Corresponding recognized disk; is NULL if the disk is not recognized */ // RecognizedDiskEntry;
148
149typedef struct _PARTLIST
150{
151 /*
152 * The system partition where the boot manager resides.
153 * The corresponding system disk is obtained via:
154 * SystemPartition->DiskEntry.
155 */
156 // NOTE: It seems to appear that the specifications of ARC and (u)EFI
157 // actually allow for multiple system partitions to exist on the system.
158 // If so we should instead rely on the BootIndicator bit of the PARTENTRY
159 // structure in order to find these.
161
164
166
167#define PARTITION_TBL_SIZE 4
168
169#define PARTITION_MAGIC 0xAA55
170
171/* Defines system type for MBR showing that a GPT is following */
172#define EFI_PMBR_OSTYPE_EFI 0xEE
173
174#include <pshpack1.h>
175
176typedef struct _PARTITION
177{
178 unsigned char BootFlags; /* bootable? 0=no, 128=yes */
179 unsigned char StartingHead; /* beginning head number */
180 unsigned char StartingSector; /* beginning sector number */
181 unsigned char StartingCylinder; /* 10 bit nmbr, with high 2 bits put in begsect */
182 unsigned char PartitionType; /* Operating System type indicator code */
183 unsigned char EndingHead; /* ending head number */
184 unsigned char EndingSector; /* ending sector number */
185 unsigned char EndingCylinder; /* also a 10 bit nmbr, with same high 2 bit trick */
186 unsigned int StartingBlock; /* first sector relative to start of disk */
187 unsigned int SectorCount; /* number of sectors in partition */
189
190typedef struct _PARTITION_SECTOR
191{
192 UCHAR BootCode[440]; /* 0x000 */
193 ULONG Signature; /* 0x1B8 */
194 UCHAR Reserved[2]; /* 0x1BC */
196 USHORT Magic; /* 0x1FE */
198
199#include <poppack.h>
200
201typedef struct
202{
208
209
210
215
217AlignUp(
220
223 IN ULONGLONG Dividend,
225
226
227#define GetPartEntryOffsetInBytes(PartEntry) \
228 ((PartEntry)->StartSector.QuadPart * (PartEntry)->DiskEntry->BytesPerSector)
229
230#define GetPartEntrySizeInBytes(PartEntry) \
231 ((PartEntry)->SectorCount.QuadPart * (PartEntry)->DiskEntry->BytesPerSector)
232
233#define GetDiskSizeInBytes(DiskEntry) \
234 ((DiskEntry)->SectorCount.QuadPart * (DiskEntry)->BytesPerSector)
235
236
239 IN PDISKENTRY DiskEntry);
240
243 IN PPARTENTRY PartEntry);
244
247
248VOID
251
255 IN ULONG HwDiskNumber);
256
260 IN ULONG DiskNumber);
261
265 IN USHORT Port,
266 IN USHORT Bus,
267 IN USHORT Id);
268
273
276 // IN PPARTLIST List,
277 IN PDISKENTRY DiskEntry,
279
283 IN ULONG DiskNumber,
285 OUT PDISKENTRY* pDiskEntry,
286 OUT PPARTENTRY* pPartEntry OPTIONAL);
287
291 IN ULONG DiskNumber,
293
297 IN PPARTENTRY CurrentPart OPTIONAL);
298
302 IN PPARTENTRY CurrentPart OPTIONAL);
303
306 _In_ PPARTENTRY PartEntry);
307
310 _In_ PPARTENTRY PartEntry);
311
315 _Inout_ PPARTENTRY PartEntry,
316 _In_opt_ ULONGLONG SizeBytes);
317
321 _Inout_ PPARTENTRY PartEntry,
322 _In_opt_ ULONGLONG SizeBytes);
323
326 IN PPARTENTRY PartEntry);
327
331 IN PPARTENTRY PartEntry,
332 OUT PPARTENTRY* FreeRegion OPTIONAL);
333
337 IN BOOLEAN ForceSelect,
338 IN PDISKENTRY AlternativeDisk OPTIONAL,
339 IN PPARTENTRY AlternativePart OPTIONAL);
340
344 IN PPARTENTRY PartEntry,
345 IN PPARTENTRY OldActivePart OPTIONAL);
346
349 IN PDISKENTRY DiskEntry);
350
354
360
364
365VOID
367 IN PPARTENTRY PartEntry,
369
373 OUT PDISKENTRY *pDiskEntry OPTIONAL,
374 OUT PPARTENTRY *pPartEntry);
375
379 OUT PDISKENTRY *pDiskEntry OPTIONAL,
380 OUT PPARTENTRY *pPartEntry);
381
382/* 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:2838
VOID DestroyPartitionList(IN PPARTLIST List)
Definition: partlist.c:1951
struct _PARTITION * PPARTITION
ERROR_NUMBER PartitionCreationChecks(_In_ PPARTENTRY PartEntry)
Definition: partlist.c:2793
PPARTENTRY SelectPartition(IN PPARTLIST List, IN ULONG DiskNumber, IN ULONG PartitionNumber)
Definition: partlist.c:2203
BOOLEAN SetMountedDeviceValues(IN PPARTLIST List)
Definition: partlist.c:3905
BOOLEAN GetDiskOrPartition(IN PPARTLIST List, IN ULONG DiskNumber, IN ULONG PartitionNumber OPTIONAL, OUT PDISKENTRY *pDiskEntry, OUT PPARTENTRY *pPartEntry OPTIONAL)
Definition: partlist.c:2163
ULONGLONG AlignUp(IN ULONGLONG Value, IN ULONG Alignment)
Definition: partlist.c:79
enum _FORMATSTATE FORMATSTATE
BOOLEAN WritePartitionsToDisk(IN PPARTLIST List)
Definition: partlist.c:3807
PPARTENTRY GetPartition(IN PDISKENTRY DiskEntry, IN ULONG PartitionNumber)
Definition: partlist.c:2116
PDISKENTRY GetDiskByNumber(IN PPARTLIST List, IN ULONG DiskNumber)
Definition: partlist.c:2034
ULONGLONG RoundingDivide(IN ULONGLONG Dividend, IN ULONGLONG Divisor)
Definition: partlist.c:95
VOID SetMBRPartitionType(IN PPARTENTRY PartEntry, IN UCHAR PartitionType)
Definition: partlist.c:3981
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:2319
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:4057
BOOLEAN DeletePartition(IN PPARTLIST List, IN PPARTENTRY PartEntry, OUT PPARTENTRY *FreeRegion OPTIONAL)
Definition: partlist.c:3091
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:1867
PPARTENTRY GetNextPartition(IN PPARTLIST List, IN PPARTENTRY CurrentPart OPTIONAL)
Definition: partlist.c:2227
BOOLEAN IsPartitionActive(IN PPARTENTRY PartEntry)
Definition: partlist.c:1788
PDISKENTRY GetDiskByBiosNumber(IN PPARTLIST List, IN ULONG HwDiskNumber)
Definition: partlist.c:2008
struct _PARTITION_SECTOR PARTITION_SECTOR
BOOLEAN SetActivePartition(IN PPARTLIST List, IN PPARTENTRY PartEntry, IN PPARTENTRY OldActivePart OPTIONAL)
Definition: partlist.c:3599
struct _DISKENTRY DISKENTRY
struct _PARTLIST PARTLIST
BOOLEAN GetNextUnformattedPartition(IN PPARTLIST List, OUT PDISKENTRY *pDiskEntry OPTIONAL, OUT PPARTENTRY *pPartEntry)
Definition: partlist.c:3998
BOOLEAN SetMountedDeviceValue(IN WCHAR Letter, IN ULONG Signature, IN LARGE_INTEGER StartingOffset)
Definition: partlist.c:3844
PPARTENTRY FindSupportedSystemPartition(IN PPARTLIST List, IN BOOLEAN ForceSelect, IN PDISKENTRY AlternativeDisk OPTIONAL, IN PPARTENTRY AlternativePart OPTIONAL)
Definition: partlist.c:3304
PDISKENTRY GetDiskBySignature(IN PPARTLIST List, IN ULONG Signature)
Definition: partlist.c:2090
NTSTATUS DismountVolume(IN PPARTENTRY PartEntry)
Definition: partlist.c:2984
BOOLEAN CreatePartition(_In_ PPARTLIST List, _Inout_ PPARTENTRY PartEntry, _In_opt_ ULONGLONG SizeBytes)
Definition: partlist.c:2869
struct _BIOSDISKENTRY BIOSDISKENTRY
struct _DISKENTRY * PDISKENTRY
struct _PARTENTRY PARTENTRY
struct _PARTITION PARTITION
NTSTATUS WritePartitions(IN PDISKENTRY DiskEntry)
Definition: partlist.c:3663
PDISKENTRY GetDiskBySCSI(IN PPARTLIST List, IN USHORT Port, IN USHORT Bus, IN USHORT Id)
Definition: partlist.c:2060
BOOLEAN CreateExtendedPartition(_In_ PPARTLIST List, _Inout_ PPARTENTRY PartEntry, _In_opt_ ULONGLONG SizeBytes)
Definition: partlist.c:2930
enum _PARTITION_STYLE PARTITION_STYLE
#define _Inout_
Definition: ms_sal.h:378
#define _In_
Definition: ms_sal.h:308
#define _In_opt_
Definition: ms_sal.h:309
enum _MEDIA_TYPE MEDIA_TYPE
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:204
ULONG Signature
Definition: partlist.h:206
ULONG Identifier
Definition: partlist.h:205
LIST_ENTRY ListEntry
Definition: partlist.h:203
ULONG AdapterNumber
Definition: partlist.h:139
ULONG ControllerNumber
Definition: partlist.h:140
LIST_ENTRY ListEntry
Definition: partlist.h:138
ULONG DiskNumber
Definition: partlist.h:141
ULONG Checksum
Definition: partlist.h:143
ULONG Signature
Definition: partlist.h:142
PDISKENTRY DiskEntry
Definition: partlist.h:144
CM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry
Definition: partlist.h:145
CM_INT13_DRIVE_PARAMETER Int13DiskData
Definition: partlist.h:146
ULONG HwAdapterNumber
Definition: partlist.h:100
ULONG SectorAlignment
Definition: partlist.h:95
ULARGE_INTEGER SectorCount
Definition: partlist.h:94
UNICODE_STRING DriverName
Definition: partlist.h:120
ULONG HwControllerNumber
Definition: partlist.h:101
ULONG HwDiskNumber
Definition: partlist.h:102
ULONG SectorsPerTrack
Definition: partlist.h:91
PPARTENTRY ExtendedPartition
Definition: partlist.h:132
LIST_ENTRY LogicalPartListHead
Definition: partlist.h:129
struct _PARTLIST * PartList
Definition: partlist.h:83
BOOLEAN NewDisk
Definition: partlist.h:117
ULONG DiskNumber
Definition: partlist.h:108
ULONG BytesPerSector
Definition: partlist.h:92
BOOLEAN BiosFound
Definition: partlist.h:99
ULONGLONG Cylinders
Definition: partlist.h:89
USHORT Bus
Definition: partlist.h:111
USHORT Id
Definition: partlist.h:112
LIST_ENTRY ListEntry
Definition: partlist.h:80
BOOLEAN Dirty
Definition: partlist.h:115
USHORT Port
Definition: partlist.h:110
PARTITION_STYLE DiskStyle
Definition: partlist.h:118
ULONG TracksPerCylinder
Definition: partlist.h:90
LIST_ENTRY PrimaryPartListHead
Definition: partlist.h:128
MEDIA_TYPE MediaType
Definition: partlist.h:85
ULONG HwFixedDiskNumber
Definition: partlist.h:103
ULONG CylinderAlignment
Definition: partlist.h:96
PDRIVE_LAYOUT_INFORMATION LayoutBuffer
Definition: partlist.h:122
Definition: typedefs.h:120
BOOLEAN IsPartitioned
Definition: partlist.h:66
UCHAR PartitionType
Definition: partlist.h:53
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:74
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:192
PARTITION Partition[PARTITION_TBL_SIZE]
Definition: partlist.h:195
unsigned char PartitionType
Definition: partlist.h:182
unsigned char EndingSector
Definition: partlist.h:184
unsigned char BootFlags
Definition: partlist.h:178
unsigned char StartingHead
Definition: partlist.h:179
unsigned int StartingBlock
Definition: partlist.h:186
unsigned char EndingHead
Definition: partlist.h:183
unsigned char EndingCylinder
Definition: partlist.h:185
unsigned int SectorCount
Definition: partlist.h:187
unsigned char StartingSector
Definition: partlist.h:180
unsigned char StartingCylinder
Definition: partlist.h:181
PPARTENTRY SystemPartition
Definition: partlist.h:160
LIST_ENTRY DiskListHead
Definition: partlist.h:162
LIST_ENTRY BiosDiskListHead
Definition: partlist.h:163
#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