btcd/database/ffldb/disk_posix.go
Steven Roose 203a9130fc database: Prevent write transaction with low disk space
Currently the user is not informed of issues that are due to low disk
space (such as block processing failures and resulting orphaning
blocks).  Instead, check for available disk space before starting a
write transaction to preventively fail and inform the user of the
problem.
2018-04-08 02:21:57 +02:00

26 lines
504 B
Go

// +build !windows
// Copyright (c) 2013-2018 The btcsuite developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package ffldb
import (
"os"
"syscall"
)
// getAvailableDiskSpace returns the number of bytes of available disk space.
func getAvailableDiskSpace() (uint64, error) {
var stat syscall.Statfs_t
wd, err := os.Getwd()
if err != nil {
return 0, err
}
syscall.Statfs(wd, &stat)
return stat.Bavail * uint64(stat.Bsize), nil
}