summaryrefslogtreecommitdiff
path: root/contrib/getdents-debug/getdents
diff options
context:
space:
mode:
authorJakob Unterwurzacher2020-05-25 23:30:59 +0200
committerJakob Unterwurzacher2020-05-25 23:32:11 +0200
commitb275c53fa79c7acc555f382e0831c81491be3183 (patch)
tree343761cab6e4aba05c0bb167f87a24dc20a05d3f /contrib/getdents-debug/getdents
parent0d522e0d3b1e1ec4543ece4e7a9a0ed99da760c4 (diff)
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
Diffstat (limited to 'contrib/getdents-debug/getdents')
-rw-r--r--contrib/getdents-debug/getdents/getdents.go41
1 files changed, 28 insertions, 13 deletions
diff --git a/contrib/getdents-debug/getdents/getdents.go b/contrib/getdents-debug/getdents/getdents.go
index a70692a..cd1e49d 100644
--- a/contrib/getdents-debug/getdents/getdents.go
+++ b/contrib/getdents-debug/getdents/getdents.go
@@ -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)
- fd, err := unix.Open(path, unix.O_RDONLY, 0)
- if err != nil {
- log.Fatalf("unix.Open returned err=%v", err)
- }
-
tmp := make([]byte, 10000)
- sum := 0
for {
- n, err := unix.Getdents(fd, tmp)
- fmt.Printf("unix.Getdents fd%d: n=%d, err=%v\n", fd, n, err)
- if n <= 0 {
- fmt.Printf("total %d bytes\n", sum)
+ sum := 0
+ fd, err := unix.Open(path, unix.O_RDONLY, 0)
+ if err != nil {
+ fmt.Printf("unix.Open returned err=%v\n", err)
+ continue
+ }
+ fmt.Printf("unix.Getdents: ")
+ for {
+ n, err := unix.Getdents(fd, tmp)
+ fmt.Printf("n=%d; ", n)
+ if n <= 0 {
+ 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
}
- sum += n
}
}