Comment 4 for bug 1900842

Revision history for this message
Ian Johnson (anonymouse67) wrote :

I ended up needing to slightly modify the proposed algorithm, I was thinking the "partition" file in sysfs was a boolean indicating if it was a partition, but actually it corresponds literally to the partition number for that device, so the proposed logic should just check for the existence of the partition file. the proposed algorithm should now read something like this (note the if condition is different inside the for loop - that is the only change)

udevProps, err := $(udevadm info --query property --name /dev/block/$diskMajor:$devMinor)
if err != nil
   return err("broken")

diskDevName = filepath.Base(udevProps["DEVNAME"])
diskDevPath = udevProps["DEVPATH"]

childPartitions = {}
paths := glob("/sys" + diskDevPath + "/" + diskDevPath + "*")
for path in paths:
    if fileExists(path + "/partition"):
        ueventFile = readFile(path + "/uevent")
        partitionMajor = ueventFile["MAJOR"]
        partitionMinor = ueventFile["MINOR"]
        udevProps := $(udevadm info --query property --name /dev/block/$partitionMajor:$partitionMinor)
        childPartitions[ udevProps["ID_FS_LABEL_ENC"] ] = udevProps["ID_PART_ENTRY_UUID"]