# PartitionDxe

## Function Table

| Address | Name | Description |
|---------|------|-------------|
|  | **PartitionDriverEntryPoint** |  |
|  | **PartitionDriverBindingSupported** |  |
|  | **PartitionDriverBindingStart** |  |
|  | **PartitionDriverBindingStop** |  |
|  | **PartitionBlockIoReset** |  |
|  | **PartitionReturnChildError** |  |
|  | **PartitionBlockIoReadBlocks** |  |
|  | **PartitionBlockIoWriteBlocks** |  |
|  | **PartitionBlockIoFlushBlocks** |  |
|  | **PartitionBlockIo2Reset** |  |
|  | **PartitionBlockIo2ReadWriteCommon** |  |
|  | **PartitionCreateMediaDevicePathNode** |  |
|  | **PartitionBlockIo2ReadBlocks** |  |
|  | **PartitionBlockIo2WriteBlocks** |  |
|  | **PartitionBlockIo2FlushBlocks** |  |
|  | **PartitionCreateChildHandles** |  |
|  | **PartitionComponentNameUnsupported** |  |
|  | **PartitionCheckOverlap** |  |
|  | **PartitionRegisterOverlap** |  |
|  | **PartitionUnregisterOverlap** |  |
|  | **PartitionValidMbr** |  |
|  | **PartitionInstallMbrChildHandles** |  |
|  | **PartitionInstallGptChildHandles** |  |
|  | **PartitionCheckGptTable** |  |
|  | **PartitionCheckGptEntryArrayCrc** |  |
|  | **PartitionWriteGptTable** |  |
|  | **PartitionCheckGptEntries** |  |
|  | **PartitionInstallEltChildHandles** |  |
|  | **GetSupportedLanguages** |  |
| Global | **variable definitions** |  |
| UINT64 | **ImageHandle_0    = 0;  // 0x4E40** |  |
| 0x4E48 | **EFI_HANDLE                ImageHandle      = 0;  // 0x4EC8** |  |
| 0x4EB8 | **EFI_BOOT_SERVICES        *BootServices     = NULL; // 0x4EC0** |  |
| 0x4ED0 | **UINT16                    i                = 0;   // 0x4EB0 - Index for overlap entries** |  |
| Overlap | **detection table (0x32 entries x 32 bytes = 0xA00 bytes at 0x4F00)** |  |
| UINT8 | **byte_4F00[0xA00] = {0};** |  |
| Protocol | **GUIDs** |  |
| EFI_GUID | **CLSID_PARTITION_SYSTEM_GUID = { 0xc12a7328, 0xf81f, 0x11d2, { 0xba, 0x4b, 0x00, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b } };  // 0x4DA0** |  |
| 0x4DB0 | **EFI_GUID                  Guid2                       = { 0x00000000, 0x0000, 0x0000, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } };  // 0x4EA0 (zero GUID)** |  |
| Partition | **detection function table** |  |
| Called | **in order: GPT first, then El Torito, then MBR** |  |
| PARTITION_DETECTION_FUNC | **gPartitionDetectionTable[] = {** |  |
| GPT | **partitions** |  |
| El | **Torito (CD-ROM)** |  |
| Terminator | **};** |  |
| Driver | **Binding protocol instance** |  |
| EFI_DRIVER_BINDING_PROTOCOL | **gPartitionDriverBinding = {** |  |
| Version | **NULL,           // ImageHandle** |  |
| Component | **Name 2 protocol instance** |  |
| EFI_COMPONENT_NAME2_PROTOCOL | **gPartitionComponentName2 = {** |  |
| SupportedLanguages | **(driver-specific)** |  |
| Supported | **languages table** |  |
| SUPPORTED_LANGUAGES_ENTRY | **gSupportedLanguages[] = {** |  |
| Fallback | **{ NULL, NULL }         // Terminator** |  |
| Global | **used for Component Name protocols** |  |
| CHAR8 | ***gComponentNameDriverName[] = { "eng", "en" };  // 0x3F50, 0x3F54** |  |
| Driver | **Entry Point** |  |
| ComponentName | **(not supported)** |  |
| Authentication | **status** |  |
| Driver | **Binding Protocol** |  |
| If | **a remaining device path is provided, validate it** |  |
| Must | **be NULL, end instance, or a valid hard drive media device path** |  |
| if | **(RemainingDevicePath != NULL &&** |  |
| Check | **if controller has DevicePath protocol** |  |
| Status | **= gBS->OpenProtocol(** |  |
| Check | **if controller has Block IO protocol (the primary requirement)** |  |
| Finally | **check for Component Name 2 to verify it's a full disk controller** |  |
| Save | **previous TPL and raise to TPL_CALLBACK** |  |
| RemainingDevicePathInstance | **= RemainingDevicePath;** |  |
| If | **remaining device path is an end instance, nothing to do** |  |
| if | **(RemainingDevicePath != NULL && IsDevicePathEndInstance(RemainingDevicePath)) {** |  |
| Open | **Block IO protocol** |  |
| Open | **Disk IO protocol (optional - needed for GPT backup restore)** |  |
| Open | **Device Path protocol** |  |
| Open | **Block IO2 protocol (optional)** |  |
| BlockIo2 | **= NULL;** |  |
| Get | **media info** |  |
| BlockIoMedia | **= BlockIo;** |  |
| Try | **each partition detection method** |  |
| for | **(Index = 0; gPartitionDetectionTable[Index] != NULL; Index++) {** |  |
| If | **no partitions found, clean up protocols** |  |
| if | **(DevicePath != NULL || BlockIo2 != NULL) {** |  |
| Close | **all protocols opened by Start()** |  |
| Check | **if any children still exist** |  |
| if | **(NumberOfChildren != 0) {** |  |
| Stop | **individual children** |  |
| OldTpl | **= gBS->RaiseTPL(TPL_CALLBACK);** |  |
| Get | **the Block IO protocol from child handle** |  |
| Verify | **private data signature** |  |
| Private | **= CR(BlockIo, PARTITION_PRIVATE_DATA, BlockIo, PARTITION_PRIVATE_DATA_SIGNATURE);** |  |
| Flush | **and close Block IO** |  |
| Status | **= BlockIo->FlushBlocks(BlockIo);** |  |
| Flush | **Block IO2 if available** |  |
| if | **(BlockIo2 != NULL) {** |  |
| Uninstall | **protocols from child handle** |  |
| Uninstall | **Block IO, Block IO2, Device Path, and Partition Info** |  |
| Status | **= gBS->UninstallMultipleProtocolInterfaces(** |  |
| Unregister | **overlap and free private data** |  |
| Block | **IO Protocol Implementation** |  |
| Verify | **buffer size is a multiple of block size** |  |
| if | **(BufferSize % Private->BlockSize != 0) {** |  |
| Calculate | **offset on parent device** |  |
| OffsetLba | **= Private->CachedDiskOffset + Lba * Private->BlockSize;** |  |
| Verify | **the read is within partition bounds** |  |
| if | **(OffsetLba + BufferSize > Private->CachedDiskSize) {** |  |
| Verify | **the write is within partition bounds** |  |
| Block | **IO2 Protocol Implementation** |  |
| If | **no token (synchronous) or no buffer to map, call parent directly** |  |
| if | **(Token == NULL || *Token == NULL) {** |  |
| Create | **a wrapped device path for tracking** |  |
| VOID | ***MediaDevicePath = PartitionCreateMediaDevicePathNode(Token);** |  |
| If | **no token, call parent directly** |  |
| Child | **Handle Creation** |  |
| Allocate | **private data structure (0x1A0 bytes)** |  |
| Private | **= AllocateCopyPool(sizeof(PARTITION_PRIVATE_DATA));** |  |
| Actually | **revision** |  |
| Initialize | **Block IO2 protocol if parent supports it** |  |
| if | **(ParentBlockIo2 != NULL) {** |  |
| Set | **media parameters** |  |
| Set | **Block IO2 media parameters** |  |
| Set | **LastBlock for floppy detection** |  |
| if | **(Private->BlockIo.Media->LastBlock >= 0x20000) {** |  |
| Not | **a floppy** |  |
| Build | **full device path** |  |
| AppendedDevicePath | **= AppendDevicePathInstance(DevicePath, DevicePathInstance);** |  |
| Copy | **partition info** |  |
| Set | **partition type GUID pointer** |  |
| if | **(PartitionInfo->Type == PARTITION_TYPE_MBR) {** |  |
| Install | **protocols on new child handle** |  |
| Open | **Device Path protocol on the child handle** |  |
| Component | **Name Protocol** |  |
| Overlap | **Detection** |  |
| Find | **first free entry** |  |
| for | **(Index = 0; Index < i; Index++) {** |  |
| Table | **full** |  |
| Check | **against all registered entries** |  |
| Overlap | **detected** |  |
| No | **overlap** |  |
| Find | **first free slot** |  |
| Store | **the entry** |  |
| InUse | **flag** |  |
| Search | **for matching entry** |  |
| Clear | **entry** |  |
| MBR | **Partition Support** |  |
| Check | **MBR signature** |  |
| if | **(*(UINT16*)((UINT8*)MbrBuffer + MBR_OFFSET_SIGNATURE) != MBR_SIGNATURE) {** |  |
| Offset | **of first partition entry** |  |
| Get | **start LBA and size (24-bit CHS/LBA hybrid encoding)** |  |
| StartLBA | **= PartitionEntry->StartLBA;** |  |
| Check | **for overlap with other partitions** |  |
| for | **(SubIndex = Index + 1; SubIndex < 4; SubIndex++) {** |  |
| Reads | **MBR (512 bytes), validates it, then iterates 4 primary partition entries.** |  |
| For | **each valid entry, creates a HARDDRIVE_DEVICE_PATH media node and calls** |  |
| Extended | **partitions (EBR) are recursively followed.** |  |
| Implementation | **details from disassembly (0x1CC0):** |  |
| return | **EFI_UNSUPPORTED;  // Placeholder - full implementation in decompiled output** |  |
| Reads | **primary and backup GPT headers, validates CRC, and creates** |  |
| child | **handles for each valid GPT partition entry.** |  |
| Implementation | **details from disassembly (0x227C):** |  |
| Check | **GPT signature ("EFI PART")** |  |
| if | **(Header->Signature == GPT_HEADER_SIGNATURE) {** |  |
| Validate | **CRC (clear CRC field, recalculate, compare)** |  |
| if | **(Header->HeaderSize != 0 &&** |  |
| Determine | **write location (primary or backup)** |  |
| if | **(GptHeader->MyLBA == 1) {** |  |
| Update | **header fields** |  |
| Calculate | **new CRC** |  |
| Write | **header** |  |
| EntryArraySize | **= HeaderCopy->PartitionEntryLBA * ParentBlockIoMedia->Media->BlockSize;** |  |
| Write | **partition entries** |  |
| EntryArray | **= AllocatePool(GptHeader->SizeOfPartitionEntry * GptHeader->NumberOfPartitionEntries);** |  |
| Read | **existing entries, then write to new location** |  |
| Status | **= ParentBlockIo->ReadBlocks(** |  |
| Skip | **unused entries** |  |
| if | **(!CompareGuid(&Entry->PartitionTypeGUID, &Guid2)) {** |  |
| Out | **of range** |  |
| Check | **for required partition attribute** |  |
| if | **((Entry->Attributes & 2) != 0) {** |  |
| Required | **partition** |  |
| Check | **for overlap with subsequent entries** |  |
| for | **(SubIndex = Index + 1; SubIndex < GptHeader->NumberOfPartitionEntries; SubIndex++) {** |  |
| Overlapped | **by prev** |  |
| El | **Torito (CD-ROM) Partition Support** |  |
| Implementation | **details from disassembly (0x2D84):** |  |
| Search | **through supported languages** |  |
| if | **(This->SupportedLanguages != NULL) {** |  |
| Compare | **with requested language** |  |
| if | **(CompareLangCodes(Language, (CHAR8*)This->SupportedLanguages + Index)) {** |  |
| Skip | **to next language in the list** |  |
| while | **(((CHAR8*)This->SupportedLanguages)[Index] != '\0' &&** |  |
| Find | **matching language entry in the table** |  |
| for | **(Index = 0; gSupportedLanguages[Index].LanguageString != NULL; Index += 2) {** |  |

---
*Generated by HR650X BIOS Decompilation Project*