Source file src/cmd/go/internal/cache/statfs_linux.go
1 // Copyright 2026 The Go Authors. 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 package cache 6 7 import "syscall" 8 9 // statfs returns the blocks available to unprivileged users, the total blocks, 10 // and the block size of the file system holding dir, or zeros if unknown. 11 func statfs(dir string) (avail, total, bsize uint64) { 12 var st syscall.Statfs_t 13 if syscall.Statfs(dir, &st) != nil { 14 return 0, 0, 0 15 } 16 // Block counts are in Frsize units, as in statvfs (Bsize if Frsize is unset). 17 // Converting to int64 handles int32, uint32, and int64 fields across GOARCHes. 18 size := int64(st.Frsize) 19 if size <= 0 { 20 size = int64(st.Bsize) 21 } 22 if size <= 0 { 23 return 0, 0, 0 24 } 25 return st.Bavail, st.Blocks, uint64(size) 26 } 27