n8felton
5/4/2017 - 1:00 PM

Detect if a Mac shipped with a factory installed Apple Fusion drive

Detect if a Mac shipped with a factory installed Apple Fusion drive

#!/usr/bin/python

import objc
from Foundation import NSBundle

IOKit_bundle = NSBundle.bundleWithIdentifier_('com.apple.framework.IOKit')

functions = [("IOServiceGetMatchingServices", b"iI@o^I"),
             ("IOServiceNameMatching", b"@*"),
             ("IORegistryEntryCreateCFProperty", b"@I@@I"),
             ("IOIteratorNext", b"II"),
            ]

objc.loadBundleFunctions(IOKit_bundle, globals(), functions)

def get_io_services(service_name):
    return IOServiceGetMatchingServices(0, IOServiceNameMatching(service_name), None)

def get_io_service_properties(service_name, key_name):
    service_properties = []
    error, io_iterator_t = get_io_services(service_name)
    while True:
        io_registry_entry_t = IOIteratorNext(io_iterator_t)
        if not io_registry_entry_t:
            break
        service_properties.append(
            IORegistryEntryCreateCFProperty(io_registry_entry_t, key_name, None, 0))

    return service_properties

def get_device_characteristics():
    return get_io_service_properties("IOAHCIBlockStorageDevice", "Device Characteristics")

def is_fusion_drive():
    fusion_device_names = ['APPLE SSD', 'APPLE HDD']
    device_characteristics = get_device_characteristics()
    device_names = []
    for device in device_characteristics:
        device_names.append(device["Product Name"].strip())

    return all([any(i in j for j in device_names) for i in fusion_device_names])

if __name__ == "__main__":
    print is_fusion_drive()