//go:build linux package main import ( "os" "unsafe" "syscall" ) // BLKGETSIZE64 = _IOR(0x12, 114, sizeof(uint64)) on Linux. const blkGetSize64 = 0x80081272 func blockDeviceSize(path string) (int64, error) { f, err := os.Open(path) if err != nil { return 0, err } defer f.Close() var size uint64 _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), blkGetSize64, uintptr(unsafe.Pointer(&size))) if errno != 0 { return 0, errno } return int64(size), nil }