forked from diskfs/go-diskfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
diskfs_unix.go
29 lines (24 loc) · 847 Bytes
/
diskfs_unix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//go:build !darwin || linux || solaris || aix || freebsd || illumos || netbsd || openbsd || plan9
// +build !darwin linux solaris aix freebsd illumos netbsd openbsd plan9
package diskfs
import (
"fmt"
"os"
"golang.org/x/sys/unix"
)
// getSectorSizes get the logical and physical sector sizes for a block device
func getSectorSizes(f *os.File) (int64, int64, error) {
/*
ioctl(fd, BLKPBSZGET, &physicalsectsize);
*/
fd := f.Fd()
logicalSectorSize, err := unix.IoctlGetInt(int(fd), unix.BLKSSZGET)
if err != nil {
return 0, 0, fmt.Errorf("Unable to get device logical sector size: %v", err)
}
physicalSectorSize, err := unix.IoctlGetInt(int(fd), unix.BLKPBSZGET)
if err != nil {
return 0, 0, fmt.Errorf("Unable to get device physical sector size: %v", err)
}
return int64(logicalSectorSize), int64(physicalSectorSize), nil
}