README.md

dmg_layout #

This crate is the shared Alias-record layer for Finder metadata tooling. It:

  • reads
  • writes
  • validates

version-2 and version-3 macOS Alias records used by DMG layouts and .DS_Store pict records.

Licensed under Blue Oak.

https://mac-alias.readthedocs.io/en/latest/alias_fmt.html

Example #

use dmg_layout::{
    AliasHeader, AliasKind, AliasRecord, AliasTarget, AliasVolume, CatalogNodeId,
    DiskImageError, DiskType, ExtraEntry, FilesystemSignature, HfsTimestampSeconds,
};

fn main() -> Result<(), DiskImageError> {
    let volume = AliasVolume::new(
        b"MyDMG",
        HfsTimestampSeconds(0),
        FilesystemSignature::HIERARCHICAL_FILE_SYSTEM_PLUS,
        DiskType::Ejectable,
    )?;
    let target = AliasTarget::new(
        AliasKind::File,
        CatalogNodeId(1),
        b"background.tiff",
        CatalogNodeId(2),
        HfsTimestampSeconds(0),
    )?;
    let header = AliasHeader::new(volume, target);
    let alias = AliasRecord::new(
        header,
        vec![
            ExtraEntry::unicode_target_name("background.tiff")?,
            ExtraEntry::portable_operating_system_interface_path(
                b"/.background/background.tiff",
            )?,
        ],
    )?;
    let bytes = alias.to_bytes()?;
    assert_eq!(AliasRecord::from_bytes(&bytes)?, alias);
    Ok(())
}

Format scope #

AliasRecord is the compatibility-preserving version-2 API. AliasRecordV3 models version 3's distinct fixed header, and AliasRecordKind dispatches safely across both versions, it's what you'd want to use for a container such as the .DS_Store pict blob.

We cover all of the extra tags, and library gives typed interpretations to structural values (CNID paths, Unicode text, high-resolution HFS dates, etc.) alongside preserving byte strings and network payloads.

Unknown fields are still stored, just not interpreted.

Construction API #

Alias records are built from explicit HFS+ metadata, keeping encoding and validation independent of macOS filesystem mounts. Read volume and catalog metadata with the caller's preferred pure-Rust DMG/HFS+ reader, then pass it to AliasMetadata and AliasRecord::from_metadata.

bookmark::Data is the fully typed CoreFoundation book/alis model: it validates the prolog, TOC chain, typed values, nested references, and alignment padding. bookmark::FinderFile does the same for Finder's book/mark alias file envelope. AliasReference dispatches across either of those formats and classic Alias records without reducing the Bookmark graph to an opaque blob.

Development #

cargo test
cargo doc --no-deps

cargo test --test real_dmg

The test suite includes generated-record round trips, unknown-tag preservation, length and trailing-data rejection, non-zero padding rejection, invalid UTF-16, and metadata-built full CNID paths!