FirmwareKit.PartitionTable
1.0.0
dotnet add package FirmwareKit.PartitionTable --version 1.0.0
NuGet\Install-Package FirmwareKit.PartitionTable -Version 1.0.0
<PackageReference Include="FirmwareKit.PartitionTable" Version="1.0.0" />
<PackageVersion Include="FirmwareKit.PartitionTable" Version="1.0.0" />
<PackageReference Include="FirmwareKit.PartitionTable" />
paket add FirmwareKit.PartitionTable --version 1.0.0
#r "nuget: FirmwareKit.PartitionTable, 1.0.0"
#:package FirmwareKit.PartitionTable@1.0.0
#addin nuget:?package=FirmwareKit.PartitionTable&version=1.0.0
#tool nuget:?package=FirmwareKit.PartitionTable&version=1.0.0
FirmwareKit.PartitionTable
A .NET partition table library for reading, parsing, editing, serializing, deserializing, and saving MBR, GPT, and Amlogic EPT partition tables.
Features
- Detects Amlogic EPT, MBR, and GPT partition tables from a seekable stream or file.
- Auto-detects common GPT sector sizes (512/1024/2048/4096/8192).
- Supports editable and read-only table instances.
- Preserves stream position after parsing.
- Provides diagnostics for CRC/checksum, bounds, overlap, and hybrid MBR warnings.
- Supports conservative GPT CRC refresh/repair workflows.
- Supports high-level operation helpers (alignment and dry-run write planning).
- Supports table diffing and structured comparison reports.
- Supports advanced read options (strict sector-size and custom probe sizes).
- Supports async read APIs for service and UI scenarios.
- Supports JSON manifest import/export and manifest-to-table reconstruction via the optional
FirmwareKit.PartitionTable.Jsonpackage. - Supports atomic file writes with confirmation token.
- Uses
Crc32.NETfor CRC-32 calculation. - Targets
netstandard2.0,net8.0, andnet10.0.
Projects
FirmwareKit.PartitionTable- core library.FirmwareKit.PartitionTable.Json- optional JSON manifest extension package.FirmwareKit.PartitionTable.Cli- sample command-line tool.FirmwareKit.PartitionTable.Tests- xUnit test project.
Usage
using System.IO;
using FirmwareKit.PartitionTable;
using var stream = File.OpenRead("disk.img");
IPartitionTable table = PartitionTableReader.FromStream(stream, mutable: true);
// Optional: specify sector size explicitly when working with uncommon images.
IPartitionTable tableWithSector = PartitionTableReader.FromStream(stream, mutable: false, sectorSize: 8192);
// Optional: strict probing and custom sector list.
var options = new PartitionReadOptions
{
PreferredSectorSize = 4096,
StrictSectorSize = true,
ProbeSectorSizes = new[] { 4096, 8192 }
};
IPartitionTable strictTable = PartitionTableReader.FromStream(stream, mutable: false, options: options);
Diagnostics and repair:
var report = PartitionTableDiagnostics.Analyze(table);
if (!report.IsHealthy)
{
using var rw = File.Open("disk.img", FileMode.Open, FileAccess.ReadWrite, FileShare.None);
PartitionRepairResult repair = PartitionTableRepair.RepairGptCrcInPlace(rw, sectorSize: 4096);
}
Validate, repair, and diff tables:
PartitionDiagnosticsReport diagnostics = PartitionTableDiagnostics.Analyze(table);
PartitionRepairResult repaired = PartitionTableRepair.RepairAnyInPlace(File.Open("disk.img", FileMode.Open, FileAccess.ReadWrite, FileShare.None));
PartitionTableDiff diff = PartitionTableOperations.Compare(leftTable, rightTable);
Manifest interoperability:
// Requires the FirmwareKit.PartitionTable.Json package.
string json = PartitionTableManifestSerializer.ExportToJson(table);
PartitionTableManifest manifest = PartitionTableManifestSerializer.ImportFromJson(json);
IPartitionTable rebuilt = PartitionTableManifestSerializer.ToPartitionTable(manifest);
Handle Amlogic EPT tables:
using var reserved = File.OpenRead("reserved-partition.img");
IPartitionTable table = PartitionTableReader.FromStream(reserved, mutable: false);
if (table is AmlogicPartitionTable ept)
{
Console.WriteLine($"EPT checksum valid: {ept.IsChecksumValid}");
foreach (var part in ept.Partitions)
{
Console.WriteLine($"{part.Name}: offset=0x{part.Offset:X}, size=0x{part.Size:X}, mask={part.MaskFlags}");
}
}
Safety write:
PartitionTableWriter.WriteToFileAtomic(
table,
"disk-fixed.img",
requireConfirmation: true,
confirmation: "I_UNDERSTAND_PARTITION_WRITE");
CLI usage:
dotnet run --project FirmwareKit.PartitionTable.Cli -- read disk.img --sector-size 8192
dotnet run --project FirmwareKit.PartitionTable.Cli -- read disk.img --json
dotnet run --project FirmwareKit.PartitionTable.Cli -- write in.img out.img --sector-size 4096 --dry-run
dotnet run --project FirmwareKit.PartitionTable.Cli -- validate disk.img --sector-size 4096
dotnet run --project FirmwareKit.PartitionTable.Cli -- repair disk.img --sector-size 4096
dotnet run --project FirmwareKit.PartitionTable.Cli -- diff left.img right.img --json
dotnet run --project FirmwareKit.PartitionTable.Cli -- export disk.img manifest.json --sector-size 4096
dotnet run --project FirmwareKit.PartitionTable.Cli -- import manifest.json disk.img --keep-backup
Testing
The test project includes generated GPT fixtures and script-driven sample generation.
Run the test suite:
dotnet test FirmwareKit.PartitionTable.Tests/FirmwareKit.PartitionTable.Tests.csproj
Test data generation
Use the PowerShell script under scripts/Generate-TestData.ps1 to regenerate the GPT fixture used by the tests.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
NuGet packages (1)
Showing the top 1 NuGet packages that depend on FirmwareKit.PartitionTable:
| Package | Downloads |
|---|---|
|
FirmwareKit.PartitionTable.Json
JSON manifest import/export extensions for FirmwareKit.PartitionTable. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 145 | 4/27/2026 |