github.com/searKing/golang/go@v1.2.117/os/disk_openbsd_aix.go (about)

     1  // Copyright 2022 The searKing Author. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build openbsd || (aix && ppc64)
     6  
     7  package os
     8  
     9  import (
    10  	"syscall"
    11  )
    12  
    13  // DiskUsage returns total and free bytes available in a directory, e.g. `/`.
    14  func DiskUsage(path string) (total int64, free int64, avail int64, inodes int64, inodesFree int64, err error) {
    15  	var st syscall.Statfs_t
    16  	if err := syscall.Statfs(path, &st); err != nil {
    17  		return 0, 0, 0, 0, 0, err
    18  	}
    19  	reservedBlocks := int64(st.F_bfree) - int64(st.F_bavail)
    20  	return int64(st.F_bsize) * (int64(st.F_blocks) - reservedBlocks), int64(st.F_bsize) * int64(st.F_bfree), int64(st.F_bsize) * int64(st.F_bavail), int64(st.F_files), int64(st.F_ffree), nil
    21  }