forked from keybase/kbfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisk_limits_unix.go
37 lines (31 loc) · 991 Bytes
/
disk_limits_unix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright 2017 Keybase Inc. All rights reserved.
// Use of this source code is governed by a BSD
// license that can be found in the LICENSE file.
// +build !windows
package libkbfs
import (
"math"
"github.com/pkg/errors"
"golang.org/x/sys/unix"
)
// getDiskLimits gets the disk limits for the logical disk containing
// the given path.
func getDiskLimits(path string) (
availableBytes, availableFiles uint64, err error) {
var stat unix.Statfs_t
err = unix.Statfs(path, &stat)
if err != nil {
return 0, 0, errors.WithStack(err)
}
// Bavail is the free block count for an unprivileged user.
availableBytes = uint64(stat.Bavail) * uint64(stat.Bsize)
// Some filesystems, like btrfs, don't keep track of inodes.
// (See https://github.com/keybase/client/issues/6206 .) Use
// the total inode count to detect that case.
if stat.Files > 0 {
availableFiles = uint64(stat.Ffree)
} else {
availableFiles = math.MaxInt64
}
return availableBytes, availableFiles, nil
}