diff options
author | Jakob Unterwurzacher | 2021-05-29 16:00:40 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2021-05-29 16:00:40 +0200 |
commit | c1d7e38761d35149f19524fa19d3afaaca73f302 (patch) | |
tree | 415295dfb899027ebb65c825d6b3349e8f107b0d /contrib/findholes/main.go | |
parent | 07164cbb3a42946a8bb0286da1bc7ea52bb33ee1 (diff) |
findholes: add --create, --verify
Also, change the logic for the segment walk to not
rely on the total size. cp does not use the total
size either, and we miss bugs by cheating!
Diffstat (limited to 'contrib/findholes/main.go')
-rw-r--r-- | contrib/findholes/main.go | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/contrib/findholes/main.go b/contrib/findholes/main.go index 6f1ae64..17597ae 100644 --- a/contrib/findholes/main.go +++ b/contrib/findholes/main.go @@ -10,13 +10,25 @@ import ( ) func main() { + flags := struct { + verify *bool + create *bool + }{} + flags.verify = flag.Bool("verify", false, "Verify results using full file scan") + flags.create = flag.Bool("create", false, "Create test file with random holes") flag.Parse() if flag.NArg() != 1 { fmt.Printf("Usage: findholes FILE\n") os.Exit(1) } - f, err := os.Open(flag.Arg(0)) + path := flag.Arg(0) + + if *flags.create { + holes.Create(path) + } + + f, err := os.Open(path) if err != nil { // os.Open() gives nicer error messages than syscall.Open() fmt.Println(err) @@ -31,4 +43,15 @@ func main() { } fmt.Println(holes.PrettyPrint(segments)) + + if *flags.verify { + err = holes.Verify(int(f.Fd()), segments) + if err != nil { + fmt.Println(err) + os.Exit(1) + } else { + fmt.Println("verify ok") + } + } + } |