Improve disk code to return back disk StatFS{} structure

```
StatFS {
Total int64
Free int64
FSType string
}
```

Provides more information in a cross platform way.
This commit is contained in:
Harshavardhana
2015-10-17 19:09:43 -07:00
parent 4b3961e1df
commit a8a935f5fd
8 changed files with 116 additions and 59 deletions

View File

@@ -23,13 +23,18 @@ import (
)
// Stat returns total and free bytes available in a directory, e.g. `/`.
func Stat(path string) (total, free int64, err error) {
func Stat(path string) (statfs StatFS, err error) {
s := syscall.Statfs_t{}
err = syscall.Statfs(path, &s)
if err != nil {
return
return StatFS{}, err
}
total = int64(s.Bsize) * int64(s.Blocks)
free = int64(s.Bsize) * int64(s.Bfree)
return
statfs = StatFS{}
statfs.Total = int64(s.Bsize) * int64(s.Blocks)
statfs.Free = int64(s.Bsize) * int64(s.Bfree)
statfs.FSType, err = getFSType(path)
if err != nil {
return StatFS{}, err
}
return statfs, nil
}