 import Foundation
 
 typealias VolumeID = (NSCopying & NSSecureCoding & NSObjectProtocol)
+typealias DiskCallback = (Bool, String?) -> Void
 
 enum VolumeComponent: Int {
     case root = 1

    var id: VolumeID
    var name: String
    var device: String
    var size: Int
    var ejectable: Bool
    var removable: Bool

    static let keys: [URLResourceKey] = [.volumeIdentifierKey, .volumeLocalizedNameKey, .volumeTotalCapacityKey, .volumeIsEjectableKey, .volumeIsRemovableKey]
    static let set: Set<URLResourceKey> = [.volumeIdentifierKey, .volumeLocalizedNameKey, .volumeTotalCapacityKey, .volumeIsEjectableKey, .volumeIsRemovableKey]
    
    init(id: VolumeID, name: String, device: String, disk: DADisk, size: Int, ejectable: Bool, removable: Bool) {
        self.id = id
        self.name = name
        self.device = device
        self.disk = disk
        self.size = size
        self.ejectable = ejectable
        self.removable = removable
    }
    
    func unmount(callback: @escaping DiskCallback) {
        DADiskUnmount(disk, DADiskUnmountOptions(kDADiskUnmountOptionDefault), { (volume, dissenter, context) in
            
            let pointer = context?.load(as: DiskCallback.self)
            
            guard let function = pointer else {
                return
            }
            
            if let error = dissenter {
                function(false, String(describing: DADissenterGetStatusString(error)))
            } else {
                function(true, nil)
            }
            
        }, nil)
    }
    
    static func fromURL(_ url: URL) -> Volume? {
