1 Reply
      Latest reply on Aug 29, 2019 11:50 AM by mdobro
      Sheldon15 Level 1 Level 1 (0 points)

        The APFS reference (https://developer.apple.com/support/downloads/Apple-File-System-Reference.pdf) mentions APFS volume roles, in particular System, Recovery, Preboot etc. (APFS_VOL_ROLE_SYSTEM, APFS_VOL_ROLE_RECOVERY, APFS_VOL_ROLE_PREBOOT)

        and I'm wondering what is the API function to query the role for a given APFS volume?

        • Re: Is there an API to get APFS volume's "role"?
          mdobro Level 2 Level 2 (40 points)

          The role is listed as a property of the IOMedia object for the volume. If you can get the DADiskRef for the volume in question you can use the following code to read the property for the role:


          CFArrayRef DiskCopyRole(DADiskRef diskRef)
            CFArrayRef roles = NULL;
            io_service_t service = DADiskCopyIOMedia(diskRef);
            if (IO_OBJECT_NULL != service)
                 roles = IORegistryEntryCreateCFProperty(service, CFSTR("Role"), kCFAllocatorDefault, kNilOptions);
            return roles;