New returns the disk status for dir. May return Unsupported error if it doesn't work on this platform.
(dir string)
| 10 | // |
| 11 | // May return Unsupported error if it doesn't work on this platform. |
| 12 | func New(dir string) (info Info, err error) { |
| 13 | var statfs unix.Statfs_t |
| 14 | err = unix.Statfs(dir, &statfs) |
| 15 | if err != nil { |
| 16 | return info, err |
| 17 | } |
| 18 | // Note that these can be different sizes on different OSes so |
| 19 | // we upcast them all to uint64 |
| 20 | //nolint:unconvert |
| 21 | info.Free = uint64(statfs.Bfree) * uint64(statfs.Bsize) |
| 22 | //nolint:unconvert |
| 23 | info.Available = uint64(statfs.Bavail) * uint64(statfs.Bsize) |
| 24 | //nolint:unconvert |
| 25 | info.Total = uint64(statfs.Blocks) * uint64(statfs.Bsize) |
| 26 | return info, nil |
| 27 | } |