Files
kopia/internal/stat/stat_bsd.go
Nathan Baulch 657fda216a chore(ci): upgrade to golangci-lint 2.6.1 (#4973)
- upgrade to golangci-lint 2.6.1
- updates for gosec
- updates for govet
- updates for perfsprint
- updates modernize

Leaves out modernize:omitempty due to conflicts with tests
2025-11-11 21:27:10 -08:00

47 lines
931 B
Go

//go:build openbsd
// Package stat provides a cross-platform abstraction for
// common stat commands.
package stat
import (
"syscall"
"github.com/pkg/errors"
)
const (
diskBlockSize uint64 = 512
)
var errInvalidBlockSize = errors.New("invalid disk block size")
// GetFileAllocSize gets the space allocated on disk for the file.
// 'fname' in bytes.
func GetFileAllocSize(fname string) (uint64, error) {
var st syscall.Stat_t
err := syscall.Stat(fname, &st)
if err != nil {
return 0, err //nolint:wrapcheck
}
return uint64(st.Blocks) * diskBlockSize, nil
}
// GetBlockSize gets the disk block size of the underlying system.
func GetBlockSize(path string) (uint64, error) {
var st syscall.Statfs_t
err := syscall.Statfs(path, &st)
if err != nil {
return 0, err //nolint:wrapcheck
}
if st.F_bsize <= 0 {
return 0, errors.Wrapf(errInvalidBlockSize, "%d", st.F_bsize)
}
return uint64(st.F_bsize), nil
}