diff --git a/lib/filestream/filestream_openbsd.go b/lib/filestream/filestream_openbsd.go new file mode 100644 index 000000000..9e5383193 --- /dev/null +++ b/lib/filestream/filestream_openbsd.go @@ -0,0 +1,30 @@ +package filestream + +import ( + "fmt" + + "golang.org/x/sys/unix" +) + +func (st *streamTracker) adviseDontNeed(n int, fdatasync bool) error { + st.length += uint64(n) + if st.fd == 0 { + return nil + } + if st.length < dontNeedBlockSize { + return nil + } + blockSize := st.length - (st.length % dontNeedBlockSize) + if fdatasync { + if err := unix.Fsync(int(st.fd)); err != nil { + return fmt.Errorf("unix.Fsync error: %w", err) + } + } + st.length -= blockSize + + return nil +} + +func (st *streamTracker) close() error { + return nil +} diff --git a/lib/fs/fs.go b/lib/fs/fs.go index bedb813d4..b434b46b1 100644 --- a/lib/fs/fs.go +++ b/lib/fs/fs.go @@ -338,6 +338,6 @@ func mustGetFreeSpace(path string) uint64 { if err := unix.Fstatfs(int(fd), &stat); err != nil { logger.Panicf("FATAL: cannot determine free disk space on %q: %s", path, err) } - freeSpace := uint64(stat.Bavail) * uint64(stat.Bsize) - return freeSpace + + return freeSpace(stat) } diff --git a/lib/fs/fs_nix.go b/lib/fs/fs_nix.go new file mode 100644 index 000000000..a1e126127 --- /dev/null +++ b/lib/fs/fs_nix.go @@ -0,0 +1,9 @@ +// +build linux darwin freebsd + +package fs + +import "golang.org/x/sys/unix" + +func freeSpace(stat unix.Statfs_t) uint64 { + return uint64(stat.Bavail) * uint64(stat.Bsize) +} diff --git a/lib/fs/fs_openbsd.go b/lib/fs/fs_openbsd.go new file mode 100644 index 000000000..1ab4b9358 --- /dev/null +++ b/lib/fs/fs_openbsd.go @@ -0,0 +1,9 @@ +package fs + +import ( + "golang.org/x/sys/unix" +) + +func freeSpace(stat unix.Statfs_t) uint64 { + return uint64(stat.F_bavail) * uint64(stat.F_bsize) +}