-
Notifications
You must be signed in to change notification settings - Fork 386
/
dir_unix.go
42 lines (32 loc) · 1.11 KB
/
dir_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
38
39
40
41
42
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
//go:build !windows
package filestore
import (
"os"
"golang.org/x/sys/unix"
"storj.io/storj/storagenode/blobstore"
)
func diskInfoFromPath(path string) (info blobstore.DiskInfo, err error) {
var stat unix.Statfs_t
err = unix.Statfs(path, &stat)
if err != nil {
return blobstore.DiskInfo{TotalSpace: -1, AvailableSpace: -1}, err
}
// the Bsize size depends on the OS and unconvert gives a false-positive
reservedBlocks := int64(stat.Bfree) - int64(stat.Bavail)
totalSpace := (int64(stat.Blocks) - reservedBlocks) * int64(stat.Bsize) //nolint: unconvert
availableSpace := int64(stat.Bavail) * int64(stat.Bsize) //nolint: unconvert
return blobstore.DiskInfo{
TotalSpace: totalSpace,
AvailableSpace: availableSpace,
}, nil
}
// rename renames oldpath to newpath.
func rename(oldpath, newpath string) error {
return os.Rename(oldpath, newpath)
}
// openFileReadOnly opens the file with read only.
func openFileReadOnly(path string, perm os.FileMode) (*os.File, error) {
return os.OpenFile(path, os.O_RDONLY, perm)
}