diff --git a/gfapi/fd.go b/gfapi/fd.go index 9c8296a..4e51f09 100644 --- a/gfapi/fd.go +++ b/gfapi/fd.go @@ -7,6 +7,7 @@ package gfapi // #include // #include import "C" + import ( "os" "syscall" @@ -41,8 +42,8 @@ func (fd *Fd) Fchown(uid, gid uint32) error { // Futimens changes the atime and mtime of the Fd // // Returns error on failure -func (fd *Fd) Futimens(times [2]C.timespec) error { - _, err := C.glfs_futimens(fd.fd, times) +func (fd *Fd) Futimens(times [2]C.struct_timespec) error { + _, err := C.glfs_futimens(fd.fd, ×[0]) return err } @@ -51,7 +52,6 @@ func (fd *Fd) Futimens(times [2]C.timespec) error { // // Returns error on failure func (fd *Fd) Fstat(stat *syscall.Stat_t) error { - ret, err := C.glfs_fstat(fd.fd, (*C.struct_stat)(unsafe.Pointer(stat))) if int(ret) < 0 { return err @@ -230,12 +230,13 @@ func direntName(dirent *syscall.Dirent) string { // then all the items will be returned. func (fd *Fd) Readdir(n int) ([]os.FileInfo, error) { var ( - stat syscall.Stat_t files []os.FileInfo - statP = (*C.struct_stat)(unsafe.Pointer(&stat)) ) for i := 0; n == 0 || i < n; i++ { + var stat syscall.Stat_t + var statP = (*C.struct_stat)(unsafe.Pointer(&stat)) + d, err := C.glfs_readdirplus(fd.fd, statP) if err != nil { return nil, err diff --git a/gfapi/file.go b/gfapi/file.go index ac276a0..3486687 100644 --- a/gfapi/file.go +++ b/gfapi/file.go @@ -7,6 +7,7 @@ package gfapi // #include // #include import "C" + import ( "errors" "io" @@ -60,9 +61,9 @@ func (f *File) Chown(uid, gid int) error { } func (f *File) Futimens(atime, mtime time.Time) error { - var times [2]C.timespec - times[1].tv_sec = mtime.Unix() - times[1].tv_nsec = mtime.Nanosecond() + var times [2]C.struct_timespec + times[0] = C.struct_timespec{tv_sec: C.long(atime.Unix()), tv_nsec: C.long(atime.Nanosecond())} + times[1] = C.struct_timespec{tv_sec: C.long(mtime.Unix()), tv_nsec: C.long(mtime.Nanosecond())} return f.Fd.Futimens(times) } diff --git a/gfapi/volume.go b/gfapi/volume.go index 840052d..47654a9 100644 --- a/gfapi/volume.go +++ b/gfapi/volume.go @@ -4,7 +4,7 @@ package gfapi // for more information please 'api/src/glfs.h' in the glusterfs source. //go:generate sh -c "go tool cgo -godefs types_unix.go | gofmt > ztypes_${GOOS}_${GOARCH}.go" -//TODO: Need to run `go generate` on different platforms to generate relevant ztypes file for each +// TODO: Need to run `go generate` on different platforms to generate relevant ztypes file for each // - *BSD // - Mac OS X @@ -14,6 +14,7 @@ package gfapi // #include // #include import "C" + import ( "errors" "fmt" @@ -172,7 +173,7 @@ func (v *Volume) Chown(name string, uid, gid int) error { cname := C.CString(name) defer C.free(unsafe.Pointer(cname)) - _, err := C.glfs_chmod(v.fs, cname, C.uid_t(uid), C.gid_t(gid)) + _, err := C.glfs_chown(v.fs, cname, C.uid_t(uid), C.gid_t(gid)) return err } @@ -184,10 +185,9 @@ func (v *Volume) Chtimes(name string, mtime time.Time) error { cname := C.CString(name) defer C.free(unsafe.Pointer(cname)) - var amtime [2]C.timespec - amtime[1].tv_sec = mtime.Unix() - amtime[1].tv_nsec = mtime.Nanosecond() - _, err := C.glfs_utimens(v.fs, cname, amtime) + var amtime [2]C.struct_timespec + amtime[1] = C.struct_timespec{tv_sec: C.long(mtime.Unix()), tv_nsec: C.long(mtime.Nanosecond())} + _, err := C.glfs_utimens(v.fs, cname, &amtime[0]) return err }