pax_global_header00006660000000000000000000000064130707133020014506gustar00rootroot0000000000000052 comment=dd9dc2043353249b2910b29dcfd6f6d4e64f39be du-1.0.1/000077500000000000000000000000001307071330200121155ustar00rootroot00000000000000du-1.0.1/LICENSE000066400000000000000000000022721307071330200131250ustar00rootroot00000000000000This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means. In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to du-1.0.1/README.md000066400000000000000000000002401307071330200133700ustar00rootroot00000000000000du == Get total and available disk space on a given volume. Documentation ------------- http://godoc.org/github.com/calmh/du License ------- Public Domain du-1.0.1/cmd/000077500000000000000000000000001307071330200126605ustar00rootroot00000000000000du-1.0.1/cmd/du/000077500000000000000000000000001307071330200132705ustar00rootroot00000000000000du-1.0.1/cmd/du/main.go000066400000000000000000000005341307071330200145450ustar00rootroot00000000000000package main import ( "fmt" "log" "os" "github.com/calmh/du" ) var KB = int64(1024) func main() { usage, err := du.Get(os.Args[1]) if err != nil { log.Fatal(err) } fmt.Println("Free:", usage.FreeBytes/(KB*KB), "MiB") fmt.Println("Available:", usage.AvailBytes/(KB*KB), "MiB") fmt.Println("Size:", usage.TotalBytes/(KB*KB), "MiB") } du-1.0.1/diskusage.go000066400000000000000000000003511307071330200144220ustar00rootroot00000000000000package du // Usage holds information about total and available storage on a volume. type Usage struct { TotalBytes int64 // Size of volume FreeBytes int64 // Unused size AvailBytes int64 // Available to a non-privileged user } du-1.0.1/diskusage_posix.go000066400000000000000000000010331307071330200156420ustar00rootroot00000000000000// +build !windows,!netbsd,!openbsd,!solaris package du import ( "path/filepath" "syscall" ) // Get returns the Usage of a given path, or an error if usage data is // unavailable. func Get(path string) (Usage, error) { var stat syscall.Statfs_t err := syscall.Statfs(filepath.Clean(path), &stat) if err != nil { return Usage{}, err } u := Usage{ FreeBytes: int64(stat.Bfree) * int64(stat.Bsize), TotalBytes: int64(stat.Blocks) * int64(stat.Bsize), AvailBytes: int64(stat.Bavail) * int64(stat.Bsize), } return u, nil } du-1.0.1/diskusage_unsupported.go000066400000000000000000000004301307071330200170700ustar00rootroot00000000000000// +build netbsd openbsd solaris package du import "errors" var ErrUnsupported = errors.New("unsupported platform") // Get returns the Usage of a given path, or an error if usage data is // unavailable. func Get(path string) (Usage, error) { return Usage{}, ErrUnsupported } du-1.0.1/diskusage_windows.go000066400000000000000000000012021307071330200161700ustar00rootroot00000000000000package du import ( "runtime" "syscall" "unsafe" ) // Get returns the Usage of a given path, or an error if usage data is // unavailable. func Get(path string) (Usage, error) { h := syscall.MustLoadDLL("kernel32.dll") c := h.MustFindProc("GetDiskFreeSpaceExW") var u Usage pathw, err := syscall.UTF16PtrFromString(path) if err != nil { return Usage{}, err } ret, _, err := c.Call( uintptr(unsafe.Pointer(pathw)), uintptr(unsafe.Pointer(&u.FreeBytes)), uintptr(unsafe.Pointer(&u.TotalBytes)), uintptr(unsafe.Pointer(&u.AvailBytes))) runtime.KeepAlive(pathw) if ret == 0 { return Usage{}, err } return u, nil } du-1.0.1/diskusage_windows_test.go000077500000000000000000000012211307071330200172330ustar00rootroot00000000000000package du import "testing" func TestDiskUsage(t *testing.T) { cases := []struct { path string ok bool }{ {"c:\\", true}, {"c:\\windows", true}, {"c:\\aux", false}, {"c:\\does-not-exist-09sadkjhdsa98234bj23hgasd98", false}, } for _, tc := range cases { res, err := Get(tc.path) if tc.ok { if err != nil { t.Errorf("Unexpected error Get(%q) => %v", tc.path, err) } else if res.TotalBytes == 0 || res.AvailBytes == 0 || res.FreeBytes == 0 { t.Errorf("Suspicious result Get(%q) => %v", tc.path, res) } } else if err == nil { t.Errorf("Unexpected nil error in Get(%q)", tc.path) } } }