aboutsummaryrefslogtreecommitdiff
path: root/internal/fusefrontend/file_holes.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/fusefrontend/file_holes.go')
-rw-r--r--internal/fusefrontend/file_holes.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/internal/fusefrontend/file_holes.go b/internal/fusefrontend/file_holes.go
new file mode 100644
index 0000000..0259ae9
--- /dev/null
+++ b/internal/fusefrontend/file_holes.go
@@ -0,0 +1,29 @@
+package fusefrontend
+
+// Helper functions for sparse files (files with holes)
+
+import (
+ "github.com/hanwen/go-fuse/fuse"
+
+ "github.com/rfjakob/gocryptfs/internal/toggledlog"
+)
+
+// Will a write to offset "off" create a file hole?
+func (f *file) createsHole(plainSize uint64, off int64) bool {
+ nextBlock := f.contentEnc.PlainOffToBlockNo(plainSize)
+ targetBlock := f.contentEnc.PlainOffToBlockNo(uint64(off))
+ if targetBlock > nextBlock {
+ return true
+ }
+ return false
+}
+
+// Zero-pad the file of size plainSize to the next block boundary
+func (f *file) zeroPad(plainSize uint64) fuse.Status {
+ lastBlockLen := plainSize % f.contentEnc.PlainBS()
+ missing := f.contentEnc.PlainBS() - lastBlockLen
+ pad := make([]byte, missing)
+ toggledlog.Debug.Printf("zeroPad: Writing %d bytes\n", missing)
+ _, status := f.doWrite(pad, int64(plainSize))
+ return status
+}