aboutsummaryrefslogtreecommitdiff
path: root/internal/fusefrontend/file_allocate_truncate.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/fusefrontend/file_allocate_truncate.go')
-rw-r--r--internal/fusefrontend/file_allocate_truncate.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/internal/fusefrontend/file_allocate_truncate.go b/internal/fusefrontend/file_allocate_truncate.go
index 4a3deb1..ab955fd 100644
--- a/internal/fusefrontend/file_allocate_truncate.go
+++ b/internal/fusefrontend/file_allocate_truncate.go
@@ -9,6 +9,8 @@ import (
"sync"
"syscall"
+ "golang.org/x/sys/unix"
+
"github.com/rfjakob/gocryptfs/v2/internal/contentenc"
"github.com/hanwen/go-fuse/v2/fs"
@@ -109,6 +111,12 @@ func (f *File) truncate(newSize uint64) (errno syscall.Errno) {
f.fileTableEntry.ID = nil
return 0
} else {
+ // Prevent reads and writes concurrent with the truncate operation. It's
+ // racy on tmpfs and ext4 ( https://lore.kernel.org/all/18e9fa0f-ec31-9107-459c-ae1694503f87@gmail.com/t/ )
+ // as evident by TestOpenTruncate test failures.
+ f.LockSharedStorage(unix.F_WRLCK, 0, 0)
+ defer f.LockSharedStorage(unix.F_UNLCK, 0, 0)
+
// With -sharedstorage, we keep the on-disk file header.
// Other mounts may have the file ID cached so we cannot mess with it.