What's New / Storage, System & Virtualization

What's new in DiskImageKit

+23 NewmacOS

DiskImageKit is Apple's framework for creating, opening, and inspecting disk images, including ASIF and RAW formats. It exposes disk image metadata such as format and block size, plus creation configurations and error types for corrupted or unsupported images.

The 27 SDK adds 23 APIs and deprecates or removes none. New types include the creation configurations ASIFCreationConfiguration, ASIFLayerCreationConfiguration, and RAWCreationConfiguration, the OpenConfiguration type and OpenConfigurationProtocol, the StackedImage protocol, and the error types CorruptedImageError, IncompatibleStackingError, InvalidBlockCountError, and UnsupportedFormatError. DiskImage gains Format, BlockSize, and CreationConfiguration members, plus BlockSize.AllCases and BlockSize.RawValue.

New

23
struct

ASIFCreationConfiguration

NewmacOS
public struct ASIFCreationConfiguration : DiskImage.CreationConfiguration

The configuration to use to create Apple sparse image format (ASIF) disk images.

Declaration
public struct ASIFCreationConfiguration : DiskImage.CreationConfiguration {

    /// Creates a configuration object for a new Apple sparse image format (ASIF) disk image layer.
    ///
    /// Use this factory method to create a configuration that can be used with ``DiskImage/appending(_:)-3pfqg``.
    /// Use the configuration this method returns only for appending to stacked images, not for standalone image creation.
    ///
    /// For more information on ASIF layer creation for stacked images, see ``DiskImage/CreationConfiguration/asifLayer(url:type:)`` .
    ///
    /// - Parameters:
    ///   - url: The <doc://com.apple.documentation/documentation/foundation/url> for a file that's the backing store of the image.
    ///   - type: The ``DiskImage/LayerType`` of the layer to create (a cache or overlay layer with an optional block count).
    /// - Returns: An ``ASIFLayerCreationConfiguration`` that you can use` for stacking operations.
    public static func layer(url: URL, type: DiskImage.LayerType) -> ASIFLayerCreationConfiguration
}
struct

ASIFLayerCreationConfiguration

NewmacOS
public struct ASIFLayerCreationConfiguration : DiskImage.CreationConfiguration, DiskImage.StackableLayer

The configuration to use to create Apple sparse image format (ASIF) disk image layers in stacked images.

This type is returned by asifLayer(url:type:) and can only be used with stacking operations like appending(_:)-(CreationConfiguration&StackableLayer).

Declaration
public struct ASIFLayerCreationConfiguration : DiskImage.CreationConfiguration, DiskImage.StackableLayer {
}
struct

CorruptedImageError

NewmacOS
public struct CorruptedImageError : Error, LocalizedError

The disk image is corrupted or contains invalid data.

Declaration
public struct CorruptedImageError : Error, LocalizedError {

    /// The underlying error with additional diagnostic details.
    public let underlyingError: any Error

    /// A localized message describing what error occurred.
    public var errorDescription: String? { get }
}
extension

DiskImage.BlockSize

NewmacOS
extension DiskImage.BlockSize : Equatable
Declaration
extension DiskImage.BlockSize : Equatable {
}
extension

DiskImage.BlockSize

NewmacOS
extension DiskImage.BlockSize : Hashable
Declaration
extension DiskImage.BlockSize : Hashable {
}
extension

DiskImage.BlockSize

NewmacOS
extension DiskImage.BlockSize : RawRepresentable
Declaration
extension DiskImage.BlockSize : RawRepresentable {
}
extension

DiskImage.CreationConfiguration

NewmacOS
extension DiskImage.CreationConfiguration where Self == ASIFCreationConfiguration
Declaration
extension DiskImage.CreationConfiguration where Self == ASIFCreationConfiguration {

    /// Returns an Apple sparse image format (ASIF) configuration for standalone or base images.
    ///
    /// Use this initializer when creating a standalone image, or a base image for a stack, using ``DiskImage/init(creating:)``.
    /// To create a cache or overlay layer for a stacked disk image, use ``DiskImage/CreationConfiguration/asifLayer(url:type:)`` instead.
    ///
    /// The following example demonstrates how to create a ASIF disk image:
    /// ```
    /// _ = try DiskImage(creating: .asif(url: imageURL, blockCount: blockCount, blockSize: .bytes512))
    /// ```
    ///
    /// - Parameters:
    ///   - url: The <doc://com.apple.documentation/documentation/foundation/url> for the disk image file.
    ///   - blockCount: Size of the disk image in blocks.
    ///   - blockSize: The ``DiskImage/BlockSize`` to use.
    /// - Returns: An ``ASIFCreationConfiguration`` instance for standalone use.
    public static func asif(url: URL, blockCount: Int, blockSize: DiskImage.BlockSize) -> Self
}
extension

DiskImage.CreationConfiguration

NewmacOS
extension DiskImage.CreationConfiguration where Self == ASIFLayerCreationConfiguration
Declaration
extension DiskImage.CreationConfiguration where Self == ASIFLayerCreationConfiguration {

    /// Returns an Apple sparse image format (ASIF) configuration for stackable layers.
    ///
    /// The following example demonstrates how to append a new cache layer to a base image:
    /// ```
    /// var stackedImage = try baseImage.appending(.asifLayer(url: cacheURL, type: .cache))
    /// ```
    ///
    /// - Parameters:
    ///   - url: The <doc://com.apple.documentation/documentation/foundation/url> for the disk image file.
    ///   - type: The type of layer (cache or overlay).
    /// - Returns: An ``ASIFLayerCreationConfiguration`` instance for stacking use.
    public static func asifLayer(url: URL, type: DiskImage.LayerType) -> Self
}
extension

DiskImage.CreationConfiguration

NewmacOS
extension DiskImage.CreationConfiguration where Self == RAWCreationConfiguration
Declaration
extension DiskImage.CreationConfiguration where Self == RAWCreationConfiguration {

    /// Returns a RAW configuration for standalone or base images.
    ///
    /// The framework only supports the 512-byte block size for RAW images.
    ///
    /// The following example demonstrates how to create a RAW disk image.
    /// ```
    /// _ = try DiskImage(creating: .raw(url: imageURL, blockCount: blockCount))
    /// ```
    ///
    /// - Parameters:
    ///   - url: The <doc://com.apple.documentation/documentation/foundation/url> for the disk image file.
    ///   - blockCount: Size of the disk image in blocks.
    /// - Returns: A ``RAWCreationConfiguration`` instance.
    public static func raw(url: URL, blockCount: Int) -> Self
}
extension

DiskImage.Format

NewmacOS
extension DiskImage.Format : Equatable
Declaration
extension DiskImage.Format : Equatable {
}
extension

DiskImage.Format

NewmacOS
extension DiskImage.Format : Hashable
Declaration
extension DiskImage.Format : Hashable {
}
struct

IncompatibleStackingError

NewmacOS
public struct IncompatibleStackingError : Error, LocalizedError

The appended layer isn't compatible with the existing stack.

Declaration
public struct IncompatibleStackingError : Error, LocalizedError {

    /// A description of why the stacking operation failed.
    public let reason: String

    /// A localized message describing what error occurred.
    public var errorDescription: String? { get }
}
struct

InvalidBlockCountError

NewmacOS
public struct InvalidBlockCountError : Error, LocalizedError

The block count specified for the disk image is invalid (zero or negative).

Declaration
public struct InvalidBlockCountError : Error, LocalizedError {

    /// A localized message describing what error occurred.
    public var errorDescription: String? { get }
}
struct

OpenConfiguration

NewmacOS
public struct OpenConfiguration : OpenConfigurationProtocol

A configuration to use for opening existing disk images.

Declaration
public struct OpenConfiguration : OpenConfigurationProtocol {

    /// Open modes for disk images.
    public enum Mode {

        /// Try to open the disk image as read-write, and fallback to read-only if there's no read-write access.
        case automatic

        /// Open the disk image in read-only mode.
        ///
        /// Use this mode when opening the base image of a stacked disk image.
        case readOnly

        /// Open the disk-image with read-write permissions.
        ///
        /// Fails if there's no permission to open the image in this mode.
        case readWrite

        /// Returns a Boolean value indicating whether two values are equal.
        ///
        /// Equality is the inverse of inequality. For any values `a` and `b`,
        /// `a == b` implies that `a != b` is `false`.
        ///
        /// - Parameters:
        ///   - lhs: A value to compare.
        ///   - rhs: Another value to compare.
        public static func == (a: OpenConfiguration.Mode, b: OpenConfiguration.Mode) -> Bool

        /// Hashes the essential components of this value by feeding them into the
        /// given hasher.
        ///
        /// Implement this method to conform to the `Hashable` protocol. The
        /// components used for hashing must be the same as the components compared
        /// in your type's `==` operator implementation. Call `hasher.combine(_:)`
        /// with each of these components.
        ///
        /// - Important: In your implementation of `hash(into:)`,
        ///   don't call `finalize()` on the `hasher` instance provided,
        ///   or replace it with a different instance.
        ///   Doing so may become a compile-time error in the future.
        ///
        /// - Parameter hasher: The hasher to use when combining the components
        ///   of this instance.
        public func hash(into hasher: inout Hasher)

        /// The hash value.
        ///
        /// Hash values are not guaranteed to be equal across different executions of
        /// your program. Do not save hash values to use during a future execution.
        ///
        /// - Important: `hashValue` is deprecated as a `Hashable` requirement. To
        ///   conform to `Hashable`, implement the `hash(into:)` requirement instead.
        ///   The compiler provides an implementation for `hashValue` for you.
        public var hashValue: Int { get }
    }

    /// The URL of the disk image to open.
    public let url: URL

    /// The mode in which to open the disk image.
    public let mode: OpenConfiguration.Mode

    /// Creates a configuration for opening a disk image.
    ///
    /// - Parameters:
    ///   - url: The <doc://com.apple.documentation/documentation/foundation/url> of the disk image file to open.
    ///   - mode: The mode in which to open the image (read-only or read-write).
    public init(url: URL, mode: OpenConfiguration.Mode = .automatic)
}
extension

OpenConfiguration.Mode

NewmacOS
extension OpenConfiguration.Mode : Equatable
Declaration
extension OpenConfiguration.Mode : Equatable {
}
extension

OpenConfiguration.Mode

NewmacOS
extension OpenConfiguration.Mode : Hashable
Declaration
extension OpenConfiguration.Mode : Hashable {
}
protocol

OpenConfigurationProtocol

NewmacOS
public protocol OpenConfigurationProtocol

The protocol for disk image open configurations.

This protocol defines the common requirements for opening disk images. Conforming types can be used with init(opening:).

Declaration
public protocol OpenConfigurationProtocol {

    /// The URL of the disk image to open.
    var url: URL { get }

    /// The ``OpenConfiguration/Mode`` in which to open the disk image.
    var mode: OpenConfiguration.Mode { get }
}
extension

OpenConfigurationProtocol

NewmacOS
extension OpenConfigurationProtocol where Self == OpenConfiguration
Declaration
extension OpenConfigurationProtocol where Self == OpenConfiguration {

    /// Returns a configuration to use for opening a disk image.
    ///
    /// The following example demonstrates how to open a disk image.
    /// ```
    /// let image = try DiskImage(opening: .open(url: imageURL))
    /// ```
    ///
    /// - Parameters:
    ///   - url: A <doc://com.apple.documentation/documentation/foundation/url>  of the disk image file to open.
    ///   - mode: Mode in which to open the image (read-only or read-write).
    /// - Returns: An ``OpenConfiguration`` instance.
    public static func open(url: URL, mode: OpenConfiguration.Mode = .automatic) -> Self
}
struct

RAWCreationConfiguration

NewmacOS
public struct RAWCreationConfiguration : DiskImage.CreationConfiguration

The configuration to use to create RAW disk images.

Declaration
public struct RAWCreationConfiguration : DiskImage.CreationConfiguration {
}
protocol

StackedImage

NewmacOS
public protocol StackedImage : DiskImage

The protocol for stacked disk images that contain multiple layers.

A stacked disk image combines multiple layers into a single logical disk image. The first layer (the bottom of the stack) is the base layer, and subsequent layers are either cache or overlay layers that modify or cache the layers beneath.

The following example demonstrates how to create a stacked image.

let baseImage = try DiskImage(opening: .open(url: baseImageURL))
var stackedImage = try baseImage.appending(.asifLayer(url: cacheURL, type: .cache))
stackedImage = try stackedImage.appending(.asifLayer(url: shadowURL, type: .overlay))
Declaration
public protocol StackedImage : DiskImage {

    /// An array of all layers in the stack, from base (index 0) to top.
    var layers: [DiskImage] { get }
}
struct

UnsupportedFormatError

NewmacOS
public struct UnsupportedFormatError : Error, LocalizedError

The disk image format isn't supported.

Declaration
public struct UnsupportedFormatError : Error, LocalizedError {

    /// The underlying error with additional diagnostic details.
    public let underlyingError: any Error

    /// A localized message describing what error occurred.
    public var errorDescription: String? { get }
}
typealias

BlockSize.AllCases

NewmacOS
public typealias AllCases = [DiskImage.BlockSize]

A type that can represent a collection of all values of this type.

typealias

BlockSize.RawValue

NewmacOS
public typealias RawValue = Int

The raw type that can be used to represent all values of the conforming type.

Every distinct value of the conforming type has a corresponding unique value of the RawValue type, but there may be values of the RawValue type that don't have a corresponding value of the conforming type.

No APIs match your filter.

← More in Storage, System & Virtualization