forked from cockroachdb/pebble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault_linux_arm.go
73 lines (59 loc) · 1.9 KB
/
default_linux_arm.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright 2023 The LevelDB-Go and Pebble Authors. All rights reserved. Use
// of this source code is governed by a BSD-style license that can be found in
// the LICENSE file.
//go:build linux && arm
// +build linux,arm
package vfs
import (
"os"
"syscall"
"github.com/cockroachdb/errors"
"golang.org/x/sys/unix"
)
func wrapOSFileImpl(f *os.File) File {
lf := &linuxOnArmFile{File: f, fd: f.Fd()}
if lf.fd != InvalidFd {
lf.useSyncRange = isSyncRangeSupported(lf.fd)
}
return lf
}
func (defaultFS) OpenDir(name string) (File, error) {
f, err := os.OpenFile(name, syscall.O_CLOEXEC, 0)
if err != nil {
return nil, errors.WithStack(err)
}
return &linuxOnArmDir{f}, nil
}
// Assert that linuxOnArmFile and linuxOnArmDir implement vfs.File.
var (
_ File = (*linuxOnArmDir)(nil)
_ File = (*linuxOnArmFile)(nil)
)
type linuxOnArmDir struct {
*os.File
}
func (d *linuxOnArmDir) Prefetch(offset int64, length int64) error { return nil }
func (d *linuxOnArmDir) Preallocate(offset, length int64) error { return nil }
func (d *linuxOnArmDir) SyncData() error { return d.Sync() }
func (d *linuxOnArmDir) SyncTo(offset int64) (fullSync bool, err error) { return false, nil }
type linuxOnArmFile struct {
*os.File
fd uintptr
useSyncRange bool
}
func (f *linuxOnArmFile) Prefetch(offset int64, length int64) error {
_, _, err := unix.Syscall(unix.SYS_READAHEAD, uintptr(f.fd), uintptr(offset), uintptr(length))
return err
}
func (f *linuxOnArmFile) Preallocate(offset, length int64) error { return nil }
func (f *linuxOnArmFile) SyncData() error {
// TODO(radu): does arm support unix.Fdatasync?
return f.Sync()
}
func (f *linuxOnArmFile) SyncTo(int64) (fullSync bool, err error) {
// syscall.SyncFileRange is not defined form arm (see https://github.com/cockroachdb/pebble/issues/171).
if err = f.Sync(); err != nil {
return false, err
}
return true, nil
}