-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathstatx.go
More file actions
42 lines (32 loc) · 952 Bytes
/
statx.go
File metadata and controls
42 lines (32 loc) · 952 Bytes
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
40
41
42
//go:build linux
// +build linux
package directio
import (
"errors"
"golang.org/x/sys/unix"
)
var ErrFSNoDIOSupport = errors.New("filesystem does not expose Direct I/O alignment")
func DIOMemAlign(path string) (uint32, error) {
var stx unix.Statx_t
// Ask statx for direct I/O info. On Linux ≥6.1, STATX_DIOALIGN returns
// stx.Dio_mem_align and stx.Dio_offset_align.
mask := unix.STATX_DIOALIGN
flags := unix.AT_STATX_SYNC_AS_STAT | unix.AT_NO_AUTOMOUNT
if err := unix.Statx(unix.AT_FDCWD, path, flags, mask, &stx); err != nil {
switch {
case errors.Is(err, unix.ENOSYS),
errors.Is(err, unix.EOPNOTSUPP),
errors.Is(err, unix.ENOTSUP):
return 0, ErrFSNoDIOSupport
}
return 0, err
}
// Check which bits were actually filled by the kernel/FS.
if (stx.Mask & unix.STATX_DIOALIGN) == 0 {
return 0, ErrFSNoDIOSupport
}
if stx.Dio_mem_align == 0 {
return 0, ErrFSNoDIOSupport
}
return stx.Dio_mem_align, nil
}