From 6019598fdb9d223beec7da5848cf950ca90e85e7 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 24 May 2020 23:46:41 +0200 Subject: contrib: collect getdents stuff in getdents-debug folder --- contrib/getdents-debug/getdents/.gitignore | 1 + contrib/getdents-debug/getdents/getdents.go | 75 ++++++++++++++++++++++++++++ contrib/getdents-debug/getdents_c/.gitignore | 1 + contrib/getdents-debug/getdents_c/Makefile | 2 + contrib/getdents-debug/getdents_c/getdents.c | 39 +++++++++++++++ 5 files changed, 118 insertions(+) create mode 100644 contrib/getdents-debug/getdents/.gitignore create mode 100644 contrib/getdents-debug/getdents/getdents.go create mode 100644 contrib/getdents-debug/getdents_c/.gitignore create mode 100644 contrib/getdents-debug/getdents_c/Makefile create mode 100644 contrib/getdents-debug/getdents_c/getdents.c (limited to 'contrib/getdents-debug') diff --git a/contrib/getdents-debug/getdents/.gitignore b/contrib/getdents-debug/getdents/.gitignore new file mode 100644 index 0000000..6dae481 --- /dev/null +++ b/contrib/getdents-debug/getdents/.gitignore @@ -0,0 +1 @@ +/getdents diff --git a/contrib/getdents-debug/getdents/getdents.go b/contrib/getdents-debug/getdents/getdents.go new file mode 100644 index 0000000..a70692a --- /dev/null +++ b/contrib/getdents-debug/getdents/getdents.go @@ -0,0 +1,75 @@ +/* +Small tool to try to debug unix.Getdents problems on CIFS mounts +( https://github.com/rfjakob/gocryptfs/issues/483 ) + +Example output: + +$ while sleep 1 ; do ./getdents /mnt/synology/public/tmp/g1 ; done +unix.Getdents fd3: n=4176, err= +unix.Getdents fd3: n=4176, err= +unix.Getdents fd3: n=4176, err= +unix.Getdents fd3: n=4176, err= +unix.Getdents fd3: n=4176, err= +unix.Getdents fd3: n=3192, err= +unix.Getdents fd3: n=0, err= +total 24072 bytes +unix.Getdents fd3: n=4176, err= +unix.Getdents fd3: n=4176, err= +unix.Getdents fd3: n=4176, err= +unix.Getdents fd3: n=4176, err= +unix.Getdents fd3: n=-1, err=no such file or directory +total 16704 bytes +unix.Getdents fd3: n=4176, err= +unix.Getdents fd3: n=4176, err= +unix.Getdents fd3: n=4176, err= +unix.Getdents fd3: n=4176, err= +unix.Getdents fd3: n=4176, err= +unix.Getdents fd3: n=3192, err= +unix.Getdents fd3: n=0, err= +total 24072 bytes +*/ + +package main + +import ( + "flag" + "fmt" + "log" + "os" + + "golang.org/x/sys/unix" +) + +const ( + myName = "getdents" +) + +func main() { + flag.Usage = func() { + fmt.Fprintf(os.Stderr, "Usage: %s PATH\n", myName) + fmt.Fprintf(os.Stderr, "Run getdents(2) on PATH\n") + os.Exit(1) + } + 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) + break + } + sum += n + } +} diff --git a/contrib/getdents-debug/getdents_c/.gitignore b/contrib/getdents-debug/getdents_c/.gitignore new file mode 100644 index 0000000..2f94993 --- /dev/null +++ b/contrib/getdents-debug/getdents_c/.gitignore @@ -0,0 +1 @@ +/getdents_c diff --git a/contrib/getdents-debug/getdents_c/Makefile b/contrib/getdents-debug/getdents_c/Makefile new file mode 100644 index 0000000..95e47dc --- /dev/null +++ b/contrib/getdents-debug/getdents_c/Makefile @@ -0,0 +1,2 @@ +getdents_c: *.c Makefile + gcc getdents.c -o getdents_c diff --git a/contrib/getdents-debug/getdents_c/getdents.c b/contrib/getdents-debug/getdents_c/getdents.c new file mode 100644 index 0000000..98c2346 --- /dev/null +++ b/contrib/getdents-debug/getdents_c/getdents.c @@ -0,0 +1,39 @@ +// See ../getdents/getdents.go for some info on why +// this exists. + +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + if(argc < 2) { + printf("Usage: %s PATH\n", argv[0]); + printf("Run getdents(2) on PATH\n"); + exit(1); + } + + const char *path = argv[1]; + int fd = open(path, O_RDONLY); + if (fd == -1) { + perror("open"); + exit(1); + } + + char tmp[10000]; + int sum = 0; + for ( ; ; ) { + int n = syscall(SYS_getdents64, fd, tmp, sizeof(tmp)); + printf("getdents64 fd%d: n=%d, errno=%d\n", fd, n, errno); + if (n <= 0) { + printf("total %d bytes\n", sum); + break; + } + sum += n; + } +} -- cgit v1.2.3