-
Notifications
You must be signed in to change notification settings - Fork 0
/
sys_unix.go
39 lines (31 loc) · 901 Bytes
/
sys_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
30
31
32
33
34
35
36
37
38
39
//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
package wal
import (
"fmt"
"golang.org/x/sys/unix"
)
const (
sectorSize = 512
)
func pageSizefs(dir string) (int64, error) {
stat := unix.Statfs_t{}
if err := unix.Statfs(dir, &stat); err != nil {
return 0, fmt.Errorf("can't read directory stats: %w", err)
}
return int64(stat.Bsize), nil
}
func pageSize(name string) (int64, error) {
stat := unix.Stat_t{}
if err := unix.Stat(name, &stat); err != nil {
return 0, fmt.Errorf("can't read file stats: %w", err)
}
return int64(stat.Blksize), nil
}
func pages(name string) (int64, error) {
stat := unix.Stat_t{}
if err := unix.Stat(name, &stat); err != nil {
return 0, fmt.Errorf("can't read file stats: %w", err)
}
return stat.Blocks / (int64(stat.Blksize) / sectorSize), nil
}