ReactOS  0.4.14-dev-614-gbfd8a84
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 /* PARTITION UTILITY FUNCTIONS **********************************************/
24 
25 typedef enum _FORMATSTATE
26 {
33 
34 typedef struct _PARTENTRY
35 {
37 
38  /* The disk this partition belongs to */
40 
41  /* Partition geometry */
44 
45  BOOLEAN BootIndicator; // NOTE: See comment for the PARTLIST::SystemPartition member.
47  ULONG OnDiskPartitionNumber; /* Enumerated partition number (primary partitions first, excluding the extended partition container, then the logical partitions) */
48  ULONG PartitionNumber; /* Current partition number, only valid for the currently running NTOS instance */
49  ULONG PartitionIndex; /* Index in the LayoutBuffer->PartitionEntry[] cached array of the corresponding DiskEntry */
50 
55 
57 
58  /* Partition is partitioned disk space */
60 
63  /* Partition is new, table does not exist on disk yet */
65 
66  /* Partition was created automatically */
68 
69  /* Partition must be checked */
71 
73 
74 typedef struct _DISKENTRY
75 {
77 
78  /* The list of disks/partitions this disk belongs to */
80 
81  MEDIA_TYPE MediaType; /* FixedMedia or RemovableMedia */
82 
83  /* Disk geometry */
84 
89 
93 
94  /* BIOS Firmware parameters */
98  ULONG HwDiskNumber; /* Disk number currently assigned on the system */
99  ULONG HwFixedDiskNumber; /* Disk number on the system when *ALL* removable disks are not connected */
100 // ULONG Signature; // Obtained from LayoutBuffer->Signature
101 // ULONG Checksum;
102 
103  /* SCSI parameters */
105 // SCSI_ADDRESS;
109 
110  /* Has the partition list been modified? */
112 
113  BOOLEAN NewDisk; /* If TRUE, the disk is uninitialized */
114  PARTITION_STYLE DiskStyle; /* MBR/GPT-partitioned disk, or uninitialized disk (RAW) */
115 
117 
119  // TODO: When adding support for GPT disks:
120  // Use PDRIVE_LAYOUT_INFORMATION_EX which indicates whether
121  // the disk is MBR, GPT, or unknown (uninitialized).
122  // Depending on the style, either use the MBR or GPT partition info.
123 
124  LIST_ENTRY PrimaryPartListHead; /* List of primary partitions */
125  LIST_ENTRY LogicalPartListHead; /* List of logical partitions (Valid only for MBR-partitioned disks) */
126 
127  /* Pointer to the unique extended partition on this disk (Valid only for MBR-partitioned disks) */
129 
131 
132 typedef struct _BIOSDISKENTRY
133 {
140  PDISKENTRY DiskEntry; /* Corresponding recognized disk; is NULL if the disk is not recognized */ // RecognizedDiskEntry;
144 
145 typedef struct _PARTLIST
146 {
147  /*
148  * The system partition where the boot manager resides.
149  * The corresponding system disk is obtained via:
150  * SystemPartition->DiskEntry.
151  */
152  // NOTE: It seems to appear that the specifications of ARC and (u)EFI
153  // actually allow for multiple system partitions to exist on the system.
154  // If so we should instead rely on the BootIndicator bit of the PARTENTRY
155  // structure in order to find these.
157 
160 
161 } PARTLIST, *PPARTLIST;
162 
163 #define PARTITION_TBL_SIZE 4
164 
165 #define PARTITION_MAGIC 0xAA55
166 
167 /* Defines system type for MBR showing that a GPT is following */
168 #define EFI_PMBR_OSTYPE_EFI 0xEE
169 
170 #include <pshpack1.h>
171 
172 typedef struct _PARTITION
173 {
174  unsigned char BootFlags; /* bootable? 0=no, 128=yes */
175  unsigned char StartingHead; /* beginning head number */
176  unsigned char StartingSector; /* beginning sector number */
177  unsigned char StartingCylinder; /* 10 bit nmbr, with high 2 bits put in begsect */
178  unsigned char PartitionType; /* Operating System type indicator code */
179  unsigned char EndingHead; /* ending head number */
180  unsigned char EndingSector; /* ending sector number */
181  unsigned char EndingCylinder; /* also a 10 bit nmbr, with same high 2 bit trick */
182  unsigned int StartingBlock; /* first sector relative to start of disk */
183  unsigned int SectorCount; /* number of sectors in partition */
185 
186 typedef struct _PARTITION_SECTOR
187 {
188  UCHAR BootCode[440]; /* 0x000 */
189  ULONG Signature; /* 0x1B8 */
190  UCHAR Reserved[2]; /* 0x1BC */
192  USHORT Magic; /* 0x1FE */
194 
195 #include <poppack.h>
196 
197 typedef struct
198 {
204 
205 
206 
207 ULONGLONG
208 AlignDown(
210  IN ULONG Alignment);
211 
212 ULONGLONG
213 AlignUp(
215  IN ULONG Alignment);
216 
217 ULONGLONG
219  IN ULONGLONG Dividend,
221 
222 
223 BOOLEAN
225  IN PDISKENTRY DiskEntry);
226 
227 BOOLEAN
229  IN PPARTENTRY PartEntry);
230 
231 PPARTLIST
233 
234 VOID
236  IN PPARTLIST List);
237 
240  IN PPARTLIST List,
241  IN ULONG HwDiskNumber);
242 
245  IN PPARTLIST List,
246  IN ULONG DiskNumber);
247 
250  IN PPARTLIST List,
251  IN USHORT Port,
252  IN USHORT Bus,
253  IN USHORT Id);
254 
257  IN PPARTLIST List,
258  IN ULONG Signature);
259 
262  // IN PPARTLIST List,
263  IN PDISKENTRY DiskEntry,
265 
266 BOOLEAN
268  IN PPARTLIST List,
269  IN ULONG DiskNumber,
271  OUT PDISKENTRY* pDiskEntry,
272  OUT PPARTENTRY* pPartEntry OPTIONAL);
273 
276  IN PPARTLIST List,
277  IN ULONG DiskNumber,
279 
282  IN PPARTLIST List,
283  IN PPARTENTRY CurrentPart OPTIONAL);
284 
287  IN PPARTLIST List,
288  IN PPARTENTRY CurrentPart OPTIONAL);
289 
290 BOOLEAN
292  IN PPARTLIST List,
293  IN OUT PPARTENTRY PartEntry,
295  IN BOOLEAN AutoCreate);
296 
297 BOOLEAN
299  IN PPARTLIST List,
300  IN OUT PPARTENTRY PartEntry,
302 
303 BOOLEAN
305  IN PPARTLIST List,
306  IN OUT PPARTENTRY PartEntry,
308  IN BOOLEAN AutoCreate);
309 
310 NTSTATUS
312  IN PPARTENTRY PartEntry);
313 
314 BOOLEAN
316  IN PPARTLIST List,
317  IN PPARTENTRY PartEntry,
318  OUT PPARTENTRY* FreeRegion OPTIONAL);
319 
322  IN PPARTLIST List,
323  IN BOOLEAN ForceSelect,
324  IN PDISKENTRY AlternativeDisk OPTIONAL,
325  IN PPARTENTRY AlternativePart OPTIONAL);
326 
327 BOOLEAN
329  IN PPARTLIST List,
330  IN PPARTENTRY PartEntry,
331  IN PPARTENTRY OldActivePart OPTIONAL);
332 
333 NTSTATUS
335  IN PDISKENTRY DiskEntry);
336 
337 BOOLEAN
339  IN PPARTLIST List);
340 
341 BOOLEAN
343  IN WCHAR Letter,
346 
347 BOOLEAN
349  IN PPARTLIST List);
350 
351 VOID
353  IN PPARTENTRY PartEntry,
355 
358  IN PPARTENTRY PartEntry);
359 
362  IN PPARTENTRY PartEntry);
363 
366  IN PPARTENTRY PartEntry);
367 
368 BOOLEAN
370  IN PPARTLIST List,
371  OUT PDISKENTRY *pDiskEntry OPTIONAL,
372  OUT PPARTENTRY *pPartEntry);
373 
374 BOOLEAN
376  IN PPARTLIST List,
377  OUT PDISKENTRY *pDiskEntry OPTIONAL,
378  OUT PPARTENTRY *pPartEntry);
379 
380 /* EOF */
ERROR_NUMBER PrimaryPartitionCreationChecks(IN PPARTENTRY PartEntry)
Definition: partlist.c:4123
LIST_ENTRY PrimaryPartListHead
Definition: partlist.h:124
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
signed char * PCHAR
Definition: retypes.h:7
struct _DISKENTRY DISKENTRY
struct _PARTLIST * PartList
Definition: partlist.h:79
WCHAR DriveLetter
Definition: partlist.h:51
CPPORT Port[4]
Definition: headless.c:34
#define IN
Definition: typedefs.h:38
struct _PARTLIST PARTLIST
ULONG PartitionNumber
Definition: partlist.h:48
ULARGE_INTEGER StartSector
Definition: partlist.h:42
USHORT Id
Definition: partlist.h:108
LIST_ENTRY BiosDiskListHead
Definition: partlist.h:159
WCHAR VolumeLabel[20]
Definition: partlist.h:52
ULONG HwControllerNumber
Definition: partlist.h:97
struct _PARTLIST * PPARTLIST
struct _PARTENTRY PARTENTRY
_In_ PFCB _In_ LONGLONG StartingOffset
Definition: cdprocs.h:282
BOOLEAN IsPartitionActive(IN PPARTENTRY PartEntry)
Definition: partlist.c:1944
ULONGLONG AlignDown(IN ULONGLONG Value, IN ULONG Alignment)
Definition: partlist.c:245
ULONG CylinderAlignment
Definition: partlist.h:92
PDISKENTRY GetDiskByBiosNumber(IN PPARTLIST List, IN ULONG HwDiskNumber)
Definition: partlist.c:2164
unsigned char EndingSector
Definition: partlist.h:180
PPARTENTRY GetPrevPartition(IN PPARTLIST List, IN PPARTENTRY CurrentPart OPTIONAL)
Definition: partlist.c:2475
NTSTATUS WritePartitions(IN PDISKENTRY DiskEntry)
Definition: partlist.c:3792
USHORT Bus
Definition: partlist.h:107
ULONG HwAdapterNumber
Definition: partlist.h:96
ULARGE_INTEGER SectorCount
Definition: partlist.h:43
ULONG DiskNumber
Definition: partlist.h:200
ULONG Signature
Definition: partlist.h:202
ULONG Checksum
Definition: partlist.h:139
LIST_ENTRY DiskListHead
Definition: partlist.h:158
ULONG Signature
Definition: partlist.h:138
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:2319
ULONG ControllerNumber
Definition: partlist.h:136
ULONG DiskNumber
Definition: partlist.h:104
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:2107
PDISKENTRY GetDiskBySCSI(IN PPARTLIST List, IN USHORT Port, IN USHORT Bus, IN USHORT Id)
Definition: partlist.c:2216
BOOLEAN DeletePartition(IN PPARTLIST List, IN PPARTENTRY PartEntry, OUT PPARTENTRY *FreeRegion OPTIONAL)
Definition: partlist.c:3220
LIST_ENTRY ListEntry
Definition: partlist.h:199
BOOLEAN SetMountedDeviceValue(IN WCHAR Letter, IN ULONG Signature, IN LARGE_INTEGER StartingOffset)
Definition: partlist.c:3970
unsigned char EndingCylinder
Definition: partlist.h:181
PPARTENTRY SystemPartition
Definition: partlist.h:156
DWORD Id
ULONGLONG AlignUp(IN ULONGLONG Value, IN ULONG Alignment)
Definition: partlist.c:257
PPARTENTRY ExtendedPartition
Definition: partlist.h:128
LIST_ENTRY ListEntry
Definition: partlist.h:36
BOOLEAN LogicalPartition
Definition: partlist.h:56
unsigned char BootFlags
Definition: partlist.h:174
struct _PARTITION_TYPE * PPARTITION_TYPE
PARTITION_STYLE DiskStyle
Definition: partlist.h:114
BOOLEAN SetMountedDeviceValues(IN PPARTLIST List)
Definition: partlist.c:4032
struct _BIOSDISKENTRY BIOSDISKENTRY
FORMATSTATE FormatState
Definition: partlist.h:54
#define PARTITION_TBL_SIZE
Definition: partlist.h:163
BOOLEAN Dirty
Definition: partlist.h:111
unsigned int SectorCount
Definition: partlist.h:183
unsigned char BOOLEAN
struct _PARTITION * PPARTITION
unsigned int StartingBlock
Definition: partlist.h:182
BOOLEAN GetNextUncheckedPartition(IN PPARTLIST List, OUT PDISKENTRY *pDiskEntry OPTIONAL, OUT PPARTENTRY *pPartEntry)
Definition: partlist.c:4263
_Reserved_ PVOID Reserved
Definition: winddi.h:3974
BOOLEAN CreateLogicalPartition(IN PPARTLIST List, IN OUT PPARTENTRY PartEntry, IN ULONGLONG SectorCount, IN BOOLEAN AutoCreate)
Definition: partlist.c:3077
MEDIA_TYPE MediaType
Definition: partlist.h:81
PPARTENTRY SelectPartition(IN PPARTLIST List, IN ULONG DiskNumber, IN ULONG PartitionNumber)
Definition: partlist.c:2359
ULARGE_INTEGER SectorCount
Definition: partlist.h:90
PPARTENTRY GetNextPartition(IN PPARTLIST List, IN PPARTENTRY CurrentPart OPTIONAL)
Definition: partlist.c:2383
BOOLEAN AutoCreate
Definition: partlist.h:67
ULONG SectorAlignment
Definition: partlist.h:91
VOID SetPartitionType(IN PPARTENTRY PartEntry, IN UCHAR PartitionType)
Definition: partlist.c:4108
ULONG AdapterNumber
Definition: partlist.h:135
UCHAR PartitionType
Definition: partlist.h:46
BOOLEAN BiosFound
Definition: partlist.h:95
struct _DISKENTRY * DiskEntry
Definition: partlist.h:39
ULONG BytesPerSector
Definition: partlist.h:88
LIST_ENTRY List
Definition: psmgr.c:57
__wchar_t WCHAR
Definition: xmlstorage.h:180
UNICODE_STRING DriverName
Definition: partlist.h:116
uint64_t ULONGLONG
Definition: typedefs.h:65
ULONG OnDiskPartitionNumber
Definition: partlist.h:47
unsigned char StartingCylinder
Definition: partlist.h:177
#define MAX_PATH
Definition: compat.h:26
CM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry
Definition: partlist.h:141
LIST_ENTRY ListEntry
Definition: partlist.h:76
ULONG HwDiskNumber
Definition: partlist.h:98
WCHAR FileSystem[MAX_PATH+1]
Definition: partlist.h:53
unsigned char PartitionType
Definition: partlist.h:178
NTSTATUS DismountVolume(IN PPARTENTRY PartEntry)
Definition: partlist.c:3113
unsigned char UCHAR
Definition: xmlstorage.h:181
PDISKENTRY DiskEntry
Definition: partlist.h:140
struct BIOS_DISK * PBIOS_DISK
ULONG SectorsPerTrack
Definition: partlist.h:87
enum _ERROR_NUMBER ERROR_NUMBER
PARTITION_TYPE PartitionTypes[NUM_PARTITION_TYPE_ENTRIES]
Definition: partlist.c:62
ERROR_NUMBER ExtendedPartitionCreationChecks(IN PPARTENTRY PartEntry)
Definition: partlist.c:4150
WCHAR Letter
enum _PARTITION_STYLE PARTITION_STYLE
Definition: typedefs.h:117
ULONG SectorCount
Definition: part_xbox.c:32
ULONGLONG Cylinders
Definition: partlist.h:85
BOOLEAN New
Definition: partlist.h:64
BOOLEAN SetActivePartition(IN PPARTLIST List, IN PPARTENTRY PartEntry, IN PPARTENTRY OldActivePart OPTIONAL)
Definition: partlist.c:3728
BOOLEAN NeedsCheck
Definition: partlist.h:70
unsigned char EndingHead
Definition: partlist.h:179
enum _FORMATSTATE FORMATSTATE
struct _PARTENTRY * PPARTENTRY
PDISKENTRY GetDiskBySignature(IN PPARTLIST List, IN ULONG Signature)
Definition: partlist.c:2246
LIST_ENTRY ListEntry
Definition: partlist.h:134
unsigned char StartingHead
Definition: partlist.h:175
unsigned short USHORT
Definition: pedump.c:61
ULONG DiskNumber
Definition: partlist.h:137
BOOLEAN IsSuperFloppy(IN PDISKENTRY DiskEntry)
Definition: partlist.c:679
PARTITION Partition[PARTITION_TBL_SIZE]
Definition: partlist.h:191
PCHAR Description
Definition: partlist.h:16
UCHAR BootCode[440]
Definition: partlist.h:188
ULONG HwFixedDiskNumber
Definition: partlist.h:99
USHORT Port
Definition: partlist.h:106
struct _PARTITION PARTITION
ULONGLONG RoundingDivide(IN ULONGLONG Dividend, IN ULONGLONG Divisor)
Definition: partlist.c:273
ULONG TracksPerCylinder
Definition: partlist.h:86
struct _PARTITION_SECTOR * PPARTITION_SECTOR
LIST_ENTRY LogicalPartListHead
Definition: partlist.h:125
BOOLEAN BootIndicator
Definition: partlist.h:45
PDISKENTRY GetDiskByNumber(IN PPARTLIST List, IN ULONG DiskNumber)
Definition: partlist.c:2190
#define OUT
Definition: typedefs.h:39
CHAR PartitionType
Definition: part_xbox.c:33
_In_ LARGE_INTEGER Divisor
Definition: rtlfuncs.h:3046
unsigned int ULONG
Definition: retypes.h:1
struct _PARTITION_SECTOR PARTITION_SECTOR
_FORMATSTATE
Definition: partlist.h:25
CM_INT13_DRIVE_PARAMETER Int13DiskData
Definition: partlist.h:142
unsigned char StartingSector
Definition: partlist.h:176
static const WCHAR Signature[]
Definition: parser.c:141
ULONG Identifier
Definition: partlist.h:201
PDRIVE_LAYOUT_INFORMATION LayoutBuffer
Definition: partlist.h:118
struct _DISKENTRY * PDISKENTRY
enum _FORMATSTATE * PFORMATSTATE
BOOLEAN GetNextUnformattedPartition(IN PPARTLIST List, OUT PDISKENTRY *pDiskEntry OPTIONAL, OUT PPARTENTRY *pPartEntry)
Definition: partlist.c:4204
BOOLEAN CreateExtendedPartition(IN PPARTLIST List, IN OUT PPARTENTRY PartEntry, IN ULONGLONG SectorCount)
Definition: partlist.c:3023
ERROR_NUMBER LogicalPartitionCreationChecks(IN PPARTENTRY PartEntry)
Definition: partlist.c:4181
PPARTENTRY GetPartition(IN PDISKENTRY DiskEntry, IN ULONG PartitionNumber)
Definition: partlist.c:2272
BOOLEAN NewDisk
Definition: partlist.h:113
BOOLEAN CreatePrimaryPartition(IN PPARTLIST List, IN OUT PPARTENTRY PartEntry, IN ULONGLONG SectorCount, IN BOOLEAN AutoCreate)
Definition: partlist.c:2959
PPARTENTRY FindSupportedSystemPartition(IN PPARTLIST List, IN BOOLEAN ForceSelect, IN PDISKENTRY AlternativeDisk OPTIONAL, IN PPARTENTRY AlternativePart OPTIONAL)
Definition: partlist.c:3433
BOOLEAN WritePartitionsToDisk(IN PPARTLIST List)
Definition: partlist.c:3933
PPARTLIST CreatePartitionList(VOID)
Definition: partlist.c:2023
BOOLEAN IsPartitioned
Definition: partlist.h:59
ULONG PartitionIndex
Definition: partlist.h:49
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
#define NUM_PARTITION_TYPE_ENTRIES
Definition: partlist.h:19