ReactOS 0.4.16-dev-336-gb667d82
partlist.h
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Setup Library
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Partition list functions
5 * COPYRIGHT: Copyright 2003-2019 Casper S. Hornstrup (chorns@users.sourceforge.net)
6 * Copyright 2018-2024 Hermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
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{
39
40#include "volutil.h"
41
43typedef struct _VOLENTRY
44{
46
49
50 /* Volume must be checked */
52 /* Volume is new and has not yet been actually formatted and mounted */
54
55 // union {
56 // PVOLUME_DISK_EXTENTS pExtents;
58 // };
60
61typedef struct _PARTENTRY
62{
64
65 /* The disk this partition belongs to */
67
68 /* Partition geometry */
71
72 BOOLEAN BootIndicator; // NOTE: See comment for the PARTLIST::SystemPartition member.
74 ULONG OnDiskPartitionNumber; /* Enumerated partition number (primary partitions first, excluding the extended partition container, then the logical partitions) */
75 ULONG PartitionNumber; /* Current partition number, only valid for the currently running NTOS instance */
76 ULONG PartitionIndex; /* Index in the LayoutBuffer->PartitionEntry[] cached array of the corresponding DiskEntry */
78
80
81 /* Partition is partitioned disk space */
83
84 /* Partition is new, table does not exist on disk yet */
86
87 /*
88 * Volume-related properties:
89 * NULL: No volume is associated to this partition (either because it is
90 * an empty disk region, or the partition type is unrecognized).
91 * 0x1 : TBD.
92 * Valid pointer: A basic volume associated to this partition is (or will)
93 * be mounted by the PARTMGR and enumerated by the MOUNTMGR.
94 */
96
98
99typedef struct _DISKENTRY
100{
102
103 /* The list of disks/partitions this disk belongs to */
105
106 MEDIA_TYPE MediaType; /* FixedMedia or RemovableMedia */
107
108 /* Disk geometry */
109
114
118
119 /* BIOS Firmware parameters */
123 ULONG HwDiskNumber; /* Disk number currently assigned on the system */
124 ULONG HwFixedDiskNumber; /* Disk number on the system when *ALL* removable disks are not connected */
125// ULONG Signature; // Obtained from LayoutBuffer->Signature
126// ULONG Checksum;
127
128 /* SCSI parameters */
130// SCSI_ADDRESS;
134
135 /* Has the partition list been modified? */
137
138 BOOLEAN NewDisk; /* If TRUE, the disk is uninitialized */
139 PARTITION_STYLE DiskStyle; /* MBR/GPT-partitioned disk, or uninitialized disk (RAW) */
140
142
144 // TODO: When adding support for GPT disks:
145 // Use PDRIVE_LAYOUT_INFORMATION_EX which indicates whether
146 // the disk is MBR, GPT, or unknown (uninitialized).
147 // Depending on the style, either use the MBR or GPT partition info.
148
149 LIST_ENTRY PrimaryPartListHead; /* List of primary partitions */
150 LIST_ENTRY LogicalPartListHead; /* List of logical partitions (Valid only for MBR-partitioned disks) */
151
152 /* Pointer to the unique extended partition on this disk (Valid only for MBR-partitioned disks) */
154
156
157typedef struct _BIOSDISKENTRY
158{
165 PDISKENTRY DiskEntry; /* Corresponding recognized disk; is NULL if the disk is not recognized */ // RecognizedDiskEntry;
169
170typedef struct _PARTLIST
171{
172 /*
173 * The system partition where the boot manager resides.
174 * The corresponding system disk is obtained via:
175 * SystemPartition->DiskEntry.
176 */
177 // NOTE: It seems to appear that the specifications of ARC and (u)EFI
178 // actually allow for multiple system partitions to exist on the system.
179 // If so we should instead rely on the BootIndicator bit of the PARTENTRY
180 // structure in order to find these.
182
185
186 /* (Basic) Volumes management */
188
190
191#define PARTITION_TBL_SIZE 4
192
193#define PARTITION_MAGIC 0xAA55
194
195/* Defines system type for MBR showing that a GPT is following */
196#define EFI_PMBR_OSTYPE_EFI 0xEE
197
198#include <pshpack1.h>
199
200typedef 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 */
213
214typedef struct _PARTITION_SECTOR
215{
216 UCHAR BootCode[440]; /* 0x000 */
217 ULONG Signature; /* 0x1B8 */
218 UCHAR Reserved[2]; /* 0x1BC */
220 USHORT Magic; /* 0x1FE */
222
223#include <poppack.h>
224
225typedef struct
226{
232
233
234
239
241AlignUp(
244
247 IN ULONGLONG Dividend,
249
250
251#define GetPartEntryOffsetInBytes(PartEntry) \
252 ((PartEntry)->StartSector.QuadPart * (PartEntry)->DiskEntry->BytesPerSector)
253
254#define GetPartEntrySizeInBytes(PartEntry) \
255 ((PartEntry)->SectorCount.QuadPart * (PartEntry)->DiskEntry->BytesPerSector)
256
257#define GetDiskSizeInBytes(DiskEntry) \
258 ((DiskEntry)->SectorCount.QuadPart * (DiskEntry)->BytesPerSector)
259
260
263 _In_ const DISK_PARTITION_INFO* DiskInfo,
264 _In_opt_ const ULONGLONG* DiskSize,
266
269 _In_ const DRIVE_LAYOUT_INFORMATION* Layout,
270 _In_opt_ const ULONGLONG* DiskSize);
271
274 _In_ const DRIVE_LAYOUT_INFORMATION_EX* LayoutEx,
275 _In_opt_ const ULONGLONG* DiskSize);
276
279 _In_ PDISKENTRY DiskEntry);
280
283 IN PPARTENTRY PartEntry);
284
286NTAPI
288
289VOID
290NTAPI
293
297 _In_ ULONG HwDiskNumber);
298
302 _In_ ULONG DiskNumber);
303
308 _In_ USHORT Bus,
309 _In_ USHORT Id);
310
315
318 _In_ PDISKENTRY DiskEntry,
320
324 _In_ ULONG DiskNumber,
326
328NTAPI
331 IN PPARTENTRY CurrentPart OPTIONAL);
332
334NTAPI
337 IN PPARTENTRY CurrentPart OPTIONAL);
338
340NTAPI
342 _In_ PPARTENTRY PartEntry,
344
346NTAPI
348 _In_ PPARTENTRY PartEntry,
349 _In_opt_ ULONGLONG SizeBytes,
351
353NTAPI
356 _Inout_ PPARTENTRY PartEntry,
357 _In_opt_ ULONGLONG SizeBytes,
359
361NTAPI
364 _In_ PPARTENTRY PartEntry,
365 _Out_opt_ PPARTENTRY* FreeRegion);
366
370 IN BOOLEAN ForceSelect,
371 IN PDISKENTRY AlternativeDisk OPTIONAL,
372 IN PPARTENTRY AlternativePart OPTIONAL);
373
377 IN PPARTENTRY PartEntry,
378 IN PPARTENTRY OldActivePart OPTIONAL);
379
382 IN PDISKENTRY DiskEntry);
383
387
391
392VOID
394 IN PPARTENTRY PartEntry,
396
397/* EOF */
DWORD Id
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
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
BOOLEAN SetMountedDeviceValues(_In_ PPARTLIST List)
Definition: partlist.c:3875
struct _PARTITION * PPARTITION
BOOLEAN IsDiskSuperFloppy2(_In_ const DISK_PARTITION_INFO *DiskInfo, _In_opt_ const ULONGLONG *DiskSize, _In_ const PARTITION_INFORMATION *PartitionInfo)
Definition: partlist.c:491
ERROR_NUMBER NTAPI PartitionCreateChecks(_In_ PPARTENTRY PartEntry, _In_opt_ ULONGLONG SizeBytes, _In_opt_ ULONG_PTR PartitionInfo)
Definition: partlist.c:2881
struct _VOLENTRY VOLENTRY
ULONGLONG AlignUp(IN ULONGLONG Value, IN ULONG Alignment)
Definition: partlist.c:79
enum _FORMATSTATE FORMATSTATE
BOOLEAN WritePartitionsToDisk(IN PPARTLIST List)
Definition: partlist.c:3753
ULONGLONG RoundingDivide(IN ULONGLONG Dividend, IN ULONGLONG Divisor)
Definition: partlist.c:95
VOID SetMBRPartitionType(IN PPARTENTRY PartEntry, IN UCHAR PartitionType)
Definition: partlist.c:3899
VOID NTAPI DestroyPartitionList(IN PPARTLIST List)
Definition: partlist.c:2074
enum _FORMATSTATE * PFORMATSTATE
struct BIOS_DISK * PBIOS_DISK
BOOLEAN IsSuperFloppy(_In_ PDISKENTRY DiskEntry)
Definition: partlist.c:600
struct _PARTLIST * PPARTLIST
struct _PARTITION_SECTOR * PPARTITION_SECTOR
ULONGLONG AlignDown(IN ULONGLONG Value, IN ULONG Alignment)
Definition: partlist.c:67
PPARTENTRY NTAPI GetAdjUnpartitionedEntry(_In_ PPARTENTRY PartEntry, _In_ BOOLEAN Direction)
Retrieves, if any, the unpartitioned disk region that is adjacent (next or previous) to the specified...
Definition: partlist.c:2791
struct _VOLENTRY * PVOLENTRY
PDISKENTRY GetDiskByBiosNumber(_In_ PPARTLIST List, _In_ ULONG HwDiskNumber)
Definition: partlist.c:2128
struct _PARTENTRY * PPARTENTRY
Definition: partlist.h:42
struct _BIOSDISKENTRY * PBIOSDISKENTRY
BOOLEAN NTAPI CreatePartition(_In_ PPARTLIST List, _Inout_ PPARTENTRY PartEntry, _In_opt_ ULONGLONG SizeBytes, _In_opt_ ULONG_PTR PartitionInfo)
Definition: partlist.c:2910
_FORMATSTATE
Definition: partlist.h:33
@ UnknownFormat
Definition: partlist.h:36
@ Formatted
Definition: partlist.h:37
@ Unformatted
Definition: partlist.h:34
@ UnformattedOrDamaged
Definition: partlist.h:35
PDISKENTRY GetDiskBySCSI(_In_ PPARTLIST List, _In_ USHORT Port, _In_ USHORT Bus, _In_ USHORT Id)
Definition: partlist.c:2174
BOOLEAN NTAPI DeletePartition(_In_ PPARTLIST List, _In_ PPARTENTRY PartEntry, _Out_opt_ PPARTENTRY *FreeRegion)
Definition: partlist.c:3001
PDISKENTRY GetDiskBySignature(_In_ PPARTLIST List, _In_ ULONG Signature)
Definition: partlist.c:2204
PPARTENTRY GetPartition(_In_ PDISKENTRY DiskEntry, _In_ ULONG PartitionNumber)
Definition: partlist.c:2227
BOOLEAN IsPartitionActive(IN PPARTENTRY PartEntry)
Definition: partlist.c:1907
PPARTLIST NTAPI CreatePartitionList(VOID)
Definition: partlist.c:1988
struct _PARTITION_SECTOR PARTITION_SECTOR
BOOLEAN SetActivePartition(IN PPARTLIST List, IN PPARTENTRY PartEntry, IN PPARTENTRY OldActivePart OPTIONAL)
Definition: partlist.c:3526
struct _DISKENTRY DISKENTRY
PPARTENTRY NTAPI GetPrevPartition(IN PPARTLIST List, IN PPARTENTRY CurrentPart OPTIONAL)
Definition: partlist.c:2387
struct _PARTLIST PARTLIST
BOOLEAN IsDiskSuperFloppyEx(_In_ const DRIVE_LAYOUT_INFORMATION_EX *LayoutEx, _In_opt_ const ULONGLONG *DiskSize)
Definition: partlist.c:563
PPARTENTRY SelectPartition(_In_ PPARTLIST List, _In_ ULONG DiskNumber, _In_ ULONG PartitionNumber)
Definition: partlist.c:2268
PPARTENTRY NTAPI GetNextPartition(IN PPARTLIST List, IN PPARTENTRY CurrentPart OPTIONAL)
Definition: partlist.c:2294
PDISKENTRY GetDiskByNumber(_In_ PPARTLIST List, _In_ ULONG DiskNumber)
Definition: partlist.c:2151
PPARTENTRY FindSupportedSystemPartition(IN PPARTLIST List, IN BOOLEAN ForceSelect, IN PDISKENTRY AlternativeDisk OPTIONAL, IN PPARTENTRY AlternativePart OPTIONAL)
Definition: partlist.c:3226
struct _BIOSDISKENTRY BIOSDISKENTRY
struct _DISKENTRY * PDISKENTRY
struct _PARTENTRY PARTENTRY
Definition: partlist.h:42
struct _PARTITION PARTITION
NTSTATUS WritePartitions(IN PDISKENTRY DiskEntry)
Definition: partlist.c:3590
BOOLEAN IsDiskSuperFloppy(_In_ const DRIVE_LAYOUT_INFORMATION *Layout, _In_opt_ const ULONGLONG *DiskSize)
Definition: partlist.c:542
enum _PARTITION_STYLE PARTITION_STYLE
#define _Out_opt_
Definition: no_sal2.h:214
#define _Inout_
Definition: no_sal2.h:162
#define _In_
Definition: no_sal2.h:158
#define _In_opt_
Definition: no_sal2.h:212
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:228
ULONG Signature
Definition: partlist.h:230
ULONG Identifier
Definition: partlist.h:229
LIST_ENTRY ListEntry
Definition: partlist.h:227
ULONG AdapterNumber
Definition: partlist.h:160
ULONG ControllerNumber
Definition: partlist.h:161
LIST_ENTRY ListEntry
Definition: partlist.h:159
ULONG DiskNumber
Definition: partlist.h:162
ULONG Checksum
Definition: partlist.h:164
ULONG Signature
Definition: partlist.h:163
PDISKENTRY DiskEntry
Definition: partlist.h:165
CM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry
Definition: partlist.h:166
CM_INT13_DRIVE_PARAMETER Int13DiskData
Definition: partlist.h:167
ULONG HwAdapterNumber
Definition: partlist.h:121
ULONG SectorAlignment
Definition: partlist.h:116
ULARGE_INTEGER SectorCount
Definition: partlist.h:115
UNICODE_STRING DriverName
Definition: partlist.h:141
ULONG HwControllerNumber
Definition: partlist.h:122
ULONG HwDiskNumber
Definition: partlist.h:123
ULONG SectorsPerTrack
Definition: partlist.h:112
PPARTENTRY ExtendedPartition
Definition: partlist.h:153
LIST_ENTRY LogicalPartListHead
Definition: partlist.h:150
struct _PARTLIST * PartList
Definition: partlist.h:104
BOOLEAN NewDisk
Definition: partlist.h:138
ULONG DiskNumber
Definition: partlist.h:129
ULONG BytesPerSector
Definition: partlist.h:113
BOOLEAN BiosFound
Definition: partlist.h:120
ULONGLONG Cylinders
Definition: partlist.h:110
USHORT Bus
Definition: partlist.h:132
USHORT Id
Definition: partlist.h:133
LIST_ENTRY ListEntry
Definition: partlist.h:101
BOOLEAN Dirty
Definition: partlist.h:136
USHORT Port
Definition: partlist.h:131
PARTITION_STYLE DiskStyle
Definition: partlist.h:139
ULONG TracksPerCylinder
Definition: partlist.h:111
LIST_ENTRY PrimaryPartListHead
Definition: partlist.h:149
MEDIA_TYPE MediaType
Definition: partlist.h:106
ULONG HwFixedDiskNumber
Definition: partlist.h:124
ULONG CylinderAlignment
Definition: partlist.h:117
PDRIVE_LAYOUT_INFORMATION LayoutBuffer
Definition: partlist.h:143
Definition: typedefs.h:120
BOOLEAN IsPartitioned
Definition: partlist.h:82
UCHAR PartitionType
Definition: partlist.h:73
BOOLEAN New
Definition: partlist.h:85
ULARGE_INTEGER SectorCount
Definition: partlist.h:70
BOOLEAN BootIndicator
Definition: partlist.h:72
PVOLENTRY Volume
Definition: partlist.h:95
struct _DISKENTRY * DiskEntry
Definition: partlist.h:66
BOOLEAN LogicalPartition
Definition: partlist.h:79
ULONG OnDiskPartitionNumber
Definition: partlist.h:74
LIST_ENTRY ListEntry
Definition: partlist.h:63
ULONG PartitionNumber
Definition: partlist.h:75
ULARGE_INTEGER StartSector
Definition: partlist.h:69
ULONG PartitionIndex
Definition: partlist.h:76
UCHAR BootCode[440]
Definition: partlist.h:216
PARTITION Partition[PARTITION_TBL_SIZE]
Definition: partlist.h:219
unsigned char PartitionType
Definition: partlist.h:206
unsigned char EndingSector
Definition: partlist.h:208
unsigned char BootFlags
Definition: partlist.h:202
unsigned char StartingHead
Definition: partlist.h:203
unsigned int StartingBlock
Definition: partlist.h:210
unsigned char EndingHead
Definition: partlist.h:207
unsigned char EndingCylinder
Definition: partlist.h:209
unsigned int SectorCount
Definition: partlist.h:211
unsigned char StartingSector
Definition: partlist.h:204
unsigned char StartingCylinder
Definition: partlist.h:205
PPARTENTRY SystemPartition
Definition: partlist.h:181
LIST_ENTRY DiskListHead
Definition: partlist.h:183
LIST_ENTRY VolumesList
Definition: partlist.h:187
LIST_ENTRY BiosDiskListHead
Definition: partlist.h:184
BOOLEAN NeedsCheck
Definition: partlist.h:51
FORMATSTATE FormatState
Definition: partlist.h:48
VOLINFO Info
Definition: partlist.h:47
PPARTENTRY PartEntry
Definition: partlist.h:57
LIST_ENTRY ListEntry
Entry in VolumesList.
Definition: partlist.h:45
BOOLEAN New
Definition: partlist.h:53
#define PARTITION_TBL_SIZE
Definition: partlist.c:38
#define NTAPI
Definition: typedefs.h:36
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275
WDF_EXTERN_C_START typedef _In_ WDFDEVICE _In_ WDFCONTEXT _In_ WDF_DMA_DIRECTION Direction
_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_ struct _SET_PARTITION_INFORMATION_EX * PartitionInfo
Definition: iofuncs.h:2105
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2061
_In_ LARGE_INTEGER Divisor
Definition: rtlfuncs.h:3061
unsigned char UCHAR
Definition: xmlstorage.h:181
__wchar_t WCHAR
Definition: xmlstorage.h:180