github.com/cockroachdb/pebble@v0.0.0-20231214172447-ab4952c5f87b/vfs/disk_usage_openbsd.go (about)

     1  // Copyright 2023 The LevelDB-Go and Pebble Authors. All rights reserved. Use
     2  // of this source code is governed by a BSD-style license that can be found in
     3  // the LICENSE file.
     4  
     5  //go:build openbsd
     6  // +build openbsd
     7  
     8  package vfs
     9  
    10  import "golang.org/x/sys/unix"
    11  
    12  func (defaultFS) GetDiskUsage(path string) (DiskUsage, error) {
    13  	stat := unix.Statfs_t{}
    14  	if err := unix.Statfs(path, &stat); err != nil {
    15  		return DiskUsage{}, err
    16  	}
    17  
    18  	freeBytes := uint64(stat.F_bsize) * uint64(stat.F_bfree)
    19  	availBytes := uint64(stat.F_bsize) * uint64(stat.F_bavail)
    20  	totalBytes := uint64(stat.F_bsize) * uint64(stat.F_blocks)
    21  	return DiskUsage{
    22  		AvailBytes: availBytes,
    23  		TotalBytes: totalBytes,
    24  		UsedBytes:  totalBytes - freeBytes,
    25  	}, nil
    26  }