ApplePartitionMapReader 1.0.1

dotnet add package ApplePartitionMapReader --version 1.0.1
                    
NuGet\Install-Package ApplePartitionMapReader -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ApplePartitionMapReader" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ApplePartitionMapReader" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="ApplePartitionMapReader" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ApplePartitionMapReader --version 1.0.1
                    
#r "nuget: ApplePartitionMapReader, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ApplePartitionMapReader@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ApplePartitionMapReader&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=ApplePartitionMapReader&version=1.0.1
                    
Install as a Cake Tool

ApplePartitionMapReader

ApplePartitionMapReader is a lightweight .NET library for reading Apple Partition Maps from classic Macintosh disk images. It provides a simple, zero-allocation API to detect partition maps, enumerate partitions, and access partition metadata.


Features

  • Detect Apple Partition Maps in disk images
  • Enumerate all partitions with detailed metadata
  • Access partition properties: name, type, start block, block count, status flags
  • Strongly-typed status flags with ApplePartitionMapStatus enum
  • Zero-allocation API using struct enumerators and span-based operations
  • High-performance parsing using stack-allocated buffers

Installation

Install from NuGet:

dotnet add package ApplePartitionMapReader

Or reference the project directly:

dotnet add reference ../src/ApplePartitionMapReader.csproj

Quick Start Example

using ApplePartitionMapReader;

// Open a disk image containing an Apple Partition Map
using var stream = File.OpenRead("disk.iso");

// Check if the stream contains an Apple Partition Map
if (ApplePartitionMap.IsApplePartitionMap(stream, 0))
{
    var map = new ApplePartitionMap(stream, 0);
    
    // Enumerate all partitions (zero allocation)
    foreach (var partition in map)
    {
        Console.WriteLine($"Name: {partition.Name}");
        Console.WriteLine($"Type: {partition.Type}");
        Console.WriteLine($"Start: {partition.PartitionStartBlock}");
        Console.WriteLine($"Size: {partition.PartitionBlockCount} blocks");
        Console.WriteLine($"Status: {partition.StatusFlags}");
        Console.WriteLine();
    }
    
    // Or access by index
    var firstPartition = map[0];
    Console.WriteLine($"First partition: {firstPartition.Name}");
}

Zero-Allocation API

The library is designed for high-performance scenarios with zero heap allocations on the hot path:

Zero-Allocation Enumeration

// The foreach loop uses a struct enumerator - no allocation!
foreach (var partition in map)
{
    // Process partition
}

// Get count without enumerating
int count = map.EntryCount;

Zero-Allocation String Formatting

String16 and String32 types support span-based formatting to avoid string allocations:

Span<char> buffer = stackalloc char[32];
if (partition.Name.TryFormat(buffer, out int charsWritten))
{
    ReadOnlySpan<char> name = buffer[..charsWritten];
    // Use name without allocation
}

// Get length without allocating
int length = partition.Name.Length;

Zero-Allocation String Comparison

Compare partition names/types directly without allocating strings:

// Compare with a string span - no allocation
if (partition.Type.Equals("Apple_HFS".AsSpan()))
{
    // Handle HFS partition
}

// Compare with ASCII bytes
if (partition.Type.Equals("Apple_HFS"u8))
{
    // Handle HFS partition
}

Zero-Allocation Driver Descriptor Map Access

// Use TryGet pattern to avoid nullable struct boxing
if (map.TryGetDriverDescriptorMap(out var ddm))
{
    Console.WriteLine($"Block size: {ddm.BlockSize}");
}

API Overview

ApplePartitionMap

Member Description
ApplePartitionMap(Stream, int) Constructs a partition map reader from a seekable, readable stream at the specified offset
static bool IsApplePartitionMap(Stream, int) Checks if the stream contains a valid Apple Partition Map at the given offset
int EntryCount Gets the number of partition entries in the map
Enumerator GetEnumerator() Returns a struct enumerator for zero-allocation foreach support
ApplePartitionMapEntry this[int] Gets the partition entry at the specified index
DriverDescriptorMap? DriverDescriptorMap Gets the driver descriptor map, or null if the block is blank
bool TryGetDriverDescriptorMap(out DriverDescriptorMap) Zero-allocation alternative to get the driver descriptor map

ApplePartitionMapEntry

Represents a single partition in the map with the following properties:

Property Type Description
Signature ushort Partition signature (0x504D = 'PM')
MapEntryCount uint Total number of entries in the partition map
Name String32 Partition name
Type String32 Partition type (e.g., Apple_HFS, Apple_Driver)
PartitionStartBlock uint First block of the partition
PartitionBlockCount uint Number of blocks in the partition
DataStartBlock uint First logical block of data area
DataBlockCount uint Number of blocks in data area
StatusFlags ApplePartitionMapStatus Partition status flags
BootCodeStartBlock uint First logical block of boot code
BootCodeBlockCount uint Size of boot code in bytes
BootCodeAddress uint Boot code load address
BootCodeEntryPoint uint Boot code entry point
BootCodeChecksum uint Boot code checksum
ProcessorType String16 Processor type (e.g., "68000")

String16 / String32

Fixed-size string types with zero-allocation APIs:

Member Description
int Length Gets the string length (excluding null terminator)
bool TryFormat(Span<char>, out int) Formats the string into a span without allocation
bool Equals(ReadOnlySpan<char>) Compares with a character span without allocation
bool Equals(ReadOnlySpan<byte>) Compares with ASCII bytes without allocation
ReadOnlySpan<byte> AsReadOnlySpan() Gets the raw bytes without copying
string ToString() Converts to a string (allocates)
implicit operator string Implicit conversion to string (allocates)

ApplePartitionMapStatus

Flags enum representing partition status:

Flag Value Description
Valid 0x00000001 Entry is valid
Allocated 0x00000002 Entry is allocated
InUse 0x00000004 Entry in use
Bootable 0x00000008 Contains boot information
Readable 0x00000010 Partition is readable
Writable 0x00000020 Partition is writable
BootCodePositionIndependent 0x00000040 Boot code is position independent
OSSpecific1 0x00000080 OS-specific flag
ChainCompatibleDriver 0x00000100 Contains chain-compatible driver
RealDriver 0x00000200 Contains a real driver
ChainDriver 0x00000400 Contains a chain driver
AutoMount 0x40000000 Automatically mount at startup
StartupPartition 0x80000000 The startup partition

Common Partition Types

Type Description
Apple_partition_map The partition map itself
Apple_Driver Device driver partition
Apple_Driver43 SCSI driver partition
Apple_HFS HFS filesystem partition
Apple_Free Free/unused space
Apple_Scratch Scratch partition

License

MIT License - see LICENSE for details.

Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 89 2/4/2026
1.0.0 89 2/3/2026