Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Rikitav/Unified.Firmware/llms.txt

Use this file to discover all available pages before exploring further.

Media device path protocols describe partitions and file paths on storage media. They correspond to the Media Device Path type (0x04) in the UEFI specification and are the nodes that UEFI firmware consults when locating the EFI application to load. In almost every modern boot entry you will find a HardDriveProtocol node that identifies the target GPT partition, immediately followed by a FilePathProtocol node that names the .efi binary — together they give firmware everything it needs to find and launch a bootloader. Package: Unified.Firmware.DevicePathProtocols.Media Namespace: Unified.Firmware.BootService.Protocols

HardDriveProtocol

Represents a partition on a fixed disk. It stores the partition’s entry number, LBA offsets, GPT signature GUID, and the format/signature-type metadata that firmware needs to validate the target partition before handing control to the bootloader.
[DefineDevicePathProtocol(DeviceProtocolType.Media, 1)]
public class HardDriveProtocol() : DevicePathProtocolBase(DeviceProtocolType.Media, 1)

Constructors

// Parameterless — properties populated after construction or via Deserialize
HardDriveProtocol()

// Looks up partition geometry from the OS using the partition GUID
HardDriveProtocol(Guid partitionIdentificator)

// Constructs from a Win32 PARTITION_INFORMATION_EX struct (GPT only)
HardDriveProtocol(PARTITION_INFORMATION_EX partition)
Both convenience constructors require the partition to be GPT-formatted. Passing an MBR or RAW partition to HardDriveProtocol(PARTITION_INFORMATION_EX) throws InvalidDataException. Passing Guid.Empty to the GUID constructor throws ArgumentException.

Properties

PropertyTypeDescription
PartitionNumberuint1-based entry index in the partition table. 0 represents the whole disk.
PartitionStartulongStarting offset of the partition in bytes (converted from LBA on serialization).
PartitionSizeulongSize of the partition in bytes (converted from LBA on serialization).
GptPartitionSignatureGuidThe GPT partition GUID that uniquely identifies this partition.
PartitionFormatPartitionFormatWhether the disk uses MBR or GPT layout.
SignatureTypeSignatureTypeThe kind of disk signature carried in this node.

PartitionFormat Enum

public enum PartitionFormat : byte
{
    LegacyMBR         = 0x01,  // PC-AT compatible Master Boot Record
    GuidPartitionTable = 0x02   // GUID Partition Table (GPT)
}

SignatureType Enum

public enum SignatureType : byte
{
    NoDiskSignature = 0x00,  // No signature present
    MbrSignature    = 0x01,  // 32-bit MBR signature at offset 0x1B8
    GuidSignature   = 0x02   // 128-bit GPT GUID signature
}

Serialization

GetSerializationDataLength() returns 38 bytes:
FieldSize
PartitionNumber4 bytes (uint)
PartitionStart8 bytes (ulong, stored as LBA = bytes ÷ 512)
PartitionSize8 bytes (ulong, stored as LBA = bytes ÷ 512)
GptPartitionSignature16 bytes (GUID)
PartitionFormat1 byte
SignatureType1 byte
PartitionStart and PartitionSize are stored in the binary format as logical block addresses (512-byte sectors). The library automatically multiplies by 512 on read and divides by 512 on write, so all managed property values are in bytes.

ToString

Returns GptPartitionSignature.ToString() — the canonical GUID string of the partition (e.g., "a1b2c3d4-e5f6-7890-abcd-ef1234567890").

Example

using Unified.Firmware.BootService.Protocols;

// Construct from a known partition GUID — the library queries
// the OS to fill in partition number, LBA offsets, and format fields.
var hardDrive = new HardDriveProtocol(
    new Guid("a1b2c3d4-e5f6-7890-abcd-ef1234567890")
);

Console.WriteLine(hardDrive.PartitionFormat); // GuidPartitionTable
Console.WriteLine(hardDrive.SignatureType);   // GuidSignature
Console.WriteLine(hardDrive);                 // a1b2c3d4-e5f6-7890-abcd-ef1234567890

FilePathProtocol

Holds a null-terminated Unicode path to an EFI application or directory. This is the node that names the bootloader binary (e.g., \EFI\ubuntu\grubx64.efi) within the partition identified by the preceding HardDriveProtocol node.
[DefineDevicePathProtocol(DeviceProtocolType.Media, 4)]
public sealed class FilePathProtocol() : DevicePathProtocolBase(DeviceProtocolType.Media, 4)

Constructors

// Parameterless — set PathName after construction
FilePathProtocol()

// Convenience constructor
FilePathProtocol(string pathName)

Properties

PropertyTypeDescription
PathNamestringNull-terminated Unicode path string, including directory and file name.

Serialization

GetSerializationDataLength() returns the byte length of PathName encoded as a C-style wide string (UTF-16 LE with a two-byte null terminator). The serialized size is therefore (PathName.Length + 1) * 2 bytes.

ToString

Returns PathName directly.

Example

using Unified.Firmware.BootService.Protocols;

var filePath = new FilePathProtocol(@"EFI\Ubuntu\grubx64.efi");

Console.WriteLine(filePath);
// Output: EFI\Ubuntu\grubx64.efi
UEFI path separators are backslashes (\), not forward slashes. Use verbatim string literals (@"...") or escape your backslashes to avoid confusion.

CdRomProtocol

Describes a system partition that resides on an ISO-9660 CD-ROM following the El Torito boot specification. The boot entry number references the specific bootable entity in the El Torito Boot Catalog, which points to an EFI System Partition on the disc.
[DefineDevicePathProtocol(DeviceProtocolType.Media, 2)]
public sealed class CdRomProtocol() : DevicePathProtocolBase(DeviceProtocolType.Media, 2)

Constructors

// Parameterless — properties set after construction
CdRomProtocol()

// Convenience constructor
CdRomProtocol(uint bootEntry, ulong partitionStart, ulong partitionSize)

Properties

PropertyTypeDescription
BootEntryuintBoot Catalog entry number. 0 is the Initial/Default boot entry.
PartitionStartulongStarting Relative Logical Block Address (RBA) of the partition.
PartitionSizeulongSize of the partition in blocks (sectors).

Serialization

GetSerializationDataLength() returns 20 bytes:
FieldSize
BootEntry4 bytes (uint)
PartitionStart8 bytes (ulong)
PartitionSize8 bytes (ulong)

ToString

Returns BootEntry.ToString().

Example

using Unified.Firmware.BootService.Protocols;

// Default boot entry, spanning the entire partition starting at RBA 16
var cdRom = new CdRomProtocol(
    bootEntry:      0,
    partitionStart: 16,
    partitionSize:  300000
);

Console.WriteLine(cdRom);
// Output: 0

VendorDefinedProtocol

Carries a vendor-assigned GUID and an arbitrary byte payload in a media device path node. Use this when no standard media sub-type describes the required partition or media abstraction. The library round-trips the payload verbatim during serialization.
[DefineDevicePathProtocol(DeviceProtocolType.Media, 3)]
public class VendorDefinedProtocol() : DevicePathProtocolBase(DeviceProtocolType.Media, 3)

Constructors

// Parameterless — properties set after construction
VendorDefinedProtocol()

Properties

PropertyTypeDescription
VendorGuidGuidVendor-assigned GUID that defines the format of the data that follows.
VendorDefinedDatabyte[]Variable-length opaque vendor payload. Defaults to an empty array.

Serialization

GetSerializationDataLength() returns 16 + VendorDefinedData.Length bytes. The GUID is written as a 16-byte value, followed by the raw vendor payload.

ToString

Returns VendorGuid.ToString().

Example

using Unified.Firmware.BootService.Protocols;

var vendor = new VendorDefinedProtocol
{
    VendorGuid        = new Guid("c12a7328-f81f-11d2-ba4b-00a0c93ec93b"),
    VendorDefinedData = new byte[] { 0x01, 0x00, 0x00, 0x00 }
};

Console.WriteLine(vendor);
// Output: c12a7328-f81f-11d2-ba4b-00a0c93ec93b

MediaDeviceProtocolType Enum

MediaDeviceProtocolType enumerates all sub-type values defined by the UEFI specification for media device path nodes (Type = 0x04):
public enum MediaDeviceProtocolType : byte
{
    HardDrive           = 1,  // GPT or MBR partition on a fixed disk
    CdRom               = 2,  // El Torito CD-ROM partition
    Vendor              = 3,  // Vendor-defined media node
    FilePath            = 4,  // Null-terminated Unicode file path
    Media               = 5,  // Media Protocol Device Path
    PiwgFirmwareFile    = 6,  // PI spec firmware file
    PiwgFirmwareVolume  = 7,  // PI spec firmware volume
    RelativeOffsetRange = 8,  // Byte-offset range relative to device start
    RamDisk             = 9   // Byte-offset range relative to end of device
}
The four classes documented on this page correspond to sub-type values 1, 2, 3, and 4. Sub-types 59 are defined in the specification but do not yet have dedicated protocol classes in the library; unrecognized nodes are deserialized as RawMediaDevicePath instances.

Typical Boot Entry Pattern

The canonical UEFI boot entry for a GPT-partitioned disk pairs a HardDriveProtocol node (which targets the EFI System Partition) with a FilePathProtocol node (which names the EFI application). Together they form a complete media device path:
using Unified.Firmware.BootService.Protocols;

// Partition GUID of the EFI System Partition on this machine
var partitionGuid = new Guid("a1b2c3d4-e5f6-7890-abcd-ef1234567890");

DevicePathProtocolBase[] bootPath =
[
    // Node 1 — identify the target GPT partition
    new HardDriveProtocol(partitionGuid),

    // Node 2 — path to the EFI application within that partition
    new FilePathProtocol(@"EFI\Ubuntu\grubx64.efi"),
];
A complete device path written to NVRAM also includes the hardware nodes that precede these media nodes (e.g., PciProtocol for the storage controller) and an End sentinel node after them. The media nodes shown above represent only the terminal segment of that full path.

Build docs developers (and LLMs) love