summaryrefslogtreecommitdiff
path: root/internal/fusefrontend/file_holes.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2017-03-12 21:06:59 +0100
committerJakob Unterwurzacher2017-03-12 21:06:59 +0100
commitd36d53c9bbf1b1f1c34578d443770672528e4466 (patch)
tree33abca8ec3819ab9a4b20bd4490fe5cdabdc4169 /internal/fusefrontend/file_holes.go
parent9a0808b1ee4cca94a3178b14838b558bf03d483b (diff)
fusefrontend: truncateGrowFile: avoid createHeader() call
...if doWrite() can do it for us. This avoids the situation that the file only consists of a file header when calling doWrite. A later patch will check for this condition and warn about it, as with this change it should no longer occour in normal operation.
Diffstat (limited to 'internal/fusefrontend/file_holes.go')
-rw-r--r--internal/fusefrontend/file_holes.go9
1 files changed, 5 insertions, 4 deletions
diff --git a/internal/fusefrontend/file_holes.go b/internal/fusefrontend/file_holes.go
index 5b7a244..d779191 100644
--- a/internal/fusefrontend/file_holes.go
+++ b/internal/fusefrontend/file_holes.go
@@ -30,7 +30,7 @@ func (f *file) writePadHole(targetOff int64) fuse.Status {
}
// The write goes past the next block. nextBlock has
// to be zero-padded to the block boundary and (at least) nextBlock+1
- // will become a file hole in the ciphertext.
+ // will contain a file hole in the ciphertext.
status := f.zeroPad(plainSize)
if status != fuse.OK {
tlog.Warn.Printf("zeroPad returned error %v", status)
@@ -39,14 +39,15 @@ func (f *file) writePadHole(targetOff int64) fuse.Status {
return fuse.OK
}
-// Zero-pad the file of size plainSize to the next block boundary
+// Zero-pad the file of size plainSize to the next block boundary. This is a no-op
+// if the file is already block-aligned.
func (f *file) zeroPad(plainSize uint64) fuse.Status {
lastBlockLen := plainSize % f.contentEnc.PlainBS()
- missing := f.contentEnc.PlainBS() - lastBlockLen
- if missing == 0 {
+ if lastBlockLen == 0 {
// Already block-aligned
return fuse.OK
}
+ missing := f.contentEnc.PlainBS() - lastBlockLen
pad := make([]byte, missing)
tlog.Debug.Printf("zeroPad: Writing %d bytes\n", missing)
_, status := f.doWrite(pad, int64(plainSize))