ReactOS  0.4.15-dev-3297-g037c744
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 
32 typedef enum _FORMATSTATE
33 {
40 
41 typedef 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 
81 typedef 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 
139 typedef struct _BIOSDISKENTRY
140 {
147  PDISKENTRY DiskEntry; /* Corresponding recognized disk; is NULL if the disk is not recognized */ // RecognizedDiskEntry;
151 
152 typedef 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 
168 } PARTLIST, *PPARTLIST;
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 
179 typedef 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 
193 typedef 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 
204 typedef struct
205 {
211 
212 
213 
214 ULONGLONG
215 AlignDown(
217  IN ULONG Alignment);
218 
219 ULONGLONG
220 AlignUp(
222  IN ULONG Alignment);
223 
224 ULONGLONG
226  IN ULONGLONG Dividend,
228 
229 
230 BOOLEAN
232  IN PDISKENTRY DiskEntry);
233 
234 BOOLEAN
236  IN PPARTENTRY PartEntry);
237 
238 PPARTLIST
240 
241 VOID
243  IN PPARTLIST List);
244 
247  IN PPARTLIST List,
248  IN ULONG HwDiskNumber);
249 
252  IN PPARTLIST List,
253  IN ULONG DiskNumber);
254 
257  IN PPARTLIST List,
258  IN USHORT Port,
259  IN USHORT Bus,
260  IN USHORT Id);
261 
264  IN PPARTLIST List,
265  IN ULONG Signature);
266 
269  // IN PPARTLIST List,
270  IN PDISKENTRY DiskEntry,
272 
273 BOOLEAN
275  IN PPARTLIST List,
276  IN ULONG DiskNumber,
278  OUT PDISKENTRY* pDiskEntry,
279  OUT PPARTENTRY* pPartEntry OPTIONAL);
280 
283  IN PPARTLIST List,
284  IN ULONG DiskNumber,
286 
289  IN PPARTLIST List,
290  IN PPARTENTRY CurrentPart OPTIONAL);
291 
294  IN PPARTLIST List,
295  IN PPARTENTRY CurrentPart OPTIONAL);
296 
297 BOOLEAN
299  IN PPARTLIST List,
300  IN OUT PPARTENTRY PartEntry,
302  IN BOOLEAN AutoCreate);
303 
304 BOOLEAN
306  IN PPARTLIST List,
307  IN OUT PPARTENTRY PartEntry,
309 
310 BOOLEAN
312  IN PPARTLIST List,
313  IN OUT PPARTENTRY PartEntry,
315  IN BOOLEAN AutoCreate);
316 
317 NTSTATUS
319  IN PPARTENTRY PartEntry);
320 
321 BOOLEAN
323  IN PPARTLIST List,
324  IN PPARTENTRY PartEntry,
325  OUT PPARTENTRY* FreeRegion OPTIONAL);
326 
329  IN PPARTLIST List,
330  IN BOOLEAN ForceSelect,
331  IN PDISKENTRY AlternativeDisk OPTIONAL,
332  IN PPARTENTRY AlternativePart OPTIONAL);
333 
334 BOOLEAN
336  IN PPARTLIST List,
337  IN PPARTENTRY PartEntry,
338  IN PPARTENTRY OldActivePart OPTIONAL);
339 
340 NTSTATUS
342  IN PDISKENTRY DiskEntry);
343 
344 BOOLEAN
346  IN PPARTLIST List);
347 
348 BOOLEAN
350  IN WCHAR Letter,
353 
354 BOOLEAN
356  IN PPARTLIST List);
357 
358 VOID
360  IN PPARTENTRY PartEntry,
362 
365  IN PPARTENTRY PartEntry);
366 
369  IN PPARTENTRY PartEntry);
370 
373  IN PPARTENTRY PartEntry);
374 
375 BOOLEAN
377  IN PPARTLIST List,
378  OUT PDISKENTRY *pDiskEntry OPTIONAL,
379  OUT PPARTENTRY *pPartEntry);
380 
381 BOOLEAN
383  IN PPARTLIST List,
384  OUT PDISKENTRY *pDiskEntry OPTIONAL,
385  OUT PPARTENTRY *pPartEntry);
386 
387 /* EOF */
ERROR_NUMBER PrimaryPartitionCreationChecks(IN PPARTENTRY PartEntry)
Definition: partlist.c:3954
LIST_ENTRY PrimaryPartListHead
Definition: partlist.h:131
struct _DISKENTRY DISKENTRY
struct _PARTLIST * PartList
Definition: partlist.h:86
WCHAR DriveLetter
Definition: partlist.h:58
CPPORT Port[4]
Definition: headless.c:35
#define IN
Definition: typedefs.h:39
struct _PARTLIST PARTLIST
ULONG PartitionNumber
Definition: partlist.h:55
ULARGE_INTEGER StartSector
Definition: partlist.h:49
USHORT Id
Definition: partlist.h:115
LIST_ENTRY BiosDiskListHead
Definition: partlist.h:166
WCHAR VolumeLabel[20]
Definition: partlist.h:59
ULONG HwControllerNumber
Definition: partlist.h:104
struct _PARTLIST * PPARTLIST
struct _PARTENTRY PARTENTRY
_In_ PFCB _In_ LONGLONG StartingOffset
Definition: cdprocs.h:290
BOOLEAN IsPartitionActive(IN PPARTENTRY PartEntry)
Definition: partlist.c:1768
ULONGLONG AlignDown(IN ULONGLONG Value, IN ULONG Alignment)
Definition: partlist.c:67
ULONG CylinderAlignment
Definition: partlist.h:99
PDISKENTRY GetDiskByBiosNumber(IN PPARTLIST List, IN ULONG HwDiskNumber)
Definition: partlist.c:1988
unsigned char EndingSector
Definition: partlist.h:187
PPARTENTRY GetPrevPartition(IN PPARTLIST List, IN PPARTENTRY CurrentPart OPTIONAL)
Definition: partlist.c:2299
NTSTATUS WritePartitions(IN PDISKENTRY DiskEntry)
Definition: partlist.c:3619
USHORT Bus
Definition: partlist.h:114
ULONG HwAdapterNumber
Definition: partlist.h:103
ULARGE_INTEGER SectorCount
Definition: partlist.h:50
ULONG DiskNumber
Definition: partlist.h:207
ULONG Signature
Definition: partlist.h:209
ULONG Checksum
Definition: partlist.h:146
LIST_ENTRY DiskListHead
Definition: partlist.h:165
ULONG Signature
Definition: partlist.h:145
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:2143
ULONG ControllerNumber
Definition: partlist.h:143
ULONG DiskNumber
Definition: partlist.h:111
enum _MEDIA_TYPE MEDIA_TYPE
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2060
struct _BIOSDISKENTRY * PBIOSDISKENTRY
VOID DestroyPartitionList(IN PPARTLIST List)
Definition: partlist.c:1931
PDISKENTRY GetDiskBySCSI(IN PPARTLIST List, IN USHORT Port, IN USHORT Bus, IN USHORT Id)
Definition: partlist.c:2040
BOOLEAN DeletePartition(IN PPARTLIST List, IN PPARTENTRY PartEntry, OUT PPARTENTRY *FreeRegion OPTIONAL)
Definition: partlist.c:3047
LIST_ENTRY ListEntry
Definition: partlist.h:206
BOOLEAN SetMountedDeviceValue(IN WCHAR Letter, IN ULONG Signature, IN LARGE_INTEGER StartingOffset)
Definition: partlist.c:3800
unsigned char EndingCylinder
Definition: partlist.h:188
PPARTENTRY SystemPartition
Definition: partlist.h:163
DWORD Id
ULONGLONG AlignUp(IN ULONGLONG Value, IN ULONG Alignment)
Definition: partlist.c:79
PPARTENTRY ExtendedPartition
Definition: partlist.h:135
LIST_ENTRY ListEntry
Definition: partlist.h:43
BOOLEAN LogicalPartition
Definition: partlist.h:63
unsigned char BootFlags
Definition: partlist.h:181
PARTITION_STYLE DiskStyle
Definition: partlist.h:121
BOOLEAN SetMountedDeviceValues(IN PPARTLIST List)
Definition: partlist.c:3861
struct _BIOSDISKENTRY BIOSDISKENTRY
FORMATSTATE FormatState
Definition: partlist.h:61
#define PARTITION_TBL_SIZE
Definition: partlist.h:170
BOOLEAN Dirty
Definition: partlist.h:118
unsigned int SectorCount
Definition: partlist.h:190
unsigned char BOOLEAN
struct _PARTITION * PPARTITION
unsigned int StartingBlock
Definition: partlist.h:189
BOOLEAN GetNextUncheckedPartition(IN PPARTLIST List, OUT PDISKENTRY *pDiskEntry OPTIONAL, OUT PPARTENTRY *pPartEntry)
Definition: partlist.c:4094
_Reserved_ PVOID Reserved
Definition: winddi.h:3974
VOID SetMBRPartitionType(IN PPARTENTRY PartEntry, IN UCHAR PartitionType)
Definition: partlist.c:3937
BOOLEAN CreateLogicalPartition(IN PPARTLIST List, IN OUT PPARTENTRY PartEntry, IN ULONGLONG SectorCount, IN BOOLEAN AutoCreate)
Definition: partlist.c:2904
MEDIA_TYPE MediaType
Definition: partlist.h:88
PPARTENTRY SelectPartition(IN PPARTLIST List, IN ULONG DiskNumber, IN ULONG PartitionNumber)
Definition: partlist.c:2183
ULARGE_INTEGER SectorCount
Definition: partlist.h:97
PPARTENTRY GetNextPartition(IN PPARTLIST List, IN PPARTENTRY CurrentPart OPTIONAL)
Definition: partlist.c:2207
BOOLEAN AutoCreate
Definition: partlist.h:74
ULONG SectorAlignment
Definition: partlist.h:98
_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:142
UCHAR PartitionType
Definition: partlist.h:53
BOOLEAN BiosFound
Definition: partlist.h:102
struct _DISKENTRY * DiskEntry
Definition: partlist.h:46
ULONG BytesPerSector
Definition: partlist.h:95
__wchar_t WCHAR
Definition: xmlstorage.h:180
UNICODE_STRING DriverName
Definition: partlist.h:123
uint64_t ULONGLONG
Definition: typedefs.h:67
ULONG OnDiskPartitionNumber
Definition: partlist.h:54
unsigned char StartingCylinder
Definition: partlist.h:184
#define MAX_PATH
Definition: compat.h:34
CM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry
Definition: partlist.h:148
LIST_ENTRY ListEntry
Definition: partlist.h:83
ULONG HwDiskNumber
Definition: partlist.h:105
WCHAR FileSystem[MAX_PATH+1]
Definition: partlist.h:60
unsigned char PartitionType
Definition: partlist.h:185
NTSTATUS DismountVolume(IN PPARTENTRY PartEntry)
Definition: partlist.c:2940
unsigned char UCHAR
Definition: xmlstorage.h:181
PDISKENTRY DiskEntry
Definition: partlist.h:147
struct BIOS_DISK * PBIOS_DISK
ULONG SectorsPerTrack
Definition: partlist.h:94
enum _ERROR_NUMBER ERROR_NUMBER
ERROR_NUMBER ExtendedPartitionCreationChecks(IN PPARTENTRY PartEntry)
Definition: partlist.c:3981
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:92
BOOLEAN New
Definition: partlist.h:71
BOOLEAN SetActivePartition(IN PPARTLIST List, IN PPARTENTRY PartEntry, IN PPARTENTRY OldActivePart OPTIONAL)
Definition: partlist.c:3555
BOOLEAN NeedsCheck
Definition: partlist.h:77
unsigned char EndingHead
Definition: partlist.h:186
enum _FORMATSTATE FORMATSTATE
struct _PARTENTRY * PPARTENTRY
PDISKENTRY GetDiskBySignature(IN PPARTLIST List, IN ULONG Signature)
Definition: partlist.c:2070
LIST_ENTRY ListEntry
Definition: partlist.h:141
unsigned char StartingHead
Definition: partlist.h:182
unsigned short USHORT
Definition: pedump.c:61
ULONG DiskNumber
Definition: partlist.h:144
BOOLEAN IsSuperFloppy(IN PDISKENTRY DiskEntry)
Definition: partlist.c:501
PARTITION Partition[PARTITION_TBL_SIZE]
Definition: partlist.h:198
UCHAR BootCode[440]
Definition: partlist.h:195
ULONG HwFixedDiskNumber
Definition: partlist.h:106
USHORT Port
Definition: partlist.h:113
struct _PARTITION PARTITION
ULONGLONG RoundingDivide(IN ULONGLONG Dividend, IN ULONGLONG Divisor)
Definition: partlist.c:95
ULONG TracksPerCylinder
Definition: partlist.h:93
struct _PARTITION_SECTOR * PPARTITION_SECTOR
LIST_ENTRY LogicalPartListHead
Definition: partlist.h:132
BOOLEAN BootIndicator
Definition: partlist.h:52
PDISKENTRY GetDiskByNumber(IN PPARTLIST List, IN ULONG DiskNumber)
Definition: partlist.c:2014
#define OUT
Definition: typedefs.h:40
CHAR PartitionType
Definition: part_xbox.c:32
_In_ LARGE_INTEGER Divisor
Definition: rtlfuncs.h:3044
unsigned int ULONG
Definition: retypes.h:1
struct _PARTITION_SECTOR PARTITION_SECTOR
_FORMATSTATE
Definition: partlist.h:32
CM_INT13_DRIVE_PARAMETER Int13DiskData
Definition: partlist.h:149
unsigned char StartingSector
Definition: partlist.h:183
static const WCHAR Signature[]
Definition: parser.c:141
ULONG Identifier
Definition: partlist.h:208
PDRIVE_LAYOUT_INFORMATION LayoutBuffer
Definition: partlist.h:125
struct _DISKENTRY * PDISKENTRY
enum _FORMATSTATE * PFORMATSTATE
BOOLEAN GetNextUnformattedPartition(IN PPARTLIST List, OUT PDISKENTRY *pDiskEntry OPTIONAL, OUT PPARTENTRY *pPartEntry)
Definition: partlist.c:4035
BOOLEAN CreateExtendedPartition(IN PPARTLIST List, IN OUT PPARTENTRY PartEntry, IN ULONGLONG SectorCount)
Definition: partlist.c:2850
ERROR_NUMBER LogicalPartitionCreationChecks(IN PPARTENTRY PartEntry)
Definition: partlist.c:4012
PPARTENTRY GetPartition(IN PDISKENTRY DiskEntry, IN ULONG PartitionNumber)
Definition: partlist.c:2096
BOOLEAN NewDisk
Definition: partlist.h:120
BOOLEAN CreatePrimaryPartition(IN PPARTLIST List, IN OUT PPARTENTRY PartEntry, IN ULONGLONG SectorCount, IN BOOLEAN AutoCreate)
Definition: partlist.c:2786
PPARTENTRY FindSupportedSystemPartition(IN PPARTLIST List, IN BOOLEAN ForceSelect, IN PDISKENTRY AlternativeDisk OPTIONAL, IN PPARTENTRY AlternativePart OPTIONAL)
Definition: partlist.c:3260
BOOLEAN WritePartitionsToDisk(IN PPARTLIST List)
Definition: partlist.c:3763
PPARTLIST CreatePartitionList(VOID)
Definition: partlist.c:1847
BOOLEAN IsPartitioned
Definition: partlist.h:66
ULONG PartitionIndex
Definition: partlist.h:56
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68