【发布时间】:2022-01-27 23:23:42
【问题描述】:
我需要计算 Go 中挂载路径(例如 /mnt/mycustommount)的已用空间和已用 inode 的百分比。
这是我的尝试:
var statFsOutput unix.Statfs_t
err := unix.Statfs(mount_path, &statFsOutput)
if err != nil {
return err
}
totalBlockCount := statFsOutput.Blocks // Total data blocks in filesystem
freeSystemBlockCount = statFsOutput.Bfree // Free blocks in filesystem
freeUserBlockCount = statFsOutput.Bavail // Free blocks available to unprivileged user
现在我需要的比例是这样的:
x : 100 = (totalBlockCount - free[which?]BlockCount) : totalBlockCount
即x : 100 = usedBlockCount : totalBlockCount 。但我不明白Bfree 和Bavail 之间的区别(“非特权”用户与文件系统块有什么关系?)。
对于 inode 我的尝试:
totalInodeCount = statFsOutput.Files
freeInodeCount = statFsOutput.Ffree
// so now the proportion is
// x : 100 = (totalInodeCount - freeInodeCount) : totalInodeCount
如何获取已用存储的百分比? 我做的 inode 计算是否正确?
【问题讨论】:
标签: linux go filesystems storage disk