aboutsummaryrefslogtreecommitdiff
path: root/contrib/findholes/main.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2021-05-24 14:26:20 +0200
committerJakob Unterwurzacher2021-05-26 13:17:56 +0200
commit8bccd3b4bf18d6505723b1c5ae30de4bbaad126e (patch)
tree0f284c955b66f28d9a2f177e633add9c9f186aa2 /contrib/findholes/main.go
parent1b3c3b1347ef711ec38bb4c5cb14661035faf2ce (diff)
Add contrib/findholes
Utility and libs to find hole/data segments using lseek.
Diffstat (limited to 'contrib/findholes/main.go')
-rw-r--r--contrib/findholes/main.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/contrib/findholes/main.go b/contrib/findholes/main.go
new file mode 100644
index 0000000..6f1ae64
--- /dev/null
+++ b/contrib/findholes/main.go
@@ -0,0 +1,34 @@
+// Find and pretty-print holes & data sections of a file.
+package main
+
+import (
+ "flag"
+ "fmt"
+ "os"
+
+ "github.com/rfjakob/gocryptfs/contrib/findholes/holes"
+)
+
+func main() {
+ flag.Parse()
+ if flag.NArg() != 1 {
+ fmt.Printf("Usage: findholes FILE\n")
+ os.Exit(1)
+ }
+
+ f, err := os.Open(flag.Arg(0))
+ if err != nil {
+ // os.Open() gives nicer error messages than syscall.Open()
+ fmt.Println(err)
+ os.Exit(1)
+ }
+ defer f.Close()
+
+ segments, err := holes.Find(int(f.Fd()))
+ if err != nil {
+ fmt.Println(err)
+ os.Exit(1)
+ }
+
+ fmt.Println(holes.PrettyPrint(segments))
+}