-
Notifications
You must be signed in to change notification settings - Fork 467
/
default_unix.go
47 lines (36 loc) · 1.16 KB
/
default_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
40
41
42
43
44
45
46
47
// Copyright 2014 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 darwin || dragonfly || freebsd || (linux && arm) || netbsd || openbsd || solaris
// +build darwin dragonfly freebsd linux,arm netbsd openbsd solaris
package vfs
import (
"os"
"syscall"
"github.com/cockroachdb/errors"
)
func wrapOSFile(osFile *os.File) File {
return &unixFile{File: osFile, fd: osFile.Fd()}
}
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 &unixFile{f, InvalidFd}, nil
}
// Assert that unixFile implements vfs.File.
var _ File = (*unixFile)(nil)
type unixFile struct {
*os.File
fd uintptr
}
func (f *unixFile) Attributes() FileAttributes {
// No support for sync_file_range.
return FileAttributes{CanSyncTo: false}
}
func (f *unixFile) Preallocate(offset, length int64) error {
return preallocExtend(f.fd, offset, length)
}
func (f *unixFile) SyncData() error { return f.Sync() }
func (f *unixFile) SyncTo(int64) error { return f.Sync() }