From 7b22b426b9f5e68a0ff51799e04f193dc74586d0 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sat, 2 Jul 2016 00:12:36 +0200 Subject: contentenc: rename PlaintextRange and CiphertextRange The name could be misunderstood and actually caused a bug: doWrite used to always preallocate 4128 instead of the actual data length. --- internal/fusefrontend/file.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'internal/fusefrontend/file.go') diff --git a/internal/fusefrontend/file.go b/internal/fusefrontend/file.go index 8f13553..b5775c2 100644 --- a/internal/fusefrontend/file.go +++ b/internal/fusefrontend/file.go @@ -244,7 +244,7 @@ func (f *file) doWrite(data []byte, off int64) (uint32, fuse.Status) { // Incomplete block -> Read-Modify-Write if b.IsPartial() { // Read - o, _ := b.PlaintextRange() + o := b.BlockPlainOff() var oldData []byte oldData, status = f.doRead(o, f.contentEnc.PlainBS()) if status != fuse.OK { @@ -257,13 +257,13 @@ func (f *file) doWrite(data []byte, off int64) (uint32, fuse.Status) { } // Encrypt - blockOffset, blockLen := b.CiphertextRange() + blockOffset := b.BlockCipherOff() blockData = f.contentEnc.EncryptBlock(blockData, b.BlockNo, f.header.Id) tlog.Debug.Printf("ino%d: Writing %d bytes to block #%d", f.ino, uint64(len(blockData))-f.contentEnc.BlockOverhead(), b.BlockNo) // Prevent partially written (=corrupt) blocks by preallocating the space beforehand - err := prealloc(int(f.fd.Fd()), int64(blockOffset), int64(blockLen)) + err := prealloc(int(f.fd.Fd()), int64(blockOffset), int64(len(blockData))) if err != nil { tlog.Warn.Printf("ino%d fh%d: doWrite: prealloc failed: %s", f.ino, f.intFd(), err.Error()) status = fuse.ToStatus(err) @@ -410,12 +410,12 @@ func (f *file) Truncate(newSize uint64) fuse.Status { } lastBlock := addBlocks[len(addBlocks)-1] if lastBlock.IsPartial() { - off, _ := lastBlock.PlaintextRange() + off := lastBlock.BlockPlainOff() _, status := f.doWrite(make([]byte, lastBlock.Length), int64(off+lastBlock.Skip)) return status } else { - off, length := lastBlock.CiphertextRange() - err = syscall.Ftruncate(f.intFd(), int64(off+length)) + off := lastBlock.BlockCipherOff() + err = syscall.Ftruncate(f.intFd(), int64(off+f.contentEnc.CipherBS())) if err != nil { tlog.Warn.Printf("Truncate: grow Ftruncate returned error: %v", err) } -- cgit v1.2.3