aboutsummaryrefslogtreecommitdiff
path: root/pathfs_frontend
diff options
context:
space:
mode:
Diffstat (limited to 'pathfs_frontend')
-rw-r--r--pathfs_frontend/file.go6
-rw-r--r--pathfs_frontend/fs.go13
2 files changed, 17 insertions, 2 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
}
diff --git a/pathfs_frontend/fs.go b/pathfs_frontend/fs.go
index 0c1d879..1e4a1f3 100644
--- a/pathfs_frontend/fs.go
+++ b/pathfs_frontend/fs.go
@@ -112,8 +112,17 @@ func (fs *FS) Utimens(path string, Atime *time.Time, Mtime *time.Time, context *
return fs.FileSystem.Utimens(fs.EncryptPath(path), Atime, Mtime, context)
}
-func (fs *FS) Readlink(name string, context *fuse.Context) (out string, code fuse.Status) {
- return fs.FileSystem.Readlink(fs.EncryptPath(name), context)
+func (fs *FS) Readlink(name string, context *fuse.Context) (out string, status fuse.Status) {
+ dst, status := fs.FileSystem.Readlink(fs.EncryptPath(name), context)
+ if status != fuse.OK {
+ return "", status
+ }
+ dstPlain, err := fs.DecryptPath(dst)
+ if err != nil {
+ cryptfs.Warn.Printf("Failed decrypting symlink: %s\n", err.Error())
+ return "", fuse.EIO
+ }
+ return dstPlain, status
}
func (fs *FS) Mknod(name string, mode uint32, dev uint32, context *fuse.Context) (code fuse.Status) {