From e7ba3c61f1055d740539d608cc521d816d07cddd Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Wed, 9 Sep 2015 19:32:59 +0200 Subject: Fix File.GettAttr() size reporting The too-large reported value broke mmap (applications saw appended zero bytes) Also * Add locking for all fd operations * Add "--debug" command line switch --- pathfs_frontend/file.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'pathfs_frontend/file.go') diff --git a/pathfs_frontend/file.go b/pathfs_frontend/file.go index 8fdd4b2..493a223 100644 --- a/pathfs_frontend/file.go +++ b/pathfs_frontend/file.go @@ -58,7 +58,9 @@ func (f *file) doRead(off uint64, length uint64) ([]byte, fuse.Status) { alignedOffset, alignedLength, skip := f.cfs.CiphertextRange(off, length) cryptfs.Debug.Printf("CiphertextRange(%d, %d) -> %d, %d, %d\n", off, length, alignedOffset, alignedLength, skip) ciphertext := make([]byte, int(alignedLength)) + f.lock.Lock() n, err := f.fd.ReadAt(ciphertext, int64(alignedOffset)) + f.lock.Unlock() ciphertext = ciphertext[0:n] if err != nil && err != io.EOF { cryptfs.Warn.Printf("read: ReadAt: %s\n", err.Error()) @@ -131,11 +133,14 @@ func (f *file) Write(data []byte, off int64) (uint32, fuse.Status) { blockData = f.cfs.MergeBlocks(oldData, blockData, int(b.Offset)) cryptfs.Debug.Printf("len(oldData)=%d len(blockData)=%d\n", len(oldData), len(blockData)) } + // Write blockOffset, _ := b.CiphertextRange() blockData = f.cfs.EncryptBlock(blockData) cryptfs.Debug.Printf("WriteAt offset=%d length=%d\n", blockOffset, len(blockData)) + f.lock.Lock() _, err := f.fd.WriteAt(blockData, int64(blockOffset)) + f.lock.Unlock() if err != nil { cryptfs.Warn.Printf("Write failed: %s\n", err.Error()) @@ -213,6 +218,7 @@ func (f *file) GetAttr(a *fuse.Attr) fuse.Status { return fuse.ToStatus(err) } a.FromStat(&st) + a.Size = f.cfs.PlainSize(a.Size) return fuse.OK } -- cgit v1.2.3