posix: checkDiskFree() also checks free inodes. (#2086)

Previously checkDiskFree() checks for free available space.  This
patch enables checkDiskFree() also checks for free inodes in linux and
free clusters in windows.

Fixes #2075
This commit is contained in:
Bala FA
2016-07-04 11:04:45 +05:30
committed by Harshavardhana
parent 52b55afce0
commit 1ad5fb8f76
5 changed files with 37 additions and 2 deletions

View File

@@ -23,5 +23,7 @@ package disk
type Info struct {
Total int64
Free int64
Files int64
Ffree int64
FSType string
}

View File

@@ -41,5 +41,7 @@ func (s *MySuite) TestFree(c *C) {
c.Assert(err, IsNil)
c.Assert(di.Total, Not(Equals), 0)
c.Assert(di.Free, Not(Equals), 0)
c.Assert(di.Files, Not(Equals), 0)
c.Assert(di.Ffree, Not(Equals), 0)
c.Assert(di.FSType, Not(Equals), "UNKNOWN")
}

View File

@@ -32,6 +32,8 @@ func GetInfo(path string) (info Info, err error) {
info = Info{}
info.Total = int64(s.Bsize) * int64(s.Blocks)
info.Free = int64(s.Bsize) * int64(s.Bfree)
info.Files = int64(s.Files)
info.Ffree = int64(s.Ffree)
info.FSType, err = getFSType(path)
if err != nil {
return Info{}, err

View File

@@ -60,5 +60,33 @@ func GetInfo(path string) (info Info, err error) {
info.Total = int64(lpTotalNumberOfBytes)
info.Free = int64(lpFreeBytesAvailable)
info.FSType = getFSType(path)
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa364935(v=vs.85).aspx
// Retrieves information about the specified disk, including the amount of free space on the disk.
GetDiskFreeSpace := dll.MustFindProc("GetDiskFreeSpaceW")
// Return values of GetDiskFreeSpace()
lpSectorsPerCluster := uint32(0)
lpBytesPerSector := uint32(0)
lpNumberOfFreeClusters := uint32(0)
lpTotalNumberOfClusters := uint32(0)
// Extract values safely
// BOOL WINAPI GetDiskFreeSpace(
// _In_ LPCTSTR lpRootPathName,
// _Out_ LPDWORD lpSectorsPerCluster,
// _Out_ LPDWORD lpBytesPerSector,
// _Out_ LPDWORD lpNumberOfFreeClusters,
// _Out_ LPDWORD lpTotalNumberOfClusters
// );
_, _, _ = GetDiskFreeSpace.Call(uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(path))),
uintptr(unsafe.Pointer(&lpSectorsPerCluster)),
uintptr(unsafe.Pointer(&lpBytesPerSector)),
uintptr(unsafe.Pointer(&lpNumberOfFreeClusters)),
uintptr(unsafe.Pointer(&lpTotalNumberOfClusters)))
info.Files = int64(lpTotalNumberOfClusters)
info.Ffree = int64(lpNumberOfFreeClusters)
return info, nil
}