From 9b725c15cf50cfb85ec6ec88c47843092775dedc Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 3 Jul 2016 19:14:12 +0200 Subject: syscallcompat: OSX: add Fallocate and Openat wrappers ...and convert all calls to syscall.{Fallocate,Openat} to syscallcompat . Both syscalls are not available on OSX. We emulate Openat and just return EOPNOTSUPP for Fallocate. --- internal/fusefrontend/file.go | 4 ++-- internal/fusefrontend/file_allocate_truncate.go | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'internal/fusefrontend') diff --git a/internal/fusefrontend/file.go b/internal/fusefrontend/file.go index f0e0c41..b9bb2c9 100644 --- a/internal/fusefrontend/file.go +++ b/internal/fusefrontend/file.go @@ -101,7 +101,7 @@ func (f *file) createHeader() error { buf := h.Pack() // Prevent partially written (=corrupt) header by preallocating the space beforehand - err := syscallcompat.Prealloc(int(f.fd.Fd()), 0, contentenc.HEADER_LEN) + err := syscallcompat.EnospcPrealloc(int(f.fd.Fd()), 0, contentenc.HEADER_LEN) if err != nil { tlog.Warn.Printf("ino%d: createHeader: prealloc failed: %s\n", f.ino, err.Error()) return err @@ -262,7 +262,7 @@ func (f *file) doWrite(data []byte, off int64) (uint32, fuse.Status) { f.ino, uint64(len(blockData))-f.contentEnc.BlockOverhead(), b.BlockNo) // Prevent partially written (=corrupt) blocks by preallocating the space beforehand - err := syscallcompat.Prealloc(int(f.fd.Fd()), int64(blockOffset), int64(len(blockData))) + err := syscallcompat.EnospcPrealloc(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) diff --git a/internal/fusefrontend/file_allocate_truncate.go b/internal/fusefrontend/file_allocate_truncate.go index 65d6df6..f22fa4b 100644 --- a/internal/fusefrontend/file_allocate_truncate.go +++ b/internal/fusefrontend/file_allocate_truncate.go @@ -10,6 +10,7 @@ import ( "github.com/hanwen/go-fuse/fuse" + "github.com/rfjakob/gocryptfs/internal/syscallcompat" "github.com/rfjakob/gocryptfs/internal/tlog" ) @@ -59,7 +60,7 @@ func (f *file) Allocate(off uint64, sz uint64, mode uint32) fuse.Status { cipherOff := firstBlock.BlockCipherOff() cipherSz := lastBlock.BlockCipherOff() - cipherOff + f.contentEnc.PlainSizeToCipherSize(lastBlock.Skip+lastBlock.Length) - err := syscall.Fallocate(f.intFd(), FALLOC_FL_KEEP_SIZE, int64(cipherOff), int64(cipherSz)) + err := syscallcompat.Fallocate(f.intFd(), FALLOC_FL_KEEP_SIZE, int64(cipherOff), int64(cipherSz)) tlog.Debug.Printf("Allocate off=%d sz=%d mode=%x cipherOff=%d cipherSz=%d\n", off, sz, mode, cipherOff, cipherSz) if err != nil { -- cgit v1.2.3