ReactOS 0.4.16-dev-2610-ge2c92c0
part_gpt.c File Reference
#include "part_gpt.h"
Include dependency graph for part_gpt.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

BOOLEAN DiskReadGptHeader (_In_ UCHAR DriveNumber, _Out_ PGPT_TABLE_HEADER GptHeader)
 
BOOLEAN DiskGetGptPartitionEntry (_In_ UCHAR DriveNumber, _In_ ULONG SectorSize, _In_ ULONG PartitionNumber, _Out_ PPARTITION_INFORMATION PartitionEntry)
 

Function Documentation

◆ DiskGetGptPartitionEntry()

BOOLEAN DiskGetGptPartitionEntry ( _In_ UCHAR  DriveNumber,
_In_ ULONG  SectorSize,
_In_ ULONG  PartitionNumber,
_Out_ PPARTITION_INFORMATION  PartitionEntry 
)

Definition at line 46 of file part_gpt.c.

51{
52 GPT_TABLE_HEADER GptHeader;
53 GPT_PARTITION_ENTRY GptEntry;
54 ULONGLONG EntryLba;
55 ULONG EntryOffset;
56 ULONG EntriesPerBlock;
59
60 ASSERT(SectorSize >= 512);
61
62 /* Read GPT header */
63 if (!DiskReadGptHeader(DriveNumber, &GptHeader))
64 return FALSE;
65
66 /* Validate partition number */
67 //if (PartitionNumber == 0 || PartitionNumber > GptHeader.NumberOfPartitionEntries)
69 return FALSE;
70
71 /* Convert to 0-based index */
72 ULONG EntryIndex = PartitionNumber - 1;
73
74 EntriesPerBlock = SectorSize / GptHeader.SizeOfPartitionEntry;
75 EntryLba = GptHeader.PartitionEntryLba + (EntryIndex / EntriesPerBlock);
76 EntryOffset = (EntryIndex % EntriesPerBlock) * GptHeader.SizeOfPartitionEntry;
77
78 /* Read the block containing the partition entry */
79 if (!MachDiskReadLogicalSectors(DriveNumber, EntryLba, 1, DiskReadBuffer))
80 return FALSE;
81
82 /* Extract partition entry */
83 RtlCopyMemory(&GptEntry, (PUCHAR)DiskReadBuffer + EntryOffset, sizeof(GptEntry));
84
85 /* Check if partition is unused */
86 if (RtlEqualMemory(&GptEntry.PartitionTypeGuid, &UnusedGuid, sizeof(UnusedGuid)))
87 return FALSE;
88
89 /* Calculate partition size in blocks */
90 ULONGLONG PartitionSizeBlocks = GptEntry.EndingLba - GptEntry.StartingLba + 1;
91
92 /* Convert GPT entry to standard-style entry */
93 PartitionEntry->StartingOffset.QuadPart = (GptEntry.StartingLba * SectorSize);
94 PartitionEntry->PartitionLength.QuadPart = (PartitionSizeBlocks * SectorSize);
95 PartitionEntry->HiddenSectors = 0;
96 PartitionEntry->PartitionNumber = PartitionNumber;
97 PartitionEntry->PartitionType = PARTITION_GPT; /* Mark as GPT partition */
98 PartitionEntry->BootIndicator = RtlEqualMemory(&GptEntry.PartitionTypeGuid, &SystemGuid, sizeof(SystemGuid));
99 PartitionEntry->RecognizedPartition = TRUE;
100 PartitionEntry->RewritePartition = FALSE;
101
102 return TRUE;
103}
#define DiskReadBuffer
Definition: hardware.h:33
#define MachDiskReadLogicalSectors(Drive, Start, Count, Buf)
Definition: machine.h:120
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define RtlEqualMemory(dst, src, len)
Definition: kdvm.h:18
if(dx< 0)
Definition: linetemp.h:194
#define ASSERT(a)
Definition: mode.c:44
BOOLEAN DiskReadGptHeader(_In_ UCHAR DriveNumber, _Out_ PGPT_TABLE_HEADER GptHeader)
Definition: part_gpt.c:22
#define EFI_PART_TYPE_EFI_SYSTEM_PART_GUID
Definition: part_gpt.h:23
#define EFI_PART_TYPE_UNUSED_GUID
Definition: part_gpt.h:20
#define PARTITION_GPT
Definition: part_gpt.h:27
Definition: part_gpt.h:54
UINT64 EndingLba
Definition: part_gpt.h:58
UINT64 StartingLba
Definition: part_gpt.h:57
GUID PartitionTypeGuid
Definition: part_gpt.h:55
UINT32 NumberOfPartitionEntries
Definition: part_gpt.h:46
UINT32 SizeOfPartitionEntry
Definition: part_gpt.h:47
UINT64 PartitionEntryLba
Definition: part_gpt.h:45
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
_In_ ULONG SectorSize
Definition: halfuncs.h:291
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2061

Referenced by DiskGetPartitionEntry().

◆ DiskReadGptHeader()

BOOLEAN DiskReadGptHeader ( _In_ UCHAR  DriveNumber,
_Out_ PGPT_TABLE_HEADER  GptHeader 
)

Definition at line 22 of file part_gpt.c.

25{
26 /* Read GPT header (1 sector) from LBA 1 */
28 return FALSE;
29 RtlCopyMemory(GptHeader, DiskReadBuffer, sizeof(*GptHeader));
30
31 /* Verify GPT signature */
32 if (!RtlEqualMemory(GptHeader->Signature, EFI_PARTITION_HEADER_SIGNATURE, 8))
33 return FALSE;
34
35 /* Verify revision */
36 if (GptHeader->Revision != EFI_TABLE_REVISION)
37 {
38 TRACE("GPT header has unsupported revision: 0x%x\n", GptHeader->Revision);
39 return FALSE;
40 }
41
42 return TRUE;
43}
#define EFI_PARTITION_HEADER_SIGNATURE
Definition: part_gpt.h:11
#define EFI_TABLE_REVISION
Definition: part_gpt.h:13
#define EFI_HEADER_LOCATION
Definition: part_gpt.h:12
#define TRACE(s)
Definition: solgame.cpp:4

Referenced by DiskDetectPartitionType(), DiskGetGptPartitionEntry(), DiskInitialize(), and UefiGetBootPartitionEntry().