diff options
author | Jakob Unterwurzacher | 2015-10-04 11:39:35 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2015-10-04 11:39:35 +0200 |
commit | 2003ca965d2905e240f2b2f1c596aa02f7786c77 (patch) | |
tree | cefc83c85c7f09d372746e53738db54e1416648c /pathfs_frontend/file.go | |
parent | 5229b8f5f5ef8d3e91fe2ab1f415131337161577 (diff) |
Zero-pad last block if a file hole is created on Write()
Fixes TestFileHoles test
Diffstat (limited to 'pathfs_frontend/file.go')
-rw-r--r-- | pathfs_frontend/file.go | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/pathfs_frontend/file.go b/pathfs_frontend/file.go index 9c58557..2c2f1eb 100644 --- a/pathfs_frontend/file.go +++ b/pathfs_frontend/file.go @@ -113,7 +113,7 @@ func (f *file) doRead(off uint64, length uint64) ([]byte, fuse.Status) { // Read - FUSE call func (f *file) Read(buf []byte, off int64) (resultData fuse.ReadResult, code fuse.Status) { - cryptfs.Debug.Printf("ino%d: Read: offset=%d length=%d\n", f.ino, len(buf), off) + cryptfs.Debug.Printf("ino%d: FUSE Read: offset=%d length=%d\n", f.ino, len(buf), off) if f.writeOnly { cryptfs.Warn.Printf("ino%d: Tried to read from write-only file\n", f.ino) @@ -133,10 +133,8 @@ func (f *file) Read(buf []byte, off int64) (resultData fuse.ReadResult, code fus return fuse.ReadResultData(out), status } -// Write - FUSE call -func (f *file) Write(data []byte, off int64) (uint32, fuse.Status) { - cryptfs.Debug.Printf("ino%d: Write %s: offset=%d length=%d\n", f.ino, off, len(data)) - +// Do the actual write +func (f *file) doWrite(data []byte, off int64) (uint32, fuse.Status) { var written uint32 status := fuse.OK dataBuf := bytes.NewBuffer(data) @@ -177,10 +175,16 @@ func (f *file) Write(data []byte, off int64) (uint32, fuse.Status) { } written += uint32(b.Length) } - return written, status } +// Write - FUSE call +func (f *file) Write(data []byte, off int64) (uint32, fuse.Status) { + cryptfs.Debug.Printf("ino%d: FUSE Write %s: offset=%d length=%d\n", f.ino, off, len(data)) + f.conditionalZeroPad(off) + return f.doWrite(data, off) +} + // Release - FUSE call, forget file func (f *file) Release() { f.lock.Lock() |