aboutsummaryrefslogtreecommitdiff
path: root/pathfs_frontend/file.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2015-09-09 19:32:59 +0200
committerJakob Unterwurzacher2015-09-09 19:32:59 +0200
commite7ba3c61f1055d740539d608cc521d816d07cddd (patch)
tree576c202f47457e2e2faad3f139efc65667cdc11e /pathfs_frontend/file.go
parent80935a0e1b3848608bcc8e1e1497435801ac9940 (diff)
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
Diffstat (limited to 'pathfs_frontend/file.go')
-rw-r--r--pathfs_frontend/file.go6
1 files changed, 6 insertions, 0 deletions
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
}