contrib/getdents-debug: implement getdents -loop
$ ./getdents -loop /mnt/synology/public/tmp/g1 unix.Getdents: n=4176; n=4176; n=4176; n=4176; n=4176; n=3192; n=0; err=<nil>; total 24072 bytes unix.Getdents: n=4176; n=4176; n=4176; n=4176; n=4176; n=3192; n=0; err=<nil>; total 24072 bytes unix.Getdents: n=4176; n=-1; err=no such file or directory; total 4176 bytes
This commit is contained in:
parent
0d522e0d3b
commit
b275c53fa7
@ -27,6 +27,11 @@ unix.Getdents fd3: n=4176, err=<nil>
|
||||
unix.Getdents fd3: n=3192, err=<nil>
|
||||
unix.Getdents fd3: n=0, err=<nil>
|
||||
total 24072 bytes
|
||||
|
||||
|
||||
Failure looks like this in strace:
|
||||
|
||||
[pid 189974] getdents64(6, 0xc000105808, 10000) = -1 ENOENT (No such file or directory)
|
||||
*/
|
||||
|
||||
package main
|
||||
@ -34,7 +39,6 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
@ -46,30 +50,41 @@ const (
|
||||
|
||||
func main() {
|
||||
flag.Usage = func() {
|
||||
fmt.Fprintf(os.Stderr, "Usage: %s PATH\n", myName)
|
||||
fmt.Fprintf(os.Stderr, "Usage: %s [-loop] PATH\n", myName)
|
||||
fmt.Fprintf(os.Stderr, "Run getdents(2) on PATH\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
loop := flag.Bool("loop", false, "Run in a loop")
|
||||
flag.Parse()
|
||||
if flag.NArg() != 1 {
|
||||
flag.Usage()
|
||||
}
|
||||
path := flag.Arg(0)
|
||||
|
||||
tmp := make([]byte, 10000)
|
||||
for {
|
||||
sum := 0
|
||||
fd, err := unix.Open(path, unix.O_RDONLY, 0)
|
||||
if err != nil {
|
||||
log.Fatalf("unix.Open returned err=%v", err)
|
||||
fmt.Printf("unix.Open returned err=%v\n", err)
|
||||
continue
|
||||
}
|
||||
|
||||
tmp := make([]byte, 10000)
|
||||
sum := 0
|
||||
fmt.Printf("unix.Getdents: ")
|
||||
for {
|
||||
n, err := unix.Getdents(fd, tmp)
|
||||
fmt.Printf("unix.Getdents fd%d: n=%d, err=%v\n", fd, n, err)
|
||||
fmt.Printf("n=%d; ", n)
|
||||
if n <= 0 {
|
||||
fmt.Printf("total %d bytes\n", sum)
|
||||
fmt.Printf("err=%v; total %d bytes\n", err, sum)
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
break
|
||||
}
|
||||
sum += n
|
||||
}
|
||||
unix.Close(fd)
|
||||
if !*loop {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user