-
Notifications
You must be signed in to change notification settings - Fork 218
Description
Hi 👋,
Wanted to use the ghw.Block() functionality, and noticed on Darwin that it returns no information. I used delve to debug what was happening, and while almost all the disk information was being found, it was getting to this section of code
Lines 129 to 136 in e193f94
| args := []string{ | |
| "ioreg", | |
| "-a", // use XML output | |
| "-d", "1", // limit device tree output depth to root node | |
| "-r", // root device tree at matched node | |
| "-n", name, // match by name | |
| } | |
| out, err := exec.Command(args[0], args[1:]...).Output() |
and out was an empty string. This code is supposed to populate this struct
Lines 91 to 96 in e193f94
| type ioregPlist struct { | |
| // there's a lot more than just this... | |
| ModelNumber string `plist:"Model Number"` | |
| SerialNumber string `plist:"Serial Number"` | |
| VendorName string `plist:"Vendor Name"` | |
| } |
and when it fails it calls
Lines 140 to 142 in e193f94
| if out == nil || len(out) == 0 { | |
| return nil, nil | |
| } |
which results in the this continue clause to be called
Lines 248 to 254 in e193f94
| ioregPlist, err := ctx.getIoregPlist(infoPlist.DeviceTreePath) | |
| if err != nil { | |
| return err | |
| } | |
| if ioregPlist == nil { | |
| continue | |
| } |
As a result, none of this code is called, so nothing ever gets populated
Lines 257 to 293 in e193f94
| diskReport := &Disk{ | |
| Name: disk.DeviceIdentifier, | |
| SizeBytes: uint64(disk.Size), | |
| PhysicalBlockSizeBytes: uint64(infoPlist.DeviceBlockSize), | |
| DriveType: ctx.driveTypeFromPlist(infoPlist), | |
| IsRemovable: infoPlist.Removable, | |
| StorageController: ctx.storageControllerFromPlist(infoPlist), | |
| BusType: ctx.busTypeFromPlist(infoPlist), | |
| BusPath: busPath, | |
| NUMANodeID: -1, | |
| Vendor: ioregPlist.VendorName, | |
| Model: ioregPlist.ModelNumber, | |
| SerialNumber: ioregPlist.SerialNumber, | |
| WWN: "", | |
| Partitions: make([]*Partition, 0, len(disk.Partitions)+len(disk.APFSVolumes)), | |
| } | |
| for _, partition := range disk.Partitions { | |
| part, err := ctx.makePartition(disk, partition, false) | |
| if err != nil { | |
| return err | |
| } | |
| part.Disk = diskReport | |
| diskReport.Partitions = append(diskReport.Partitions, part) | |
| } | |
| for _, volume := range disk.APFSVolumes { | |
| part, err := ctx.makePartition(disk, volume, true) | |
| if err != nil { | |
| return err | |
| } | |
| part.Disk = diskReport | |
| diskReport.Partitions = append(diskReport.Partitions, part) | |
| } | |
| info.TotalPhysicalBytes += uint64(disk.Size) | |
| info.Disks = append(info.Disks, diskReport) | |
| info.Partitions = append(info.Partitions, diskReport.Partitions...) |
In summary, because the model number/serial number/vendor retrieval failed, we lost out on all the other information that was found. Two requests, could we populate the information even if this ioreg piece fails? And could we look into why the ioreg piece fails on darwin? I tried to query ioreg but I was not able to find an alternative way to pull this info.