github.com/searKing/golang/go@v1.2.74/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 // +build openbsd aix,ppc64 7 8 package os 9 10 import ( 11 "syscall" 12 ) 13 14 // DiskUsage returns total and free bytes available in a directory, e.g. `/`. 15 func DiskUsage(path string) (total int64, free int64, avail int64, inodes int64, inodesFree int64, err error) { 16 var st syscall.Statfs_t 17 if err := syscall.Statfs(path, &st); err != nil { 18 return 0, 0, 0, 0, 0, err 19 } 20 reservedBlocks := int64(st.F_bfree) - int64(st.F_bavail) 21 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 22 }