Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions pkg/block/block_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
package block

import (
"os"
"strconv"
"strings"
"syscall"
"unsafe"

"github.com/StackExchange/wmi"

Expand Down Expand Up @@ -207,6 +210,26 @@ func getDiskDrives() ([]win32DiskDrive, error) {
if err := wmi.Query(wqlDiskDrive, &win3232DiskDriveDescriptions); err != nil {
return nil, err
}
for _, disk := range win3232DiskDriveDescriptions {
if disk.DeviceID == nil {
continue
}
volume, err := os.OpenFile(*disk.DeviceID, os.O_RDWR, 0)
if err != nil {
continue
}
// Get the volume's underlying partition size in NTFS clusters.
var (
partitionSize int64
bytes uint32
)
const _IOCTL_DISK_GET_LENGTH_INFO = 0x0007405C
err = syscall.DeviceIoControl(syscall.Handle(volume.Fd()), _IOCTL_DISK_GET_LENGTH_INFO, nil, 0, (*byte)(unsafe.Pointer(&partitionSize)), 8, &bytes, nil)
volume.Close()
if err == nil {
*disk.Size = uint64(partitionSize)
}
}
return win3232DiskDriveDescriptions, nil
}

Expand Down