ReactOS  0.4.13-dev-235-g7373cb3
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 
48  ULONG OnDiskPartitionNumber; /* Enumerated partition number (primary partitions first, excluding the extended partition container, then the logical partitions) */
49  ULONG PartitionNumber; /* Current partition number, only valid for the currently running NTOS instance */
50  ULONG PartitionIndex; /* Index in the LayoutBuffer->PartitionEntry[] cached array of the corresponding DiskEntry */
51 
56 
58 
59  /* Partition is partitioned disk space */
61 
64  /* Partition is new, table does not exist on disk yet */
66 
67  /* Partition was created automatically */
69 
70  /* Partition must be checked */
72 
74 
75 typedef struct _DISKENTRY
76 {
78 
79  /* The list of disks/partitions this disk belongs to */
81 
82  MEDIA_TYPE MediaType; /* FixedMedia or RemovableMedia */
83 
84  /* Disk geometry */
85 
90 
94 
95  /* BIOS Firmware parameters */
99  ULONG HwDiskNumber; /* Disk number currently assigned on the system */
100  ULONG HwFixedDiskNumber; /* Disk number on the system when *ALL* removable disks are not connected */
101 // ULONG Signature; // Obtained from LayoutBuffer->Signature
102 // ULONG Checksum;
103 
104  /* SCSI parameters */
106 // SCSI_ADDRESS;
110 
111  /* Has the partition list been modified? */
113 
114  BOOLEAN NewDisk; /* If TRUE, the disk is uninitialized */
115  PARTITION_STYLE DiskStyle; /* MBR/GPT-partitioned disk, or uninitialized disk (RAW) */
116 
118 
120  // TODO: When adding support for GPT disks:
121  // Use PDRIVE_LAYOUT_INFORMATION_EX which indicates whether
122  // the disk is MBR, GPT, or unknown (uninitialized).
123  // Depending on the style, either use the MBR or GPT partition info.
124 
125  LIST_ENTRY PrimaryPartListHead; /* List of primary partitions */
126  LIST_ENTRY LogicalPartListHead; /* List of logical partitions (Valid only for MBR-partitioned disks) */
127 
128  /* Pointer to the unique extended partition on this disk (Valid only for MBR-partitioned disks) */
130 
132 
133 typedef struct _BIOSDISKENTRY
134 {
141  PDISKENTRY DiskEntry; /* Corresponding recognized disk; is NULL if the disk is not recognized */ // RecognizedDiskEntry;
145 
146 typedef struct _PARTLIST
147 {
148  /*
149  * The system partition where the boot manager resides.
150  * The corresponding system disk is obtained via:
151  * SystemPartition->DiskEntry.
152  */
154  /*
155  * The original system partition in case we are redefining it because
156  * we do not have write support on it.
157  * Please note that this is partly a HACK and MUST NEVER happen on
158  * architectures where real system partitions are mandatory (because then
159  * they are formatted in FAT FS and we support write operation on them).
160  * The corresponding original system disk is obtained via:
161  * OriginalSystemPartition->DiskEntry.
162  */
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 
235 PPARTLIST
237 
238 VOID
240  IN PPARTLIST List);
241 
244  IN PPARTLIST List,
245  IN ULONG HwDiskNumber);
246 
249  IN PPARTLIST List,
250  IN ULONG DiskNumber);
251 
254  IN PPARTLIST List,
255  IN USHORT Port,
256  IN USHORT Bus,
257  IN USHORT Id);
258 
261  IN PPARTLIST List,
262  IN ULONG Signature);
263 
266  // IN PPARTLIST List,
267  IN PDISKENTRY DiskEntry,
269 
270 BOOLEAN
272  IN PPARTLIST List,
273  IN ULONG DiskNumber,
275  OUT PDISKENTRY* pDiskEntry,
276  OUT PPARTENTRY* pPartEntry OPTIONAL);
277 
280  IN PPARTLIST List,
281  IN ULONG DiskNumber,
283 
286  IN PPARTLIST List,
287  IN PPARTENTRY CurrentPart OPTIONAL);
288 
291  IN PPARTLIST List,
292  IN PPARTENTRY CurrentPart OPTIONAL);
293 
294 BOOLEAN
296  IN PPARTLIST List,
297  IN PPARTENTRY SelectedEntry,
299  IN BOOLEAN AutoCreate);
300 
301 BOOLEAN
303  IN PPARTLIST List,
304  IN PPARTENTRY SelectedEntry,
306 
307 BOOLEAN
309  IN PPARTLIST List,
310  IN PPARTENTRY SelectedEntry,
312  IN BOOLEAN AutoCreate);
313 
314 BOOLEAN
316  IN PPARTLIST List,
317  IN PPARTENTRY PartEntry,
318  OUT PPARTENTRY* FreeRegion OPTIONAL);
319 
320 VOID
322  IN PPARTLIST List,
323  IN BOOLEAN ForceSelect,
324  IN PDISKENTRY AlternateDisk OPTIONAL,
325  IN PPARTENTRY AlternatePart OPTIONAL);
326 
327 NTSTATUS
329  IN PDISKENTRY DiskEntry);
330 
331 BOOLEAN
333  IN PPARTLIST List);
334 
335 BOOLEAN
337  IN WCHAR Letter,
340 
341 BOOLEAN
343  IN PPARTLIST List);
344 
345 VOID
347  IN PPARTENTRY PartEntry,
349 
352  IN PPARTENTRY PartEntry);
353 
356  IN PPARTENTRY PartEntry);
357 
360  IN PPARTENTRY PartEntry);
361 
362 BOOLEAN
364  IN PPARTLIST List,
365  OUT PDISKENTRY *pDiskEntry OPTIONAL,
366  OUT PPARTENTRY *pPartEntry);
367 
368 BOOLEAN
370  IN PPARTLIST List,
371  OUT PDISKENTRY *pDiskEntry OPTIONAL,
372  OUT PPARTENTRY *pPartEntry);
373 
374 /* EOF */
ERROR_NUMBER PrimaryPartitionCreationChecks(IN PPARTENTRY PartEntry)
Definition: partlist.c:3996
LIST_ENTRY PrimaryPartListHead
Definition: partlist.h:125
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2327
signed char * PCHAR
Definition: retypes.h:7
struct _DISKENTRY DISKENTRY
struct _PARTLIST * PartList
Definition: partlist.h:80
VOID CheckActiveSystemPartition(IN PPARTLIST List, IN BOOLEAN ForceSelect, IN PDISKENTRY AlternateDisk OPTIONAL, IN PPARTENTRY AlternatePart OPTIONAL)
Definition: partlist.c:3324
WCHAR DriveLetter
Definition: partlist.h:52
CPPORT Port[4]
Definition: headless.c:34
#define IN
Definition: typedefs.h:38
struct _PARTLIST PARTLIST
ULONG PartitionNumber
Definition: partlist.h:49
ULARGE_INTEGER StartSector
Definition: partlist.h:42
USHORT Id
Definition: partlist.h:109
LIST_ENTRY BiosDiskListHead
Definition: partlist.h:166
WCHAR VolumeLabel[20]
Definition: partlist.h:53
ULONG HwControllerNumber
Definition: partlist.h:98
struct _PARTLIST * PPARTLIST
struct _PARTENTRY PARTENTRY
_In_ PFCB _In_ LONGLONG StartingOffset
Definition: cdprocs.h:282
ULONGLONG AlignDown(IN ULONGLONG Value, IN ULONG Alignment)
Definition: partlist.c:245
ULONG CylinderAlignment
Definition: partlist.h:93
PDISKENTRY GetDiskByBiosNumber(IN PPARTLIST List, IN ULONG HwDiskNumber)
Definition: partlist.c:1974
unsigned char EndingSector
Definition: partlist.h:187
PPARTENTRY GetPrevPartition(IN PPARTLIST List, IN PPARTENTRY CurrentPart OPTIONAL)
Definition: partlist.c:2285
NTSTATUS WritePartitions(IN PDISKENTRY DiskEntry)
Definition: partlist.c:3665
USHORT Bus
Definition: partlist.h:108
ULONG HwAdapterNumber
Definition: partlist.h:97
ULARGE_INTEGER SectorCount
Definition: partlist.h:43
ULONG DiskNumber
Definition: partlist.h:207
ULONG Signature
Definition: partlist.h:209
ULONG Checksum
Definition: partlist.h:140
LIST_ENTRY DiskListHead
Definition: partlist.h:165
ULONG Signature
Definition: partlist.h:139
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:2129
ULONG ControllerNumber
Definition: partlist.h:137
ULONG DiskNumber
Definition: partlist.h:105
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:1917
PDISKENTRY GetDiskBySCSI(IN PPARTLIST List, IN USHORT Port, IN USHORT Bus, IN USHORT Id)
Definition: partlist.c:2026
BOOLEAN DeletePartition(IN PPARTLIST List, IN PPARTENTRY PartEntry, OUT PPARTENTRY *FreeRegion OPTIONAL)
Definition: partlist.c:3041
LIST_ENTRY ListEntry
Definition: partlist.h:206
BOOLEAN SetMountedDeviceValue(IN WCHAR Letter, IN ULONG Signature, IN LARGE_INTEGER StartingOffset)
Definition: partlist.c:3843
unsigned char EndingCylinder
Definition: partlist.h:188
PPARTENTRY SystemPartition
Definition: partlist.h:153
DWORD Id
ULONGLONG AlignUp(IN ULONGLONG Value, IN ULONG Alignment)
Definition: partlist.c:257
PPARTENTRY ExtendedPartition
Definition: partlist.h:129
LIST_ENTRY ListEntry
Definition: partlist.h:36
BOOLEAN LogicalPartition
Definition: partlist.h:57
unsigned char BootFlags
Definition: partlist.h:181
struct _PARTITION_TYPE * PPARTITION_TYPE
PARTITION_STYLE DiskStyle
Definition: partlist.h:115
BOOLEAN SetMountedDeviceValues(IN PPARTLIST List)
Definition: partlist.c:3905
struct _BIOSDISKENTRY BIOSDISKENTRY
FORMATSTATE FormatState
Definition: partlist.h:55
#define PARTITION_TBL_SIZE
Definition: partlist.h:170
BOOLEAN Dirty
Definition: partlist.h:112
unsigned int SectorCount
Definition: partlist.h:190
unsigned char BOOLEAN
struct _PARTITION * PPARTITION
unsigned int StartingBlock
Definition: partlist.h:189
BOOLEAN CreateExtendedPartition(IN PPARTLIST List, IN PPARTENTRY SelectedEntry, IN ULONGLONG SectorCount)
Definition: partlist.c:2837
BOOLEAN GetNextUncheckedPartition(IN PPARTLIST List, OUT PDISKENTRY *pDiskEntry OPTIONAL, OUT PPARTENTRY *pPartEntry)
Definition: partlist.c:4136
_Reserved_ PVOID Reserved
Definition: winddi.h:3974
MEDIA_TYPE MediaType
Definition: partlist.h:82
PPARTENTRY SelectPartition(IN PPARTLIST List, IN ULONG DiskNumber, IN ULONG PartitionNumber)
Definition: partlist.c:2169
ULARGE_INTEGER SectorCount
Definition: partlist.h:91
PPARTENTRY GetNextPartition(IN PPARTLIST List, IN PPARTENTRY CurrentPart OPTIONAL)
Definition: partlist.c:2193
BOOLEAN AutoCreate
Definition: partlist.h:68
ULONG SectorAlignment
Definition: partlist.h:92
VOID SetPartitionType(IN PPARTENTRY PartEntry, IN UCHAR PartitionType)
Definition: partlist.c:3981
ULONG AdapterNumber
Definition: partlist.h:136
UCHAR PartitionType
Definition: partlist.h:46
BOOLEAN BiosFound
Definition: partlist.h:96
struct _DISKENTRY * DiskEntry
Definition: partlist.h:39
ULONG BytesPerSector
Definition: partlist.h:89
LIST_ENTRY List
Definition: psmgr.c:57
__wchar_t WCHAR
Definition: xmlstorage.h:180
UNICODE_STRING DriverName
Definition: partlist.h:117
uint64_t ULONGLONG
Definition: typedefs.h:65
ULONG OnDiskPartitionNumber
Definition: partlist.h:48
unsigned char StartingCylinder
Definition: partlist.h:184
#define MAX_PATH
Definition: compat.h:26
CM_DISK_GEOMETRY_DEVICE_DATA DiskGeometry
Definition: partlist.h:142
LIST_ENTRY ListEntry
Definition: partlist.h:77
ULONG HwDiskNumber
Definition: partlist.h:99
WCHAR FileSystem[MAX_PATH+1]
Definition: partlist.h:54
unsigned char PartitionType
Definition: partlist.h:185
unsigned char UCHAR
Definition: xmlstorage.h:181
PDISKENTRY DiskEntry
Definition: partlist.h:141
struct BIOS_DISK * PBIOS_DISK
ULONG SectorsPerTrack
Definition: partlist.h:88
enum _ERROR_NUMBER ERROR_NUMBER
BOOLEAN CreateLogicalPartition(IN PPARTLIST List, IN PPARTENTRY SelectedEntry, IN ULONGLONG SectorCount, IN BOOLEAN AutoCreate)
Definition: partlist.c:2894
PARTITION_TYPE PartitionTypes[NUM_PARTITION_TYPE_ENTRIES]
Definition: partlist.c:62
ERROR_NUMBER ExtendedPartitionCreationChecks(IN PPARTENTRY PartEntry)
Definition: partlist.c:4023
WCHAR Letter
enum _PARTITION_STYLE PARTITION_STYLE
Definition: typedefs.h:117
ULONG SectorCount
Definition: part_xbox.c:32
ULONGLONG Cylinders
Definition: partlist.h:86
BOOLEAN New
Definition: partlist.h:65
BOOLEAN CreatePrimaryPartition(IN PPARTLIST List, IN PPARTENTRY SelectedEntry, IN ULONGLONG SectorCount, IN BOOLEAN AutoCreate)
Definition: partlist.c:2769
BOOLEAN NeedsCheck
Definition: partlist.h:71
unsigned char EndingHead
Definition: partlist.h:186
PPARTENTRY OriginalSystemPartition
Definition: partlist.h:163
enum _FORMATSTATE FORMATSTATE
struct _PARTENTRY * PPARTENTRY
PDISKENTRY GetDiskBySignature(IN PPARTLIST List, IN ULONG Signature)
Definition: partlist.c:2056
LIST_ENTRY ListEntry
Definition: partlist.h:135
unsigned char StartingHead
Definition: partlist.h:182
unsigned short USHORT
Definition: pedump.c:61
ULONG DiskNumber
Definition: partlist.h:138
BOOLEAN IsSuperFloppy(IN PDISKENTRY DiskEntry)
Definition: partlist.c:679
PARTITION Partition[PARTITION_TBL_SIZE]
Definition: partlist.h:198
PCHAR Description
Definition: partlist.h:16
UCHAR BootCode[440]
Definition: partlist.h:195
ULONG HwFixedDiskNumber
Definition: partlist.h:100
USHORT Port
Definition: partlist.h:107
struct _PARTITION PARTITION
ULONGLONG RoundingDivide(IN ULONGLONG Dividend, IN ULONGLONG Divisor)
Definition: partlist.c:273
ULONG TracksPerCylinder
Definition: partlist.h:87
struct _PARTITION_SECTOR * PPARTITION_SECTOR
LIST_ENTRY LogicalPartListHead
Definition: partlist.h:126
BOOLEAN BootIndicator
Definition: partlist.h:45
PDISKENTRY GetDiskByNumber(IN PPARTLIST List, IN ULONG DiskNumber)
Definition: partlist.c:2000
#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:143
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:119
struct _DISKENTRY * PDISKENTRY
enum _FORMATSTATE * PFORMATSTATE
BOOLEAN GetNextUnformattedPartition(IN PPARTLIST List, OUT PDISKENTRY *pDiskEntry OPTIONAL, OUT PPARTENTRY *pPartEntry)
Definition: partlist.c:4077
ERROR_NUMBER LogicalPartitionCreationChecks(IN PPARTENTRY PartEntry)
Definition: partlist.c:4054
PPARTENTRY GetPartition(IN PDISKENTRY DiskEntry, IN ULONG PartitionNumber)
Definition: partlist.c:2082
BOOLEAN NewDisk
Definition: partlist.h:114
BOOLEAN WritePartitionsToDisk(IN PPARTLIST List)
Definition: partlist.c:3806
PPARTLIST CreatePartitionList(VOID)
Definition: partlist.c:1840
ULONG HiddenSectors
Definition: partlist.h:47
BOOLEAN IsPartitioned
Definition: partlist.h:60
ULONG PartitionIndex
Definition: partlist.h:50
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
#define NUM_PARTITION_TYPE_ENTRIES
Definition: partlist.h:19