Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

MacOS Block() returns no information #187

Open
audiolion opened this issue May 5, 2020 · 5 comments
Open

MacOS Block() returns no information #187

audiolion opened this issue May 5, 2020 · 5 comments
Assignees
Labels
block Block storage and device issues bug macos
Milestone

Comments

@audiolion
Copy link

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

ghw/block_darwin.go

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

ghw/block_darwin.go

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

ghw/block_darwin.go

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

ghw/block_darwin.go

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

ghw/block_darwin.go

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.

@jaypipes
Copy link
Owner

jaypipes commented May 5, 2020

Hi @audiolion! Thanks very much for the bug report! I'll look into a fix ASAP.

@jaypipes jaypipes added block Block storage and device issues bug macos labels May 5, 2020
@jaypipes jaypipes self-assigned this May 5, 2020
@jaypipes jaypipes added this to the v1.0.0 milestone May 5, 2020
@audiolion
Copy link
Author

nice! If I can help in anyway let me know. I don't have another mac to confirm if this is purely an issue with my machine or if it presents on other machines as well. Maybe something changed with Catalina?

@jaypipes
Copy link
Owner

@audiolion hey, I haven't forgotten about you! Trying to get my hands on a Mac to reproduce your issue and push a fix. Sorry for the delay!

@audiolion
Copy link
Author

Hey no worries. Mac is so difficult to develop for because you can't emulate it :(. I might be able to set up a mac mini that you can remote into?

@codestation
Copy link

I had the same problem so i had a friend run some tests and found this:

The MacBook i have runs on a HDD and diskutil reports the following DevicePath

IODeviceTree:/PCI0@0/SATA@1F,2/PRT0@0/PMP@0

So ioreg gets called with PMP@0 and returns nothing. The library doesn't work here. Note: I ran ioreg by hand with AppleAHCIDiskDriver as name and got the disk model/serial.

The MacBook from my friend uses a SSD and diskutil returns this DevicePath

IODeviceTree:/PCI0@0/RP01@1C/SSD0@0/AppleS3XController

In this case ioreg gets called with AppleS3XController and got the disk model/serial. The library works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
block Block storage and device issues bug macos
Projects
None yet
Development

No branches or pull requests

3 participants