Skip to content

Commit

Permalink
Switch from syscall.Getdents to unix.Getdents
Browse files Browse the repository at this point in the history
On mips64le, syscall.Getdents() and struct syscall.Dirent do
not fit together, causing our parseDirents() implementation to
return garbage ( see rfjakob/gocryptfs#200
and golang/go#23624 ).

Switch to unix.Getdents which does not have this problem -
the next Go release with the syscall package fixes is too
far away, and will take time to trickle into distros.

This issue has been reported by Debian maintainer
Felix Lechner.
  • Loading branch information
rfjakob committed Jan 31, 2018
1 parent 6975cb3 commit 19acbd2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions fuse/test/loopback_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"testing"
"time"

"golang.org/x/sys/unix"

"github.com/hanwen/go-fuse/fuse"
)

Expand Down Expand Up @@ -143,7 +145,7 @@ func TestFallocate(t *testing.T) {
}
}

// Check that "." and ".." exists. syscall.Getdents is linux specific.
// Check that "." and ".." exists. unix.Getdents is linux specific.
func TestSpecialEntries(t *testing.T) {
tc := NewTestCase(t)
defer tc.Cleanup()
Expand All @@ -154,7 +156,7 @@ func TestSpecialEntries(t *testing.T) {
}
defer d.Close()
buf := make([]byte, 100)
n, err := syscall.Getdents(int(d.Fd()), buf)
n, err := unix.Getdents(int(d.Fd()), buf)
if n == 0 {
t.Errorf("directory is empty, entries '.' and '..' are missing")
}
Expand All @@ -180,7 +182,7 @@ func TestReaddirInodes(t *testing.T) {
buf := make([]byte, 100)
// readdir(3) use getdents64(2) internally which returns linux_dirent64
// structures. We don't have readdir(3) so we call getdents64(2) directly.
n, err := syscall.Getdents(int(d.Fd()), buf)
n, err := unix.Getdents(int(d.Fd()), buf)
if n == 0 {
t.Error("empty directory - we need at least one file")
}
Expand Down
4 changes: 3 additions & 1 deletion fuse/test/xfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"syscall"
"testing"
"unsafe"

"golang.org/x/sys/unix"
)

func clen(n []byte) int {
Expand All @@ -34,7 +36,7 @@ type CDirent struct {
func parseDirents(buf []byte) []CDirent {
var result []CDirent
for len(buf) > 0 {
de := *(*syscall.Dirent)(unsafe.Pointer(&buf[0]))
de := *(*unix.Dirent)(unsafe.Pointer(&buf[0]))
buf = buf[de.Reclen:]
bytes := (*[10000]byte)(unsafe.Pointer(&de.Name[0]))
var name = string(bytes[0:clen(bytes[:])])
Expand Down

0 comments on commit 19acbd2

Please sign in to comment.