From d36d53c9bbf1b1f1c34578d443770672528e4466 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 12 Mar 2017 21:06:59 +0100 Subject: 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. --- internal/fusefrontend/file_holes.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'internal/fusefrontend/file_holes.go') 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)) -- cgit v1.2.3