api: Various fixes.

- limit list buckets to limit only 100 buckets, all uppercase buckets
  are now lowercase and work transparently with all calls.
- Change disk.Stat to disk.GetInfo and return back disk.Info{} struct.
- Introduce new ioutils package which implements ReadDirN(path, n),
  ReadDirNamesN(path, n)
This commit is contained in:
Harshavardhana
2016-01-24 23:03:38 -08:00
committed by Harshavardhana
parent 432a073e6b
commit 497f13d733
11 changed files with 247 additions and 132 deletions

View File

@@ -16,11 +16,11 @@
package disk
// StatFS stat fs struct is container which holds following values
// Info stat fs struct is container which holds following values
// Total - total size of the volume / disk
// Free - free size of the volume / disk
// FSType - file system type string
type StatFS struct {
// Type - file system type string
type Info struct {
Total int64
Free int64
FSType string

View File

@@ -36,9 +36,9 @@ func (s *MySuite) TestFree(c *C) {
path, err := ioutil.TempDir(os.TempDir(), "minio-")
c.Assert(err, IsNil)
statfs, err := disk.Stat(path)
di, err := disk.GetInfo(path)
c.Assert(err, IsNil)
c.Assert(statfs.Total, Not(Equals), 0)
c.Assert(statfs.Free, Not(Equals), 0)
c.Assert(statfs.FSType, Not(Equals), "UNKNOWN")
c.Assert(di.Total, Not(Equals), 0)
c.Assert(di.Free, Not(Equals), 0)
c.Assert(di.FSType, Not(Equals), "UNKNOWN")
}

View File

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

View File

@@ -23,11 +23,11 @@ import (
"unsafe"
)
// Stat returns total and free bytes available in a directory, e.g. `C:\`.
// GetInfo returns total and free bytes available in a directory, e.g. `C:\`.
// It returns free space available to the user (including quota limitations)
//
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa364937(v=vs.85).aspx
func Stat(path string) (statfs StatFS, err error) {
func GetInfo(path string) (info Info, err error) {
dll := syscall.MustLoadDLL("kernel32.dll")
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa364937(v=vs.85).aspx
// Retrieves information about the amount of space that is available on a disk volume,
@@ -50,9 +50,9 @@ func Stat(path string) (statfs StatFS, err error) {
uintptr(unsafe.Pointer(&lpFreeBytesAvailable)),
uintptr(unsafe.Pointer(&lpTotalNumberOfBytes)),
uintptr(unsafe.Pointer(&lpTotalNumberOfFreeBytes)))
statfs = StatFS{}
statfs.Total = int64(lpTotalNumberOfBytes)
statfs.Free = int64(lpFreeBytesAvailable)
statfs.FSType = getFSType(path)
return statfs, nil
info = Info{}
info.Total = int64(lpTotalNumberOfBytes)
info.Free = int64(lpFreeBytesAvailable)
info.FSType = getFSType(path)
return info, nil
}