You must login to view /gokrazy/tools/src/commit/ab669011325737dc654a82ce14d60c5476688dfc/internal.
The GitHub option should be usable for most people, it only links via username.

Files
tools/internal/packer/parttable_darwin.go

29 lines
648 B
Go

package packer
import (
"unsafe"
"golang.org/x/sys/unix"
)
const (
// TODO: get these into golang.org/x/sys/unix
DKIOCGETBLOCKCOUNT = 0x40086419 // e.g. 31116288
DKIOCGETBLOCKSIZE = 0x40046418 // e.g. 512
)
func deviceSize(fd uintptr) (uint64, error) {
var (
blocksize uint32
blockcount uint64
)
if _, _, errno := unix.Syscall(unix.SYS_IOCTL, fd, DKIOCGETBLOCKSIZE, uintptr(unsafe.Pointer(&blocksize))); errno != 0 {
return 0, errno
}
if _, _, errno := unix.Syscall(unix.SYS_IOCTL, fd, DKIOCGETBLOCKCOUNT, uintptr(unsafe.Pointer(&blockcount))); errno != 0 {
return 0, errno
}
return uint64(blocksize) * blockcount, nil
}