func()

in internal/diskutil/types/disk.go [68:89]


func (d *DiskInfo) ParentDeviceID() (string, error) {
	// APFS Containers and Volumes are virtualized and should have a physical store which represents a physical disk
	if d.APFSPhysicalStores == nil {
		return "", fmt.Errorf("no physical stores found in disk")
	}

	// Check if there's more than one Physical Store in the disk's info. Having more than one APFS Physical Store
	// is unexpected and the common case shouldn't violate this.
	//
	// Note: more than one physical store can indicate a fusion drive - https://support.apple.com/en-us/HT202574.
	if len(d.APFSPhysicalStores) != 1 {
		return "", fmt.Errorf("expected 1 physical store but got [%d]", len(d.APFSPhysicalStores))
	}

	id := identifier.ParseDiskID(d.APFSPhysicalStores[0].DeviceIdentifier)
	if id == "" {
		return "", fmt.Errorf("physical store [%s] does not contain the expected expression \"disk[0-9]+\"",
			d.APFSPhysicalStores[0].DeviceIdentifier)
	}

	return id, nil
}