Commit 6e330dd3 authored by lch's avatar lch Committed by Han-Wen Nienhuys

posixtest: made a unified interface of dirent and replace Getdents

Change-Id: Ibc41b9efc62f89359e712def53b1cfc1dd4c24fc
parent 4dece6d7
...@@ -11,6 +11,10 @@ import ( ...@@ -11,6 +11,10 @@ import (
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
type dirent struct {
unix.Dirent
}
// DirSeek tests that seeking on a directory works for // DirSeek tests that seeking on a directory works for
// https://github.com/hanwen/go-fuse/issues/344 . // https://github.com/hanwen/go-fuse/issues/344 .
// //
...@@ -47,7 +51,7 @@ func DirSeek(t *testing.T, mnt string) { ...@@ -47,7 +51,7 @@ func DirSeek(t *testing.T, mnt string) {
total := 0 total := 0
for { for {
n, err := unix.Getdents(fd, buf) n, err := unix.ReadDirent(fd, buf)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -55,24 +59,24 @@ func DirSeek(t *testing.T, mnt string) { ...@@ -55,24 +59,24 @@ func DirSeek(t *testing.T, mnt string) {
break break
} }
for bpos := 0; bpos < n; total++ { for bpos := 0; bpos < n; total++ {
d := (*unix.Dirent)(unsafe.Pointer(&buf[bpos])) d := (*dirent)(unsafe.Pointer(&buf[bpos]))
if total > historyLen { if total > historyLen {
t.Fatal("too many files") t.Fatal("too many files")
} }
for i := 0; i < total; i++ { for i := 0; i < total; i++ {
if offHistory[i] == d.Off { if offHistory[i] == d.off() {
t.Errorf("entries %d and %d gave duplicate d.Off %d", t.Errorf("entries %d and %d gave duplicate d.Off %d",
i, total, d.Off) i, total, d.off())
} }
} }
offHistory[total] = d.Off offHistory[total] = d.off()
inoHistory[total] = d.Ino inoHistory[total] = d.ino()
bpos += int(d.Reclen) bpos += int(d.Reclen)
} }
} }
// check if seek works correctly // check if seek works correctly
d := (*unix.Dirent)(unsafe.Pointer(&buf[0])) d := (*dirent)(unsafe.Pointer(&buf[0]))
for i := total - 1; i >= 0; i-- { for i := total - 1; i >= 0; i-- {
var seekTo int64 var seekTo int64
if i > 0 { if i > 0 {
...@@ -83,7 +87,7 @@ func DirSeek(t *testing.T, mnt string) { ...@@ -83,7 +87,7 @@ func DirSeek(t *testing.T, mnt string) {
t.Fatal(err) t.Fatal(err)
} }
n, err := unix.Getdents(fd, buf) n, err := unix.ReadDirent(fd, buf)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -92,9 +96,9 @@ func DirSeek(t *testing.T, mnt string) { ...@@ -92,9 +96,9 @@ func DirSeek(t *testing.T, mnt string) {
continue continue
} }
if d.Ino != inoHistory[i] { if d.ino() != inoHistory[i] {
t.Errorf("entry %d has inode %d, expected %d", t.Errorf("entry %d has inode %d, expected %d",
i, d.Ino, inoHistory[i]) i, d.ino(), inoHistory[i])
} }
} }
} }
package posixtest
func (d *dirent) off() int64 {
return int64(d.Seekoff)
}
func (d *dirent) ino() uint64 {
return d.Ino
}
package posixtest
func (d *dirent) off() int64 {
return d.Off
}
func (d *dirent) ino() uint64 {
return d.Fileno
}
package posixtest
func (d *dirent) off() int64 {
return d.Off
}
func (d *dirent) ino() uint64 {
return d.Ino
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment