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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a similar approach to Get-PhysicalDisk under windows, and if not, there are no plans to move forward in the near future #1165

Open
OyeHan opened this issue Dec 2, 2023 · 3 comments

Comments

@OyeHan
Copy link

OyeHan commented Dec 2, 2023

No description provided.

@GuillaumeGomez
Copy link
Owner

It was originally what I wanted to achieve but unfortunately, I couldn't find how to do it in other platforms than Windows.

@CarterLi
Copy link

CarterLi commented Dec 3, 2023

This is what I use in my project. All of them don't require root privileges.

  • Windows:
    • the raw device file is called \\.\PhysicalDriveX, while X is 0, 1, 2, 3... without empty slots.
    • Get the number of drives in HKLM\SYSTEM\CurrentControlSet\Services\disk\Enum\Count, or just keep open the raw device file until getting INVALID_HANDLE.
    • Get vendor, model name and serial number with IOCTL_STORAGE_QUERY_PROPERTY / StorageDeviceProperty
    • Get disk size with IOCTL_DISK_GET_DRIVE_GEOMETRY_EX
  • Linux:
    • All physical disks are in /sys/block/
    • Get disk name with /sys/block/X/device/vendor and /sys/block/X/device/model
    • Get serial number with /sys/block/X/device/serial
    • Get disk size with /sys/block/X/size
  • macOS:
    • All physical disk can be get with IOServiceMatching(kIOMediaClass)
    • Get name with the entry name of IOMedia service
    • Get serial number with kIOPropertyProductSerialNumberKey
    • Get disk size with kIOMediaSizeKey
  • FreeBSD:
    • Use libgeom, or parse sysctl kern.geom.confxml manually. All physical disks have rank = 1
    • Get name with config.descr
    • Get serial number with config.ident
    • Get disk size with lg_mediasize

@CarterLi
Copy link

CarterLi commented Dec 4, 2023

It's also possible to get disk kind with libgeom. There are keys called rotationrate in sysctl kern.geom.confxml. If its value is 0, the disk is non-rotating.

BTW, disk kinds should belong to physical disks instead of partitions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants