From d64ccf7cf4d110d515b07b7f95127f12ecd4d318 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Tue, 25 Oct 2016 22:37:45 +0200 Subject: fusefrontend: move hole padding check out of Write() The details of the hole handling don't have to be in Write, so move it away. --- internal/fusefrontend/file.go | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'internal/fusefrontend/file.go') diff --git a/internal/fusefrontend/file.go b/internal/fusefrontend/file.go index 9fb9f7e..ee48930 100644 --- a/internal/fusefrontend/file.go +++ b/internal/fusefrontend/file.go @@ -297,21 +297,11 @@ func (f *file) Write(data []byte, off int64) (uint32, fuse.Status) { } wlock.lock(f.ino) defer wlock.unlock(f.ino) - tlog.Debug.Printf("ino%d: FUSE Write: offset=%d length=%d", f.ino, off, len(data)) - - fi, err := f.fd.Stat() - if err != nil { - tlog.Warn.Printf("Write: Fstat failed: %v", err) - return 0, fuse.ToStatus(err) - } - plainSize := f.contentEnc.CipherSizeToPlainSize(uint64(fi.Size())) - if f.createsCiphertextHole(plainSize, off) { - status := f.zeroPad(plainSize) - if status != fuse.OK { - tlog.Warn.Printf("zeroPad returned error %v", status) - return 0, status - } + // If the write creates a file hole, we have to zero-pad the last block. + status := f.writePadHole(off) + if !status.Ok() { + return 0, status } return f.doWrite(data, off) } -- cgit v1.2.3