Get APFS container's physical store using the API - Swift

Hi, i have made some code in Swift that allows me to get a list of the storage disks and the relative partitions present in a mac (everything made using the IOKit api), this of course includes the APFS containers that are managed by the OS as separate storage devices.

To have a proper representation of the partitions tree in my code i need to know which are the actual partitions housing a given APFS container.

I have tried to look for this information on documentation and on the internet, then into the IORegistry (using the registry explorer app) and searching for this info into the description dictionaries provided by Disk arbitration but so far no luck, even by comparing the UUIDs.

In IORegistry explorer in the IOService plane I can also see that the APFS Container in my mac's ssd is listed as a sub-node of it's physical storage a partition, but since i am using an IOIterator object to scan the IORegistry i have no idea of how i should look into sub-nodes for a given node.

Also i think that some particular storage configurations might have an APFS container split across multiple physical storage devices, in fact the diskutil list -plist command shows the physical store for each APFS containers as an array in the plist output, so the child approach might not be effective there.

So how can i do this?

I am doing all of this stuff because i am working to a sandbox-friendly open source swift package for macOS apps to easily get a complete tree structure of disks and partitions, in a similar fashion to the above mentioned diskutil list -plist command, my goal is actually to have the exact same structure provided by that command, with the same info.

Hi,

First off, as a general comment, I'd strongly recommend filing a DTS incident on this, basically asking for "general background". There are a LOT of issues involved in understanding how the system organizes and present storage, which makes it very difficult to neatly summarize.

In terms of the specific registry "scan" question here, way "RAID-like" drivers are typically implemented is by having the same driver match against two different devices, so "IOObjectIsEqualTo" can be used to verify that a driver appearing in multiple places in the same hierarchy is identical. You can also "invert" the registry search directions, searching "up" from lower level parent driver
"up" to the final volume instead of the typical "down" from the volume toward mass storage.

There are a lot of other "tricks" (typically based on property values) that can be used to handle specific kinds of volumes, but the complication is that there's no guarantee that they'll "generalize". That's my big warning here- if you want to handle "anything", the you should try to search out a very broad data set, particularly as many 3rd party configurations as possible.

-Kevin Elliott DTS Engineer, CoreOS/Hardware

Get APFS container's physical store using the API - Swift
 
 
Q